Search in sources :

Example 1 with TagDescription

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

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

the class ASGChaosCrawler method findAggressionCoefficient.

/**
     * Reads tags on AutoScalingGroup looking for the tag for the aggression coefficient 
     * and determines the coefficient value. The default value is 1 if there no tag or 
     * if the value in the tag is not a parsable number.
     * 
     * @param asg The AutoScalingGroup that might have an aggression coefficient tag
     * @return The set or default aggression coefficient.
     */
protected double findAggressionCoefficient(AutoScalingGroup asg) {
    List<TagDescription> tagDescriptions = asg.getTags();
    double aggression = 1.0;
    for (TagDescription tagDescription : tagDescriptions) {
        if (CHAOS_MONKEY_AGGRESSION_COEFFICIENT_KEY.equalsIgnoreCase(tagDescription.getKey())) {
            String value = tagDescription.getValue();
            // prevent NPE on parseDouble
            if (value == null) {
                break;
            }
            try {
                aggression = Double.parseDouble(value);
                LOGGER.info("Aggression coefficient of {} found for ASG {}", value, asg.getAutoScalingGroupName());
            } catch (NumberFormatException e) {
                LOGGER.warn("Unparsable value of {} found in tag {} for ASG {}", value, CHAOS_MONKEY_AGGRESSION_COEFFICIENT_KEY, asg.getAutoScalingGroupName());
                aggression = 1.0;
            }
            // stop looking
            break;
        }
    }
    return aggression;
}
Also used : TagDescription(com.amazonaws.services.autoscaling.model.TagDescription)

Example 3 with TagDescription

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

the class TestASGChaosCrawler method testFindAggressionCoefficient_unparsable.

@Test
public void testFindAggressionCoefficient_unparsable() {
    AutoScalingGroup asg1 = mkAsg("asg1", "i-123456789012345670");
    Set<TagDescription> tagDescriptions = new HashSet<>();
    tagDescriptions.add(makeTunableTag("not a number"));
    asg1.setTags(tagDescriptions);
    double aggression = crawler.findAggressionCoefficient(asg1);
    Assert.assertEquals(aggression, 1.0);
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with TagDescription

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

the class TestASGChaosCrawler method testFindAggressionCoefficient.

@Test
public void testFindAggressionCoefficient() {
    AutoScalingGroup asg1 = mkAsg("asg1", "i-123456789012345670");
    Set<TagDescription> tagDescriptions = new HashSet<>();
    tagDescriptions.add(makeTunableTag("1.0"));
    asg1.setTags(tagDescriptions);
    double aggression = crawler.findAggressionCoefficient(asg1);
    Assert.assertEquals(aggression, 1.0);
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with TagDescription

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

the class TestASGChaosCrawler method testFindAggressionCoefficient_two.

@Test
public void testFindAggressionCoefficient_two() {
    AutoScalingGroup asg1 = mkAsg("asg1", "i-123456789012345670");
    Set<TagDescription> tagDescriptions = new HashSet<>();
    tagDescriptions.add(makeTunableTag("2.0"));
    asg1.setTags(tagDescriptions);
    double aggression = crawler.findAggressionCoefficient(asg1);
    Assert.assertEquals(aggression, 2.0);
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)10 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)7 Test (org.testng.annotations.Test)5 HashSet (java.util.HashSet)4 Instance (com.amazonaws.services.autoscaling.model.Instance)2 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)1 Resource (com.netflix.simianarmy.Resource)1 AWSResource (com.netflix.simianarmy.aws.AWSResource)1 BasicInstanceGroup (com.netflix.simianarmy.basic.chaos.BasicInstanceGroup)1 InstanceGroup (com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup)1 Cluster (com.netflix.simianarmy.conformity.Cluster)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 BeforeTest (org.testng.annotations.BeforeTest)1