Search in sources :

Example 61 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOldDetachedVolumeRule method testDetachedVolumeNotOld.

@Test
public void testDetachedVolumeNotOld() {
    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);
    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 62 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOldDetachedVolumeRule method testNonVolumeResource.

@Test
public void testNonVolumeResource() {
    Resource resource = new AWSResource().withId("asg1").withResourceType(AWSResourceType.ASG);
    ((AWSResource) resource).setAWSResourceState("available");
    OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), 0, 0);
    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) Test(org.testng.annotations.Test)

Example 63 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestOrphanedELBRule method testMissingCountsCheckWithExtraFields.

@Test
public void testMissingCountsCheckWithExtraFields() {
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("test-elb").withResourceType(AWSResourceType.ELB).withOwnerEmail("owner@foo.com");
    resource.setAdditionalField("bogusField1", "0");
    resource.setAdditionalField("bogusField2", "0");
    OrphanedELBRule rule = new OrphanedELBRule(new TestMonkeyCalendar(), 7);
    Assert.assertTrue(rule.isValid(resource));
}
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) Test(org.testng.annotations.Test)

Example 64 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testExcludeTaggedResourceTagMatchOnly.

@Test
public void testExcludeTaggedResourceTagMatchOnly() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", "somethingelse");
    r1.setTag("tag2", "somethingelse2");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertFalse(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 65 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testNameValueConstructor2.

@Test
public void testNameValueConstructor2() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag1", "excludeme");
    String names = "tag1,tag2";
    String vals = "excludeme,excludeme2";
    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)

Aggregations

Resource (com.netflix.simianarmy.Resource)145 AWSResource (com.netflix.simianarmy.aws.AWSResource)132 Test (org.testng.annotations.Test)110 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)64 DateTime (org.joda.time.DateTime)60 Date (java.util.Date)45 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)18 JsonNode (org.codehaus.jackson.JsonNode)17 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)11 BeforeTest (org.testng.annotations.BeforeTest)9 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)8 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)6 HashSet (java.util.HashSet)6 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)5 Instance (com.amazonaws.services.ec2.model.Instance)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 Snapshot (com.amazonaws.services.ec2.model.Snapshot)4