|
@@ -0,0 +1,53 @@
|
|
|
|
+package com.fdkankan.contro.util;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.aliyun.ess20220222.models.ExecuteScalingRuleRequest;
|
|
|
|
+import com.aliyun.ess20220222.models.ExecuteScalingRuleResponse;
|
|
|
|
+import com.aliyun.teaopenapi.models.Config;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
|
|
+@Component
|
|
|
|
+public class EcsScaling {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Value("${scaling.rule.ari}")
|
|
|
|
+ private String scalingRuleAri;
|
|
|
|
+
|
|
|
|
+ @Value("${scaling.accessKeyId:#{null}}")
|
|
|
|
+ private String accessKeyId;
|
|
|
|
+
|
|
|
|
+ @Value("${scaling.accessKeySecret:#{null}}")
|
|
|
|
+ private String accessKeySecret;
|
|
|
|
+
|
|
|
|
+ @Value("${scaling.endPoint:ess.aliyuncs.com}")
|
|
|
|
+ public String endPoint;
|
|
|
|
+
|
|
|
|
+ public void createEcs() throws Exception {
|
|
|
|
+ com.aliyun.teaopenapi.models.Config config = new Config();
|
|
|
|
+ config.setAccessKeyId("LTAI5tHbheG3Z9Nx31Q1SJEd");
|
|
|
|
+ config.setAccessKeySecret("dpDNDlryaixBw4htEgh4P44GrAq2Fg");
|
|
|
|
+ config.setEndpoint("ess.aliyuncs.com");
|
|
|
|
+ config.setRegionId("cn-shenzhen");
|
|
|
|
+
|
|
|
|
+ com.aliyun.ess20220222.Client client = null;
|
|
|
|
+ try {
|
|
|
|
+ client = new com.aliyun.ess20220222.Client(config);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("创建弹性伸缩客户端异常", e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 创建API请求并设置参数
|
|
|
|
+ ExecuteScalingRuleRequest executeScalingRuleRequest = new ExecuteScalingRuleRequest();
|
|
|
|
+ executeScalingRuleRequest.setScalingRuleAri("ari:acs:ess:cn-shenzhen:1899912233141089:scalingrule/asr-wz9f0ovgu3lhqy6p2euh");
|
|
|
|
+
|
|
|
|
+ // 发起请求并处理应答或异常
|
|
|
|
+ ExecuteScalingRuleResponse executeScalingRuleResponse = null;
|
|
|
|
+ executeScalingRuleResponse = client.executeScalingRule(executeScalingRuleRequest);
|
|
|
|
+ log.info("启动弹性伸缩结果:{}",JSON.toJSONString(executeScalingRuleResponse));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|