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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations