Search in sources :

Example 1 with EurekaModule

use of com.netflix.discovery.guice.EurekaModule 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 2 with EurekaModule

use of com.netflix.discovery.guice.EurekaModule in project eureka by Netflix.

the class ExampleEurekaGovernatedService method init.

private static LifecycleInjector init() throws Exception {
    System.out.println("Creating injector for Example Service");
    LifecycleInjector injector = InjectorBuilder.fromModules(new EurekaModule(), new ExampleServiceModule()).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();
            bind(DynamicPropertyFactory.class).toInstance(configInstance);
            // the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
            // environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
            bind(EurekaInstanceConfig.class).to(MyDataCenterInstanceConfig.class);
        // (DiscoveryClient optional bindings) bind the optional event bus
        // bind(EventBus.class).to(EventBusImpl.class).in(Scopes.SINGLETON);
        }
    }).createInjector();
    System.out.println("Done creating the injector");
    return injector;
}
Also used : EurekaModule(com.netflix.discovery.guice.EurekaModule) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule)

Aggregations

EurekaModule (com.netflix.discovery.guice.EurekaModule)2 AbstractModule (com.google.inject.AbstractModule)1 Injector (com.google.inject.Injector)1 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)1 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)1 DiscoveryClient (com.netflix.discovery.DiscoveryClient)1 LifecycleInjector (com.netflix.governator.LifecycleInjector)1 UntaggedRule (com.netflix.simianarmy.aws.janitor.rule.generic.UntaggedRule)1