Authored by qinchao

自动伸缩

... ... @@ -119,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;
... ... @@ -144,12 +144,39 @@ public class AwsQueryService {
}
}
if(!nameTag.equals(group.getAutoScalingGroupName())&&!equalsName.equals(group.getAutoScalingGroupName())){
continue;
if(nameTag.equals(group.getAutoScalingGroupName())||equalsName.equals(group.getAutoScalingGroupName())){
commGroup = new CommAutoScalingGroup();
commGroup.setScalingGroupName(group.getAutoScalingGroupName());
commGroup.setMinSize(group.getMinSize());
commGroup.setMaxSize(group.getMaxSize());
commGroup.setDesiredCapacity(group.getDesiredCapacity());
if(CollectionUtils.isNotEmpty(group.getInstances())){
Collection<String> ids = new ArrayList<>();
Map<String, Boolean> idsMap = new HashMap<>();
for(com.amazonaws.services.autoscaling.model.Instance instance : group.getInstances()){
ids.add(instance.getInstanceId());
idsMap.put(instance.getInstanceId(),instance.getProtectedFromScaleIn());
}
//根据InstanceId获取详细信息
List<CommAutoScalingInstances> commInstancess = getDescribeInstances(ids, idsMap);
//计算出几台是受保护的机器,方便前台使用
if(CollectionUtils.isNotEmpty(commInstancess)){
int count = 0;
for(CommAutoScalingInstances awsInstance : commInstancess){
if("TRUE".equals(awsInstance.getProtectedFrom().toUpperCase())){
count += 1;
}
}
commGroup.setProtectedFromCount(count);
}
commGroup.setScalingInstancess(commInstancess);
commGroups.add(commGroup);
}
}
}else{
commGroup = new CommAutoScalingGroup();
commGroup.setScalingGroupName(group.getAutoScalingGroupName());
commGroup.setMinSize(group.getMinSize());
... ... @@ -180,6 +207,9 @@ public class AwsQueryService {
commGroups.add(commGroup);
}
}
}
}catch (Exception e){
DEBUG.error(" - AwsController - getAwsAutoScaling - error", e);
}
... ...
... ... @@ -137,7 +137,13 @@ public class CloudToolController {
public BaseResponse getIpsByScalingGroupId(int cloudType,String groupName ,String groupId){
BaseResponse response = new BaseResponse();
List<String> ipList = null;
if(1==cloudType){
if(groupName==null||groupName.length()<=0){
response.setCode(300);
response.setMessage("aws伸缩组名字为空");
return response;
}
List<CommAutoScalingGroup> autoScalingGroups = awsQueryService.autoScalingConfig(groupName);
if(autoScalingGroups!=null&&autoScalingGroups.get(0)!=null&&autoScalingGroups.get(0).getScalingInstancess()!=null){
ipList=new ArrayList<String>();
... ...