public static InstanceInfo takeFirst(Applications applications) { for (Application application : applications.getRegisteredApplications()) { if (!application.getInstances().isEmpty()) { return application.getInstances().get(0); } } return null; }
public static int countInstances(Applications applications) { int count = 0; for(Application application: applications.getRegisteredApplications()) { count += application.getInstances().size(); } return count; } }
@Override public void serialize(Application value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeStringField(ELEM_NAME, value.getName()); jgen.writeObjectField(ELEM_INSTANCE, value.getInstances()); jgen.writeEndObject(); } }
public static Map<String, InstanceInfo> selectInstancesMappedById(Application application) { Map<String, InstanceInfo> result = new HashMap<>(); for (InstanceInfo instance : application.getInstances()) { result.put(instance.getId(), instance); } return result; }
public static void copyApplication(Application source, Application result) { if (source != null) { for (InstanceInfo instance : source.getInstances()) { result.addInstance(instance); } } }
public List<InstanceInfo> getMetaServiceInstances() { Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_METASERVICE); if (application == null) { Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_METASERVICE); } return application != null ? application.getInstances() : Collections.emptyList(); }
public List<InstanceInfo> getAdminServiceInstances() { Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_ADMINSERVICE); if (application == null) { Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_ADMINSERVICE); } return application != null ? application.getInstances() : Collections.emptyList(); } }
public List<InstanceInfo> getConfigServiceInstances() { Application application = eurekaClient.getApplication(ServiceNameConsts.APOLLO_CONFIGSERVICE); if (application == null) { Tracer.logEvent("Apollo.EurekaDiscovery.NotFound", ServiceNameConsts.APOLLO_CONFIGSERVICE); } return application != null ? application.getInstances() : Collections.emptyList(); }
public static InstanceInfo selectInstance(Applications applications, String id) { for (Application application : applications.getRegisteredApplications()) { for (InstanceInfo instance : application.getInstances()) { if (instance.getId().equals(id)) { return instance; } } } return null; }
private static String stringifyAppMap(Map<String, Application> applicationMap) { StringBuilder builder = new StringBuilder(); for (Map.Entry<String, Application> entry : applicationMap.entrySet()) { String entryAsString = String.format("{ name : %s , instance count: %d }", entry.getKey(), entry.getValue().getInstances().size()); builder.append(entryAsString); } return builder.toString(); }
public static Application copyApplication(Application application) { Application copy = new Application(application.getName()); for (InstanceInfo instance : application.getInstances()) { copy.addInstance(instance); } return copy; }
public static void deepCopyApplication(Application source, Application result, Transformer<InstanceInfo> transformer) { for (InstanceInfo instance : source.getInstances()) { InstanceInfo copy = transformer.apply(instance); if (copy == instance) { copy = new InstanceInfo(instance); } result.addInstance(copy); } }
@Override public Boolean call() throws Exception { List<Application> applicationList = client.getApplications().getRegisteredApplications(); return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2; } }, 1, TimeUnit.MINUTES);
public static void copyApplications(Applications source, Applications result) { if (source != null) { for (Application app : source.getRegisteredApplications()) { result.addApplication(new Application(app.getName(), app.getInstances())); } } }
@Test public void testGetVipWithRemoteRegionRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress(); when(requestHandler.getVip(vipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress, REMOTE_REGION); verifyResponseOkWithEntity(vipApps, httpResponse); }
@Test public void testGetSecureVipWithRemoteRegionRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String secureVipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getSecureVipAddress(); when(requestHandler.getSecureVip(secureVipAddress, REMOTE_REGION)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getSecureVip(secureVipAddress, REMOTE_REGION); verifyResponseOkWithEntity(vipApps, httpResponse); }
@Test public void testGetVipRequest() throws Exception { Applications vipApps = InstanceInfoGenerator.newBuilder(1, 2).build().toApplications(); String vipAddress = vipApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress(); when(requestHandler.getVip(vipAddress)).thenReturn(createResponse(vipApps)); EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getVip(vipAddress); verifyResponseOkWithEntity(vipApps, httpResponse); }
@Test public void testGetAppsFromAllRemoteRegions() throws Exception { Applications apps = registry.getApplicationsFromAllRemoteRegions(); List<Application> registeredApplications = apps.getRegisteredApplications(); Assert.assertEquals("Apps size from remote regions do not match", 1, registeredApplications.size()); Application app = registeredApplications.iterator().next(); Assert.assertEquals("Added app did not return from remote registry", REMOTE_REGION_APP_NAME, app.getName()); Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size()); }
@Before public void setUp() { when(clientConfig.getEurekaServerURLContext()).thenReturn("context"); when(clientConfig.getRegion()).thenReturn("region"); applications = InstanceInfoGenerator.newBuilder(5, "eurekaRead", "someOther").build().toApplications(); vipAddress = applications.getRegisteredApplications("eurekaRead").getInstances().get(0).getVIPAddress(); when(clientFactory.newClient()).thenReturn(httpClient); when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, applications).build()); resolver = new EurekaHttpResolver(clientConfig, transportConfig, clientFactory, vipAddress); }
@Test public void testGetAppsFromLocalRegionOnly() throws Exception { registerInstanceLocally(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME)); Applications apps = registry.getApplicationsFromLocalRegionOnly(); List<Application> registeredApplications = apps.getRegisteredApplications(); Assert.assertEquals("Apps size from local region do not match", 1, registeredApplications.size()); Application app = registeredApplications.iterator().next(); Assert.assertEquals("Added app did not return from local registry", LOCAL_REGION_APP_NAME, app.getName()); Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size()); }