Search in sources :

Example 1 with Instance

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;
}
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 Instance

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;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) LinkedList(java.util.LinkedList) TunableInstanceGroup(com.netflix.simianarmy.tunable.TunableInstanceGroup) BasicInstanceGroup(com.netflix.simianarmy.basic.chaos.BasicInstanceGroup)

Example 3 with Instance

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);
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance)

Example 4 with 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());
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) Test(org.testng.annotations.Test)

Example 5 with Instance

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;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) Instance(com.amazonaws.services.autoscaling.model.Instance) DescribeAutoScalingGroupsResult(com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)

Aggregations

Instance (com.amazonaws.services.autoscaling.model.Instance)10 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)9 DescribeAutoScalingGroupsResult (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsResult)2 SuspendedProcess (com.amazonaws.services.autoscaling.model.SuspendedProcess)2 TagDescription (com.amazonaws.services.autoscaling.model.TagDescription)2 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Test (org.testng.annotations.Test)2 DescribeAutoScalingGroupsRequest (com.amazonaws.services.autoscaling.model.DescribeAutoScalingGroupsRequest)1 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 Cluster (com.netflix.simianarmy.conformity.Cluster)1 TunableInstanceGroup (com.netflix.simianarmy.tunable.TunableInstanceGroup)1 Map (java.util.Map)1