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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations