Search in sources :

Example 1 with EurekaHttpResolver

use of com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver 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());
        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();
        }
    }
}
Also used : ClosableResolver(com.netflix.discovery.shared.resolver.ClosableResolver) ApplicationsResolver(com.netflix.discovery.shared.resolver.aws.ApplicationsResolver) EurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver) TestEurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver) Applications(com.netflix.discovery.shared.Applications) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) TestEurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver) Test(org.junit.Test)

Example 2 with EurekaHttpResolver

use of com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver 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);
}
Also used : EurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver) ApplicationsResolver(com.netflix.discovery.shared.resolver.aws.ApplicationsResolver)

Example 3 with EurekaHttpResolver

use of com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver 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());
}
Also used : AsyncResolver(com.netflix.discovery.shared.resolver.AsyncResolver) ClusterResolver(com.netflix.discovery.shared.resolver.ClusterResolver) ConfigClusterResolver(com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver) ZoneAffinityClusterResolver(com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver) EurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver) ApplicationsResolver(com.netflix.discovery.shared.resolver.aws.ApplicationsResolver) AwsEndpoint(com.netflix.discovery.shared.resolver.aws.AwsEndpoint) ConfigClusterResolver(com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver) ZoneAffinityClusterResolver(com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver)

Aggregations

ApplicationsResolver (com.netflix.discovery.shared.resolver.aws.ApplicationsResolver)3 EurekaHttpResolver (com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver)3 Applications (com.netflix.discovery.shared.Applications)1 AsyncResolver (com.netflix.discovery.shared.resolver.AsyncResolver)1 ClosableResolver (com.netflix.discovery.shared.resolver.ClosableResolver)1 ClusterResolver (com.netflix.discovery.shared.resolver.ClusterResolver)1 AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)1 ConfigClusterResolver (com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver)1 TestEurekaHttpResolver (com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver)1 ZoneAffinityClusterResolver (com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver)1 List (java.util.List)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1