Search in sources :

Example 56 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class ApplicationsResourceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(20, 6).build();
    testApplications = instanceInfos.toApplications();
    applicationsResource = new ApplicationsResource(serverContext);
    for (Application application : testApplications.getRegisteredApplications()) {
        for (InstanceInfo instanceInfo : application.getInstances()) {
            registry.register(instanceInfo, false);
        }
    }
}
Also used : InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) Before(org.junit.Before)

Example 57 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class InstanceRegistryTest method testGetAppsFromAllRemoteRegions.

@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());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 58 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class AbstractVIPResourceTest method testFullVipGet.

@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));
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 59 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class ApplicationFunctions method toApplicationMap.

public static Map<String, Application> toApplicationMap(List<InstanceInfo> instances) {
    Map<String, Application> applicationMap = new HashMap<String, Application>();
    for (InstanceInfo instance : instances) {
        String appName = instance.getAppName();
        Application application = applicationMap.get(appName);
        if (application == null) {
            applicationMap.put(appName, application = new Application(appName));
        }
        application.addInstance(instance);
    }
    return applicationMap;
}
Also used : HashMap(java.util.HashMap) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 60 with Application

use of com.netflix.discovery.shared.Application in project eureka by Netflix.

the class InstanceInfoGenerator method toApplications.

public Applications toApplications() {
    Map<String, Application> appsByName = new HashMap<>();
    Iterator<InstanceInfo> it = serviceIterator();
    while (it.hasNext()) {
        InstanceInfo instanceInfo = it.next();
        Application instanceApp = appsByName.get(instanceInfo.getAppName());
        if (instanceApp == null) {
            instanceApp = new Application(instanceInfo.getAppName());
            appsByName.put(instanceInfo.getAppName(), instanceApp);
        }
        instanceApp.addInstance(instanceInfo);
    }
    // Do not pass application list to the constructor, as it does not initialize properly Applications
    // data structure.
    Applications applications = new Applications();
    for (Application app : appsByName.values()) {
        applications.addApplication(app);
    }
    applications.shuffleInstances(false);
    applications.setAppsHashCode(applications.getReconcileHashCode());
    applications.setVersion(1L);
    return applications;
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) HashMap(java.util.HashMap) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

Application (com.netflix.discovery.shared.Application)60 InstanceInfo (com.netflix.appinfo.InstanceInfo)35 Applications (com.netflix.discovery.shared.Applications)25 Test (org.junit.Test)18 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 HashMap (java.util.HashMap)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)2 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1