Search in sources :

Example 56 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testNameValueConstructor.

@Test
public void testNameValueConstructor() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag1", "excludeme");
    String names = "tag1";
    String vals = "excludeme";
    TagValueExclusionRule rule = new TagValueExclusionRule(names.split(","), vals.split(","));
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 57 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testExcludeTaggedResourceWithTagAndValueMatchBoth.

@Test
public void testExcludeTaggedResourceWithTagAndValueMatchBoth() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", "excludeme");
    r1.setTag("tag2", "excludeme2");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 58 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestUntaggedRule method testUntaggedResource.

@Test
public void testUntaggedResource() {
    DateTime now = DateTime.now();
    Resource imageResource = new AWSResource().withId("ami-123123").withResourceType(AWSResourceType.IMAGE);
    Resource asgResource = new AWSResource().withId("my-cool-asg").withResourceType(AWSResourceType.ASG);
    Resource ebsSnapshotResource = new AWSResource().withId("snap-12345678901234567").withResourceType(AWSResourceType.EBS_SNAPSHOT);
    Resource lauchConfigurationResource = new AWSResource().withId("my-cool-launch-configuration").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    Set<String> tags = new HashSet<String>();
    tags.add("tag1");
    tags.add("tag2");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    UntaggedRule rule = new UntaggedRule(new TestMonkeyCalendar(), tags, retentionDaysWithOwner, retentionDaysWithoutOwner);
    Assert.assertFalse(rule.isValid(imageResource));
    Assert.assertFalse(rule.isValid(asgResource));
    Assert.assertFalse(rule.isValid(ebsSnapshotResource));
    Assert.assertFalse(rule.isValid(lauchConfigurationResource));
    TestUtils.verifyTerminationTimeRough(imageResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(asgResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(ebsSnapshotResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(lauchConfigurationResource, retentionDaysWithoutOwner, now);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 59 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOldDetachedVolumeRule method testAttachedVolume.

@Test
public void testAttachedVolume() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("available");
    String metaTag = VolumeTaggingMonkey.makeMetaTag("i-12345678901234567", "owner", null);
    resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
    int retentionDays = 4;
    OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 60 with AWSResource

use of com.netflix.simianarmy.aws.AWSResource in project SimianArmy by Netflix.

the class TestOldDetachedVolumeRule method testTaggedAsNotMark.

@Test
public void testTaggedAsNotMark() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("vol-12345678901234567").withResourceType(AWSResourceType.EBS_VOLUME).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("available");
    Date lastDetachTime = new Date(now.minusDays(ageThreshold + 1).getMillis());
    String metaTag = VolumeTaggingMonkey.makeMetaTag(null, null, lastDetachTime);
    resource.setTag(JanitorMonkey.JANITOR_META_TAG, metaTag);
    int retentionDays = 4;
    OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
    resource.setTag(JanitorMonkey.JANITOR_TAG, "donotmark");
    Assert.assertTrue(rule.isValid(resource));
    Assert.assertNull(resource.getExpectedTerminationTime());
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

AWSResource (com.netflix.simianarmy.aws.AWSResource)109 Resource (com.netflix.simianarmy.Resource)102 Test (org.testng.annotations.Test)89 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)64 DateTime (org.joda.time.DateTime)63 Date (java.util.Date)41 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 BeforeTest (org.testng.annotations.BeforeTest)9 JsonNode (org.codehaus.jackson.JsonNode)7 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)6 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)5 HashSet (java.util.HashSet)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 LinkedList (java.util.LinkedList)4 Tag (com.amazonaws.services.ec2.model.Tag)3 HashMap (java.util.HashMap)3 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)2 LaunchConfiguration (com.amazonaws.services.autoscaling.model.LaunchConfiguration)2 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)1 Instance (com.amazonaws.services.autoscaling.model.Instance)1