use of com.netflix.discovery.shared.resolver.aws.ApplicationsResolver in project eureka by Netflix.
the class EurekaHttpClients method queryClientResolver.
/**
* @return a resolver that resolves eureka server endpoints for query operations
*/
static ClosableResolver<AwsEndpoint> queryClientResolver(final ClusterResolver bootstrapResolver, final TransportClientFactory transportClientFactory, final EurekaClientConfig clientConfig, final EurekaTransportConfig transportConfig, final InstanceInfo myInstanceInfo, final ApplicationsResolver.ApplicationsSource applicationsSource, final EndpointRandomizer randomizer) {
final EurekaHttpResolver remoteResolver = new EurekaHttpResolver(clientConfig, transportConfig, bootstrapResolver, transportClientFactory, transportConfig.getReadClusterVip());
final ApplicationsResolver localResolver = new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getReadClusterVip());
return compositeQueryResolver(remoteResolver, localResolver, clientConfig, transportConfig, myInstanceInfo, randomizer);
}
use of com.netflix.discovery.shared.resolver.aws.ApplicationsResolver in project eureka by Netflix.
the class EurekaHttpClientsTest method testCanonicalResolver.
@Test
public void testCanonicalResolver() throws Exception {
when(clientConfig.getEurekaServerURLContext()).thenReturn("context");
when(clientConfig.getRegion()).thenReturn("region");
when(transportConfig.getAsyncExecutorThreadPoolSize()).thenReturn(3);
when(transportConfig.getAsyncResolverRefreshIntervalMs()).thenReturn(400);
when(transportConfig.getAsyncResolverWarmUpTimeoutMs()).thenReturn(400);
Applications applications = InstanceInfoGenerator.newBuilder(5, "eurekaRead", "someOther").build().toApplications();
String vipAddress = applications.getRegisteredApplications("eurekaRead").getInstances().get(0).getVIPAddress();
ApplicationsResolver.ApplicationsSource applicationsSource = mock(ApplicationsResolver.ApplicationsSource.class);
when(applicationsSource.getApplications(anyInt(), eq(TimeUnit.SECONDS))).thenReturn(// first time
null).thenReturn(// subsequent times
applications);
EurekaHttpClientFactory remoteResolverClientFactory = mock(EurekaHttpClientFactory.class);
EurekaHttpClient httpClient = mock(EurekaHttpClient.class);
when(remoteResolverClientFactory.newClient()).thenReturn(httpClient);
when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, applications).build());
EurekaHttpResolver remoteResolver = spy(new TestEurekaHttpResolver(clientConfig, transportConfig, remoteResolverClientFactory, vipAddress));
when(transportConfig.getReadClusterVip()).thenReturn(vipAddress);
ApplicationsResolver localResolver = spy(new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getReadClusterVip()));
ClosableResolver resolver = null;
try {
resolver = EurekaHttpClients.compositeQueryResolver(remoteResolver, localResolver, clientConfig, transportConfig, applicationInfoManager.getInfo(), randomizer);
List endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
verify(remoteResolver, times(1)).getClusterEndpoints();
verify(localResolver, times(1)).getClusterEndpoints();
// wait for the second cycle that hits the app source
verify(applicationsSource, timeout(3000).times(2)).getApplications(anyInt(), eq(TimeUnit.SECONDS));
endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
verify(remoteResolver, times(1)).getClusterEndpoints();
verify(localResolver, times(2)).getClusterEndpoints();
} finally {
if (resolver != null) {
resolver.shutdown();
}
}
}
use of com.netflix.discovery.shared.resolver.aws.ApplicationsResolver in project eureka by Netflix.
the class EurekaHttpClients method queryClientResolver.
/**
* @return a resolver that resolves eureka server endpoints for query operations
*/
static ClosableResolver<AwsEndpoint> queryClientResolver(final ClusterResolver bootstrapResolver, final TransportClientFactory transportClientFactory, final EurekaClientConfig clientConfig, final EurekaTransportConfig transportConfig, final InstanceInfo myInstanceInfo, final ApplicationsResolver.ApplicationsSource applicationsSource) {
final EurekaHttpResolver remoteResolver = new EurekaHttpResolver(clientConfig, transportConfig, bootstrapResolver, transportClientFactory, transportConfig.getReadClusterVip());
final ApplicationsResolver localResolver = new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getReadClusterVip());
return compositeQueryResolver(remoteResolver, localResolver, clientConfig, transportConfig, myInstanceInfo);
}
use of com.netflix.discovery.shared.resolver.aws.ApplicationsResolver in project eureka by Netflix.
the class EurekaHttpClients method compositeBootstrapResolver.
/**
* @return a bootstrap resolver that resolves eureka server endpoints via a remote call to a "vip source"
* the local registry, where the source is found from a rootResolver (dns or config)
*/
static ClosableResolver<AwsEndpoint> compositeBootstrapResolver(final EurekaClientConfig clientConfig, final EurekaTransportConfig transportConfig, final TransportClientFactory transportClientFactory, final InstanceInfo myInstanceInfo, final ApplicationsResolver.ApplicationsSource applicationsSource) {
final ClusterResolver rootResolver = new ConfigClusterResolver(clientConfig, myInstanceInfo);
final EurekaHttpResolver remoteResolver = new EurekaHttpResolver(clientConfig, transportConfig, rootResolver, transportClientFactory, transportConfig.getWriteClusterVip());
final ApplicationsResolver localResolver = new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getWriteClusterVip());
ClusterResolver<AwsEndpoint> compositeResolver = new ClusterResolver<AwsEndpoint>() {
@Override
public String getRegion() {
return clientConfig.getRegion();
}
@Override
public List<AwsEndpoint> getClusterEndpoints() {
List<AwsEndpoint> result = localResolver.getClusterEndpoints();
if (result.isEmpty()) {
result = remoteResolver.getClusterEndpoints();
}
return result;
}
};
List<AwsEndpoint> initialValue = compositeResolver.getClusterEndpoints();
if (initialValue.isEmpty()) {
String msg = "Initial resolution of Eureka endpoints failed. Check ConfigClusterResolver logs for more info";
logger.error(msg);
failFastOnInitCheck(clientConfig, msg);
}
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
return new AsyncResolver<>(EurekaClientNames.BOOTSTRAP, new ZoneAffinityClusterResolver(compositeResolver, myZone, true), initialValue, transportConfig.getAsyncExecutorThreadPoolSize(), transportConfig.getAsyncResolverRefreshIntervalMs());
}
use of com.netflix.discovery.shared.resolver.aws.ApplicationsResolver in project eureka by Netflix.
the class EurekaHttpClients method compositeBootstrapResolver.
/**
* @return a bootstrap resolver that resolves eureka server endpoints via a remote call to a "vip source"
* the local registry, where the source is found from a rootResolver (dns or config)
*/
static ClosableResolver<AwsEndpoint> compositeBootstrapResolver(final EurekaClientConfig clientConfig, final EurekaTransportConfig transportConfig, final TransportClientFactory transportClientFactory, final InstanceInfo myInstanceInfo, final ApplicationsResolver.ApplicationsSource applicationsSource, final EndpointRandomizer randomizer) {
final ClusterResolver rootResolver = new ConfigClusterResolver(clientConfig, myInstanceInfo);
final EurekaHttpResolver remoteResolver = new EurekaHttpResolver(clientConfig, transportConfig, rootResolver, transportClientFactory, transportConfig.getWriteClusterVip());
final ApplicationsResolver localResolver = new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getWriteClusterVip());
ClusterResolver<AwsEndpoint> compositeResolver = new ClusterResolver<AwsEndpoint>() {
@Override
public String getRegion() {
return clientConfig.getRegion();
}
@Override
public List<AwsEndpoint> getClusterEndpoints() {
List<AwsEndpoint> result = localResolver.getClusterEndpoints();
if (result.isEmpty()) {
result = remoteResolver.getClusterEndpoints();
}
return result;
}
};
List<AwsEndpoint> initialValue = compositeResolver.getClusterEndpoints();
if (initialValue.isEmpty()) {
String msg = "Initial resolution of Eureka endpoints failed. Check ConfigClusterResolver logs for more info";
logger.error(msg);
failFastOnInitCheck(clientConfig, msg);
}
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
return new AsyncResolver<>(EurekaClientNames.BOOTSTRAP, new ZoneAffinityClusterResolver(compositeResolver, myZone, true, randomizer), initialValue, transportConfig.getAsyncExecutorThreadPoolSize(), transportConfig.getAsyncResolverRefreshIntervalMs());
}
Aggregations