com.netflix.discovery.EurekaClientConfig Java Examples

The following examples show how to use com.netflix.discovery.EurekaClientConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EurekaHandlerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    eurekaIsDisabledPropertySupplierMock = mock(Supplier.class);
    datacenterTypePropertySupplierMock = mock(Supplier.class);
    cloudInstanceConfigMock = mock(CloudInstanceConfig.class);

    doReturn(false).when(eurekaIsDisabledPropertySupplierMock).get();
    doReturn(MyOwn.name()).when(datacenterTypePropertySupplierMock).get();

    handlerSpy = spy(new EurekaHandler(eurekaIsDisabledPropertySupplierMock, datacenterTypePropertySupplierMock));

    doNothing().when(handlerSpy).initDiscoveryManager(any(EurekaInstanceConfig.class),
                                                      any(EurekaClientConfig.class));
    doNothing().when(handlerSpy).shutdownDiscoveryManager();
    doNothing().when(handlerSpy).setEurekaInstanceStatus(any(InstanceStatus.class));
    doReturn(cloudInstanceConfigMock).when(handlerSpy).createCloudInstanceConfig(anyString());
}
 
Example #2
Source File: EurekaHandlerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP() {
    // given
    EurekaInstanceConfig instanceConfigMock = mock(EurekaInstanceConfig.class);
    doReturn(instanceConfigMock).when(handlerSpy).createEurekaInstanceConfig();
    assertThat(handlerSpy.registered.get()).isFalse();

    // when
    handlerSpy.register();

    // then
    assertThat(handlerSpy.registered.get()).isTrue();
    verify(handlerSpy).createEurekaInstanceConfig();

    ArgumentCaptor<EurekaClientConfig> clientConfigCaptor = ArgumentCaptor.forClass(EurekaClientConfig.class);
    verify(handlerSpy).initDiscoveryManager(eq(instanceConfigMock),
                                            clientConfigCaptor.capture());
    EurekaClientConfig clientConfigUsed = clientConfigCaptor.getValue();
    assertThat(clientConfigUsed).isInstanceOf(DefaultEurekaClientConfig.class);
    assertThat(Whitebox.getInternalState(clientConfigUsed, "namespace")).isEqualTo(handlerSpy.eurekaClientNamespace);

    verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP);
}
 
Example #3
Source File: DiscoveryClientConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@RefreshScope
public ApimlDiscoveryClient eurekaClient(ApplicationInfoManager manager,
                                         EurekaClientConfig config,
                                         EurekaInstanceConfig instance,
                                         @Autowired(required = false) HealthCheckHandler healthCheckHandler
) {
    ApplicationInfoManager appManager;
    if (AopUtils.isAopProxy(manager)) {
        appManager = ProxyUtils.getTargetObject(manager);
    } else {
        appManager = manager;
    }
    final ApimlDiscoveryClient discoveryClientClient = new ApimlDiscoveryClient(appManager, config, this.optionalArgs, this.context);
    discoveryClientClient.registerHealthCheck(healthCheckHandler);

    discoveryClientClient.registerEventListener(event -> {
        if (event instanceof CacheRefreshedEvent) {
            refreshableRouteLocators.forEach(RefreshableRouteLocator::refresh);
            zuulHandlerMapping.setDirty(true);
        }
    });
    return discoveryClientClient;
}
 
Example #4
Source File: DiscoveryClientTestConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@RefreshScope
public ApimlDiscoveryClientStub eurekaClient(ApplicationInfoManager manager,
                                             EurekaClientConfig config,
                                             EurekaInstanceConfig instance,
                                             @Autowired(required = false) HealthCheckHandler healthCheckHandler,
                                             ApplicationRegistry applicationRegistry
) {
    ApplicationInfoManager appManager;
    if (AopUtils.isAopProxy(manager)) {
        appManager = ProxyUtils.getTargetObject(manager);
    } else {
        appManager = manager;
    }

    final ApimlDiscoveryClientStub discoveryClient = new ApimlDiscoveryClientStub(appManager, config, this.optionalArgs, this.context, applicationRegistry);
    discoveryClient.registerHealthCheck(healthCheckHandler);

    discoveryClient.registerEventListener(event -> {
        if (event instanceof CacheRefreshedEvent) {
            refreshableRouteLocators.forEach(RefreshableRouteLocator::refresh);
            zuulHandlerMapping.setDirty(true);
        }
    });
    return discoveryClient;
}
 
