Search in sources :

Example 11 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project chassis by Kixeye.

the class EurekaConfiguration method eurekaDiscoveryManager.

/***
     * Initializes Eureka Client Library (aka DiscoveryManager)
     *
     * @return discovery manager bean
     */
@Bean(destroyMethod = "shutdownComponent")
public DiscoveryManager eurekaDiscoveryManager(MetadataCollector metadataCollector) {
    final DiscoveryManager bean = DiscoveryManager.getInstance();
    if (!disableEureka) {
        // set eureka.port via http.port if not already set
        int httpPort = ConfigurationManager.getConfigInstance().getInt("http.port", -1);
        int httpsPort = ConfigurationManager.getConfigInstance().getInt("https.port", -1);
        int eurekaPort = ConfigurationManager.getConfigInstance().getInt("eureka.port", -1);
        int eurekaSecurePort = ConfigurationManager.getConfigInstance().getInt("eureka.securePort", -1);
        boolean httpPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("http.enabled", false);
        boolean httpsPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("https.enabled", false);
        if (httpPort != -1 && eurekaPort == -1) {
            ConfigurationManager.getConfigInstance().setProperty("eureka.port", httpPort);
            ConfigurationManager.getConfigInstance().setProperty("eureka.port.enabled", httpPortEnabled);
        }
        if (httpsPort != -1 && eurekaSecurePort == -1) {
            ConfigurationManager.getConfigInstance().setProperty("eureka.securePort", httpsPort);
            ConfigurationManager.getConfigInstance().setProperty("eureka.securePort.enabled", httpsPortEnabled);
        }
        // set eureka.name and eureka.vipAddress with @SpringApp name if not already set
        String appName = ConfigurationManager.getConfigInstance().getString("app.name", null);
        String eurekaName = ConfigurationManager.getConfigInstance().getString("eureka.name", null);
        String eurekaVip = ConfigurationManager.getConfigInstance().getString("eureka.vipAddress", null);
        String eurekaSecureVipAddress = ConfigurationManager.getConfigInstance().getString("eureka.secureVipAddress", null);
        if (appName != null && eurekaName == null) {
            ConfigurationManager.getConfigInstance().setProperty("eureka.name", appName);
        }
        if (appName != null && eurekaVip == null) {
            ConfigurationManager.getConfigInstance().setProperty("eureka.vipAddress", appName);
        }
        if (appName != null && eurekaSecureVipAddress == null) {
            ConfigurationManager.getConfigInstance().setProperty("eureka.secureVipAddress", appName);
        }
        // initialize DiscoveryManager if it hasn't already been done
        if (ApplicationInfoManager.getInstance().getInfo() == null) {
            EurekaInstanceConfig config;
            switch(datacenter.toLowerCase()) {
                case "amazon":
                case "cloud":
                    config = new KixeyeCloudInstanceConfig(metadataCollector);
                    break;
                default:
                    config = new KixeyeMyDataCenterInstanceConfig(metadataCollector);
                    break;
            }
            bean.initComponent(config, new DefaultEurekaClientConfig());
        }
    }
    return bean;
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) DiscoveryManager(com.netflix.discovery.DiscoveryManager) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) Bean(org.springframework.context.annotation.Bean)

Example 12 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.

the class Jersey2EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // has a binding for jersey2
    Assert.assertNotNull(binding);
    TransportClientFactories transportClientFactories = injector.getInstance(TransportClientFactories.class);
    Assert.assertTrue(transportClientFactories instanceof Jersey2TransportClientFactories);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) Jersey2TransportClientFactories(com.netflix.discovery.shared.transport.jersey2.Jersey2TransportClientFactories) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 13 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig 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)

Example 14 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.

the class DiscoveryClientResource method createApplicationManager.

private ApplicationInfoManager createApplicationManager() {
    if (applicationManager == null) {
        EurekaInstanceConfig instanceConfig = new MyDataCenterInstanceConfig(EUREKA_TEST_NAMESPACE) {

            @Override
            public String getAppname() {
                return "discoveryClientTest";
            }

            @Override
            public int getLeaseRenewalIntervalInSeconds() {
                return 1;
            }
        };
        applicationManager = new ApplicationInfoManager(instanceConfig);
    }
    return applicationManager;
}
Also used : EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 15 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project riposte by Nike-Inc.

the class EurekaHandler method createEurekaInstanceConfig.

protected EurekaInstanceConfig createEurekaInstanceConfig() {
    EurekaInstanceConfig eurekaInstanceConfig;
    String datacenterType = datacenterTypePropertySupplier.get();
    DataCenterInfo.Name dcType = DataCenterInfo.Name.MyOwn;
    if (null != datacenterType) {
        try {
            dcType = DataCenterInfo.Name.valueOf(datacenterType);
        } catch (IllegalArgumentException e) {
            logger.warn(String.format("Illegal value %s for eureka datacenter provided in property %s. " + "Ignoring the same and defaulting to %s", datacenterType, EUREKA_DATACENTER_TYPE_PROP_NAME, dcType));
        }
    }
    switch(dcType) {
        case Amazon:
        case // Intentional fall-through
        Netflix:
            eurekaInstanceConfig = createCloudInstanceConfig(eurekaNamespace);
            break;
        default:
            // Every other value is just custom data center.
            eurekaInstanceConfig = new MyDataCenterInstanceConfig(eurekaNamespace);
            break;
    }
    return eurekaInstanceConfig;
}
Also used : EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DataCenterInfo(com.netflix.appinfo.DataCenterInfo)

Aggregations

EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)16 Test (org.junit.Test)8 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)6 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)5 DiscoveryClient (com.netflix.discovery.DiscoveryClient)5 AbstractModule (com.google.inject.AbstractModule)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)4 EurekaClient (com.netflix.discovery.EurekaClient)4 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 LifecycleInjector (com.netflix.governator.LifecycleInjector)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Before (org.junit.Before)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1