Search in sources :

Example 96 with Applications

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

the class ApplicationFunctions method merge.

public static Applications merge(Applications first, Applications second) {
    Set<String> firstNames = applicationNames(first);
    Set<String> secondNames = applicationNames(second);
    Set<String> allNames = new HashSet<>(firstNames);
    allNames.addAll(secondNames);
    Applications merged = new Applications();
    for (String appName : allNames) {
        if (firstNames.contains(appName)) {
            if (secondNames.contains(appName)) {
                merged.addApplication(merge(first.getRegisteredApplications(appName), second.getRegisteredApplications(appName)));
            } else {
                merged.addApplication(copyOf(first.getRegisteredApplications(appName)));
            }
        } else {
            merged.addApplication(copyOf(second.getRegisteredApplications(appName)));
        }
    }
    return updateMeta(merged);
}
Also used : Applications(com.netflix.discovery.shared.Applications) HashSet(java.util.HashSet)

Example 97 with Applications

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

the class InstanceInfoGenerator method takeDelta.

public Applications takeDelta(int count) {
    if (currentIt == null) {
        currentIt = serviceIterator();
        allApplications = new Applications();
    }
    List<InstanceInfo> instanceBatch = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        InstanceInfo next = currentIt.next();
        next.setActionType(ActionType.ADDED);
        instanceBatch.add(next);
    }
    Applications nextBatch = EurekaEntityFunctions.toApplications(toApplicationMap(instanceBatch));
    allApplications = mergeApplications(allApplications, nextBatch);
    nextBatch.setAppsHashCode(allApplications.getAppsHashCode());
    return nextBatch;
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 98 with Applications

use of com.netflix.discovery.shared.Applications 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 99 with Applications

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

the class InstanceInfoGenerator method takeDeltaForDelete.

public Applications takeDeltaForDelete(boolean useInstanceId, int instanceCount) {
    List<InstanceInfo> instanceInfoList = new ArrayList<>();
    for (int i = 0; i < instanceCount; i++) {
        instanceInfoList.add(this.generateInstanceInfo(i, i, useInstanceId, ActionType.DELETED));
    }
    Applications delete = EurekaEntityFunctions.toApplications(toApplicationMap(instanceInfoList));
    allApplications = mergeApplications(allApplications, delete);
    delete.setAppsHashCode(allApplications.getAppsHashCode());
    return delete;
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) ArrayList(java.util.ArrayList) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Example 100 with Applications

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

the class SimpleEurekaHttpServer method handleVipsGET.

private void handleVipsGET(HttpExchange httpExchange) throws IOException {
    Matcher matcher = Pattern.compile("/v2/vips/([^/]+)").matcher(httpExchange.getRequestURI().getPath());
    if (matcher.matches()) {
        String regions = getQueryParam(httpExchange, "regions");
        EurekaHttpResponse<Applications> httpResponse = regions == null ? requestHandler.getVip(matcher.group(1)) : requestHandler.getVip(matcher.group(1), regions);
        mapResponse(httpExchange, httpResponse);
    } else {
        httpExchange.sendResponseHeaders(HttpServletResponse.SC_NOT_FOUND, 0);
    }
}
Also used : Applications(com.netflix.discovery.shared.Applications) Matcher(java.util.regex.Matcher)

Aggregations

Applications (com.netflix.discovery.shared.Applications)120 Test (org.junit.Test)68 Application (com.netflix.discovery.shared.Application)41 InstanceInfo (com.netflix.appinfo.InstanceInfo)29 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)13 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)13 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)10 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 XStream (com.thoughtworks.xstream.XStream)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InputStream (java.io.InputStream)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 FileInputStream (java.io.FileInputStream)4 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4