|
|
package com.monitor.awstools.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.amazonaws.regions.Regions;
|
|
|
import com.amazonaws.services.autoscaling.AmazonAutoScaling;
|
|
|
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
|
|
|
import com.amazonaws.services.autoscaling.model.AutoScalingGroup;
|
|
|
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest;
|
|
|
import com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult;
|
|
|
import com.amazonaws.services.autoscaling.model.*;
|
|
|
import com.amazonaws.services.ec2.model.*;
|
|
|
import com.amazonaws.services.ec2.model.Filter;
|
|
|
import com.amazonaws.services.ec2.model.Instance;
|
|
|
import com.amazonaws.services.ec2.model.Tag;
|
|
|
import com.monitor.awstools.comp.AWSClientComp;
|
|
|
import com.monitor.awstools.model.AwsModifyScalingGroupReq;
|
|
|
import com.monitor.awstools.model.M_Instance;
|
|
|
import com.monitor.awstools.model.M_SnapShot;
|
|
|
import com.monitor.awstools.model.M_Volume;
|
|
|
import com.monitor.cloudtools.model.CommAutoScalingGroup;
|
|
|
import com.monitor.cloudtools.model.CommAutoScalingInstances;
|
|
|
import com.monitor.cloudtools.util.DateTimeUtil;
|
|
|
import com.monitor.model.response.BaseResponse;
|
|
|
import com.monitor.qcloudtools.constant.QcloudConstant;
|
|
|
import com.monitor.qcloudtools.model.QcloudDescribeScalingActivitySet;
|
|
|
import com.monitor.qcloudtools.util.QcloudSdkUtil;
|
|
|
import com.qcloud.Module.Scaling;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
...
|
...
|
@@ -42,13 +51,62 @@ public class AwsQueryService { |
|
|
//获取AutoScaling组信息
|
|
|
commAutoScalingGroups = this.getAwsAutoScaling(equalsName);
|
|
|
} catch (Exception e) {
|
|
|
DEBUG.error(" - AwsController - autoScalingConfig - error", e);
|
|
|
DEBUG.error(" - AwsQueryService - autoScalingConfig - error", e);
|
|
|
}
|
|
|
|
|
|
return commAutoScalingGroups;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改伸缩组信息
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
public BaseResponse modifyScalingGroup(AwsModifyScalingGroupReq req){
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
if(req==null){
|
|
|
return null;
|
|
|
}
|
|
|
try{
|
|
|
AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials());
|
|
|
client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1));
|
|
|
UpdateAutoScalingGroupRequest request = new UpdateAutoScalingGroupRequest()
|
|
|
.withAutoScalingGroupName(req.getScalingGroupName())
|
|
|
.withMaxSize(req.getMaxSize()).withMinSize(req.getMinSize()).withDesiredCapacity(req.getDesiredCapacity());
|
|
|
UpdateAutoScalingGroupResult awsResponse = client.updateAutoScalingGroup(request);
|
|
|
if(awsResponse==null){
|
|
|
response.setCode(300);
|
|
|
response.setMessage("伸缩结果未知");
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
DEBUG.error(" - AwsQueryService - modifyScalingGroup- error", e);
|
|
|
response.setCode(300);
|
|
|
response.setMessage(e.getMessage());
|
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
public BaseResponse describeScalingActivity(String scalingGroupName) {
|
|
|
BaseResponse response = new BaseResponse();
|
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(scalingGroupName)){
|
|
|
return null;
|
|
|
}
|
|
|
try{
|
|
|
List<CommAutoScalingGroup> commAutoScalingGroups = this.getAwsAutoScaling(scalingGroupName);
|
|
|
if(commAutoScalingGroups == null||commAutoScalingGroups.size()<=0){
|
|
|
return null;
|
|
|
}
|
|
|
response.setData(commAutoScalingGroups.get(0).getScalingInstancess());
|
|
|
}catch (Exception e){
|
|
|
DEBUG.error(" - AwsQueryService - describeScalingActivity- error", e);
|
|
|
response.setCode(300);
|
|
|
response.setMessage(e.getMessage());
|
|
|
}
|
|
|
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取AutoScaling组的信息
|
|
|
* @return
|
|
|
*/
|
...
|
...
|
@@ -57,17 +115,23 @@ public class AwsQueryService { |
|
|
try {
|
|
|
AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials());
|
|
|
client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1));
|
|
|
DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest()
|
|
|
.withAutoScalingGroupNames();
|
|
|
DescribeAutoScalingGroupsRequest request = null;
|
|
|
if(StringUtils.isNotBlank(equalsName)){
|
|
|
request = new DescribeAutoScalingGroupsRequest()
|
|
|
.withAutoScalingGroupNames(equalsName);
|
|
|
}else{
|
|
|
request = new DescribeAutoScalingGroupsRequest()
|
|
|
.withAutoScalingGroupNames();
|
|
|
}
|
|
|
DescribeAutoScalingGroupsResult result = client .describeAutoScalingGroups(request);
|
|
|
if(result == null || CollectionUtils.isEmpty(result.getAutoScalingGroups())){
|
|
|
if(result == null){
|
|
|
return null;
|
|
|
}
|
|
|
commGroups = new ArrayList<>();
|
|
|
CommAutoScalingGroup commGroup;
|
|
|
for(AutoScalingGroup group : result.getAutoScalingGroups()){
|
|
|
if(equalsName != null){
|
|
|
if(group.getAutoScalingGroupName().toLowerCase().indexOf(equalsName) == -1){
|
|
|
if(StringUtils.isNotBlank(equalsName)){
|
|
|
if(!group.getAutoScalingGroupName().toLowerCase().equals(equalsName)){
|
|
|
continue;
|
|
|
}
|
|
|
}
|
...
|
...
|
|