use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.
the class TestOldDetachedVolumeRule method testResourceWithExpectedTerminationTimeSet.
@Test
public void testResourceWithExpectedTerminationTimeSet() {
DateTime now = DateTime.now();
Date oldTermDate = new Date(now.plusDays(10).getMillis());
String oldTermReason = "Foo";
int ageThreshold = 5;
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.setExpectedTerminationTime(oldTermDate);
resource.setTerminationReason(oldTermReason);
Assert.assertFalse(rule.isValid(resource));
Assert.assertEquals(oldTermDate, resource.getExpectedTerminationTime());
Assert.assertEquals(oldTermReason, resource.getTerminationReason());
}
use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.
the class TestJanitorContext method testJanitorWithUnmarking.
@Test
public static void testJanitorWithUnmarking() {
Collection<Resource> crawledResources = new ArrayList<Resource>();
Map<String, Resource> trackedResources = new HashMap<String, Resource>();
int n = 10;
DateTime now = DateTime.now();
Date markTime = new Date(now.minusDays(5).getMillis());
Date notifyTime = new Date(now.minusDays(4).getMillis());
Date terminationTime = new Date(now.minusDays(1).getMillis());
for (Resource r : generateTestingResources(n)) {
if (Integer.parseInt(r.getId()) % 3 == 0) {
trackedResources.put(r.getId(), r);
r.setState(CleanupState.MARKED);
r.setMarkTime(markTime);
r.setExpectedTerminationTime(terminationTime);
r.setNotificationTime(notifyTime);
}
}
for (Resource r : generateTestingResources(n)) {
crawledResources.add(r);
}
TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(trackedResources);
TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
janitor.setLeashed(false);
Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.MARKED, TEST_REGION).size(), n / 3);
janitor.markResources();
// (n/3-n/6) resources were already marked, so in the last run the marked resources
// should be n/2 - n/3 + n/6.
Assert.assertEquals(janitor.getMarkedResources().size(), n / 2 - n / 3 + n / 6);
Assert.assertEquals(janitor.getUnmarkedResources().size(), n / 6);
janitor.cleanupResources();
Assert.assertEquals(janitor.getCleanedResources().size(), n / 2);
Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
Assert.assertEquals(janitor.getUnmarkedResourcesCount(), n / 6);
}
use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.
the class TestJanitorContext method testJanitorWithUnmarkingUserTerminated.
@Test
public static void testJanitorWithUnmarkingUserTerminated() {
Collection<Resource> crawledResources = new ArrayList<Resource>();
Map<String, Resource> trackedResources = new HashMap<String, Resource>();
int n = 10;
DateTime now = DateTime.now();
Date markTime = new Date(now.minusDays(5).getMillis());
Date notifyTime = new Date(now.minusDays(4).getMillis());
Date terminationTime = new Date(now.minusDays(1).getMillis());
for (Resource r : generateTestingResources(n)) {
if (Integer.parseInt(r.getId()) % 3 != 0) {
crawledResources.add(r);
} else {
trackedResources.put(r.getId(), r);
r.setState(CleanupState.MARKED);
r.setMarkTime(markTime);
r.setNotificationTime(notifyTime);
r.setExpectedTerminationTime(terminationTime);
}
}
TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(trackedResources);
TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
janitor.setLeashed(false);
Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n - n / 3);
Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.MARKED, TEST_REGION).size(), n / 3);
janitor.markResources();
// n/3 resources should be considered user terminated
Assert.assertEquals(janitor.getMarkedResources().size(), n / 2 - n / 3 + n / 6);
Assert.assertEquals(janitor.getUnmarkedResources().size(), n / 3);
janitor.cleanupResources();
Assert.assertEquals(janitor.getCleanedResources().size(), n / 2 - n / 3 + n / 6);
Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
Assert.assertEquals(janitor.getUnmarkedResourcesCount(), n / 3);
}
use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.
the class TestJanitorContext method testLeashedJanitorForMarking.
@Test
public static void testLeashedJanitorForMarking() {
Collection<Resource> crawledResources = new ArrayList<Resource>();
int n = 10;
for (Resource r : generateTestingResources(n)) {
crawledResources.add(r);
}
TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(new HashMap<String, Resource>());
TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
janitor.setLeashed(true);
Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
janitor.markResources();
Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), n / 2);
// No resource is really changed in tracker
Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.MARKED, TEST_REGION).size(), 0);
}
use of com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar in project SimianArmy by Netflix.
the class TestJanitorContext method testJanitorWithFutureTerminationTime.
@Test
public static void testJanitorWithFutureTerminationTime() {
Collection<Resource> crawledResources = new ArrayList<Resource>();
Map<String, Resource> trackedResources = new HashMap<String, Resource>();
int n = 10;
DateTime now = DateTime.now();
Date markTime = new Date(now.minusDays(5).getMillis());
Date notifyTime = new Date(now.minusDays(4).getMillis());
Date terminationTime = new Date(now.plusDays(10).getMillis());
for (Resource r : generateTestingResources(n)) {
trackedResources.put(r.getId(), r);
r.setState(CleanupState.MARKED);
r.setNotificationTime(notifyTime);
r.setMarkTime(markTime);
r.setExpectedTerminationTime(terminationTime);
}
for (Resource r : generateTestingResources(n)) {
crawledResources.add(r);
}
TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
TestJanitorResourceTracker resourceTracker = new TestJanitorResourceTracker(trackedResources);
TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
janitor.setLeashed(false);
Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.MARKED, TEST_REGION).size(), n);
janitor.cleanupResources();
Assert.assertEquals(janitor.getCleanedResources().size(), 0);
Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
}
Aggregations