Showing
1 changed file
with
22 additions
and
5 deletions
@@ -5,6 +5,7 @@ import com.amazonaws.regions.Regions; | @@ -5,6 +5,7 @@ import com.amazonaws.regions.Regions; | ||
5 | import com.amazonaws.services.autoscaling.AmazonAutoScaling; | 5 | import com.amazonaws.services.autoscaling.AmazonAutoScaling; |
6 | import com.amazonaws.services.autoscaling.AmazonAutoScalingClient; | 6 | import com.amazonaws.services.autoscaling.AmazonAutoScalingClient; |
7 | import com.amazonaws.services.autoscaling.model.*; | 7 | import com.amazonaws.services.autoscaling.model.*; |
8 | +import com.amazonaws.services.autoscaling.model.TagDescription; | ||
8 | import com.amazonaws.services.ec2.model.*; | 9 | import com.amazonaws.services.ec2.model.*; |
9 | import com.amazonaws.services.ec2.model.Filter; | 10 | import com.amazonaws.services.ec2.model.Filter; |
10 | import com.amazonaws.services.ec2.model.Instance; | 11 | import com.amazonaws.services.ec2.model.Instance; |
@@ -32,6 +33,7 @@ import org.springframework.stereotype.Service; | @@ -32,6 +33,7 @@ import org.springframework.stereotype.Service; | ||
32 | 33 | ||
33 | import java.text.SimpleDateFormat; | 34 | import java.text.SimpleDateFormat; |
34 | import java.util.*; | 35 | import java.util.*; |
36 | +import java.util.stream.Stream; | ||
35 | 37 | ||
36 | /** | 38 | /** |
37 | * Created by yoho on 2016/8/31. | 39 | * Created by yoho on 2016/8/31. |
@@ -57,6 +59,7 @@ public class AwsQueryService { | @@ -57,6 +59,7 @@ public class AwsQueryService { | ||
57 | return commAutoScalingGroups; | 59 | return commAutoScalingGroups; |
58 | } | 60 | } |
59 | 61 | ||
62 | + | ||
60 | /** | 63 | /** |
61 | * 修改伸缩组信息 | 64 | * 修改伸缩组信息 |
62 | * @param req | 65 | * @param req |
@@ -116,13 +119,13 @@ public class AwsQueryService { | @@ -116,13 +119,13 @@ public class AwsQueryService { | ||
116 | AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials()); | 119 | AmazonAutoScaling client = new AmazonAutoScalingClient(awsClientComp.getAWSCredentials()); |
117 | client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1)); | 120 | client.setRegion(awsClientComp.getRegion(Regions.CN_NORTH_1)); |
118 | DescribeAutoScalingGroupsRequest request = null; | 121 | DescribeAutoScalingGroupsRequest request = null; |
119 | - if(StringUtils.isNotBlank(equalsName)){ | 122 | + /*if(StringUtils.isNotBlank(equalsName)){ |
120 | request = new DescribeAutoScalingGroupsRequest() | 123 | request = new DescribeAutoScalingGroupsRequest() |
121 | .withAutoScalingGroupNames(equalsName); | 124 | .withAutoScalingGroupNames(equalsName); |
122 | - }else{ | 125 | + }else{*/ |
123 | request = new DescribeAutoScalingGroupsRequest() | 126 | request = new DescribeAutoScalingGroupsRequest() |
124 | .withAutoScalingGroupNames(); | 127 | .withAutoScalingGroupNames(); |
125 | - } | 128 | + // } |
126 | DescribeAutoScalingGroupsResult result = client .describeAutoScalingGroups(request); | 129 | DescribeAutoScalingGroupsResult result = client .describeAutoScalingGroups(request); |
127 | if(result == null){ | 130 | if(result == null){ |
128 | return null; | 131 | return null; |
@@ -130,9 +133,23 @@ public class AwsQueryService { | @@ -130,9 +133,23 @@ public class AwsQueryService { | ||
130 | commGroups = new ArrayList<>(); | 133 | commGroups = new ArrayList<>(); |
131 | CommAutoScalingGroup commGroup; | 134 | CommAutoScalingGroup commGroup; |
132 | for(AutoScalingGroup group : result.getAutoScalingGroups()){ | 135 | for(AutoScalingGroup group : result.getAutoScalingGroups()){ |
133 | - if(StringUtils.isNotBlank(equalsName)&&!equalsName.equals(group.getAutoScalingGroupName())){ | ||
134 | - continue; | 136 | + if(StringUtils.isNotBlank(equalsName)){ |
137 | + | ||
138 | + String nameTag=""; | ||
139 | + List<TagDescription> tags=group.getTags(); | ||
140 | + if(tags!=null&&tags.size()>0){ | ||
141 | + Stream<TagDescription> streams= tags.stream().filter(tag -> tag.getKey().equalsIgnoreCase("Name")); | ||
142 | + if(streams!=null){ | ||
143 | + nameTag= streams.findFirst().get().getValue(); | ||
144 | + } | ||
145 | + } | ||
146 | + | ||
147 | + if(!nameTag.equals(group.getAutoScalingGroupName())&&!equalsName.equals(group.getAutoScalingGroupName())){ | ||
148 | + continue; | ||
149 | + } | ||
150 | + | ||
135 | } | 151 | } |
152 | + | ||
136 | commGroup = new CommAutoScalingGroup(); | 153 | commGroup = new CommAutoScalingGroup(); |
137 | commGroup.setScalingGroupName(group.getAutoScalingGroupName()); | 154 | commGroup.setScalingGroupName(group.getAutoScalingGroupName()); |
138 | commGroup.setMinSize(group.getMinSize()); | 155 | commGroup.setMinSize(group.getMinSize()); |
-
Please register or login to post a comment