Search in sources :

Example 6 with MonkeyCalendar

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

the class TestOldUnusedLaunchConfigRule method testUnsedLaunchConfigNotOld.

@Test
public void testUnsedLaunchConfigNotOld() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "false");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold - 1).getMillis()));
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, 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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 7 with MonkeyCalendar

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

the class TestOldUnusedLaunchConfigRule method testResourceWithExpectedTerminationTimeSet.

@Test
public void testResourceWithExpectedTerminationTimeSet() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "false");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    Date oldTermDate = new Date(now.minusDays(10).getMillis());
    String oldTermReason = "Foo";
    resource.setExpectedTerminationTime(oldTermDate);
    resource.setTerminationReason(oldTermReason);
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, ageThreshold, retentionDays);
    Assert.assertFalse(rule.isValid(resource));
    Assert.assertEquals(oldTermDate, resource.getExpectedTerminationTime());
    Assert.assertEquals(oldTermReason, resource.getTerminationReason());
}
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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 8 with MonkeyCalendar

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

the class TestOldUnusedLaunchConfigRule method testUsedLaunchConfigNoLaunchTimeSet.

@Test
public void testUsedLaunchConfigNoLaunchTimeSet() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "true");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, 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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) Test(org.testng.annotations.Test)

Example 9 with MonkeyCalendar

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

the class TestOldUnusedLaunchConfigRule method testOldUnsedLaunchConfig.

@Test
public void testOldUnsedLaunchConfig() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "false");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, ageThreshold, retentionDays);
    Assert.assertFalse(rule.isValid(resource));
    TestUtils.verifyTerminationTimeRough(resource, retentionDays, 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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 10 with MonkeyCalendar

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

the class TestOldUnusedLaunchConfigRule method testUsedLaunchConfig.

@Test
public void testUsedLaunchConfig() {
    Resource resource = new AWSResource().withId("launchConfig1").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    resource.setAdditionalField(LaunchConfigJanitorCrawler.LAUNCH_CONFIG_FIELD_USED_BY_ASG, "true");
    MonkeyCalendar calendar = new TestMonkeyCalendar();
    int ageThreshold = 3;
    DateTime now = new DateTime(calendar.now().getTimeInMillis());
    resource.setLaunchTime(new Date(now.minusDays(ageThreshold + 1).getMillis()));
    int retentionDays = 3;
    OldUnusedLaunchConfigRule rule = new OldUnusedLaunchConfigRule(calendar, 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) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) MonkeyCalendar(com.netflix.simianarmy.MonkeyCalendar) DateTime(org.joda.time.DateTime) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 Resource (com.netflix.simianarmy.Resource)21 AWSResource (com.netflix.simianarmy.aws.AWSResource)21 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)21 Test (org.testng.annotations.Test)21 DateTime (org.joda.time.DateTime)17 Date (java.util.Date)8 Calendar (java.util.Calendar)1