Search in sources :

Example 11 with AmazonAutoScalingClient

use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.

the class AWSClient method describeLaunchConfigurations.

/**
 * Describe a set of specific launch configurations.
 *
 * @param names the launch configuration names
 * @return the launch configurations
 */
public List<LaunchConfiguration> describeLaunchConfigurations(String... names) {
    if (names == null || names.length == 0) {
        LOGGER.info(String.format("Getting all launch configurations in region %s.", region));
    } else {
        LOGGER.info(String.format("Getting launch configurations for %d names in region %s.", names.length, region));
    }
    List<LaunchConfiguration> lcs = new LinkedList<LaunchConfiguration>();
    AmazonAutoScalingClient asgClient = asgClient();
    DescribeLaunchConfigurationsRequest request = new DescribeLaunchConfigurationsRequest().withLaunchConfigurationNames(names);
    DescribeLaunchConfigurationsResult result = asgClient.describeLaunchConfigurations(request);
    lcs.addAll(result.getLaunchConfigurations());
    while (result.getNextToken() != null) {
        request.setNextToken(result.getNextToken());
        result = asgClient.describeLaunchConfigurations(request);
        lcs.addAll(result.getLaunchConfigurations());
    }
    LOGGER.info(String.format("Got %d launch configurations in region %s.", lcs.size(), region));
    return lcs;
}
Also used : AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient)

Example 12 with AmazonAutoScalingClient

use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.

the class AWSClient method describeAutoScalingGroups.

/**
 * Describe a set of specific auto scaling groups.
 *
 * @param names the ASG names
 * @return the auto scaling groups
 */
public List<AutoScalingGroup> describeAutoScalingGroups(String... names) {
    if (names == null || names.length == 0) {
        LOGGER.info(String.format("Getting all auto-scaling groups in region %s.", region));
    } else {
        LOGGER.info(String.format("Getting auto-scaling groups for %d names in region %s.", names.length, region));
    }
    List<AutoScalingGroup> asgs = new LinkedList<AutoScalingGroup>();
    AmazonAutoScalingClient asgClient = asgClient();
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest();
    if (names != null) {
        request.setAutoScalingGroupNames(Arrays.asList(names));
    }
    DescribeAutoScalingGroupsResult result = asgClient.describeAutoScalingGroups(request);
    asgs.addAll(result.getAutoScalingGroups());
    while (result.getNextToken() != null) {
        request.setNextToken(result.getNextToken());
        result = asgClient.describeAutoScalingGroups(request);
        asgs.addAll(result.getAutoScalingGroups());
    }
    LOGGER.info(String.format("Got %d auto-scaling groups in region %s.", asgs.size(), region));
    return asgs;
}
Also used : AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient)

Example 13 with AmazonAutoScalingClient

use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project SimianArmy by Netflix.

the class AWSClient method describeAutoScalingInstances.

/**
 * Describe a set of specific auto-scaling instances.
 *
 * @param instanceIds the instance ids
 * @return the instances
 */
public List<AutoScalingInstanceDetails> describeAutoScalingInstances(String... instanceIds) {
    if (instanceIds == null || instanceIds.length == 0) {
        LOGGER.info(String.format("Getting all auto-scaling instances in region %s.", region));
    } else {
        LOGGER.info(String.format("Getting auto-scaling instances for %d ids in region %s.", instanceIds.length, region));
    }
    List<AutoScalingInstanceDetails> instances = new LinkedList<AutoScalingInstanceDetails>();
    AmazonAutoScalingClient asgClient = asgClient();
    DescribeAutoScalingInstancesRequest request = new DescribeAutoScalingInstancesRequest();
    if (instanceIds != null) {
        request.setInstanceIds(Arrays.asList(instanceIds));
    }
    DescribeAutoScalingInstancesResult result = asgClient.describeAutoScalingInstances(request);
    instances.addAll(result.getAutoScalingInstances());
    while (result.getNextToken() != null) {
        request = request.withNextToken(result.getNextToken());
        result = asgClient.describeAutoScalingInstances(request);
        instances.addAll(result.getAutoScalingInstances());
    }
    LOGGER.info(String.format("Got %d auto-scaling instances.", instances.size()));
    return instances;
}
Also used : AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient)