Example #5
Source File: EurekaClientAutoConfigurationTests.java    From spring-cloud-netflix with Apache License 2.0 6 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class,
		search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager,
		EurekaClientConfig config, ApplicationContext context) {
	return new CloudEurekaClient(manager, config, null, context) {
		@Override
		public synchronized void shutdown() {
			CountDownLatch latch = countDownLatch();
			if (latch.getCount() == 1) {
				latch.countDown();
			}
			super.shutdown();
		}
	};
}
 
Example #6
Source File: ApiMediationClientImplTest.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Test
// It just tests that the https base configuration won't throw any exception.
public void httpsBaseUrlFormat() throws ServiceDefinitionException {
    ApiMediationServiceConfigReader apiMediationServiceConfigReader = new ApiMediationServiceConfigReader();

    ApiMediationServiceConfig config = apiMediationServiceConfigReader.buildConfiguration("/https-service-configuration.yml");

    EurekaClientProvider clientProvider = Mockito.mock(EurekaClientProvider.class);
    EurekaInstanceConfigCreator instanceConfigCreator = new EurekaInstanceConfigCreator();

    EurekaClientConfig clientConfig = new EurekaClientConfiguration(config);
    EurekaClientConfigProvider eurekaClientConfigProvider = Mockito.mock(ApiMlEurekaClientConfigProvider.class);
    when(eurekaClientConfigProvider.config(config)).thenReturn(clientConfig);

    ApiMediationClient client = new ApiMediationClientImpl(clientProvider, eurekaClientConfigProvider, instanceConfigCreator);

    client.register(config);

    verify(clientProvider).client(any(), any(), any());
}
 
Example #7
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
RefreshablePeerEurekaNodes(final PeerAwareInstanceRegistry registry,
		final EurekaServerConfig serverConfig,
		final EurekaClientConfig clientConfig, final ServerCodecs serverCodecs,
		final ApplicationInfoManager applicationInfoManager,
		final ReplicationClientAdditionalFilters replicationClientAdditionalFilters) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
	this.replicationClientAdditionalFilters = replicationClientAdditionalFilters;
}
 
Example #8
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnEnabledHealthIndicator("eureka")
public EurekaHealthIndicator eurekaHealthIndicator(EurekaClient eurekaClient,
		EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
	return new EurekaHealthIndicator(eurekaClient, instanceConfig, clientConfig);
}
 
Example #9
Source File: EurekaHandlerTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Test
public void register_does_nothing_if_eureka_is_disabled() {
    // given
    doReturn(true).when(eurekaIsDisabledPropertySupplierMock).get();

    // when
    handlerSpy.register();

    // then
    verify(handlerSpy, never()).createEurekaInstanceConfig();
    verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class),
                                                     any(EurekaClientConfig.class));
    verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class));
}
 
Example #10
Source File: EurekaHandlerTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Test
public void register_does_nothing_if_already_registered() {
    // given
    handlerSpy.registered.set(true);

    // when
    handlerSpy.register();

    // then
    verify(handlerSpy, never()).createEurekaInstanceConfig();
    verify(handlerSpy, never()).initDiscoveryManager(any(EurekaInstanceConfig.class),
                                                     any(EurekaClientConfig.class));
    verify(handlerSpy, never()).setEurekaInstanceStatus(any(InstanceStatus.class));
}
 
Example #11
Source File: EurekaClientAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean(value = EurekaClient.class,
		search = SearchStrategy.CURRENT)
public EurekaClient eurekaClient(ApplicationInfoManager manager,
		EurekaClientConfig config) {
	return new CloudEurekaClient(manager, config, this.optionalArgs,
			this.context);
}
 
Example #12
Source File: EurekaComponents.java    From kork with Apache License 2.0 5 votes vote down vote up
@Bean
@Deprecated // prefer to use EurekaClient interface rather than directly depending on
// DiscoveryClient
public DiscoveryClient discoveryClient(
    ApplicationInfoManager applicationInfoManager,
    EurekaClientConfig eurekaClientConfig,
    DiscoveryClient.DiscoveryClientOptionalArgs optionalArgs) {
  return new DiscoveryClient(applicationInfoManager, eurekaClientConfig, optionalArgs);
}
 
