Search in sources :

Example 71 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 72 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)

Example 73 with Application

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

the class BaseDiscoveryClientTester method createRemoteAppsDelta.

protected static List<Application> createRemoteAppsDelta() {
    Application myapp1 = new Application(REMOTE_REGION_APP1_NAME);
    InstanceInfo instanceInfo1 = createInstance(REMOTE_REGION_APP1_NAME, ALL_REGIONS_VIP1_ADDR, REMOTE_REGION_APP1_INSTANCE2_HOSTNAME, REMOTE_ZONE);
    instanceInfo1.setActionType(InstanceInfo.ActionType.ADDED);
    myapp1.addInstance(instanceInfo1);
    Application myapp2 = new Application(REMOTE_REGION_APP2_NAME);
    InstanceInfo instanceInfo2 = createInstance(REMOTE_REGION_APP2_NAME, ALL_REGIONS_VIP2_ADDR, REMOTE_REGION_APP2_INSTANCE2_HOSTNAME, REMOTE_ZONE);
    instanceInfo2.setActionType(InstanceInfo.ActionType.ADDED);
    myapp2.addInstance(instanceInfo2);
    return Arrays.asList(myapp1, myapp2);
}
Also used : Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 74 with Application

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

the class AbstractJerseyEurekaHttpClient method getApplication.

@Override
public EurekaHttpResponse<Application> getApplication(String appName) {
    String urlPath = "apps/" + appName;
    ClientResponse response = null;
    try {
        Builder requestBuilder = jerseyClient.resource(serviceUrl).path(urlPath).getRequestBuilder();
        addExtraHeaders(requestBuilder);
        response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
        Application application = null;
        if (response.getStatus() == Status.OK.getStatusCode() && response.hasEntity()) {
            application = response.getEntity(Application.class);
        }
        return anEurekaHttpResponse(response.getStatus(), Application.class).headers(headersOf(response)).entity(application).build();
    } finally {
        if (logger.isDebugEnabled()) {
            logger.debug("Jersey HTTP GET {}{}; statusCode={}", serviceUrl, urlPath, response == null ? "N/A" : response.getStatus());
        }
        if (response != null) {
            response.close();
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) EurekaHttpResponseBuilder(com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder) Builder(com.sun.jersey.api.client.WebResource.Builder) Application(com.netflix.discovery.shared.Application)

Example 75 with Application

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

the class EurekaEntityComparators method equal.

public static boolean equal(Applications first, Applications second) {
    if (first == second) {
        return true;
    }
    if (first == null || first == null && second != null) {
        return false;
    }
    List<Application> firstApps = first.getRegisteredApplications();
    List<Application> secondApps = second.getRegisteredApplications();
    if (firstApps == null && secondApps == null) {
        return true;
    }
    if (firstApps == null || secondApps == null || firstApps.size() != secondApps.size()) {
        return false;
    }
    for (Application firstApp : firstApps) {
        Application secondApp = second.getRegisteredApplications(firstApp.getName());
        if (!equal(firstApp, secondApp)) {
            return false;
        }
    }
    return true;
}
Also used : Application(com.netflix.discovery.shared.Application)

Aggregations

Application (com.netflix.discovery.shared.Application)104 InstanceInfo (com.netflix.appinfo.InstanceInfo)51 Test (org.junit.Test)43 Applications (com.netflix.discovery.shared.Applications)41 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Map (java.util.Map)6 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)4 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 AmazonInfo (com.netflix.appinfo.AmazonInfo)2 InstanceStatus (com.netflix.appinfo.InstanceInfo.InstanceStatus)2 Pair (com.netflix.discovery.shared.Pair)2