use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class NonEc2EurekaClientModuleTest method testDI.
@SuppressWarnings("deprecation")
@Test
public void testDI() {
InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
Assert.assertEquals(eurekaClient, discoveryClient);
EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
Assert.assertTrue(eurekaInstanceConfig instanceof EurekaArchaius2InstanceConfig);
ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
InstanceInfo myInfo = applicationInfoManager.getInfo();
Assert.assertEquals(DataCenterInfo.Name.MyOwn, myInfo.getDataCenterInfo().getName());
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class AbstractJersey2EurekaHttpClient method sendHeartBeat.
@Override
public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {
String urlPath = "apps/" + appName + '/' + id;
Response response = null;
try {
WebTarget webResource = jerseyClient.target(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.request();
addExtraProperties(requestBuilder);
addExtraHeaders(requestBuilder);
requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE);
// Jersey2 refuses to handle PUT with no body
response = requestBuilder.put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE));
EurekaHttpResponseBuilder<InstanceInfo> eurekaResponseBuilder = anEurekaHttpResponse(response.getStatus(), InstanceInfo.class).headers(headersOf(response));
if (response.hasEntity()) {
eurekaResponseBuilder.entity(response.readEntity(InstanceInfo.class));
}
return eurekaResponseBuilder.build();
} finally {
if (logger.isDebugEnabled()) {
logger.debug("Jersey2 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 DiscoveryClient method getNextServerFromEureka.
/*
* (non-Javadoc)
*
* @see
* com.netflix.discovery.shared.LookupService#getNextServerFromEureka(java
* .lang.String, boolean)
*/
@Override
public InstanceInfo getNextServerFromEureka(String virtualHostname, boolean secure) {
List<InstanceInfo> instanceInfoList = this.getInstancesByVipAddress(virtualHostname, secure);
if (instanceInfoList == null || instanceInfoList.isEmpty()) {
throw new RuntimeException("No matches for the virtual host name :" + virtualHostname);
}
Applications apps = this.localRegionApps.get();
int index = (int) (apps.getNextIndex(virtualHostname.toUpperCase(Locale.ROOT), secure).incrementAndGet() % instanceInfoList.size());
return instanceInfoList.get(index);
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class DiscoveryClient method updateInstanceRemoteStatus.
private synchronized void updateInstanceRemoteStatus() {
// Determine this instance's status for this app and set to UNKNOWN if not found
InstanceInfo.InstanceStatus currentRemoteInstanceStatus = null;
if (instanceInfo.getAppName() != null) {
Application app = getApplication(instanceInfo.getAppName());
if (app != null) {
InstanceInfo remoteInstanceInfo = app.getByInstanceId(instanceInfo.getId());
if (remoteInstanceInfo != null) {
currentRemoteInstanceStatus = remoteInstanceInfo.getStatus();
}
}
}
if (currentRemoteInstanceStatus == null) {
currentRemoteInstanceStatus = InstanceInfo.InstanceStatus.UNKNOWN;
}
// Notify if status changed
if (lastRemoteInstanceStatus != currentRemoteInstanceStatus) {
onRemoteStatusChanged(lastRemoteInstanceStatus, currentRemoteInstanceStatus);
lastRemoteInstanceStatus = currentRemoteInstanceStatus;
}
}
use of com.netflix.appinfo.InstanceInfo in project eureka by Netflix.
the class Ec2EurekaClientModuleTest method testDI.
@SuppressWarnings("deprecation")
@Test
public void testDI() {
InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
Assert.assertEquals(eurekaClient, discoveryClient);
EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
Assert.assertTrue(eurekaInstanceConfig instanceof Ec2EurekaArchaius2InstanceConfig);
ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
InstanceInfo myInfo = applicationInfoManager.getInfo();
Assert.assertTrue(myInfo.getDataCenterInfo() instanceof AmazonInfo);
Assert.assertEquals(DataCenterInfo.Name.Amazon, myInfo.getDataCenterInfo().getName());
}
Aggregations