Skip to content

Commit

Permalink
filter registered services returned in /services/v1 api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jitendra Dhawan committed Nov 21, 2024
1 parent 705785c commit 73dff82
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,7 +171,7 @@ public List<ServiceNode<T>> getAllNodes(
@Override
public Collection<Service> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -208,7 +209,7 @@ private void updateRegistry() {
alreadyUpdating.set(true);
val updatedFinders = new ConcurrentHashMap<Service, ServiceFinder<T, R>>();
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -290,11 +291,4 @@ private void waitTillServiceIsReady(Service service) {
}
}

private Set<Service> getEligibleServices() {
return serviceDataSource.services()
.stream()
.filter(service -> !excludedServices.contains(service.getServiceName()))
.collect(Collectors.toSet());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand All @@ -32,6 +33,14 @@
@UtilityClass
public class FinderUtils {

public static Set<Service> getEligibleServices(final Collection<Service> services,
final Set<String> excludedServices) {
return services.stream()
.filter(service -> !excludedServices.contains(service.getServiceName()))
.collect(Collectors.toSet());
}


public static<T> List<ServiceNode<T>> filterValidNodes(
final Service service,
final Collection<ServiceNode<T>> serviceNodes,
Expand Down

0 comments on commit 73dff82

Please sign in to comment.