use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class AbstractJerseyEurekaHttpClient method sendHeartBeat.
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {
String urlPath = "apps/" + appName + '/' + id;
ClientResponse response = null;
try {
WebResource webResource = jerseyClient.resource(serviceUrl).path(urlPath).queryParam("status", info.getStatus().toString()).queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString());
if (overriddenStatus != null) {
webResource = webResource.queryParam("overriddenstatus", overriddenStatus.name());
}
Builder requestBuilder = webResource.getRequestBuilder();
addExtraHeaders(requestBuilder);
response = requestBuilder.put(ClientResponse.class);
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(response.getStatus(), InstanceInfo.class).headers(headersOf(response));
if (response.hasEntity()) {
eurekaResponseBuilder.entity(response.getEntity(InstanceInfo.class));
}
return eurekaResponseBuilder.build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey HTTP PUT {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class AbstractJerseyEurekaHttpClient method getInstanceInternal.
private EurekaHttpResponse<InstanceInfo> getInstanceInternal(String urlPath) {
ClientResponse response = null;
try {
Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
addExtraHeaders(requestBuilder);
response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
InstanceInfo infoFromPeer = null;
if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
infoFromPeer = response.getEntity(InstanceInfo.class);
}
return anEurekaHttpResponse(response.getStatus(), InstanceInfo.class).headers(headersOf(response)).entity(infoFromPeer).build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey HTTP GET {}/{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
}
if (response != null) {
response.close();
}
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testGetByVipInRemoteRegion.
@Test
public void testGetByVipInRemoteRegion() throws Exception {
prepareRemoteRegionRegistry();
EurekaClient client = discoveryClientResource.getClient();
String vipAddress = takeFirst(client.getApplicationsForARegion(TEST_REMOTE_REGION)).getVIPAddress();
List<InstanceInfo> instancesByVipAddress = client.getInstancesByVipAddress(vipAddress, false, TEST_REMOTE_REGION);
assertThat(instancesByVipAddress.size(), is(equalTo(2)));
InstanceInfo instance = instancesByVipAddress.iterator().next();
assertThat(instance.getVIPAddress(), is(equalTo(vipAddress)));
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull.
@Test
public void testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull() throws Exception {
InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
// Full fetch with one item
InstanceInfo first = instanceGen.first();
Applications initial = toApplications(first);
when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build());
EurekaClient client = discoveryClientResource.getClient();
assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_")));
// Delta with one add
InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo1").setStatus(InstanceStatus.DOWN).setDataCenterInfo(null).build();
InstanceInfo third = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo2").setStatus(InstanceStatus.UP).setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return null;
}
}).build();
Applications delta = toApplications(second, third);
delta.setAppsHashCode("DOWN_1_UP_2_");
when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_2_")));
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testEurekaClientPeriodicHeartbeat.
@Test
public void testEurekaClientPeriodicHeartbeat() throws Exception {
DiscoveryClientResource registeringClientResource = discoveryClientResource.fork().withRegistration(true).withRegistryFetch(false).build();
InstanceInfo instance = registeringClientResource.getMyInstanceInfo();
when(requestHandler.register(any(InstanceInfo.class))).thenReturn(EurekaHttpResponse.status(204));
when(requestHandler.sendHeartBeat(instance.getAppName(), instance.getId(), null, null)).thenReturn(anEurekaHttpResponse(200, InstanceInfo.class).build());
// Initialize
registeringClientResource.getClient();
verify(requestHandler, timeout(5 * 1000).atLeast(2)).sendHeartBeat(instance.getAppName(), instance.getId(), null, null);
}
Aggregations