Search in sources :

Example 6 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getASGJanitor.

private ASGJanitor getASGJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    boolean discoveryEnabled = configuration().getBoolOrElse("simianarmy.janitor.Eureka.enabled", false);
    ASGInstanceValidator instanceValidator;
    if (discoveryEnabled) {
        LOGGER.info("Initializing Discovery client.");
        Injector injector = Guice.createInjector(new EurekaModule());
        DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
        instanceValidator = new DiscoveryASGInstanceValidator(discoveryClient);
    } else {
        LOGGER.info("Discovery/Eureka is not enabled, use the dummy instance validator.");
        instanceValidator = new DummyASGInstanceValidator();
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.oldEmptyASGRule.enabled", false)) {
        ruleEngine.addRule(new OldEmptyASGRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldEmptyASGRule.launchConfigAgeThreshold", 50), (int) configuration().getNumOrElse("simianarmy.janitor.rule.oldEmptyASGRule.retentionDays", 10), instanceValidator));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.suspendedASGRule.enabled", false)) {
        ruleEngine.addRule(new SuspendedASGRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.suspendedASGRule.suspensionAgeThreshold", 2), (int) configuration().getNumOrElse("simianarmy.janitor.rule.suspendedASGRule.retentionDays", 5), instanceValidator));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("ASG")) {
        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 EddaASGJanitorCrawler(createEddaClient(), awsClient().region());
    } else {
        crawler = new ASGJanitorCrawler(awsClient());
    }
    BasicJanitorContext asgJanitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, crawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new ASGJanitor(awsClient(), asgJanitorCtx);
}
Also used : EurekaModule(com.netflix.discovery.guice.EurekaModule) UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) Injector(com.google.inject.Injector) DiscoveryClient(com.netflix.discovery.DiscoveryClient)

Example 7 with UntaggedRule

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

the class BasicJanitorMonkeyContext method getEBSSnapshotJanitor.

private EBSSnapshotJanitor getEBSSnapshotJanitor() {
    JanitorRuleEngine ruleEngine = createJanitorRuleEngine();
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.noGeneratedAMIRule.enabled", false)) {
        ruleEngine.addRule(new NoGeneratedAMIRule(monkeyCalendar, (int) configuration().getNumOrElse("simianarmy.janitor.rule.noGeneratedAMIRule.ageThreshold", 30), (int) configuration().getNumOrElse("simianarmy.janitor.rule.noGeneratedAMIRule.retentionDays", 7), configuration().getStrOrElse("simianarmy.janitor.rule.noGeneratedAMIRule.ownerEmail", null)));
    }
    if (configuration().getBoolOrElse("simianarmy.janitor.rule.untaggedRule.enabled", false) && getUntaggedRuleResourceSet().contains("EBS_SNAPSHOT")) {
        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 snapshotCrawler;
    if (configuration().getBoolOrElse("simianarmy.janitor.edda.enabled", false)) {
        snapshotCrawler = new EddaEBSSnapshotJanitorCrawler(configuration().getStr("simianarmy.janitor.snapshots.ownerId"), createEddaClient(), awsClient().region());
    } else {
        snapshotCrawler = new EBSSnapshotJanitorCrawler(awsClient());
    }
    BasicJanitorContext snapshotJanitorCtx = new BasicJanitorContext(monkeyRegion, ruleEngine, snapshotCrawler, janitorResourceTracker, monkeyCalendar, configuration(), recorder());
    return new EBSSnapshotJanitor(awsClient(), snapshotJanitorCtx);
}
Also used : UntaggedRule(com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule) NoGeneratedAMIRule(com.netflix.simianarmy.aws.janitor.rule.snapshot.NoGeneratedAMIRule)

Example 8 with UntaggedRule

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

the class TestBasicJanitorMonkeyContext method testAddRuleWithoutUntaggedRuleResource.

@Test
public void testAddRuleWithoutUntaggedRuleResource() {
    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("ASG")) {
        ruleEngine.addRule(rule);
    }
    Assert.assertFalse(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)

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