use of com.amazonaws.services.autoscaling.model.Activity in project cloudbreak by hortonworks.
the class ASGroupStatusCheckerTask method doCall.
@Override
protected Boolean doCall() {
LOGGER.info("Checking status of Auto Scaling group '{}'", autoScalingGroupName);
AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(getAuthenticatedContext().getCloudCredential()), getAuthenticatedContext().getCloudContext().getLocation().getRegion().value());
List<String> instanceIds = cloudFormationStackUtil.getInstanceIds(autoScalingClient, autoScalingGroupName);
if (instanceIds.size() < requiredInstances) {
LOGGER.debug("Instances in AS group: {}, needed: {}", instanceIds.size(), requiredInstances);
List<Activity> activities = getAutoScalingActivities();
if (latestActivity.isPresent()) {
checkForSpotRequest(latestActivity.get(), amazonEC2Client);
activities = activities.stream().filter(activity -> activity.getStartTime().after(latestActivity.get().getStartTime())).collect(Collectors.toList());
}
updateLatestActivity(activities);
checkFailedActivities(activities);
return false;
}
Collection<DescribeInstanceStatusResult> describeInstanceStatusResultList = new ArrayList<>();
List<List<String>> partitionedInstanceIdsList = Lists.partition(instanceIds, MAX_INSTANCE_ID_SIZE);
for (List<String> partitionedInstanceIds : partitionedInstanceIdsList) {
DescribeInstanceStatusRequest describeInstanceStatusRequest = new DescribeInstanceStatusRequest().withInstanceIds(partitionedInstanceIds);
DescribeInstanceStatusResult describeResult = amazonEC2Client.describeInstanceStatus(describeInstanceStatusRequest);
describeInstanceStatusResultList.add(describeResult);
}
List<InstanceStatus> instanceStatusList = describeInstanceStatusResultList.stream().flatMap(describeInstanceStatusResult -> describeInstanceStatusResult.getInstanceStatuses().stream()).collect(Collectors.toList());
if (instanceStatusList.size() < requiredInstances) {
LOGGER.debug("Instances up: {}, needed: {}", instanceStatusList.size(), requiredInstances);
return false;
}
for (InstanceStatus status : instanceStatusList) {
if (INSTANCE_RUNNING != status.getInstanceState().getCode()) {
LOGGER.debug("Instances are up but not all of them are in running state.");
return false;
}
}
return true;
}
Aggregations