Example 14 with AmazonAutoScalingClient

use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project cloudbreak by hortonworks.

the class AwsResourceConnector method resumeAutoScaling.

private void resumeAutoScaling(AuthenticatedContext ac, CloudStack stack) {
    AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(ac.getCloudCredential()), ac.getCloudContext().getLocation().getRegion().value());
    for (Group group : stack.getGroups()) {
        String asGroupName = cfStackUtil.getAutoscalingGroupName(ac, group.getName(), ac.getCloudContext().getLocation().getRegion().value());
        amazonASClient.resumeProcesses(new ResumeProcessesRequest().withAutoScalingGroupName(asGroupName).withScalingProcesses(SUSPENDED_PROCESSES));
    }
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) ResumeProcessesRequest(com.amazonaws.services.autoscaling.model.ResumeProcessesRequest)

Example 15 with AmazonAutoScalingClient

use of com.amazonaws.services.autoscaling.AmazonAutoScalingClient in project cloudbreak by hortonworks.

the class AwsResourceConnector method downscale.

@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext auth, CloudStack stack, List<CloudResource> resources, List<CloudInstance> vms, Object resourcesToRemove) {
    Collection<String> instanceIds = new ArrayList<>();
    for (CloudInstance vm : vms) {
        instanceIds.add(vm.getInstanceId());
    }
    String asGroupName = cfStackUtil.getAutoscalingGroupName(auth, vms.get(0).getTemplate().getGroupName(), auth.getCloudContext().getLocation().getRegion().value());
    DetachInstancesRequest detachInstancesRequest = new DetachInstancesRequest().withAutoScalingGroupName(asGroupName).withInstanceIds(instanceIds).withShouldDecrementDesiredCapacity(true);
    AmazonAutoScalingClient amazonASClient = awsClient.createAutoScalingClient(new AwsCredentialView(auth.getCloudCredential()), auth.getCloudContext().getLocation().getRegion().value());
    try {
        amazonASClient.detachInstances(detachInstancesRequest);
    } catch (AmazonServiceException e) {
        if (!"ValidationError".equals(e.getErrorCode()) || !e.getErrorMessage().contains("not part of Auto Scaling") || instanceIds.stream().anyMatch(id -> !e.getErrorMessage().contains(id))) {
            throw e;
        }
        LOGGER.info(e.getErrorMessage());
    }
    AmazonEC2Client amazonEC2Client = awsClient.createAccess(new AwsCredentialView(auth.getCloudCredential()), auth.getCloudContext().getLocation().getRegion().value());
    try {
        amazonEC2Client.terminateInstances(new TerminateInstancesRequest().withInstanceIds(instanceIds));
    } catch (AmazonServiceException e) {
        if (!"InvalidInstanceID.NotFound".equals(e.getErrorCode())) {
            throw e;
        }
        LOGGER.info(e.getErrorMessage());
    }
    LOGGER.info("Terminated instances in stack '{}': '{}'", auth.getCloudContext().getId(), instanceIds);
    return check(auth, resources);
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) ArrayList(java.util.ArrayList) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DetachInstancesRequest(com.amazonaws.services.autoscaling.model.DetachInstancesRequest) TerminateInstancesRequest(com.amazonaws.services.ec2.model.TerminateInstancesRequest)

Aggregations

AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)18 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)9 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)6 AmazonServiceException (com.amazonaws.AmazonServiceException)5 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)5 ArrayList (java.util.ArrayList)5 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)3 ResumeProcessesRequest (com.amazonaws.services.autoscaling.model.ResumeProcessesRequest)3 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 ClientConfiguration (com.amazonaws.ClientConfiguration)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)2 DescribeScalingActivitiesRequest (com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesRequest)2 DescribeScalingActivitiesResult (com.amazonaws.services.autoscaling.model.DescribeScalingActivitiesResult)2 DetachInstancesRequest (com.amazonaws.services.autoscaling.model.DetachInstancesRequest)2 SuspendProcessesRequest (com.amazonaws.services.autoscaling.model.SuspendProcessesRequest)2 UpdateAutoScalingGroupRequest (com.amazonaws.services.autoscaling.model.UpdateAutoScalingGroupRequest)2 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)2