Search in sources :

Example 6 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 7 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 8 with AmazonAutoScalingClient

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

the class AwsAsgUtil method retrieveAutoScalingGroupCrossAccount.

private AutoScalingGroup retrieveAutoScalingGroupCrossAccount(String asgAccount, String asgName) {
    logger.debug("Getting cross account ASG for asgName: " + asgName + ", asgAccount: " + asgAccount);
    Credentials credentials = stsCredentials.get(asgAccount);
    if (credentials == null || credentials.getExpiration().getTime() < System.currentTimeMillis() + 1000) {
        stsCredentials.put(asgAccount, initializeStsSession(asgAccount));
        credentials = stsCredentials.get(asgAccount);
    }
    ClientConfiguration clientConfiguration = new ClientConfiguration().withConnectionTimeout(serverConfig.getASGQueryTimeoutMs());
    AmazonAutoScaling autoScalingClient = new AmazonAutoScalingClient(new BasicSessionCredentials(credentials.getAccessKeyId(), credentials.getSecretAccessKey(), credentials.getSessionToken()), clientConfiguration);
    String region = clientConfig.getRegion();
    if (!region.equals("us-east-1")) {
        autoScalingClient.setEndpoint("autoscaling." + region + ".amazonaws.com");
    }
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asgName);
    DescribeAutoScalingGroupsResult result = autoScalingClient.describeAutoScalingGroups(request);
    List<AutoScalingGroup> asgs = result.getAutoScalingGroups();
    if (asgs.isEmpty()) {
        return null;
    } else {
        return asgs.get(0);
    }
}
Also used : DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) AmazonAutoScalingClient(com.amazonaws.services.autoscaling.AmazonAutoScalingClient) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) AmazonAutoScaling(com.amazonaws.services.autoscaling.AmazonAutoScaling) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) Credentials(com.amazonaws.services.securitytoken.model.Credentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)8 ClientConfiguration (com.amazonaws.ClientConfiguration)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)1 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)1 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 NotFoundException (com.netflix.simianarmy.NotFoundException)1