Search in sources :

Example 1 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getInstanceJanitor.

private InstanceJanitor getInstanceJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.orphanedInstanceRule.enabled", false)) {
        ruleEngine.addRule(new OrphanedInstanceRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.orphanedInstanceRule.instanceAgeThreshold", 2), (int) configuration().getNumOrElse("simianarmy.janitor.rule.orphanedInstanceRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.orphanedInstanceRule.retentionDaysWithoutOwner", 8), configuration().getBoolOrElse("simianarmy.janitor.rule.orphanedInstanceRule.opsworks.parentage", false)));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("INSTANCE")) {
        ruleEngine.addRule(new UntaggedRule(monkeyCalendar, getPropertySet("simianarmy.janitor.rule.untaggedRule.requiredTags"), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithoutOwner", 8)));
    }
    JanitorCrawler instanceCrawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        instanceCrawler = new EddaInstanceJanitorCrawler(createEddaClient(), awsClient().region());
    } else {
        instanceCrawler = new InstanceJanitorCrawler(awsClient());
    }
    BasicJanitorContext instanceJanitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, instanceCrawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new InstanceJanitor(awsClient(), instanceJanitorCtx);
}
Also used : UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) OrphanedInstanceRule(com.netflix.simianarmy.aws.janitor.rule.instance.OrphanedInstanceRule)

Example 2 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getEBSVolumeJanitor.

private EBSVolumeJanitor getEBSVolumeJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.oldDetachedVolumeRule.enabled", false)) {
        ruleEngine.addRule(new OldDetachedVolumeRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldDetachedVolumeRule.detachDaysThreshold", 30), (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldDetachedVolumeRule.retentionDays", 7)));
        if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false) && configuration().getBoolOrElse("simianarmy.janitor.rule.deleteOnTerminationRule.enabled", false)) {
            ruleEngine.addRule(new DeleteOnTerminationRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.deleteOnTerminationRule.retentionDays", 3)));
        }
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("EBS_VOLUME")) {
        ruleEngine.addRule(new UntaggedRule(monkeyCalendar, getPropertySet("simianarmy.janitor.rule.untaggedRule.requiredTags"), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithoutOwner", 8)));
    }
    JanitorCrawler volumeCrawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        volumeCrawler = new EddaEBSVolumeJanitorCrawler(createEddaClient(), awsClient().region());
    } else {
        volumeCrawler = new EBSVolumeJanitorCrawler(awsClient());
    }
    BasicJanitorContext volumeJanitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, volumeCrawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new EBSVolumeJanitor(awsClient(), volumeJanitorCtx);
}
Also used : DeleteOnTerminationRule(com.netflix.simianarmy.aws.janitor.rule.volume.DeleteOnTerminationRule) UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) OldDetachedVolumeRule(com.netflix.simianarmy.aws.janitor.rule.volume.OldDetachedVolumeRule)

Example 3 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getImageJanitor.

private ImageJanitor getImageJanitor() {
    JanitorCrawler crawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        crawler = new EddaImageJanitorCrawler(createEddaClient(), configuration().getStr("simianarmy.janitor.image.ownerId"), (int) configuration().getNumOrElse("simianarmy.janitor.image.crawler.lookBackDays", 60), awsClient().region());
    } else {
        throw new RuntimeException("Image Janitor only works when Edda is enabled.");
    }
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.unusedImageRule.enabled", false)) {
        ruleEngine.addRule(new UnusedImageRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.unusedImageRule.retentionDays", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.unusedImageRule.lastReferenceDaysThreshold", 45)));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("IMAGE")) {
        ruleEngine.addRule(new UntaggedRule(monkeyCalendar, getPropertySet("simianarmy.janitor.rule.untaggedRule.requiredTags"), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithoutOwner", 8)));
    }
    BasicJanitorContext janitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, crawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new ImageJanitor(awsClient(), janitorCtx);
}
Also used : UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) UnusedImageRule(com.netflix.simianarmy.aws.janitor.rule.ami.UnusedImageRule)

Example 4 with UntaggedRule

use of com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule 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 5 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getLaunchConfigJanitor.

private LaunchConfigJanitor getLaunchConfigJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.oldUnusedLaunchConfigRule.enabled", false)) {
        ruleEngine.addRule(new OldUnusedLaunchConfigRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldUnusedLaunchConfigRule.ageThreshold", 4), (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldUnusedLaunchConfigRule.retentionDays", 3)));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("LAUNCH_CONFIG")) {
        ruleEngine.addRule(new UntaggedRule(monkeyCalendar, getPropertySet("simianarmy.janitor.rule.untaggedRule.requiredTags"), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithOwner", 3), (int) configuration().getNumOrElse("simianarmy.janitor.rule.untaggedRule.retentionDaysWithoutOwner", 8)));
    }
    JanitorCrawler crawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        crawler = new EddaLaunchConfigJanitorCrawler(createEddaClient(), awsClient().region());
    } else {
        crawler = new LaunchConfigJanitorCrawler(awsClient());
    }
    BasicJanitorContext janitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, crawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new LaunchConfigJanitor(awsClient(), janitorCtx);
}
Also used : UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) OldUnusedLaunchConfigRule(com.netflix.simianarmy.aws.janitor.rule.launchconfig.OldUnusedLaunchConfigRule)

Aggregations

UntaggedRule (com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule)8 BasicJanitorRuleEngine (com.netflix.simianarmy.basic.janitor.BasicJanitorRuleEngine)2 Test (org.testng.annotations.Test)2 Injector (com.google.inject.Injector)1 DiscoveryClient (com.netflix.discovery.DiscoveryClient)1 EurekaModule (com.netflix.discovery.guice.EurekaModule)1 UnusedImageRule (com.netflix.simianarmy.aws.janitor.rule.ami.UnusedImageRule)1 OrphanedInstanceRule (com.netflix.simianarmy.aws.janitor.rule.instance.OrphanedInstanceRule)1 OldUnusedLaunchConfigRule (com.netflix.simianarmy.aws.janitor.rule.launchconfig.OldUnusedLaunchConfigRule)1 NoGeneratedAMIRule (com.netflix.simianarmy.aws.janitor.rule.snapshot.NoGeneratedAMIRule)1 DeleteOnTerminationRule (com.netflix.simianarmy.aws.janitor.rule.volume.DeleteOnTerminationRule)1 OldDetachedVolumeRule (com.netflix.simianarmy.aws.janitor.rule.volume.OldDetachedVolumeRule)1