Search in sources :

Example 31 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestNoGeneratedAMIRule method testWithAMIs.

@Test
public void testWithAMIs() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("snap-12345678901234567").withResourceType(AWSResourceType.EBS_SNAPSHOT).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("completed");
    resource.setAdditionalField(EBSSnapshotJanitorCrawler.SNAPSHOT_FIELD_AMIS, "ami-123");
    int retentionDays = 4;
    NoGeneratedAMIRule rule = new NoGeneratedAMIRule(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) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 32 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestNoGeneratedAMIRule method testUserSpecifiedTerminationDate.

@Test
public void testUserSpecifiedTerminationDate() {
    int ageThreshold = 5;
    DateTime now = DateTime.now();
    Resource resource = new AWSResource().withId("snap-12345678901234567").withResourceType(AWSResourceType.EBS_SNAPSHOT).withLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    ((AWSResource) resource).setAWSResourceState("completed");
    int retentionDays = 4;
    DateTime userDate = new DateTime(now.plusDays(3).withTimeAtStartOfDay());
    resource.setTag(JanitorMonkey.JANITOR_TAG, NoGeneratedAMIRule.TERMINATION_DATE_FORMATTER.print(userDate));
    NoGeneratedAMIRule rule = new NoGeneratedAMIRule(new TestMonkeyCalendar(), ageThreshold, retentionDays);
    Assert.assertFalse(rule.isValid(resource));
    Assert.assertEquals(resource.getExpectedTerminationTime().getTime(), userDate.getMillis());
}
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) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 33 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.

the class TestOldDetachedVolumeRule method testNullResource.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testNullResource() {
    OldDetachedVolumeRule rule = new OldDetachedVolumeRule(new TestMonkeyCalendar(), 5, 4);
    rule.isValid(null);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) Test(org.testng.annotations.Test)

Example 34 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar 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 35 with TestMonkeyCalendar

use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar 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)

Aggregations

TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)79 Test (org.testng.annotations.Test)79 AWSResource (com.netflix.simianarmy.aws.AWSResource)73 Resource (com.netflix.simianarmy.Resource)64 DateTime (org.joda.time.DateTime)51 Date (java.util.Date)28 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 BasicJanitorRuleEngine (com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine)9 HashSet (java.util.HashSet)5 Calendar (java.util.Calendar)1