public static Set<String> applicationNames(Applications applications) { Set<String> names = new HashSet<String>(); for (Application application : applications.getRegisteredApplications()) { names.add(application.getName()); } return names; }
/** * Remove the <em>application</em> from the list. * * @param app the <em>application</em> */ public void removeApplication(Application app) { this.appNameApplicationMap.remove(app.getName().toUpperCase(Locale.ROOT)); this.applications.remove(app); } }
public static Set<String> selectApplicationNames(Applications applications) { Set<String> result = new HashSet<>(); for (Application app : applications.getRegisteredApplications()) { result.add(app.getName()); } return result; }
@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(); } }
/** * Add the <em>application</em> to the list. * * @param app * the <em>application</em> to be added. */ public void addApplication(Application app) { appNameApplicationMap.put(app.getName().toUpperCase(Locale.ROOT), app); addInstancesToVIPMaps(app, this.virtualHostNameAppMap, this.secureVirtualHostNameAppMap); applications.add(app); }
public static Application copyOf(Application application) { Application copy = new Application(application.getName()); for (InstanceInfo instance : application.getInstances()) { copy.addInstance(instance); } return copy; }
public static Application copyApplication(Application application) { Application copy = new Application(application.getName()); for (InstanceInfo instance : application.getInstances()) { copy.addInstance(instance); } return copy; }
public static Application deepCopyApplication(Application source) { Application result = new Application(source.getName()); deepCopyApplication(source, result, EurekaEntityTransformers.<InstanceInfo>identity()); return result; }
/** * Generate pay load with both JSON and XML formats for a given application. */ private String getPayLoad(Key key, Application app) { if (app == null) { return EMPTY_PAYLOAD; } EncoderWrapper encoderWrapper = serverCodecs.getEncoder(key.getType(), key.getEurekaAccept()); try { return encoderWrapper.encode(app); } catch (Exception e) { logger.error("Failed to encode the payload for application {}", app.getName(), e); return ""; } }
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 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()); }
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Application app = (Application) source; writer.startNode(ELEM_NAME); writer.setValue(app.getName()); writer.endNode(); for (InstanceInfo instanceInfo : app.getInstances()) { writer.startNode(NODE_INSTANCE); context.convertAnother(instanceInfo); writer.endNode(); } }
@Test public void testFullVipGet() throws Exception { Response response = resource.getVipResponse( Version.V2.name(), vipName, MediaType.APPLICATION_JSON, EurekaAccept.full, 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()); assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(true)); }
@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()); }
@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()); }
@Test public void testRemoteEnabledAndQueried() throws Exception { setUp(true); Applications applications = client.getApplicationsForARegion(REMOTE_REGION); List<Application> registeredApplications = applications.getRegisteredApplications(); Assert.assertNotNull("Remote region apps not found.", registeredApplications); Assert.assertEquals("Remote apps size not as expected.", 1, registeredApplications.size()); Assert.assertEquals("Remote region apps not present.", REMOTE_REGION_APP_NAME, registeredApplications.get(0).getName()); }
@Override @Before public void setUp() throws Exception { super.setUp(); InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(6, 1).build(); testApplication = instanceInfos.toApplications().getRegisteredApplications().get(0); applicationResource = new ApplicationResource(testApplication.getName(), serverContext.getServerConfig(), serverContext.getRegistry()); for (InstanceInfo instanceInfo : testApplication.getInstances()) { registry.register(instanceInfo, false); } }