Search in sources :

Example 1 with LaunchConfiguration

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

the class LaunchConfigJanitorCrawler method getLaunchConfigResources.

private List<Resource> getLaunchConfigResources(String... launchConfigNames) {
    List<Resource> resources = Lists.newArrayList();
    AWSClient awsClient = getAWSClient();
    Set<String> usedLCs = Sets.newHashSet();
    for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups()) {
        usedLCs.add(asg.getLaunchConfigurationName());
    }
    for (LaunchConfiguration launchConfiguration : awsClient.describeLaunchConfigurations(launchConfigNames)) {
        String lcName = launchConfiguration.getLaunchConfigurationName();
        Resource lcResource = new AWSResource().withId(lcName).withRegion(getAWSClient().region()).withResourceType(AWSResourceType.LAUNCH_CONFIG).withLaunchTime(launchConfiguration.getCreatedTime());
        lcResource.setOwnerEmail(getOwnerEmailForResource(lcResource));
        lcResource.setAdditionalField(LAUNCH_CONFIG_FIELD_USED_BY_ASG, String.valueOf(usedLCs.contains(lcName)));
        resources.add(lcResource);
    }
    return resources;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) LaunchConfiguration(com.amazonaws.services.autoscaling.model.LaunchConfiguration) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSClient(com.netflix.simianarmy.client.aws.AWSClient)

Example 2 with LaunchConfiguration

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

the class ASGJanitorCrawler method getASGResources.

private List<Resource> getASGResources(String... asgNames) {
    AWSClient awsClient = getAWSClient();
    List<LaunchConfiguration> launchConfigurations = awsClient.describeLaunchConfigurations();
    for (LaunchConfiguration lc : launchConfigurations) {
        nameToLaunchConfig.put(lc.getLaunchConfigurationName(), lc);
    }
    List<Resource> resources = new LinkedList<Resource>();
    for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(asgNames)) {
        Resource asgResource = new AWSResource().withId(asg.getAutoScalingGroupName()).withResourceType(AWSResourceType.ASG).withRegion(awsClient.region()).withLaunchTime(asg.getCreatedTime());
        for (TagDescription tag : asg.getTags()) {
            asgResource.setTag(tag.getKey(), tag.getValue());
        }
        asgResource.setDescription(String.format("%d instances", asg.getInstances().size()));
        asgResource.setOwnerEmail(getOwnerEmailForResource(asgResource));
        if (asg.getStatus() != null) {
            ((AWSResource) asgResource).setAWSResourceState(asg.getStatus());
        }
        Integer maxSize = asg.getMaxSize();
        if (maxSize != null) {
            asgResource.setAdditionalField(ASG_FIELD_MAX_SIZE, String.valueOf(maxSize));
        }
        // Adds instances and ELBs as additional fields.
        List<String> instances = new ArrayList<String>();
        for (Instance instance : asg.getInstances()) {
            instances.add(instance.getInstanceId());
        }
        asgResource.setAdditionalField(ASG_FIELD_INSTANCES, StringUtils.join(instances, ","));
        asgResource.setAdditionalField(ASG_FIELD_ELBS, StringUtils.join(asg.getLoadBalancerNames(), ","));
        String lcName = asg.getLaunchConfigurationName();
        LaunchConfiguration lc = nameToLaunchConfig.get(lcName);
        if (lc != null) {
            asgResource.setAdditionalField(ASG_FIELD_LC_NAME, lcName);
        }
        if (lc != null && lc.getCreatedTime() != null) {
            asgResource.setAdditionalField(ASG_FIELD_LC_CREATION_TIME, String.valueOf(lc.getCreatedTime().getTime()));
        }
        // sets the field for the time when the ASG's traffic is suspended from ELB
        for (SuspendedProcess sp : asg.getSuspendedProcesses()) {
            if ("AddToLoadBalancer".equals(sp.getProcessName())) {
                String suspensionTime = getSuspensionTimeString(sp.getSuspensionReason());
                if (suspensionTime != null) {
                    LOGGER.info(String.format("Suspension time of ASG %s is %s", asg.getAutoScalingGroupName(), suspensionTime));
                    asgResource.setAdditionalField(ASG_FIELD_SUSPENSION_TIME, suspensionTime);
                    break;
                }
            }
        }
        resources.add(asgResource);
    }
    return resources;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) ArrayList(java.util.ArrayList) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) LinkedList(java.util.LinkedList) LaunchConfiguration(com.amazonaws.services.autoscaling.model.LaunchConfiguration) AWSResource(com.netflix.simianarmy.aws.AWSResource) SuspendedProcess(com.amazonaws.services.autoscaling.model.SuspendedProcess)

Example 3 with LaunchConfiguration

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

the class TestLaunchConfigJanitorCrawler method testInstancesWithResourceType.

@Test
public void testInstancesWithResourceType() {
    int n = 2;
    List<LaunchConfiguration> lcList = createLaunchConfigList(n);
    LaunchConfigJanitorCrawler crawler = new LaunchConfigJanitorCrawler(createMockAWSClient(createASGList(n), lcList));
    for (AWSResourceType resourceType : AWSResourceType.values()) {
        List<Resource> resources = crawler.resources(resourceType);
        if (resourceType == AWSResourceType.LAUNCH_CONFIG) {
            verifyLaunchConfigList(resources, lcList);
        } else {
            Assert.assertTrue(resources.isEmpty());
        }
    }
}
Also used : LaunchConfiguration(com.amazonaws.services.autoscaling.model.LaunchConfiguration) AWSResourceType(com.netflix.simianarmy.aws.AWSResourceType) Resource(com.netflix.simianarmy.Resource) Test(org.testng.annotations.Test)

Aggregations

LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)3 Resource (com.netflix.simianarmy.Resource)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 AWSResource (com.netflix.simianarmy.aws.AWSResource)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 Instance (com.amazonaws.services.autoscaling.model.Instance)1 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)1 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)1 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Test (org.testng.annotations.Test)1