Example #13
Source File: EurekaServerBootstrap.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public EurekaServerBootstrap(ApplicationInfoManager applicationInfoManager,
		EurekaClientConfig eurekaClientConfig, EurekaServerConfig eurekaServerConfig,
		PeerAwareInstanceRegistry registry, EurekaServerContext serverContext) {
	this.applicationInfoManager = applicationInfoManager;
	this.eurekaClientConfig = eurekaClientConfig;
	this.eurekaServerConfig = eurekaServerConfig;
	this.registry = registry;
	this.serverContext = serverContext;
}
 
Example #14
Source File: InstanceRegistry.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public InstanceRegistry(EurekaServerConfig serverConfig,
		EurekaClientConfig clientConfig, ServerCodecs serverCodecs,
		EurekaClient eurekaClient, int expectedNumberOfClientsSendingRenews,
		int defaultOpenForTrafficCount) {
	super(serverConfig, clientConfig, serverCodecs, eurekaClient);

	this.expectedNumberOfClientsSendingRenews = expectedNumberOfClientsSendingRenews;
	this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
}
 
Example #15
Source File: EurekaServerAutoConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public EurekaServerConfig eurekaServerConfig(EurekaClientConfig clientConfig) {
	EurekaServerConfigBean server = new EurekaServerConfigBean();
	if (clientConfig.shouldRegisterWithEureka()) {
		// Set a sensible default if we are supposed to replicate
		server.setRegistrySyncRetries(5);
	}
	return server;
}
 
Example #16
Source File: DiscoveryServerConfig.java    From mPaaS with Apache License 2.0 5 votes vote down vote up
public CustomRefreshablePeerEurekaNodes(
        final PeerAwareInstanceRegistry registry,
        final EurekaServerConfig serverConfig,
        final EurekaClientConfig clientConfig,
        final ServerCodecs serverCodecs,
        final ApplicationInfoManager applicationInfoManager) {
    super(registry, serverConfig, clientConfig, serverCodecs, applicationInfoManager);
}
 
Example #17
Source File: EurekaCustomPeerNodesTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public PeerEurekaNodes myPeerEurekaNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig eurekaServerConfig,
		EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	return new CustomEurekaPeerNodes(registry, eurekaServerConfig,
			eurekaClientConfig, serverCodecs, applicationInfoManager);
}
 
Example #18
Source File: EurekaCustomPeerNodesTests.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
		ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
}
 
Example #19
Source File: EurekaHealthIndicator.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public EurekaHealthIndicator(EurekaClient eurekaClient,
		EurekaInstanceConfig instanceConfig, EurekaClientConfig clientConfig) {
	super();
	this.eurekaClient = eurekaClient;
	this.instanceConfig = instanceConfig;
	this.clientConfig = clientConfig;
}
 
Example #20
Source File: CloudEurekaClient.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
		EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs<?> args,
		ApplicationEventPublisher publisher) {
	super(applicationInfoManager, config, args);
	this.applicationInfoManager = applicationInfoManager;
	this.publisher = publisher;
	this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class,
			"eurekaTransport");
	ReflectionUtils.makeAccessible(this.eurekaTransportField);
}
 
Example #21
Source File: EurekaLoadBalancerClientConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
public EurekaLoadBalancerClientConfiguration(
		@Autowired(required = false) EurekaClientConfig clientConfig,
		@Autowired(required = false) EurekaInstanceConfig eurekaInstanceConfig,
		LoadBalancerZoneConfig zoneConfig,
		EurekaLoadBalancerProperties eurekaLoadBalancerProperties) {
	this.clientConfig = clientConfig;
	this.eurekaConfig = eurekaInstanceConfig;
	this.zoneConfig = zoneConfig;
	this.eurekaLoadBalancerProperties = eurekaLoadBalancerProperties;
}
 
Example #22
Source File: RestTemplateTransportClientFactories.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Override
public TransportClientFactory newTransportClientFactory(
		final EurekaClientConfig clientConfig,
		final Collection<Void> additionalFilters, final InstanceInfo myInstanceInfo,
		final Optional<SSLContext> sslContext,
		final Optional<HostnameVerifier> hostnameVerifier) {
	return new RestTemplateTransportClientFactory();
}
 
Example #23
Source File: WebClientTransportClientFactories.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Override
public TransportClientFactory newTransportClientFactory(
		final EurekaClientConfig clientConfig,
		final Collection<Void> additionalFilters, final InstanceInfo myInstanceInfo,
		final Optional<SSLContext> sslContext,
		final Optional<HostnameVerifier> hostnameVerifier) {
	return new WebClientTransportClientFactory();
}
 
