|
@@ -28,14 +28,20 @@ public class AliYunScalingService implements ScalingService{
|
|
|
@Value("${scaling.rule.ari}")
|
|
|
private String ScalingRuleAri;
|
|
|
|
|
|
- private static String AccessKeyId = "LTAI4GKZQBM1zZZZBJK7nGjR";
|
|
|
+ @Value("${scaling.url}")
|
|
|
+ private String url;
|
|
|
+
|
|
|
+ @Value("${accessKey.id}")
|
|
|
+ private String accessKeyId;
|
|
|
+
|
|
|
+ @Value("${accessKey.secret}")
|
|
|
+ private String accessKeySecret;
|
|
|
|
|
|
private String sign(String action, Map<String, String> parameters) throws Exception{
|
|
|
final String HTTP_METHOD = "GET";
|
|
|
|
|
|
final String ALGORITHM = "HmacSHA1";
|
|
|
final String ENCODING = "UTF-8";
|
|
|
- String keySecret = "bo1ura8KODXASVyZ5fofy0fWFILumz&";
|
|
|
|
|
|
// 对参数进行排序
|
|
|
String[] sortedKeys = parameters.keySet().toArray(new String[]{});
|
|
@@ -58,7 +64,7 @@ public class AliYunScalingService implements ScalingService{
|
|
|
stringToSign.append(percentEncode(canonicalizedQueryString.toString().substring(1)));
|
|
|
|
|
|
Mac mac = Mac.getInstance(ALGORITHM);
|
|
|
- mac.init(new SecretKeySpec(keySecret.getBytes(ENCODING), ALGORITHM));
|
|
|
+ mac.init(new SecretKeySpec(accessKeySecret.getBytes(ENCODING), ALGORITHM));
|
|
|
byte[] signData = mac.doFinal(stringToSign.toString().getBytes(ENCODING));
|
|
|
|
|
|
String signature = new String(org.apache.commons.codec.binary.Base64.encodeBase64(signData));
|
|
@@ -98,7 +104,7 @@ public class AliYunScalingService implements ScalingService{
|
|
|
parameters.put("Action", "ExecuteScalingRule");
|
|
|
parameters.put("ScalingRuleAri", ruleAri);
|
|
|
parameters.put("Version", "2014-08-28");
|
|
|
- parameters.put("AccessKeyId", AccessKeyId);
|
|
|
+ parameters.put("AccessKeyId", accessKeyId);
|
|
|
parameters.put("Timestamp", formatIso8601Date(new Date()));
|
|
|
parameters.put("SignatureMethod", "HMAC-SHA1");
|
|
|
parameters.put("SignatureVersion", "1.0");
|
|
@@ -133,9 +139,9 @@ public class AliYunScalingService implements ScalingService{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return OkHttpUtils.httpGet("http://ess.aliyuncs.com?" + parameterBuffer.toString());
|
|
|
+ return OkHttpUtils.httpGet(url + "?" + parameterBuffer.toString());
|
|
|
}catch (Exception e){
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("启动弹性伸缩失败");
|
|
|
}
|
|
|
|
|
|
return null;
|
|
@@ -153,7 +159,7 @@ public class AliYunScalingService implements ScalingService{
|
|
|
parameters.put("InstanceId.1", id);
|
|
|
parameters.put("ScalingGroupId", ScalingGroupId);
|
|
|
parameters.put("Version", "2014-08-28");
|
|
|
- parameters.put("AccessKeyId", AccessKeyId);
|
|
|
+ parameters.put("AccessKeyId", accessKeyId);
|
|
|
parameters.put("Timestamp", formatIso8601Date(new Date()));
|
|
|
parameters.put("SignatureMethod", "HMAC-SHA1");
|
|
|
parameters.put("SignatureVersion", "1.0");
|
|
@@ -188,7 +194,7 @@ public class AliYunScalingService implements ScalingService{
|
|
|
}
|
|
|
}
|
|
|
// System.out.println("POST parameter : " + parameterBuffer.toString());
|
|
|
- return OkHttpUtils.httpGet("http://ess.aliyuncs.com?" + parameterBuffer.toString());
|
|
|
+ return OkHttpUtils.httpGet(url + "?" + parameterBuffer.toString());
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|