From 73dff82d07a828f126f33ccadf70d69e227b2036 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 16:58:04 +0530 Subject: [PATCH] filter registered services returned in /services/v1 api --- .../ranger/client/AbstractRangerHubClient.java | 4 +++- .../ranger/core/finderhub/ServiceFinderHub.java | 12 +++--------- .../io/appform/ranger/core/util/FinderUtils.java | 9 +++++++++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ranger-client/src/main/java/io/appform/ranger/client/AbstractRangerHubClient.java b/ranger-client/src/main/java/io/appform/ranger/client/AbstractRangerHubClient.java index 4c52d290..f48b6b38 100644 --- a/ranger-client/src/main/java/io/appform/ranger/client/AbstractRangerHubClient.java +++ b/ranger-client/src/main/java/io/appform/ranger/client/AbstractRangerHubClient.java @@ -32,6 +32,8 @@ import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import java.util.stream.Collectors; + +import io.appform.ranger.core.util.FinderUtils; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; @@ -169,7 +171,7 @@ public List> getAllNodes( @Override public Collection getRegisteredServices() { try { - return this.getHub().getServiceDataSource().services(); + return FinderUtils.getEligibleServices(this.getHub().getServiceDataSource().services(), excludedServices); } catch (Exception e) { log.error("Call to the hub failed with exception, {}", e.getMessage()); diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java index 5785c41c..d01ad3ff 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHub.java @@ -26,6 +26,7 @@ import io.appform.ranger.core.signals.ScheduledSignal; import io.appform.ranger.core.signals.Signal; import io.appform.ranger.core.util.Exceptions; +import io.appform.ranger.core.util.FinderUtils; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -208,7 +209,7 @@ private void updateRegistry() { alreadyUpdating.set(true); val updatedFinders = new ConcurrentHashMap>(); try { - val services = getEligibleServices(); + val services = FinderUtils.getEligibleServices(serviceDataSource.services(), excludedServices); if (services.isEmpty()) { log.debug("No services found for the service data source. Skipping update on the registry"); return; @@ -243,7 +244,7 @@ private void updateRegistry() { } private void waitTillHubIsReady() { - val services = getEligibleServices(); + val services = FinderUtils.getEligibleServices(serviceDataSource.services(), excludedServices); val timeToRefresh = Math.max(hubStartTimeoutMs, (serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism()); if (timeToRefresh != hubStartTimeoutMs) { @@ -290,11 +291,4 @@ private void waitTillServiceIsReady(Service service) { } } - private Set getEligibleServices() { - return serviceDataSource.services() - .stream() - .filter(service -> !excludedServices.contains(service.getServiceName())) - .collect(Collectors.toSet()); - } - } diff --git a/ranger-core/src/main/java/io/appform/ranger/core/util/FinderUtils.java b/ranger-core/src/main/java/io/appform/ranger/core/util/FinderUtils.java index 5fa2f760..412486b4 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/util/FinderUtils.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/util/FinderUtils.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; /** @@ -32,6 +33,14 @@ @UtilityClass public class FinderUtils { + public static Set getEligibleServices(final Collection services, + final Set excludedServices) { + return services.stream() + .filter(service -> !excludedServices.contains(service.getServiceName())) + .collect(Collectors.toSet()); + } + + public static List> filterValidNodes( final Service service, final Collection> serviceNodes,