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