Search in sources :

Example 6 with TagDescription

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

the class TestASGChaosCrawler method testFindAggressionCoefficient_null.

@Test
public void testFindAggressionCoefficient_null() {
    AutoScalingGroup asg1 = mkAsg("asg1", "i-123456789012345670");
    Set<TagDescription> tagDescriptions = new HashSet<>();
    tagDescriptions.add(makeTunableTag(null));
    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 7 with TagDescription

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

the class TestASGChaosCrawler method makeTunableTag.

private TagDescription makeTunableTag(String value) {
    TagDescription desc = new TagDescription();
    desc.setKey("chaosMonkey.aggressionCoefficient");
    desc.setValue(value);
    return desc;
}
Also used : TagDescription(com.amazonaws.services.autoscaling.model.TagDescription)

Example 8 with TagDescription

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

the class TestFilterASGChaosCrawler method testFilterGroups.

@Test
public void testFilterGroups() {
    List<TagDescription> tagList = new ArrayList<TagDescription>();
    TagDescription td = new TagDescription();
    td.setKey(tagKey);
    td.setValue(tagValue);
    tagList.add(td);
    List<InstanceGroup> listGroup = new LinkedList<InstanceGroup>();
    listGroup.add(new BasicInstanceGroup("asg1", Types.ASG, "region1", tagList));
    listGroup.add(new BasicInstanceGroup("asg2", Types.ASG, "region2", Collections.<TagDescription>emptyList()));
    listGroup.add(new BasicInstanceGroup("asg3", Types.ASG, "region3", tagList));
    listGroup.add(new BasicInstanceGroup("asg4", Types.ASG, "region4", Collections.<TagDescription>emptyList()));
    when(crawlerMock.groups()).thenReturn(listGroup);
    List<InstanceGroup> groups = crawlerMock.groups();
    assertEquals(groups.size(), 4);
    groups = crawler.groups();
    assertEquals(groups.size(), 2);
    assertEquals(groups.get(0).name(), "asg1");
    assertEquals(groups.get(1).name(), "asg3");
}
Also used : BasicInstanceGroup(com.netflix.simianarmy.basic.chaos.BasicInstanceGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription) InstanceGroup(com.netflix.simianarmy.chaos.ChaosCrawler.InstanceGroup) BasicInstanceGroup(com.netflix.simianarmy.basic.chaos.BasicInstanceGroup) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 9 with TagDescription

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

Example 10 with TagDescription

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

the class TestASGOwnerEmailTag method makeASG.

private AutoScalingGroup makeASG(String asgName, String ownerEmail) {
    TagDescription tag = new TagDescription().withKey(OWNER_TAG_KEY).withValue(ownerEmail);
    AutoScalingGroup asg = new AutoScalingGroup().withAutoScalingGroupName(asgName).withTags(tag);
    return asg;
}
Also used : AutoScalingGroup(com.amazonaws.services.autoscaling.model.AutoScalingGroup) TagDescription(com.amazonaws.services.autoscaling.model.TagDescription)

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