Example #24
Source File: EurekaCustomPeerNodesTest.java    From didi-eureka-server with MIT License 5 votes vote down vote up
public CustomEurekaPeerNodes(PeerAwareInstanceRegistry registry,
		EurekaServerConfig serverConfig, EurekaClientConfig clientConfig,
		ServerCodecs serverCodecs,
		ApplicationInfoManager applicationInfoManager) {
	super(registry, serverConfig, clientConfig, serverCodecs,
			applicationInfoManager);
}
 
Example #25
Source File: EurekaStore.java    From qconfig with MIT License 5 votes vote down vote up
protected PeerEurekaNodes getPeerEurekaNodes(PeerAwareInstanceRegistry registry, EurekaServerConfig eurekaServerConfig, EurekaClientConfig eurekaClientConfig, ServerCodecs serverCodecs, ApplicationInfoManager applicationInfoManager) {
    return new PeerEurekaNodes(
            registry,
            eurekaServerConfig,
            eurekaClientConfig,
            serverCodecs,
            applicationInfoManager
    );
}
 
Example #26
Source File: ApimlDiscoveryClient.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public ApimlDiscoveryClient(
    ApplicationInfoManager applicationInfoManager,
    EurekaClientConfig config,
    AbstractDiscoveryClientOptionalArgs<?> args,
    ApplicationEventPublisher publisher
) {
    super(applicationInfoManager, config, args, publisher);
    init();
}
 
Example #27
Source File: DiscoveryEnabledNIWSServerList.java    From ribbon with Apache License 2.0 5 votes vote down vote up
protected DiscoveryEnabledServer createServer(final InstanceInfo instanceInfo, boolean useSecurePort, boolean useIpAddr) {
    DiscoveryEnabledServer server = new DiscoveryEnabledServer(instanceInfo, useSecurePort, useIpAddr);

    // Get availabilty zone for this instance.
    EurekaClientConfig clientConfig = eurekaClientProvider.get().getEurekaClientConfig();
    String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
    String instanceZone = InstanceInfo.getZone(availZones, instanceInfo);
    server.setZone(instanceZone);

    return server;
}
 
Example #28
Source File: EurekaConfig.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
@Primary
public ApimlInstanceRegistry getApimlInstanceRegistry(
    EurekaServerConfig serverConfig,
    EurekaClientConfig clientConfig,
    ServerCodecs serverCodecs,
    EurekaClient eurekaClient,
    InstanceRegistryProperties instanceRegistryProperties,
    ApplicationContext appCntx)
{
    eurekaClient.getApplications(); // force initialization
    return new ApimlInstanceRegistry(serverConfig, clientConfig, serverCodecs, eurekaClient, instanceRegistryProperties,appCntx);
}
 
Example #29
Source File: ApimlInstanceRegistry.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
public ApimlInstanceRegistry(
    EurekaServerConfig serverConfig,
    EurekaClientConfig clientConfig,
    ServerCodecs serverCodecs,
    EurekaClient eurekaClient,
    InstanceRegistryProperties instanceRegistryProperties,
    ApplicationContext appCntx
) {
    super(serverConfig, clientConfig, serverCodecs, eurekaClient,
        instanceRegistryProperties.getExpectedNumberOfClientsSendingRenews(),
        instanceRegistryProperties.getDefaultOpenForTrafficCount()
    );
    this.appCntx = appCntx;
    init();
}
 
Example #30
Source File: EurekaConfigServerBootstrapConfiguration.java    From spring-cloud-netflix with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigServerInstanceProvider.Function eurekaConfigServerInstanceProvider(
		EurekaHttpClient client, EurekaClientConfig config) {

	return serviceId -> {
		if (log.isDebugEnabled()) {
			log.debug("eurekaConfigServerInstanceProvider finding instances for "
					+ serviceId);
		}
		EurekaHttpResponse<Applications> response = client
				.getApplications(config.getRegion());
		List<ServiceInstance> instances = new ArrayList<>();
		if (!isSuccessful(response) || response.getEntity() == null) {
			return instances;
		}

		Applications applications = response.getEntity();
		applications.shuffleInstances(config.shouldFilterOnlyUpInstances());
		List<InstanceInfo> infos = applications
				.getInstancesByVirtualHostName(serviceId);
		for (InstanceInfo info : infos) {
			instances.add(new EurekaServiceInstance(info));
		}
		if (log.isDebugEnabled()) {
			log.debug("eurekaConfigServerInstanceProvider found " + infos.size()
					+ " instance(s) for " + serviceId + ", " + instances);
		}
		return instances;
	};
}