Java Code Examples for com.netflix.discovery.shared.Applications#getRegisteredApplications()
The following examples show how to use
com.netflix.discovery.shared.Applications#getRegisteredApplications() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MossInstanceDiscoveryListener.java From Moss with Apache License 2.0 | 6 votes |
public List<String> getServicesByEureka() { Applications applications = cloudEurekaClient.get().getApplications(); if (applications == null) { return Collections.emptyList(); } List<Application> registered = applications.getRegisteredApplications(); List<String> names = new ArrayList<>(); for (Application app : registered) { if (app.getInstances().isEmpty()) { continue; } names.add(app.getName().toLowerCase()); } return names; }
Example 2
Source File: InstanceRefreshService.java From api-layer with Eclipse Public License 2.0 | 6 votes |
/** * Get this instance service details and check if it should be processed * * @param containersUpdated containers, which were updated * @param cachedServices existing services * @param deltaFromDiscovery changed service instances * @param instance this instance */ private void processServiceInstance(Set<String> containersUpdated, Applications cachedServices, Applications deltaFromDiscovery, InstanceInfo instance) { Application application = null; // Get the application which this instance belongs to if (cachedServices != null && cachedServices.getRegisteredApplications() != null) { application = cachedServices.getRegisteredApplications().stream() .filter(service -> service.getName().equalsIgnoreCase(instance.getAppName())).findFirst().orElse(null); } // if its new then it will only be in the delta if (application == null || application.getInstances().isEmpty()) { application = deltaFromDiscovery.getRegisteredApplications().stream() .filter(service -> service.getName().equalsIgnoreCase(instance.getAppName())).findFirst().orElse(null); } // there's no chance which this case is not called. It's just double check if (application == null || application.getInstances().isEmpty()) { log.debug("Instance {} couldn't get details from cache and delta", instance.getAppName()); return; } processInstance(containersUpdated, instance, application); }
Example 3
Source File: InstanceRefreshService.java From api-layer with Eclipse Public License 2.0 | 6 votes |
/** * Compare cached instances against eureka delta to send back a change-list * * @param delta retrieved from Eureka * @return changed instances */ private Set<InstanceInfo> updateDelta(Applications delta) { int deltaCount = 0; Set<InstanceInfo> updatedInstances = new HashSet<>(); for (Application app : delta.getRegisteredApplications()) { for (InstanceInfo instance : app.getInstances()) { ++deltaCount; if (InstanceInfo.ActionType.ADDED.equals(instance.getActionType())) { log.debug("Added instance {} to the list of changed instances ", instance.getId()); updatedInstances.add(instance); } else if (InstanceInfo.ActionType.MODIFIED.equals(instance.getActionType())) { log.debug("Modified instance {} added to the list of changed instances ", instance.getId()); updatedInstances.add(instance); } else if (InstanceInfo.ActionType.DELETED.equals(instance.getActionType())) { log.debug("Deleted instance {} added to the list of changed instances ", instance.getId()); instance.setStatus(InstanceInfo.InstanceStatus.DOWN); updatedInstances.add(instance); } } } log.debug("The total number of changed instances fetched by the delta processor : {}", deltaCount); return updatedInstances; }
Example 4
Source File: InstanceRetrievalServiceTest.java From api-layer with Eclipse Public License 2.0 | 6 votes |
@Test public void testGetAllInstancesFromDiscovery_whenNeedApplicationsWithoutFilter() throws JsonProcessingException { Map<String, InstanceInfo> instanceInfoMap = createInstances(); Applications expectedApplications = new Applications(); instanceInfoMap.forEach((key, value) -> expectedApplications.addApplication(new Application(value.getAppName(), Collections.singletonList(value)))); ObjectMapper mapper = new ObjectMapper(); String bodyAll = mapper.writeValueAsString(new ApplicationsWrapper(expectedApplications)); mockRetrieveApplicationService(discoveryServiceAllAppsUrl, bodyAll); Applications actualApplications = instanceRetrievalService.getAllInstancesFromDiscovery(false); assertEquals(expectedApplications.size(), actualApplications.size()); List<Application> actualApplicationList = new ArrayList<>(actualApplications.getRegisteredApplications()); expectedApplications .getRegisteredApplications() .forEach(expectedApplication -> assertThat(actualApplicationList, hasItem(hasProperty("name", equalTo(expectedApplication.getName())))) ); }
Example 5
Source File: EurekaDiscoveryClient.java From spring-cloud-netflix with Apache License 2.0 | 6 votes |
@Override public List<String> getServices() { Applications applications = this.eurekaClient.getApplications(); if (applications == null) { return Collections.emptyList(); } List<Application> registered = applications.getRegisteredApplications(); List<String> names = new ArrayList<>(); for (Application app : registered) { if (app.getInstances().isEmpty()) { continue; } names.add(app.getName().toLowerCase()); } return names; }
Example 6
Source File: EurekaResource.java From karyon with Apache License 2.0 | 6 votes |
@GET public Response getEurekaDetails() { List<EurekaInstanceInfo> instanceInfoList = new ArrayList<EurekaInstanceInfo>(); DiscoveryClient discoveryClient = DiscoveryManager.getInstance().getDiscoveryClient(); if (null != discoveryClient) { Applications apps = discoveryClient.getApplications(); for (Application app : apps.getRegisteredApplications()) { for (InstanceInfo inst : app.getInstances()) { instanceInfoList.add(new EurekaInstanceInfo(inst.getAppName(), inst.getId(), inst.getStatus().name(), inst.getIPAddr(), inst.getHostName())); } } } GsonBuilder gsonBuilder = new GsonBuilder().serializeNulls(); Gson gson = gsonBuilder.create(); String response = gson.toJson(new KaryonAdminResponse(instanceInfoList)); return Response.ok(response).build(); }
Example 7
Source File: EurekaServiceDiscovery.java From spring-cloud-gray with Apache License 2.0 | 5 votes |
@Override public List<ServiceInfo> listAllSerivceInfos() { Applications applications = eurekaClient.getApplications(); if (applications == null) { return Collections.emptyList(); } List<Application> applicationList = applications.getRegisteredApplications(); return applicationList.stream().map(this::ofApplication).collect(Collectors.toList()); }
Example 8
Source File: InstanceRetrievalServiceTest.java From api-layer with Eclipse Public License 2.0 | 5 votes |
@Test public void testGetAllInstancesFromDiscovery_whenNeedApplicationsWithDeltaFilter() throws JsonProcessingException { String discoveryServiceAppsUrl = discoveryConfigProperties.getLocations() + APPS_ENDPOINT + DELTA_ENDPOINT; Map<String, InstanceInfo> instanceInfoMap = createInstances(); Applications expectedApplications = new Applications(); instanceInfoMap.forEach((key, value) -> expectedApplications.addApplication(new Application(value.getAppName(), Collections.singletonList(value)))); ObjectMapper mapper = new ObjectMapper(); String bodyAll = mapper.writeValueAsString(new ApplicationsWrapper(expectedApplications)); mockRetrieveApplicationService(discoveryServiceAppsUrl, bodyAll); Applications actualApplications = instanceRetrievalService.getAllInstancesFromDiscovery(true); assertEquals(expectedApplications.size(), actualApplications.size()); List<Application> actualApplicationList = new ArrayList<>(actualApplications.getRegisteredApplications()); expectedApplications .getRegisteredApplications() .forEach(expectedApplication -> assertThat(actualApplicationList, hasItem(hasProperty("name", equalTo(expectedApplication.getName())))) ); }
Example 9
Source File: ArmeriaEurekaClientTest.java From armeria with Apache License 2.0 | 5 votes |
private static List<Endpoint> endpointsFromApplications(Applications applications, boolean secureVip) { final Builder<Endpoint> builder = ImmutableList.builder(); for (Application application : applications.getRegisteredApplications()) { builder.addAll(endpointsFromApplication(application, secureVip)); } return builder.build(); }
Example 10
Source File: EurekaHealthIndicator.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
private Map<String, Object> getApplications() { Applications applications = this.eurekaClient.getApplications(); if (applications == null) { return Collections.emptyMap(); } Map<String, Object> result = new HashMap<>(); for (Application application : applications.getRegisteredApplications()) { if (!application.getInstances().isEmpty()) { result.put(application.getName(), application.getInstances().size()); } } return result; }
Example 11
Source File: EurekaApplications.java From api-layer with Eclipse Public License 2.0 | 4 votes |
public List<Application> getRegistered() { Applications applications = eurekaClient.getApplications(); return applications.getRegisteredApplications(); }