use of com.amazonaws.services.autoscaling.model.Instance 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.Instance in project SimianArmy by Netflix.
the class ASGChaosCrawler method groups.
@Override
public List<InstanceGroup> groups(String... names) {
List<InstanceGroup> list = new LinkedList<InstanceGroup>();
for (AutoScalingGroup asg : awsClient.describeAutoScalingGroups(names)) {
InstanceGroup ig = getInstanceGroup(asg, findAggressionCoefficient(asg));
for (Instance inst : asg.getInstances()) {
ig.addInstance(inst.getInstanceId());
}
list.add(ig);
}
return list;
}
use of com.amazonaws.services.autoscaling.model.Instance in project SimianArmy by Netflix.
the class VSphereGroups method addInstance.
/**
* Add the given instance to the named group.
*/
public void addInstance(final String instanceId, final String groupName) {
if (!map.containsKey(groupName)) {
final AutoScalingGroup asg = new AutoScalingGroup();
asg.setAutoScalingGroupName(groupName);
map.put(groupName, asg);
}
final AutoScalingGroup asg = map.get(groupName);
Instance instance = new Instance();
instance.setInstanceId(instanceId);
asg.getInstances().add(instance);
}
use of com.amazonaws.services.autoscaling.model.Instance in project SimianArmy by Netflix.
the class TestVSphereGroups method shouldReturnListContainigSingleASGWhenAddInstanceIsCalledOnce.
@Test
public void shouldReturnListContainigSingleASGWhenAddInstanceIsCalledOnce() {
VSphereGroups groups = new VSphereGroups();
groups.addInstance("anyInstanceId", "anyGroupName");
List<AutoScalingGroup> list = groups.asList();
assertEquals(1, list.size());
AutoScalingGroup firstItem = list.get(0);
assertEquals("anyGroupName", firstItem.getAutoScalingGroupName());
List<Instance> instances = firstItem.getInstances();
assertEquals(1, instances.size());
assertEquals("anyInstanceId", instances.get(0).getInstanceId());
}
use of com.amazonaws.services.autoscaling.model.Instance in project SimianArmy by Netflix.
the class TestAWSClient method mkAsgResult.
private DescribeAutoScalingGroupsResult mkAsgResult(String asgName, String instanceId) {
DescribeAutoScalingGroupsResult result = new DescribeAutoScalingGroupsResult();
AutoScalingGroup asg = new AutoScalingGroup();
asg.setAutoScalingGroupName(asgName);
Instance inst = new Instance();
inst.setInstanceId(instanceId);
asg.setInstances(Arrays.asList(inst));
result.setAutoScalingGroups(Arrays.asList(asg));
return result;
}
Aggregations