Search in sources :

Example 1 with Activity

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;
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) Activity(com.amazonaws.services.autoscaling.model.Activity) LoggerFactory(org.slf4j.LoggerFactory) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Matcher(java.util.regex.Matcher) Lists(com.google.common.collect.Lists) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) DescribeScalingActivitiesRequest(com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) PollBooleanStateTask(com.sequenceiq.cloudbreak.cloud.task.PollBooleanStateTask) Logger(org.slf4j.Logger) Collection(java.util.Collection) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) CloudFormationStackUtil(com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) Collectors(java.util.stream.Collectors) DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) List(java.util.List) Component(org.springframework.stereotype.Component) Optional(java.util.Optional) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest) AwsClient(com.sequenceiq.cloudbreak.cloud.aws.AwsClient) Pattern(java.util.regex.Pattern) DescribeSpotInstanceRequestsRequest(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) ArrayList(java.util.ArrayList) Activity(com.amazonaws.services.autoscaling.model.Activity) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 Activity (com.amazonaws.services.autoscaling.model.Activity)1 DescribeScalingActivitiesRequest (com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest)1 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeInstanceStatusRequest (com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest)1 DescribeInstanceStatusResult (com.amazonaws.services.ec2.model.DescribeInstanceStatusResult)1 DescribeSpotInstanceRequestsRequest (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsRequest)1 DescribeSpotInstanceRequestsResult (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult)1 InstanceStatus (com.amazonaws.services.ec2.model.InstanceStatus)1 SpotInstanceRequest (com.amazonaws.services.ec2.model.SpotInstanceRequest)1 Lists (com.google.common.collect.Lists)1 AwsClient (com.sequenceiq.cloudbreak.cloud.aws.AwsClient)1 CloudFormationStackUtil (com.sequenceiq.cloudbreak.cloud.aws.CloudFormationStackUtil)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 PollBooleanStateTask (com.sequenceiq.cloudbreak.cloud.task.PollBooleanStateTask)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1