Search in sources :

Example 11 with AwsEndpoint

use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint 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());
}
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

AwsEndpoint (com.netflix.discovery.shared.resolver.aws.AwsEndpoint)11 AsyncResolver (com.netflix.discovery.shared.resolver.AsyncResolver)6 ConfigClusterResolver (com.netflix.discovery.shared.resolver.aws.ConfigClusterResolver)6 ZoneAffinityClusterResolver (com.netflix.discovery.shared.resolver.aws.ZoneAffinityClusterResolver)6 ClusterResolver (com.netflix.discovery.shared.resolver.ClusterResolver)4 ApplicationsResolver (com.netflix.discovery.shared.resolver.aws.ApplicationsResolver)3 Test (org.junit.Test)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 EurekaHttpResolver (com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver)2 List (java.util.List)2 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 MyDataCenterInfo (com.netflix.appinfo.MyDataCenterInfo)1 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)1 Applications (com.netflix.discovery.shared.Applications)1 EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)1 EurekaTransportConfig (com.netflix.discovery.shared.transport.EurekaTransportConfig)1 ArrayList (java.util.ArrayList)1 Matchers.anyString (org.mockito.Matchers.anyString)1