Search in sources :

Example 1 with SuspendedProcess

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

the class AWSClusterCrawler method clusters.

/**
     * In this implementation, every auto scaling group is considered a cluster.
     * @param clusterNames
     *          the cluster names
     * @return the list of clusters matching the names, when names are empty, return all clusters
     */
@Override
public List<Cluster> clusters(String... clusterNames) {
    List<Cluster> list = Lists.newArrayList();
    for (Map.Entry<String, AWSClient> entry : regionToAwsClient.entrySet()) {
        String region = entry.getKey();
        AWSClient awsClient = entry.getValue();
        Set<String> asgInstances = Sets.newHashSet();
        LOGGER.info(String.format("Crawling clusters in region %s", region));
        for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(clusterNames)) {
            List<String> instances = Lists.newArrayList();
            for (Instance instance : asg.getInstances()) {
                instances.add(instance.getInstanceId());
                asgInstances.add(instance.getInstanceId());
            }
            com.netflix.simianarmy.conformity.AutoScalingGroup conformityAsg = new com.netflix.simianarmy.conformity.AutoScalingGroup(asg.getAutoScalingGroupName(), instances.toArray(new String[instances.size()]));
            for (SuspendedProcess sp : asg.getSuspendedProcesses()) {
                if ("AddToLoadBalancer".equals(sp.getProcessName())) {
                    LOGGER.info(String.format("ASG %s is suspended: %s", asg.getAutoScalingGroupName(), asg.getSuspendedProcesses()));
                    conformityAsg.setSuspended(true);
                }
            }
            Cluster cluster = new Cluster(asg.getAutoScalingGroupName(), region, conformityAsg);
            List<TagDescription> tagDescriptions = asg.getTags();
            for (TagDescription tagDescription : tagDescriptions) {
                if (BasicSimianArmyContext.GLOBAL_OWNER_TAGKEY.equalsIgnoreCase(tagDescription.getKey())) {
                    String value = tagDescription.getValue();
                    if (value != null) {
                        cluster.setOwnerEmail(value);
                    }
                }
            }
            updateCluster(cluster);
            list.add(cluster);
        }
        //Cluster containing all solo instances
        Set<String> instances = Sets.newHashSet();
        for (com.amazonaws.services.ec2.model.Instance awsInstance : awsClient.describeInstances()) {
            if (!asgInstances.contains(awsInstance.getInstanceId())) {
                LOGGER.info(String.format("Adding instance %s to soloInstances cluster.", awsInstance.getInstanceId()));
                instances.add(awsInstance.getInstanceId());
            }
        }
        //Only create cluster if we have solo instances.
        if (!instances.isEmpty()) {
            Cluster cluster = new Cluster("SoloInstances", region, instances);
            updateCluster(cluster);
            list.add(cluster);
        }
    }
    return list;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) Cluster(com.netflix.simianarmy.conformity.Cluster) AWSClient(com.netflix.simianarmy.client.aws.AWSClient) SuspendedProcess(com.amazonaws.services.autoscaling.model.SuspendedProcess) Map(java.util.Map)

Example 2 with SuspendedProcess

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

the class TestASGJanitorCrawler method mkASG.

private AutoScalingGroup mkASG(String asgName) {
    AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(asgName);
    // set the suspended processes
    List<SuspendedProcess> sps = new ArrayList<SuspendedProcess>();
    sps.add(new SuspendedProcess().withProcessName("Launch").withSuspensionReason("User suspended at 2012-12-02T23:00:03"));
    sps.add(new SuspendedProcess().withProcessName("AddToLoadBalancer").withSuspensionReason("User suspended at 2012-12-03T23:00:03"));
    asg.setSuspendedProcesses(sps);
    return asg;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) ArrayList(java.util.ArrayList) SuspendedProcess(com.amazonaws.services.autoscaling.model.SuspendedProcess)

Example 3 with SuspendedProcess

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

Aggregations

AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)3 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)3 Instance (com.amazonaws.services.autoscaling.model.Instance)2 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 ArrayList (java.util.ArrayList)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)1 Resource (com.netflix.simianarmy.Resource)1 AWSResource (com.netflix.simianarmy.aws.AWSResource)1 Cluster (com.netflix.simianarmy.conformity.Cluster)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1