Search in sources :

Example 1 with DescribeAutoScalingGroupsResult

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

the class TestAWSClient method mkAsgResult.

private DescribeAutoScalingGroupsResult mkAsgResult(String asgName, String instanceId) {
    DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult();
    AutoScalingGroup asg = new AutoScalingGroup();
    asg.setAutoScalingGroupName(asgName);
    Instance inst = new Instance();
    inst.setInstanceId(instanceId);
    asg.setInstances(Arrays.asList(inst));
    result.setAutoScalingGroups(Arrays.asList(asg));
    return result;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Example 2 with DescribeAutoScalingGroupsResult

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

the class TestAWSClient method testDescribeAutoScalingGroups.

@Test
public void testDescribeAutoScalingGroups() {
    DescribeAutoScalingGroupsResult result1 = mkAsgResult("asg1", "i-123456789012345670");
    result1.setNextToken("nextToken");
    DescribeAutoScalingGroupsResult result2 = mkAsgResult("asg2", "i-123456789012345671");
    when(asgMock.describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class))).thenReturn(result1).thenReturn(result2);
    List<AutoScalingGroup> asgs = this.describeAutoScalingGroups();
    verify(asgMock, times(2)).describeAutoScalingGroups(any(DescribeAutoScalingGroupsRequest.class));
    Assert.assertEquals(asgs.size(), 2);
    // 2 asgs with 1 instance each
    Assert.assertEquals(asgs.get(0).getAutoScalingGroupName(), "asg1");
    Assert.assertEquals(asgs.get(0).getInstances().size(), 1);
    Assert.assertEquals(asgs.get(0).getInstances().get(0).getInstanceId(), "i-123456789012345670");
    Assert.assertEquals(asgs.get(1).getAutoScalingGroupName(), "asg2");
    Assert.assertEquals(asgs.get(1).getInstances().size(), 1);
    Assert.assertEquals(asgs.get(1).getInstances().get(0).getInstanceId(), "i-123456789012345671");
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) DescribeAutoScalingGroupsRequest(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult) Test(org.testng.annotations.Test)

Example 3 with DescribeAutoScalingGroupsResult

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

the class AwsAsgUtil method retrieveAutoScalingGroup.

/**
     * Queries AWS to get the autoscaling information given the asgName.
     *
     * @param asgName
     *            - The name of the ASG.
     * @return - The auto scaling group information.
     */
private AutoScalingGroup retrieveAutoScalingGroup(String asgName) {
    if (Strings.isNullOrEmpty(asgName)) {
        logger.warn("null asgName specified, not attempting to retrieve AutoScalingGroup from AWS");
        return null;
    }
    // You can pass one name or a list of names in the request
    DescribeAutoScalingGroupsRequest request = new DescribeAutoScalingGroupsRequest().withAutoScalingGroupNames(asgName);
    DescribeAutoScalingGroupsResult result = awsClient.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) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Example 4 with DescribeAutoScalingGroupsResult

use of com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult 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

AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)4 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)4 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)3 ClientConfiguration (com.amazonaws.ClientConfiguration)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 AmazonAutoScaling (com.amazonaws.services.autoscaling.AmazonAutoScaling)1 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)1 Instance (com.amazonaws.services.autoscaling.model.Instance)1 Credentials (com.amazonaws.services.securitytoken.model.Credentials)1 Test (org.testng.annotations.Test)1