Search in sources :

Example 1 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class NonEc2EurekaClientModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
    Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
    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);
    Assert.assertTrue(eurekaInstanceConfig instanceof EurekaArchaius2InstanceConfig);
    ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
    InstanceInfo myInfo = applicationInfoManager.getInfo();
    Assert.assertEquals(DataCenterInfo.Name.MyOwn, myInfo.getDataCenterInfo().getName());
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaArchaius2InstanceConfig(com.netflix.appinfo.EurekaArchaius2InstanceConfig) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) VipAddressResolver(com.netflix.appinfo.providers.VipAddressResolver) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 2 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class Ec2EurekaClientModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
    Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
    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);
    Assert.assertTrue(eurekaInstanceConfig instanceof Ec2EurekaArchaius2InstanceConfig);
    ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
    InstanceInfo myInfo = applicationInfoManager.getInfo();
    Assert.assertTrue(myInfo.getDataCenterInfo() instanceof AmazonInfo);
    Assert.assertEquals(DataCenterInfo.Name.Amazon, myInfo.getDataCenterInfo().getName());
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Ec2EurekaArchaius2InstanceConfig(com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) VipAddressResolver(com.netflix.appinfo.providers.VipAddressResolver) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 3 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class EurekaJacksonCodec method formatKey.

protected static String formatKey(String keyTemplate) {
    EurekaClientConfig clientConfig = DiscoveryManager.getInstance().getEurekaClientConfig();
    String replacement;
    if (clientConfig == null) {
        replacement = "__";
    } else {
        replacement = clientConfig.getEscapeCharReplacement();
    }
    StringBuilder sb = new StringBuilder(keyTemplate.length() + 1);
    for (char c : keyTemplate.toCharArray()) {
        if (c == '_') {
            sb.append(replacement);
        } else {
            sb.append(c);
        }
    }
    return sb.toString();
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig)

Example 4 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class EurekaBootStrap method initEurekaServerContext.

/**
     * init hook for server context. Override for custom logic.
     */
protected void initEurekaServerContext() throws Exception {
    EurekaServerConfig eurekaServerConfig = new DefaultEurekaServerConfig();
    // For backward compatibility
    JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    logger.info("Initializing the eureka client...");
    logger.info(eurekaServerConfig.getJsonCodecName());
    ServerCodecs serverCodecs = new DefaultServerCodecs(eurekaServerConfig);
    ApplicationInfoManager applicationInfoManager = null;
    if (eurekaClient == null) {
        EurekaInstanceConfig instanceConfig = isCloud(ConfigurationManager.getDeploymentContext()) ? new CloudInstanceConfig() : new MyDataCenterInstanceConfig();
        applicationInfoManager = new ApplicationInfoManager(instanceConfig, new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get());
        EurekaClientConfig eurekaClientConfig = new DefaultEurekaClientConfig();
        eurekaClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig);
    } else {
        applicationInfoManager = eurekaClient.getApplicationInfoManager();
    }
    PeerAwareInstanceRegistry registry;
    if (isAws(applicationInfoManager.getInfo())) {
        registry = new AwsInstanceRegistry(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
        awsBinder = new AwsBinderDelegate(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), registry, applicationInfoManager);
        awsBinder.start();
    } else {
        registry = new PeerAwareInstanceRegistryImpl(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
    }
    PeerEurekaNodes peerEurekaNodes = getPeerEurekaNodes(registry, eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, applicationInfoManager);
    serverContext = new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, peerEurekaNodes, applicationInfoManager);
    EurekaServerContextHolder.initialize(serverContext);
    serverContext.initialize();
    logger.info("Initialized server context");
    // Copy registry from neighboring eureka node
    int registryCount = registry.syncUp();
    registry.openForTraffic(applicationInfoManager, registryCount);
    // Register all monitoring statistics.
    EurekaMonitors.registerAllStats();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) PeerAwareInstanceRegistryImpl(com.netflix.eureka.registry.PeerAwareInstanceRegistryImpl) CloudInstanceConfig(com.netflix.appinfo.CloudInstanceConfig) DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaConfigBasedInstanceInfoProvider(com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs) ServerCodecs(com.netflix.eureka.resources.ServerCodecs) PeerAwareInstanceRegistry(com.netflix.eureka.registry.PeerAwareInstanceRegistry) PeerEurekaNodes(com.netflix.eureka.cluster.PeerEurekaNodes) AwsBinderDelegate(com.netflix.eureka.aws.AwsBinderDelegate) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) DiscoveryClient(com.netflix.discovery.DiscoveryClient) AwsInstanceRegistry(com.netflix.eureka.registry.AwsInstanceRegistry) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Example 5 with EurekaClientConfig

use of com.netflix.discovery.EurekaClientConfig in project eureka by Netflix.

the class EurekaModuleTest 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));
    // no bindings so defaulting to default of jersey1
    Assert.assertNull(binding);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Aggregations

EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)9 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)6 DiscoveryClient (com.netflix.discovery.DiscoveryClient)6 InstanceInfo (com.netflix.appinfo.InstanceInfo)5 Test (org.junit.Test)5 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)4 EurekaClient (com.netflix.discovery.EurekaClient)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 PeerEurekaNodes (com.netflix.eureka.cluster.PeerEurekaNodes)2 PeerAwareInstanceRegistry (com.netflix.eureka.registry.PeerAwareInstanceRegistry)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1 EurekaArchaius2InstanceConfig (com.netflix.appinfo.EurekaArchaius2InstanceConfig)1 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)1 EurekaConfigBasedInstanceInfoProvider (com.netflix.appinfo.providers.EurekaConfigBasedInstanceInfoProvider)1 Application (com.netflix.discovery.shared.Application)1