use of com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesWithResourceType.
@Test
public void testInstancesWithResourceType() {
List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
List<Instance> instanceList = createInstanceList();
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
for (AWSResourceType resourceType : AWSResourceType.values()) {
List<Resource> resources = crawler.resources(resourceType);
if (resourceType == AWSResourceType.INSTANCE) {
verifyInstanceList(resources, instanceDetailsList);
} else {
Assert.assertTrue(resources.isEmpty());
}
}
}
use of com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesWithNullIds.
@Test
public void testInstancesWithNullIds() {
List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
List<Instance> instanceList = createInstanceList();
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
List<Resource> resources = crawler.resources();
verifyInstanceList(resources, instanceDetailsList);
}
use of com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails in project SimianArmy by Netflix.
the class InstanceJanitorCrawler method getInstanceResources.
private List<Resource> getInstanceResources(String... instanceIds) {
List<Resource> resources = new LinkedList<Resource>();
AWSClient awsClient = getAWSClient();
Map<String, AutoScalingInstanceDetails> idToASGInstance = new HashMap<String, AutoScalingInstanceDetails>();
for (AutoScalingInstanceDetails instanceDetails : awsClient.describeAutoScalingInstances(instanceIds)) {
idToASGInstance.put(instanceDetails.getInstanceId(), instanceDetails);
}
for (Instance instance : awsClient.describeInstances(instanceIds)) {
Resource instanceResource = new AWSResource().withId(instance.getInstanceId()).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.INSTANCE).withLaunchTime(instance.getLaunchTime());
for (Tag tag : instance.getTags()) {
instanceResource.setTag(tag.getKey(), tag.getValue());
}
String description = String.format("type=%s; host=%s", instance.getInstanceType(), instance.getPublicDnsName() == null ? "" : instance.getPublicDnsName());
instanceResource.setDescription(description);
instanceResource.setOwnerEmail(getOwnerEmailForResource(instanceResource));
String asgName = getAsgName(instanceResource, idToASGInstance);
if (asgName != null) {
instanceResource.setAdditionalField(INSTANCE_FIELD_ASG_NAME, asgName);
LOGGER.info(String.format("instance %s has a ASG tag name %s.", instanceResource.getId(), asgName));
}
String opsworksStackName = getOpsWorksStackName(instanceResource);
if (opsworksStackName != null) {
instanceResource.setAdditionalField(INSTANCE_FIELD_OPSWORKS_STACK_NAME, opsworksStackName);
LOGGER.info(String.format("instance %s is part of an OpsWorks stack named %s.", instanceResource.getId(), opsworksStackName));
}
if (instance.getState() != null) {
((AWSResource) instanceResource).setAWSResourceState(instance.getState().getName());
}
resources.add(instanceResource);
}
return resources;
}
use of com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method verifyInstanceList.
private void verifyInstanceList(List<Resource> resources, List<AutoScalingInstanceDetails> instanceList) {
Assert.assertEquals(resources.size(), instanceList.size());
for (int i = 0; i < resources.size(); i++) {
AutoScalingInstanceDetails instance = instanceList.get(i);
verifyInstance(resources.get(i), instance.getInstanceId(), instance.getAutoScalingGroupName());
}
}
use of com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails in project SimianArmy by Netflix.
the class TestInstanceJanitorCrawler method testInstancesWithIds.
@Test
public void testInstancesWithIds() {
List<AutoScalingInstanceDetails> instanceDetailsList = createInstanceDetailsList();
List<Instance> instanceList = createInstanceList();
String[] ids = { "i-12345678901234560", "i-12345678901234561" };
AWSClient awsMock = createMockAWSClient(instanceDetailsList, instanceList, ids);
InstanceJanitorCrawler crawler = new InstanceJanitorCrawler(awsMock);
List<Resource> resources = crawler.resources(ids);
verifyInstanceList(resources, instanceDetailsList);
}
Aggregations