我使用AWS Java SDK自动缩放ec2实例。以下是代码段。
AmazonAutoScaling client = AmazonAutoScalingClientBuilder.standard().build();
SetDesiredCapacityRequest request = new SetDesiredCapacityRequest().withAutoScalingGroupName("my-auto-scaling-group").withDesiredCapacity(2)
.withHonorCooldown(true);
SetDesiredCapacityResult response = client.setDesiredCapacity(request);
我已将 withHonorCooldown()设置为true。这意味着后续的自动扩展请求将被阻止,直到AWS启动Ec2实例为止。所以我的用例是,由于大多数请求都失败了,因此我同时触发了100个对AWS的自动扩展请求。因此,我的要求是检查特定的AWS自动扩展组中当前是否正在进行任何活动。
if(!client.isAutoscaleInprogress())
client.setDesiredCapacity(request)
答案 0 :(得分:0)
boolean isScalingActivityInProgress(){
AmazonAutoScaling client = AmazonAutoScalingClientBuilder.standard().build();
DescribeScalingActivitiesRequest request = new DescribeScalingActivitiesRequest().withAutoScalingGroupName("my-auto-scaling-group");
DescribeScalingActivitiesResult response = client .describeScalingActivities(request);
Activity activity=response.getActivities().get(0);
return !ScalingActivityStatusCode.Successful.name().equalsIgnoreCase(activity.getStatusCode()
}
注意:活动。getStatusCode()返回自动缩放组的当前活动状态。