use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class ApplicationsResolver method getClusterEndpoints.
@Override
public List<AwsEndpoint> getClusterEndpoints() {
List<AwsEndpoint> result = new ArrayList<>();
Applications applications = applicationsSource.getApplications(transportConfig.getApplicationsResolverDataStalenessThresholdSeconds(), TimeUnit.SECONDS);
if (applications != null && vipAddress != null) {
List<InstanceInfo> validInstanceInfos = applications.getInstancesByVirtualHostName(vipAddress);
for (InstanceInfo instanceInfo : validInstanceInfos) {
if (instanceInfo.getStatus() == InstanceInfo.InstanceStatus.UP) {
AwsEndpoint endpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceInfo);
if (endpoint != null) {
result.add(endpoint);
}
}
}
}
logger.debug("Retrieved endpoint list {}", result);
return result;
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpResolver method getClusterEndpoints.
@Override
public List<AwsEndpoint> getClusterEndpoints() {
List<AwsEndpoint> result = new ArrayList<>();
EurekaHttpClient client = null;
try {
client = clientFactory.newClient();
EurekaHttpResponse<Applications> response = client.getVip(vipAddress);
if (validResponse(response)) {
Applications applications = response.getEntity();
if (applications != null) {
// filter out non-UP instances
applications.shuffleInstances(true);
List<InstanceInfo> validInstanceInfos = applications.getInstancesByVirtualHostName(vipAddress);
for (InstanceInfo instanceInfo : validInstanceInfos) {
AwsEndpoint endpoint = ResolverUtils.instanceInfoToEndpoint(clientConfig, transportConfig, instanceInfo);
if (endpoint != null) {
result.add(endpoint);
}
}
logger.debug("Retrieved endpoint list {}", result);
return result;
}
}
} catch (Exception e) {
logger.error("Error contacting server for endpoints with vipAddress:{}", vipAddress, e);
} finally {
if (client != null) {
client.shutdown();
}
}
logger.info("Returning empty endpoint list");
return Collections.emptyList();
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class CodecLoadTester method createJacksonNgAction.
Func0 createJacksonNgAction(final MediaType mediaType, final boolean compact) {
return new Func0<Object>() {
@Override
public int call(Object object) {
AbstractEurekaJacksonCodec codec;
if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
codec = compact ? jsonCodecNgCompact : jsonCodecNG;
} else {
codec = compact ? xmlCodecNgCompact : xmlCodecNG;
}
ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
try {
codec.writeTo(object, captureStream);
byte[] bytes = captureStream.toByteArray();
InputStream source = new ByteArrayInputStream(bytes);
Applications readValue = codec.getObjectMapper(object.getClass()).readValue(source, Applications.class);
secondHolder.value = readValue;
return bytes.length;
} catch (IOException e) {
throw new RuntimeException("unexpected", e);
}
}
};
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class CodecLoadTester method loadWithCodec.
private Applications loadWithCodec(String fileName, MediaType mediaType) throws IOException {
FileInputStream fis = new FileInputStream(fileName);
BufferedInputStream bis = new BufferedInputStream(fis);
return (Applications) xstreamCodec.read(bis, Applications.class, mediaType);
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class BackUpRegistryTest method testLocalOnly.
@Test
public void testLocalOnly() throws Exception {
setUp(false);
Applications applications = client.getApplications();
List<Application> registeredApplications = applications.getRegisteredApplications();
System.out.println("***" + registeredApplications);
Assert.assertNotNull("Local region apps not found.", registeredApplications);
Assert.assertEquals("Local apps size not as expected.", 1, registeredApplications.size());
Assert.assertEquals("Local region apps not present.", LOCAL_REGION_APP_NAME, registeredApplications.get(0).getName());
}
Aggregations