From f82cb9c2e0ef76985a145d1e6769caabe15257a1 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 08:43:17 +0530 Subject: [PATCH 01/10] add feature to exclude services , fix ranger health check registration and throw exception when zk node data source fails to read --- .../client/AbstractRangerHubClient.java | 29 ++++++++++----- .../ranger/client/stubs/RangerTestHub.java | 3 +- .../ServiceRegistryUpdater.java | 2 +- .../core/finderhub/ServiceFinderHub.java | 37 ++++++++++--------- .../finderhub/ServiceFinderHubBuilder.java | 20 +++++++--- .../ranger/core/model/HubConstants.java | 6 ++- .../drove/AbstractRangerDroveHubClient.java | 20 +++++----- .../DroveServiceDataSource.java | 8 +++- .../DroveServiceDataSourceTest.java | 4 +- .../http/AbstractRangerHttpHubClient.java | 11 ++++-- .../HttpServiceDataSource.java | 15 ++++++-- .../HttpServiceDataSourceTest.java | 4 +- .../server/bundle/RangerHubServerBundle.java | 22 ++++++----- .../RangerServerConfiguration.java | 12 ++++++ .../RangerUpstreamConfiguration.java | 7 +++- .../bundle/healthcheck/RangerHealthCheck.java | 14 ++++--- .../client/zk/AbstractRangerZKHubClient.java | 10 +++-- .../ZkCommunicationException.java | 29 +++++++++++++++ .../servicefinder/ZkNodeDataSource.java | 8 +++- .../servicefinderhub/ZkServiceDataSource.java | 5 +++ .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 21 files changed, 187 insertions(+), 81 deletions(-) create mode 100644 ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkCommunicationException.java 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 4c816a86..e04926fc 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 @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; import lombok.Getter; @@ -48,6 +49,9 @@ public abstract class AbstractRangerHubClient, D private ServiceDataSource serviceDataSource; private long serviceRefreshDurationMs; private long hubRefreshDurationMs; + private long serviceRefreshTimeoutMs; + private long hubStartTimeoutMs; + private Set excludedServices; @Override public void start() { @@ -62,23 +66,28 @@ public void start() { } this.nodeRefreshTimeMs = Math.max(HubConstants.MINIMUM_REFRESH_TIME_MS, this.nodeRefreshTimeMs); - if (this.serviceRefreshDurationMs <= 0) { + if (this.serviceRefreshTimeoutMs <= 0) { log.warn("Service Refresh interval too low: {} ms. Has been upgraded to {} ms ", - this.serviceRefreshDurationMs, - HubConstants.SERVICE_REFRESH_DURATION_MS); - this.serviceRefreshDurationMs = HubConstants.SERVICE_REFRESH_DURATION_MS; + this.serviceRefreshTimeoutMs, + HubConstants.SERVICE_REFRESH_TIMEOUT_MS); + this.serviceRefreshTimeoutMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; } - if (this.hubRefreshDurationMs <= 0) { + if (this.hubStartTimeoutMs <= 0) { log.warn("Hub Refresh interval too low: {} ms. Has been upgraded to {} ms ", - this.hubRefreshDurationMs, - HubConstants.HUB_REFRESH_DURATION_MS); - this.hubRefreshDurationMs = HubConstants.HUB_REFRESH_DURATION_MS; + this.hubStartTimeoutMs, + HubConstants.HUB_START_TIMEOUT_MS); + this.hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; + } + + if(null == this.excludedServices){ + this.excludedServices = Collections.emptySet(); } if(null == this.serviceDataSource){ - this.serviceDataSource = getDefaultDataSource(); + this.serviceDataSource = getDefaultDataSource(this.excludedServices); } + this.hub = buildHub(); this.hub.start(); } @@ -181,7 +190,7 @@ public CompletableFuture addService(Service service) { } - protected abstract ServiceDataSource getDefaultDataSource(); + protected abstract ServiceDataSource getDefaultDataSource(final Set excludedServices); protected abstract ServiceFinderFactory getFinderFactory(); diff --git a/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java b/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java index ac46feb3..bb5a6d8f 100644 --- a/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java +++ b/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java @@ -23,6 +23,7 @@ import io.appform.ranger.core.units.TestNodeData; import lombok.Builder; import lombok.Getter; +import java.util.Set; import lombok.experimental.SuperBuilder; @Getter @@ -51,7 +52,7 @@ protected void postBuild(ServiceFinderHub excludedServices) { return new StaticDataSource(Sets.newHashSet(RangerHubTestUtils.service)); } diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 92a2b340..39da1cb4 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -47,7 +47,7 @@ public class ServiceRegistryUpdater> { private final Lock checkLock = new ReentrantLock(); private final Condition checkCondition = checkLock.newCondition(); - private boolean checkForUpdate = false; + private volatile boolean checkForUpdate = false; private Future queryThreadFuture; private final ExecutorService executorService = Executors.newFixedThreadPool(1); 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 2611b4f0..ef7a2c1d 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 @@ -17,6 +17,7 @@ import com.github.rholder.retry.RetryerBuilder; import com.github.rholder.retry.StopStrategies; +import com.github.rholder.retry.WaitStrategies; import com.google.common.base.Stopwatch; import io.appform.ranger.core.finder.ServiceFinder; import io.appform.ranger.core.model.HubConstants; @@ -52,7 +53,7 @@ public class ServiceFinderHub> { new AtomicReference<>(new ConcurrentHashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); - private boolean updateAvailable = false; + private volatile boolean updateAvailable = false; private final ExecutorService executorService = Executors.newFixedThreadPool(1); @Getter @@ -72,32 +73,32 @@ public class ServiceFinderHub> { private final AtomicInteger poolThreadIndex = new AtomicInteger(0); private Future monitorFuture = null; - private final long serviceRefreshDurationMs; - private final long hubRefreshDurationMs; + private final long serviceRefreshTimeoutMs; + private final long hubStartTimeoutMs; private final ForkJoinPool refresherPool; public ServiceFinderHub( ServiceDataSource serviceDataSource, ServiceFinderFactory finderFactory - ) { + ) { this(serviceDataSource, finderFactory, - HubConstants.SERVICE_REFRESH_DURATION_MS, HubConstants.HUB_REFRESH_DURATION_MS); + HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS); } public ServiceFinderHub( ServiceDataSource serviceDataSource, ServiceFinderFactory finderFactory, - long serviceRefreshDurationMs, - long hubRefreshDurationMs) { + long serviceRefreshTimeoutMs, + long hubStartTimeoutMs) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; - this.serviceRefreshDurationMs = serviceRefreshDurationMs == 0 ? HubConstants.SERVICE_REFRESH_DURATION_MS : serviceRefreshDurationMs; - this.hubRefreshDurationMs = hubRefreshDurationMs == 0 ? HubConstants.HUB_REFRESH_DURATION_MS : hubRefreshDurationMs; + this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs == 0 ? HubConstants.SERVICE_REFRESH_TIMEOUT_MS : serviceRefreshTimeoutMs; + this.hubStartTimeoutMs = hubStartTimeoutMs == 0 ? HubConstants.HUB_START_TIMEOUT_MS : hubStartTimeoutMs; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", - () -> null, - Collections.emptyList(), - 10_000)); + () -> null, + Collections.emptyList(), + 10_000)); this.refresherPool = createRefresherPool(); } @@ -240,12 +241,12 @@ private void updateRegistry() { private void waitTillHubIsReady() { val services = serviceDataSource.services(); - val timeToRefresh = Math.max(hubRefreshDurationMs, - (serviceRefreshDurationMs * services.size()) / refresherPool.getParallelism()); - if (timeToRefresh != hubRefreshDurationMs) { + val timeToRefresh = Math.max(hubStartTimeoutMs, + (serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism()); + if (timeToRefresh != hubStartTimeoutMs) { log.warn("Max hub refresh time has been dynamically adjusted to {} ms from the provided {} ms as the " + - "provided time would have been insufficient to refresh {} services.", - timeToRefresh, hubRefreshDurationMs, services.size()); + "provided time would have been insufficient to refresh {} services.", + timeToRefresh, hubStartTimeoutMs, services.size()); } val hubRefresher = CompletableFuture.allOf( services.stream() @@ -273,7 +274,7 @@ private void waitTillServiceIsReady(Service service) { try { RetryerBuilder.newBuilder() .retryIfResult(r -> !r) - .withStopStrategy(StopStrategies.stopAfterDelay(serviceRefreshDurationMs, TimeUnit.MILLISECONDS)) + .withStopStrategy(StopStrategies.stopAfterDelay(serviceRefreshTimeoutMs, TimeUnit.MILLISECONDS)) .build() .call(() -> Optional.ofNullable(getFinders().get().get(service)) .map(ServiceFinder::getServiceRegistry) diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 4a47b397..4dfe8970 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -20,6 +20,8 @@ import io.appform.ranger.core.model.ServiceRegistry; import io.appform.ranger.core.signals.ScheduledSignal; import io.appform.ranger.core.signals.Signal; +import java.util.HashSet; +import java.util.Set; import lombok.val; import java.util.ArrayList; @@ -38,8 +40,9 @@ public abstract class ServiceFinderHubBuilder> { private final List> extraStartSignalConsumers = new ArrayList<>(); private final List> extraStopSignalConsumers = new ArrayList<>(); private final List> extraRefreshSignals = new ArrayList<>(); - private long serviceRefreshDurationMs = HubConstants.SERVICE_REFRESH_DURATION_MS; - private long hubRefreshDurationMs = HubConstants.HUB_REFRESH_DURATION_MS; + private long serviceRefreshDurationMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; + private long hubRefreshDurationMs = HubConstants.HUB_START_TIMEOUT_MS; + private Set excludedServices = new HashSet<>(); public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { this.serviceDataSource = serviceDataSource; @@ -50,7 +53,7 @@ public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFacto this.serviceFinderFactory = serviceFinderFactory; return this; } - + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; @@ -81,6 +84,11 @@ public ServiceFinderHubBuilder withHubRefreshDuration(long hubRefreshDurat return this; } + public ServiceFinderHubBuilder withExcludedServices(Set excludedServices) { + this.excludedServices = excludedServices; + return this; + } + public ServiceFinderHub build() { preBuild(); Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); @@ -89,9 +97,9 @@ public ServiceFinderHub build() { val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshDurationMs, hubRefreshDurationMs); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", - () -> null, - Collections.emptyList(), - refreshFrequencyMs); + () -> null, + Collections.emptyList(), + refreshFrequencyMs); hub.registerUpdateSignal(refreshSignal); extraRefreshSignals.forEach(hub::registerUpdateSignal); diff --git a/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java b/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java index 6e782d8f..fa7eb0b0 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java @@ -19,9 +19,11 @@ @UtilityClass public class HubConstants { - public static final long SERVICE_REFRESH_DURATION_MS = 10_000; - public static final long HUB_REFRESH_DURATION_MS = 30_000; + public static final long SERVICE_REFRESH_TIMEOUT_MS = 10_000; + public static final long HUB_START_TIMEOUT_MS = 30_000; public static final long REFRESH_FREQUENCY_MS = 10_000; public static final int CONNECTION_RETRY_TIME_MS = 5_000; public static final int MINIMUM_REFRESH_TIME_MS = 5_000; + public static final int MINIMUM_SERVICE_REFRESH_TIMEOUT_MS = 1_000; + public static final int MINIMUM_HUB_START_TIMEOUT_MS = 5_000; } diff --git a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java index 31604db5..00734940 100644 --- a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java +++ b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java @@ -26,6 +26,7 @@ import io.appform.ranger.drove.servicefinderhub.DroveServiceDataSource; import io.appform.ranger.drove.servicefinderhub.DroveServiceFinderHubBuilder; import io.appform.ranger.drove.common.DroveCommunicator; +import java.util.Set; import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -35,7 +36,7 @@ @Getter @SuperBuilder public abstract class AbstractRangerDroveHubClient, D extends DroveResponseDataDeserializer> - extends AbstractRangerHubClient { + extends AbstractRangerHubClient { private final DroveUpstreamConfig clientConfig; private final DroveCommunicator droveCommunicator; @@ -44,18 +45,19 @@ public abstract class AbstractRangerDroveHubClient nodeSelector = new RandomServiceNodeSelector<>(); @Override - protected ServiceDataSource getDefaultDataSource() { - return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator); + protected ServiceDataSource getDefaultDataSource(Set excludedServices) { + return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator, excludedServices); } @Override protected ServiceFinderHub buildHub() { return new DroveServiceFinderHubBuilder() - .withServiceDataSource(getServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) - .withRefreshFrequencyMs(getNodeRefreshTimeMs()) - .withHubRefreshDuration(getHubRefreshDurationMs()) - .withServiceRefreshDuration(getServiceRefreshDurationMs()) - .build(); + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withRefreshFrequencyMs(getNodeRefreshTimeMs()) + .withHubRefreshDuration(getHubStartTimeoutMs()) + .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) + .withExcludedServices(getExcludedServices()) + .build(); } } diff --git a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java index f303dcdd..a71e484f 100644 --- a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java +++ b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java @@ -22,6 +22,8 @@ import io.appform.ranger.drove.common.DroveNodeDataStoreConnector; import io.appform.ranger.drove.config.DroveUpstreamConfig; import io.appform.ranger.drove.common.DroveCommunicator; +import java.util.Collections; +import java.util.Set; import lombok.extern.slf4j.Slf4j; import java.util.Collection; @@ -29,14 +31,17 @@ @Slf4j public class DroveServiceDataSource extends DroveNodeDataStoreConnector implements ServiceDataSource { private final String namespace; + private final Set excludedServices; public DroveServiceDataSource( final DroveUpstreamConfig config, final ObjectMapper mapper, final String namespace, - final DroveCommunicator droveClient) { + final DroveCommunicator droveClient, + Set excludedServices) { super(config, mapper, droveClient); this.namespace = namespace; + this.excludedServices = excludedServices; } @Override @@ -45,6 +50,7 @@ public Collection services() { Preconditions.checkNotNull(mapper, "mapper has not been set for node data"); return droveClient.services() .stream() + .filter(serviceName -> !excludedServices.contains(serviceName)) .map(serviceName -> new Service(namespace, serviceName)) .toList(); } diff --git a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java index fe5fac64..661b8e95 100644 --- a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java +++ b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java @@ -25,10 +25,12 @@ import io.appform.ranger.core.units.TestNodeData; import io.appform.ranger.drove.config.DroveUpstreamConfig; import io.appform.ranger.drove.utils.RangerDroveUtils; +import java.util.Collections; import lombok.SneakyThrows; import lombok.val; import org.junit.jupiter.api.Test; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; @@ -103,7 +105,7 @@ void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) { clientConfig, MAPPER, namespace, - droveClient); + droveClient, Collections.emptySet()); finder.start(); val services = finder.services(); assertFalse(services.isEmpty()); diff --git a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java index 139363c3..e11a85ef 100644 --- a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java @@ -27,6 +27,7 @@ import io.appform.ranger.http.servicefinderhub.HttpServiceDataSource; import io.appform.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; import io.appform.ranger.http.utils.RangerHttpUtils; +import java.util.Set; import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -49,12 +50,13 @@ public abstract class AbstractRangerHttpHubClient nodeSelector = new RandomServiceNodeSelector<>(); @Override - protected ServiceDataSource getDefaultDataSource() { + protected ServiceDataSource getDefaultDataSource(Set excludedServices) { return new HttpServiceDataSource<>(clientConfig, Objects.requireNonNullElseGet(getHttpClient(), () -> RangerHttpUtils.httpClient( clientConfig, - getMapper()))); + getMapper())), + excludedServices); } @Override @@ -63,8 +65,9 @@ protected ServiceFinderHub buildHub() { .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) .withRefreshFrequencyMs(getNodeRefreshTimeMs()) - .withHubRefreshDuration(getHubRefreshDurationMs()) - .withServiceRefreshDuration(getServiceRefreshDurationMs()) + .withHubRefreshDuration(getHubStartTimeoutMs()) + .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) + .withExcludedServices(getExcludedServices()) .build(); } } diff --git a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java index a52cc214..36b1cce9 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -20,6 +20,8 @@ import io.appform.ranger.http.common.HttpNodeDataStoreConnector; import io.appform.ranger.http.config.HttpClientConfig; import io.appform.ranger.http.servicefinder.HttpCommunicator; +import java.util.Set; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import java.util.Collection; @@ -28,13 +30,20 @@ @Slf4j public class HttpServiceDataSource extends HttpNodeDataStoreConnector implements ServiceDataSource { - public HttpServiceDataSource(HttpClientConfig config, HttpCommunicator httpClient) { + private final Set excludedServices; + + public HttpServiceDataSource(HttpClientConfig config, HttpCommunicator httpClient, + final Set excludedServices) { super(config, httpClient); + this.excludedServices = excludedServices; } @Override public Collection services() { - Objects.requireNonNull(config, "client config has not been set for node data"); - return httpCommunicator.services(); + Objects.requireNonNull(config, "client config has not been set for node data"); + return httpCommunicator.services(). + stream() + .filter(service -> !excludedServices.contains(service.getServiceName())) + .collect(Collectors.toSet()); } } diff --git a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 7662a167..1bbf9e01 100644 --- a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -23,6 +23,7 @@ import io.appform.ranger.http.config.HttpClientConfig; import io.appform.ranger.http.model.ServiceDataSourceResponse; import io.appform.ranger.http.utils.RangerHttpUtils; +import java.util.Collections; import lombok.val; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -55,7 +56,8 @@ void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOExc .connectionTimeoutMs(30_000) .operationTimeoutMs(30_000) .build(); - val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, RangerHttpUtils.httpClient(clientConfig, MAPPER)); + val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, RangerHttpUtils.httpClient(clientConfig, MAPPER), + Collections.emptySet()); val services = httpServiceDataSource.services(); Assertions.assertNotNull(services); Assertions.assertFalse(services.isEmpty()); diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java index b6013c1d..dd141bcc 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java @@ -67,7 +67,7 @@ protected List>> serverConfig.getUpstreams(), Collections.emptyList()); return upstreams.stream() .map(rangerUpstreamConfiguration -> rangerUpstreamConfiguration.accept(new HubCreatorVisitor( - serverConfig.getNamespace()))) + serverConfig.getNamespace(), serverConfig.getExcludedServices()))) .flatMap(Collection::stream) .toList(); } @@ -81,9 +81,7 @@ protected List> withLifecycleSignals(U configuration) { @Override protected List withHealthChecks(U configuration) { - return curatorFrameworks.stream() - .map(curatorFramework -> (HealthCheck) new RangerHealthCheck(curatorFramework)) - .toList(); + return Collections.singletonList((HealthCheck) new RangerHealthCheck(curatorFrameworks)); } @AllArgsConstructor @@ -91,6 +89,7 @@ private class HubCreatorVisitor implements RangerConfigurationVisitor>>> { private final String namespace; + private final Set excludedServices; private RangerHubClient> addCuratorAndGetZkHubClient( String zookeeper, RangerZkUpstreamConfiguration zkConfiguration) { @@ -106,9 +105,10 @@ private RangerHubClient> addCurat .curatorFramework(curatorFramework) .disablePushUpdaters(zkConfiguration.isDisablePushUpdaters()) .mapper(getMapper()) - .serviceRefreshDurationMs(zkConfiguration.getServiceRefreshDurationMs()) - .hubRefreshDurationMs(zkConfiguration.getServiceRefreshDurationMs()) + .serviceRefreshTimeoutMs(zkConfiguration.getServiceRefreshTimeoutMs()) + .hubStartTimeoutMs(zkConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(zkConfiguration.getNodeRefreshTimeMs()) + .excludedServices(excludedServices) .deserializer(data -> { try { return getMapper().readValue(data, new TypeReference>() { @@ -129,9 +129,10 @@ private RangerHubClient> getHttpH .mapper(getMapper()) .clientConfig(httpClientConfig) .httpClient(RangerHttpUtils.httpClient(httpClientConfig, getMapper())) - .serviceRefreshDurationMs(httpConfiguration.getServiceRefreshDurationMs()) - .hubRefreshDurationMs(httpConfiguration.getServiceRefreshDurationMs()) + .serviceRefreshTimeoutMs(httpConfiguration.getServiceRefreshTimeoutMs()) + .hubStartTimeoutMs(httpConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(httpConfiguration.getNodeRefreshTimeMs()) + .excludedServices(excludedServices) .deserializer(data -> { try { return getMapper().readValue(data, new TypeReference<>() {}); @@ -156,9 +157,10 @@ private RangerHubClient> getDrove .mapper(getMapper()) .clientConfig(droveConfig) .droveCommunicator(droveCommunicator) - .serviceRefreshDurationMs(droveUpstreamConfiguration.getServiceRefreshDurationMs()) - .hubRefreshDurationMs(droveUpstreamConfiguration.getServiceRefreshDurationMs()) + .serviceRefreshTimeoutMs(droveUpstreamConfiguration.getServiceRefreshTimeoutMs()) + .hubStartTimeoutMs(droveUpstreamConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(droveUpstreamConfiguration.getNodeRefreshTimeMs()) + .excludedServices(excludedServices) .deserializer(new DroveResponseDataDeserializer<>() { @Override protected ShardInfo translate(ExposedAppInfo appInfo, ExposedAppInfo.ExposedHost host) { diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java index 7211b6f1..014568bd 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java @@ -15,6 +15,9 @@ */ package io.appform.ranger.hub.server.bundle.configuration; +import java.util.Collections; +import java.util.Objects; +import java.util.Set; import lombok.Builder; import lombok.Value; import lombok.extern.jackson.Jacksonized; @@ -38,4 +41,13 @@ public class RangerServerConfiguration { @NotEmpty @Valid List upstreams; + + Set excludedServices; + + public Set getExcludedServices() { + return Objects.isNull(excludedServices) + ? Collections.emptySet() : + excludedServices; + } + } diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java index c418df4c..16eea744 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java @@ -41,8 +41,11 @@ public abstract class RangerUpstreamConfiguration { @Min(HubConstants.MINIMUM_REFRESH_TIME_MS) private int nodeRefreshTimeMs = HubConstants.MINIMUM_REFRESH_TIME_MS; - @Min(HubConstants.MINIMUM_REFRESH_TIME_MS) - private int serviceRefreshDurationMs = HubConstants.MINIMUM_REFRESH_TIME_MS; + @Min(HubConstants.MINIMUM_SERVICE_REFRESH_TIMEOUT_MS) + private int serviceRefreshTimeoutMs = HubConstants.MINIMUM_SERVICE_REFRESH_TIMEOUT_MS; + + @Min(HubConstants.MINIMUM_HUB_START_TIMEOUT_MS) + private int hubStartTimeoutMs = HubConstants.MINIMUM_HUB_START_TIMEOUT_MS; protected RangerUpstreamConfiguration(BackendType type) { this.type = type; diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java index 69d4ce95..76fb0d3c 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java @@ -19,18 +19,22 @@ import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; +import java.util.List; + @Slf4j public class RangerHealthCheck extends HealthCheck { - private final CuratorFramework curatorFramework; + private final List curatorFrameworks; - public RangerHealthCheck(CuratorFramework curatorFramework){ - this.curatorFramework = curatorFramework; + public RangerHealthCheck(final List curatorFrameworks){ + this.curatorFrameworks = curatorFrameworks; } @Override protected Result check() { - return curatorFramework.getZookeeperClient().isConnected() ? - Result.healthy("Service is healthy") : Result.unhealthy("Can't connect to zookeeper"); + return curatorFrameworks.stream() + .allMatch(curatorFramework -> curatorFramework.getZookeeperClient().isConnected()) + ? Result.healthy("Service is healthy") + : Result.unhealthy("Can't connect to zookeeper"); } } diff --git a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java index 36e46bdb..56cae4c3 100644 --- a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java @@ -22,6 +22,7 @@ import io.appform.ranger.zookeeper.serde.ZkNodeDataDeserializer; import io.appform.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import io.appform.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; +import java.util.Set; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; @@ -46,14 +47,15 @@ protected ServiceFinderHub buildHub() { .withRefreshFrequencyMs(getNodeRefreshTimeMs()) .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) - .withHubRefreshDuration(getHubRefreshDurationMs()) - .withServiceRefreshDuration(getServiceRefreshDurationMs()) + .withHubRefreshDuration(getHubStartTimeoutMs()) + .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) + .withExcludedServices(getExcludedServices()) .build(); } @Override - protected ServiceDataSource getDefaultDataSource() { - return new ZkServiceDataSource(getNamespace(), connectionString, curatorFramework); + protected ServiceDataSource getDefaultDataSource(final Set excludedServices) { + return new ZkServiceDataSource(getNamespace(), excludedServices, connectionString, curatorFramework); } } diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkCommunicationException.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkCommunicationException.java new file mode 100644 index 00000000..3de05d85 --- /dev/null +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkCommunicationException.java @@ -0,0 +1,29 @@ +/* + * Copyright 2024 Authors, Flipkart Internet Pvt. Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.appform.ranger.zookeeper.servicefinder; + +import io.appform.ranger.core.exceptions.CommunicationException; + +/** + * Thrown in case there is an issue communicating with the Zookeeper upstream. + + */ +public class ZkCommunicationException extends CommunicationException { + public ZkCommunicationException(final String message) { + super(message); + } +} diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index f2fea6fa..dd9bdd45 100644 --- a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -93,8 +93,9 @@ private Optional>> checkForUpdateOnZookeeper(D deserializer) } catch (Exception e) { log.error("Error getting service data from zookeeper: ", e); + throw new ZkCommunicationException("Error communicating to Zk: exception %s , message: %s" + .formatted(e.getClass().getSimpleName(), e.getMessage())); } - return Optional.empty(); } private Optional readChild(String parentPath, String child) throws Exception { @@ -107,8 +108,11 @@ private Optional readChild(String parentPath, String child) throws Excep return Optional.empty(); } catch (KeeperException e) { - log.error("Could not get data for node: " + path, e); + log.error("Could not get data for node: {}", path, e); return Optional.empty(); + } catch (Exception e){ + log.error("Could not read child for node: {}", path, e); + throw e; } } diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 43dc32de..77fd9557 100644 --- a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -19,6 +19,7 @@ import io.appform.ranger.core.finderhub.ServiceDataSource; import io.appform.ranger.core.model.Service; import io.appform.ranger.zookeeper.util.PathBuilder; +import java.util.Set; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -40,13 +41,16 @@ public class ZkServiceDataSource implements ServiceDataSource { private final String connectionString; private CuratorFramework curatorFramework; private boolean curatorProvided; + private final Set excludedServices; public ZkServiceDataSource(String namespace, + Set excludedServices, String connectionString, CuratorFramework curatorFramework){ this.namespace = namespace; this.connectionString = connectionString; this.curatorFramework = curatorFramework; + this.excludedServices = excludedServices; } @Override @@ -56,6 +60,7 @@ public Collection services() { .forPath(PathBuilder.REGISTERED_SERVICES_PATH); return null == children ? Collections.emptySet() : children.stream() + .filter(child -> !excludedServices.contains(child)) .map(child -> Service.builder().namespace(namespace).serviceName(child).build()) .collect(Collectors.toSet()); } diff --git a/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java index ffc26164..82d1ec46 100644 --- a/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -106,7 +106,7 @@ void testHub() { .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) - .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString(), curatorFramework)) + .withServiceDataSource(new ZkServiceDataSource("test", Collections.emptySet(), testingCluster.getConnectString(), curatorFramework)) .withServiceFinderFactory(ZkShardedServiceFinderFactory.builder() .curatorFramework(curatorFramework) .deserializer(this::read) From 047a029326479cfe19585f09c64c6bafdee5acc7 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 08:52:38 +0530 Subject: [PATCH 02/10] add changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ccdca2f..636acb5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ All notable changes to this project will be documented in this file. ## [1.1-RC2] - +- Add feature to exclude services from service data source +- Create one single `RangerHealthCheck` for all curatorFrameworks when giving multiple zookeeper connection strings +- Update `lastUpdatedTimeStamp` for service nodes in service registry for zk / http communication failures from any kind of node data source - zk/http/drove - Pertaining to PR : https://github.com/appform-io/ranger/pull/22/, building of a ServiceFinderHub and a ServiceFinder are bounded. ## [1.0-RC18] From 83770e3242365a791f38421ab48ae049f1bd2df8 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 15:03:32 +0530 Subject: [PATCH 03/10] address code review comments --- .../client/AbstractRangerHubClient.java | 26 ++++++++++++----- .../ranger/client/stubs/RangerTestHub.java | 3 +- .../ServiceRegistryUpdater.java | 9 +++--- .../core/finderhub/ServiceFinderHub.java | 29 +++++++++++++------ .../finderhub/ServiceFinderHubBuilder.java | 2 +- .../core/finderhub/ServiceFinderHubTest.java | 5 ++-- .../drove/AbstractRangerDroveHubClient.java | 5 ++-- .../DroveServiceDataSource.java | 6 +--- .../DroveServiceDataSourceTest.java | 2 +- .../http/AbstractRangerHttpHubClient.java | 6 ++-- .../HttpServiceDataSource.java | 11 ++----- .../HttpServiceDataSourceTest.java | 3 +- .../client/zk/AbstractRangerZKHubClient.java | 5 ++-- .../servicefinder/ZkNodeDataSource.java | 4 +-- .../servicefinderhub/ZkServiceDataSource.java | 4 --- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 16 files changed, 62 insertions(+), 60 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 e04926fc..bd3e45bc 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 @@ -26,10 +26,12 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; +import java.util.stream.Collectors; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; @@ -47,9 +49,16 @@ public abstract class AbstractRangerHubClient, D private int nodeRefreshTimeMs; private ServiceFinderHub hub; private ServiceDataSource serviceDataSource; - private long serviceRefreshDurationMs; - private long hubRefreshDurationMs; + + /** + * Initial time to wait for service node data to be refreshed in service registry (in milliseconds) + */ private long serviceRefreshTimeoutMs; + + /** + * Time to wait for Hub Start completion (in milliseconds) + * Hub Start is considered to be completed if service registry for all eligible services has been refreshed + */ private long hubStartTimeoutMs; private Set excludedServices; @@ -80,12 +89,10 @@ public void start() { this.hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; } - if(null == this.excludedServices){ - this.excludedServices = Collections.emptySet(); - } + this.excludedServices = Objects.requireNonNullElseGet(this.excludedServices, Set::of); if(null == this.serviceDataSource){ - this.serviceDataSource = getDefaultDataSource(this.excludedServices); + this.serviceDataSource = getDefaultDataSource(); } this.hub = buildHub(); @@ -162,7 +169,10 @@ public List> getAllNodes( @Override public Collection getRegisteredServices() { try { - return this.getHub().getServiceDataSource().services(); + return this.getHub().getServiceDataSource().services() + .stream() + .filter(service -> !excludedServices.contains(service.getServiceName())) + .collect(Collectors.toSet()); } catch (Exception e) { log.error("Call to the hub failed with exception, {}", e.getMessage()); @@ -190,7 +200,7 @@ public CompletableFuture addService(Service service) { } - protected abstract ServiceDataSource getDefaultDataSource(final Set excludedServices); + protected abstract ServiceDataSource getDefaultDataSource(); protected abstract ServiceFinderFactory getFinderFactory(); diff --git a/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java b/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java index bb5a6d8f..ac46feb3 100644 --- a/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java +++ b/ranger-client/src/test/java/io/appform/ranger/client/stubs/RangerTestHub.java @@ -23,7 +23,6 @@ import io.appform.ranger.core.units.TestNodeData; import lombok.Builder; import lombok.Getter; -import java.util.Set; import lombok.experimental.SuperBuilder; @Getter @@ -52,7 +51,7 @@ protected void postBuild(ServiceFinderHub excludedServices) { + protected ServiceDataSource getDefaultDataSource() { return new StaticDataSource(Sets.newHashSet(RangerHubTestUtils.service)); } diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 39da1cb4..4d8f17f7 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -26,6 +26,7 @@ import io.appform.ranger.core.signals.Signal; import io.appform.ranger.core.util.Exceptions; import io.appform.ranger.core.util.FinderUtils; +import java.util.concurrent.atomic.AtomicBoolean; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -47,7 +48,7 @@ public class ServiceRegistryUpdater> { private final Lock checkLock = new ReentrantLock(); private final Condition checkCondition = checkLock.newCondition(); - private volatile boolean checkForUpdate = false; + private final AtomicBoolean checkForUpdate = new AtomicBoolean(false); private Future queryThreadFuture; private final ExecutorService executorService = Executors.newFixedThreadPool(1); @@ -95,7 +96,7 @@ public void checkForUpdate(T signalData) { Preconditions.checkArgument(null == signalData); try { checkLock.lock(); - checkForUpdate = true; + checkForUpdate.set(true); checkCondition.signalAll(); } finally { @@ -108,7 +109,7 @@ private Void queryExecutor() { while (true) { try { checkLock.lock(); - while (!checkForUpdate) { + while (!checkForUpdate.get()) { checkCondition.await(); } updateRegistry(); @@ -122,7 +123,7 @@ private Void queryExecutor() { log.error("Registry update failed for service: " + serviceRegistry.getService().name(), e); } finally { - checkForUpdate = false; + checkForUpdate.set(false); checkLock.unlock(); } } 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 ef7a2c1d..a97201d8 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 @@ -17,7 +17,6 @@ import com.github.rholder.retry.RetryerBuilder; import com.github.rholder.retry.StopStrategies; -import com.github.rholder.retry.WaitStrategies; import com.google.common.base.Stopwatch; import io.appform.ranger.core.finder.ServiceFinder; import io.appform.ranger.core.model.HubConstants; @@ -53,7 +52,7 @@ public class ServiceFinderHub> { new AtomicReference<>(new ConcurrentHashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); - private volatile boolean updateAvailable = false; + private final AtomicBoolean updateAvailable = new AtomicBoolean(false); private final ExecutorService executorService = Executors.newFixedThreadPool(1); @Getter @@ -76,6 +75,8 @@ public class ServiceFinderHub> { private final long serviceRefreshTimeoutMs; private final long hubStartTimeoutMs; + private final Set excludedServices; + private final ForkJoinPool refresherPool; public ServiceFinderHub( @@ -83,14 +84,15 @@ public ServiceFinderHub( ServiceFinderFactory finderFactory ) { this(serviceDataSource, finderFactory, - HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS); + HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of()); } public ServiceFinderHub( ServiceDataSource serviceDataSource, ServiceFinderFactory finderFactory, long serviceRefreshTimeoutMs, - long hubStartTimeoutMs) { + long hubStartTimeoutMs, + final Set excludedServices) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs == 0 ? HubConstants.SERVICE_REFRESH_TIMEOUT_MS : serviceRefreshTimeoutMs; @@ -100,6 +102,7 @@ public ServiceFinderHub( Collections.emptyList(), 10_000)); this.refresherPool = createRefresherPool(); + this.excludedServices = excludedServices; } public Optional> finder(final Service service) { @@ -156,7 +159,7 @@ public void registerUpdateSignal(final Signal refreshSignal) { public void updateAvailable() { try { updateLock.lock(); - updateAvailable = true; + updateAvailable.set(true); updateCond.signalAll(); } finally { @@ -180,7 +183,7 @@ private void monitor() { while (true) { try { updateLock.lock(); - while (!updateAvailable) { + while (!updateAvailable.get()) { updateCond.await(); } updateRegistry(); @@ -191,7 +194,7 @@ private void monitor() { break; } finally { - updateAvailable = false; + updateAvailable.set(false); updateLock.unlock(); } } @@ -205,7 +208,7 @@ private void updateRegistry() { alreadyUpdating.set(true); val updatedFinders = new ConcurrentHashMap>(); try { - val services = serviceDataSource.services(); + val services = getEligibleServices(); if (services.isEmpty()) { log.debug("No services found for the service data source. Skipping update on the registry"); return; @@ -240,7 +243,7 @@ private void updateRegistry() { } private void waitTillHubIsReady() { - val services = serviceDataSource.services(); + val services = getEligibleServices(); val timeToRefresh = Math.max(hubStartTimeoutMs, (serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism()); if (timeToRefresh != hubStartTimeoutMs) { @@ -286,4 +289,12 @@ private void waitTillServiceIsReady(Service service) { .illegalState("Could not perform initial state for service: " + service.getServiceName(), e); } } + + 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/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 4dfe8970..456a10ae 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -95,7 +95,7 @@ public ServiceFinderHub build() { Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, - serviceRefreshDurationMs, hubRefreshDurationMs); + serviceRefreshDurationMs, hubRefreshDurationMs, excludedServices); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", () -> null, Collections.emptyList(), diff --git a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java index 3778ee5c..d3e01277 100644 --- a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java +++ b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java @@ -27,6 +27,7 @@ import io.appform.ranger.core.model.*; import io.appform.ranger.core.units.TestNodeData; import io.appform.ranger.core.utils.RangerTestUtils; +import java.util.Set; import lombok.val; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -73,7 +74,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(5) - .build(), 1_000, 5_000 + .build(), 1_000, 5_000, Set.of() ); Assertions.assertThrows(IllegalStateException.class, delayedHub::start); val serviceFinderHub = new ServiceFinderHub<>(new DynamicDataSource(Lists.newArrayList(new Service("NS", "SERVICE"))), @@ -82,7 +83,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(1) - .build(), 5_000, 5_000 + .build(), 5_000, 5_000,Set.of() ); serviceFinderHub.start(); Assertions.assertTrue(serviceFinderHub.finder(new Service("NS", "SERVICE")).isPresent()); diff --git a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java index 00734940..2ef63eaa 100644 --- a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java +++ b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java @@ -26,7 +26,6 @@ import io.appform.ranger.drove.servicefinderhub.DroveServiceDataSource; import io.appform.ranger.drove.servicefinderhub.DroveServiceFinderHubBuilder; import io.appform.ranger.drove.common.DroveCommunicator; -import java.util.Set; import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -45,8 +44,8 @@ public abstract class AbstractRangerDroveHubClient nodeSelector = new RandomServiceNodeSelector<>(); @Override - protected ServiceDataSource getDefaultDataSource(Set excludedServices) { - return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator, excludedServices); + protected ServiceDataSource getDefaultDataSource() { + return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator); } @Override diff --git a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java index a71e484f..2e875133 100644 --- a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java +++ b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java @@ -31,17 +31,14 @@ @Slf4j public class DroveServiceDataSource extends DroveNodeDataStoreConnector implements ServiceDataSource { private final String namespace; - private final Set excludedServices; public DroveServiceDataSource( final DroveUpstreamConfig config, final ObjectMapper mapper, final String namespace, - final DroveCommunicator droveClient, - Set excludedServices) { + final DroveCommunicator droveClient) { super(config, mapper, droveClient); this.namespace = namespace; - this.excludedServices = excludedServices; } @Override @@ -50,7 +47,6 @@ public Collection services() { Preconditions.checkNotNull(mapper, "mapper has not been set for node data"); return droveClient.services() .stream() - .filter(serviceName -> !excludedServices.contains(serviceName)) .map(serviceName -> new Service(namespace, serviceName)) .toList(); } diff --git a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java index 661b8e95..34b088d3 100644 --- a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java +++ b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java @@ -105,7 +105,7 @@ void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) { clientConfig, MAPPER, namespace, - droveClient, Collections.emptySet()); + droveClient); finder.start(); val services = finder.services(); assertFalse(services.isEmpty()); diff --git a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java index e11a85ef..74d12afa 100644 --- a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java @@ -27,7 +27,6 @@ import io.appform.ranger.http.servicefinderhub.HttpServiceDataSource; import io.appform.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; import io.appform.ranger.http.utils.RangerHttpUtils; -import java.util.Set; import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -50,13 +49,12 @@ public abstract class AbstractRangerHttpHubClient nodeSelector = new RandomServiceNodeSelector<>(); @Override - protected ServiceDataSource getDefaultDataSource(Set excludedServices) { + protected ServiceDataSource getDefaultDataSource() { return new HttpServiceDataSource<>(clientConfig, Objects.requireNonNullElseGet(getHttpClient(), () -> RangerHttpUtils.httpClient( clientConfig, - getMapper())), - excludedServices); + getMapper()))); } @Override diff --git a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java index 36b1cce9..601edc7c 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -30,20 +30,13 @@ @Slf4j public class HttpServiceDataSource extends HttpNodeDataStoreConnector implements ServiceDataSource { - private final Set excludedServices; - - public HttpServiceDataSource(HttpClientConfig config, HttpCommunicator httpClient, - final Set excludedServices) { + public HttpServiceDataSource(HttpClientConfig config, HttpCommunicator httpClient) { super(config, httpClient); - this.excludedServices = excludedServices; } @Override public Collection services() { Objects.requireNonNull(config, "client config has not been set for node data"); - return httpCommunicator.services(). - stream() - .filter(service -> !excludedServices.contains(service.getServiceName())) - .collect(Collectors.toSet()); + return httpCommunicator.services(); } } diff --git a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 1bbf9e01..590dbc28 100644 --- a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -56,8 +56,7 @@ void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOExc .connectionTimeoutMs(30_000) .operationTimeoutMs(30_000) .build(); - val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, RangerHttpUtils.httpClient(clientConfig, MAPPER), - Collections.emptySet()); + val httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, RangerHttpUtils.httpClient(clientConfig, MAPPER)); val services = httpServiceDataSource.services(); Assertions.assertNotNull(services); Assertions.assertFalse(services.isEmpty()); diff --git a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java index 56cae4c3..47f73cb8 100644 --- a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java @@ -22,7 +22,6 @@ import io.appform.ranger.zookeeper.serde.ZkNodeDataDeserializer; import io.appform.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import io.appform.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; -import java.util.Set; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; @@ -54,8 +53,8 @@ protected ServiceFinderHub buildHub() { } @Override - protected ServiceDataSource getDefaultDataSource(final Set excludedServices) { - return new ZkServiceDataSource(getNamespace(), excludedServices, connectionString, curatorFramework); + protected ServiceDataSource getDefaultDataSource() { + return new ZkServiceDataSource(getNamespace(), connectionString, curatorFramework); } } diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index dd9bdd45..0548e622 100644 --- a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -92,8 +92,8 @@ private Optional>> checkForUpdateOnZookeeper(D deserializer) return Optional.of(Collections.emptyList()); } catch (Exception e) { - log.error("Error getting service data from zookeeper: ", e); - throw new ZkCommunicationException("Error communicating to Zk: exception %s , message: %s" + log.error("Error getting node data from zookeeper: ", e); + throw new ZkCommunicationException("Error getting node data from zookeeper: exception %s , message: %s" .formatted(e.getClass().getSimpleName(), e.getMessage())); } } diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 77fd9557..d0e1fa1c 100644 --- a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -41,16 +41,13 @@ public class ZkServiceDataSource implements ServiceDataSource { private final String connectionString; private CuratorFramework curatorFramework; private boolean curatorProvided; - private final Set excludedServices; public ZkServiceDataSource(String namespace, - Set excludedServices, String connectionString, CuratorFramework curatorFramework){ this.namespace = namespace; this.connectionString = connectionString; this.curatorFramework = curatorFramework; - this.excludedServices = excludedServices; } @Override @@ -60,7 +57,6 @@ public Collection services() { .forPath(PathBuilder.REGISTERED_SERVICES_PATH); return null == children ? Collections.emptySet() : children.stream() - .filter(child -> !excludedServices.contains(child)) .map(child -> Service.builder().namespace(namespace).serviceName(child).build()) .collect(Collectors.toSet()); } diff --git a/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java index 82d1ec46..ffc26164 100644 --- a/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/io/appform/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -106,7 +106,7 @@ void testHub() { .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) - .withServiceDataSource(new ZkServiceDataSource("test", Collections.emptySet(), testingCluster.getConnectString(), curatorFramework)) + .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString(), curatorFramework)) .withServiceFinderFactory(ZkShardedServiceFinderFactory.builder() .curatorFramework(curatorFramework) .deserializer(this::read) From 63d292c9dac13ec2c7606a1ac9a8787c8bff1edb Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 15:08:47 +0530 Subject: [PATCH 04/10] rename variables with refresh duration ms to timeout ms --- .../core/finderhub/ServiceFinderHubBuilder.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 456a10ae..94c0263b 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -40,8 +40,8 @@ public abstract class ServiceFinderHubBuilder> { private final List> extraStartSignalConsumers = new ArrayList<>(); private final List> extraStopSignalConsumers = new ArrayList<>(); private final List> extraRefreshSignals = new ArrayList<>(); - private long serviceRefreshDurationMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; - private long hubRefreshDurationMs = HubConstants.HUB_START_TIMEOUT_MS; + private long serviceRefreshTimeoutMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; + private long hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; private Set excludedServices = new HashSet<>(); public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { @@ -75,12 +75,12 @@ public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRe } public ServiceFinderHubBuilder withServiceRefreshDuration(long serviceRefreshDurationMs) { - this.serviceRefreshDurationMs = serviceRefreshDurationMs; + this.serviceRefreshTimeoutMs = serviceRefreshDurationMs; return this; } public ServiceFinderHubBuilder withHubRefreshDuration(long hubRefreshDurationMs) { - this.hubRefreshDurationMs = hubRefreshDurationMs; + this.hubStartTimeoutMs = hubRefreshDurationMs; return this; } @@ -94,8 +94,8 @@ public ServiceFinderHub build() { Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); - val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, - serviceRefreshDurationMs, hubRefreshDurationMs, excludedServices); + val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshTimeoutMs, + hubStartTimeoutMs, excludedServices); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", () -> null, Collections.emptyList(), From 6f37b09b3fbbf349cf8ada5d48d503e4643c277f Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 15:23:44 +0530 Subject: [PATCH 05/10] fix formatting --- .../ranger/client/AbstractRangerHubClient.java | 5 +---- .../ranger/core/finderhub/ServiceFinderHub.java | 12 ++++++------ .../core/finderhub/ServiceFinderHubBuilder.java | 14 +++++++------- .../core/finderhub/ServiceFinderHubTest.java | 2 +- .../client/drove/AbstractRangerDroveHubClient.java | 14 +++++++------- .../client/http/AbstractRangerHttpHubClient.java | 4 ++-- .../servicefinderhub/HttpServiceDataSource.java | 2 +- .../hub/server/bundle/RangerHubServerBundle.java | 2 +- .../configuration/RangerServerConfiguration.java | 4 +--- .../client/zk/AbstractRangerZKHubClient.java | 4 ++-- .../servicefinderhub/ZkServiceDataSource.java | 1 - 11 files changed, 29 insertions(+), 35 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 bd3e45bc..4c52d290 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 @@ -169,10 +169,7 @@ public List> getAllNodes( @Override public Collection getRegisteredServices() { try { - return this.getHub().getServiceDataSource().services() - .stream() - .filter(service -> !excludedServices.contains(service.getServiceName())) - .collect(Collectors.toSet()); + return this.getHub().getServiceDataSource().services(); } 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 a97201d8..5785c41c 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 @@ -82,7 +82,7 @@ public class ServiceFinderHub> { public ServiceFinderHub( ServiceDataSource serviceDataSource, ServiceFinderFactory finderFactory - ) { + ) { this(serviceDataSource, finderFactory, HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of()); } @@ -98,9 +98,9 @@ public ServiceFinderHub( this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs == 0 ? HubConstants.SERVICE_REFRESH_TIMEOUT_MS : serviceRefreshTimeoutMs; this.hubStartTimeoutMs = hubStartTimeoutMs == 0 ? HubConstants.HUB_START_TIMEOUT_MS : hubStartTimeoutMs; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", - () -> null, - Collections.emptyList(), - 10_000)); + () -> null, + Collections.emptyList(), + 10_000)); this.refresherPool = createRefresherPool(); this.excludedServices = excludedServices; } @@ -245,10 +245,10 @@ private void updateRegistry() { private void waitTillHubIsReady() { val services = getEligibleServices(); val timeToRefresh = Math.max(hubStartTimeoutMs, - (serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism()); + (serviceRefreshTimeoutMs * services.size()) / refresherPool.getParallelism()); if (timeToRefresh != hubStartTimeoutMs) { log.warn("Max hub refresh time has been dynamically adjusted to {} ms from the provided {} ms as the " + - "provided time would have been insufficient to refresh {} services.", + "provided time would have been insufficient to refresh {} services.", timeToRefresh, hubStartTimeoutMs, services.size()); } val hubRefresher = CompletableFuture.allOf( diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 94c0263b..7c31820d 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -74,13 +74,13 @@ public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRe return this; } - public ServiceFinderHubBuilder withServiceRefreshDuration(long serviceRefreshDurationMs) { - this.serviceRefreshTimeoutMs = serviceRefreshDurationMs; + public ServiceFinderHubBuilder withServiceRefreshTimeout(long serviceRefreshTimeoutMs) { + this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs; return this; } - public ServiceFinderHubBuilder withHubRefreshDuration(long hubRefreshDurationMs) { - this.hubStartTimeoutMs = hubRefreshDurationMs; + public ServiceFinderHubBuilder withHubStartTimeout(long hubStartTimeoutMs) { + this.hubStartTimeoutMs = hubStartTimeoutMs; return this; } @@ -97,9 +97,9 @@ public ServiceFinderHub build() { val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceRefreshTimeoutMs, hubStartTimeoutMs, excludedServices); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", - () -> null, - Collections.emptyList(), - refreshFrequencyMs); + () -> null, + Collections.emptyList(), + refreshFrequencyMs); hub.registerUpdateSignal(refreshSignal); extraRefreshSignals.forEach(hub::registerUpdateSignal); diff --git a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java index d3e01277..535f99ad 100644 --- a/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java +++ b/ranger-core/src/test/java/io/appform/ranger/core/finderhub/ServiceFinderHubTest.java @@ -83,7 +83,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(1) - .build(), 5_000, 5_000,Set.of() + .build(), 5_000, 5_000, Set.of() ); serviceFinderHub.start(); Assertions.assertTrue(serviceFinderHub.finder(new Service("NS", "SERVICE")).isPresent()); diff --git a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java index 2ef63eaa..8d028cca 100644 --- a/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java +++ b/ranger-drove-client/src/main/java/io/appform/ranger/client/drove/AbstractRangerDroveHubClient.java @@ -51,12 +51,12 @@ protected ServiceDataSource getDefaultDataSource() { @Override protected ServiceFinderHub buildHub() { return new DroveServiceFinderHubBuilder() - .withServiceDataSource(getServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) - .withRefreshFrequencyMs(getNodeRefreshTimeMs()) - .withHubRefreshDuration(getHubStartTimeoutMs()) - .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) - .withExcludedServices(getExcludedServices()) - .build(); + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withRefreshFrequencyMs(getNodeRefreshTimeMs()) + .withHubStartTimeout(getHubStartTimeoutMs()) + .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) + .withExcludedServices(getExcludedServices()) + .build(); } } diff --git a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java index 74d12afa..9f9430e6 100644 --- a/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/io/appform/ranger/client/http/AbstractRangerHttpHubClient.java @@ -63,8 +63,8 @@ protected ServiceFinderHub buildHub() { .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) .withRefreshFrequencyMs(getNodeRefreshTimeMs()) - .withHubRefreshDuration(getHubStartTimeoutMs()) - .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) + .withHubStartTimeout(getHubStartTimeoutMs()) + .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) .withExcludedServices(getExcludedServices()) .build(); } diff --git a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java index 601edc7c..5df325f8 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -36,7 +36,7 @@ public HttpServiceDataSource(HttpClientConfig config, HttpCommunicator httpCl @Override public Collection services() { - Objects.requireNonNull(config, "client config has not been set for node data"); + Objects.requireNonNull(config, "client config has not been set for node data"); return httpCommunicator.services(); } } diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java index dd141bcc..8a3eb670 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java @@ -81,7 +81,7 @@ protected List> withLifecycleSignals(U configuration) { @Override protected List withHealthChecks(U configuration) { - return Collections.singletonList((HealthCheck) new RangerHealthCheck(curatorFrameworks)); + return List.of(new RangerHealthCheck(curatorFrameworks)); } @AllArgsConstructor diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java index 014568bd..9923bda8 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java @@ -45,9 +45,7 @@ public class RangerServerConfiguration { Set excludedServices; public Set getExcludedServices() { - return Objects.isNull(excludedServices) - ? Collections.emptySet() : - excludedServices; + return Objects.requireNonNullElseGet(excludedServices,Set::of); } } diff --git a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java index 47f73cb8..3d5b6694 100644 --- a/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/io/appform/ranger/client/zk/AbstractRangerZKHubClient.java @@ -46,8 +46,8 @@ protected ServiceFinderHub buildHub() { .withRefreshFrequencyMs(getNodeRefreshTimeMs()) .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) - .withHubRefreshDuration(getHubStartTimeoutMs()) - .withServiceRefreshDuration(getServiceRefreshTimeoutMs()) + .withHubStartTimeout(getHubStartTimeoutMs()) + .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) .withExcludedServices(getExcludedServices()) .build(); } diff --git a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index d0e1fa1c..43dc32de 100644 --- a/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/io/appform/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -19,7 +19,6 @@ import io.appform.ranger.core.finderhub.ServiceDataSource; import io.appform.ranger.core.model.Service; import io.appform.ranger.zookeeper.util.PathBuilder; -import java.util.Set; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import lombok.val; From 705785c03482cd8c6cf07c4eaefc023909323f40 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 15:28:09 +0530 Subject: [PATCH 06/10] optimize imports --- .../ranger/drove/servicefinderhub/DroveServiceDataSource.java | 2 -- .../drove/servicefinderhub/DroveServiceDataSourceTest.java | 2 -- .../ranger/http/servicefinderhub/HttpServiceDataSource.java | 2 -- .../ranger/http/servicefinderhub/HttpServiceDataSourceTest.java | 1 - .../server/bundle/configuration/RangerServerConfiguration.java | 1 - 5 files changed, 8 deletions(-) diff --git a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java index 2e875133..f303dcdd 100644 --- a/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java +++ b/ranger-drove/src/main/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSource.java @@ -22,8 +22,6 @@ import io.appform.ranger.drove.common.DroveNodeDataStoreConnector; import io.appform.ranger.drove.config.DroveUpstreamConfig; import io.appform.ranger.drove.common.DroveCommunicator; -import java.util.Collections; -import java.util.Set; import lombok.extern.slf4j.Slf4j; import java.util.Collection; diff --git a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java index 34b088d3..fe5fac64 100644 --- a/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java +++ b/ranger-drove/src/test/java/io/appform/ranger/drove/servicefinderhub/DroveServiceDataSourceTest.java @@ -25,12 +25,10 @@ import io.appform.ranger.core.units.TestNodeData; import io.appform.ranger.drove.config.DroveUpstreamConfig; import io.appform.ranger.drove.utils.RangerDroveUtils; -import java.util.Collections; import lombok.SneakyThrows; import lombok.val; import org.junit.jupiter.api.Test; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Map; diff --git a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java index 5df325f8..a52cc214 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -20,8 +20,6 @@ import io.appform.ranger.http.common.HttpNodeDataStoreConnector; import io.appform.ranger.http.config.HttpClientConfig; import io.appform.ranger.http.servicefinder.HttpCommunicator; -import java.util.Set; -import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import java.util.Collection; diff --git a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 590dbc28..7662a167 100644 --- a/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/io/appform/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -23,7 +23,6 @@ import io.appform.ranger.http.config.HttpClientConfig; import io.appform.ranger.http.model.ServiceDataSourceResponse; import io.appform.ranger.http.utils.RangerHttpUtils; -import java.util.Collections; import lombok.val; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java index 9923bda8..e2232a33 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java @@ -15,7 +15,6 @@ */ package io.appform.ranger.hub.server.bundle.configuration; -import java.util.Collections; import java.util.Objects; import java.util.Set; import lombok.Builder; From 73dff82d07a828f126f33ccadf70d69e227b2036 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 16:58:04 +0530 Subject: [PATCH 07/10] 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, From df73636f4cbd37249d49d539c059ad83a1d2093a Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 17:01:24 +0530 Subject: [PATCH 08/10] add null check in constructor to initialize excluded services as empty set --- .../java/io/appform/ranger/core/finderhub/ServiceFinderHub.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d01ad3ff..f2ecd452 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 @@ -103,7 +103,7 @@ public ServiceFinderHub( Collections.emptyList(), 10_000)); this.refresherPool = createRefresherPool(); - this.excludedServices = excludedServices; + this.excludedServices = Objects.requireNonNullElseGet(excludedServices, Set::of); } public Optional> finder(final Service service) { From 02af4db45567df3570145e91610ffe921a9e6699 Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 17:10:38 +0530 Subject: [PATCH 09/10] add null check for safety for the input excludedServices --- .../ranger/core/finderhub/ServiceFinderHubBuilder.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java index 7c31820d..6f85c4c1 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -20,13 +20,11 @@ import io.appform.ranger.core.model.ServiceRegistry; import io.appform.ranger.core.signals.ScheduledSignal; import io.appform.ranger.core.signals.Signal; -import java.util.HashSet; -import java.util.Set; + +import java.util.*; + import lombok.val; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import java.util.function.Consumer; /** @@ -85,7 +83,7 @@ public ServiceFinderHubBuilder withHubStartTimeout(long hubStartTimeoutMs) } public ServiceFinderHubBuilder withExcludedServices(Set excludedServices) { - this.excludedServices = excludedServices; + this.excludedServices = Objects.requireNonNullElseGet(excludedServices, Set::of); return this; } From c0ecf7af10ef4cb96f7d381f912d489ad0f85bac Mon Sep 17 00:00:00 2001 From: Jitendra Dhawan Date: Thu, 21 Nov 2024 18:08:36 +0530 Subject: [PATCH 10/10] change default service refresh timeout and hub start timeout ms --- .../main/java/io/appform/ranger/core/model/HubConstants.java | 4 ++-- .../bundle/configuration/RangerUpstreamConfiguration.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java b/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java index fa7eb0b0..9dca422a 100644 --- a/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java +++ b/ranger-core/src/main/java/io/appform/ranger/core/model/HubConstants.java @@ -19,8 +19,8 @@ @UtilityClass public class HubConstants { - public static final long SERVICE_REFRESH_TIMEOUT_MS = 10_000; - public static final long HUB_START_TIMEOUT_MS = 30_000; + public static final int SERVICE_REFRESH_TIMEOUT_MS = 10_000; + public static final int HUB_START_TIMEOUT_MS = 30_000; public static final long REFRESH_FREQUENCY_MS = 10_000; public static final int CONNECTION_RETRY_TIME_MS = 5_000; public static final int MINIMUM_REFRESH_TIME_MS = 5_000; diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java index 16eea744..06ec4b43 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java @@ -42,10 +42,10 @@ public abstract class RangerUpstreamConfiguration { private int nodeRefreshTimeMs = HubConstants.MINIMUM_REFRESH_TIME_MS; @Min(HubConstants.MINIMUM_SERVICE_REFRESH_TIMEOUT_MS) - private int serviceRefreshTimeoutMs = HubConstants.MINIMUM_SERVICE_REFRESH_TIMEOUT_MS; + private int serviceRefreshTimeoutMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; @Min(HubConstants.MINIMUM_HUB_START_TIMEOUT_MS) - private int hubStartTimeoutMs = HubConstants.MINIMUM_HUB_START_TIMEOUT_MS; + private int hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; protected RangerUpstreamConfiguration(BackendType type) { this.type = type;