本文整理了Java中com.netflix.discovery.shared.Application.getByInstanceId()
方法的一些代码示例,展示了Application.getByInstanceId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.getByInstanceId()
方法的具体详情如下:
包路径:com.netflix.discovery.shared.Application
类名称:Application
方法名:getByInstanceId
[英]Get the instance info that matches the given id.
[中]获取与给定id匹配的实例信息。
代码示例来源:origin: Netflix/eureka
@Override
public List<InstanceInfo> getInstancesById(String id) {
List<InstanceInfo> list = Collections.emptyList();
for (Application app : applications.get().getRegisteredApplications()) {
InstanceInfo info = app.getByInstanceId(id);
if (info != null) {
list.add(info);
return list;
}
}
return list;
}
代码示例来源:origin: Netflix/eureka
@Override
public List<InstanceInfo> getInstancesById(String id) {
List<InstanceInfo> instancesList = new ArrayList<InstanceInfo>();
for (Application app : this.getApplications()
.getRegisteredApplications()) {
InstanceInfo instanceInfo = app.getByInstanceId(id);
if (instanceInfo != null) {
instancesList.add(instanceInfo);
}
}
return instancesList;
}
代码示例来源:origin: Netflix/eureka
for (Application application : remoteRegistry.getApplications()
.getRegisteredApplications()) {
InstanceInfo instanceInfo = application.getByInstanceId(id);
if (instanceInfo != null) {
list.add(instanceInfo);
代码示例来源:origin: Netflix/eureka
/**
* Gets the {@link InstanceInfo} information.
*
* @param appName the application name for which the information is requested.
* @param id the unique identifier of the instance.
* @param includeRemoteRegions true, if we need to include applications from remote regions
* as indicated by the region {@link URL} by this property
* {@link EurekaServerConfig#getRemoteRegionUrls()}, false otherwise
* @return the information about the instance.
*/
@Override
public InstanceInfo getInstanceByAppAndId(String appName, String id, boolean includeRemoteRegions) {
Map<String, Lease<InstanceInfo>> leaseMap = registry.get(appName);
Lease<InstanceInfo> lease = null;
if (leaseMap != null) {
lease = leaseMap.get(id);
}
if (lease != null
&& (!isLeaseExpirationEnabled() || !lease.isExpired())) {
return decorateInstanceInfo(lease);
} else if (includeRemoteRegions) {
for (RemoteRegionRegistry remoteRegistry : this.regionNameVSRemoteRegistry.values()) {
Application application = remoteRegistry.getApplication(appName);
if (application != null) {
return application.getByInstanceId(id);
}
}
}
return null;
}
代码示例来源:origin: Netflix/eureka
protected void verifyLocalInstanceStatus(String id, InstanceInfo.InstanceStatus status) {
InstanceInfo instanceInfo = registry.getApplication(LOCAL_REGION_APP_NAME).getByInstanceId(id);
assertThat("InstanceInfo with id " + id + " not found", instanceInfo, is(notNullValue()));
assertThat("Invalid InstanceInfo state", instanceInfo.getStatus(), is(equalTo(status)));
}
代码示例来源:origin: Netflix/eureka
public static boolean equal(Application first, Application second) {
if (first == second) {
return true;
}
if (first == null || first == null && second != null) {
return false;
}
if (first.getName() != null ? !first.getName().equals(second.getName()) : second.getName() != null) {
return false;
}
List<InstanceInfo> firstInstanceInfos = first.getInstances();
List<InstanceInfo> secondInstanceInfos = second.getInstances();
if (firstInstanceInfos == null && secondInstanceInfos == null) {
return true;
}
if (firstInstanceInfos == null || secondInstanceInfos == null || firstInstanceInfos.size() != secondInstanceInfos.size()) {
return false;
}
for (InstanceInfo firstInstanceInfo : firstInstanceInfos) {
InstanceInfo secondInstanceInfo = second.getByInstanceId(firstInstanceInfo.getId());
if (!equal(firstInstanceInfo, secondInstanceInfo)) {
return false;
}
}
return true;
}
代码示例来源:origin: Netflix/eureka
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;
}
}
代码示例来源:origin: Netflix/eureka
@Test
public void testMiniAppGet() throws Exception {
Response response = applicationResource.getApplication(
Version.V2.name(),
MediaType.APPLICATION_JSON,
EurekaAccept.compact.name()
);
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Application decodedApp = decoder.decode(json, Application.class);
// assert false as one is mini, so should NOT equal
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false));
for (InstanceInfo instanceInfo : testApplication.getInstances()) {
InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
}
}
代码示例来源:origin: Netflix/eureka
@Test
public void testMiniVipGet() throws Exception {
Response response = resource.getVipResponse(
Version.V2.name(),
vipName,
MediaType.APPLICATION_JSON,
EurekaAccept.compact,
Key.EntityType.VIP
);
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Applications decodedApps = decoder.decode(json, Applications.class);
Application decodedApp = decodedApps.getRegisteredApplications(testApplication.getName());
// assert false as one is mini, so should NOT equal
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false));
for (InstanceInfo instanceInfo : testApplication.getInstances()) {
InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
}
}
}
代码示例来源:origin: Netflix/eureka
InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
代码示例来源:origin: Netflix/eureka
remoteRegionsRegistry.put("us-east-1", new Applications());
applications.shuffleAndIndexInstances(remoteRegionsRegistry, clientConfig, instanceRegionChecker);
assertNotNull(remoteRegionsRegistry.get("us-east-1").getRegisteredApplications("TestApp").getByInstanceId("test.east.hostname"));
assertNull(applications.getRegisteredApplications("TestApp").getByInstanceId("test.east.hostname"));
assertNull(remoteRegionsRegistry.get("us-east-1").getRegisteredApplications("TestApp").getByInstanceId("test.west.hostname"));
assertNotNull(applications.getRegisteredApplications("TestApp").getByInstanceId("test.west.hostname"));
代码示例来源:origin: Netflix/eureka
/**
* Test that instancesMap in Application and shuffleVirtualHostNameMap in
* Applications are correctly updated when the last instance is removed from
* an application and shuffleInstances has been run.
*/
@Test
public void shuffleVirtualHostNameMapLastInstanceTest() {
DataCenterInfo myDCI = new DataCenterInfo() {
public DataCenterInfo.Name getName() {
return DataCenterInfo.Name.MyOwn;
}
};
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder().setAppName("test")
.setVIPAddress("test.testname:1").setDataCenterInfo(myDCI).setHostName("test.hostname").build();
Application application = new Application("TestApp");
application.addInstance(instanceInfo);
Applications applications = new Applications();
applications.addApplication(application);
applications.shuffleInstances(true);
List<InstanceInfo> testApp = applications.getInstancesByVirtualHostName("test.testname:1");
assertEquals(Iterables.getOnlyElement(testApp), application.getByInstanceId("test.hostname"));
application.removeInstance(instanceInfo);
assertEquals(0, applications.size());
applications.shuffleInstances(true);
testApp = applications.getInstancesByVirtualHostName("test.testname:1");
assertTrue(testApp.isEmpty());
assertNull(application.getByInstanceId("test.hostname"));
}
代码示例来源:origin: Netflix/eureka
List<InstanceInfo> testApp = applications.getInstancesByVirtualHostName("test.testname:1");
assertEquals(Iterables.getOnlyElement(testApp), application.getByInstanceId("test.hostname"));
assertNull(application.getByInstanceId("test.hostname"));
assertEquals(0, applications.size());
assertTrue(testApp.isEmpty());
assertNull(application.getByInstanceId("test.hostname"));
代码示例来源:origin: Netflix/eureka
@Test
public void testInstanceFiltering() {
DataCenterInfo myDCI = new DataCenterInfo() {
public DataCenterInfo.Name getName() {
return DataCenterInfo.Name.MyOwn;
}
};
InstanceInfo instanceInfo = InstanceInfo.Builder.newBuilder()
.setAppName("test")
.setVIPAddress("test.testname:1")
.setSecureVIPAddress("securetest.testname:7102")
.setDataCenterInfo(myDCI)
.setHostName("test.hostname")
.setStatus(InstanceStatus.DOWN)
.build();
Application application = new Application("TestApp");
application.addInstance(instanceInfo);
Applications applications = new Applications();
applications.addApplication(application);
applications.shuffleInstances(true);
assertNotNull(applications.getRegisteredApplications("TestApp").getByInstanceId("test.hostname"));
assertTrue(applications.getInstancesBySecureVirtualHostName("securetest.testname:7102").isEmpty());
assertTrue(applications.getInstancesBySecureVirtualHostName("test.testname:1").isEmpty());
}
代码示例来源:origin: com.netflix.eureka/eureka2-test-utils
public InstanceInfo findInstance(String instanceId) {
for (Application app : applications.getRegisteredApplications()) {
InstanceInfo instanceInfo = app.getByInstanceId(instanceId);
if (instanceInfo != null) {
return instanceInfo;
}
}
return null;
}
代码示例来源:origin: com.netflix.eureka/eureka-core
@Override
public List<InstanceInfo> getInstancesById(String id) {
List<InstanceInfo> list = Collections.emptyList();
for (Application app : applications.get().getRegisteredApplications()) {
InstanceInfo info = app.getByInstanceId(id);
if (info != null) {
list.add(info);
return list;
}
}
return list;
}
代码示例来源:origin: com.netflix.eureka/eureka-client
@Override
public List<InstanceInfo> getInstancesById(String id) {
List<InstanceInfo> instancesList = new ArrayList<InstanceInfo>();
for (Application app : this.getApplications()
.getRegisteredApplications()) {
InstanceInfo instanceInfo = app.getByInstanceId(id);
if (instanceInfo != null) {
instancesList.add(instanceInfo);
}
}
return instancesList;
}
代码示例来源:origin: saleson/fm-cloud
private boolean isDownline(GrayInstance grayInstance){
Application app = eurekaClient.getApplication(grayInstance.getServiceId());
return app==null || app.getByInstanceId(grayInstance.getInstanceId())==null;
}
}
代码示例来源:origin: SpringCloud/spring-cloud-gray
private boolean isDownline(GrayInstance grayInstance) {
Application app = eurekaClient.getApplication(grayInstance.getServiceId());
return app == null || app.getByInstanceId(grayInstance.getInstanceId()) == null;
}
代码示例来源:origin: com.netflix.eureka/eureka-client
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;
}
}
内容来源于网络,如有侵权,请联系作者删除!