Search in sources :

Example 6 with BasicJanitorRuleEngine

use of com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine in project SimianArmy by Netflix.

the class TestJanitorContext method testJanitorWithoutNotification.

@Test
public static void testJanitorWithoutNotification() {
    Collection<Resource> crawledResources = new ArrayList<Resource>();
    Map<String, Resource> trackedResources = new HashMap<String, Resource>();
    int n = 10;
    for (Resource r : generateTestingResources(n)) {
        trackedResources.put(r.getId(), r);
        r.setState(CleanupState.MARKED);
        // The marking/cleanup is not notified so we the Janitor won't clean it up.
        // r.setNotificationTime(new Date());
        r.setMarkTime(new Date());
        r.setExpectedTerminationTime(new Date(DateTime.now().plusDays(10).getMillis()));
    }
    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);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 7 with BasicJanitorRuleEngine

use of com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine in project SimianArmy by Netflix.

the class TestBasicJanitorMonkeyContext method testAddRuleWithUntaggedRuleResource.

@Test
public void testAddRuleWithUntaggedRuleResource() {
    JanitorRuleEngine ruleEngine = new BasicJanitorRuleEngine();
    Boolean untaggedRuleEnabled = new Boolean(true);
    Rule rule = new UntaggedRule(monkeyCalendar, SIMIANARMY_JANITOR_RULE_UNTAGGEDRULE_REQUIREDTAGS, SIMIANARMY_JANITOR_RULE_UNTAGGEDRULE_RETENTIONDAYSWITHOWNER, SIMIANARMY_JANITOR_RULE_UNTAGGEDRULE_RETENTIONDAYSWITHOUTOWNER);
    if (untaggedRuleEnabled && getUntaggedRuleResourceSet().contains("INSTANCE")) {
        ruleEngine.addRule(rule);
    }
    Assert.assertTrue(ruleEngine.getRules().contains(rule));
}
Also used : UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 8 with BasicJanitorRuleEngine

use of com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine in project SimianArmy by Netflix.

the class TestJanitorContext method testJanitorWithCleanupFailure.

@Test
public static void testJanitorWithCleanupFailure() {
    Collection<Resource> crawledResources = new ArrayList<Resource>();
    int n = 20;
    for (Resource r : generateTestingResources(n)) {
        crawledResources.add(r);
    }
    TestJanitorCrawler crawler = new TestJanitorCrawler(crawledResources);
    TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new IsEvenRule()), crawler, new TestJanitorResourceTracker(new HashMap<String, Resource>()), new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
    janitor.setLeashed(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
    janitor.cleanupResources();
    Assert.assertEquals(janitor.getCleanedResources().size(), n / 2 - 1);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 1);
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 1);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 9 with BasicJanitorRuleEngine

use of com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine in project SimianArmy by Netflix.

the class TestJanitorContext method testJanitor.

@Test
public static void testJanitor() {
    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(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), 0);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n / 2);
    Assert.assertEquals(janitor.markedResourceIds.size(), n / 2);
    for (int i = 1; i <= n; i += 2) {
        Assert.assertTrue(janitor.markedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.cleanedResourceIds.size(), 0);
    janitor.cleanupResources();
    Assert.assertEquals(janitor.getCleanedResources().size(), n / 2);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
    Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.JANITOR_TERMINATED, TEST_REGION).size(), n / 2);
    Assert.assertEquals(janitor.cleanedResourceIds.size(), n / 2);
    for (int i = 1; i <= n; i += 2) {
        Assert.assertTrue(janitor.cleanedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Example 10 with BasicJanitorRuleEngine

use of com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine in project SimianArmy by Netflix.

the class TestJanitorContext method testJanitorWithoutHoldingOffCleanup.

@Test
public static void testJanitorWithoutHoldingOffCleanup() {
    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>());
    DateTime now = DateTime.now();
    TestAbstractJanitor janitor = new TestAbstractJanitor(new TestJanitorContext(TEST_REGION, new BasicJanitorRuleEngine().addRule(new ImmediateCleanupRule(now)), crawler, resourceTracker, new TestMonkeyCalendar()), TestResourceType.TEST_RESOURCE_TYPE);
    janitor.setLeashed(false);
    Assert.assertEquals(crawler.resources(TestResourceType.TEST_RESOURCE_TYPE).size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), 0);
    janitor.markResources();
    Assert.assertEquals(janitor.getMarkedResources().size(), n);
    Assert.assertEquals(janitor.markedResourceIds.size(), n);
    for (int i = 1; i <= n; i++) {
        Assert.assertTrue(janitor.markedResourceIds.contains(String.valueOf(i)));
    }
    Assert.assertEquals(janitor.cleanedResourceIds.size(), 0);
    janitor.cleanupResources();
    // No resource is cleaned since the notification is later than expected termination time.
    Assert.assertEquals(janitor.getCleanedResources().size(), n);
    Assert.assertEquals(janitor.getFailedToCleanResources().size(), 0);
    Assert.assertEquals(resourceTracker.getResources(TestResourceType.TEST_RESOURCE_TYPE, CleanupState.JANITOR_TERMINATED, TEST_REGION).size(), n);
    Assert.assertEquals(janitor.cleanedResourceIds.size(), n);
    Assert.assertEquals(janitor.getResourcesCleanedCount(), janitor.cleanedResourceIds.size());
    Assert.assertEquals(janitor.getMarkedResourcesCount(), janitor.markedResourceIds.size());
    Assert.assertEquals(janitor.getFailedToCleanResourcesCount(), 0);
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) DateTime(org.joda.time.DateTime) TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) BasicJanitorRuleEngine(com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine) Test(org.testng.annotations.Test)

Aggregations

BasicJanitorRuleEngine (com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine)11 Test (org.testng.annotations.Test)11 AWSResource (com.netflix.simianarmy.aws.AWSResource)9 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)9 DateTime (org.joda.time.DateTime)4 UntaggedRule (com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule)2