use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class ResolverUtils method instanceInfoToEndpoint.
public static AwsEndpoint instanceInfoToEndpoint(EurekaClientConfig clientConfig, EurekaTransportConfig transportConfig, InstanceInfo instanceInfo) {
String zone = null;
DataCenterInfo dataCenterInfo = instanceInfo.getDataCenterInfo();
if (dataCenterInfo instanceof AmazonInfo) {
zone = ((AmazonInfo) dataCenterInfo).get(AmazonInfo.MetaDataKey.availabilityZone);
} else {
zone = instanceInfo.getMetadata().get("zone");
}
String networkAddress;
if (transportConfig.applicationsResolverUseIp()) {
if (instanceInfo.getDataCenterInfo() instanceof AmazonInfo) {
networkAddress = ((AmazonInfo) instanceInfo.getDataCenterInfo()).get(AmazonInfo.MetaDataKey.localIpv4);
} else {
networkAddress = instanceInfo.getIPAddr();
}
} else {
networkAddress = instanceInfo.getHostName();
}
if (networkAddress == null) {
// final check
logger.error("Cannot resolve InstanceInfo {} to a proper resolver endpoint, skipping", instanceInfo);
return null;
}
return new AwsEndpoint(networkAddress, instanceInfo.getPort(), false, clientConfig.getEurekaServerURLContext(), clientConfig.getRegion(), zone);
}
use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class ResolverUtils method splitByZone.
/**
* @return returns two element array with first item containing list of endpoints from client's zone,
* and in the second list all the remaining ones
*/
public static List<AwsEndpoint>[] splitByZone(List<AwsEndpoint> eurekaEndpoints, String myZone) {
if (eurekaEndpoints.isEmpty()) {
return new List[] { Collections.emptyList(), Collections.emptyList() };
}
if (myZone == null) {
return new List[] { Collections.emptyList(), new ArrayList<>(eurekaEndpoints) };
}
List<AwsEndpoint> myZoneList = new ArrayList<>(eurekaEndpoints.size());
List<AwsEndpoint> remainingZonesList = new ArrayList<>(eurekaEndpoints.size());
for (AwsEndpoint endpoint : eurekaEndpoints) {
if (myZone.equalsIgnoreCase(endpoint.getZone())) {
myZoneList.add(endpoint);
} else {
remainingZonesList.add(endpoint);
}
}
return new List[] { myZoneList, remainingZonesList };
}
use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class EurekaHttpClients method defaultBootstrapResolver.
/**
* @return a bootstrap resolver that resolves eureka server endpoints based on either DNS or static config,
* depending on configuration for one or the other. This resolver will warm up at the start.
*/
static ClosableResolver<AwsEndpoint> defaultBootstrapResolver(final EurekaClientConfig clientConfig, final InstanceInfo myInstanceInfo, final EndpointRandomizer randomizer) {
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
ClusterResolver<AwsEndpoint> delegateResolver = new ZoneAffinityClusterResolver(new ConfigClusterResolver(clientConfig, myInstanceInfo), myZone, true, randomizer);
List<AwsEndpoint> initialValue = delegateResolver.getClusterEndpoints();
if (initialValue.isEmpty()) {
String msg = "Initial resolution of Eureka server endpoints failed. Check ConfigClusterResolver logs for more info";
logger.error(msg);
failFastOnInitCheck(clientConfig, msg);
}
return new AsyncResolver<>(EurekaClientNames.BOOTSTRAP, delegateResolver, initialValue, 1, clientConfig.getEurekaServiceUrlPollIntervalSeconds() * 1000);
}
use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class EurekaHttpClients method compositeQueryResolver.
/**
* @return a composite resolver that resolves eureka server endpoints for query operations, given two resolvers:
* a resolver that can resolve targets via a remote call to a remote source, and a resolver that
* can resolve targets via data in the local registry.
*/
/* testing */
static ClosableResolver<AwsEndpoint> compositeQueryResolver(final ClusterResolver<AwsEndpoint> remoteResolver, final ClusterResolver<AwsEndpoint> localResolver, final EurekaClientConfig clientConfig, final EurekaTransportConfig transportConfig, final InstanceInfo myInstanceInfo, final EndpointRandomizer randomizer) {
String[] availZones = clientConfig.getAvailabilityZones(clientConfig.getRegion());
String myZone = InstanceInfo.getZone(availZones, myInstanceInfo);
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;
}
};
return new AsyncResolver<>(EurekaClientNames.QUERY, new ZoneAffinityClusterResolver(compositeResolver, myZone, true, randomizer), transportConfig.getAsyncExecutorThreadPoolSize(), transportConfig.getAsyncResolverRefreshIntervalMs(), transportConfig.getAsyncResolverWarmUpTimeoutMs());
}
use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class ResolverUtilsTest method testInstanceInfoToEndpoint.
@Test
public void testInstanceInfoToEndpoint() throws Exception {
EurekaClientConfig clientConfig = mock(EurekaClientConfig.class);
when(clientConfig.getEurekaServerURLContext()).thenReturn("/eureka");
when(clientConfig.getRegion()).thenReturn("region");
EurekaTransportConfig transportConfig = mock(EurekaTransportConfig.class);
when(transportConfig.applicationsResolverUseIp()).thenReturn(false);
AmazonInfo amazonInfo = AmazonInfo.Builder.newBuilder().addMetadata(AmazonInfo.MetaDataKey.availabilityZone, "us-east-1c").build();
InstanceInfo instanceWithAWSInfo = InstanceInfo.Builder.newBuilder().setAppName("appName").setHostName("hostName").setPort(8080).setDataCenterInfo(amazonInfo).build();
AwsEndpoint awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithAWSInfo);
assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());
MyDataCenterInfo myDataCenterInfo = new MyDataCenterInfo(DataCenterInfo.Name.MyOwn);
InstanceInfo instanceWithMyDataInfo = InstanceInfo.Builder.newBuilder().setAppName("appName").setHostName("hostName").setPort(8080).setDataCenterInfo(myDataCenterInfo).add("zone", "us-east-1c").build();
awsEndpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceWithMyDataInfo);
assertEquals("zone not equals.", "us-east-1c", awsEndpoint.getZone());
}
Aggregations