Search in sources :

Example 81 with Applications

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

the class SimpleEurekaHttpServer method handleSecureVipsGET.

private void handleSecureVipsGET(HttpExchange httpExchange) throws IOException {
    Matcher matcher = Pattern.compile("/v2/svips/([^/]+)").matcher(httpExchange.getRequestURI().getPath());
    if (matcher.matches()) {
        String regions = getQueryParam(httpExchange, "regions");
        EurekaHttpResponse<Applications> httpResponse = regions == null ? requestHandler.getSecureVip(matcher.group(1)) : requestHandler.getSecureVip(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)

Example 82 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)

Example 83 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<String>(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 84 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 85 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<InstanceInfo>();
    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)

Aggregations

Applications (com.netflix.discovery.shared.Applications)85 Test (org.junit.Test)43 Application (com.netflix.discovery.shared.Application)25 InstanceInfo (com.netflix.appinfo.InstanceInfo)22 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)11 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)10 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)8 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Response (javax.ws.rs.core.Response)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3