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 f48b6b38..a84aefce 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 @@ -22,22 +22,15 @@ import io.appform.ranger.core.finderhub.ServiceFinderFactory; import io.appform.ranger.core.finderhub.ServiceFinderHub; import io.appform.ranger.core.model.*; - -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 io.appform.ranger.core.util.FinderUtils; import lombok.Getter; import lombok.experimental.SuperBuilder; import lombok.extern.slf4j.Slf4j; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.function.Predicate; + @Slf4j @Getter @SuperBuilder @@ -63,6 +56,7 @@ public abstract class AbstractRangerHubClient, D */ private long hubStartTimeoutMs; private Set excludedServices; + private boolean replicationSource; @Override public void start() { diff --git a/ranger-client/src/main/java/io/appform/ranger/client/RangerHubClient.java b/ranger-client/src/main/java/io/appform/ranger/client/RangerHubClient.java index b88a5913..b0aca3d4 100644 --- a/ranger-client/src/main/java/io/appform/ranger/client/RangerHubClient.java +++ b/ranger-client/src/main/java/io/appform/ranger/client/RangerHubClient.java @@ -58,4 +58,6 @@ List> getAllNodes( final Service service, final Predicate criteria, final ShardSelector shardSelector); + + boolean isReplicationSource(); } 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 9af57172..54fa0d98 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 @@ -78,15 +78,16 @@ public class ServiceFinderHub> { private final long hubStartTimeoutMs; private final Set excludedServices; + @Getter + private final boolean replicationSource; private final ForkJoinPool refresherPool; public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory - ) { + ServiceFinderFactory finderFactory) { this(serviceDataSource, finderFactory, - HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of()); + HubConstants.SERVICE_REFRESH_TIMEOUT_MS, HubConstants.HUB_START_TIMEOUT_MS, Set.of(), false); } public ServiceFinderHub( @@ -94,11 +95,13 @@ public ServiceFinderHub( ServiceFinderFactory finderFactory, long serviceRefreshTimeoutMs, long hubStartTimeoutMs, - final Set excludedServices) { + final Set excludedServices, + boolean replicationSource) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.serviceRefreshTimeoutMs = serviceRefreshTimeoutMs == 0 ? HubConstants.SERVICE_REFRESH_TIMEOUT_MS : serviceRefreshTimeoutMs; this.hubStartTimeoutMs = hubStartTimeoutMs == 0 ? HubConstants.HUB_START_TIMEOUT_MS : hubStartTimeoutMs; + this.replicationSource = replicationSource; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", () -> null, Collections.emptyList(), 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 6f85c4c1..db947669 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,11 +20,9 @@ import io.appform.ranger.core.model.ServiceRegistry; import io.appform.ranger.core.signals.ScheduledSignal; import io.appform.ranger.core.signals.Signal; - -import java.util.*; - import lombok.val; +import java.util.*; import java.util.function.Consumer; /** @@ -40,6 +38,8 @@ public abstract class ServiceFinderHubBuilder> { private final List> extraRefreshSignals = new ArrayList<>(); private long serviceRefreshTimeoutMs = HubConstants.SERVICE_REFRESH_TIMEOUT_MS; private long hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; + private boolean replicationSource = false; + private Set excludedServices = new HashSet<>(); public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { @@ -87,13 +87,18 @@ public ServiceFinderHubBuilder withExcludedServices(Set excludedSe return this; } + public ServiceFinderHubBuilder withReplicationSource(boolean replicationSource) { + this.replicationSource = replicationSource; + return this; + } + public ServiceFinderHub build() { preBuild(); 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, serviceRefreshTimeoutMs, - hubStartTimeoutMs, excludedServices); + hubStartTimeoutMs, excludedServices, replicationSource); 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 de92dbac..b9e76048 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,15 +27,11 @@ 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; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; +import java.util.*; class ServiceFinderHubTest { @@ -93,8 +89,7 @@ void testDelayedServiceAddition() { .withServiceName(service.getServiceName()) .withDeserializer(new Deserializer() {}) .withSleepDuration(5) - .build(), 1_000, 5_000, Set.of() - ); + .build(), 1_000, 5_000, Set.of(), false); Assertions.assertThrows(IllegalStateException.class, delayedHub::start); val serviceFinderHub = new ServiceFinderHub<>(new DynamicDataSource(Lists.newArrayList(new Service("NS", "SERVICE"))), service -> new TestServiceFinderBuilder() @@ -102,8 +97,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(), false); serviceFinderHub.start(); Assertions.assertTrue(serviceFinderHub.finder(new Service("NS", "SERVICE")).isPresent()); } diff --git a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json index f0855806..ba2c090b 100644 --- a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json +++ b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json @@ -4,5 +4,5 @@ "iterations" : 4, "threads" : 1, "forks" : 3, - "mean_ops" : 812476.3197574528 + "mean_ops" : 780203.0578756403 } \ No newline at end of file diff --git a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json index 179cec48..c6d9e714 100644 --- a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json +++ b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json @@ -4,5 +4,5 @@ "iterations" : 4, "threads" : 1, "forks" : 3, - "mean_ops" : 592802.8071907263 + "mean_ops" : 610879.2316480416 } \ No newline at end of file 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 8d028cca..dde199a4 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 @@ -21,11 +21,11 @@ import io.appform.ranger.core.finderhub.ServiceFinderHub; import io.appform.ranger.core.model.ServiceNodeSelector; import io.appform.ranger.core.model.ServiceRegistry; +import io.appform.ranger.drove.common.DroveCommunicator; import io.appform.ranger.drove.config.DroveUpstreamConfig; import io.appform.ranger.drove.serde.DroveResponseDataDeserializer; import io.appform.ranger.drove.servicefinderhub.DroveServiceDataSource; import io.appform.ranger.drove.servicefinderhub.DroveServiceFinderHubBuilder; -import io.appform.ranger.drove.common.DroveCommunicator; import lombok.Builder; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -34,29 +34,31 @@ @Slf4j @Getter @SuperBuilder -public abstract class AbstractRangerDroveHubClient, D extends DroveResponseDataDeserializer> +public abstract class AbstractRangerDroveHubClient, + D extends DroveResponseDataDeserializer> extends AbstractRangerHubClient { - private final DroveUpstreamConfig clientConfig; - private final DroveCommunicator droveCommunicator; + private final DroveUpstreamConfig clientConfig; + private final DroveCommunicator droveCommunicator; - @Builder.Default - private final ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>(); + @Builder.Default + private final ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>(); - @Override - protected ServiceDataSource getDefaultDataSource() { - return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator); - } + @Override + protected ServiceDataSource getDefaultDataSource() { + return new DroveServiceDataSource<>(clientConfig, getMapper(), getNamespace(), droveCommunicator); + } - @Override - protected ServiceFinderHub buildHub() { - return new DroveServiceFinderHubBuilder() - .withServiceDataSource(getServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) - .withRefreshFrequencyMs(getNodeRefreshTimeMs()) - .withHubStartTimeout(getHubStartTimeoutMs()) - .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) - .withExcludedServices(getExcludedServices()) - .build(); - } + @Override + protected ServiceFinderHub buildHub() { + return new DroveServiceFinderHubBuilder() + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withRefreshFrequencyMs(getNodeRefreshTimeMs()) + .withHubStartTimeout(getHubStartTimeoutMs()) + .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) + .withExcludedServices(getExcludedServices()) + .withReplicationSource(isReplicationSource()) + .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 9f9430e6..654bee9e 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 @@ -66,6 +66,7 @@ protected ServiceFinderHub buildHub() { .withHubStartTimeout(getHubStartTimeoutMs()) .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) .withExcludedServices(getExcludedServices()) + .withReplicationSource(isReplicationSource()) .build(); } } diff --git a/ranger-http-client/src/test/java/io/appform/ranger/client/http/BaseRangerHttpClientTest.java b/ranger-http-client/src/test/java/io/appform/ranger/client/http/BaseRangerHttpClientTest.java index 1d2909f2..a4facb94 100644 --- a/ranger-http-client/src/test/java/io/appform/ranger/client/http/BaseRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/io/appform/ranger/client/http/BaseRangerHttpClientTest.java @@ -61,7 +61,7 @@ public void prepareHttpMocks() throws Exception { ServiceNodesResponse.builder() .data(Lists.newArrayList(node)) .build()); - wireMockExtension.stubFor(get(urlEqualTo("/ranger/nodes/v1/test-n/test-s")) + wireMockExtension.stubFor(get(urlPathEqualTo("/ranger/nodes/v1/test-n/test-s")) .willReturn(aResponse() .withBody(payload) .withStatus(200))); @@ -72,7 +72,7 @@ public void prepareHttpMocks() throws Exception { )) .build(); val response = objectMapper.writeValueAsBytes(responseObj); - wireMockExtension.stubFor(get(urlEqualTo("/ranger/services/v1")) + wireMockExtension.stubFor(get(urlPathEqualTo("/ranger/services/v1")) .willReturn(aResponse() .withBody(response) .withStatus(200))); diff --git a/ranger-http/pom.xml b/ranger-http/pom.xml index e98668d3..9791ff02 100644 --- a/ranger-http/pom.xml +++ b/ranger-http/pom.xml @@ -55,5 +55,11 @@ ${project.version} test-jar + + ch.qos.logback + logback-classic + ${logback.version} + test + \ No newline at end of file diff --git a/ranger-http/src/main/java/io/appform/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/io/appform/ranger/http/config/HttpClientConfig.java index 574e843c..02544d40 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/config/HttpClientConfig.java @@ -34,4 +34,5 @@ public class HttpClientConfig { long connectionTimeoutMs; long operationTimeoutMs; long refreshIntervalMillis; + boolean skipReplicatedData; } diff --git a/ranger-http/src/main/java/io/appform/ranger/http/servicefinder/HttpApiCommunicator.java b/ranger-http/src/main/java/io/appform/ranger/http/servicefinder/HttpApiCommunicator.java index 4b6247e9..58ccfae8 100644 --- a/ranger-http/src/main/java/io/appform/ranger/http/servicefinder/HttpApiCommunicator.java +++ b/ranger-http/src/main/java/io/appform/ranger/http/servicefinder/HttpApiCommunicator.java @@ -73,6 +73,7 @@ public Set services() { .host(config.getHost()) .port(config.getPort() == 0 ? defaultPort() : config.getPort()) .encodedPath("/ranger/services/v1") + .addQueryParameter("skipReplicationSources", Objects.toString(config.isSkipReplicatedData())) .build(); val request = new Request.Builder() .url(httpUrl) @@ -109,6 +110,7 @@ public List> listNodes( .host(config.getHost()) .port(config.getPort() == 0 ? defaultPort() : config.getPort()) .encodedPath(url) + .addQueryParameter("skipReplicationSources", Objects.toString(config.isSkipReplicatedData())) .build(); val request = new Request.Builder() .url(httpUrl) diff --git a/ranger-http/src/test/java/io/appform/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/io/appform/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 246cc9ab..88c1b6cb 100644 --- a/ranger-http/src/test/java/io/appform/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/io/appform/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -62,7 +62,7 @@ void testFinder(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { ServiceNodesResponse.builder() .data(Collections.singletonList(node)) .build()); - stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) + stubFor(get(urlPathEqualTo("/ranger/nodes/v1/testns/test")) .willReturn(aResponse() .withBody(payload) .withStatus(200))); 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..7733f610 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 @@ -45,7 +45,7 @@ void testServiceDataSource(WireMockRuntimeInfo wireMockRuntimeInfo) throws IOExc )) .build(); val response = MAPPER.writeValueAsBytes(responseObj); - stubFor(get(urlEqualTo("/ranger/services/v1")) + stubFor(get(urlPathEqualTo("/ranger/services/v1")) .willReturn(aResponse() .withBody(response) .withStatus(200))); diff --git a/ranger-http/src/test/java/io/appform/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java b/ranger-http/src/test/java/io/appform/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java index 32459252..a2ee5795 100644 --- a/ranger-http/src/test/java/io/appform/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java +++ b/ranger-http/src/test/java/io/appform/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java @@ -61,7 +61,7 @@ void testProvider(WireMockRuntimeInfo wireMockRuntimeInfo) throws Exception { ) .build()); byte[] requestBytes = MAPPER.writeValueAsBytes(testNode); - stubFor(post(urlEqualTo("/ranger/nodes/v1/add/testns/test")) + stubFor(post(urlPathEqualTo("/ranger/nodes/v1/add/testns/test")) .withRequestBody(binaryEqualTo(requestBytes)) .willReturn(aResponse() .withBody(response) 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 8a3eb670..63ce587e 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 @@ -109,6 +109,7 @@ private RangerHubClient> addCurat .hubStartTimeoutMs(zkConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(zkConfiguration.getNodeRefreshTimeMs()) .excludedServices(excludedServices) + .replicationSource(zkConfiguration.isReplicationSource()) .deserializer(data -> { try { return getMapper().readValue(data, new TypeReference>() { @@ -133,6 +134,7 @@ private RangerHubClient> getHttpH .hubStartTimeoutMs(httpConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(httpConfiguration.getNodeRefreshTimeMs()) .excludedServices(excludedServices) + .replicationSource(httpConfiguration.isReplicationSource()) .deserializer(data -> { try { return getMapper().readValue(data, new TypeReference<>() {}); @@ -161,6 +163,7 @@ private RangerHubClient> getDrove .hubStartTimeoutMs(droveUpstreamConfiguration.getHubStartTimeoutMs()) .nodeRefreshTimeMs(droveUpstreamConfiguration.getNodeRefreshTimeMs()) .excludedServices(excludedServices) + .replicationSource(droveUpstreamConfiguration.isReplicationSource()) .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/RangerUpstreamConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java index 06ec4b43..4061d498 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 @@ -47,6 +47,8 @@ public abstract class RangerUpstreamConfiguration { @Min(HubConstants.MINIMUM_HUB_START_TIMEOUT_MS) private int hubStartTimeoutMs = HubConstants.HUB_START_TIMEOUT_MS; + private boolean replicationSource; + protected RangerUpstreamConfiguration(BackendType type) { this.type = type; } diff --git a/ranger-hub-server-bundle/src/test/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundleTest.java b/ranger-hub-server-bundle/src/test/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundleTest.java index c1f433ba..3b41b263 100644 --- a/ranger-hub-server-bundle/src/test/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundleTest.java +++ b/ranger-hub-server-bundle/src/test/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundleTest.java @@ -106,12 +106,12 @@ protected RangerServerConfiguration getRangerConfiguration(TestConfig configurat .serviceName("service-" + i) .build()) .collect(Collectors.toUnmodifiableSet()); - stubFor(get("/ranger/services/v1") + stubFor(get(urlPathEqualTo("/ranger/services/v1")) .willReturn(okJson(environment.getObjectMapper() .writeValueAsString(ServiceDataSourceResponse.builder() .data(services) .build())))); - stubFor(any(urlMatching("/ranger/nodes/v1/test/service-[0-9]+")) + stubFor(any(urlPathMatching("/ranger/nodes/v1/test/service-[0-9]+")) .willReturn(okJson(mapper.writeValueAsString( ServiceNodesResponse.builder() .data(IntStream.rangeClosed(1, 5) diff --git a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java index a66c1045..e82f658d 100644 --- a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java +++ b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java @@ -51,7 +51,8 @@ public RangerResource(List> rangerHubs) { @GET @Path("/services/v1") @Timed - public GenericResponse> getServices() { + public GenericResponse> getServices( + @QueryParam("skipReplicationSources") @DefaultValue("false") boolean skipReplicationSources) { return GenericResponse.>builder() .data(rangerHubs.stream() .map(RangerHubClient::getRegisteredServices) @@ -65,10 +66,12 @@ public GenericResponse> getServices() { @Timed public GenericResponse>> getNodes( @NotNull @NotEmpty @PathParam("namespace") final String namespace, - @NotNull @NotEmpty @PathParam("serviceName") final String serviceName) { + @NotNull @NotEmpty @PathParam("serviceName") final String serviceName, + @QueryParam("skipReplicationSources") @DefaultValue("false") boolean skipReplicationSources) { val service = Service.builder().namespace(namespace).serviceName(serviceName).build(); return GenericResponse.>>builder() .data(rangerHubs.stream() + .filter(hub -> skipReplicationSources && !hub.isReplicationSource()) .map(hub -> hub.getAllNodes(service)) .flatMap(List::stream) .collect(Collectors.toMap(node -> node.getHost() + ":" + node.getPort(), 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 3d5b6694..d64bb060 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 @@ -36,10 +36,11 @@ public abstract class AbstractRangerZKHubClient, private final boolean disablePushUpdaters; private final String connectionString; private final CuratorFramework curatorFramework; + private boolean replicationSource; @Override protected ServiceFinderHub buildHub() { - return new ZkServiceFinderHubBuilder() + return new ZkServiceFinderHubBuilder() .withCuratorFramework(curatorFramework) .withConnectionString(connectionString) .withNamespace(getNamespace()) @@ -49,6 +50,7 @@ protected ServiceFinderHub buildHub() { .withHubStartTimeout(getHubStartTimeoutMs()) .withServiceRefreshTimeout(getServiceRefreshTimeoutMs()) .withExcludedServices(getExcludedServices()) + .withReplicationSource(isReplicationSource()) .build(); }