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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations