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;
}
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");
}
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);
}
}
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);
}
}
Aggregations