Authored by qinchao

自动伸缩

... ... @@ -5,6 +5,7 @@ import com.amazonaws.regions.Regions;
import com.amazonaws.services.autoscaling.AmazonAutoScaling;
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient;
import com.amazonaws.services.autoscaling.model.*;
import com.amazonaws.services.autoscaling.model.TagDescription;
import com.amazonaws.services.ec2.model.*;
import com.amazonaws.services.ec2.model.Filter;
import com.amazonaws.services.ec2.model.Instance;
... ... @@ -32,6 +33,7 @@ import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Stream;
/**
* Created by yoho on 2016/8/31.
... ... @@ -57,6 +59,7 @@ public class AwsQueryService {
return commAutoScalingGroups;
}
/**
* 修改伸缩组信息
* @param req
... ... @@ -116,13 +119,13 @@ public class AwsQueryService {
AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials());
client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1));
DescribeAutoScalingGroupsRequest request = null;
if(StringUtils.isNotBlank(equalsName)){
/*if(StringUtils.isNotBlank(equalsName)){
request = new DescribeAutoScalingGroupsRequest()
.withAutoScalingGroupNames(equalsName);
}else{
}else{*/
request = new DescribeAutoScalingGroupsRequest()
.withAutoScalingGroupNames();
}
// }
DescribeAutoScalingGroupsResult result = client .describeAutoScalingGroups(request);
if(result == null){
return null;
... ... @@ -130,9 +133,23 @@ public class AwsQueryService {
commGroups = new ArrayList<>();
CommAutoScalingGroup commGroup;
for(AutoScalingGroup group : result.getAutoScalingGroups()){
if(StringUtils.isNotBlank(equalsName)&&!equalsName.equals(group.getAutoScalingGroupName())){
continue;
if(StringUtils.isNotBlank(equalsName)){
String nameTag="";
List<TagDescription> tags=group.getTags();
if(tags!=null&&tags.size()>0){
Stream<TagDescription> streams= tags.stream().filter(tag -> tag.getKey().equalsIgnoreCase("Name"));
if(streams!=null){
nameTag= streams.findFirst().get().getValue();
}
}
if(!nameTag.equals(group.getAutoScalingGroupName())&&!equalsName.equals(group.getAutoScalingGroupName())){
continue;
}
}
commGroup = new CommAutoScalingGroup();
commGroup.setScalingGroupName(group.getAutoScalingGroupName());
commGroup.setMinSize(group.getMinSize());
... ...