Search in sources :

Example 1 with AutoScalingInstanceDetails

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());
        }
    }
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Example 2 with AutoScalingInstanceDetails

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);
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Example 3 with AutoScalingInstanceDetails

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;
}
Also used : HashMap(java.util.HashMap) Instance(com.amazonaws.services.ec2.model.Instance) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Tag(com.amazonaws.services.ec2.model.Tag) LinkedList(java.util.LinkedList)

Example 4 with AutoScalingInstanceDetails

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());
    }
}
Also used : AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)

Example 5 with AutoScalingInstanceDetails

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);
}
Also used : Instance(com.amazonaws.services.ec2.model.Instance) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AutoScalingInstanceDetails(com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) Test(org.testng.annotations.Test)

Aggregations

AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)6 Instance (com.amazonaws.services.ec2.model.Instance)5 Resource (com.netflix.simianarmy.Resource)5 AWSResource (com.netflix.simianarmy.aws.AWSResource)5 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)5 Test (org.testng.annotations.Test)4 Tag (com.amazonaws.services.ec2.model.Tag)1 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1