From 4ab3e8ead2e9b06d8a69fec3efb3eb125df7e166 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 23 Sep 2021 18:56:15 +0530 Subject: [PATCH 01/53] 1. Reorganized ranger-zookeeper and ranger-http into servicefinder, serviceprovider and servicehub package structures, each workflow has a containment 2. Added an implementation for http node data sink and registration --- .../HttpNodeDataStoreConnector.java | 2 +- .../http/model/ServiceNodesRequest.java | 18 ------- .../http/serde/HttpRequestDataSerializer.java | 11 ++++ .../JacksonHTTPResponseDataDeserializer.java | 33 ------------ .../HttpNodeDataSource.java | 3 +- .../HttpShardedServiceFinderBuilder.java | 2 +- .../serviceprovider/HttpNodeDataSink.java | 54 +++++++++++++++++++ .../HttpServiceProviderBuilder.java | 37 +++++++++++++ .../HttpShardedServiceFinderBuilderTest.java | 1 + .../zookeeper/ServiceFinderBuilders.java | 4 +- .../zookeeper/ServiceProviderBuilders.java | 2 +- .../ZkWatcherRegistryUpdateSignal.java | 2 +- .../ZkNodeDataSource.java | 3 +- .../ZkShardedServiceFinderFactory.java | 2 +- .../ZkSimpleShardedServiceFinderBuilder.java | 3 +- .../ZkUnshardedFinderBuilder.java | 3 +- .../ServiceFinderHubBuilder.java | 2 +- .../ZkNodeDataStoreConnector.java | 2 +- .../ZkServiceDataSource.java | 2 +- .../ZkServiceFinderHubBuilder.java | 2 +- .../ZkNodeDataSink.java | 3 +- .../ZkServiceProviderBuilder.java | 2 +- .../zookeeper/servicehub/ServiceHubTest.java | 6 +-- 23 files changed, 128 insertions(+), 71 deletions(-) rename ranger-http/src/main/java/com/flipkart/ranger/http/{ => common}/HttpNodeDataStoreConnector.java (97%) delete mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesRequest.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java delete mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/serde/JacksonHTTPResponseDataDeserializer.java rename ranger-http/src/main/java/com/flipkart/ranger/http/{ => servicefinder}/HttpNodeDataSource.java (96%) rename ranger-http/src/main/java/com/flipkart/ranger/http/{ => servicefinder}/HttpShardedServiceFinderBuilder.java (95%) create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => common}/ZkWatcherRegistryUpdateSignal.java (97%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinder}/ZkNodeDataSource.java (96%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinder}/ZkShardedServiceFinderFactory.java (97%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinder}/ZkSimpleShardedServiceFinderBuilder.java (95%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinder}/ZkUnshardedFinderBuilder.java (95%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinderhub}/ServiceFinderHubBuilder.java (98%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinderhub}/ZkNodeDataStoreConnector.java (98%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinderhub}/ZkServiceDataSource.java (96%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => servicefinderhub}/ZkServiceFinderHubBuilder.java (97%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => serviceprovider}/ZkNodeDataSink.java (95%) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{zk => serviceprovider}/ZkServiceProviderBuilder.java (97%) diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java similarity index 97% rename from ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataStoreConnector.java rename to ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index ee0e61be..af207a3e 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.http; +package com.flipkart.ranger.http.common; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.model.NodeDataStoreConnector; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesRequest.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesRequest.java deleted file mode 100644 index 548560a9..00000000 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesRequest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.flipkart.ranger.http.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Builder; -import lombok.Data; - -/** - * - */ -@Data -public class ServiceNodesRequest { - private final String serviceName; - - @Builder - public ServiceNodesRequest(@JsonProperty("serviceName") String serviceName) { - this.serviceName = serviceName; - } -} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java new file mode 100644 index 00000000..2ca42b57 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java @@ -0,0 +1,11 @@ +package com.flipkart.ranger.http.serde; + +import com.flipkart.ranger.core.model.Serializer; +import com.flipkart.ranger.core.model.ServiceNode; + +@FunctionalInterface +public interface HttpRequestDataSerializer extends Serializer { + + byte[] serialize(final ServiceNode node); + +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/JacksonHTTPResponseDataDeserializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/JacksonHTTPResponseDataDeserializer.java deleted file mode 100644 index 64ff3600..00000000 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/JacksonHTTPResponseDataDeserializer.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.flipkart.ranger.http.serde; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.http.model.ServiceNodesResponse; - -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; - -/** - * - */ -public class JacksonHTTPResponseDataDeserializer implements HTTPResponseDataDeserializer { - private final ObjectMapper mapper; - - public JacksonHTTPResponseDataDeserializer(ObjectMapper mapper) { - this.mapper = mapper; - } - - @Override - public Collection> deserialize(byte[] data) { - try { - final ServiceNodesResponse response - = mapper.readValue(data, new TypeReference>() {}); - return response.isSuccess() ? response.getNodes() : Collections.emptyList(); - } - catch (IOException e) { - throw new IllegalArgumentException(e); - } - } -} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java similarity index 96% rename from ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataSource.java rename to ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 9ec4d2d7..0e038fdf 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.http; +package com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.model.NodeDataSource; @@ -6,6 +6,7 @@ import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.core.util.FinderUtils; +import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java similarity index 95% rename from ranger-http/src/main/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilder.java rename to ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 042f56e2..b3b1228c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.http; +package com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java new file mode 100644 index 00000000..ea87e52e --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -0,0 +1,54 @@ +package com.flipkart.ranger.http.serviceprovider; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.model.NodeDataSink; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; +import com.google.common.base.Preconditions; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.RequestBody; + +import java.io.IOException; + +@Slf4j +public class HttpNodeDataSink> extends HttpNodeDataStoreConnector implements NodeDataSink { + + public HttpNodeDataSink(Service service, HttpClientConfig config, ObjectMapper mapper) { + super(service, config, mapper); + } + + @Override + public void updateState(S serializer, ServiceNode serviceNode) { + Preconditions.checkNotNull(serializer, "Serializer has not been set for node data"); + val httpUrl = new HttpUrl.Builder() + .scheme(config.isSecure() + ? "https" + : "http") + .host(config.getHost()) + .port(config.getPort() == 0 + ? defaultPort() + : config.getPort()) + .encodedPath(String.format("/ranger/nodes/v1/add/%s/%s", service.getNamespace(), service.getServiceName())) + .build(); + RequestBody requestBody = RequestBody.create(serializer.serialize(serviceNode)); + val request = new Request.Builder() + .url(httpUrl) + .post(requestBody) + .build(); + try (val response = httpClient.newCall(request).execute()) { + if (!response.isSuccessful()) { + log.warn("HTTP call to {} returned: {}", httpUrl.toString(), response.code()); + } + } + catch (IOException e) { + Exceptions.illegalState("Error updating the server with service data: " + httpUrl, e); + } + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java new file mode 100644 index 00000000..f10bddc5 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java @@ -0,0 +1,37 @@ +package com.flipkart.ranger.http.serviceprovider; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.model.NodeDataSink; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.serviceprovider.BaseServiceProviderBuilder; +import com.flipkart.ranger.core.serviceprovider.ServiceProvider; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HttpServiceProviderBuilder extends BaseServiceProviderBuilder, HttpRequestDataSerializer> { + + private HttpClientConfig clientConfig; + private ObjectMapper mapper; + + public HttpServiceProviderBuilder withClientConfiguration(final HttpClientConfig clientConfig) { + this.clientConfig = clientConfig; + return this; + } + + public HttpServiceProviderBuilder withObjectmapper(final ObjectMapper mapper){ + this.mapper = mapper; + return this; + } + + @Override + public ServiceProvider> build() { + return super.buildProvider(); + } + + @Override + protected NodeDataSink> dataSink(Service service) { + return new HttpNodeDataSink<>(service, clientConfig, mapper); + } +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java index 7415aaa4..7011a0d0 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java @@ -10,6 +10,7 @@ import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; import com.github.tomakehurst.wiremock.junit.WireMockRule; import lombok.Data; import lombok.val; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index 33c2dbc3..504e46c5 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -16,8 +16,8 @@ package com.flipkart.ranger.zookeeper; -import com.flipkart.ranger.zookeeper.zk.ZkSimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.zookeeper.zk.ZkUnshardedFinderBuilder; +import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.zookeeper.servicefinder.ZkUnshardedFinderBuilder; public class ServiceFinderBuilders { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java index 9feac3c4..b636d243 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.zookeeper; -import com.flipkart.ranger.zookeeper.zk.ZkServiceProviderBuilder; +import com.flipkart.ranger.zookeeper.serviceprovider.ZkServiceProviderBuilder; import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; public class ServiceProviderBuilders { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkWatcherRegistryUpdateSignal.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java similarity index 97% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkWatcherRegistryUpdateSignal.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java index e4d9c3dc..76b94b42 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkWatcherRegistryUpdateSignal.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.common; import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java similarity index 96% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSource.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index 9d701053..371e414c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -1,9 +1,10 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.FinderUtils; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkNodeDataStoreConnector; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.util.PathBuilder; import com.google.common.base.Preconditions; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java similarity index 97% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkShardedServiceFinderFactory.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java index f6feca8d..0d82fa14 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.sharded.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java similarity index 95% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkSimpleShardedServiceFinderBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index bfb6345d..88b3f930 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -1,10 +1,11 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; +import com.flipkart.ranger.zookeeper.common.ZkWatcherRegistryUpdateSignal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkUnshardedFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java similarity index 95% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkUnshardedFinderBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java index 1e0259d3..64e92bba 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkUnshardedFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterFinder; import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; @@ -6,6 +6,7 @@ import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; +import com.flipkart.ranger.zookeeper.common.ZkWatcherRegistryUpdateSignal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java similarity index 98% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ServiceFinderHubBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java index 91d28c3b..973a69dd 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataStoreConnector.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java similarity index 98% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataStoreConnector.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java index 2ad0c2f4..fb2d51cb 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataStoreConnector.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java similarity index 96% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceDataSource.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 3f3cfd00..011b19a8 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java similarity index 97% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceFinderHubBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 9fa692b6..6aa678a1 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.model.ServiceRegistry; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSink.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java similarity index 95% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSink.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java index 3e5d27ab..41050eb3 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkNodeDataSink.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java @@ -1,9 +1,10 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.serviceprovider; import com.flipkart.ranger.core.model.NodeDataSink; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkNodeDataStoreConnector; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; import com.flipkart.ranger.zookeeper.util.PathBuilder; import com.google.common.base.Preconditions; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceProviderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java similarity index 97% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceProviderBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java index cb6a47f8..0a37fd55 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/zk/ZkServiceProviderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.zk; +package com.flipkart.ranger.zookeeper.serviceprovider; import com.flipkart.ranger.core.model.NodeDataSink; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 6292b505..9a04dd45 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -12,9 +12,9 @@ import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.core.utils.TestUtils; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; -import com.flipkart.ranger.zookeeper.zk.ZkServiceDataSource; -import com.flipkart.ranger.zookeeper.zk.ZkShardedServiceFinderFactory; -import com.flipkart.ranger.zookeeper.zk.ZkServiceFinderHubBuilder; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; +import com.flipkart.ranger.zookeeper.servicefinder.ZkShardedServiceFinderFactory; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; import lombok.Data; import lombok.extern.slf4j.Slf4j; import lombok.val; From 36429bb89fcbc7d7f49f3e0fc1575e3b98ebb91c Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 23 Sep 2021 18:58:15 +0530 Subject: [PATCH 02/53] Moved ZKWatcherRegistryUpdateSignal into signals in finder --- .../servicefinder/ZkSimpleShardedServiceFinderBuilder.java | 2 +- .../zookeeper/servicefinder/ZkUnshardedFinderBuilder.java | 2 +- .../signals}/ZkWatcherRegistryUpdateSignal.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{common => servicefinder/signals}/ZkWatcherRegistryUpdateSignal.java (97%) diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index 88b3f930..fde11e7e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -5,8 +5,8 @@ import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; -import com.flipkart.ranger.zookeeper.common.ZkWatcherRegistryUpdateSignal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; +import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java index 64e92bba..881e4f71 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java @@ -6,8 +6,8 @@ import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; -import com.flipkart.ranger.zookeeper.common.ZkWatcherRegistryUpdateSignal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; +import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java similarity index 97% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java index 76b94b42..832923e2 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkWatcherRegistryUpdateSignal.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.common; +package com.flipkart.ranger.zookeeper.servicefinder.signals; import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; From 39d6ba99349ba3e3fa89acdd30e30fc066309e76 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 23 Sep 2021 22:42:17 +0530 Subject: [PATCH 03/53] Moved ZKNodeDataStoreConnector to commons in ZK Added a dummy project structure for ranger-server --- pom.xml | 6 ++-- .../core/finder/ServiceRegistryUpdater.java | 8 ++--- .../sharded/MapBasedServiceRegistry.java | 3 +- .../SimpleShardedServiceFinderBuilder.java | 1 - .../common/HttpNodeDataStoreConnector.java | 1 - .../ranger/http/config/HttpClientConfig.java | 1 - .../model/ServiceRegistrationResponse.java | 17 ++++++++++ .../serviceprovider/HttpNodeDataSink.java | 32 ++++++++++++++++--- .../java/com/flipkart/ranger/server/App.java | 4 +++ .../ranger/server/AppConfiguration.java | 4 +++ .../server/resources/RangerResource.java | 4 +++ .../ZkNodeDataStoreConnector.java | 2 +- .../servicefinder/ZkNodeDataSource.java | 2 +- .../serviceprovider/ZkNodeDataSink.java | 2 +- 14 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/App.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{servicefinderhub => common}/ZkNodeDataStoreConnector.java (98%) diff --git a/pom.xml b/pom.xml index 5e6d95f0..4bb0a0e5 100644 --- a/pom.xml +++ b/pom.xml @@ -60,8 +60,8 @@ 1.7.32 3.8.0 - 1.8 - 1.18.20 + 11 + 1.18.2 4.13.2 4.1.0 @@ -78,7 +78,7 @@ com.google.code.findbugs annotations - 3.0.1u2 + 3.0.1 com.google.guava diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java index c348036f..460ecca9 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java @@ -134,11 +134,11 @@ private void updateRegistry() { serviceRegistry.getService().getServiceName()); return; } - val nodes = nodeDataSource.refresh(deserializer).orElse(null); - if (null != nodes) { - log.debug("Updating nodelist of size: {} for [{}]", nodes.size(), + val nodeList = nodeDataSource.refresh(deserializer); + if (nodeList.isPresent()) { + log.debug("Updating nodelist of size: {} for [{}]", nodeList.get().size(), serviceRegistry.getService().getServiceName()); - serviceRegistry.updateNodes(nodes); + serviceRegistry.updateNodes(nodeList.get()); initialRefreshCompleted.compareAndSet(false, true); } else { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java index 116b411e..83b0f903 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java @@ -29,8 +29,7 @@ public class MapBasedServiceRegistry extends ServiceRegistry { private AtomicReference>> nodes = new AtomicReference<>(); - public MapBasedServiceRegistry( - Service service) { + public MapBasedServiceRegistry(Service service) { super(service); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java index 25a2a596..fa05593b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java @@ -36,5 +36,4 @@ protected SimpleShardedServiceFinder buildFinder( final MapBasedServiceRegistry serviceRegistry = new MapBasedServiceRegistry<>(service); return new SimpleShardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); } - } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index af207a3e..06999dc6 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -21,7 +21,6 @@ public class HttpNodeDataStoreConnector implements NodeDataStoreConnector protected final HttpClientConfig config; protected final OkHttpClient httpClient; protected final ObjectMapper mapper; - protected final AtomicBoolean firstCall = new AtomicBoolean(false); public HttpNodeDataStoreConnector( Service service, diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java index ebac969d..f755f8a6 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java @@ -15,5 +15,4 @@ public class HttpClientConfig { private long connectionTimeoutMs; private long operationTimeoutMs; private String nodesRequestPath; - } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java new file mode 100644 index 00000000..cc3e5f76 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java @@ -0,0 +1,17 @@ +package com.flipkart.ranger.http.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; + +@Data +public class ServiceRegistrationResponse { + private final boolean success; + + @Builder + public ServiceRegistrationResponse( + @JsonProperty("success") boolean success + ) { + this.success = success; + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index ea87e52e..cbcd7366 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -5,8 +5,10 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.core.util.FinderUtils; import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceRegistrationResponse; import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; @@ -14,8 +16,10 @@ import okhttp3.HttpUrl; import okhttp3.Request; import okhttp3.RequestBody; +import okhttp3.ResponseBody; import java.io.IOException; +import java.util.Optional; @Slf4j public class HttpNodeDataSink> extends HttpNodeDataStoreConnector implements NodeDataSink { @@ -26,7 +30,6 @@ public HttpNodeDataSink(Service service, HttpClientConfig config, ObjectMapper m @Override public void updateState(S serializer, ServiceNode serviceNode) { - Preconditions.checkNotNull(serializer, "Serializer has not been set for node data"); val httpUrl = new HttpUrl.Builder() .scheme(config.isSecure() ? "https" @@ -37,18 +40,37 @@ public void updateState(S serializer, ServiceNode serviceNode) { : config.getPort()) .encodedPath(String.format("/ranger/nodes/v1/add/%s/%s", service.getNamespace(), service.getServiceName())) .build(); - RequestBody requestBody = RequestBody.create(serializer.serialize(serviceNode)); + val requestBody = RequestBody.create(serializer.serialize(serviceNode)); + val serviceRegistrationResponse = registerService(httpUrl, requestBody); + if(!serviceRegistrationResponse.isPresent() || !serviceRegistrationResponse.get().isSuccess()){ + Exceptions.illegalState("Error updating state on the server for nodedata: " + httpUrl); + } + } + + private Optional registerService(HttpUrl httpUrl, RequestBody requestBody){ val request = new Request.Builder() .url(httpUrl) .post(requestBody) .build(); try (val response = httpClient.newCall(request).execute()) { - if (!response.isSuccessful()) { - log.warn("HTTP call to {} returned: {}", httpUrl.toString(), response.code()); + if (response.isSuccessful()) { + try (final ResponseBody body = response.body()) { + if (null == body) { + log.warn("HTTP call to {} returned empty body", httpUrl); + } + else { + final byte[] bytes = body.bytes(); + return Optional.of(mapper.readValue(bytes, ServiceRegistrationResponse.class)); + } + } + } + else { + log.warn("HTTP call to {} has returned: {}", httpUrl, response.code()); } } catch (IOException e) { - Exceptions.illegalState("Error updating the server with service data: " + httpUrl, e); + Exceptions.illegalState("Error updating state on the server: " + httpUrl, e); } + return Optional.empty(); } } diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/App.java b/ranger-server/src/main/java/com/flipkart/ranger/server/App.java new file mode 100644 index 00000000..34a18f60 --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/App.java @@ -0,0 +1,4 @@ +package com.flipkart.ranger.server; + +public class App { +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java b/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java new file mode 100644 index 00000000..88513c7c --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java @@ -0,0 +1,4 @@ +package com.flipkart.ranger.server; + +public class AppConfiguration { +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java new file mode 100644 index 00000000..588219a7 --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java @@ -0,0 +1,4 @@ +package com.flipkart.ranger.server.resources; + +public class RangerResource { +} diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java similarity index 98% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java index fb2d51cb..28e981a9 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkNodeDataStoreConnector.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.servicefinderhub; +package com.flipkart.ranger.zookeeper.common; import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index 371e414c..065013a6 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -4,7 +4,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.FinderUtils; -import com.flipkart.ranger.zookeeper.servicefinderhub.ZkNodeDataStoreConnector; +import com.flipkart.ranger.zookeeper.common.ZkNodeDataStoreConnector; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.util.PathBuilder; import com.google.common.base.Preconditions; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java index 41050eb3..b2e0d48e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java @@ -4,7 +4,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.zookeeper.servicefinderhub.ZkNodeDataStoreConnector; +import com.flipkart.ranger.zookeeper.common.ZkNodeDataStoreConnector; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; import com.flipkart.ranger.zookeeper.util.PathBuilder; import com.google.common.base.Preconditions; From 86d16382cead9a7be2d0eb38d1eebbd592769eff Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 23 Sep 2021 22:48:37 +0530 Subject: [PATCH 04/53] Restored the java version to 1.8 for backward compatibility --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4bb0a0e5..6deb4a58 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 1.7.32 3.8.0 - 11 + 1.8 1.18.2 4.13.2 From bf3325cc4629acd2e3db51ed22dfe8cb9cc4f379 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 24 Sep 2021 15:01:29 +0530 Subject: [PATCH 05/53] Optimized imports --- .../ranger/core/finder/ServiceFinder.java | 2 +- .../finder/sharded/MatchingShardSelector.java | 2 +- .../sharded/SimpleShardedServiceFinder.java | 2 +- .../finder/unsharded/NoOpShardSelector.java | 2 +- .../unsharded/UnshardedFinderBuilder.java | 4 +- .../ServiceHealthAggregator.java | 4 +- .../monitor/IsolatedHealthMonitor.java | 2 +- .../monitor/sample/CountMonitor.java | 2 +- .../BaseServiceProviderBuilder.java | 5 +- .../core/serviceprovider/ServiceProvider.java | 7 +- .../http/HttpServiceFinderBuilders.java | 15 ++++ .../http/HttpServiceProviderBuilders.java | 14 +++ .../common/HttpNodeDataStoreConnector.java | 4 +- .../servicefinder/HttpNodeDataSource.java | 3 + .../HttpShardedServiceFinderBuilder.java | 17 +++- .../serviceprovider/HttpNodeDataSink.java | 8 +- .../HttpServiceProviderBuilder.java | 5 +- .../HttpShardedServiceFinderBuilderTest.java | 88 +++++++++---------- .../zookeeper/ServiceProviderBuilders.java | 2 +- .../ZkWatcherRegistryUpdateSignal.java | 2 +- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 21 files changed, 124 insertions(+), 68 deletions(-) create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index d6004f9f..36a1e089 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -17,10 +17,10 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; -import com.flipkart.ranger.core.model.ServiceNodeSelector; import lombok.Getter; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java index 5dc212ae..265e69d3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java @@ -16,8 +16,8 @@ package com.flipkart.ranger.core.finder.sharded; -import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java index 5c0405c3..ba27a764 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java @@ -16,9 +16,9 @@ package com.flipkart.ranger.core.finder.sharded; -import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; public class SimpleShardedServiceFinder extends ServiceFinder> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java index 3718eb50..39c1a2cd 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java @@ -16,8 +16,8 @@ package com.flipkart.ranger.core.finder.unsharded; -import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java index b9af94aa..010b3d82 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java @@ -16,11 +16,11 @@ package com.flipkart.ranger.core.finder.unsharded; +import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder; import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder; import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; public abstract class UnshardedFinderBuilder, D extends Deserializer> extends BaseServiceFinderBuilder { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java index 094e43fc..68dee1ff 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java @@ -16,10 +16,10 @@ package com.flipkart.ranger.core.healthservice; -import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; -import com.flipkart.ranger.core.healthservice.monitor.Monitor; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; +import com.flipkart.ranger.core.healthservice.monitor.Monitor; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java index 19511975..0597d466 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java @@ -16,10 +16,10 @@ package com.flipkart.ranger.core.healthservice.monitor; +import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.CountMonitor; import com.flipkart.ranger.core.healthservice.monitor.sample.PingCheckMonitor; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; -import com.flipkart.ranger.core.healthservice.TimeEntity; import java.util.Date; import java.util.concurrent.atomic.AtomicBoolean; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java index 2529bfa5..14acdaed 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java @@ -16,9 +16,9 @@ package com.flipkart.ranger.core.healthservice.monitor.sample; -import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.healthservice.TimeEntity; +import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; /** * A monitor that can be used as a counting monitor to check if any countable entity breaches a threashhold diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java index 38db70af..c8a8f7b6 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java @@ -22,7 +22,10 @@ import com.flipkart.ranger.core.healthservice.HealthService; import com.flipkart.ranger.core.healthservice.ServiceHealthAggregator; import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.NodeDataSink; +import com.flipkart.ranger.core.model.Serializer; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ScheduledSignal; import com.flipkart.ranger.core.signals.Signal; import com.google.common.base.Preconditions; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java index 2c19997e..dac9caef 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java @@ -16,10 +16,13 @@ package com.flipkart.ranger.core.serviceprovider; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.healthcheck.HealthcheckResult; +import com.flipkart.ranger.core.model.NodeDataSink; +import com.flipkart.ranger.core.model.Serializer; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.signals.Signal; -import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import lombok.Getter; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java new file mode 100644 index 00000000..c50cfe95 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -0,0 +1,15 @@ +package com.flipkart.ranger.http; + +import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; + +public class HttpServiceFinderBuilders { + + private void HttpServiceProviderBuilders(){ + throw new InstantiationError("Must not instantiate this class"); + } + + public static HttpShardedServiceFinderBuilder httpShardedServiceFinderBuilder(){ + return new HttpShardedServiceFinderBuilder<>(); + } + +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java new file mode 100644 index 00000000..694d7594 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java @@ -0,0 +1,14 @@ +package com.flipkart.ranger.http; + +import com.flipkart.ranger.http.serviceprovider.HttpServiceProviderBuilder; + +public class HttpServiceProviderBuilders { + + private HttpServiceProviderBuilders() { + throw new InstantiationError("Must not instantiate this class"); + } + + public static HttpServiceProviderBuilder httpServiceProviderBuilder() { + return new HttpServiceProviderBuilder<>(); + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index 06999dc6..f9413bae 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -4,12 +4,14 @@ import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; +import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; +import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; /** * diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 0e038fdf..04939323 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -9,6 +9,7 @@ import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; import lombok.val; import okhttp3.HttpUrl; @@ -34,6 +35,8 @@ public HttpNodeDataSource( @Override public Optional>> refresh(D deserializer) { + Preconditions.checkNotNull(config, "client config has not been set for node data"); + Preconditions.checkNotNull(mapper, "mapper has not been set for node data"); val httpUrl = new HttpUrl.Builder() .scheme(config.isSecure() ? "https" diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index b3b1228c..676b2704 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -7,26 +7,35 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import com.google.common.base.Preconditions; /** * */ -public class HttpShardedServiceFinderBuilder> extends SimpleShardedServiceFinderBuilder, D> { +public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer> { private HttpClientConfig clientConfig; + private ObjectMapper mapper; - public HttpShardedServiceFinderBuilder withClientConfig(final HttpClientConfig clientConfig) { + public HttpShardedServiceFinderBuilder withClientConfig(final HttpClientConfig clientConfig) { this.clientConfig = clientConfig; return this; } + public HttpShardedServiceFinderBuilder withObjectMapper(final ObjectMapper mapper){ + this.mapper = mapper; + return this; + } + @Override public SimpleShardedServiceFinder build() { return buildFinder(); } @Override - protected NodeDataSource dataSource(Service service) { - return new HttpNodeDataSource<>(service, clientConfig, new ObjectMapper()); + protected NodeDataSource> dataSource(Service service) { + return new HttpNodeDataSource<>(service, clientConfig, mapper); } + + } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index cbcd7366..de2ee759 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -5,7 +5,6 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.util.FinderUtils; import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceRegistrationResponse; @@ -30,6 +29,9 @@ public HttpNodeDataSink(Service service, HttpClientConfig config, ObjectMapper m @Override public void updateState(S serializer, ServiceNode serviceNode) { + Preconditions.checkNotNull(config, "client config has not been set for node data"); + Preconditions.checkNotNull(mapper, "mapper has not been set for node data"); + val httpUrl = new HttpUrl.Builder() .scheme(config.isSecure() ? "https" @@ -60,7 +62,9 @@ private Optional registerService(HttpUrl httpUrl, R } else { final byte[] bytes = body.bytes(); - return Optional.of(mapper.readValue(bytes, ServiceRegistrationResponse.class)); + return Optional.of( + mapper.readValue(bytes, ServiceRegistrationResponse.class) + ); } } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java index f10bddc5..83c85962 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java @@ -20,7 +20,7 @@ public HttpServiceProviderBuilder withClientConfiguration(final HttpClientCon return this; } - public HttpServiceProviderBuilder withObjectmapper(final ObjectMapper mapper){ + public HttpServiceProviderBuilder withObjectMapper(final ObjectMapper mapper){ this.mapper = mapper; return this; } @@ -32,6 +32,9 @@ public ServiceProvider> build() { @Override protected NodeDataSink> dataSink(Service service) { + if(null == mapper){ + mapper = new ObjectMapper(); + } return new HttpNodeDataSink<>(service, clientConfig, mapper); } } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java index 7011a0d0..54584e87 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java @@ -46,50 +46,50 @@ public NodeData(@JsonProperty("name") String name) { @Test public void testFinder() throws Exception { - final NodeData testNode = new NodeData("testNode"); - final ServiceNode node = new ServiceNode<>("127.0.0.1", 80, testNode); - node.setHealthcheckStatus(HealthcheckStatus.healthy); - node.setLastUpdatedTimeStamp(System.currentTimeMillis()); - val payload = MAPPER.writeValueAsBytes( - ServiceNodesResponse.builder() - .node(node) - .success(true) - .build()); - server.stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) - .willReturn(aResponse() - .withBody(payload) - .withStatus(200))); - val clientConfig = HttpClientConfig.builder() - .host("127.0.0.1") - .port(server.port()) - .connectionTimeoutMs(30_000) - .operationTimeoutMs(30_000) - .build(); - final SimpleShardedServiceFinder finder = new HttpShardedServiceFinderBuilder>() - .withClientConfig(clientConfig) - .withNamespace("testns") - .withServiceName("test") - .withDeserializer(data -> { - final ServiceNodesResponse response; - try { - response = MAPPER.readValue(data, new TypeReference>() {}); - } - catch (IOException e) { - throw new IllegalArgumentException(e); - } - return response.isSuccess() ? response.getNodes() : Collections.emptyList(); - }) - .withShardSelector((criteria, registry) -> registry - .nodes() - .entries() - .stream() - .filter(e -> e.getKey().getName().equals(criteria.getName())) - .map(Map.Entry::getValue) - .collect(Collectors.toList())) - .build(); - finder.start(); - TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(testNode)); +// final NodeData testNode = new NodeData("testNode"); +// final ServiceNode node = new ServiceNode<>("127.0.0.1", 80, testNode); +// node.setHealthcheckStatus(HealthcheckStatus.healthy); +// node.setLastUpdatedTimeStamp(System.currentTimeMillis()); +// val payload = MAPPER.writeValueAsBytes( +// ServiceNodesResponse.builder() +// .node(node) +// .success(true) +// .build()); +// server.stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) +// .willReturn(aResponse() +// .withBody(payload) +// .withStatus(200))); +// val clientConfig = HttpClientConfig.builder() +// .host("127.0.0.1") +// .port(server.port()) +// .connectionTimeoutMs(30_000) +// .operationTimeoutMs(30_000) +// .build(); +// final SimpleShardedServiceFinder finder = new HttpShardedServiceFinderBuilder>() +// .withClientConfig(clientConfig) +// .withNamespace("testns") +// .withServiceName("test") +// .withDeserializer(data -> { +// final ServiceNodesResponse response; +// try { +// response = MAPPER.readValue(data, new TypeReference>() {}); +// } +// catch (IOException e) { +// throw new IllegalArgumentException(e); +// } +// return response.isSuccess() ? response.getNodes() : Collections.emptyList(); +// }) +// .withShardSelector((criteria, registry) -> registry +// .nodes() +// .entries() +// .stream() +// .filter(e -> e.getKey().getName().equals(criteria.getName())) +// .map(Map.Entry::getValue) +// .collect(Collectors.toList())) +// .build(); +// finder.start(); +// TestUtils.sleepForSeconds(3); +// Assert.assertNotNull(finder.get(testNode)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java index b636d243..568ed6fe 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java @@ -16,8 +16,8 @@ package com.flipkart.ranger.zookeeper; -import com.flipkart.ranger.zookeeper.serviceprovider.ZkServiceProviderBuilder; import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; +import com.flipkart.ranger.zookeeper.serviceprovider.ZkServiceProviderBuilder; public class ServiceProviderBuilders { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java index 832923e2..901c2c7b 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java @@ -2,8 +2,8 @@ import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.zookeeper.util.PathBuilder; import com.flipkart.ranger.core.signals.Signal; +import com.flipkart.ranger.zookeeper.util.PathBuilder; import lombok.EqualsAndHashCode; import lombok.ToString; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 9a04dd45..d988f004 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -12,8 +12,8 @@ import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.core.utils.TestUtils; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; -import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import com.flipkart.ranger.zookeeper.servicefinder.ZkShardedServiceFinderFactory; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; import lombok.Data; import lombok.extern.slf4j.Slf4j; From 7210e86f00223542092f55e2685484a77488eaf2 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 24 Sep 2021 15:03:15 +0530 Subject: [PATCH 06/53] Fixed HttpShardedServiceFinderBuilderTest --- .../HttpShardedServiceFinderBuilderTest.java | 91 ++++++++++--------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java index 54584e87..67800fd0 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java @@ -9,7 +9,6 @@ import com.flipkart.ranger.core.utils.TestUtils; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; -import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; import com.github.tomakehurst.wiremock.junit.WireMockRule; import lombok.Data; @@ -46,50 +45,52 @@ public NodeData(@JsonProperty("name") String name) { @Test public void testFinder() throws Exception { -// final NodeData testNode = new NodeData("testNode"); -// final ServiceNode node = new ServiceNode<>("127.0.0.1", 80, testNode); -// node.setHealthcheckStatus(HealthcheckStatus.healthy); -// node.setLastUpdatedTimeStamp(System.currentTimeMillis()); -// val payload = MAPPER.writeValueAsBytes( -// ServiceNodesResponse.builder() -// .node(node) -// .success(true) -// .build()); -// server.stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) -// .willReturn(aResponse() -// .withBody(payload) -// .withStatus(200))); -// val clientConfig = HttpClientConfig.builder() -// .host("127.0.0.1") -// .port(server.port()) -// .connectionTimeoutMs(30_000) -// .operationTimeoutMs(30_000) -// .build(); -// final SimpleShardedServiceFinder finder = new HttpShardedServiceFinderBuilder>() -// .withClientConfig(clientConfig) -// .withNamespace("testns") -// .withServiceName("test") -// .withDeserializer(data -> { -// final ServiceNodesResponse response; -// try { -// response = MAPPER.readValue(data, new TypeReference>() {}); -// } -// catch (IOException e) { -// throw new IllegalArgumentException(e); -// } -// return response.isSuccess() ? response.getNodes() : Collections.emptyList(); -// }) -// .withShardSelector((criteria, registry) -> registry -// .nodes() -// .entries() -// .stream() -// .filter(e -> e.getKey().getName().equals(criteria.getName())) -// .map(Map.Entry::getValue) -// .collect(Collectors.toList())) -// .build(); -// finder.start(); -// TestUtils.sleepForSeconds(3); -// Assert.assertNotNull(finder.get(testNode)); + final NodeData testNode = new NodeData("testNode"); + final ServiceNode node = new ServiceNode<>("127.0.0.1", 80, testNode); + node.setHealthcheckStatus(HealthcheckStatus.healthy); + node.setLastUpdatedTimeStamp(System.currentTimeMillis()); + val payload = MAPPER.writeValueAsBytes( + ServiceNodesResponse.builder() + .node(node) + .success(true) + .build()); + server.stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) + .willReturn(aResponse() + .withBody(payload) + .withStatus(200))); + val clientConfig = HttpClientConfig.builder() + .host("127.0.0.1") + .port(server.port()) + .connectionTimeoutMs(30_000) + .operationTimeoutMs(30_000) + .build(); + + final SimpleShardedServiceFinder finder = new HttpShardedServiceFinderBuilder() + .withClientConfig(clientConfig) + .withNamespace("testns") + .withServiceName("test") + .withObjectMapper(MAPPER) + .withDeserializer(data -> { + final ServiceNodesResponse response; + try { + response = MAPPER.readValue(data, new TypeReference>() {}); + } + catch (IOException e) { + throw new IllegalArgumentException(e); + } + return response.isSuccess() ? response.getNodes() : Collections.emptyList(); + }) + .withShardSelector((criteria, registry) -> registry + .nodes() + .entries() + .stream() + .filter(e -> e.getKey().getName().equals(criteria.getName())) + .map(Map.Entry::getValue) + .collect(Collectors.toList())) + .build(); + finder.start(); + TestUtils.sleepForSeconds(3); + Assert.assertNotNull(finder.get(testNode)); } } \ No newline at end of file From b7b68cee5bc4bf5faad263f9a659c7a6efa66206 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 24 Sep 2021 18:55:07 +0530 Subject: [PATCH 07/53] Added healthcheck handlers for service provision --- .../BaseServiceProviderBuilder.java | 26 ++++++++++++------- .../common/HttpNodeDataStoreConnector.java | 2 +- .../ranger/http/config/HttpClientConfig.java | 2 +- .../HttpShardedServiceFinderBuilder.java | 1 - .../HttpServiceProviderBuilder.java | 3 --- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java index c8a8f7b6..8f46a0d8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java @@ -51,11 +51,12 @@ public abstract class BaseServiceProviderBuilder healthchecks = Lists.newArrayList(); protected NodeDataSink nodeDataSource = null; + protected List healthchecks = Lists.newArrayList(); + protected List> healthCheckHandlers = Lists.newArrayList(); protected final List> startSignalHandlers = Lists.newArrayList(); protected final List> stopSignalHandlers = Lists.newArrayList(); - protected final List> extraRefreshSignals = Lists.newArrayList(); + protected final List> additionalRefreshSignals = Lists.newArrayList(); /* list of isolated monitors */ private List isolatedMonitors = Lists.newArrayList(); @@ -95,6 +96,11 @@ public B withHealthcheck(Healthcheck healthcheck) { return (B)this; } + public B withHealthcheckHandlers(List> healthCheckHandlers){ + this.healthCheckHandlers.addAll(healthCheckHandlers); + return (B)this; + } + public B withHealthUpdateIntervalMs(int healthUpdateIntervalMs) { this.healthUpdateIntervalMs = healthUpdateIntervalMs; return (B)this; @@ -144,13 +150,13 @@ public B withStopSignalHandlers(List> stopSignalHandlers) { return (B)this; } - public B withExtraRefreshSignal(Signal extraRefreshSignal) { - this.extraRefreshSignals.add(extraRefreshSignal); + public B withadditionalRefreshSignal(Signal additionalRefreshSignal) { + this.additionalRefreshSignals.add(additionalRefreshSignal); return (B)this; } - public B withExtraRefreshSignals(List> extraRefreshSignals) { - this.extraRefreshSignals.addAll(extraRefreshSignals); + public B withAdditionalRefreshSignals(List> additionalRefreshSignals) { + this.additionalRefreshSignals.addAll(additionalRefreshSignals); return (B)this; } @@ -178,21 +184,23 @@ protected final ServiceProvider buildProvider() { for (IsolatedHealthMonitor isolatedMonitor : isolatedMonitors) { serviceHealthAggregator.addIsolatedMonitor(isolatedMonitor); } + healthchecks.add(serviceHealthAggregator); final Service service = new Service(namespace, serviceName); final ScheduledSignal healthcheckUpdateSignalGenerator = new ScheduledSignal<>( service, new HealthChecker(healthchecks, staleUpdateThresholdMs), - Collections.emptyList(), - healthUpdateIntervalMs); + healthCheckHandlers, + healthUpdateIntervalMs + ); final NodeDataSink usableNodeDataSource = dataSink(service); final List healthServices = Collections.singletonList(serviceHealthAggregator); final List> signalGenerators = ImmutableList.>builder() .add(healthcheckUpdateSignalGenerator) - .addAll(extraRefreshSignals) + .addAll(additionalRefreshSignals) .build(); final ServiceProvider serviceProvider = new ServiceProvider<>(service, new ServiceNode<>(hostname, port, nodeData), diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index f9413bae..d49e99e7 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -40,7 +40,7 @@ public HttpNodeDataStoreConnector( .connectionPool(new ConnectionPool(1, 30, TimeUnit.SECONDS)) .build(); this.config = config; - this.mapper = mapper; + this.mapper = null != mapper ? mapper : new ObjectMapper(); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java index f755f8a6..ab176cfa 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java @@ -14,5 +14,5 @@ public class HttpClientConfig { private boolean secure; private long connectionTimeoutMs; private long operationTimeoutMs; - private String nodesRequestPath; + private long refreshIntervalMillis; } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 676b2704..ab040354 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -7,7 +7,6 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; -import com.google.common.base.Preconditions; /** * diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java index 83c85962..9568f0ae 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java @@ -32,9 +32,6 @@ public ServiceProvider> build() { @Override protected NodeDataSink> dataSink(Service service) { - if(null == mapper){ - mapper = new ObjectMapper(); - } return new HttpNodeDataSink<>(service, clientConfig, mapper); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index d988f004..a01327e1 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -96,7 +96,7 @@ public void testHub() throws InterruptedException { .withSerializer(this::write) .withNodeData(new TestShardInfo("prod")) .withHealthcheck(() -> HealthcheckStatus.healthy) - .withExtraRefreshSignal(refreshProviderSignal) + .withadditionalRefreshSignal(refreshProviderSignal) .withCuratorFramework(curatorFramework) .build(); provider1.start(); From c51f153439d984fbf0de2bc3353f27e42aface1a Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 24 Sep 2021 22:33:08 +0530 Subject: [PATCH 08/53] Cleaned up the health update --- .../ranger/core/finderhub/ServiceFinderFactory.java | 1 + .../ranger/core/healthcheck/Healthcheck.java | 2 +- .../serviceprovider/BaseServiceProviderBuilder.java | 12 ++++-------- .../http/servicefinder/HttpNodeDataSource.java | 1 - .../serviceprovider/HttpServiceProviderBuilder.java | 2 ++ 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 5c89b2ca..f78b8011 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -10,4 +10,5 @@ public interface ServiceFinderFactory> { ServiceFinder buildFinder(final Service service); + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java index ab266709..bd800f2e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java @@ -26,5 +26,5 @@ public interface Healthcheck { * * @return health status */ - public HealthcheckStatus check(); + HealthcheckStatus check(); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java index 8f46a0d8..602f5808 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java @@ -53,7 +53,6 @@ public abstract class BaseServiceProviderBuilder nodeDataSource = null; protected List healthchecks = Lists.newArrayList(); - protected List> healthCheckHandlers = Lists.newArrayList(); protected final List> startSignalHandlers = Lists.newArrayList(); protected final List> stopSignalHandlers = Lists.newArrayList(); protected final List> additionalRefreshSignals = Lists.newArrayList(); @@ -96,11 +95,6 @@ public B withHealthcheck(Healthcheck healthcheck) { return (B)this; } - public B withHealthcheckHandlers(List> healthCheckHandlers){ - this.healthCheckHandlers.addAll(healthCheckHandlers); - return (B)this; - } - public B withHealthUpdateIntervalMs(int healthUpdateIntervalMs) { this.healthUpdateIntervalMs = healthUpdateIntervalMs; return (B)this; @@ -187,14 +181,16 @@ protected final ServiceProvider buildProvider() { healthchecks.add(serviceHealthAggregator); final Service service = new Service(namespace, serviceName); + final NodeDataSink usableNodeDataSource = dataSink(service); + final ScheduledSignal healthcheckUpdateSignalGenerator = new ScheduledSignal<>( service, new HealthChecker(healthchecks, staleUpdateThresholdMs), - healthCheckHandlers, + Collections.emptyList(), healthUpdateIntervalMs ); - final NodeDataSink usableNodeDataSource = dataSink(service); + final List healthServices = Collections.singletonList(serviceHealthAggregator); final List> signalGenerators diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 04939323..57589f45 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -32,7 +32,6 @@ public HttpNodeDataSource( super(service, config, mapper); } - @Override public Optional>> refresh(D deserializer) { Preconditions.checkNotNull(config, "client config has not been set for node data"); diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java index 9568f0ae..b40f53b6 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java @@ -1,10 +1,12 @@ package com.flipkart.ranger.http.serviceprovider; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.NodeDataSink; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.serviceprovider.BaseServiceProviderBuilder; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; +import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; import lombok.extern.slf4j.Slf4j; From a65346c33bcd8b8975f2dee001d6a07e77a28ad1 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 24 Sep 2021 22:38:11 +0530 Subject: [PATCH 09/53] Added a nodeselector and moved nodeselectors underneath it --- .../flipkart/ranger/core/finder/BaseServiceFinderBuilder.java | 1 + .../finder/{ => nodeselector}/RandomServiceNodeSelector.java | 2 +- .../{ => nodeselector}/RoundRobinServiceNodeSelector.java | 2 +- .../src/main/java/com/flipkart/ranger/core/model/Service.java | 1 + .../flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java | 2 +- .../flipkart/ranger/zookeeper/model/ServiceProviderTest.java | 2 +- 6 files changed, 6 insertions(+), 4 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{ => nodeselector}/RandomServiceNodeSelector.java (95%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{ => nodeselector}/RoundRobinServiceNodeSelector.java (95%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index b9af724a..01f90d59 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -16,6 +16,7 @@ package com.flipkart.ranger.core.finder; +import com.flipkart.ranger.core.finder.nodeselector.RandomServiceNodeSelector; import com.flipkart.ranger.core.finder.signals.ScheduledRegistryUpdateSignal; import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.core.signals.Signal; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java similarity index 95% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java index 3dc91885..4e27abf4 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RandomServiceNodeSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder; +package com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java similarity index 95% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java index 62ae215d..9073493b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/RoundRobinServiceNodeSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder; +package com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java index ec3e7fe0..ab971fa7 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java @@ -18,6 +18,7 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; @Data diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 0bb56679..4b76a870 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -18,7 +18,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 23432125..480b976e 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; From c850abac88f85153ec84e0d17f0b1d837006c86c Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 26 Sep 2021 18:23:11 +0530 Subject: [PATCH 10/53] Reorganized the structure of ranger core into finder, serviceprovider, finderhub and health --- .../core/finder/BaseServiceFinderBuilder.java | 3 +- .../SimpleShardedServiceFinder.java | 3 +- .../SimpleShardedServiceFinderBuilder.java | 5 +- .../UnshardedClusterFinder.java | 4 +- .../UnshardedFinderBuilder.java | 10 +- .../MapBasedServiceRegistry.java | 2 +- .../ServiceRegistryUpdater.java | 2 +- .../UnshardedClusterServiceRegistry.java | 3 +- .../ScheduledRegistryUpdateSignal.java | 2 +- .../MatchingShardSelector.java | 3 +- .../NoOpShardSelector.java | 4 +- .../UnshardedClusterInfo.java | 2 +- .../ranger/core/{utils => }/TestUtils.java | 2 +- .../core/finder/SimpleShardFinderTest.java | 37 ++++++ .../finder/UnshardedClusterFinderTest.java | 38 ++++++ .../RoundRobinServiceNodeSelectorTest.java | 26 ++++ .../MapBasedServiceRegistryTest.java | 23 ++++ .../MatchingShardSelectorTest.java | 23 ++++ .../shardselector/NoopShardSelectorTest.java | 23 ++++ .../serviceprovider/ServiceProviderTest.java | 121 ++++++++++++++++++ .../ranger/core/units/TestNodeData.java | 26 ++++ .../ranger/core/utils/RegistryTestUtils.java | 36 ++++++ .../HttpShardedServiceFinderBuilder.java | 4 +- .../HttpShardedServiceFinderBuilderTest.java | 4 +- .../java/com/flipkart/ranger/server/App.java | 4 - .../ranger/server/AppConfiguration.java | 4 - .../server/resources/RangerResource.java | 4 - .../zookeeper/ServiceProviderBuilders.java | 2 +- .../ZkShardedServiceFinderFactory.java | 4 +- .../ZkSimpleShardedServiceFinderBuilder.java | 4 +- .../ZkUnshardedFinderBuilder.java | 6 +- .../ServiceHealthAggregatorTest.java | 2 +- .../ServiceProviderIntegrationTest.java | 6 +- .../model/CustomShardSelectorTest.java | 4 +- .../model/ServiceNoProviderTest.java | 2 +- .../model/ServiceProviderExtCuratorTest.java | 2 +- .../model/ServiceProviderHealthcheckTest.java | 4 +- .../zookeeper/model/ServiceProviderTest.java | 2 +- .../model/SimpleServiceProviderTest.java | 4 +- .../zookeeper/servicehub/ServiceHubTest.java | 4 +- 40 files changed, 406 insertions(+), 58 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{sharded => }/SimpleShardedServiceFinder.java (90%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{sharded => }/SimpleShardedServiceFinderBuilder.java (89%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{unsharded => }/UnshardedClusterFinder.java (86%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{unsharded => }/UnshardedFinderBuilder.java (81%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{sharded => serviceregistry}/MapBasedServiceRegistry.java (96%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{ => serviceregistry}/ServiceRegistryUpdater.java (98%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{unsharded => serviceregistry}/UnshardedClusterServiceRegistry.java (92%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{signals => serviceregistry/signal}/ScheduledRegistryUpdateSignal.java (88%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{sharded => shardselector}/MatchingShardSelector.java (88%) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{unsharded => shardselector}/NoOpShardSelector.java (84%) rename ranger-core/src/main/java/com/flipkart/ranger/core/{finder/unsharded => model}/UnshardedClusterInfo.java (94%) rename ranger-core/src/test/java/com/flipkart/ranger/core/{utils => }/TestUtils.java (86%) create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java delete mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/App.java delete mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java delete mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 01f90d59..4323bc53 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -17,7 +17,8 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.nodeselector.RandomServiceNodeSelector; -import com.flipkart.ranger.core.finder.signals.ScheduledRegistryUpdateSignal; +import com.flipkart.ranger.core.finder.serviceregistry.ServiceRegistryUpdater; +import com.flipkart.ranger.core.finder.serviceregistry.signal.ScheduledRegistryUpdateSignal; import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.core.signals.Signal; import com.google.common.base.Preconditions; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java similarity index 90% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index ba27a764..699d7eea 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.sharded; +package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java similarity index 89% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index fa05593b..29c4bc34 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.sharded; +package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java similarity index 86% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java index be55c096..d06224cc 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java @@ -14,11 +14,13 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.unsharded; +package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; public class UnshardedClusterFinder extends ServiceFinder { public UnshardedClusterFinder(UnshardedClusterServiceRegistry serviceRegistry, diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java similarity index 81% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java index 010b3d82..85b1dbbc 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java @@ -14,13 +14,11 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.unsharded; +package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.BaseServiceFinderBuilder; -import com.flipkart.ranger.core.model.Deserializer; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; +import com.flipkart.ranger.core.model.*; public abstract class UnshardedFinderBuilder, D extends Deserializer> extends BaseServiceFinderBuilder { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java similarity index 96% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java index 83b0f903..72610e3f 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MapBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.sharded; +package com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java similarity index 98% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 460ecca9..67ffe220 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder; +package com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.NodeDataSource; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java similarity index 92% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java index d5fe01af..5db2e9ca 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.unsharded; +package com.flipkart.ranger.core.finder.serviceregistry; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceRegistry; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java similarity index 88% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java index 63ae6289..b25effc6 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/signals/ScheduledRegistryUpdateSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.core.finder.signals; +package com.flipkart.ranger.core.finder.serviceregistry.signal; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.ScheduledSignal; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java similarity index 88% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 265e69d3..40a7fa53 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/sharded/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.sharded; +package com.flipkart.ranger.core.finder.shardselector; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java similarity index 84% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java index 39c1a2cd..71ea432c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/NoOpShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java @@ -14,8 +14,10 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.unsharded; +package com.flipkart.ranger.core.finder.shardselector; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterInfo.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java similarity index 94% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterInfo.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java index 93d45fce..d3a73820 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/unsharded/UnshardedClusterInfo.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.flipkart.ranger.core.finder.unsharded; +package com.flipkart.ranger.core.model; public class UnshardedClusterInfo { @Override diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/TestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java similarity index 86% rename from ranger-core/src/test/java/com/flipkart/ranger/core/utils/TestUtils.java rename to ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java index cb98cc62..34af52ab 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/TestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.core.utils; +package com.flipkart.ranger.core; import java.util.concurrent.TimeUnit; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java new file mode 100644 index 00000000..2def38bc --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -0,0 +1,37 @@ +package com.flipkart.ranger.core.finder; + +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.RegistryTestUtils; +import com.google.common.collect.Lists; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class SimpleShardFinderTest { + + static class TestSimpleShardSelector implements ShardSelector>{ + + @Override + public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { + return Lists.newArrayList(); + } + } + + @Test + public void testSimpleShardedFinder(){ + final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); + final TestSimpleShardSelector shardSelector = new TestSimpleShardSelector<>(); + final RoundRobinServiceNodeSelector roundRobinServiceNodeSelector = new RoundRobinServiceNodeSelector<>(); + val simpleShardedFinder = new SimpleShardedServiceFinder<>( + serviceRegistry, shardSelector, roundRobinServiceNodeSelector); + val testNodeDataServiceNode = simpleShardedFinder.get( + TestNodeData.builder().nodeId(2).build()); + Assert.assertNull(testNodeDataServiceNode); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java new file mode 100644 index 00000000..5dd2f424 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -0,0 +1,38 @@ +package com.flipkart.ranger.core.finder; + +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.utils.RegistryTestUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class UnshardedClusterFinderTest { + + static class TestUnshardedNodeSelector implements ServiceNodeSelector{ + + @Override + public ServiceNode select(List> serviceNodes) { + return serviceNodes.get(0); + } + } + @Test + public void unshardedClusterFinder(){ + final UnshardedClusterServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); + final NoOpShardSelector shardSelector = new NoOpShardSelector(); + final UnshardedClusterInfo unshardedClusterInfo = new UnshardedClusterInfo(); + UnshardedClusterFinder unshardedClusterFinder = new UnshardedClusterFinder( + unshardedRegistry, + shardSelector, + new TestUnshardedNodeSelector() + ); + final ServiceNode serviceNode = unshardedClusterFinder.get(unshardedClusterInfo); + Assert.assertNotNull(serviceNode); + Assert.assertEquals("localhost-1", serviceNode.getHost()); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java new file mode 100644 index 00000000..a533c41b --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java @@ -0,0 +1,26 @@ +package com.flipkart.ranger.core.finder.nodeselector; + +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import com.google.common.collect.Lists; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class RoundRobinServiceNodeSelectorTest { + @Test + public void testRandomNodeSelector(){ + final RoundRobinServiceNodeSelector roundRobinSelector = new RoundRobinServiceNodeSelector(); + List> serviceNodes = Lists.newArrayList(); + serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().nodeId(1).build())); + serviceNodes.add(new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().nodeId(2).build())); + serviceNodes.add(new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().nodeId(3).build())); + ServiceNode select = roundRobinSelector.select(serviceNodes); + Assert.assertTrue(select.getHost().equalsIgnoreCase("localhost-2")); + select = roundRobinSelector.select(serviceNodes); + Assert.assertTrue(select.getHost().equalsIgnoreCase("localhost-3")); + select = roundRobinSelector.select(serviceNodes); + Assert.assertTrue(select.getHost().equalsIgnoreCase("localhost-1")); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java new file mode 100644 index 00000000..3bb1382b --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -0,0 +1,23 @@ +package com.flipkart.ranger.core.finder.serviceregistry; + +import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.RegistryTestUtils; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +public class MapBasedServiceRegistryTest { + + @Test + public void testMapBasedServiceRegistryWithMatchingShardSelector(){ + final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); + Assert.assertTrue(null != serviceRegistry.nodes() && !serviceRegistry.nodes().isEmpty()); + final MatchingShardSelector matchingShardSelector = new MatchingShardSelector<>(); + val nodes = matchingShardSelector.nodes( + TestNodeData.builder().nodeId(1).build(), serviceRegistry); + Assert.assertFalse(nodes.isEmpty()); + Assert.assertEquals("localhost-1", nodes.get(0).getHost()); + } + +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java new file mode 100644 index 00000000..d92f3206 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -0,0 +1,23 @@ +package com.flipkart.ranger.core.finder.shardselector; + +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.RegistryTestUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class MatchingShardSelectorTest { + + @Test + public void testMatchingShardSelector(){ + final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); + final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); + final List> nodes = shardSelector.nodes( + TestNodeData.builder().nodeId(1).build(), serviceRegistry); + Assert.assertFalse(nodes.isEmpty()); + Assert.assertEquals("localhost-1", nodes.get(0).getHost()); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java new file mode 100644 index 00000000..2818c4b8 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java @@ -0,0 +1,23 @@ +package com.flipkart.ranger.core.finder.shardselector; + +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.utils.RegistryTestUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +public class NoopShardSelectorTest { + + @Test + public void testNoOpShardSelector(){ + final UnshardedClusterServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); + final NoOpShardSelector shardSelector = new NoOpShardSelector(); + final UnshardedClusterInfo unshardedClusterInfo = new UnshardedClusterInfo(); + final List> nodes = shardSelector.nodes(unshardedClusterInfo, serviceRegistry); + Assert.assertFalse(nodes.isEmpty()); + Assert.assertEquals("localhost-1", nodes.get(0).getHost()); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java new file mode 100644 index 00000000..ea430e70 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java @@ -0,0 +1,121 @@ +package com.flipkart.ranger.core.serviceprovider; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.NodeDataSink; +import com.flipkart.ranger.core.model.Serializer; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import org.junit.Assert; +import org.junit.Test; + +public class ServiceProviderTest { + + static TestNodeData testNodeData = null; + + interface TestSerializer extends Serializer { + byte[] serialize(final ServiceNode node); + } + + static class TestSerializerImpl implements TestSerializer{ + private ObjectMapper objectMapper; + + public TestSerializerImpl(){ + objectMapper = new ObjectMapper(); + } + + @Override + public byte[] serialize(ServiceNode node) { + try{ + return objectMapper.writeValueAsBytes(node); + }catch (JsonProcessingException jpe){ + return null; + } + } + } + + static class TestNodeDataSink> implements NodeDataSink{ + + public TestNodeDataSink(){ + } + + @Override + public void updateState(S serializer, ServiceNode serviceNode) { + testNodeData = (TestNodeData) serviceNode.getNodeData(); + } + + @Override + public void start() { + + } + + @Override + public void ensureConnected() { + + } + + @Override + public void stop() { + + } + + @Override + public boolean isActive() { + return true; + } + } + + public class TestServiceProviderBuilder extends BaseServiceProviderBuilder, TestSerializer> { + + @Override + public ServiceProvider> build() { + return super.buildProvider(); + } + + @Override + protected NodeDataSink> dataSink(Service service) { + return new TestNodeDataSink<>(); + } + } + + @Test(expected = NullPointerException.class) + public void testInvalidServiceProvider(){ + new TestServiceProviderBuilder() + .withServiceName("test-service") + .withNamespace("test") + .withHostname("localhost-1") + .withPort(9000) + .build(); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvalidServiceProviderNoHealthCheck(){ + new TestServiceProviderBuilder() + .withServiceName("test-service") + .withNamespace("test") + .withHostname("localhost-1") + .withPort(9000) + .withSerializer(new TestSerializerImpl()) + .build(); + } + + @Test + public void testBuildServiceProvider(){ + ServiceProvider> testProvider = new TestServiceProviderBuilder() + .withServiceName("test-service") + .withNamespace("test") + .withHostname("localhost-1") + .withPort(9000) + .withSerializer(new TestSerializerImpl()) + .withNodeData(TestNodeData.builder().nodeId(1).build()) + .withHealthcheck(Healthchecks.defaultHealthyCheck()) + .withHealthUpdateIntervalMs(1000) + .build(); + testProvider.start(); + Assert.assertNotNull(testNodeData); + Assert.assertEquals(1, testNodeData.getNodeId()); + } + +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java new file mode 100644 index 00000000..059599c0 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java @@ -0,0 +1,26 @@ +package com.flipkart.ranger.core.units; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class TestNodeData { + private int nodeId; + + @Override + public boolean equals(Object obj){ + if(this == obj) + return true; + if(obj == null || obj.getClass()!= this.getClass()) + return false; + TestNodeData that = (TestNodeData) obj; + return (that.nodeId == this.nodeId); + } + + @Override + public int hashCode(){ + return this.nodeId; + } + +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java new file mode 100644 index 00000000..0e6acb45 --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -0,0 +1,36 @@ +package com.flipkart.ranger.core.utils; + +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.units.TestNodeData; +import com.google.common.collect.Lists; + +import java.util.List; + +public class RegistryTestUtils { + + public static MapBasedServiceRegistry getServiceRegistry(){ + final Service service = new Service("test", "test-service"); + final MapBasedServiceRegistry serviceRegistry = new MapBasedServiceRegistry<>(service); + List> serviceNodes = Lists.newArrayList(); + serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().nodeId(1).build())); + serviceNodes.add(new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().nodeId(2).build())); + serviceNodes.add(new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().nodeId(3).build())); + serviceRegistry.updateNodes(serviceNodes); + return serviceRegistry; + } + + public static UnshardedClusterServiceRegistry getUnshardedRegistry(){ + final Service service = new Service("test", "test-service"); + final UnshardedClusterServiceRegistry serviceRegistry = new UnshardedClusterServiceRegistry(service); + List> serviceNodes = Lists.newArrayList(); + serviceNodes.add(new ServiceNode<>("localhost-1", 9000, new UnshardedClusterInfo())); + serviceNodes.add(new ServiceNode<>("localhost-2", 9001, new UnshardedClusterInfo())); + serviceNodes.add(new ServiceNode<>("localhost-3", 9002, new UnshardedClusterInfo())); + serviceRegistry.updateNodes(serviceNodes); + return serviceRegistry; + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index ab040354..074de977 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -1,8 +1,8 @@ package com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java index 67800fd0..4d006a3d 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.utils.TestUtils; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/App.java b/ranger-server/src/main/java/com/flipkart/ranger/server/App.java deleted file mode 100644 index 34a18f60..00000000 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/App.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.flipkart.ranger.server; - -public class App { -} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java b/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java deleted file mode 100644 index 88513c7c..00000000 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/AppConfiguration.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.flipkart.ranger.server; - -public class AppConfiguration { -} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java deleted file mode 100644 index 588219a7..00000000 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.flipkart.ranger.server.resources; - -public class RangerResource { -} diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java index 568ed6fe..091a9857 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.zookeeper; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.zookeeper.serviceprovider.ZkServiceProviderBuilder; public class ServiceProviderBuilders { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java index 0d82fa14..6e2ded99 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.zookeeper.servicefinder; -import com.flipkart.ranger.core.finder.sharded.MapBasedServiceRegistry; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index fde11e7e..fac2a75f 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.zookeeper.servicefinder; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java index 881e4f71..af964455 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java @@ -1,8 +1,8 @@ package com.flipkart.ranger.zookeeper.servicefinder; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterFinder; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; -import com.flipkart.ranger.core.finder.unsharded.UnshardedFinderBuilder; +import com.flipkart.ranger.core.finder.UnshardedClusterFinder; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.finder.UnshardedFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java index 6f52e2eb..0f340ecf 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java @@ -21,7 +21,7 @@ import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; import com.flipkart.ranger.core.healthservice.monitor.Monitor; -import com.flipkart.ranger.core.utils.TestUtils; +import com.flipkart.ranger.core.TestUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 64ed9401..e940a5ba 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -19,14 +19,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterFinder; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; +import com.flipkart.ranger.core.finder.UnshardedClusterFinder; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.utils.TestUtils; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import lombok.val; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 36587d52..4e3895d3 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.MapBasedServiceRegistry; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 4b76a870..2186ede4 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index 5c8b1183..5c7f830d 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 3e31e1e9..3f5fd1d3 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -19,12 +19,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; -import com.flipkart.ranger.core.utils.TestUtils; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 480b976e..3778e000 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; -import com.flipkart.ranger.core.finder.sharded.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 71d163bb..a4aa20c7 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -19,8 +19,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterFinder; -import com.flipkart.ranger.core.finder.unsharded.UnshardedClusterInfo; +import com.flipkart.ranger.core.finder.UnshardedClusterFinder; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index a01327e1..322a809c 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -3,14 +3,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.sharded.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.utils.TestUtils; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.flipkart.ranger.zookeeper.servicefinder.ZkShardedServiceFinderFactory; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; From 37d763bae394084c8ec3354f3acb06fcc64fd305 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 27 Sep 2021 11:46:22 +0530 Subject: [PATCH 11/53] Added a finderSelector - for custom finder selection from the service hub --- .../finder/SimpleShardedServiceFinder.java | 1 - .../core/finderhub/ServiceFinderHub.java | 7 +++++-- .../finderhub}/ServiceFinderHubBuilder.java | 17 ++++++++++++----- .../core/finderhub/ServiceFinderSelector.java | 14 ++++++++++++++ .../core/finderhub/SimpleFinderSelector.java | 19 +++++++++++++++++++ .../finder/UnshardedClusterFinderTest.java | 1 - .../servicefinder/HttpNodeDataSource.java | 2 +- .../serviceprovider/HttpNodeDataSink.java | 2 +- .../ZkServiceFinderHubBuilder.java | 1 + .../ZkShardedServiceFinderFactory.java | 3 ++- .../zookeeper/servicehub/ServiceHubTest.java | 4 ++-- 11 files changed, 57 insertions(+), 14 deletions(-) rename {ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub => ranger-core/src/main/java/com/flipkart/ranger/core/finderhub}/ServiceFinderHubBuilder.java (87%) create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/{servicefinder => servicefinderhub}/ZkShardedServiceFinderFactory.java (94%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index 699d7eea..2ac130d5 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -16,7 +16,6 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index aceeb761..f5a2d595 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -28,6 +28,7 @@ @Slf4j public class ServiceFinderHub> { private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); + private final ServiceFinderSelector serviceFinderSelector; private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; @@ -50,17 +51,19 @@ public class ServiceFinderHub> { public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory) { + ServiceFinderFactory finderFactory, + ServiceFinderSelector serviceFinderSelector) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", () -> null, Collections.emptyList(), 10_000)); + this.serviceFinderSelector = serviceFinderSelector; } public Optional> finder(final Service service) { - return Optional.ofNullable(finders.get().get(service)); + return serviceFinderSelector.finder(service, finders.get()); } public void start() { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java similarity index 87% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 973a69dd..b1346714 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,8 +1,5 @@ -package com.flipkart.ranger.zookeeper.servicefinderhub; +package com.flipkart.ranger.core.finderhub; -import com.flipkart.ranger.core.finderhub.ServiceDataSource; -import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ScheduledSignal; import com.flipkart.ranger.core.signals.Signal; @@ -20,6 +17,7 @@ public abstract class ServiceFinderHubBuilder> { private ServiceDataSource serviceDataSource; private ServiceFinderFactory serviceFinderFactory; + private ServiceFinderSelector serviceFinderSelector; private long refreshFrequencyMs = 10_000; private List> extraStartSignalConsumers = new ArrayList<>(); private List> extraStopSignalConsumers = new ArrayList<>(); @@ -35,6 +33,11 @@ public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFacto return this; } + public ServiceFinderHubBuilder withFinderSelector(ServiceFinderSelector serviceFinderSelector){ + this.serviceFinderSelector = serviceFinderSelector; + return this; + } + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; @@ -58,7 +61,11 @@ public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRe 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); + if(null == serviceFinderSelector){ + serviceFinderSelector = new SimpleFinderSelector<>(); + } + + val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceFinderSelector); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", () -> null, Collections.emptyList(), diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java new file mode 100644 index 00000000..2529b9d5 --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java @@ -0,0 +1,14 @@ +package com.flipkart.ranger.core.finderhub; + +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceRegistry; + +import java.util.Map; +import java.util.Optional; + +public interface ServiceFinderSelector> { + + Optional> finder(Service service, Map> finders); + +} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java new file mode 100644 index 00000000..de596f3a --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java @@ -0,0 +1,19 @@ +package com.flipkart.ranger.core.finderhub; + +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceRegistry; +import lombok.Data; + +import java.util.Map; +import java.util.Optional; + +@Data +public class SimpleFinderSelector> implements ServiceFinderSelector { + + @Override + public Optional> finder(Service service, Map> finders) { + return Optional.ofNullable(finders.get(service)); + } + +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index 5dd2f424..a961ffa1 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,6 +1,5 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; import com.flipkart.ranger.core.model.ServiceNode; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 57589f45..c664a958 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -44,7 +44,7 @@ public Optional>> refresh(D deserializer) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/ranger/nodes/v1/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/v1/ranger/nodes/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val request = new Request.Builder() .url(httpUrl) diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index de2ee759..d3d87d26 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -40,7 +40,7 @@ public void updateState(S serializer, ServiceNode serviceNode) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/ranger/nodes/v1/add/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/v1/ranger/nodes/add/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val requestBody = RequestBody.create(serializer.serialize(serviceNode)); val serviceRegistrationResponse = registerService(httpUrl, requestBody); diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 6aa678a1..6ab9ebe7 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; import com.flipkart.ranger.core.model.ServiceRegistry; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java similarity index 94% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 6e2ded99..f3004e5c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.zookeeper.servicefinder; +package com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; @@ -7,6 +7,7 @@ import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; +import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; import lombok.Builder; import lombok.val; import org.apache.curator.framework.CuratorFramework; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 322a809c..b13640e0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -12,7 +12,7 @@ import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; -import com.flipkart.ranger.zookeeper.servicefinder.ZkShardedServiceFinderFactory; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; import lombok.Data; @@ -68,7 +68,7 @@ public void stopTestCluster() throws Exception { } @Test - public void testHub() throws InterruptedException { + public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); val hub = new ZkServiceFinderHubBuilder>() .withCuratorFramework(curatorFramework) From 96d910f9838defb381257fcf54182048b59b5aaa Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 27 Sep 2021 16:57:51 +0530 Subject: [PATCH 12/53] Reverted the finderSelector --- .../core/finderhub/ServiceFinderHub.java | 7 ++----- .../finderhub/ServiceFinderHubBuilder.java | 13 ++----------- .../core/finderhub/ServiceFinderSelector.java | 14 -------------- .../core/finderhub/SimpleFinderSelector.java | 19 ------------------- .../servicefinder/HttpNodeDataSource.java | 2 +- .../serviceprovider/HttpNodeDataSink.java | 2 +- 6 files changed, 6 insertions(+), 51 deletions(-) delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index f5a2d595..aceeb761 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -28,7 +28,6 @@ @Slf4j public class ServiceFinderHub> { private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); - private final ServiceFinderSelector serviceFinderSelector; private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; @@ -51,19 +50,17 @@ public class ServiceFinderHub> { public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory, - ServiceFinderSelector serviceFinderSelector) { + ServiceFinderFactory finderFactory) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", () -> null, Collections.emptyList(), 10_000)); - this.serviceFinderSelector = serviceFinderSelector; } public Optional> finder(final Service service) { - return serviceFinderSelector.finder(service, finders.get()); + return Optional.ofNullable(finders.get().get(service)); } public void start() { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index b1346714..085db33d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -17,7 +17,6 @@ public abstract class ServiceFinderHubBuilder> { private ServiceDataSource serviceDataSource; private ServiceFinderFactory serviceFinderFactory; - private ServiceFinderSelector serviceFinderSelector; private long refreshFrequencyMs = 10_000; private List> extraStartSignalConsumers = new ArrayList<>(); private List> extraStopSignalConsumers = new ArrayList<>(); @@ -32,12 +31,7 @@ public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFacto this.serviceFinderFactory = serviceFinderFactory; return this; } - - public ServiceFinderHubBuilder withFinderSelector(ServiceFinderSelector serviceFinderSelector){ - this.serviceFinderSelector = serviceFinderSelector; - return this; - } - + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; @@ -61,11 +55,8 @@ public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRe public ServiceFinderHub build() { Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); - if(null == serviceFinderSelector){ - serviceFinderSelector = new SimpleFinderSelector<>(); - } - val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory, serviceFinderSelector); + val hub = new ServiceFinderHub<>(serviceDataSource, serviceFinderFactory); final ScheduledSignal refreshSignal = new ScheduledSignal<>("service-hub-refresh-timer", () -> null, Collections.emptyList(), diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java deleted file mode 100644 index 2529b9d5..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderSelector.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.flipkart.ranger.core.finderhub; - -import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceRegistry; - -import java.util.Map; -import java.util.Optional; - -public interface ServiceFinderSelector> { - - Optional> finder(Service service, Map> finders); - -} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java deleted file mode 100644 index de596f3a..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/SimpleFinderSelector.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.flipkart.ranger.core.finderhub; - -import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceRegistry; -import lombok.Data; - -import java.util.Map; -import java.util.Optional; - -@Data -public class SimpleFinderSelector> implements ServiceFinderSelector { - - @Override - public Optional> finder(Service service, Map> finders) { - return Optional.ofNullable(finders.get(service)); - } - -} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index c664a958..57589f45 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -44,7 +44,7 @@ public Optional>> refresh(D deserializer) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/v1/ranger/nodes/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/ranger/nodes/v1/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val request = new Request.Builder() .url(httpUrl) diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index d3d87d26..de2ee759 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -40,7 +40,7 @@ public void updateState(S serializer, ServiceNode serviceNode) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/v1/ranger/nodes/add/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/ranger/nodes/v1/add/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val requestBody = RequestBody.create(serializer.serialize(serviceNode)); val serviceRegistrationResponse = registerService(httpUrl, requestBody); From 79a6f58b4471ea21c8ac9e824aa4c17192e7b046 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 29 Sep 2021 00:38:53 +0530 Subject: [PATCH 13/53] Added a criteria holder, make it return the relevant nodeData. So that custom criteria could be passed to the shardSelector which can help in shardSelection --- .../core/finder/BaseServiceFinderBuilder.java | 13 ++++++----- .../ranger/core/finder/ServiceFinder.java | 15 +++++------- .../finder/SimpleShardedServiceFinder.java | 5 ++-- .../SimpleShardedServiceFinderBuilder.java | 14 +++++------ .../core/finder/UnshardedClusterFinder.java | 6 ++--- .../core/finder/UnshardedFinderBuilder.java | 6 ++--- .../UnshardedClusterServiceRegistry.java | 2 +- .../shardselector/MatchingShardSelector.java | 7 +++--- .../shardselector/NoOpShardSelector.java | 9 ++++---- .../core/finderhub/ServiceFinderFactory.java | 5 ++-- .../core/finderhub/ServiceFinderHub.java | 15 ++++++------ .../finderhub/ServiceFinderHubBuilder.java | 21 +++++++++-------- .../flipkart/ranger/core/model/Criteria.java | 6 +++++ .../flipkart/ranger/core/model/Service.java | 1 - .../ranger/core/model/ShardSelector.java | 6 +++-- .../ranger/core/model/UnshardedCriteria.java | 14 +++++++++++ .../core/finder/SimpleShardFinderTest.java | 9 ++++---- .../finder/UnshardedClusterFinderTest.java | 3 ++- .../MapBasedServiceRegistryTest.java | 2 +- .../MatchingShardSelectorTest.java | 4 +++- .../shardselector/NoopShardSelectorTest.java | 3 ++- .../common/HttpNodeDataStoreConnector.java | 3 --- .../HttpShardedServiceFinderBuilder.java | 3 ++- .../HttpServiceProviderBuilder.java | 2 -- .../HttpShardedServiceFinderBuilderTest.java | 6 ++--- .../ZkSimpleShardedServiceFinderBuilder.java | 4 ++-- .../ZkUnshardedFinderBuilder.java | 5 ++-- .../ZkServiceFinderHubBuilder.java | 11 +++++---- .../ZkShardedServiceFinderFactory.java | 9 ++++---- .../ServiceHealthAggregatorTest.java | 2 +- .../ServiceProviderIntegrationTest.java | 4 ++-- .../model/CustomShardSelectorTest.java | 15 ++++++------ .../model/ServiceNoProviderTest.java | 6 ++--- .../model/ServiceProviderExtCuratorTest.java | 8 +++---- .../model/ServiceProviderHealthcheckTest.java | 6 ++--- .../zookeeper/model/ServiceProviderTest.java | 23 ++++++++++--------- .../model/SimpleServiceProviderTest.java | 2 +- .../zookeeper/servicehub/ServiceHubTest.java | 9 ++++---- 38 files changed, 157 insertions(+), 127 deletions(-) create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 4323bc53..44976559 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -37,16 +37,17 @@ public abstract class BaseServiceFinderBuilder < T, R extends ServiceRegistry, - F extends ServiceFinder, - B extends BaseServiceFinderBuilder, - D extends Deserializer> { + F extends ServiceFinder, + B extends BaseServiceFinderBuilder, + D extends Deserializer, + U extends Criteria> { protected String namespace; protected String serviceName; protected int nodeRefreshIntervalMs; protected boolean disablePushUpdaters; protected D deserializer; - protected ShardSelector shardSelector; + protected ShardSelector shardSelector; protected ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>(); protected final List> additionalRefreshSignals = new ArrayList<>(); protected final List> startSignalHandlers = Lists.newArrayList(); @@ -67,7 +68,7 @@ public B withDeserializer(D deserializer) { return (B)this; } - public B withShardSelector(ShardSelector shardSelector) { + public B withShardSelector(ShardSelector shardSelector) { this.shardSelector = shardSelector; return (B)this; } @@ -175,7 +176,7 @@ protected List> implementationSpecificRefreshSignals(Service service, protected abstract F buildFinder( Service service, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index 36a1e089..da37642c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -16,10 +16,7 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ServiceRegistry; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -28,10 +25,10 @@ import java.util.List; @Slf4j -public abstract class ServiceFinder> { +public abstract class ServiceFinder, U extends Criteria> { @Getter private final ServiceRegistryType serviceRegistry; - private final ShardSelector shardSelector; + private final ShardSelector shardSelector; private final ServiceNodeSelector nodeSelector; @Getter private final ExternalTriggeredSignal startSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); @@ -40,14 +37,14 @@ public abstract class ServiceFinder shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { this.serviceRegistry = serviceRegistry; this.shardSelector = shardSelector; this.nodeSelector = nodeSelector; } - public ServiceNode get(T criteria) { + public ServiceNode get(U criteria) { List> nodes = shardSelector.nodes(criteria, serviceRegistry); if (null == nodes || nodes.isEmpty()) { return null; @@ -55,7 +52,7 @@ public ServiceNode get(T criteria) { return nodeSelector.select(nodes); } - public List> getAll(T criteria) { + public List> getAll(U criteria) { return shardSelector.nodes(criteria, serviceRegistry); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index 2ac130d5..e6931ad4 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -17,12 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -public class SimpleShardedServiceFinder extends ServiceFinder> { +public class SimpleShardedServiceFinder extends ServiceFinder, Criteria> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, - ShardSelector> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index 29c4bc34..e095a6e2 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -18,19 +18,17 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; -import com.flipkart.ranger.core.model.Deserializer; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; -public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer> - extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D> { +public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> + extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, Criteria> { @Override protected SimpleShardedServiceFinder buildFinder( Service service, - ShardSelector> shardSelector, - ServiceNodeSelector nodeSelector) { + ShardSelector, Criteria> shardSelector, + ServiceNodeSelector nodeSelector + ) { if (null == shardSelector) { shardSelector = new MatchingShardSelector<>(); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java index d06224cc..106b91da 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java @@ -16,15 +16,15 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; -public class UnshardedClusterFinder extends ServiceFinder { +public class UnshardedClusterFinder extends ServiceFinder { public UnshardedClusterFinder(UnshardedClusterServiceRegistry serviceRegistry, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java index 85b1dbbc..f62d9a36 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java @@ -20,13 +20,13 @@ import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; import com.flipkart.ranger.core.model.*; -public abstract class UnshardedFinderBuilder, D extends Deserializer> - extends BaseServiceFinderBuilder { +public abstract class UnshardedFinderBuilder, D extends Deserializer, U extends Criteria> + extends BaseServiceFinderBuilder { @Override protected UnshardedClusterFinder buildFinder( Service service, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { final UnshardedClusterServiceRegistry unshardedClusterServiceRegistry = new UnshardedClusterServiceRegistry(service); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java index 5db2e9ca..23d963d8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java @@ -16,10 +16,10 @@ package com.flipkart.ranger.core.finder.serviceregistry; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceRegistry; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.google.common.collect.ImmutableList; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 40a7fa53..86a9912b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -17,15 +17,16 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; -public class MatchingShardSelector implements ShardSelector> { +public class MatchingShardSelector implements ShardSelector, Criteria> { @Override - public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { - return serviceRegistry.nodes().get(criteria); + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { + return serviceRegistry.nodes().get(criteria.getCriteria()); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java index 71ea432c..22db305d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java @@ -16,17 +16,18 @@ package com.flipkart.ranger.core.finder.shardselector; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; import java.util.List; -public class NoOpShardSelector implements ShardSelector { +public class NoOpShardSelector implements ShardSelector { + @Override - public List> nodes(UnshardedClusterInfo criteria, - UnshardedClusterServiceRegistry serviceRegistry) { + public List> nodes(UnshardedCriteria criteria, UnshardedClusterServiceRegistry serviceRegistry) { return serviceRegistry.nodes(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index f78b8011..0d392469 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -1,14 +1,15 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; /** * */ -public interface ServiceFinderFactory> { +public interface ServiceFinderFactory, U extends Criteria> { - ServiceFinder buildFinder(final Service service); + ServiceFinder buildFinder(final Service service); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index aceeb761..eadb23e3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; @@ -26,8 +27,8 @@ * */ @Slf4j -public class ServiceFinderHub> { - private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); +public class ServiceFinderHub, U extends Criteria> { + private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; @@ -43,14 +44,14 @@ public class ServiceFinderHub> { private final List> refreshSignals = new ArrayList<>(); private final ServiceDataSource serviceDataSource; - private final ServiceFinderFactory finderFactory; + private final ServiceFinderFactory finderFactory; private AtomicBoolean alreadyUpdating = new AtomicBoolean(false); private Future monitorFuture = null; public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory) { + ServiceFinderFactory finderFactory) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", @@ -59,7 +60,7 @@ public ServiceFinderHub( 10_000)); } - public Optional> finder(final Service service) { + public Optional> finder(final Service service) { return Optional.ofNullable(finders.get().get(service)); } @@ -126,10 +127,10 @@ private void updateRegistry() { return; } alreadyUpdating.set(true); - final Map> updatedFinders = new HashMap<>(); + final Map> updatedFinders = new HashMap<>(); try { final Collection services = serviceDataSource.services(); - final Map> knownServiceFinders = finders.get(); + final Map> knownServiceFinders = finders.get(); val newFinders = services.stream() .filter(service -> !knownServiceFinders.containsKey(service)) .collect(Collectors.toMap(Function.identity(), finderFactory::buildFinder)); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 085db33d..60e044a9 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,5 +1,6 @@ package com.flipkart.ranger.core.finderhub; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ScheduledSignal; import com.flipkart.ranger.core.signals.Signal; @@ -14,45 +15,45 @@ /** * */ -public abstract class ServiceFinderHubBuilder> { +public abstract class ServiceFinderHubBuilder, U extends Criteria> { private ServiceDataSource serviceDataSource; - private ServiceFinderFactory serviceFinderFactory; + private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; private List> extraStartSignalConsumers = new ArrayList<>(); private List> extraStopSignalConsumers = new ArrayList<>(); private List> extraRefreshSignals = new ArrayList<>(); - public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { + public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { this.serviceDataSource = serviceDataSource; return this; } - public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { + public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { this.serviceFinderFactory = serviceFinderFactory; return this; } - public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; } - public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { this.extraStartSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { this.extraStopSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { + public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { this.extraRefreshSignals.add(extraRefreshSignal); return this; } - public ServiceFinderHub build() { + public ServiceFinderHub build() { Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); @@ -76,5 +77,5 @@ public ServiceFinderHub build() { } protected abstract void preBuild(); - protected abstract void postBuild(ServiceFinderHub serviceFinderHub); + protected abstract void postBuild(ServiceFinderHub serviceFinderHub); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java new file mode 100644 index 00000000..83a381e6 --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -0,0 +1,6 @@ +package com.flipkart.ranger.core.model; + +public interface Criteria { + + T getCriteria(); +} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java index ab971fa7..ec3e7fe0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java @@ -18,7 +18,6 @@ import lombok.AccessLevel; import lombok.AllArgsConstructor; -import lombok.Builder; import lombok.Data; @Data diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index 7cea8c84..e77c59d1 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -18,6 +18,8 @@ import java.util.List; -public interface ShardSelector> { - List> nodes(T criteria, ServiceRegistryType serviceRegistry); +public interface ShardSelector, U extends Criteria> { + + List> nodes(U criteria, ServiceRegistryType serviceRegistry); + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java new file mode 100644 index 00000000..3732405f --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java @@ -0,0 +1,14 @@ +package com.flipkart.ranger.core.model; + +import lombok.Data; + +@Data +public class UnshardedCriteria implements Criteria { + + private final UnshardedClusterInfo unshardedClusterInfo; + + @Override + public UnshardedClusterInfo getCriteria() { + return unshardedClusterInfo; + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 2def38bc..96e376d4 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.units.TestNodeData; @@ -15,10 +16,10 @@ public class SimpleShardFinderTest { - static class TestSimpleShardSelector implements ShardSelector>{ - + static class TestSimpleShardSelector implements ShardSelector, Criteria>{ + @Override - public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { return Lists.newArrayList(); } } @@ -31,7 +32,7 @@ public void testSimpleShardedFinder(){ val simpleShardedFinder = new SimpleShardedServiceFinder<>( serviceRegistry, shardSelector, roundRobinServiceNodeSelector); val testNodeDataServiceNode = simpleShardedFinder.get( - TestNodeData.builder().nodeId(2).build()); + () -> TestNodeData.builder().nodeId(2).build()); Assert.assertNull(testNodeDataServiceNode); } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index a961ffa1..d10ec0df 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -5,6 +5,7 @@ import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; @@ -30,7 +31,7 @@ public void unshardedClusterFinder(){ shardSelector, new TestUnshardedNodeSelector() ); - final ServiceNode serviceNode = unshardedClusterFinder.get(unshardedClusterInfo); + final ServiceNode serviceNode = unshardedClusterFinder.get(new UnshardedCriteria(unshardedClusterInfo)); Assert.assertNotNull(serviceNode); Assert.assertEquals("localhost-1", serviceNode.getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index 3bb1382b..effeb67b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -15,7 +15,7 @@ public void testMapBasedServiceRegistryWithMatchingShardSelector(){ Assert.assertTrue(null != serviceRegistry.nodes() && !serviceRegistry.nodes().isEmpty()); final MatchingShardSelector matchingShardSelector = new MatchingShardSelector<>(); val nodes = matchingShardSelector.nodes( - TestNodeData.builder().nodeId(1).build(), serviceRegistry); + () -> TestNodeData.builder().nodeId(1).build(), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index d92f3206..b2067ed6 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.RegistryTestUtils; @@ -15,8 +16,9 @@ public class MatchingShardSelectorTest { public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); + Criteria criteria = () -> TestNodeData.builder().nodeId(1).build(); final List> nodes = shardSelector.nodes( - TestNodeData.builder().nodeId(1).build(), serviceRegistry); + criteria, serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java index 2818c4b8..5e88ce10 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java @@ -3,6 +3,7 @@ import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; @@ -16,7 +17,7 @@ public void testNoOpShardSelector(){ final UnshardedClusterServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); final NoOpShardSelector shardSelector = new NoOpShardSelector(); final UnshardedClusterInfo unshardedClusterInfo = new UnshardedClusterInfo(); - final List> nodes = shardSelector.nodes(unshardedClusterInfo, serviceRegistry); + final List> nodes = shardSelector.nodes(new UnshardedCriteria(unshardedClusterInfo), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index d49e99e7..7c79642d 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -4,13 +4,10 @@ import com.flipkart.ranger.core.model.NodeDataStoreConnector; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; -import lombok.Getter; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; -import java.io.IOException; import java.util.concurrent.TimeUnit; /** diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 074de977..b1ec0cb4 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; @@ -11,7 +12,7 @@ /** * */ -public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer> { +public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java index b40f53b6..9568f0ae 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java @@ -1,12 +1,10 @@ package com.flipkart.ranger.http.serviceprovider; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.NodeDataSink; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.serviceprovider.BaseServiceProviderBuilder; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; -import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java index 4d006a3d..260797e1 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java @@ -3,10 +3,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; @@ -84,13 +84,13 @@ public void testFinder() throws Exception { .nodes() .entries() .stream() - .filter(e -> e.getKey().getName().equals(criteria.getName())) + .filter(e -> e.getKey().getName().equals(criteria.getCriteria().getName())) .map(Map.Entry::getValue) .collect(Collectors.toList())) .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(testNode)); + Assert.assertNotNull(finder.get(() -> testNode)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index fac2a75f..ee102818 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; @@ -20,11 +21,10 @@ * */ @Slf4j -public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer> { +public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { protected CuratorFramework curatorFramework; protected String connectionString; - public ZkSimpleShardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java index af964455..aefd232e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java @@ -1,10 +1,11 @@ package com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.UnshardedClusterFinder; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.finder.UnshardedFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -21,7 +22,7 @@ * */ @Slf4j -public class ZkUnshardedFinderBuilder extends UnshardedFinderBuilder> { +public class ZkUnshardedFinderBuilder extends UnshardedFinderBuilder, UnshardedCriteria> { private CuratorFramework curatorFramework; private String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 6ab9ebe7..142af36c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; @@ -13,22 +14,22 @@ * */ @Slf4j -public class ZkServiceFinderHubBuilder> extends ServiceFinderHubBuilder { +public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { private String namespace; private CuratorFramework curatorFramework; private String connectionString; - public ZkServiceFinderHubBuilder withNamespace(final String namespace) { + public ZkServiceFinderHubBuilder withNamespace(final String namespace) { this.namespace = namespace; return this; } - public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { + public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @@ -49,7 +50,7 @@ protected void preBuild() { } @Override - protected void postBuild(ServiceFinderHub serviceFinderHub) { + protected void postBuild(ServiceFinderHub serviceFinderHub) { log.debug("No post build steps necessary"); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index f3004e5c..36ae667f 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -1,8 +1,9 @@ package com.flipkart.ranger.zookeeper.servicefinderhub; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -15,13 +16,13 @@ /** * */ -public class ZkShardedServiceFinderFactory implements ServiceFinderFactory> { +public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector> shardSelector; + private final ShardSelector, Criteria> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -31,7 +32,7 @@ public ZkShardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java index 0f340ecf..7e73331c 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java @@ -16,12 +16,12 @@ package com.flipkart.ranger.zookeeper.healthservice; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.healthservice.ServiceHealthAggregator; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; import com.flipkart.ranger.core.healthservice.monitor.Monitor; -import com.flipkart.ranger.core.TestUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index e940a5ba..22a31875 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -19,14 +19,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.finder.UnshardedClusterFinder; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import lombok.val; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 4e3895d3..2616d523 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -19,9 +19,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; @@ -113,14 +114,14 @@ public int hashCode() { } } - private static final class TestShardSelector implements ShardSelector> { + private static final class TestShardSelector implements ShardSelector, Criteria> { @Override - public List> nodes(TestShardInfo criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); - if((shardInfo.getA() + shardInfo.getB()) == (criteria.getA() + criteria.getB())) { + if((shardInfo.getA() + shardInfo.getB()) == (criteria.getCriteria().getA() + criteria.getCriteria().getB())) { nodes.add(entry.getValue()); } } @@ -147,18 +148,18 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(new TestShardInfo(1, 10)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1, 10)); Assert.assertNull(node); } { - ServiceNode node = serviceFinder.get(new TestShardInfo(1, 2)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1, 2)); Assert.assertNotNull(node); Assert.assertEquals(new TestShardInfo(1, 2), node.getNodeData()); } serviceFinder.stop(); } - private void registerService(String host, int port, int a, int b) throws Exception { + private void registerService(String host, int port, int a, int b) { final ServiceProvider> serviceProvider = ServiceProviderBuilders.shardedServiceProviderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 2186ede4..b2d9b6b4 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -18,8 +18,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; @@ -114,7 +114,7 @@ public void testBasicDiscovery() throws Exception { }) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNull(node); serviceFinder.stop(); @@ -140,7 +140,7 @@ public void testBasicDiscoveryRR() throws Exception { }) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNull(node); serviceFinder.stop(); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index 5c7f830d..f7fac9d3 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -129,25 +129,25 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RandomSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); Assert.assertNull(node); } serviceFinder.stop(); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 3f5fd1d3..3da8676e 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -19,12 +19,12 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; -import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; @@ -116,13 +116,13 @@ public void testBasicDiscovery() throws Exception { .withNodeRefreshIntervalMs(1000) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals("localhost-1", node.getHost()); TestServiceProvider testServiceProvider = serviceProviders.get(node.getHost()); testServiceProvider.oor(); TestUtils.sleepForSeconds(6); - Assert.assertNull(serviceFinder.get(new TestShardInfo(1))); + Assert.assertNull(serviceFinder.get(() -> new TestShardInfo(1))); serviceFinder.stop(); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 3778e000..6cf2d166 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -19,9 +19,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -126,24 +127,24 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { - ServiceNode node = serviceFinder.get(new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RandomSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); Assert.assertNull(node); } serviceFinder.stop(); @@ -172,24 +173,24 @@ public void testBasicDiscoveryRR() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { - ServiceNode node = serviceFinder.get(new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RoundRobinSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); Assert.assertNull(node); } serviceFinder.stop(); @@ -215,7 +216,7 @@ public void testVisibility() throws Exception { }) .build(); serviceFinder.start(); - List> all = serviceFinder.getAll(new TestShardInfo(1)); + List> all = serviceFinder.getAll(() -> new TestShardInfo(1)); log.info("Testing ServiceFinder.getAll()"); for (ServiceNode serviceNode : all) { log.info("node = " + serviceNode.getHost() + ":" + serviceNode.getPort() + " " + serviceNode.getHealthcheckStatus() + " " + serviceNode @@ -225,7 +226,7 @@ public void testVisibility() throws Exception { serviceFinder.stop(); } - private void registerService(String host, int port, int shardId) throws Exception { + private void registerService(String host, int port, int shardId) { final ServiceProvider> serviceProvider = ServiceProviderBuilders.shardedServiceProviderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index a4aa20c7..4009c6a9 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -20,9 +20,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.UnshardedClusterFinder; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.google.common.collect.HashMultiset; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index b13640e0..7e6abab1 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -3,18 +3,19 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; -import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; import lombok.Data; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -70,7 +71,7 @@ public void stopTestCluster() throws Exception { @Test public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); - val hub = new ZkServiceFinderHubBuilder>() + val hub = new ZkServiceFinderHubBuilder, Criteria>() .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) @@ -106,7 +107,7 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(new TestShardInfo("prod"))) + .map(finder -> finder.get(() -> new TestShardInfo("prod"))) .orElse(null); Assert.assertNotNull(node); hub.stop(); From cdae64874529468f60bbedcb84e5f102faa45cca Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 30 Sep 2021 17:11:43 +0530 Subject: [PATCH 14/53] Added tests for httpModule of ranger --- .../shardselector/MatchingShardSelector.java | 1 + .../core/serviceprovider/ServiceProvider.java | 1 + .../MatchingShardSelectorTest.java | 3 +- .../http/HttpServiceProviderBuilders.java | 6 +- .../ranger/http/config/HttpClientConfig.java | 6 +- .../http/model/ServiceNodesResponse.java | 4 +- ...=> HttpShardedServiceProviderBuilder.java} | 6 +- .../flipkart/ranger/http/ResourceHelper.java | 29 +++++++ .../HttpNodeDataStoreConnectorTest.java | 23 ++++++ .../http/config/HttpClientConfigTest.java | 17 ++++ .../http/model/ServiceNodeResponseTest.java | 30 ++++++++ .../ServiceRegistrationResponseTest.java | 15 ++++ .../HttpShardedServiceFinderBuilderTest.java | 2 +- ...HttpShardedServiceProviderBuilderTest.java | 77 +++++++++++++++++++ .../resources/fixtures/httpClientConfig.json | 8 ++ .../fixtures/serviceNodesResponse.json | 23 ++++++ .../resources/fixtures/serviceResponse.json | 3 + 17 files changed, 240 insertions(+), 14 deletions(-) rename ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/{HttpServiceProviderBuilder.java => HttpShardedServiceProviderBuilder.java} (73%) create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java rename ranger-http/src/test/java/com/flipkart/ranger/http/{ => servicefinder}/HttpShardedServiceFinderBuilderTest.java (98%) create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java create mode 100644 ranger-http/src/test/resources/fixtures/httpClientConfig.json create mode 100644 ranger-http/src/test/resources/fixtures/serviceNodesResponse.json create mode 100644 ranger-http/src/test/resources/fixtures/serviceResponse.json diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 86a9912b..1d84a834 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -29,4 +29,5 @@ public class MatchingShardSelector implements ShardSelector> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodes().get(criteria.getCriteria()); } + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java index dac9caef..f388da3e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java @@ -35,6 +35,7 @@ public class ServiceProvider> { private final Service service; private final ServiceNode serviceNode; private final S serializer; + @Getter private final NodeDataSink dataSink; @Getter private final ExternalTriggeredSignal startSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index b2067ed6..08481cb2 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -16,9 +16,8 @@ public class MatchingShardSelectorTest { public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); - Criteria criteria = () -> TestNodeData.builder().nodeId(1).build(); final List> nodes = shardSelector.nodes( - criteria, serviceRegistry); + () -> TestNodeData.builder().nodeId(1).build(), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java index 694d7594..cb134751 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java @@ -1,6 +1,6 @@ package com.flipkart.ranger.http; -import com.flipkart.ranger.http.serviceprovider.HttpServiceProviderBuilder; +import com.flipkart.ranger.http.serviceprovider.HttpShardedServiceProviderBuilder; public class HttpServiceProviderBuilders { @@ -8,7 +8,7 @@ private HttpServiceProviderBuilders() { throw new InstantiationError("Must not instantiate this class"); } - public static HttpServiceProviderBuilder httpServiceProviderBuilder() { - return new HttpServiceProviderBuilder<>(); + public static HttpShardedServiceProviderBuilder httpServiceProviderBuilder() { + return new HttpShardedServiceProviderBuilder<>(); } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java index ab176cfa..bd284bd1 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java @@ -1,13 +1,15 @@ package com.flipkart.ranger.http.config; -import lombok.Builder; -import lombok.Data; +import lombok.*; /** * */ @Data +@AllArgsConstructor @Builder +@ToString +@NoArgsConstructor public class HttpClientConfig { private String host; private int port; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 2de6cc0d..add2954d 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -2,9 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.flipkart.ranger.core.model.ServiceNode; -import lombok.Builder; -import lombok.Data; -import lombok.Singular; +import lombok.*; import java.util.List; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java similarity index 73% rename from ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java rename to ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java index 9568f0ae..6153d7eb 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java @@ -10,17 +10,17 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class HttpServiceProviderBuilder extends BaseServiceProviderBuilder, HttpRequestDataSerializer> { +public class HttpShardedServiceProviderBuilder extends BaseServiceProviderBuilder, HttpRequestDataSerializer> { private HttpClientConfig clientConfig; private ObjectMapper mapper; - public HttpServiceProviderBuilder withClientConfiguration(final HttpClientConfig clientConfig) { + public HttpShardedServiceProviderBuilder withClientConfiguration(final HttpClientConfig clientConfig) { this.clientConfig = clientConfig; return this; } - public HttpServiceProviderBuilder withObjectMapper(final ObjectMapper mapper){ + public HttpShardedServiceProviderBuilder withObjectMapper(final ObjectMapper mapper){ this.mapper = mapper; return this; } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java b/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java new file mode 100644 index 00000000..9defe986 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java @@ -0,0 +1,29 @@ +package com.flipkart.ranger.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.stream.Collectors; + +public class ResourceHelper { + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static String getResource(String path) { + final InputStream data = ResourceHelper.class.getClassLoader().getResourceAsStream(path); + return new BufferedReader( + new InputStreamReader(data)) + .lines() + .collect(Collectors.joining("\n")); + } + + @SneakyThrows + public static T getResource(String path, Class klass) { + final String data = getResource(path); + return objectMapper.readValue(data, klass); + } + +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java new file mode 100644 index 00000000..ca8eb59f --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java @@ -0,0 +1,23 @@ +package com.flipkart.ranger.http.common; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.http.config.HttpClientConfig; +import org.junit.Assert; +import org.junit.Test; + +public class HttpNodeDataStoreConnectorTest { + + @Test + public void testHttpNodeDataStoreConnector(){ + final Service service = new Service("test", "test-service"); + final ObjectMapper objectMapper = new ObjectMapper(); + final HttpClientConfig httpClientConfig = HttpClientConfig.builder() + .host("localhost-1") + .port(80) + .build(); + HttpNodeDataStoreConnector httpNodeDataStoreConnector = new HttpNodeDataStoreConnector(service, httpClientConfig, objectMapper); + Assert.assertNotNull(httpNodeDataStoreConnector); + Assert.assertTrue(httpNodeDataStoreConnector.isActive()); + } +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java new file mode 100644 index 00000000..f2187f94 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java @@ -0,0 +1,17 @@ +package com.flipkart.ranger.http.config; + +import com.flipkart.ranger.http.ResourceHelper; +import org.junit.Assert; +import org.junit.Test; + +public class HttpClientConfigTest { + + @Test + public void testHttpClientConfig(){ + HttpClientConfig resource = ResourceHelper.getResource("fixtures/httpClientConfig.json", HttpClientConfig.class); + Assert.assertEquals("localhost-1", resource.getHost()); + Assert.assertEquals(80, resource.getPort()); + Assert.assertEquals(10, resource.getConnectionTimeoutMs()); + Assert.assertEquals(10, resource.getOperationTimeoutMs()); + } +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java new file mode 100644 index 00000000..b55ff764 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java @@ -0,0 +1,30 @@ +package com.flipkart.ranger.http.model; + +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.http.ResourceHelper; +import lombok.*; +import org.junit.Assert; +import org.junit.Test; + +public class ServiceNodeResponseTest { + + @AllArgsConstructor + @NoArgsConstructor + @Getter + @Setter + static class TestNodeInfo{ + private int shardId; + private String farmId; + } + + @Test + public void testServiceNodesResponse(){ + val serviceNodesResponse = ResourceHelper.getResource("fixtures/serviceNodesResponse.json", ServiceNodesResponse.class); + Assert.assertNotNull(serviceNodesResponse); + Assert.assertFalse(serviceNodesResponse.getNodes().isEmpty()); + Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getNodes().get(0)).getNodeData()); + Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getNodes().get(1)).getNodeData()); + Assert.assertEquals(((ServiceNode) serviceNodesResponse.getNodes().get(0)).getHost(), "localhost-1"); + Assert.assertEquals(((ServiceNode) serviceNodesResponse.getNodes().get(1)).getHost(), "localhost-2"); + } +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java new file mode 100644 index 00000000..096f5608 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java @@ -0,0 +1,15 @@ +package com.flipkart.ranger.http.model; + +import com.flipkart.ranger.http.ResourceHelper; +import org.junit.Assert; +import org.junit.Test; + +public class ServiceRegistrationResponseTest { + + @Test + public void testServiceRegistrationResponse(){ + ServiceRegistrationResponse resource = ResourceHelper.getResource("fixtures/serviceResponse.json", ServiceRegistrationResponse.class); + Assert.assertNotNull(resource); + Assert.assertTrue(resource.isSuccess()); + } +} diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java similarity index 98% rename from ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java rename to ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 260797e1..b73749be 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -1,4 +1,4 @@ -package com.flipkart.ranger.http; +package com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java new file mode 100644 index 00000000..2e5e0a33 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java @@ -0,0 +1,77 @@ +package com.flipkart.ranger.http.serviceprovider; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.serviceprovider.ServiceProvider; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.model.ServiceRegistrationResponse; +import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; +import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilderTest; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import lombok.Builder; +import lombok.Data; +import lombok.val; +import okhttp3.RequestBody; +import org.junit.Rule; +import org.junit.Test; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; + +public class HttpShardedServiceProviderBuilderTest { + + @Data + private static final class TestNodeData { + private final String farmId; + + @Builder + public TestNodeData(@JsonProperty("farmId") String farmId) { + this.farmId = farmId; + } + } + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @Rule + public WireMockRule server = new WireMockRule(8888); + + @Test + public void testProvider() throws Exception { + TestNodeData nm5NodeData = TestNodeData.builder().farmId("nm5").build(); + ServiceNode testNode = new ServiceNode<>("localhost-1", 80, nm5NodeData); + val response = MAPPER.writeValueAsBytes( + ServiceRegistrationResponse.builder() + .success(true) + .build()); + byte[] requestBytes = MAPPER.writeValueAsBytes(testNode); + server.stubFor(post(urlEqualTo("/ranger/nodes/v1/add/testns/test")) + .withRequestBody(binaryEqualTo(requestBytes)) + .willReturn(aResponse() + .withBody(response) + .withStatus(200))); + val clientConfig = HttpClientConfig.builder() + .host("127.0.0.1") + .port(server.port()) + .connectionTimeoutMs(30_000) + .operationTimeoutMs(30_000) + .build(); + ServiceProvider> serviceProvider = new HttpShardedServiceProviderBuilder() + .withNamespace("testns") + .withServiceName("test") + .withHostname("localhost-1") + .withPort(80) + .withHealthcheck(Healthchecks.defaultHealthyCheck()) + .withHealthUpdateIntervalMs(1000) + .withObjectMapper(MAPPER) + .withClientConfiguration(clientConfig) + .withNodeData(nm5NodeData) + .withSerializer(node -> requestBytes) + .build(); + serviceProvider.start(); + } + +} diff --git a/ranger-http/src/test/resources/fixtures/httpClientConfig.json b/ranger-http/src/test/resources/fixtures/httpClientConfig.json new file mode 100644 index 00000000..3855f309 --- /dev/null +++ b/ranger-http/src/test/resources/fixtures/httpClientConfig.json @@ -0,0 +1,8 @@ +{ + "host" : "localhost-1", + "port" : 80, + "secure" : false, + "connectionTimeoutMs" : 10, + "operationTimeoutMs" : 10, + "refreshIntervalMillis" : 1000 +} \ No newline at end of file diff --git a/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json new file mode 100644 index 00000000..8b8cb917 --- /dev/null +++ b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json @@ -0,0 +1,23 @@ +{ + "success" : true, + "nodes" : [ + { + "host" : "localhost-1", + "port" : 80, + "nodeData" : { + "shardId" : 1, + "farmId" : "nb1" + }, + "healthcheckStatus" : "healthy" + }, + { + "host" : "localhost-2", + "port" : 90, + "nodeData" : { + "shardId" : 2, + "farmId" : "nm5" + }, + "healthcheckStatus" : "healthy" + } + ] +} \ No newline at end of file diff --git a/ranger-http/src/test/resources/fixtures/serviceResponse.json b/ranger-http/src/test/resources/fixtures/serviceResponse.json new file mode 100644 index 00000000..753c708a --- /dev/null +++ b/ranger-http/src/test/resources/fixtures/serviceResponse.json @@ -0,0 +1,3 @@ +{ + "success" : true +} \ No newline at end of file From e8d11f501337123d464ebf3ffca44d85eb3b1d03 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 8 Oct 2021 11:40:12 +0530 Subject: [PATCH 15/53] Renamed unsharded serviceregistry to list based service registry --- .../ranger/core/finder/UnshardedClusterFinder.java | 8 ++++---- .../ranger/core/finder/UnshardedFinderBuilder.java | 12 ++++++------ ...ceRegistry.java => ListBasedServiceRegistry.java} | 4 ++-- .../core/finder/shardselector/NoOpShardSelector.java | 6 +++--- .../core/finder/UnshardedClusterFinderTest.java | 4 ++-- .../finder/shardselector/NoopShardSelectorTest.java | 4 ++-- .../ranger/core/utils/RegistryTestUtils.java | 6 +++--- 7 files changed, 22 insertions(+), 22 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/{UnshardedClusterServiceRegistry.java => ListBasedServiceRegistry.java} (90%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java index 106b91da..fed927eb 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java @@ -16,15 +16,15 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.model.UnshardedCriteria; -public class UnshardedClusterFinder extends ServiceFinder { - public UnshardedClusterFinder(UnshardedClusterServiceRegistry serviceRegistry, - ShardSelector shardSelector, +public class UnshardedClusterFinder extends ServiceFinder { + public UnshardedClusterFinder(ListBasedServiceRegistry serviceRegistry, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java index f62d9a36..d42011bb 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java @@ -16,20 +16,20 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; import com.flipkart.ranger.core.model.*; public abstract class UnshardedFinderBuilder, D extends Deserializer, U extends Criteria> - extends BaseServiceFinderBuilder { + extends BaseServiceFinderBuilder { @Override protected UnshardedClusterFinder buildFinder( Service service, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { - final UnshardedClusterServiceRegistry unshardedClusterServiceRegistry - = new UnshardedClusterServiceRegistry(service); - return new UnshardedClusterFinder(unshardedClusterServiceRegistry, new NoOpShardSelector(), nodeSelector); + final ListBasedServiceRegistry listBasedServiceRegistry + = new ListBasedServiceRegistry(service); + return new UnshardedClusterFinder(listBasedServiceRegistry, new NoOpShardSelector(), nodeSelector); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java similarity index 90% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java index 23d963d8..682e518d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/UnshardedClusterServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java @@ -25,11 +25,11 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; -public class UnshardedClusterServiceRegistry extends ServiceRegistry { +public class ListBasedServiceRegistry extends ServiceRegistry { private AtomicReference>> nodes = new AtomicReference<>(); - public UnshardedClusterServiceRegistry(Service service) { + public ListBasedServiceRegistry(Service service) { super(service); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java index 22db305d..983616af 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.core.finder.shardselector; -import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.UnshardedClusterInfo; @@ -24,10 +24,10 @@ import java.util.List; -public class NoOpShardSelector implements ShardSelector { +public class NoOpShardSelector implements ShardSelector { @Override - public List> nodes(UnshardedCriteria criteria, UnshardedClusterServiceRegistry serviceRegistry) { + public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodes(); } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index d10ec0df..a075a508 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,6 +1,6 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; @@ -23,7 +23,7 @@ public ServiceNode select(List> nodes = shardSelector.nodes(new UnshardedCriteria(unshardedClusterInfo), serviceRegistry); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java index 0e6acb45..9baa8dfb 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.utils; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.finder.serviceregistry.UnshardedClusterServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.UnshardedClusterInfo; @@ -23,9 +23,9 @@ public static MapBasedServiceRegistry getServiceRegistry(){ return serviceRegistry; } - public static UnshardedClusterServiceRegistry getUnshardedRegistry(){ + public static ListBasedServiceRegistry getUnshardedRegistry(){ final Service service = new Service("test", "test-service"); - final UnshardedClusterServiceRegistry serviceRegistry = new UnshardedClusterServiceRegistry(service); + final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry(service); List> serviceNodes = Lists.newArrayList(); serviceNodes.add(new ServiceNode<>("localhost-1", 9000, new UnshardedClusterInfo())); serviceNodes.add(new ServiceNode<>("localhost-2", 9001, new UnshardedClusterInfo())); From e384d07e960ddb9036f29868468f4bd9e0d0f175 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 8 Oct 2021 11:42:44 +0530 Subject: [PATCH 16/53] Added an abstract nodeList to serviceRegistry and implemented in its implementations --- .../finder/serviceregistry/ListBasedServiceRegistry.java | 7 +++++++ .../finder/serviceregistry/MapBasedServiceRegistry.java | 9 +++++++++ .../com/flipkart/ranger/core/model/ServiceRegistry.java | 2 ++ 3 files changed, 18 insertions(+) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java index 682e518d..3e1cae24 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java @@ -22,6 +22,7 @@ import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.google.common.collect.ImmutableList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -37,6 +38,12 @@ public List> nodes() { return nodes.get(); } + @Override + public List> nodeList() { + List> nodes = this.nodes.get(); + return null == nodes ? Collections.emptyList() : nodes; + } + @Override public void updateNodes(List> serviceNodes) { nodes.set(ImmutableList.copyOf(serviceNodes)); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java index 72610e3f..133c6191 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java @@ -23,8 +23,11 @@ import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; public class MapBasedServiceRegistry extends ServiceRegistry { private AtomicReference>> nodes = new AtomicReference<>(); @@ -38,6 +41,12 @@ public ListMultimap> nodes() { return null == nodeList ? ImmutableListMultimap.of() : nodeList; } + @Override + public List> nodeList() { + final ListMultimap> nodeList = nodes.get(); + return null == nodeList ? Collections.emptyList() : new ArrayList<>(nodeList.values()); + } + @Override public void updateNodes(List> nodes) { ListMultimap> serviceNodes = ArrayListMultimap.create(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java index 09209aaf..fe549220 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java @@ -27,5 +27,7 @@ public abstract class ServiceRegistry { private final Service service; + public abstract List> nodeList(); + public abstract void updateNodes(List> nodes); } From e4a6b4a30f45de1ec57570734f5b0c94ce682b8a Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 8 Oct 2021 19:19:48 +0530 Subject: [PATCH 17/53] a) Criteria has been broken down into sharded and unsharded criteria, one for mapBasedRegistry and one for listBasedServiceRegistry b) Tests added for the broken down criteria across all the modules --- .../core/finder/BaseServiceFinderBuilder.java | 2 +- .../ranger/core/finder/ServiceFinder.java | 2 +- .../finder/SimpleShardedServiceFinder.java | 5 ++- .../SimpleShardedServiceFinderBuilder.java | 6 +-- ...java => SimpleUnshardedServiceFinder.java} | 14 +++--- .../SimpleUnshardedServiceFinderBuilder.java | 38 ++++++++++++++++ .../core/finder/UnshardedFinderBuilder.java | 35 --------------- .../ListBasedServiceRegistry.java | 16 +++---- .../shardselector/ListBasedShardSelector.java | 20 +++++++++ .../shardselector/MatchingShardSelector.java | 11 +++-- .../shardselector/NoOpShardSelector.java | 33 -------------- .../core/finderhub/ServiceFinderFactory.java | 2 +- .../core/finderhub/ServiceFinderHub.java | 2 +- .../finderhub/ServiceFinderHubBuilder.java | 2 +- .../flipkart/ranger/core/model/Criteria.java | 5 +-- .../ranger/core/model/ShardSelector.java | 3 +- .../ranger/core/model/ShardedCriteria.java | 9 ++++ .../core/model/UnshardedClusterInfo.java | 29 ------------ .../ranger/core/model/UnshardedCriteria.java | 11 ++--- .../core/finder/SimpleShardFinderTest.java | 12 ++--- .../finder/UnshardedClusterFinderTest.java | 19 ++++---- .../MapBasedServiceRegistryTest.java | 3 +- ...t.java => ListBasedShardSelectorTest.java} | 11 +++-- .../MatchingShardSelectorTest.java | 4 +- .../ranger/core/utils/CriteriaUtils.java | 26 +++++++++++ .../ranger/core/utils/RegistryTestUtils.java | 13 +++--- .../HttpShardedServiceFinderBuilder.java | 3 +- .../HttpShardedServiceFinderBuilderTest.java | 10 ++++- .../zookeeper/ServiceFinderBuilders.java | 6 +-- .../zookeeper/ServiceProviderBuilders.java | 3 +- .../ZkSimpleShardedServiceFinderBuilder.java | 3 +- ...kSimpleUnshardedServiceFinderBuilder.java} | 23 +++++----- .../ZkServiceFinderHubBuilder.java | 2 +- .../ZkShardedServiceFinderFactory.java | 11 ++--- .../ServiceProviderIntegrationTest.java | 40 ++++++++++++++--- .../model/CustomShardSelectorTest.java | 22 ++++++--- .../model/ServiceNoProviderTest.java | 15 ++++++- .../model/ServiceProviderExtCuratorTest.java | 18 ++++++-- .../model/ServiceProviderHealthcheckTest.java | 16 ++++++- .../zookeeper/model/ServiceProviderTest.java | 28 ++++++++---- .../model/SimpleServiceProviderTest.java | 45 +++++++++++++++---- .../zookeeper/servicehub/ServiceHubTest.java | 10 ++++- 42 files changed, 345 insertions(+), 243 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/{UnshardedClusterFinder.java => SimpleUnshardedServiceFinder.java} (55%) create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java rename ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/{NoopShardSelectorTest.java => ListBasedShardSelectorTest.java} (56%) create mode 100644 ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java rename ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/{ZkUnshardedFinderBuilder.java => ZkSimpleUnshardedServiceFinderBuilder.java} (64%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 44976559..0f6ac2f8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -40,7 +40,7 @@ public abstract class BaseServiceFinderBuilder F extends ServiceFinder, B extends BaseServiceFinderBuilder, D extends Deserializer, - U extends Criteria> { + U extends Criteria> { protected String namespace; protected String serviceName; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index da37642c..f0bf7d4d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -25,7 +25,7 @@ import java.util.List; @Slf4j -public abstract class ServiceFinder, U extends Criteria> { +public abstract class ServiceFinder, U extends Criteria> { @Getter private final ServiceRegistryType serviceRegistry; private final ShardSelector shardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index e6931ad4..0186091a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -20,10 +20,11 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.ShardedCriteria; -public class SimpleShardedServiceFinder extends ServiceFinder, Criteria> { +public class SimpleShardedServiceFinder extends ServiceFinder, ShardedCriteria> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, - ShardSelector, Criteria> shardSelector, + ShardSelector, ShardedCriteria> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index e095a6e2..86456189 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -20,13 +20,13 @@ import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; import com.flipkart.ranger.core.model.*; -public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> - extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, Criteria> { +public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends ShardedCriteria> + extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, ShardedCriteria> { @Override protected SimpleShardedServiceFinder buildFinder( Service service, - ShardSelector, Criteria> shardSelector, + ShardSelector, ShardedCriteria> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java similarity index 55% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index fed927eb..eab06737 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedClusterFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -17,15 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.*; -public class UnshardedClusterFinder extends ServiceFinder { - public UnshardedClusterFinder(ListBasedServiceRegistry serviceRegistry, - ShardSelector shardSelector, - ServiceNodeSelector nodeSelector) { +public class SimpleUnshardedServiceFinder extends ServiceFinder, UnshardedCriteria> { + public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, + ShardSelector, UnshardedCriteria> shardSelector, + ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java new file mode 100644 index 00000000..c1098cf6 --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -0,0 +1,38 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder; + +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.ListBasedShardSelector; +import com.flipkart.ranger.core.model.*; + +public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends UnshardedCriteria> + extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, UnshardedCriteria> { + + @Override + protected SimpleUnshardedServiceFinder buildFinder( + Service service, + ShardSelector, UnshardedCriteria> shardSelector, + ServiceNodeSelector nodeSelector + ) { + if (null == shardSelector) { + shardSelector = new ListBasedShardSelector<>(); + } + final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); + return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); + } +} \ No newline at end of file diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java deleted file mode 100644 index d42011bb..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/UnshardedFinderBuilder.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2015 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 com.flipkart.ranger.core.finder; - -import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; -import com.flipkart.ranger.core.model.*; - -public abstract class UnshardedFinderBuilder, D extends Deserializer, U extends Criteria> - extends BaseServiceFinderBuilder { - - @Override - protected UnshardedClusterFinder buildFinder( - Service service, - ShardSelector shardSelector, - ServiceNodeSelector nodeSelector) { - final ListBasedServiceRegistry listBasedServiceRegistry - = new ListBasedServiceRegistry(service); - return new UnshardedClusterFinder(listBasedServiceRegistry, new NoOpShardSelector(), nodeSelector); - } -} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java index 3e1cae24..77c0522d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java @@ -19,33 +19,27 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceRegistry; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.google.common.collect.ImmutableList; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -public class ListBasedServiceRegistry extends ServiceRegistry { - private AtomicReference>> nodes +public class ListBasedServiceRegistry extends ServiceRegistry { + private AtomicReference>> nodes = new AtomicReference<>(); public ListBasedServiceRegistry(Service service) { super(service); } - public List> nodes() { - return nodes.get(); - } - - @Override - public List> nodeList() { - List> nodes = this.nodes.get(); + public List> nodeList() { + List> nodes = this.nodes.get(); return null == nodes ? Collections.emptyList() : nodes; } @Override - public void updateNodes(List> serviceNodes) { + public void updateNodes(List> serviceNodes) { nodes.set(ImmutableList.copyOf(serviceNodes)); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java new file mode 100644 index 00000000..e49a48de --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java @@ -0,0 +1,20 @@ +package com.flipkart.ranger.core.finder.shardselector; + +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedCriteria; + +import java.util.List; +import java.util.stream.Collectors; + +public class ListBasedShardSelector implements ShardSelector, UnshardedCriteria> { + + @Override + public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + if(null == criteria){ + return serviceRegistry.nodeList(); + } + return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList()); + } +} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 1d84a834..b6f58631 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -20,14 +20,19 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.ShardedCriteria; +import com.google.common.base.Preconditions; +import java.util.Collections; import java.util.List; +import java.util.Optional; -public class MatchingShardSelector implements ShardSelector, Criteria> { +public class MatchingShardSelector implements ShardSelector, ShardedCriteria> { @Override - public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { - return serviceRegistry.nodes().get(criteria.getCriteria()); + public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { + Preconditions.checkNotNull(criteria, "Criteria can't be null"); + return serviceRegistry.nodes().get(criteria.getShard()); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java deleted file mode 100644 index 983616af..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoOpShardSelector.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Copyright 2015 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 com.flipkart.ranger.core.finder.shardselector; - -import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; -import com.flipkart.ranger.core.model.UnshardedCriteria; - -import java.util.List; - -public class NoOpShardSelector implements ShardSelector { - - @Override - public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { - return serviceRegistry.nodes(); - } -} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 0d392469..779bbe5f 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -8,7 +8,7 @@ /** * */ -public interface ServiceFinderFactory, U extends Criteria> { +public interface ServiceFinderFactory, U extends Criteria> { ServiceFinder buildFinder(final Service service); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index eadb23e3..3248efb7 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -27,7 +27,7 @@ * */ @Slf4j -public class ServiceFinderHub, U extends Criteria> { +public class ServiceFinderHub, U extends Criteria> { private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 60e044a9..228bc710 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -15,7 +15,7 @@ /** * */ -public abstract class ServiceFinderHubBuilder, U extends Criteria> { +public abstract class ServiceFinderHubBuilder, U extends Criteria> { private ServiceDataSource serviceDataSource; private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index 83a381e6..e88030f0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -1,6 +1,5 @@ package com.flipkart.ranger.core.model; -public interface Criteria { - - T getCriteria(); +public interface Criteria> { + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index e77c59d1..b9bbd406 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -17,8 +17,9 @@ package com.flipkart.ranger.core.model; import java.util.List; +import java.util.stream.Collectors; -public interface ShardSelector, U extends Criteria> { +public interface ShardSelector, U extends Criteria> { List> nodes(U criteria, ServiceRegistryType serviceRegistry); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java new file mode 100644 index 00000000..ed9fe9d2 --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java @@ -0,0 +1,9 @@ +package com.flipkart.ranger.core.model; + +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; + +public abstract class ShardedCriteria implements Criteria> { + + public abstract T getShard(); + +} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java deleted file mode 100644 index d3a73820..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedClusterInfo.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright 2015 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 com.flipkart.ranger.core.model; - -public class UnshardedClusterInfo { - @Override - public int hashCode() { - return 0; - } - - @Override - public boolean equals(Object obj) { - return super.equals(obj); - } -} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java index 3732405f..c5c35c4b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java @@ -1,14 +1,9 @@ package com.flipkart.ranger.core.model; -import lombok.Data; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -@Data -public class UnshardedCriteria implements Criteria { +public abstract class UnshardedCriteria implements Criteria> { - private final UnshardedClusterInfo unshardedClusterInfo; + public abstract boolean apply(T nodeData); - @Override - public UnshardedClusterInfo getCriteria() { - return unshardedClusterInfo; - } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 96e376d4..55095651 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -5,7 +5,9 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import com.google.common.collect.Lists; import lombok.val; @@ -16,10 +18,10 @@ public class SimpleShardFinderTest { - static class TestSimpleShardSelector implements ShardSelector, Criteria>{ - + static class TestSimpleShardSelector implements ShardSelector, ShardedCriteria>{ + @Override - public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { return Lists.newArrayList(); } } @@ -29,10 +31,10 @@ public void testSimpleShardedFinder(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final TestSimpleShardSelector shardSelector = new TestSimpleShardSelector<>(); final RoundRobinServiceNodeSelector roundRobinServiceNodeSelector = new RoundRobinServiceNodeSelector<>(); - val simpleShardedFinder = new SimpleShardedServiceFinder<>( + val simpleShardedFinder = new SimpleShardedServiceFinder( serviceRegistry, shardSelector, roundRobinServiceNodeSelector); val testNodeDataServiceNode = simpleShardedFinder.get( - () -> TestNodeData.builder().nodeId(2).build()); + CriteriaUtils.getShardedCriteria(2)); Assert.assertNull(testNodeDataServiceNode); } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index a075a508..bfbbce30 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,11 +1,11 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.NoOpShardSelector; +import com.flipkart.ranger.core.finder.shardselector.ListBasedShardSelector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; @@ -14,24 +14,23 @@ public class UnshardedClusterFinderTest { - static class TestUnshardedNodeSelector implements ServiceNodeSelector{ + static class TestUnshardedNodeSelector implements ServiceNodeSelector{ @Override - public ServiceNode select(List> serviceNodes) { + public ServiceNode select(List> serviceNodes) { return serviceNodes.get(0); } } @Test public void unshardedClusterFinder(){ - final ListBasedServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); - final NoOpShardSelector shardSelector = new NoOpShardSelector(); - final UnshardedClusterInfo unshardedClusterInfo = new UnshardedClusterInfo(); - UnshardedClusterFinder unshardedClusterFinder = new UnshardedClusterFinder( + final ListBasedServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); + final ListBasedShardSelector shardSelector = new ListBasedShardSelector<>(); + SimpleUnshardedServiceFinder simpleUnshardedServiceFinder = new SimpleUnshardedServiceFinder( unshardedRegistry, shardSelector, new TestUnshardedNodeSelector() ); - final ServiceNode serviceNode = unshardedClusterFinder.get(new UnshardedCriteria(unshardedClusterInfo)); + final ServiceNode serviceNode = simpleUnshardedServiceFinder.get(CriteriaUtils.getUnshardedCriteria(1)); Assert.assertNotNull(serviceNode); Assert.assertEquals("localhost-1", serviceNode.getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index effeb67b..6f60d275 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import lombok.val; import org.junit.Assert; @@ -15,7 +16,7 @@ public void testMapBasedServiceRegistryWithMatchingShardSelector(){ Assert.assertTrue(null != serviceRegistry.nodes() && !serviceRegistry.nodes().isEmpty()); final MatchingShardSelector matchingShardSelector = new MatchingShardSelector<>(); val nodes = matchingShardSelector.nodes( - () -> TestNodeData.builder().nodeId(1).build(), serviceRegistry); + CriteriaUtils.getShardedCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java similarity index 56% rename from ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java rename to ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java index 2c2ff76b..78052eaf 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java @@ -2,22 +2,21 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; import java.util.List; -public class NoopShardSelectorTest { +public class ListBasedShardSelectorTest { @Test public void testNoOpShardSelector(){ final ListBasedServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); - final NoOpShardSelector shardSelector = new NoOpShardSelector(); - final UnshardedClusterInfo unshardedClusterInfo = new UnshardedClusterInfo(); - final List> nodes = shardSelector.nodes(new UnshardedCriteria(unshardedClusterInfo), serviceRegistry); + final ListBasedShardSelector shardSelector = new ListBasedShardSelector<>(); + final List> nodes = shardSelector.nodes(CriteriaUtils.getUnshardedCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index 08481cb2..47b91948 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -1,9 +1,9 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; @@ -17,7 +17,7 @@ public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); final List> nodes = shardSelector.nodes( - () -> TestNodeData.builder().nodeId(1).build(), serviceRegistry); + CriteriaUtils.getShardedCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java new file mode 100644 index 00000000..08e74fbb --- /dev/null +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -0,0 +1,26 @@ +package com.flipkart.ranger.core.utils; + +import com.flipkart.ranger.core.model.ShardedCriteria; +import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.units.TestNodeData; + +public class CriteriaUtils { + + public static ShardedCriteria getShardedCriteria(int shardId){ + return new ShardedCriteria() { + @Override + public TestNodeData getShard() { + return TestNodeData.builder().nodeId(shardId).build(); + } + }; + } + + public static UnshardedCriteria getUnshardedCriteria(int shardId){ + return new UnshardedCriteria() { + @Override + public boolean apply(TestNodeData nodeData) { + return nodeData.getNodeId() == shardId; + } + }; + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java index 9baa8dfb..1f69f05b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -4,7 +4,6 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.core.units.TestNodeData; import com.google.common.collect.Lists; @@ -23,13 +22,13 @@ public static MapBasedServiceRegistry getServiceRegistry(){ return serviceRegistry; } - public static ListBasedServiceRegistry getUnshardedRegistry(){ + public static ListBasedServiceRegistry getUnshardedRegistry(){ final Service service = new Service("test", "test-service"); - final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry(service); - List> serviceNodes = Lists.newArrayList(); - serviceNodes.add(new ServiceNode<>("localhost-1", 9000, new UnshardedClusterInfo())); - serviceNodes.add(new ServiceNode<>("localhost-2", 9001, new UnshardedClusterInfo())); - serviceNodes.add(new ServiceNode<>("localhost-3", 9002, new UnshardedClusterInfo())); + final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); + List> serviceNodes = Lists.newArrayList(); + serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestNodeData.builder().nodeId(1).build())); + serviceNodes.add(new ServiceNode<>("localhost-2", 9001, TestNodeData.builder().nodeId(2).build())); + serviceNodes.add(new ServiceNode<>("localhost-3", 9002, TestNodeData.builder().nodeId(3).build())); serviceRegistry.updateNodes(serviceNodes); return serviceRegistry; } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index b1ec0cb4..ac7884dc 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -6,13 +6,14 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; /** * */ -public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { +public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, ShardedCriteria> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index b73749be..9fe34c63 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -7,6 +7,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; @@ -84,13 +85,18 @@ public void testFinder() throws Exception { .nodes() .entries() .stream() - .filter(e -> e.getKey().getName().equals(criteria.getCriteria().getName())) + .filter(e -> e.getKey().getName().equals(criteria.getShard().getName())) .map(Map.Entry::getValue) .collect(Collectors.toList())) .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(() -> testNode)); + Assert.assertNotNull(finder.get(new ShardedCriteria() { + @Override + public NodeData getShard() { + return testNode; + } + })); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index 504e46c5..bc3dade3 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -17,7 +17,7 @@ package com.flipkart.ranger.zookeeper; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.zookeeper.servicefinder.ZkUnshardedFinderBuilder; +import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; public class ServiceFinderBuilders { @@ -29,7 +29,7 @@ public static ZkSimpleShardedServiceFinderBuilder shardedFinderBuilder() return new ZkSimpleShardedServiceFinderBuilder<>(); } - public static ZkUnshardedFinderBuilder unshardedFinderBuilder() { - return new ZkUnshardedFinderBuilder(); + public static ZkSimpleUnshardedServiceFinderBuilder unshardedFinderBuilder() { + return new ZkSimpleUnshardedServiceFinderBuilder<>(); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java index 091a9857..4a034f4c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java @@ -16,7 +16,6 @@ package com.flipkart.ranger.zookeeper; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; import com.flipkart.ranger.zookeeper.serviceprovider.ZkServiceProviderBuilder; public class ServiceProviderBuilders { @@ -29,7 +28,7 @@ public static ZkServiceProviderBuilder shardedServiceProviderBuilder() { return new ZkServiceProviderBuilder<>(); } - public static ZkServiceProviderBuilder unshardedServiceProviderBuilder() { + public static ZkServiceProviderBuilder unshardedServiceProviderBuilder() { return new ZkServiceProviderBuilder<>(); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index ee102818..301dd131 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -5,6 +5,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -21,7 +22,7 @@ * */ @Slf4j -public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { +public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, ShardedCriteria> { protected CuratorFramework curatorFramework; protected String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java similarity index 64% rename from ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java rename to ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index aefd232e..33f0289f 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkUnshardedFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -1,11 +1,8 @@ package com.flipkart.ranger.zookeeper.servicefinder; -import com.flipkart.ranger.core.finder.UnshardedClusterFinder; -import com.flipkart.ranger.core.finder.UnshardedFinderBuilder; -import com.flipkart.ranger.core.model.NodeDataSource; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -22,22 +19,22 @@ * */ @Slf4j -public class ZkUnshardedFinderBuilder extends UnshardedFinderBuilder, UnshardedCriteria> { +public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, UnshardedCriteria> { private CuratorFramework curatorFramework; private String connectionString; - public ZkUnshardedFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkSimpleUnshardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkUnshardedFinderBuilder withConnectionString(final String connectionString) { + public ZkSimpleUnshardedServiceFinderBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @Override - public UnshardedClusterFinder build() { + public SimpleUnshardedServiceFinder build() { boolean curatorProvided = curatorFramework != null; if (!curatorProvided) { Preconditions.checkNotNull(connectionString); @@ -52,15 +49,15 @@ public UnshardedClusterFinder build() { } @Override - protected NodeDataSource> dataSource( + protected NodeDataSource> dataSource( Service service) { return new ZkNodeDataSource<>(service, curatorFramework); } @Override - protected List> implementationSpecificRefreshSignals( - final Service service, final NodeDataSource> nodeDataSource) { + protected List> implementationSpecificRefreshSignals( + final Service service, final NodeDataSource> nodeDataSource) { if (!disablePushUpdaters) { return Collections.singletonList( new ZkWatcherRegistryUpdateSignal<>(service, nodeDataSource, curatorFramework)); diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 142af36c..f0f67b6e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -14,7 +14,7 @@ * */ @Slf4j -public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { +public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { private String namespace; private CuratorFramework curatorFramework; private String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 36ae667f..56b8072e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -3,10 +3,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; import lombok.Builder; @@ -16,13 +13,13 @@ /** * */ -public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { +public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, ShardedCriteria> { private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, Criteria> shardSelector; + private final ShardSelector, ShardedCriteria> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -32,7 +29,7 @@ public ZkShardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, Criteria> shardSelector, + ShardSelector, ShardedCriteria> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 22a31875..eeb90af2 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -20,12 +20,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.TestUtils; -import com.flipkart.ranger.core.finder.UnshardedClusterFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -50,8 +50,19 @@ public class ServiceProviderIntegrationTest { private TestingCluster testingCluster; private ObjectMapper objectMapper; - UnshardedClusterFinder serviceFinder; + SimpleUnshardedServiceFinder serviceFinder; + private static final class UnshardedClusterInfo { + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + } @Before public void startTestCluster() throws Exception { objectMapper = new ObjectMapper(); @@ -65,7 +76,7 @@ public void startTestCluster() throws Exception { registerService("localhost-4", 9000, 2, anotherFile); - serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() + serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -101,7 +112,12 @@ public void testBasicDiscovery() throws Exception { boolean filecreate = file.createNewFile(); System.out.println("created file"); TestUtils.sleepForSeconds(8); - List> all = serviceFinder.getAll(null); + List> all = serviceFinder.getAll(new UnshardedCriteria() { + @Override + public boolean apply(Object nodeData) { + return true; + } + }); System.out.println("all = " + all); Assert.assertEquals(3, all.size()); @@ -109,7 +125,12 @@ public void testBasicDiscovery() throws Exception { delete = file.delete(); System.out.println("deleted file"); TestUtils.sleepForSeconds(8); - all = serviceFinder.getAll(null); + all = serviceFinder.getAll(new UnshardedCriteria() { + @Override + public boolean apply(Object nodeData) { + return true; + } + }); System.out.println("all = " + all); Assert.assertEquals(0, all.size()); @@ -117,7 +138,12 @@ public void testBasicDiscovery() throws Exception { filecreate = anotherFile.createNewFile(); System.out.println("created anotherFile"); TestUtils.sleepForSeconds(6); - all = serviceFinder.getAll(null); + all = serviceFinder.getAll(new UnshardedCriteria() { + @Override + public boolean apply(Object nodeData) { + return true; + } + }); System.out.println("all = " + all); Assert.assertEquals(1, all.size()); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 2616d523..56ceb42b 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -22,9 +22,9 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; + @Slf4j public class CustomShardSelectorTest { private TestingCluster testingCluster; @@ -112,16 +113,25 @@ public int hashCode() { result = 31 * result + b; return result; } + + protected static ShardedCriteria getCriteria(int a, int b){ + return new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new TestShardInfo(a, b); + } + }; + } } - private static final class TestShardSelector implements ShardSelector, Criteria> { + private static final class TestShardSelector implements ShardSelector, ShardedCriteria> { @Override - public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); - if((shardInfo.getA() + shardInfo.getB()) == (criteria.getCriteria().getA() + criteria.getCriteria().getB())) { + if((shardInfo.getA() + shardInfo.getB()) == (criteria.getShard().getA() + criteria.getShard().getB())) { nodes.add(entry.getValue()); } } @@ -148,11 +158,11 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1, 10)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1, 10)); Assert.assertNull(node); } { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1, 2)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1, 2)); Assert.assertNotNull(node); Assert.assertEquals(new TestShardInfo(1, 2), node.getNodeData()); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index b2d9b6b4..b2949050 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -21,6 +21,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; import org.apache.curator.test.TestingCluster; @@ -93,8 +94,18 @@ public boolean equals(Object o) { public int hashCode() { return shardId; } + + protected static ShardedCriteria getCriteria(int shardId){ + return new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new TestShardInfo(shardId); + } + }; + } } + @Test public void testBasicDiscovery() throws Exception { SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() @@ -114,7 +125,7 @@ public void testBasicDiscovery() throws Exception { }) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNull(node); serviceFinder.stop(); @@ -140,7 +151,7 @@ public void testBasicDiscoveryRR() throws Exception { }) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNull(node); serviceFinder.stop(); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index f7fac9d3..f78fc8c0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -22,6 +22,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -108,6 +109,15 @@ public boolean equals(Object o) { public int hashCode() { return shardId; } + + protected static ShardedCriteria getCriteria(int shardId){ + return new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new TestShardInfo(shardId); + } + }; + } } @Test @@ -129,25 +139,25 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RandomSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(99)); Assert.assertNull(node); } serviceFinder.stop(); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 3da8676e..6dfa47c1 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -95,6 +96,17 @@ public boolean equals(Object o) { public int hashCode() { return shardId; } + + protected static ShardedCriteria getCriteria(int shardId){ + return new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new + + TestShardInfo(shardId); + } + }; + } } @Test @@ -116,13 +128,13 @@ public void testBasicDiscovery() throws Exception { .withNodeRefreshIntervalMs(1000) .build(); serviceFinder.start(); - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals("localhost-1", node.getHost()); TestServiceProvider testServiceProvider = serviceProviders.get(node.getHost()); testServiceProvider.oor(); TestUtils.sleepForSeconds(6); - Assert.assertNull(serviceFinder.get(() -> new TestShardInfo(1))); + Assert.assertNull(serviceFinder.get(TestShardInfo.getCriteria(1))); serviceFinder.stop(); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 6cf2d166..0df5c464 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -107,6 +108,15 @@ public boolean equals(Object o) { public int hashCode() { return shardId; } + + protected static ShardedCriteria getCriteria(int shardId){ + return new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new TestShardInfo(shardId); + } + }; + } } @Test @@ -127,24 +137,24 @@ public void testBasicDiscovery() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RandomSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(99)); Assert.assertNull(node); } serviceFinder.stop(); @@ -173,24 +183,24 @@ public void testBasicDiscoveryRR() throws Exception { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(1)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(1)); Assert.assertNotNull(node); Assert.assertEquals(1, node.getNodeData().getShardId()); } long startTime = System.currentTimeMillis(); for (long i = 0; i < 1000000; i++) { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(2)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(2)); Assert.assertNotNull(node); Assert.assertEquals(2, node.getNodeData().getShardId()); } log.info("PERF::RoundRobinSelector::Took (ms):" + (System.currentTimeMillis() - startTime)); { - ServiceNode node = serviceFinder.get(() -> new TestShardInfo(99)); + ServiceNode node = serviceFinder.get(TestShardInfo.getCriteria(99)); Assert.assertNull(node); } serviceFinder.stop(); @@ -216,7 +226,7 @@ public void testVisibility() throws Exception { }) .build(); serviceFinder.start(); - List> all = serviceFinder.getAll(() -> new TestShardInfo(1)); + List> all = serviceFinder.getAll(TestShardInfo.getCriteria(1)); log.info("Testing ServiceFinder.getAll()"); for (ServiceNode serviceNode : all) { log.info("node = " + serviceNode.getHost() + ":" + serviceNode.getPort() + " " + serviceNode.getHealthcheckStatus() + " " + serviceNode diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 4009c6a9..337cd570 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -19,10 +19,14 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.UnshardedClusterFinder; +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedClusterInfo; +import com.flipkart.ranger.core.model.ShardedCriteria; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.google.common.collect.HashMultiset; @@ -58,27 +62,45 @@ public void stopTestCluster() throws Exception { } } + private static class UnshardedInfo { + + @Override + public int hashCode() { + return 0; + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + } + @Test - public void testBasicDiscovery() throws Exception { - UnshardedClusterFinder serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() + public void testBasicDiscovery() { + SimpleUnshardedServiceFinder serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") + .withDisableWatchers() .withDeserializer(data -> { try { return objectMapper.readValue(data, - new TypeReference>() { + new TypeReference>() { }); } catch (IOException e) { e.printStackTrace(); } return null; }) - .withDisableWatchers() .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(null); + ServiceNode node = serviceFinder.get(new UnshardedCriteria() { + @Override + public boolean apply(UnshardedInfo nodeData) { + return true; + } + }); Assert.assertNotNull(node); System.out.println(node.getHost()); } @@ -86,7 +108,12 @@ public void testBasicDiscovery() throws Exception { long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(null); + ServiceNode node = serviceFinder.get(new UnshardedCriteria() { + @Override + public boolean apply(UnshardedInfo nodeData) { + return true; + } + }); Assert.assertNotNull(node); frequency.add(node.getHost()); } @@ -96,7 +123,7 @@ public void testBasicDiscovery() throws Exception { } private void registerService(String host, int port, int shardId) throws Exception { - val serviceProvider = ServiceProviderBuilders.unshardedServiceProviderBuilder() + val serviceProvider = ServiceProviderBuilders.unshardedServiceProviderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 7e6abab1..bed71014 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -10,6 +10,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -71,7 +72,7 @@ public void stopTestCluster() throws Exception { @Test public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); - val hub = new ZkServiceFinderHubBuilder, Criteria>() + val hub = new ZkServiceFinderHubBuilder, ShardedCriteria>() .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) @@ -107,7 +108,12 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(() -> new TestShardInfo("prod"))) + .map(finder -> finder.get(new ShardedCriteria() { + @Override + public TestShardInfo getShard() { + return new TestShardInfo("prod"); + } + })) .orElse(null); Assert.assertNotNull(node); hub.stop(); From d8e33d5fd635089473497258e1cdc6752936c8a4 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 11 Oct 2021 22:18:15 +0530 Subject: [PATCH 18/53] Removed the server module --- pom.xml | 1 - .../HttpShardedServiceFinderBuilder.java | 1 - ranger-server/pom.xml | 22 ------- .../ZKUnshardedServiceFinderFactory.java | 62 +++++++++++++++++++ 4 files changed, 62 insertions(+), 24 deletions(-) delete mode 100644 ranger-server/pom.xml create mode 100644 ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java diff --git a/pom.xml b/pom.xml index 6deb4a58..fe029426 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,6 @@ ranger-core ranger-zookeeper ranger-http - ranger-server diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index ac7884dc..c01c8dc3 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ShardedCriteria; diff --git a/ranger-server/pom.xml b/ranger-server/pom.xml deleted file mode 100644 index 8743e241..00000000 --- a/ranger-server/pom.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - ranger - com.flipkart.ranger - 1.0-SNAPSHOT - - 4.0.0 - - ranger-server - - - - com.flipkart.ranger - ranger-zookeeper - ${project.version} - - - - \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java new file mode 100644 index 00000000..7ea5a3af --- /dev/null +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -0,0 +1,62 @@ +package com.flipkart.ranger.zookeeper.servicefinderhub; + +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; +import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; +import lombok.Builder; +import lombok.Getter; +import lombok.val; +import org.apache.curator.framework.CuratorFramework; + + +@Getter +public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, UnshardedCriteria>{ + + private final CuratorFramework curatorFramework; + private final String connectionString; + private final int nodeRefreshIntervalMs; + private final boolean disablePushUpdaters; + private final ZkNodeDataDeserializer deserializer; + private final ShardSelector, UnshardedCriteria> shardSelector; + private final ServiceNodeSelector nodeSelector; + + @Builder + public ZKUnshardedServiceFinderFactory( + CuratorFramework curatorFramework, + String connectionString, + int nodeRefreshIntervalMs, + boolean disablePushUpdaters, + ZkNodeDataDeserializer deserializer, + ShardSelector, UnshardedCriteria> shardSelector, + ServiceNodeSelector nodeSelector) { + this.curatorFramework = curatorFramework; + this.connectionString = connectionString; + this.nodeRefreshIntervalMs = nodeRefreshIntervalMs; + this.disablePushUpdaters = disablePushUpdaters; + this.deserializer = deserializer; + this.shardSelector = shardSelector; + this.nodeSelector = nodeSelector; + } + + @Override + public SimpleUnshardedServiceFinder buildFinder(Service service) { + val finder = new ZkSimpleUnshardedServiceFinderBuilder() + .withDeserializer(deserializer) + .withNamespace(service.getNamespace()) + .withServiceName(service.getServiceName()) + .withNodeRefreshIntervalMs(nodeRefreshIntervalMs) + .withDisableWatchers(disablePushUpdaters) + .withShardSelector(shardSelector) + .withNodeSelector(nodeSelector) + .withConnectionString(connectionString) + .withCuratorFramework(curatorFramework) + .build(); + finder.start(); + return finder; + } +} From 0d59101ad01d4a75afba38bb809d4c12b5a1cc7b Mon Sep 17 00:00:00 2001 From: Koushik R Date: Tue, 12 Oct 2021 12:42:52 +0530 Subject: [PATCH 19/53] Removed the unnecessary server --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fe029426..58eff335 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ UTF-8 30.1.1-jre - 4.0.1 + 4.2.0 2.12.5 1.7.32 From f0e07cd76949e13db72a5044d93aa8d84aed960d Mon Sep 17 00:00:00 2001 From: Koushik R Date: Tue, 12 Oct 2021 16:02:07 +0530 Subject: [PATCH 20/53] Added http service finder hub --- .../finderhub/ServiceFinderHubBuilder.java | 2 + .../http/model/ServiceDataSourceResponse.java | 18 +++++ .../HttpUnshardedServiceFinderBuilider.java | 37 +++++++++ .../HttpServiceDataSource.java | 77 +++++++++++++++++++ .../HttpServiceFinderHubBuilder.java | 21 +++++ .../HttpUnshardedServiceFinderFactory.java | 61 +++++++++++++++ 6 files changed, 216 insertions(+) create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 228bc710..b86d6e82 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -54,6 +54,7 @@ public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extr } public ServiceFinderHub build() { + preBuild(); Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); @@ -73,6 +74,7 @@ public ServiceFinderHub build() { .registerConsumers(extraStopSignalConsumers) .registerConsumer(x -> refreshSignal.stop()) .registerConsumer(x -> serviceDataSource.stop()); + postBuild(hub); return hub; } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java new file mode 100644 index 00000000..6bb0af2c --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java @@ -0,0 +1,18 @@ +package com.flipkart.ranger.http.model; + +import com.flipkart.ranger.core.model.Service; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class ServiceDataSourceResponse { + private boolean success; + private List services; +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java new file mode 100644 index 00000000..ed33cbc0 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -0,0 +1,37 @@ +package com.flipkart.ranger.http.servicefinder; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.NodeDataSource; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; + +public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, UnshardedCriteria> { + + private HttpClientConfig clientConfig; + private ObjectMapper mapper; + + public HttpUnshardedServiceFinderBuilider withClientConfig(final HttpClientConfig clientConfig) { + this.clientConfig = clientConfig; + return this; + } + + public HttpUnshardedServiceFinderBuilider withObjectMapper(final ObjectMapper mapper) { + this.mapper = mapper; + return this; + } + + @Override + public SimpleUnshardedServiceFinder build() { + return buildFinder(); + } + + @Override + protected NodeDataSource> dataSource(Service service) { + return new HttpNodeDataSource<>(service, clientConfig, mapper); + } +} + diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java new file mode 100644 index 00000000..8244a85e --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -0,0 +1,77 @@ +package com.flipkart.ranger.http.servicefinderhub; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.core.util.FinderUtils; +import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceDataSourceResponse; +import com.google.common.base.Preconditions; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import okhttp3.HttpUrl; +import okhttp3.Request; +import okhttp3.ResponseBody; + +import java.io.IOException; +import java.util.Collection; +import java.util.Collections; + +@Slf4j +public class HttpServiceDataSource extends HttpNodeDataStoreConnector implements ServiceDataSource { + + public HttpServiceDataSource(Service service, HttpClientConfig config, ObjectMapper mapper) { + super(service, config, mapper); + } + + @Override + public Collection services() { + Preconditions.checkNotNull(config, "client config has not been set for node data"); + Preconditions.checkNotNull(mapper, "mapper has not been set for node data"); + + val httpUrl = new HttpUrl.Builder() + .scheme(config.isSecure() + ? "https" + : "http") + .host(config.getHost()) + .port(config.getPort() == 0 + ? defaultPort() + : config.getPort()) + .encodedPath("/ranger/services") + .build(); + val request = new Request.Builder() + .url(httpUrl) + .get() + .build(); + + try (val response = httpClient.newCall(request).execute()) { + if (response.isSuccessful()) { + try (final ResponseBody body = response.body()) { + if (null == body) { + log.warn("HTTP call to {} returned empty body", httpUrl); + } + else { + final byte[] bytes = body.bytes(); + val serviceDataSourceResponse = mapper.readValue(bytes, ServiceDataSourceResponse.class); + if(serviceDataSourceResponse.isSuccess()){ + return serviceDataSourceResponse.getServices(); + } + } + } + } + else { + log.warn("HTTP call to {} returned: {}", httpUrl, response.code()); + } + } + catch (IOException e) { + Exceptions.illegalState("Error fetching data from server: " + httpUrl, e); + } + + log.error("No data returned from server: " + httpUrl); + return Collections.emptyList(); + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java new file mode 100644 index 00000000..963674e8 --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -0,0 +1,21 @@ +package com.flipkart.ranger.http.servicefinderhub; + +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.ServiceRegistry; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class HttpServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { + + @Override + protected void preBuild() { + log.info("No pre-ebuild actions necessary"); + } + + @Override + protected void postBuild(ServiceFinderHub serviceFinderHub) { + log.info("No post build actions necessary"); + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java new file mode 100644 index 00000000..104f650f --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -0,0 +1,61 @@ +package com.flipkart.ranger.http.servicefinderhub; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import com.flipkart.ranger.http.servicefinder.HttpUnshardedServiceFinderBuilider; +import lombok.Builder; +import lombok.Getter; +import lombok.val; + +@Getter +public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, UnshardedCriteria> { + + private final HttpClientConfig clientConfig; + private final ObjectMapper mapper; + private final HTTPResponseDataDeserializer deserializer; + private final ShardSelector, UnshardedCriteria> shardSelector; + private final ServiceNodeSelector nodeSelector; + private final int nodeRefreshIntervalMs; + + @Builder + public HttpUnshardedServiceFinderFactory( + HttpClientConfig httpClientConfig, + ObjectMapper mapper, + HTTPResponseDataDeserializer deserializer, + ShardSelector, UnshardedCriteria> shardSelector, + ServiceNodeSelector nodeSelector, + int nodeRefreshIntervalMs) + { + this.clientConfig = httpClientConfig; + this.mapper = mapper; + this.deserializer = deserializer; + this.shardSelector = shardSelector; + this.nodeSelector = nodeSelector; + this.nodeRefreshIntervalMs = nodeRefreshIntervalMs; + } + + @Override + public ServiceFinder, UnshardedCriteria> buildFinder(Service service) { + val serviceFinder = new HttpUnshardedServiceFinderBuilider() + .withClientConfig(clientConfig) + .withObjectMapper(mapper) + .withDeserializer(deserializer) + .withNamespace(service.getNamespace()) + .withServiceName(service.getServiceName()) + .withNodeRefreshIntervalMs(nodeRefreshIntervalMs) + .withShardSelector(shardSelector) + .withNodeSelector(nodeSelector) + .build(); + serviceFinder.start(); + return serviceFinder; + } +} From d3e1c72ed186b3df77912b223d07bbfcf1d89ac5 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Tue, 12 Oct 2021 16:52:35 +0530 Subject: [PATCH 21/53] Added tests for http hub --- .../core/finderhub/StaticDataSource.java | 34 +++++++++ .../flipkart/ranger/core/model/Service.java | 6 +- .../common/HttpNodeDataStoreConnector.java | 5 +- .../http/model/ServiceDataSourceResponse.java | 6 +- .../http/model/ServiceNodesResponse.java | 2 +- .../serde/HTTPResponseDataDeserializer.java | 3 +- .../servicefinder/HttpNodeDataSource.java | 38 ++++++---- .../HttpServiceDataSource.java | 4 +- .../serviceprovider/HttpNodeDataSink.java | 5 +- .../HttpNodeDataStoreConnectorTest.java | 3 +- .../HttpShardedServiceFinderBuilderTest.java | 4 +- .../HttpServiceDataSourceTest.java | 71 +++++++++++++++++++ 12 files changed, 146 insertions(+), 35 deletions(-) create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java create mode 100644 ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java new file mode 100644 index 00000000..1953853b --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java @@ -0,0 +1,34 @@ +package com.flipkart.ranger.core.finderhub; + +import com.flipkart.ranger.core.model.Service; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.util.Collection; +import java.util.List; + +/* +A static data source to be used when we know the services beforehand and don't have to fetch from a source. + */ + +@Slf4j +@AllArgsConstructor +public class StaticDataSource implements ServiceDataSource{ + + private final List services; + + @Override + public Collection services() throws Exception { + return services; + } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } +} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java index ec3e7fe0..3847f48c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java @@ -23,8 +23,10 @@ @Data @AllArgsConstructor(access = AccessLevel.PUBLIC) public class Service { - private final String namespace; - private final String serviceName; + private String namespace; + private String serviceName; + + public Service(){} public String name() { return String.format("%s/%s", namespace, serviceName); diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index 7c79642d..2b41617c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -16,16 +16,13 @@ @Slf4j public class HttpNodeDataStoreConnector implements NodeDataStoreConnector { - protected final Service service; protected final HttpClientConfig config; - protected final OkHttpClient httpClient; protected final ObjectMapper mapper; + protected final OkHttpClient httpClient; public HttpNodeDataStoreConnector( - Service service, final HttpClientConfig config, ObjectMapper mapper) { - this.service = service; this.httpClient = new OkHttpClient.Builder() .callTimeout(config.getOperationTimeoutMs() == 0 ? 3000 diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java index 6bb0af2c..285ab55c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java @@ -1,10 +1,7 @@ package com.flipkart.ranger.http.model; import com.flipkart.ranger.core.model.Service; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import java.util.List; @@ -12,6 +9,7 @@ @NoArgsConstructor @Getter @Setter +@Builder public class ServiceDataSourceResponse { private boolean success; private List services; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index add2954d..92b6cc4c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -10,7 +10,7 @@ * */ @Data -public class ServiceNodesResponse { +public class ServiceNodesResponse { private final boolean success; final List> nodes; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java index 3ece5323..af35a36a 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.http.model.ServiceNodesResponse; import java.util.Collection; @@ -10,5 +11,5 @@ */ @FunctionalInterface public interface HTTPResponseDataDeserializer extends Deserializer { - Collection> deserialize(byte []data); + ServiceNodesResponse deserialize(byte []data); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 57589f45..8c10bff4 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -8,6 +8,7 @@ import com.flipkart.ranger.core.util.FinderUtils; import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; @@ -17,6 +18,7 @@ import okhttp3.ResponseBody; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -25,11 +27,15 @@ */ @Slf4j public class HttpNodeDataSource> extends HttpNodeDataStoreConnector implements NodeDataSource { + + private final Service service; + public HttpNodeDataSource( Service service, final HttpClientConfig config, ObjectMapper mapper) { - super(service, config, mapper); + super(config, mapper); + this.service = service; } @Override @@ -42,37 +48,39 @@ public Optional>> refresh(D deserializer) { : "http") .host(config.getHost()) .port(config.getPort() == 0 - ? defaultPort() - : config.getPort()) + ? defaultPort() + : config.getPort()) .encodedPath(String.format("/ranger/nodes/v1/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val request = new Request.Builder() .url(httpUrl) .get() .build(); + ServiceNodesResponse serviceNodesResponse = null; try (val response = httpClient.newCall(request).execute()) { if (response.isSuccessful()) { try (final ResponseBody body = response.body()) { if (null == body) { log.warn("HTTP call to {} returned empty body", httpUrl); - } - else { + } else { final byte[] bytes = body.bytes(); - return Optional.of(FinderUtils.filterValidNodes( - service, - deserializer.deserialize(bytes), - healthcheckZombieCheckThresholdTime(service))); + serviceNodesResponse = deserializer.deserialize(bytes); } } + } else { + log.warn("HTTP call to {} returned: {}", httpUrl, response.code()); } - else { - log.warn("HTTP call to {} returned: {}", httpUrl.toString(), response.code()); - } - } - catch (IOException e) { + } catch (IOException e) { Exceptions.illegalState("Error fetching data from server: " + httpUrl, e); } - log.error("No data returned from server: " + httpUrl); + + if (null != serviceNodesResponse && null != serviceNodesResponse.getNodes() && + !serviceNodesResponse.getNodes().isEmpty()) { + return Optional.of(FinderUtils.filterValidNodes( + service, + serviceNodesResponse.getNodes(), + healthcheckZombieCheckThresholdTime(service))); + } return Optional.empty(); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java index 8244a85e..636fd463 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -24,8 +24,8 @@ @Slf4j public class HttpServiceDataSource extends HttpNodeDataStoreConnector implements ServiceDataSource { - public HttpServiceDataSource(Service service, HttpClientConfig config, ObjectMapper mapper) { - super(service, config, mapper); + public HttpServiceDataSource(HttpClientConfig config, ObjectMapper mapper) { + super(config, mapper); } @Override diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index de2ee759..02be98c7 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -23,8 +23,11 @@ @Slf4j public class HttpNodeDataSink> extends HttpNodeDataStoreConnector implements NodeDataSink { + private final Service service; + public HttpNodeDataSink(Service service, HttpClientConfig config, ObjectMapper mapper) { - super(service, config, mapper); + super(config, mapper); + this.service = service; } @Override diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java index ca8eb59f..07b264d6 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java @@ -10,13 +10,12 @@ public class HttpNodeDataStoreConnectorTest { @Test public void testHttpNodeDataStoreConnector(){ - final Service service = new Service("test", "test-service"); final ObjectMapper objectMapper = new ObjectMapper(); final HttpClientConfig httpClientConfig = HttpClientConfig.builder() .host("localhost-1") .port(80) .build(); - HttpNodeDataStoreConnector httpNodeDataStoreConnector = new HttpNodeDataStoreConnector(service, httpClientConfig, objectMapper); + HttpNodeDataStoreConnector httpNodeDataStoreConnector = new HttpNodeDataStoreConnector(httpClientConfig, objectMapper); Assert.assertNotNull(httpNodeDataStoreConnector); Assert.assertTrue(httpNodeDataStoreConnector.isActive()); } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 9fe34c63..1332f666 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -72,14 +72,12 @@ public void testFinder() throws Exception { .withServiceName("test") .withObjectMapper(MAPPER) .withDeserializer(data -> { - final ServiceNodesResponse response; try { - response = MAPPER.readValue(data, new TypeReference>() {}); + return MAPPER.readValue(data, new TypeReference>() {}); } catch (IOException e) { throw new IllegalArgumentException(e); } - return response.isSuccess() ? response.getNodes() : Collections.emptyList(); }) .withShardSelector((criteria, registry) -> registry .nodes() diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java new file mode 100644 index 00000000..50881825 --- /dev/null +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -0,0 +1,71 @@ +package com.flipkart.ranger.http.servicefinderhub; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceDataSourceResponse; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.google.common.collect.Lists; +import lombok.Builder; +import lombok.Data; +import lombok.val; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collection; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; + +public class HttpServiceDataSourceTest { + + @Data + private static final class TestNodeData { + private final String farmId; + + @Builder + public TestNodeData(@JsonProperty("farmId") String farmId) { + this.farmId = farmId; + } + } + + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @Rule + public WireMockRule server = new WireMockRule(8888); + + @Test + public void testServiceDataSource() throws IOException { + val responseObj = ServiceDataSourceResponse.builder() + .success(true) + .services(Lists.newArrayList( + new Service("test-n", "test-s"), + new Service("test-n", "test-s1"), + new Service("test-n", "test-s2") + )) + .build(); + val response = MAPPER.writeValueAsBytes(responseObj); + server.stubFor(get(urlEqualTo("/ranger/services")) + .willReturn(aResponse() + .withBody(response) + .withStatus(200))); + val clientConfig = HttpClientConfig.builder() + .host("127.0.0.1") + .port(server.port()) + .connectionTimeoutMs(30_000) + .operationTimeoutMs(30_000) + .build(); + HttpServiceDataSource httpServiceDataSource = new HttpServiceDataSource<>(clientConfig, MAPPER); + Collection services = httpServiceDataSource.services(); + Assert.assertNotNull(services); + Assert.assertFalse(services.isEmpty()); + Assert.assertEquals(3, services.size()); + Assert.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s"))); + Assert.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s1"))); + Assert.assertFalse(services.stream().noneMatch(each -> each.getServiceName().equalsIgnoreCase("test-s2"))); + } + +} From 72820c8d124a17d8922ebe90eff1f4d47f4bc40a Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 21:04:49 +0530 Subject: [PATCH 22/53] Changed ZKServiceDataSource to take in connectionString for consitency purposes and to manage the lifecycle within --- .../servicefinderhub/ZkServiceDataSource.java | 20 ++++++++++++++++--- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 011b19a8..2d1ad935 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -2,8 +2,11 @@ import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.model.Service; +import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; import java.util.Collection; import java.util.List; @@ -16,11 +19,12 @@ public class ZkServiceDataSource implements ServiceDataSource { private final String namespace; - private final CuratorFramework curatorFramework; + private final String connectionString; + private CuratorFramework curatorFramework; - public ZkServiceDataSource(String namespace, CuratorFramework curatorFramework) { + public ZkServiceDataSource(String namespace, String connectionString){ this.namespace = namespace; - this.curatorFramework = curatorFramework; + this.connectionString = connectionString; } @Override @@ -34,6 +38,14 @@ public Collection services() throws Exception { @Override public void start() { + Preconditions.checkNotNull(connectionString); + log.info("Building custom curator framework"); + curatorFramework = CuratorFrameworkFactory.builder() + .namespace(namespace) + .connectString(connectionString) + .retryPolicy(new ExponentialBackoffRetry(1000, 100)) + .build(); + curatorFramework.start(); try { curatorFramework.blockUntilConnected(); } @@ -45,6 +57,8 @@ public void start() { @Override public void stop() { + log.info("Service data stopped"); + curatorFramework.close(); log.info("Service data source stopped"); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index bed71014..0a6ff525 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -76,7 +76,7 @@ public void testHub() { .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) - .withServiceDataSource(new ZkServiceDataSource("test", curatorFramework)) + .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString())) .withServiceFinderFactory(ZkShardedServiceFinderFactory.builder() .curatorFramework(curatorFramework) .deserializer(this::read) From 69f488326dd923d7c769022e74f41235d3eb5a74 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 21:41:34 +0530 Subject: [PATCH 23/53] Updated lombok version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58eff335..5b2d0e7a 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ 3.8.0 1.8 - 1.18.2 + 1.18.16 4.13.2 4.1.0 From 3806e9facb29e9f5115c7f009161642b3afa7957 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 22:17:07 +0530 Subject: [PATCH 24/53] Made Criteria as interfaces instead. @FunctionalInterface at that --- .../java/com/flipkart/ranger/core/model/ShardedCriteria.java | 5 +++-- .../com/flipkart/ranger/core/model/UnshardedCriteria.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java index ed9fe9d2..04516985 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java @@ -2,8 +2,9 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -public abstract class ShardedCriteria implements Criteria> { +@FunctionalInterface +public interface ShardedCriteria extends Criteria> { - public abstract T getShard(); + T getShard(); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java index c5c35c4b..7c1ab40b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java @@ -2,8 +2,9 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -public abstract class UnshardedCriteria implements Criteria> { +@FunctionalInterface +public interface UnshardedCriteria extends Criteria> { - public abstract boolean apply(T nodeData); + boolean apply(T nodeData); } From bfd19e62ff5621165dec0ded260b8993cfe762c2 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 22:23:28 +0530 Subject: [PATCH 25/53] Fixed lambda expressions under criteria in tests --- .../flipkart/ranger/core/utils/CriteriaUtils.java | 14 ++------------ .../HttpShardedServiceFinderBuilderTest.java | 7 +------ .../ServiceProviderIntegrationTest.java | 7 +------ .../zookeeper/model/CustomShardSelectorTest.java | 9 ++------- .../zookeeper/model/ServiceNoProviderTest.java | 9 ++------- .../model/ServiceProviderExtCuratorTest.java | 9 ++------- .../model/ServiceProviderHealthcheckTest.java | 12 +++--------- .../zookeeper/model/ServiceProviderTest.java | 9 ++------- .../zookeeper/model/SimpleServiceProviderTest.java | 7 +------ .../zookeeper/servicehub/ServiceHubTest.java | 7 +------ 10 files changed, 17 insertions(+), 73 deletions(-) diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index 08e74fbb..f70ae409 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -7,20 +7,10 @@ public class CriteriaUtils { public static ShardedCriteria getShardedCriteria(int shardId){ - return new ShardedCriteria() { - @Override - public TestNodeData getShard() { - return TestNodeData.builder().nodeId(shardId).build(); - } - }; + return () -> TestNodeData.builder().nodeId(shardId).build(); } public static UnshardedCriteria getUnshardedCriteria(int shardId){ - return new UnshardedCriteria() { - @Override - public boolean apply(TestNodeData nodeData) { - return nodeData.getNodeId() == shardId; - } - }; + return nodeData -> nodeData.getNodeId() == shardId; } } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 1332f666..e9887e00 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -89,12 +89,7 @@ public void testFinder() throws Exception { .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(new ShardedCriteria() { - @Override - public NodeData getShard() { - return testNode; - } - })); + Assert.assertNotNull(finder.get(() -> testNode)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index eeb90af2..9006f779 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -112,12 +112,7 @@ public void testBasicDiscovery() throws Exception { boolean filecreate = file.createNewFile(); System.out.println("created file"); TestUtils.sleepForSeconds(8); - List> all = serviceFinder.getAll(new UnshardedCriteria() { - @Override - public boolean apply(Object nodeData) { - return true; - } - }); + List> all = serviceFinder.getAll((UnshardedCriteria) nodeData -> true); System.out.println("all = " + all); Assert.assertEquals(3, all.size()); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 56ceb42b..9f88f406 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -114,13 +114,8 @@ public int hashCode() { return result; } - protected static ShardedCriteria getCriteria(int a, int b){ - return new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new TestShardInfo(a, b); - } - }; + private static ShardedCriteria getCriteria(int a, int b){ + return () -> new TestShardInfo(a, b); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index b2949050..47da9f54 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -95,13 +95,8 @@ public int hashCode() { return shardId; } - protected static ShardedCriteria getCriteria(int shardId){ - return new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new TestShardInfo(shardId); - } - }; + private static ShardedCriteria getCriteria(int shardId){ + return () -> new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index f78fc8c0..cf025279 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -110,13 +110,8 @@ public int hashCode() { return shardId; } - protected static ShardedCriteria getCriteria(int shardId){ - return new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new TestShardInfo(shardId); - } - }; + private static ShardedCriteria getCriteria(int shardId){ + return () -> new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 6dfa47c1..acb05e5a 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -97,15 +97,9 @@ public int hashCode() { return shardId; } - protected static ShardedCriteria getCriteria(int shardId){ - return new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new - - TestShardInfo(shardId); - } - }; + private static ShardedCriteria getCriteria(int shardId){ + return () -> new + TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 0df5c464..9a713bbb 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -109,13 +109,8 @@ public int hashCode() { return shardId; } - protected static ShardedCriteria getCriteria(int shardId){ - return new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new TestShardInfo(shardId); - } - }; + private static ShardedCriteria getCriteria(int shardId){ + return () -> new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 337cd570..12bacbcd 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -95,12 +95,7 @@ public void testBasicDiscovery() { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(new UnshardedCriteria() { - @Override - public boolean apply(UnshardedInfo nodeData) { - return true; - } - }); + ServiceNode node = serviceFinder.get(nodeData -> true); Assert.assertNotNull(node); System.out.println(node.getHost()); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 0a6ff525..e0bc6ade 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -108,12 +108,7 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(new ShardedCriteria() { - @Override - public TestShardInfo getShard() { - return new TestShardInfo("prod"); - } - })) + .map(finder -> finder.get(() -> new TestShardInfo("prod"))) .orElse(null); Assert.assertNotNull(node); hub.stop(); From 773091add808974b5db76a6b07693e37256d8fb1 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 22:48:57 +0530 Subject: [PATCH 26/53] ServiceRegistry type removed from criteria --- .../flipkart/ranger/core/finder/BaseServiceFinderBuilder.java | 2 +- .../java/com/flipkart/ranger/core/finder/ServiceFinder.java | 2 +- .../core/finder/shardselector/MatchingShardSelector.java | 1 + .../flipkart/ranger/core/finderhub/ServiceFinderFactory.java | 2 +- .../com/flipkart/ranger/core/finderhub/ServiceFinderHub.java | 2 +- .../ranger/core/finderhub/ServiceFinderHubBuilder.java | 2 +- .../main/java/com/flipkart/ranger/core/model/Criteria.java | 2 +- .../java/com/flipkart/ranger/core/model/ShardSelector.java | 3 +-- .../java/com/flipkart/ranger/core/model/ShardedCriteria.java | 4 +--- .../com/flipkart/ranger/core/model/UnshardedCriteria.java | 4 +--- .../http/servicefinderhub/HttpServiceFinderHubBuilder.java | 2 +- .../zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java | 2 +- 12 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 0f6ac2f8..44976559 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -40,7 +40,7 @@ public abstract class BaseServiceFinderBuilder F extends ServiceFinder, B extends BaseServiceFinderBuilder, D extends Deserializer, - U extends Criteria> { + U extends Criteria> { protected String namespace; protected String serviceName; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index f0bf7d4d..da37642c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -25,7 +25,7 @@ import java.util.List; @Slf4j -public abstract class ServiceFinder, U extends Criteria> { +public abstract class ServiceFinder, U extends Criteria> { @Getter private final ServiceRegistryType serviceRegistry; private final ShardSelector shardSelector; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index b6f58631..b2673675 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -35,4 +35,5 @@ public List> nodes(ShardedCriteria criteria, MapBasedServiceRe return serviceRegistry.nodes().get(criteria.getShard()); } + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 779bbe5f..0d392469 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -8,7 +8,7 @@ /** * */ -public interface ServiceFinderFactory, U extends Criteria> { +public interface ServiceFinderFactory, U extends Criteria> { ServiceFinder buildFinder(final Service service); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index 3248efb7..eadb23e3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -27,7 +27,7 @@ * */ @Slf4j -public class ServiceFinderHub, U extends Criteria> { +public class ServiceFinderHub, U extends Criteria> { private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index b86d6e82..99ed93bf 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -15,7 +15,7 @@ /** * */ -public abstract class ServiceFinderHubBuilder, U extends Criteria> { +public abstract class ServiceFinderHubBuilder, U extends Criteria> { private ServiceDataSource serviceDataSource; private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index e88030f0..70ecbdea 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -1,5 +1,5 @@ package com.flipkart.ranger.core.model; -public interface Criteria> { +public interface Criteria { } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index b9bbd406..e77c59d1 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -17,9 +17,8 @@ package com.flipkart.ranger.core.model; import java.util.List; -import java.util.stream.Collectors; -public interface ShardSelector, U extends Criteria> { +public interface ShardSelector, U extends Criteria> { List> nodes(U criteria, ServiceRegistryType serviceRegistry); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java index 04516985..13d09f0a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java @@ -1,9 +1,7 @@ package com.flipkart.ranger.core.model; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; - @FunctionalInterface -public interface ShardedCriteria extends Criteria> { +public interface ShardedCriteria extends Criteria { T getShard(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java index 7c1ab40b..53ea0000 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java @@ -1,9 +1,7 @@ package com.flipkart.ranger.core.model; -import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; - @FunctionalInterface -public interface UnshardedCriteria extends Criteria> { +public interface UnshardedCriteria extends Criteria { boolean apply(T nodeData); diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index 963674e8..81f82ad4 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -7,7 +7,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class HttpServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { +public class HttpServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { @Override protected void preBuild() { diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index f0f67b6e..142af36c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -14,7 +14,7 @@ * */ @Slf4j -public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { +public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { private String namespace; private CuratorFramework curatorFramework; private String connectionString; From c50cc9a198790c5ee903144d579bc69d288bc866 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Wed, 13 Oct 2021 22:56:40 +0530 Subject: [PATCH 27/53] Optimized imports --- .../ranger/core/finder/SimpleShardedServiceFinder.java | 1 - .../ranger/core/finder/SimpleUnshardedServiceFinder.java | 5 +++-- .../finder/serviceregistry/MapBasedServiceRegistry.java | 1 - .../core/finder/shardselector/MatchingShardSelector.java | 3 --- .../flipkart/ranger/core/finder/SimpleShardFinderTest.java | 1 - .../com/flipkart/ranger/core/utils/RegistryTestUtils.java | 2 +- .../ranger/http/common/HttpNodeDataStoreConnector.java | 1 - .../flipkart/ranger/http/model/ServiceNodesResponse.java | 4 +++- .../ranger/http/serde/HTTPResponseDataDeserializer.java | 3 --- .../ranger/http/servicefinder/HttpNodeDataSource.java | 1 - .../http/servicefinderhub/HttpServiceDataSource.java | 3 --- .../HttpUnshardedServiceFinderFactory.java | 1 - .../ranger/http/common/HttpNodeDataStoreConnectorTest.java | 1 - .../servicefinder/HttpShardedServiceFinderBuilderTest.java | 3 --- .../http/servicefinderhub/HttpServiceDataSourceTest.java | 1 - .../HttpShardedServiceProviderBuilderTest.java | 5 ----- .../servicefinder/ZkSimpleShardedServiceFinderBuilder.java | 1 - .../ZkSimpleUnshardedServiceFinderBuilder.java | 4 +++- .../servicefinderhub/ZKUnshardedServiceFinderFactory.java | 7 ++++--- .../servicefinderhub/ZkShardedServiceFinderFactory.java | 5 ++++- .../ranger/zookeeper/model/ServiceProviderTest.java | 1 - .../ranger/zookeeper/model/SimpleServiceProviderTest.java | 4 ---- .../ranger/zookeeper/servicehub/ServiceHubTest.java | 1 - 23 files changed, 18 insertions(+), 41 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index 0186091a..39cbdc56 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -17,7 +17,6 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.ShardedCriteria; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index eab06737..4a93250d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -17,8 +17,9 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedCriteria; public class SimpleUnshardedServiceFinder extends ServiceFinder, UnshardedCriteria> { public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java index 133c6191..912f0b8b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java @@ -27,7 +27,6 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicReference; -import java.util.stream.Collectors; public class MapBasedServiceRegistry extends ServiceRegistry { private AtomicReference>> nodes = new AtomicReference<>(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index b2673675..52d9ecc8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -17,15 +17,12 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.ShardedCriteria; import com.google.common.base.Preconditions; -import java.util.Collections; import java.util.List; -import java.util.Optional; public class MatchingShardSelector implements ShardSelector, ShardedCriteria> { diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 55095651..238daab7 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.model.ShardedCriteria; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java index 1f69f05b..5213d28d 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.utils; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index 2b41617c..8d22d5ba 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.model.NodeDataStoreConnector; -import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import lombok.extern.slf4j.Slf4j; import okhttp3.ConnectionPool; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 92b6cc4c..35b03356 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.flipkart.ranger.core.model.ServiceNode; -import lombok.*; +import lombok.Builder; +import lombok.Data; +import lombok.Singular; import java.util.List; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java index af35a36a..0cf065cb 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java @@ -1,11 +1,8 @@ package com.flipkart.ranger.http.serde; import com.flipkart.ranger.core.model.Deserializer; -import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.http.model.ServiceNodesResponse; -import java.util.Collection; - /** * */ diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 8c10bff4..5711c1fa 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -18,7 +18,6 @@ import okhttp3.ResponseBody; import java.io.IOException; -import java.util.Collections; import java.util.List; import java.util.Optional; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java index 636fd463..a33b273c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -1,12 +1,9 @@ package com.flipkart.ranger.http.servicefinderhub; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.core.util.FinderUtils; import com.flipkart.ranger.http.common.HttpNodeDataStoreConnector; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceDataSourceResponse; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 104f650f..6762a0c1 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java index 07b264d6..0a328ed0 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java @@ -1,7 +1,6 @@ package com.flipkart.ranger.http.common; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import org.junit.Assert; import org.junit.Test; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index e9887e00..be594fac 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -7,10 +7,8 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; -import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; import com.github.tomakehurst.wiremock.junit.WireMockRule; import lombok.Data; import lombok.val; @@ -19,7 +17,6 @@ import org.junit.Test; import java.io.IOException; -import java.util.Collections; import java.util.Map; import java.util.stream.Collectors; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 50881825..99203676 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -18,7 +18,6 @@ import java.util.Collection; import static com.github.tomakehurst.wiremock.client.WireMock.*; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; public class HttpServiceDataSourceTest { diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java index 2e5e0a33..bff51890 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java @@ -2,21 +2,16 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.TestUtils; -import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.http.config.HttpClientConfig; -import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.model.ServiceRegistrationResponse; import com.flipkart.ranger.http.serde.HttpRequestDataSerializer; -import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilderTest; import com.github.tomakehurst.wiremock.junit.WireMockRule; import lombok.Builder; import lombok.Data; import lombok.val; -import okhttp3.RequestBody; import org.junit.Rule; import org.junit.Test; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index 301dd131..f66bb5eb 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ShardedCriteria; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index 33f0289f..a9a70958 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -2,7 +2,9 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.NodeDataSource; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 7ea5a3af..f424840a 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -1,11 +1,12 @@ package com.flipkart.ranger.zookeeper.servicefinderhub; -import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; import lombok.Builder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 56b8072e..f11f0594 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -3,7 +3,10 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; import lombok.Builder; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 9a713bbb..df55123a 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -22,7 +22,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 12bacbcd..d9f9c8fa 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -19,13 +19,9 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; -import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.model.UnshardedCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index e0bc6ade..d90e71da 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -7,7 +7,6 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardedCriteria; From 1eac3ed2437e3fed3318b2e8f0546b0ec57ec8f4 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 14 Oct 2021 09:29:07 +0530 Subject: [PATCH 28/53] Optimized imports --- .../ranger/zookeeper/model/CustomShardSelectorTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 9f88f406..e2cc6663 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -122,7 +122,10 @@ private static ShardedCriteria getCriteria(int a, int b){ private static final class TestShardSelector implements ShardSelector, ShardedCriteria> { @Override - public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes( + ShardedCriteria criteria, + MapBasedServiceRegistry serviceRegistry + ) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); From 5af8ff6af92516b57347a2a0e3c2976c7ae5b034 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 14 Oct 2021 12:12:34 +0530 Subject: [PATCH 29/53] Added a noop shard selector --- .../SimpleUnshardedServiceFinderBuilder.java | 4 ++-- ...hardSelector.java => FilterShardSelector.java} | 2 +- .../finder/shardselector/NoopShardSelector.java | 15 +++++++++++++++ .../core/finder/UnshardedClusterFinderTest.java | 4 ++-- ...ctorTest.java => FilterShardSelectorTest.java} | 4 ++-- 5 files changed, 22 insertions(+), 7 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/{ListBasedShardSelector.java => FilterShardSelector.java} (85%) create mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java rename ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/{ListBasedShardSelectorTest.java => FilterShardSelectorTest.java} (85%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index c1098cf6..3fefd1a8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -17,7 +17,7 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.ListBasedShardSelector; +import com.flipkart.ranger.core.finder.shardselector.FilterShardSelector; import com.flipkart.ranger.core.model.*; public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends UnshardedCriteria> @@ -30,7 +30,7 @@ protected SimpleUnshardedServiceFinder buildFinder( ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { - shardSelector = new ListBasedShardSelector<>(); + shardSelector = new FilterShardSelector<>(); } final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java similarity index 85% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java index e49a48de..cf54e326 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java @@ -8,7 +8,7 @@ import java.util.List; import java.util.stream.Collectors; -public class ListBasedShardSelector implements ShardSelector, UnshardedCriteria> { +public class FilterShardSelector implements ShardSelector, UnshardedCriteria> { @Override public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java new file mode 100644 index 00000000..8043325a --- /dev/null +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -0,0 +1,15 @@ +package com.flipkart.ranger.core.finder.shardselector; + +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.UnshardedCriteria; + +import java.util.List; + +public class NoopShardSelector implements ShardSelector, UnshardedCriteria> { + @Override + public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + return serviceRegistry.nodeList(); + } +} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index bfbbce30..92e9fec3 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.ListBasedShardSelector; +import com.flipkart.ranger.core.finder.shardselector.FilterShardSelector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.units.TestNodeData; @@ -24,7 +24,7 @@ public ServiceNode select(List> serviceN @Test public void unshardedClusterFinder(){ final ListBasedServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); - final ListBasedShardSelector shardSelector = new ListBasedShardSelector<>(); + final FilterShardSelector shardSelector = new FilterShardSelector<>(); SimpleUnshardedServiceFinder simpleUnshardedServiceFinder = new SimpleUnshardedServiceFinder( unshardedRegistry, shardSelector, diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java similarity index 85% rename from ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java rename to ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java index 78052eaf..c34ea1af 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListBasedShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java @@ -10,12 +10,12 @@ import java.util.List; -public class ListBasedShardSelectorTest { +public class FilterShardSelectorTest { @Test public void testNoOpShardSelector(){ final ListBasedServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); - final ListBasedShardSelector shardSelector = new ListBasedShardSelector<>(); + final FilterShardSelector shardSelector = new FilterShardSelector<>(); final List> nodes = shardSelector.nodes(CriteriaUtils.getUnshardedCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); From d93bdc9c9f5472d09aea9bbd151a7af84f4a62ff Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 14 Oct 2021 13:07:12 +0530 Subject: [PATCH 30/53] Unsharded criteria renamed to filter criteria --- .../core/finder/SimpleUnshardedServiceFinder.java | 6 +++--- .../finder/SimpleUnshardedServiceFinderBuilder.java | 6 +++--- .../core/finder/shardselector/FilterShardSelector.java | 6 +++--- .../core/finder/shardselector/NoopShardSelector.java | 6 +++--- .../{UnshardedCriteria.java => FilterCriteria.java} | 2 +- .../ranger/core/finder/UnshardedClusterFinderTest.java | 2 +- .../finder/shardselector/FilterShardSelectorTest.java | 2 +- .../com/flipkart/ranger/core/utils/CriteriaUtils.java | 4 ++-- .../HttpUnshardedServiceFinderBuilider.java | 4 ++-- .../HttpUnshardedServiceFinderFactory.java | 10 +++++----- .../ZkSimpleUnshardedServiceFinderBuilder.java | 4 ++-- .../ZKUnshardedServiceFinderFactory.java | 8 ++++---- .../healthservice/ServiceProviderIntegrationTest.java | 8 ++++---- .../zookeeper/model/SimpleServiceProviderTest.java | 4 ++-- 14 files changed, 36 insertions(+), 36 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/model/{UnshardedCriteria.java => FilterCriteria.java} (61%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index 4a93250d..8dc6fb56 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -19,11 +19,11 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; -public class SimpleUnshardedServiceFinder extends ServiceFinder, UnshardedCriteria> { +public class SimpleUnshardedServiceFinder extends ServiceFinder, FilterCriteria> { public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, - ShardSelector, UnshardedCriteria> shardSelector, + ShardSelector, FilterCriteria> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index 3fefd1a8..e2053a08 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -20,13 +20,13 @@ import com.flipkart.ranger.core.finder.shardselector.FilterShardSelector; import com.flipkart.ranger.core.model.*; -public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends UnshardedCriteria> - extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, UnshardedCriteria> { +public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends FilterCriteria> + extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, FilterCriteria> { @Override protected SimpleUnshardedServiceFinder buildFinder( Service service, - ShardSelector, UnshardedCriteria> shardSelector, + ShardSelector, FilterCriteria> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java index cf54e326..917e3b3d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java @@ -3,15 +3,15 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import java.util.List; import java.util.stream.Collectors; -public class FilterShardSelector implements ShardSelector, UnshardedCriteria> { +public class FilterShardSelector implements ShardSelector, FilterCriteria> { @Override - public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(FilterCriteria criteria, ListBasedServiceRegistry serviceRegistry) { if(null == criteria){ return serviceRegistry.nodeList(); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 8043325a..4c00420a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -3,13 +3,13 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import java.util.List; -public class NoopShardSelector implements ShardSelector, UnshardedCriteria> { +public class NoopShardSelector implements ShardSelector, FilterCriteria> { @Override - public List> nodes(UnshardedCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(FilterCriteria criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodeList(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java similarity index 61% rename from ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java index 53ea0000..43f739ac 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/UnshardedCriteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.model; @FunctionalInterface -public interface UnshardedCriteria extends Criteria { +public interface FilterCriteria extends Criteria { boolean apply(T nodeData); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index 92e9fec3..c9e43a0b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -30,7 +30,7 @@ public void unshardedClusterFinder(){ shardSelector, new TestUnshardedNodeSelector() ); - final ServiceNode serviceNode = simpleUnshardedServiceFinder.get(CriteriaUtils.getUnshardedCriteria(1)); + final ServiceNode serviceNode = simpleUnshardedServiceFinder.get(CriteriaUtils.getFilterCriteria(1)); Assert.assertNotNull(serviceNode); Assert.assertEquals("localhost-1", serviceNode.getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java index c34ea1af..38e23cd7 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java @@ -16,7 +16,7 @@ public class FilterShardSelectorTest { public void testNoOpShardSelector(){ final ListBasedServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); final FilterShardSelector shardSelector = new FilterShardSelector<>(); - final List> nodes = shardSelector.nodes(CriteriaUtils.getUnshardedCriteria(1), serviceRegistry); + final List> nodes = shardSelector.nodes(CriteriaUtils.getFilterCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index f70ae409..504e3eb7 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.utils; import com.flipkart.ranger.core.model.ShardedCriteria; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.core.units.TestNodeData; public class CriteriaUtils { @@ -10,7 +10,7 @@ public static ShardedCriteria getShardedCriteria(int shardId){ return () -> TestNodeData.builder().nodeId(shardId).build(); } - public static UnshardedCriteria getUnshardedCriteria(int shardId){ + public static FilterCriteria getFilterCriteria(int shardId){ return nodeData -> nodeData.getNodeId() == shardId; } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index ed33cbc0..d02d448c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -5,11 +5,11 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; -public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, UnshardedCriteria> { +public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, FilterCriteria> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 6762a0c1..4d82b958 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -7,7 +7,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinder.HttpUnshardedServiceFinderBuilider; @@ -16,12 +16,12 @@ import lombok.val; @Getter -public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, UnshardedCriteria> { +public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, FilterCriteria> { private final HttpClientConfig clientConfig; private final ObjectMapper mapper; private final HTTPResponseDataDeserializer deserializer; - private final ShardSelector, UnshardedCriteria> shardSelector; + private final ShardSelector, FilterCriteria> shardSelector; private final ServiceNodeSelector nodeSelector; private final int nodeRefreshIntervalMs; @@ -30,7 +30,7 @@ public HttpUnshardedServiceFinderFactory( HttpClientConfig httpClientConfig, ObjectMapper mapper, HTTPResponseDataDeserializer deserializer, - ShardSelector, UnshardedCriteria> shardSelector, + ShardSelector, FilterCriteria> shardSelector, ServiceNodeSelector nodeSelector, int nodeRefreshIntervalMs) { @@ -43,7 +43,7 @@ public HttpUnshardedServiceFinderFactory( } @Override - public ServiceFinder, UnshardedCriteria> buildFinder(Service service) { + public ServiceFinder, FilterCriteria> buildFinder(Service service) { val serviceFinder = new HttpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) .withObjectMapper(mapper) diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index a9a70958..38fdfa10 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -4,7 +4,7 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -21,7 +21,7 @@ * */ @Slf4j -public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, UnshardedCriteria> { +public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, FilterCriteria> { private CuratorFramework curatorFramework; private String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index f424840a..84df8f35 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -6,7 +6,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; import lombok.Builder; @@ -16,14 +16,14 @@ @Getter -public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, UnshardedCriteria>{ +public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, FilterCriteria>{ private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, UnshardedCriteria> shardSelector; + private final ShardSelector, FilterCriteria> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -33,7 +33,7 @@ public ZKUnshardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, UnshardedCriteria> shardSelector, + ShardSelector, FilterCriteria> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 9006f779..68d9253b 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -25,7 +25,7 @@ import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -112,7 +112,7 @@ public void testBasicDiscovery() throws Exception { boolean filecreate = file.createNewFile(); System.out.println("created file"); TestUtils.sleepForSeconds(8); - List> all = serviceFinder.getAll((UnshardedCriteria) nodeData -> true); + List> all = serviceFinder.getAll((FilterCriteria) nodeData -> true); System.out.println("all = " + all); Assert.assertEquals(3, all.size()); @@ -120,7 +120,7 @@ public void testBasicDiscovery() throws Exception { delete = file.delete(); System.out.println("deleted file"); TestUtils.sleepForSeconds(8); - all = serviceFinder.getAll(new UnshardedCriteria() { + all = serviceFinder.getAll(new FilterCriteria() { @Override public boolean apply(Object nodeData) { return true; @@ -133,7 +133,7 @@ public boolean apply(Object nodeData) { filecreate = anotherFile.createNewFile(); System.out.println("created anotherFile"); TestUtils.sleepForSeconds(6); - all = serviceFinder.getAll(new UnshardedCriteria() { + all = serviceFinder.getAll(new FilterCriteria() { @Override public boolean apply(Object nodeData) { return true; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index d9f9c8fa..21c6d70c 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -22,7 +22,7 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.UnshardedCriteria; +import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.google.common.collect.HashMultiset; @@ -99,7 +99,7 @@ public void testBasicDiscovery() { long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(new UnshardedCriteria() { + ServiceNode node = serviceFinder.get(new FilterCriteria() { @Override public boolean apply(UnshardedInfo nodeData) { return true; From 37f5f8e82cab19b8040888ff0b25acfd1cd3f551 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Thu, 14 Oct 2021 16:55:22 +0530 Subject: [PATCH 31/53] Normalized criteria into a single interface --- .../finder/SimpleShardedServiceFinder.java | 6 +++--- .../SimpleShardedServiceFinderBuilder.java | 6 +++--- .../finder/SimpleUnshardedServiceFinder.java | 6 +++--- .../SimpleUnshardedServiceFinderBuilder.java | 10 +++++----- ...rdSelector.java => ListShardSelector.java} | 6 +++--- .../shardselector/MatchingShardSelector.java | 20 ++++++++++++------- .../shardselector/NoopShardSelector.java | 7 ++++--- .../flipkart/ranger/core/model/Criteria.java | 3 ++- .../ranger/core/model/FilterCriteria.java | 8 -------- .../ranger/core/model/ShardedCriteria.java | 8 -------- .../core/finder/SimpleShardFinderTest.java | 8 ++++---- .../finder/UnshardedClusterFinderTest.java | 6 +++--- .../MapBasedServiceRegistryTest.java | 2 +- ...orTest.java => ListShardSelectorTest.java} | 6 +++--- .../MatchingShardSelectorTest.java | 2 +- .../ranger/core/utils/CriteriaUtils.java | 11 +++------- .../HttpShardedServiceFinderBuilder.java | 4 ++-- .../HttpUnshardedServiceFinderBuilider.java | 4 ++-- .../HttpUnshardedServiceFinderFactory.java | 10 +++++----- .../HttpShardedServiceFinderBuilderTest.java | 4 ++-- .../ZkSimpleShardedServiceFinderBuilder.java | 4 ++-- ...ZkSimpleUnshardedServiceFinderBuilder.java | 4 ++-- .../ZKUnshardedServiceFinderFactory.java | 8 ++++---- .../ZkShardedServiceFinderFactory.java | 8 ++++---- .../ServiceProviderIntegrationTest.java | 18 ++++------------- .../model/CustomShardSelectorTest.java | 12 +++++------ .../model/ServiceNoProviderTest.java | 6 +++--- .../model/ServiceProviderExtCuratorTest.java | 7 ++++--- .../model/ServiceProviderHealthcheckTest.java | 7 +++---- .../zookeeper/model/ServiceProviderTest.java | 6 +++--- .../model/SimpleServiceProviderTest.java | 9 ++------- .../zookeeper/servicehub/ServiceHubTest.java | 6 +++--- 32 files changed, 102 insertions(+), 130 deletions(-) rename ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/{FilterShardSelector.java => ListShardSelector.java} (65%) delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java delete mode 100644 ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java rename ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/{FilterShardSelectorTest.java => ListShardSelectorTest.java} (79%) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index 39cbdc56..e6931ad4 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -17,13 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.ShardedCriteria; -public class SimpleShardedServiceFinder extends ServiceFinder, ShardedCriteria> { +public class SimpleShardedServiceFinder extends ServiceFinder, Criteria> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, - ShardSelector, ShardedCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index 86456189..e095a6e2 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -20,13 +20,13 @@ import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; import com.flipkart.ranger.core.model.*; -public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends ShardedCriteria> - extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, ShardedCriteria> { +public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> + extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, Criteria> { @Override protected SimpleShardedServiceFinder buildFinder( Service service, - ShardSelector, ShardedCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index 8dc6fb56..25e51f45 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -17,13 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.FilterCriteria; -public class SimpleUnshardedServiceFinder extends ServiceFinder, FilterCriteria> { +public class SimpleUnshardedServiceFinder extends ServiceFinder, Criteria> { public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, - ShardSelector, FilterCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index e2053a08..a598ce41 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -17,20 +17,20 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.FilterShardSelector; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.model.*; -public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends FilterCriteria> - extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, FilterCriteria> { +public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> + extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, Criteria> { @Override protected SimpleUnshardedServiceFinder buildFinder( Service service, - ShardSelector, FilterCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { - shardSelector = new FilterShardSelector<>(); + shardSelector = new ListShardSelector<>(); } final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java similarity index 65% rename from ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java rename to ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 917e3b3d..92731406 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -1,17 +1,17 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.FilterCriteria; import java.util.List; import java.util.stream.Collectors; -public class FilterShardSelector implements ShardSelector, FilterCriteria> { +public class ListShardSelector implements ShardSelector, Criteria> { @Override - public List> nodes(FilterCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, ListBasedServiceRegistry serviceRegistry) { if(null == criteria){ return serviceRegistry.nodeList(); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 52d9ecc8..0551b96f 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -17,20 +17,26 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.google.common.base.Preconditions; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; + +public class MatchingShardSelector implements ShardSelector, Criteria> { -public class MatchingShardSelector implements ShardSelector, ShardedCriteria> { @Override - public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { Preconditions.checkNotNull(criteria, "Criteria can't be null"); - return serviceRegistry.nodes().get(criteria.getShard()); - } - + return serviceRegistry.nodes() + .entries() + .stream() + .filter(e -> criteria.apply(e.getKey())) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); + } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 4c00420a..3f3a7184 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -1,15 +1,16 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.FilterCriteria; import java.util.List; -public class NoopShardSelector implements ShardSelector, FilterCriteria> { +public class NoopShardSelector implements ShardSelector, Criteria> { + @Override - public List> nodes(FilterCriteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodeList(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index 70ecbdea..83c31ff8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -1,5 +1,6 @@ package com.flipkart.ranger.core.model; +@FunctionalInterface public interface Criteria { - + boolean apply(T nodeData); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java deleted file mode 100644 index 43f739ac..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/FilterCriteria.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.flipkart.ranger.core.model; - -@FunctionalInterface -public interface FilterCriteria extends Criteria { - - boolean apply(T nodeData); - -} diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java deleted file mode 100644 index 13d09f0a..00000000 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardedCriteria.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.flipkart.ranger.core.model; - -@FunctionalInterface -public interface ShardedCriteria extends Criteria { - - T getShard(); - -} diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 238daab7..09a961be 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -2,9 +2,9 @@ import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; @@ -17,10 +17,10 @@ public class SimpleShardFinderTest { - static class TestSimpleShardSelector implements ShardSelector, ShardedCriteria>{ + static class TestSimpleShardSelector implements ShardSelector, Criteria>{ @Override - public List> nodes(ShardedCriteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { return Lists.newArrayList(); } } @@ -33,7 +33,7 @@ public void testSimpleShardedFinder(){ val simpleShardedFinder = new SimpleShardedServiceFinder( serviceRegistry, shardSelector, roundRobinServiceNodeSelector); val testNodeDataServiceNode = simpleShardedFinder.get( - CriteriaUtils.getShardedCriteria(2)); + CriteriaUtils.getCriteria(2)); Assert.assertNull(testNodeDataServiceNode); } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index c9e43a0b..3f5b73da 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,7 +1,7 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.FilterShardSelector; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.units.TestNodeData; @@ -24,13 +24,13 @@ public ServiceNode select(List> serviceN @Test public void unshardedClusterFinder(){ final ListBasedServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); - final FilterShardSelector shardSelector = new FilterShardSelector<>(); + final ListShardSelector shardSelector = new ListShardSelector<>(); SimpleUnshardedServiceFinder simpleUnshardedServiceFinder = new SimpleUnshardedServiceFinder( unshardedRegistry, shardSelector, new TestUnshardedNodeSelector() ); - final ServiceNode serviceNode = simpleUnshardedServiceFinder.get(CriteriaUtils.getFilterCriteria(1)); + final ServiceNode serviceNode = simpleUnshardedServiceFinder.get(CriteriaUtils.getCriteria(1)); Assert.assertNotNull(serviceNode); Assert.assertEquals("localhost-1", serviceNode.getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index 6f60d275..073b8202 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -16,7 +16,7 @@ public void testMapBasedServiceRegistryWithMatchingShardSelector(){ Assert.assertTrue(null != serviceRegistry.nodes() && !serviceRegistry.nodes().isEmpty()); final MatchingShardSelector matchingShardSelector = new MatchingShardSelector<>(); val nodes = matchingShardSelector.nodes( - CriteriaUtils.getShardedCriteria(1), serviceRegistry); + CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java similarity index 79% rename from ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java rename to ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java index 38e23cd7..9c469af2 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/FilterShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java @@ -10,13 +10,13 @@ import java.util.List; -public class FilterShardSelectorTest { +public class ListShardSelectorTest { @Test public void testNoOpShardSelector(){ final ListBasedServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); - final FilterShardSelector shardSelector = new FilterShardSelector<>(); - final List> nodes = shardSelector.nodes(CriteriaUtils.getFilterCriteria(1), serviceRegistry); + final ListShardSelector shardSelector = new ListShardSelector<>(); + final List> nodes = shardSelector.nodes(CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index 47b91948..0fc3702e 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -17,7 +17,7 @@ public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); final List> nodes = shardSelector.nodes( - CriteriaUtils.getShardedCriteria(1), serviceRegistry); + CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index 504e3eb7..d16eb56b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,16 +1,11 @@ package com.flipkart.ranger.core.utils; -import com.flipkart.ranger.core.model.ShardedCriteria; -import com.flipkart.ranger.core.model.FilterCriteria; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.units.TestNodeData; public class CriteriaUtils { - - public static ShardedCriteria getShardedCriteria(int shardId){ - return () -> TestNodeData.builder().nodeId(shardId).build(); - } - - public static FilterCriteria getFilterCriteria(int shardId){ + + public static Criteria getCriteria(int shardId){ return nodeData -> nodeData.getNodeId() == shardId; } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index c01c8dc3..b1ec0cb4 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -3,16 +3,16 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; /** * */ -public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, ShardedCriteria> { +public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index d02d448c..96d8a40c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -3,13 +3,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; -public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, FilterCriteria> { +public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 4d82b958..02e2defe 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -4,10 +4,10 @@ import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinder.HttpUnshardedServiceFinderBuilider; @@ -16,12 +16,12 @@ import lombok.val; @Getter -public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, FilterCriteria> { +public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { private final HttpClientConfig clientConfig; private final ObjectMapper mapper; private final HTTPResponseDataDeserializer deserializer; - private final ShardSelector, FilterCriteria> shardSelector; + private final ShardSelector, Criteria> shardSelector; private final ServiceNodeSelector nodeSelector; private final int nodeRefreshIntervalMs; @@ -30,7 +30,7 @@ public HttpUnshardedServiceFinderFactory( HttpClientConfig httpClientConfig, ObjectMapper mapper, HTTPResponseDataDeserializer deserializer, - ShardSelector, FilterCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector, int nodeRefreshIntervalMs) { @@ -43,7 +43,7 @@ public HttpUnshardedServiceFinderFactory( } @Override - public ServiceFinder, FilterCriteria> buildFinder(Service service) { + public ServiceFinder, Criteria> buildFinder(Service service) { val serviceFinder = new HttpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) .withObjectMapper(mapper) diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index be594fac..52d1da45 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -80,13 +80,13 @@ public void testFinder() throws Exception { .nodes() .entries() .stream() - .filter(e -> e.getKey().getName().equals(criteria.getShard().getName())) + .filter(e -> criteria.apply(e.getKey())) .map(Map.Entry::getValue) .collect(Collectors.toList())) .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(() -> testNode)); + Assert.assertNotNull(finder.get(nodeData -> true)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index f66bb5eb..ee102818 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -2,9 +2,9 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -21,7 +21,7 @@ * */ @Slf4j -public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, ShardedCriteria> { +public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { protected CuratorFramework curatorFramework; protected String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index 38fdfa10..ed47bb3c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -2,9 +2,9 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.core.signals.Signal; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.signals.ZkWatcherRegistryUpdateSignal; @@ -21,7 +21,7 @@ * */ @Slf4j -public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, FilterCriteria> { +public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { private CuratorFramework curatorFramework; private String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 84df8f35..78cc65db 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -3,10 +3,10 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; import lombok.Builder; @@ -16,14 +16,14 @@ @Getter -public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, FilterCriteria>{ +public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, Criteria>{ private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, FilterCriteria> shardSelector; + private final ShardSelector, Criteria> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -33,7 +33,7 @@ public ZKUnshardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, FilterCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index f11f0594..36ae667f 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -3,10 +3,10 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; import lombok.Builder; @@ -16,13 +16,13 @@ /** * */ -public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, ShardedCriteria> { +public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, ShardedCriteria> shardSelector; + private final ShardSelector, Criteria> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -32,7 +32,7 @@ public ZkShardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, ShardedCriteria> shardSelector, + ShardSelector, Criteria> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 68d9253b..2b2d271c 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -24,8 +24,8 @@ import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -112,7 +112,7 @@ public void testBasicDiscovery() throws Exception { boolean filecreate = file.createNewFile(); System.out.println("created file"); TestUtils.sleepForSeconds(8); - List> all = serviceFinder.getAll((FilterCriteria) nodeData -> true); + List> all = serviceFinder.getAll(nodeData -> true); System.out.println("all = " + all); Assert.assertEquals(3, all.size()); @@ -120,12 +120,7 @@ public void testBasicDiscovery() throws Exception { delete = file.delete(); System.out.println("deleted file"); TestUtils.sleepForSeconds(8); - all = serviceFinder.getAll(new FilterCriteria() { - @Override - public boolean apply(Object nodeData) { - return true; - } - }); + all = serviceFinder.getAll(nodeData -> true); System.out.println("all = " + all); Assert.assertEquals(0, all.size()); @@ -133,12 +128,7 @@ public boolean apply(Object nodeData) { filecreate = anotherFile.createNewFile(); System.out.println("created anotherFile"); TestUtils.sleepForSeconds(6); - all = serviceFinder.getAll(new FilterCriteria() { - @Override - public boolean apply(Object nodeData) { - return true; - } - }); + all = serviceFinder.getAll(nodeData -> true); System.out.println("all = " + all); Assert.assertEquals(1, all.size()); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index e2cc6663..9a45ad72 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -22,9 +22,9 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -114,22 +114,22 @@ public int hashCode() { return result; } - private static ShardedCriteria getCriteria(int a, int b){ - return () -> new TestShardInfo(a, b); + private static Criteria getCriteria(int a, int b){ + return nodeData -> nodeData.getA() == a && nodeData.getB() == b; } } - private static final class TestShardSelector implements ShardSelector, ShardedCriteria> { + private static final class TestShardSelector implements ShardSelector, Criteria> { @Override public List> nodes( - ShardedCriteria criteria, + Criteria criteria, MapBasedServiceRegistry serviceRegistry ) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); - if((shardInfo.getA() + shardInfo.getB()) == (criteria.getShard().getA() + criteria.getShard().getB())) { + if(criteria.apply(shardInfo)) { nodes.add(entry.getValue()); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 47da9f54..cd1177b0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -20,8 +20,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; import org.apache.curator.test.TestingCluster; @@ -95,8 +95,8 @@ public int hashCode() { return shardId; } - private static ShardedCriteria getCriteria(int shardId){ - return () -> new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index cf025279..367a5e1e 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -21,8 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -110,9 +110,10 @@ public int hashCode() { return shardId; } - private static ShardedCriteria getCriteria(int shardId){ - return () -> new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } + } @Test diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index acb05e5a..cc8bd959 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -23,8 +23,8 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -97,9 +97,8 @@ public int hashCode() { return shardId; } - private static ShardedCriteria getCriteria(int shardId){ - return () -> new - TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index df55123a..28c727b0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -22,8 +22,8 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -108,8 +108,8 @@ public int hashCode() { return shardId; } - private static ShardedCriteria getCriteria(int shardId){ - return () -> new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 21c6d70c..e5625fb8 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -21,8 +21,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.FilterCriteria; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import com.google.common.collect.HashMultiset; @@ -99,12 +99,7 @@ public void testBasicDiscovery() { long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(new FilterCriteria() { - @Override - public boolean apply(UnshardedInfo nodeData) { - return true; - } - }); + ServiceNode node = serviceFinder.get(nodeData -> true); Assert.assertNotNull(node); frequency.add(node.getHost()); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index d90e71da..6f342875 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -7,9 +7,9 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ShardedCriteria; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -71,7 +71,7 @@ public void stopTestCluster() throws Exception { @Test public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); - val hub = new ZkServiceFinderHubBuilder, ShardedCriteria>() + val hub = new ZkServiceFinderHubBuilder, Criteria>() .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) @@ -107,7 +107,7 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(() -> new TestShardInfo("prod"))) + .map(finder -> finder.get(nodeData -> nodeData.getEnvironment().equalsIgnoreCase("prod"))) .orElse(null); Assert.assertNotNull(node); hub.stop(); From 0e3d7a5c2ced560fe6de12adcc73cbff9a041445 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Fri, 15 Oct 2021 18:46:31 +0530 Subject: [PATCH 32/53] Added curator to datasource --- .../servicefinderhub/ZkServiceDataSource.java | 29 ++++++++++++------- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 2d1ad935..a67d8589 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -19,12 +19,16 @@ public class ZkServiceDataSource implements ServiceDataSource { private final String namespace; - private final String connectionString; + private String connectionString; private CuratorFramework curatorFramework; + private boolean manageCurator; - public ZkServiceDataSource(String namespace, String connectionString){ + public ZkServiceDataSource(String namespace, + String connectionString, + CuratorFramework curatorFramework){ this.namespace = namespace; this.connectionString = connectionString; + this.curatorFramework = curatorFramework; } @Override @@ -38,14 +42,17 @@ public Collection services() throws Exception { @Override public void start() { - Preconditions.checkNotNull(connectionString); - log.info("Building custom curator framework"); - curatorFramework = CuratorFrameworkFactory.builder() - .namespace(namespace) - .connectString(connectionString) - .retryPolicy(new ExponentialBackoffRetry(1000, 100)) - .build(); - curatorFramework.start(); + if(null == curatorFramework){ + Preconditions.checkNotNull(connectionString); + log.info("Building custom curator framework"); + curatorFramework = CuratorFrameworkFactory.builder() + .namespace(namespace) + .connectString(connectionString) + .retryPolicy(new ExponentialBackoffRetry(1000, 100)) + .build(); + curatorFramework.start(); + manageCurator = true; + } try { curatorFramework.blockUntilConnected(); } @@ -58,7 +65,7 @@ public void start() { @Override public void stop() { log.info("Service data stopped"); - curatorFramework.close(); + if(manageCurator) curatorFramework.close(); log.info("Service data source stopped"); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 6f342875..351d7c98 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -75,7 +75,7 @@ public void testHub() { .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) - .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString())) + .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString(), curatorFramework)) .withServiceFinderFactory(ZkShardedServiceFinderFactory.builder() .curatorFramework(curatorFramework) .deserializer(this::read) From 831863e60e3fd13a8a62b071ea4c4e3511f38490 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sat, 16 Oct 2021 11:35:21 +0530 Subject: [PATCH 33/53] Changed matching selector to support a missing criteria --- .../core/finder/shardselector/MatchingShardSelector.java | 4 +++- .../com/flipkart/ranger/http/HttpServiceFinderBuilders.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 0551b96f..3d7b6d4b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -30,7 +30,9 @@ public class MatchingShardSelector implements ShardSelector> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { - Preconditions.checkNotNull(criteria, "Criteria can't be null"); + if(criteria == null){ + return serviceRegistry.nodeList(); + } return serviceRegistry.nodes() .entries() diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java index c50cfe95..97a2db63 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.http; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; +import com.flipkart.ranger.http.servicefinder.HttpUnshardedServiceFinderBuilider; public class HttpServiceFinderBuilders { @@ -12,4 +13,7 @@ public static HttpShardedServiceFinderBuilder httpShardedServiceFinderBui return new HttpShardedServiceFinderBuilder<>(); } + public static HttpUnshardedServiceFinderBuilider httpUnshardedServiceFinderBuilider(){ + return new HttpUnshardedServiceFinderBuilider<>(); + } } From fc21d46cf317c8a07528307080deb9486a125e02 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sat, 16 Oct 2021 18:30:54 +0530 Subject: [PATCH 34/53] Committing locally to save stash --- .../core/finder/BaseServiceFinderBuilder.java | 13 ++++++------ .../ranger/core/finder/ServiceFinder.java | 15 +++++++------ .../finder/SimpleShardedServiceFinder.java | 5 ++--- .../SimpleShardedServiceFinderBuilder.java | 11 ++++++---- .../finder/SimpleUnshardedServiceFinder.java | 5 ++--- .../SimpleUnshardedServiceFinderBuilder.java | 11 ++++++---- .../shardselector/ListShardSelector.java | 8 +++---- .../shardselector/MatchingShardSelector.java | 16 ++++---------- .../shardselector/NoopShardSelector.java | 5 ++--- .../core/finderhub/ServiceFinderFactory.java | 5 ++--- .../core/finderhub/ServiceFinderHub.java | 15 +++++++------ .../finderhub/ServiceFinderHubBuilder.java | 21 +++++++++---------- .../flipkart/ranger/core/model/Criteria.java | 2 ++ .../ranger/core/model/ShardSelector.java | 4 ++-- .../core/finder/SimpleShardFinderTest.java | 5 ++--- .../ranger/core/units/TestNodeData.java | 2 ++ .../ranger/core/utils/CriteriaUtils.java | 5 ++--- .../HttpShardedServiceFinderBuilder.java | 4 +--- .../HttpUnshardedServiceFinderBuilider.java | 3 +-- .../HttpServiceFinderHubBuilder.java | 5 ++--- .../HttpUnshardedServiceFinderFactory.java | 9 ++++---- .../HttpShardedServiceFinderBuilderTest.java | 3 +-- .../ZkSimpleShardedServiceFinderBuilder.java | 3 +-- ...ZkSimpleUnshardedServiceFinderBuilder.java | 3 +-- .../ZKUnshardedServiceFinderFactory.java | 7 +++---- .../ZkServiceFinderHubBuilder.java | 11 +++++----- .../ZkShardedServiceFinderFactory.java | 7 +++---- .../ServiceProviderIntegrationTest.java | 7 +++---- .../model/CustomShardSelectorTest.java | 14 +++++-------- .../model/ServiceNoProviderTest.java | 5 ++--- .../model/ServiceProviderExtCuratorTest.java | 5 ++--- .../model/ServiceProviderHealthcheckTest.java | 5 ++--- .../zookeeper/model/ServiceProviderTest.java | 5 ++--- .../model/SimpleServiceProviderTest.java | 5 ++--- .../zookeeper/servicehub/ServiceHubTest.java | 5 ++--- 35 files changed, 114 insertions(+), 140 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 44976559..4323bc53 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -37,17 +37,16 @@ public abstract class BaseServiceFinderBuilder < T, R extends ServiceRegistry, - F extends ServiceFinder, - B extends BaseServiceFinderBuilder, - D extends Deserializer, - U extends Criteria> { + F extends ServiceFinder, + B extends BaseServiceFinderBuilder, + D extends Deserializer> { protected String namespace; protected String serviceName; protected int nodeRefreshIntervalMs; protected boolean disablePushUpdaters; protected D deserializer; - protected ShardSelector shardSelector; + protected ShardSelector shardSelector; protected ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>(); protected final List> additionalRefreshSignals = new ArrayList<>(); protected final List> startSignalHandlers = Lists.newArrayList(); @@ -68,7 +67,7 @@ public B withDeserializer(D deserializer) { return (B)this; } - public B withShardSelector(ShardSelector shardSelector) { + public B withShardSelector(ShardSelector shardSelector) { this.shardSelector = shardSelector; return (B)this; } @@ -176,7 +175,7 @@ protected List> implementationSpecificRefreshSignals(Service service, protected abstract F buildFinder( Service service, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index da37642c..36a1e089 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -16,7 +16,10 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ServiceRegistry; +import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -25,10 +28,10 @@ import java.util.List; @Slf4j -public abstract class ServiceFinder, U extends Criteria> { +public abstract class ServiceFinder> { @Getter private final ServiceRegistryType serviceRegistry; - private final ShardSelector shardSelector; + private final ShardSelector shardSelector; private final ServiceNodeSelector nodeSelector; @Getter private final ExternalTriggeredSignal startSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); @@ -37,14 +40,14 @@ public abstract class ServiceFinder shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { this.serviceRegistry = serviceRegistry; this.shardSelector = shardSelector; this.nodeSelector = nodeSelector; } - public ServiceNode get(U criteria) { + public ServiceNode get(T criteria) { List> nodes = shardSelector.nodes(criteria, serviceRegistry); if (null == nodes || nodes.isEmpty()) { return null; @@ -52,7 +55,7 @@ public ServiceNode get(U criteria) { return nodeSelector.select(nodes); } - public List> getAll(U criteria) { + public List> getAll(T criteria) { return shardSelector.nodes(criteria, serviceRegistry); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index e6931ad4..2ac130d5 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -17,13 +17,12 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -public class SimpleShardedServiceFinder extends ServiceFinder, Criteria> { +public class SimpleShardedServiceFinder extends ServiceFinder> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index e095a6e2..7349047b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -18,15 +18,18 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.Deserializer; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; -public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> - extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, Criteria> { +public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer> + extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D> { @Override protected SimpleShardedServiceFinder buildFinder( Service service, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index 25e51f45..d4923409 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -17,13 +17,12 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -public class SimpleUnshardedServiceFinder extends ServiceFinder, Criteria> { +public class SimpleUnshardedServiceFinder extends ServiceFinder> { public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index a598ce41..35ca94d1 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -18,15 +18,18 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.Deserializer; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; -public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, U extends Criteria> - extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, Criteria> { +public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer> + extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D> { @Override protected SimpleUnshardedServiceFinder buildFinder( Service service, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 92731406..0b56bf74 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -1,20 +1,20 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; import java.util.stream.Collectors; -public class ListShardSelector implements ShardSelector, Criteria> { +public class ListShardSelector implements ShardSelector> { @Override - public List> nodes(Criteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(T criteria, ListBasedServiceRegistry serviceRegistry) { if(null == criteria){ return serviceRegistry.nodeList(); } - return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList()); + return serviceRegistry.nodeList().stream().filter(node -> criteria.equals(node.getNodeData())).collect(Collectors.toList()); } + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 3d7b6d4b..4c806c9e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -17,28 +17,20 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.google.common.base.Preconditions; -import java.util.*; -import java.util.stream.Collectors; +import java.util.List; -public class MatchingShardSelector implements ShardSelector, Criteria> { +public class MatchingShardSelector implements ShardSelector> { @Override - public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { if(criteria == null){ return serviceRegistry.nodeList(); } - return serviceRegistry.nodes() - .entries() - .stream() - .filter(e -> criteria.apply(e.getKey())) - .map(Map.Entry::getValue) - .collect(Collectors.toList()); + return serviceRegistry.nodes().get(criteria); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 3f3a7184..032ee645 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -1,16 +1,15 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; -public class NoopShardSelector implements ShardSelector, Criteria> { +public class NoopShardSelector implements ShardSelector> { @Override - public List> nodes(Criteria criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(T criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodeList(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 0d392469..f78b8011 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -1,15 +1,14 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; /** * */ -public interface ServiceFinderFactory, U extends Criteria> { +public interface ServiceFinderFactory> { - ServiceFinder buildFinder(final Service service); + ServiceFinder buildFinder(final Service service); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index eadb23e3..aceeb761 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -1,7 +1,6 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; @@ -27,8 +26,8 @@ * */ @Slf4j -public class ServiceFinderHub, U extends Criteria> { - private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); +public class ServiceFinderHub> { + private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; @@ -44,14 +43,14 @@ public class ServiceFinderHub, U extends Criteri private final List> refreshSignals = new ArrayList<>(); private final ServiceDataSource serviceDataSource; - private final ServiceFinderFactory finderFactory; + private final ServiceFinderFactory finderFactory; private AtomicBoolean alreadyUpdating = new AtomicBoolean(false); private Future monitorFuture = null; public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory) { + ServiceFinderFactory finderFactory) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", @@ -60,7 +59,7 @@ public ServiceFinderHub( 10_000)); } - public Optional> finder(final Service service) { + public Optional> finder(final Service service) { return Optional.ofNullable(finders.get().get(service)); } @@ -127,10 +126,10 @@ private void updateRegistry() { return; } alreadyUpdating.set(true); - final Map> updatedFinders = new HashMap<>(); + final Map> updatedFinders = new HashMap<>(); try { final Collection services = serviceDataSource.services(); - final Map> knownServiceFinders = finders.get(); + final Map> knownServiceFinders = finders.get(); val newFinders = services.stream() .filter(service -> !knownServiceFinders.containsKey(service)) .collect(Collectors.toMap(Function.identity(), finderFactory::buildFinder)); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 99ed93bf..2fdd5824 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,6 +1,5 @@ package com.flipkart.ranger.core.finderhub; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ScheduledSignal; import com.flipkart.ranger.core.signals.Signal; @@ -15,45 +14,45 @@ /** * */ -public abstract class ServiceFinderHubBuilder, U extends Criteria> { +public abstract class ServiceFinderHubBuilder> { private ServiceDataSource serviceDataSource; - private ServiceFinderFactory serviceFinderFactory; + private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; private List> extraStartSignalConsumers = new ArrayList<>(); private List> extraStopSignalConsumers = new ArrayList<>(); private List> extraRefreshSignals = new ArrayList<>(); - public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { + public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { this.serviceDataSource = serviceDataSource; return this; } - public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { + public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { this.serviceFinderFactory = serviceFinderFactory; return this; } - public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; } - public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { this.extraStartSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { this.extraStopSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { + public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { this.extraRefreshSignals.add(extraRefreshSignal); return this; } - public ServiceFinderHub build() { + public ServiceFinderHub build() { preBuild(); Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); @@ -79,5 +78,5 @@ public ServiceFinderHub build() { } protected abstract void preBuild(); - protected abstract void postBuild(ServiceFinderHub serviceFinderHub); + protected abstract void postBuild(ServiceFinderHub serviceFinderHub); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index 83c31ff8..1cc72b62 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -2,5 +2,7 @@ @FunctionalInterface public interface Criteria { + boolean apply(T nodeData); + } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index e77c59d1..e6ada2ee 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -18,8 +18,8 @@ import java.util.List; -public interface ShardSelector, U extends Criteria> { +public interface ShardSelector> { - List> nodes(U criteria, ServiceRegistryType serviceRegistry); + List> nodes(T criteria, ServiceRegistryType serviceRegistry); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 09a961be..c27b496e 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.units.TestNodeData; @@ -17,10 +16,10 @@ public class SimpleShardFinderTest { - static class TestSimpleShardSelector implements ShardSelector, Criteria>{ + static class TestSimpleShardSelector implements ShardSelector>{ @Override - public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { return Lists.newArrayList(); } } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java index 059599c0..024de9b0 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java @@ -1,9 +1,11 @@ package com.flipkart.ranger.core.units; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @Data +@AllArgsConstructor @Builder public class TestNodeData { private int nodeId; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index d16eb56b..321e9df2 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,11 +1,10 @@ package com.flipkart.ranger.core.utils; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.units.TestNodeData; public class CriteriaUtils { - public static Criteria getCriteria(int shardId){ - return nodeData -> nodeData.getNodeId() == shardId; + public static TestNodeData getCriteria(int shardId){ + return new TestNodeData(shardId); } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index b1ec0cb4..41839464 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; @@ -12,7 +11,7 @@ /** * */ -public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { +public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer> { private HttpClientConfig clientConfig; private ObjectMapper mapper; @@ -37,5 +36,4 @@ protected NodeDataSource> dataSource(Service return new HttpNodeDataSource<>(service, clientConfig, mapper); } - } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index 96d8a40c..a9c0bfff 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -3,13 +3,12 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; -public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, Criteria> { +public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer> { private HttpClientConfig clientConfig; private ObjectMapper mapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index 81f82ad4..cc3a343e 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -2,12 +2,11 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import lombok.extern.slf4j.Slf4j; @Slf4j -public class HttpServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { +public class HttpServiceFinderHubBuilder> extends ServiceFinderHubBuilder { @Override protected void preBuild() { @@ -15,7 +14,7 @@ protected void preBuild() { } @Override - protected void postBuild(ServiceFinderHub serviceFinderHub) { + protected void postBuild(ServiceFinderHub serviceFinderHub) { log.info("No post build actions necessary"); } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 02e2defe..8b43e701 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -4,7 +4,6 @@ import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -16,12 +15,12 @@ import lombok.val; @Getter -public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { +public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory> { private final HttpClientConfig clientConfig; private final ObjectMapper mapper; private final HTTPResponseDataDeserializer deserializer; - private final ShardSelector, Criteria> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; private final int nodeRefreshIntervalMs; @@ -30,7 +29,7 @@ public HttpUnshardedServiceFinderFactory( HttpClientConfig httpClientConfig, ObjectMapper mapper, HTTPResponseDataDeserializer deserializer, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector, int nodeRefreshIntervalMs) { @@ -43,7 +42,7 @@ public HttpUnshardedServiceFinderFactory( } @Override - public ServiceFinder, Criteria> buildFinder(Service service) { + public ServiceFinder> buildFinder(Service service) { val serviceFinder = new HttpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) .withObjectMapper(mapper) diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 52d1da45..c58f5937 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -80,13 +80,12 @@ public void testFinder() throws Exception { .nodes() .entries() .stream() - .filter(e -> criteria.apply(e.getKey())) .map(Map.Entry::getValue) .collect(Collectors.toList())) .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(nodeData -> true)); + Assert.assertNotNull(finder.get(testNode)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index ee102818..5f43e9fe 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; @@ -21,7 +20,7 @@ * */ @Slf4j -public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { +public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer> { protected CuratorFramework curatorFramework; protected String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index ed47bb3c..9d56354d 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; @@ -21,7 +20,7 @@ * */ @Slf4j -public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, Criteria> { +public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer> { private CuratorFramework curatorFramework; private String connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 78cc65db..222c9f86 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -3,7 +3,6 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -16,14 +15,14 @@ @Getter -public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory, Criteria>{ +public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory>{ private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, Criteria> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -33,7 +32,7 @@ public ZKUnshardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 142af36c..6ab9ebe7 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -2,7 +2,6 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; @@ -14,22 +13,22 @@ * */ @Slf4j -public class ZkServiceFinderHubBuilder, U extends Criteria> extends ServiceFinderHubBuilder { +public class ZkServiceFinderHubBuilder> extends ServiceFinderHubBuilder { private String namespace; private CuratorFramework curatorFramework; private String connectionString; - public ZkServiceFinderHubBuilder withNamespace(final String namespace) { + public ZkServiceFinderHubBuilder withNamespace(final String namespace) { this.namespace = namespace; return this; } - public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { + public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @@ -50,7 +49,7 @@ protected void preBuild() { } @Override - protected void postBuild(ServiceFinderHub serviceFinderHub) { + protected void postBuild(ServiceFinderHub serviceFinderHub) { log.debug("No post build steps necessary"); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 36ae667f..5df48337 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -3,7 +3,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -16,13 +15,13 @@ /** * */ -public class ZkShardedServiceFinderFactory implements ServiceFinderFactory, Criteria> { +public class ZkShardedServiceFinderFactory implements ServiceFinderFactory> { private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector, Criteria> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -32,7 +31,7 @@ public ZkShardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector, Criteria> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 2b2d271c..e98fe778 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -24,7 +24,6 @@ import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -112,7 +111,7 @@ public void testBasicDiscovery() throws Exception { boolean filecreate = file.createNewFile(); System.out.println("created file"); TestUtils.sleepForSeconds(8); - List> all = serviceFinder.getAll(nodeData -> true); + List> all = serviceFinder.getAll(null); System.out.println("all = " + all); Assert.assertEquals(3, all.size()); @@ -120,7 +119,7 @@ public void testBasicDiscovery() throws Exception { delete = file.delete(); System.out.println("deleted file"); TestUtils.sleepForSeconds(8); - all = serviceFinder.getAll(nodeData -> true); + all = serviceFinder.getAll(null); System.out.println("all = " + all); Assert.assertEquals(0, all.size()); @@ -128,7 +127,7 @@ public void testBasicDiscovery() throws Exception { filecreate = anotherFile.createNewFile(); System.out.println("created anotherFile"); TestUtils.sleepForSeconds(6); - all = serviceFinder.getAll(nodeData -> true); + all = serviceFinder.getAll(null); System.out.println("all = " + all); Assert.assertEquals(1, all.size()); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index 9a45ad72..ae1e23ab 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -22,7 +22,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; @@ -114,22 +113,19 @@ public int hashCode() { return result; } - private static Criteria getCriteria(int a, int b){ - return nodeData -> nodeData.getA() == a && nodeData.getB() == b; + private static TestShardInfo getCriteria(int a, int b){ + return new TestShardInfo(a, b); } } - private static final class TestShardSelector implements ShardSelector, Criteria> { + private static final class TestShardSelector implements ShardSelector> { @Override - public List> nodes( - Criteria criteria, - MapBasedServiceRegistry serviceRegistry - ) { + public List> nodes(TestShardInfo criteria, MapBasedServiceRegistry serviceRegistry) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); - if(criteria.apply(shardInfo)) { + if(criteria.equals(shardInfo)){ nodes.add(entry.getValue()); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index cd1177b0..92f67c0f 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -20,7 +20,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; @@ -95,8 +94,8 @@ public int hashCode() { return shardId; } - private static Criteria getCriteria(int shardId){ - return nodeData -> nodeData.getShardId() == shardId; + private static TestShardInfo getCriteria(int shardId){ + return new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index 367a5e1e..0e102ee9 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -110,8 +109,8 @@ public int hashCode() { return shardId; } - private static Criteria getCriteria(int shardId){ - return nodeData -> nodeData.getShardId() == shardId; + private static TestShardInfo getCriteria(int shardId){ + return new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index cc8bd959..5338536e 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -23,7 +23,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -97,8 +96,8 @@ public int hashCode() { return shardId; } - private static Criteria getCriteria(int shardId){ - return nodeData -> nodeData.getShardId() == shardId; + private static TestShardInfo getCriteria(int shardId){ + return new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 28c727b0..439ed373 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -22,7 +22,6 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -108,8 +107,8 @@ public int hashCode() { return shardId; } - private static Criteria getCriteria(int shardId){ - return nodeData -> nodeData.getShardId() == shardId; + private static TestShardInfo getCriteria(int shardId){ + return new TestShardInfo(shardId); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index e5625fb8..61dd42b1 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -91,7 +90,7 @@ public void testBasicDiscovery() { .build(); serviceFinder.start(); { - ServiceNode node = serviceFinder.get(nodeData -> true); + ServiceNode node = serviceFinder.get(null); Assert.assertNotNull(node); System.out.println(node.getHost()); } @@ -99,7 +98,7 @@ public void testBasicDiscovery() { long startTime = System.currentTimeMillis(); for(long i = 0; i <1000000; i++) { - ServiceNode node = serviceFinder.get(nodeData -> true); + ServiceNode node = serviceFinder.get(null); Assert.assertNotNull(node); frequency.add(node.getHost()); } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 351d7c98..6e6fd025 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -7,7 +7,6 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; -import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; @@ -71,7 +70,7 @@ public void stopTestCluster() throws Exception { @Test public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); - val hub = new ZkServiceFinderHubBuilder, Criteria>() + val hub = new ZkServiceFinderHubBuilder>() .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) @@ -107,7 +106,7 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(nodeData -> nodeData.getEnvironment().equalsIgnoreCase("prod"))) + .map(finder -> finder.get(new TestShardInfo("prod"))) .orElse(null); Assert.assertNotNull(node); hub.stop(); From ada0f6d7c0c63b359197b9f85731f0395a58f064 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sat, 16 Oct 2021 19:39:21 +0530 Subject: [PATCH 35/53] Criteria is now part of the parent closure --- .../core/finder/BaseServiceFinderBuilder.java | 13 ++++++----- .../ranger/core/finder/ServiceFinder.java | 15 +++++-------- .../finder/SimpleShardedServiceFinder.java | 5 +++-- .../SimpleShardedServiceFinderBuilder.java | 13 +++++------ .../finder/SimpleUnshardedServiceFinder.java | 5 +++-- .../SimpleUnshardedServiceFinderBuilder.java | 13 +++++------ .../shardselector/ListShardSelector.java | 8 +++---- .../shardselector/MatchingShardSelector.java | 21 +++++++++++------- .../shardselector/NoopShardSelector.java | 5 +++-- .../core/finderhub/ServiceFinderFactory.java | 5 +++-- .../core/finderhub/ServiceFinderHub.java | 15 +++++++------ .../finderhub/ServiceFinderHubBuilder.java | 22 ++++++++++--------- .../ranger/core/model/ShardSelector.java | 4 ++-- .../core/finder/SimpleShardFinderTest.java | 10 +++++---- .../finder/UnshardedClusterFinderTest.java | 5 +++-- .../MapBasedServiceRegistryTest.java | 3 ++- .../shardselector/ListShardSelectorTest.java | 3 ++- .../MatchingShardSelectorTest.java | 3 ++- .../ranger/core/utils/CriteriaUtils.java | 5 +++-- .../http/HttpServiceFinderBuilders.java | 5 +++-- .../HttpShardedServiceFinderBuilder.java | 9 ++++---- .../HttpUnshardedServiceFinderBuilider.java | 13 ++++++----- .../HttpServiceFinderHubBuilder.java | 5 +++-- .../HttpUnshardedServiceFinderFactory.java | 11 +++++----- .../HttpShardedServiceFinderBuilderTest.java | 13 +++++------ .../zookeeper/ServiceFinderBuilders.java | 5 +++-- .../ZkSimpleShardedServiceFinderBuilder.java | 9 ++++---- ...ZkSimpleUnshardedServiceFinderBuilder.java | 10 +++++---- .../ZKUnshardedServiceFinderFactory.java | 11 +++++----- .../ZkServiceFinderHubBuilder.java | 11 +++++----- .../ZkShardedServiceFinderFactory.java | 11 +++++----- .../model/CustomShardSelectorTest.java | 13 ++++++----- .../model/ServiceNoProviderTest.java | 7 +++--- .../model/ServiceProviderExtCuratorTest.java | 9 ++++---- .../model/ServiceProviderHealthcheckTest.java | 9 ++++---- .../zookeeper/model/ServiceProviderTest.java | 13 ++++++----- .../model/SimpleServiceProviderTest.java | 5 +++-- .../zookeeper/servicehub/ServiceHubTest.java | 7 +++--- 38 files changed, 188 insertions(+), 161 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 4323bc53..73e04fad 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -37,16 +37,17 @@ public abstract class BaseServiceFinderBuilder < T, R extends ServiceRegistry, - F extends ServiceFinder, - B extends BaseServiceFinderBuilder, - D extends Deserializer> { + F extends ServiceFinder, + B extends BaseServiceFinderBuilder, + D extends Deserializer, + C extends Criteria> { protected String namespace; protected String serviceName; protected int nodeRefreshIntervalMs; protected boolean disablePushUpdaters; protected D deserializer; - protected ShardSelector shardSelector; + protected ShardSelector shardSelector; protected ServiceNodeSelector nodeSelector = new RandomServiceNodeSelector<>(); protected final List> additionalRefreshSignals = new ArrayList<>(); protected final List> startSignalHandlers = Lists.newArrayList(); @@ -67,7 +68,7 @@ public B withDeserializer(D deserializer) { return (B)this; } - public B withShardSelector(ShardSelector shardSelector) { + public B withShardSelector(ShardSelector shardSelector) { this.shardSelector = shardSelector; return (B)this; } @@ -175,7 +176,7 @@ protected List> implementationSpecificRefreshSignals(Service service, protected abstract F buildFinder( Service service, - ShardSelector shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index 36a1e089..7a9a2194 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -16,10 +16,7 @@ package com.flipkart.ranger.core.finder; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ServiceRegistry; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -28,10 +25,10 @@ import java.util.List; @Slf4j -public abstract class ServiceFinder> { +public abstract class ServiceFinder, ServiceRegistryType extends ServiceRegistry> { @Getter private final ServiceRegistryType serviceRegistry; - private final ShardSelector shardSelector; + private final ShardSelector shardSelector; private final ServiceNodeSelector nodeSelector; @Getter private final ExternalTriggeredSignal startSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); @@ -40,14 +37,14 @@ public abstract class ServiceFinder shardSelector, + ShardSelector shardSelector, ServiceNodeSelector nodeSelector) { this.serviceRegistry = serviceRegistry; this.shardSelector = shardSelector; this.nodeSelector = nodeSelector; } - public ServiceNode get(T criteria) { + public ServiceNode get(C criteria) { List> nodes = shardSelector.nodes(criteria, serviceRegistry); if (null == nodes || nodes.isEmpty()) { return null; @@ -55,7 +52,7 @@ public ServiceNode get(T criteria) { return nodeSelector.select(nodes); } - public List> getAll(T criteria) { + public List> getAll(C criteria) { return shardSelector.nodes(criteria, serviceRegistry); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index 2ac130d5..c77c8d15 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -17,12 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -public class SimpleShardedServiceFinder extends ServiceFinder> { +public class SimpleShardedServiceFinder> extends ServiceFinder> { public SimpleShardedServiceFinder(MapBasedServiceRegistry serviceRegistry, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index 7349047b..30dc076a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -18,18 +18,15 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; -import com.flipkart.ranger.core.model.Deserializer; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; -public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer> - extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D> { +public abstract class SimpleShardedServiceFinderBuilder, D extends Deserializer, C extends Criteria> + extends BaseServiceFinderBuilder, SimpleShardedServiceFinder, B, D, C> { @Override - protected SimpleShardedServiceFinder buildFinder( + protected SimpleShardedServiceFinder buildFinder( Service service, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index d4923409..ba652efb 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -17,12 +17,13 @@ package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; -public class SimpleUnshardedServiceFinder extends ServiceFinder> { +public class SimpleUnshardedServiceFinder> extends ServiceFinder> { public SimpleUnshardedServiceFinder(ListBasedServiceRegistry serviceRegistry, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { super(serviceRegistry, shardSelector, nodeSelector); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index 35ca94d1..844bb912 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -18,18 +18,15 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; -import com.flipkart.ranger.core.model.Deserializer; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNodeSelector; -import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.core.model.*; -public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer> - extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D> { +public abstract class SimpleUnshardedServiceFinderBuilder, D extends Deserializer, C extends Criteria> + extends BaseServiceFinderBuilder, SimpleUnshardedServiceFinder, B, D, C> { @Override - protected SimpleUnshardedServiceFinder buildFinder( + protected SimpleUnshardedServiceFinder buildFinder( Service service, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector ) { if (null == shardSelector) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 0b56bf74..1108e6e1 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -1,20 +1,20 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; import java.util.stream.Collectors; -public class ListShardSelector implements ShardSelector> { +public class ListShardSelector> implements ShardSelector> { @Override - public List> nodes(T criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) { if(null == criteria){ return serviceRegistry.nodeList(); } - return serviceRegistry.nodeList().stream().filter(node -> criteria.equals(node.getNodeData())).collect(Collectors.toList()); + return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList()); } - } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 4c806c9e..c9f4f0e3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -17,20 +17,25 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; -public class MatchingShardSelector implements ShardSelector> { - +public class MatchingShardSelector> implements ShardSelector> { @Override - public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { - if(criteria == null){ - return serviceRegistry.nodeList(); - } - - return serviceRegistry.nodes().get(criteria); + public List> nodes(C criteria, MapBasedServiceRegistry serviceRegistry) { + if(null == criteria) return serviceRegistry.nodeList(); + return serviceRegistry.nodes() + .entries() + .stream() + .filter(each -> criteria.apply(each.getKey())) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 032ee645..931c44a0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -1,15 +1,16 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; -public class NoopShardSelector implements ShardSelector> { +public class NoopShardSelector> implements ShardSelector> { @Override - public List> nodes(T criteria, ListBasedServiceRegistry serviceRegistry) { + public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodeList(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index f78b8011..44562591 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -1,14 +1,15 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; /** * */ -public interface ServiceFinderFactory> { +public interface ServiceFinderFactory, R extends ServiceRegistry> { - ServiceFinder buildFinder(final Service service); + ServiceFinder buildFinder(final Service service); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index aceeb761..a9e7bbb5 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; @@ -26,8 +27,8 @@ * */ @Slf4j -public class ServiceFinderHub> { - private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); +public class ServiceFinderHub, R extends ServiceRegistry> { + private final AtomicReference>> finders = new AtomicReference<>(new HashMap<>()); private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; @@ -43,14 +44,14 @@ public class ServiceFinderHub> { private final List> refreshSignals = new ArrayList<>(); private final ServiceDataSource serviceDataSource; - private final ServiceFinderFactory finderFactory; + private final ServiceFinderFactory finderFactory; private AtomicBoolean alreadyUpdating = new AtomicBoolean(false); private Future monitorFuture = null; public ServiceFinderHub( ServiceDataSource serviceDataSource, - ServiceFinderFactory finderFactory) { + ServiceFinderFactory finderFactory) { this.serviceDataSource = serviceDataSource; this.finderFactory = finderFactory; this.refreshSignals.add(new ScheduledSignal<>("service-hub-updater", @@ -59,7 +60,7 @@ public ServiceFinderHub( 10_000)); } - public Optional> finder(final Service service) { + public Optional> finder(final Service service) { return Optional.ofNullable(finders.get().get(service)); } @@ -126,10 +127,10 @@ private void updateRegistry() { return; } alreadyUpdating.set(true); - final Map> updatedFinders = new HashMap<>(); + final Map> updatedFinders = new HashMap<>(); try { final Collection services = serviceDataSource.services(); - final Map> knownServiceFinders = finders.get(); + final Map> knownServiceFinders = finders.get(); val newFinders = services.stream() .filter(service -> !knownServiceFinders.containsKey(service)) .collect(Collectors.toMap(Function.identity(), finderFactory::buildFinder)); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 2fdd5824..75144811 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,5 +1,6 @@ package com.flipkart.ranger.core.finderhub; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.signals.ScheduledSignal; import com.flipkart.ranger.core.signals.Signal; @@ -14,45 +15,45 @@ /** * */ -public abstract class ServiceFinderHubBuilder> { +public abstract class ServiceFinderHubBuilder, R extends ServiceRegistry> { private ServiceDataSource serviceDataSource; - private ServiceFinderFactory serviceFinderFactory; + private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; private List> extraStartSignalConsumers = new ArrayList<>(); private List> extraStopSignalConsumers = new ArrayList<>(); private List> extraRefreshSignals = new ArrayList<>(); - public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { + public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { this.serviceDataSource = serviceDataSource; return this; } - public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { + public ServiceFinderHubBuilder withServiceFinderFactory(ServiceFinderFactory serviceFinderFactory) { this.serviceFinderFactory = serviceFinderFactory; return this; } - public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { + public ServiceFinderHubBuilder withRefreshFrequencyMs(long refreshFrequencyMs) { this.refreshFrequencyMs = refreshFrequencyMs; return this; } - public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStartSignalConsumer(Consumer consumer) { this.extraStartSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { + public ServiceFinderHubBuilder withExtraStopSignalConsumer(Consumer consumer) { this.extraStopSignalConsumers.add(consumer); return this; } - public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { + public ServiceFinderHubBuilder withExtraRefreshSignal(Signal extraRefreshSignal) { this.extraRefreshSignals.add(extraRefreshSignal); return this; } - public ServiceFinderHub build() { + public ServiceFinderHub build() { preBuild(); Preconditions.checkNotNull(serviceDataSource, "Provide a non-null service data source"); Preconditions.checkNotNull(serviceFinderFactory, "Provide a non-null service finder factory"); @@ -78,5 +79,6 @@ public ServiceFinderHub build() { } protected abstract void preBuild(); - protected abstract void postBuild(ServiceFinderHub serviceFinderHub); + + protected abstract void postBuild(ServiceFinderHub serviceFinderHub); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index e6ada2ee..9d3b0b8e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -18,8 +18,8 @@ import java.util.List; -public interface ShardSelector> { +public interface ShardSelector, ServiceRegistryType extends ServiceRegistry> { - List> nodes(T criteria, ServiceRegistryType serviceRegistry); + List> nodes(C criteria, ServiceRegistryType serviceRegistry); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index c27b496e..583418b8 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -2,7 +2,9 @@ import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; @@ -16,10 +18,10 @@ public class SimpleShardFinderTest { - static class TestSimpleShardSelector implements ShardSelector>{ + static class TestSimpleShardSelector> implements ShardSelector>{ @Override - public List> nodes(T criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(C criteria, MapBasedServiceRegistry serviceRegistry) { return Lists.newArrayList(); } } @@ -27,9 +29,9 @@ public List> nodes(T criteria, MapBasedServiceRegistry service @Test public void testSimpleShardedFinder(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); - final TestSimpleShardSelector shardSelector = new TestSimpleShardSelector<>(); + final TestSimpleShardSelector> shardSelector = new TestSimpleShardSelector<>(); final RoundRobinServiceNodeSelector roundRobinServiceNodeSelector = new RoundRobinServiceNodeSelector<>(); - val simpleShardedFinder = new SimpleShardedServiceFinder( + val simpleShardedFinder = new SimpleShardedServiceFinder<>( serviceRegistry, shardSelector, roundRobinServiceNodeSelector); val testNodeDataServiceNode = simpleShardedFinder.get( CriteriaUtils.getCriteria(2)); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index 3f5b73da..eef32ac0 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.units.TestNodeData; @@ -24,8 +25,8 @@ public ServiceNode select(List> serviceN @Test public void unshardedClusterFinder(){ final ListBasedServiceRegistry unshardedRegistry = RegistryTestUtils.getUnshardedRegistry(); - final ListShardSelector shardSelector = new ListShardSelector<>(); - SimpleUnshardedServiceFinder simpleUnshardedServiceFinder = new SimpleUnshardedServiceFinder( + final ListShardSelector> shardSelector = new ListShardSelector<>(); + SimpleUnshardedServiceFinder> simpleUnshardedServiceFinder = new SimpleUnshardedServiceFinder<>( unshardedRegistry, shardSelector, new TestUnshardedNodeSelector() diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index 073b8202..d765a67e 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; @@ -14,7 +15,7 @@ public class MapBasedServiceRegistryTest { public void testMapBasedServiceRegistryWithMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); Assert.assertTrue(null != serviceRegistry.nodes() && !serviceRegistry.nodes().isEmpty()); - final MatchingShardSelector matchingShardSelector = new MatchingShardSelector<>(); + final MatchingShardSelector> matchingShardSelector = new MatchingShardSelector<>(); val nodes = matchingShardSelector.nodes( CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java index 9c469af2..2568784c 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; @@ -15,7 +16,7 @@ public class ListShardSelectorTest { @Test public void testNoOpShardSelector(){ final ListBasedServiceRegistry serviceRegistry = RegistryTestUtils.getUnshardedRegistry(); - final ListShardSelector shardSelector = new ListShardSelector<>(); + final ListShardSelector> shardSelector = new ListShardSelector<>(); final List> nodes = shardSelector.nodes(CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index 0fc3702e..1c8e352f 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -1,6 +1,7 @@ package com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; @@ -15,7 +16,7 @@ public class MatchingShardSelectorTest { @Test public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); - final MatchingShardSelector shardSelector = new MatchingShardSelector<>(); + final MatchingShardSelector> shardSelector = new MatchingShardSelector<>(); final List> nodes = shardSelector.nodes( CriteriaUtils.getCriteria(1), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index 321e9df2..d16eb56b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,10 +1,11 @@ package com.flipkart.ranger.core.utils; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.units.TestNodeData; public class CriteriaUtils { - public static TestNodeData getCriteria(int shardId){ - return new TestNodeData(shardId); + public static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getNodeId() == shardId; } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java index 97a2db63..4a677c76 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -1,5 +1,6 @@ package com.flipkart.ranger.http; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; import com.flipkart.ranger.http.servicefinder.HttpUnshardedServiceFinderBuilider; @@ -9,11 +10,11 @@ private void HttpServiceProviderBuilders(){ throw new InstantiationError("Must not instantiate this class"); } - public static HttpShardedServiceFinderBuilder httpShardedServiceFinderBuilder(){ + public static HttpShardedServiceFinderBuilder> httpShardedServiceFinderBuilder(){ return new HttpShardedServiceFinderBuilder<>(); } - public static HttpUnshardedServiceFinderBuilider httpUnshardedServiceFinderBuilider(){ + public static HttpUnshardedServiceFinderBuilider> httpUnshardedServiceFinderBuilider(){ return new HttpUnshardedServiceFinderBuilider<>(); } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 41839464..064f036a 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; @@ -11,23 +12,23 @@ /** * */ -public class HttpShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer> { +public class HttpShardedServiceFinderBuilder> extends SimpleShardedServiceFinderBuilder, HTTPResponseDataDeserializer, C> { private HttpClientConfig clientConfig; private ObjectMapper mapper; - public HttpShardedServiceFinderBuilder withClientConfig(final HttpClientConfig clientConfig) { + public HttpShardedServiceFinderBuilder withClientConfig(final HttpClientConfig clientConfig) { this.clientConfig = clientConfig; return this; } - public HttpShardedServiceFinderBuilder withObjectMapper(final ObjectMapper mapper){ + public HttpShardedServiceFinderBuilder withObjectMapper(final ObjectMapper mapper){ this.mapper = mapper; return this; } @Override - public SimpleShardedServiceFinder build() { + public SimpleShardedServiceFinder build() { return buildFinder(); } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index a9c0bfff..f07873e3 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -3,28 +3,28 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.NodeDataSource; -import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.*; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; -public class HttpUnshardedServiceFinderBuilider extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer> { +public class HttpUnshardedServiceFinderBuilider> + extends SimpleUnshardedServiceFinderBuilder, HTTPResponseDataDeserializer, C> { private HttpClientConfig clientConfig; private ObjectMapper mapper; - public HttpUnshardedServiceFinderBuilider withClientConfig(final HttpClientConfig clientConfig) { + public HttpUnshardedServiceFinderBuilider withClientConfig(final HttpClientConfig clientConfig) { this.clientConfig = clientConfig; return this; } - public HttpUnshardedServiceFinderBuilider withObjectMapper(final ObjectMapper mapper) { + public HttpUnshardedServiceFinderBuilider withObjectMapper(final ObjectMapper mapper) { this.mapper = mapper; return this; } @Override - public SimpleUnshardedServiceFinder build() { + public SimpleUnshardedServiceFinder build() { return buildFinder(); } @@ -32,5 +32,6 @@ public SimpleUnshardedServiceFinder build() { protected NodeDataSource> dataSource(Service service) { return new HttpNodeDataSource<>(service, clientConfig, mapper); } + } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index cc3a343e..44e67432 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -2,11 +2,12 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import lombok.extern.slf4j.Slf4j; @Slf4j -public class HttpServiceFinderHubBuilder> extends ServiceFinderHubBuilder { +public class HttpServiceFinderHubBuilder, R extends ServiceRegistry> extends ServiceFinderHubBuilder { @Override protected void preBuild() { @@ -14,7 +15,7 @@ protected void preBuild() { } @Override - protected void postBuild(ServiceFinderHub serviceFinderHub) { + protected void postBuild(ServiceFinderHub serviceFinderHub) { log.info("No post build actions necessary"); } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 8b43e701..d1e7e966 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -4,6 +4,7 @@ import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -15,12 +16,12 @@ import lombok.val; @Getter -public class HttpUnshardedServiceFinderFactory implements ServiceFinderFactory> { +public class HttpUnshardedServiceFinderFactory> implements ServiceFinderFactory> { private final HttpClientConfig clientConfig; private final ObjectMapper mapper; private final HTTPResponseDataDeserializer deserializer; - private final ShardSelector> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; private final int nodeRefreshIntervalMs; @@ -29,7 +30,7 @@ public HttpUnshardedServiceFinderFactory( HttpClientConfig httpClientConfig, ObjectMapper mapper, HTTPResponseDataDeserializer deserializer, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector, int nodeRefreshIntervalMs) { @@ -42,8 +43,8 @@ public HttpUnshardedServiceFinderFactory( } @Override - public ServiceFinder> buildFinder(Service service) { - val serviceFinder = new HttpUnshardedServiceFinderBuilider() + public ServiceFinder> buildFinder(Service service) { + val serviceFinder = new HttpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) .withObjectMapper(mapper) .withDeserializer(deserializer) diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index c58f5937..969e8721 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -6,7 +6,9 @@ import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.github.tomakehurst.wiremock.junit.WireMockRule; @@ -63,7 +65,7 @@ public void testFinder() throws Exception { .operationTimeoutMs(30_000) .build(); - final SimpleShardedServiceFinder finder = new HttpShardedServiceFinderBuilder() + final SimpleShardedServiceFinder> finder = new HttpShardedServiceFinderBuilder>() .withClientConfig(clientConfig) .withNamespace("testns") .withServiceName("test") @@ -76,16 +78,11 @@ public void testFinder() throws Exception { throw new IllegalArgumentException(e); } }) - .withShardSelector((criteria, registry) -> registry - .nodes() - .entries() - .stream() - .map(Map.Entry::getValue) - .collect(Collectors.toList())) + .withShardSelector((criteria, registry) -> registry.nodeList()) .build(); finder.start(); TestUtils.sleepForSeconds(3); - Assert.assertNotNull(finder.get(testNode)); + Assert.assertNotNull(finder.get(nodeData -> true)); } } \ No newline at end of file diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index bc3dade3..012acfeb 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -16,6 +16,7 @@ package com.flipkart.ranger.zookeeper; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleShardedServiceFinderBuilder; import com.flipkart.ranger.zookeeper.servicefinder.ZkSimpleUnshardedServiceFinderBuilder; @@ -25,11 +26,11 @@ private ServiceFinderBuilders() { throw new InstantiationError("Must not instantiate this class"); } - public static ZkSimpleShardedServiceFinderBuilder shardedFinderBuilder() { + public static ZkSimpleShardedServiceFinderBuilder> shardedFinderBuilder() { return new ZkSimpleShardedServiceFinderBuilder<>(); } - public static ZkSimpleUnshardedServiceFinderBuilder unshardedFinderBuilder() { + public static ZkSimpleUnshardedServiceFinderBuilder> unshardedFinderBuilder() { return new ZkSimpleUnshardedServiceFinderBuilder<>(); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index 5f43e9fe..b4ab8e58 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; @@ -20,22 +21,22 @@ * */ @Slf4j -public class ZkSimpleShardedServiceFinderBuilder extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer> { +public class ZkSimpleShardedServiceFinderBuilder> extends SimpleShardedServiceFinderBuilder, ZkNodeDataDeserializer, C> { protected CuratorFramework curatorFramework; protected String connectionString; - public ZkSimpleShardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkSimpleShardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkSimpleShardedServiceFinderBuilder withConnectionString(final String connectionString) { + public ZkSimpleShardedServiceFinderBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @Override - public SimpleShardedServiceFinder build() { + public SimpleShardedServiceFinder build() { boolean curatorProvided = curatorFramework != null; if (!curatorProvided) { Preconditions.checkNotNull(connectionString); diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index 9d56354d..9051e3de 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.NodeDataSource; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.signals.Signal; @@ -20,22 +21,23 @@ * */ @Slf4j -public class ZkSimpleUnshardedServiceFinderBuilder extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer> { +public class ZkSimpleUnshardedServiceFinderBuilder> + extends SimpleUnshardedServiceFinderBuilder, ZkNodeDataDeserializer, C> { private CuratorFramework curatorFramework; private String connectionString; - public ZkSimpleUnshardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkSimpleUnshardedServiceFinderBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkSimpleUnshardedServiceFinderBuilder withConnectionString(final String connectionString) { + public ZkSimpleUnshardedServiceFinderBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @Override - public SimpleUnshardedServiceFinder build() { + public SimpleUnshardedServiceFinder build() { boolean curatorProvided = curatorFramework != null; if (!curatorProvided) { Preconditions.checkNotNull(connectionString); diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 222c9f86..8545d26b 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -3,6 +3,7 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -15,14 +16,14 @@ @Getter -public class ZKUnshardedServiceFinderFactory implements ServiceFinderFactory>{ +public class ZKUnshardedServiceFinderFactory> implements ServiceFinderFactory>{ private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -32,7 +33,7 @@ public ZKUnshardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; @@ -44,8 +45,8 @@ public ZKUnshardedServiceFinderFactory( } @Override - public SimpleUnshardedServiceFinder buildFinder(Service service) { - val finder = new ZkSimpleUnshardedServiceFinderBuilder() + public SimpleUnshardedServiceFinder buildFinder(Service service) { + val finder = new ZkSimpleUnshardedServiceFinderBuilder() .withDeserializer(deserializer) .withNamespace(service.getNamespace()) .withServiceName(service.getServiceName()) diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 6ab9ebe7..19d9eb5b 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -2,6 +2,7 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceRegistry; import com.google.common.base.Preconditions; import lombok.extern.slf4j.Slf4j; @@ -13,22 +14,22 @@ * */ @Slf4j -public class ZkServiceFinderHubBuilder> extends ServiceFinderHubBuilder { +public class ZkServiceFinderHubBuilder, R extends ServiceRegistry> extends ServiceFinderHubBuilder { private String namespace; private CuratorFramework curatorFramework; private String connectionString; - public ZkServiceFinderHubBuilder withNamespace(final String namespace) { + public ZkServiceFinderHubBuilder withNamespace(final String namespace) { this.namespace = namespace; return this; } - public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { + public ZkServiceFinderHubBuilder withCuratorFramework(CuratorFramework curatorFramework) { this.curatorFramework = curatorFramework; return this; } - public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { + public ZkServiceFinderHubBuilder withConnectionString(final String connectionString) { this.connectionString = connectionString; return this; } @@ -49,7 +50,7 @@ protected void preBuild() { } @Override - protected void postBuild(ServiceFinderHub serviceFinderHub) { + protected void postBuild(ServiceFinderHub serviceFinderHub) { log.debug("No post build steps necessary"); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 5df48337..6dca3bcf 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -3,6 +3,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNodeSelector; import com.flipkart.ranger.core.model.ShardSelector; @@ -15,13 +16,13 @@ /** * */ -public class ZkShardedServiceFinderFactory implements ServiceFinderFactory> { +public class ZkShardedServiceFinderFactory> implements ServiceFinderFactory> { private final CuratorFramework curatorFramework; private final String connectionString; private final int nodeRefreshIntervalMs; private final boolean disablePushUpdaters; private final ZkNodeDataDeserializer deserializer; - private final ShardSelector> shardSelector; + private final ShardSelector> shardSelector; private final ServiceNodeSelector nodeSelector; @Builder @@ -31,7 +32,7 @@ public ZkShardedServiceFinderFactory( int nodeRefreshIntervalMs, boolean disablePushUpdaters, ZkNodeDataDeserializer deserializer, - ShardSelector> shardSelector, + ShardSelector> shardSelector, ServiceNodeSelector nodeSelector) { this.curatorFramework = curatorFramework; this.connectionString = connectionString; @@ -43,8 +44,8 @@ public ZkShardedServiceFinderFactory( } @Override - public SimpleShardedServiceFinder buildFinder(Service service) { - val finder = new ZkSimpleShardedServiceFinderBuilder() + public SimpleShardedServiceFinder buildFinder(Service service) { + val finder = new ZkSimpleShardedServiceFinderBuilder() .withDeserializer(deserializer) .withNamespace(service.getNamespace()) .withServiceName(service.getServiceName()) diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index ae1e23ab..f2949abc 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -22,6 +22,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; @@ -113,19 +114,19 @@ public int hashCode() { return result; } - private static TestShardInfo getCriteria(int a, int b){ - return new TestShardInfo(a, b); + private static Criteria getCriteria(int a, int b){ + return nodeData -> nodeData.getA() == a && nodeData.getB() == b; } } - private static final class TestShardSelector implements ShardSelector> { + private static final class TestShardSelector implements ShardSelector, MapBasedServiceRegistry> { @Override - public List> nodes(TestShardInfo criteria, MapBasedServiceRegistry serviceRegistry) { + public List> nodes(Criteria criteria, MapBasedServiceRegistry serviceRegistry) { List> nodes = Lists.newArrayList(); for(Map.Entry> entry : serviceRegistry.nodes().entries()) { TestShardInfo shardInfo = entry.getKey(); - if(criteria.equals(shardInfo)){ + if(criteria.apply(shardInfo)){ nodes.add(entry.getValue()); } } @@ -135,7 +136,7 @@ public List> nodes(TestShardInfo criteria, MapBasedSe @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 92f67c0f..610a4211 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import lombok.val; @@ -94,15 +95,15 @@ public int hashCode() { return shardId; } - private static TestShardInfo getCriteria(int shardId){ - return new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> shardId == nodeData.getShardId(); } } @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index 0e102ee9..61d6cf01 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -109,15 +110,15 @@ public int hashCode() { return shardId; } - private static TestShardInfo getCriteria(int shardId){ - return new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } @Test - public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + public void testBasicDiscovery() { + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withCuratorFramework(curatorFramework) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 5338536e..099807c0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -23,6 +23,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthcheck; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -96,14 +97,14 @@ public int hashCode() { return shardId; } - private static TestShardInfo getCriteria(int shardId){ - return new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } @Test - public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + public void testBasicDiscovery() { + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 439ed373..cdc584ca 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -22,6 +22,7 @@ import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -107,14 +108,14 @@ public int hashCode() { return shardId; } - private static TestShardInfo getCriteria(int shardId){ - return new TestShardInfo(shardId); + private static Criteria getCriteria(int shardId){ + return nodeData -> nodeData.getShardId() == shardId; } } @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -156,7 +157,7 @@ public void testBasicDiscovery() throws Exception { @Test public void testBasicDiscoveryRR() throws Exception { - SimpleShardedServiceFinder serviceFinder + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") @@ -201,8 +202,8 @@ public void testBasicDiscoveryRR() throws Exception { } @Test - public void testVisibility() throws Exception { - SimpleShardedServiceFinder serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + public void testVisibility() { + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 61dd42b1..46f14a0f 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.healthcheck.Healthchecks; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; @@ -72,7 +73,7 @@ public boolean equals(Object obj) { @Test public void testBasicDiscovery() { - SimpleUnshardedServiceFinder serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() + SimpleUnshardedServiceFinder> serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -107,7 +108,7 @@ public void testBasicDiscovery() { //while (true); } - private void registerService(String host, int port, int shardId) throws Exception { + private void registerService(String host, int port, int shardId) { val serviceProvider = ServiceProviderBuilders.unshardedServiceProviderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 6e6fd025..c468f61a 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -7,6 +7,7 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; @@ -70,12 +71,12 @@ public void stopTestCluster() throws Exception { @Test public void testHub() { ExternalTriggeredSignal refreshHubSignal = new ExternalTriggeredSignal<>(() -> null, Collections.emptyList()); - val hub = new ZkServiceFinderHubBuilder>() + val hub = new ZkServiceFinderHubBuilder, MapBasedServiceRegistry>() .withCuratorFramework(curatorFramework) .withNamespace("test") .withRefreshFrequencyMs(1000) .withServiceDataSource(new ZkServiceDataSource("test", testingCluster.getConnectString(), curatorFramework)) - .withServiceFinderFactory(ZkShardedServiceFinderFactory.builder() + .withServiceFinderFactory(ZkShardedServiceFinderFactory.>builder() .curatorFramework(curatorFramework) .deserializer(this::read) .build()) @@ -106,7 +107,7 @@ public void testHub() { TestUtils.sleepForSeconds(3); val node = hub.finder(new Service(NAMESPACE, "s1")) - .map(finder -> finder.get(new TestShardInfo("prod"))) + .map(finder -> finder.get(nodeData -> nodeData.getEnvironment().equalsIgnoreCase("prod"))) .orElse(null); Assert.assertNotNull(node); hub.stop(); From b23cfcc72bb835ac4433852f41d31d8fc159e9a2 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sat, 16 Oct 2021 20:51:18 +0530 Subject: [PATCH 36/53] Simplified the static builders --- .../ranger/core/finder/shardselector/ListShardSelector.java | 2 ++ .../com/flipkart/ranger/http/HttpServiceFinderBuilders.java | 4 ++-- .../com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 1108e6e1..61b7d2f0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -17,4 +17,6 @@ public List> nodes(C criteria, ListBasedServiceRegistry servic } return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList()); } + + } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java index 4a677c76..371f7538 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -10,11 +10,11 @@ private void HttpServiceProviderBuilders(){ throw new InstantiationError("Must not instantiate this class"); } - public static HttpShardedServiceFinderBuilder> httpShardedServiceFinderBuilder(){ + public static > HttpShardedServiceFinderBuilder httpShardedServiceFinderBuilder(){ return new HttpShardedServiceFinderBuilder<>(); } - public static HttpUnshardedServiceFinderBuilider> httpUnshardedServiceFinderBuilider(){ + public static > HttpUnshardedServiceFinderBuilider httpUnshardedServiceFinderBuilider(){ return new HttpUnshardedServiceFinderBuilider<>(); } } diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index 012acfeb..1dbf83d2 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -26,11 +26,11 @@ private ServiceFinderBuilders() { throw new InstantiationError("Must not instantiate this class"); } - public static ZkSimpleShardedServiceFinderBuilder> shardedFinderBuilder() { + public static > ZkSimpleShardedServiceFinderBuilder shardedFinderBuilder() { return new ZkSimpleShardedServiceFinderBuilder<>(); } - public static ZkSimpleUnshardedServiceFinderBuilder> unshardedFinderBuilder() { + public static > ZkSimpleUnshardedServiceFinderBuilder> unshardedFinderBuilder() { return new ZkSimpleUnshardedServiceFinderBuilder<>(); } } From 37ee531d72e51e90a8d30915417ab5784e6a19b7 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 00:22:36 +0530 Subject: [PATCH 37/53] Fixed tests in service discovery bundle --- pom.xml | 5 +++++ .../flipkart/ranger/zookeeper/ServiceFinderBuilders.java | 2 +- .../healthservice/ServiceProviderIntegrationTest.java | 3 ++- .../ranger/zookeeper/model/CustomShardSelectorTest.java | 2 +- .../ranger/zookeeper/model/ServiceNoProviderTest.java | 6 +++--- .../zookeeper/model/ServiceProviderExtCuratorTest.java | 2 +- .../zookeeper/model/ServiceProviderHealthcheckTest.java | 2 +- .../ranger/zookeeper/model/ServiceProviderTest.java | 7 ++++--- .../ranger/zookeeper/model/SimpleServiceProviderTest.java | 2 +- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 5b2d0e7a..1501e2a6 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,11 @@ Tushar Naik tushar.naik@flipkart.com + + koushikr + Koushik Ramachandra + rkoushik.14@gmail.com + diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index 1dbf83d2..e9571310 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -30,7 +30,7 @@ public static > ZkSimpleShardedServiceFinderBuilder(); } - public static > ZkSimpleUnshardedServiceFinderBuilder> unshardedFinderBuilder() { + public static > ZkSimpleUnshardedServiceFinderBuilder unshardedFinderBuilder() { return new ZkSimpleUnshardedServiceFinderBuilder<>(); } } diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index e98fe778..6bb3edd5 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.healthcheck.Healthchecks; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.sample.RotationStatusMonitor; +import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; @@ -75,7 +76,7 @@ public void startTestCluster() throws Exception { registerService("localhost-4", 9000, 2, anotherFile); - serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() + serviceFinder = ServiceFinderBuilders.>unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index f2949abc..d5d0d94f 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -136,7 +136,7 @@ public List> nodes(Criteria criteria, @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index 610a4211..e10ace89 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -103,7 +103,7 @@ private static Criteria getCriteria(int shardId){ @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -127,8 +127,8 @@ public void testBasicDiscovery() throws Exception { } @Test - public void testBasicDiscoveryRR() throws Exception { - val serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + public void testBasicDiscoveryRR() { + val serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index 61d6cf01..e8da9d45 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -118,7 +118,7 @@ private static Criteria getCriteria(int shardId){ @Test public void testBasicDiscovery() { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withCuratorFramework(curatorFramework) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 099807c0..2c19abd6 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -104,7 +104,7 @@ private static Criteria getCriteria(int shardId){ @Test public void testBasicDiscovery() { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index cdc584ca..255c95eb 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -115,7 +115,7 @@ private static Criteria getCriteria(int shardId){ @Test public void testBasicDiscovery() throws Exception { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -158,7 +158,7 @@ public void testBasicDiscovery() throws Exception { @Test public void testBasicDiscoveryRR() throws Exception { SimpleShardedServiceFinder> serviceFinder - = ServiceFinderBuilders.shardedFinderBuilder() + = ServiceFinderBuilders.>shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") @@ -203,7 +203,8 @@ public void testBasicDiscoveryRR() throws Exception { @Test public void testVisibility() { - SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + SimpleShardedServiceFinder> serviceFinder = ServiceFinderBuilders. + >shardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 46f14a0f..6800ebc1 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -73,7 +73,7 @@ public boolean equals(Object obj) { @Test public void testBasicDiscovery() { - SimpleUnshardedServiceFinder> serviceFinder = ServiceFinderBuilders.unshardedFinderBuilder() + SimpleUnshardedServiceFinder> serviceFinder = ServiceFinderBuilders.>unshardedFinderBuilder() .withConnectionString(testingCluster.getConnectString()) .withNamespace("test") .withServiceName("test-service") From c8432f47909b6497fca6f7c139cb2606bc768f9e Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 00:39:42 +0530 Subject: [PATCH 38/53] Added the required licence to the classes that were missing the licence info --- CHANGELOG.md | 0 .../signal/ScheduledRegistryUpdateSignal.java | 15 +++++++++++++++ .../finder/shardselector/ListShardSelector.java | 15 +++++++++++++++ .../finder/shardselector/NoopShardSelector.java | 15 +++++++++++++++ .../core/finderhub/ServiceDataSource.java | 15 +++++++++++++++ .../core/finderhub/ServiceFinderFactory.java | 15 +++++++++++++++ .../ranger/core/finderhub/ServiceFinderHub.java | 15 +++++++++++++++ .../core/finderhub/ServiceFinderHubBuilder.java | 15 +++++++++++++++ .../ranger/core/finderhub/StaticDataSource.java | 15 +++++++++++++++ .../core/healthcheck/HealthcheckResult.java | 15 +++++++++++++++ .../ranger/core/healthcheck/Healthchecks.java | 15 +++++++++++++++ .../monitor/sample/CountMonitor.java | 15 +++++++++++++++ .../monitor/sample/RotationStatusMonitor.java | 15 +++++++++++++++ .../flipkart/ranger/core/model/Criteria.java | 15 +++++++++++++++ .../ranger/core/model/NodeDataSink.java | 15 +++++++++++++++ .../ranger/core/model/NodeDataSource.java | 15 +++++++++++++++ .../core/model/NodeDataStoreConnector.java | 15 +++++++++++++++ .../core/signals/ExternalTriggeredSignal.java | 15 +++++++++++++++ .../ranger/core/signals/ScheduledSignal.java | 15 +++++++++++++++ .../flipkart/ranger/core/signals/Signal.java | 15 +++++++++++++++ .../flipkart/ranger/core/util/Exceptions.java | 15 +++++++++++++++ .../flipkart/ranger/core/util/FinderUtils.java | 15 +++++++++++++++ .../com/flipkart/ranger/core/TestUtils.java | 15 +++++++++++++++ .../core/finder/SimpleShardFinderTest.java | 15 +++++++++++++++ .../core/finder/UnshardedClusterFinderTest.java | 15 +++++++++++++++ .../RoundRobinServiceNodeSelectorTest.java | 17 ++++++++++++++++- .../MapBasedServiceRegistryTest.java | 15 +++++++++++++++ .../shardselector/ListShardSelectorTest.java | 15 +++++++++++++++ .../MatchingShardSelectorTest.java | 15 +++++++++++++++ .../serviceprovider/ServiceProviderTest.java | 15 +++++++++++++++ .../ranger/core/units/TestNodeData.java | 15 +++++++++++++++ .../ranger/core/utils/CriteriaUtils.java | 15 +++++++++++++++ .../ranger/core/utils/RegistryTestUtils.java | 15 +++++++++++++++ .../ranger/http/HttpServiceFinderBuilders.java | 15 +++++++++++++++ .../http/HttpServiceProviderBuilders.java | 15 +++++++++++++++ .../http/common/HttpNodeDataStoreConnector.java | 15 +++++++++++++++ .../ranger/http/config/HttpClientConfig.java | 15 +++++++++++++++ .../http/model/ServiceDataSourceResponse.java | 15 +++++++++++++++ .../ranger/http/model/ServiceNodesResponse.java | 15 +++++++++++++++ .../http/model/ServiceRegistrationResponse.java | 15 +++++++++++++++ .../serde/HTTPResponseDataDeserializer.java | 15 +++++++++++++++ .../http/serde/HttpRequestDataSerializer.java | 15 +++++++++++++++ .../http/servicefinder/HttpNodeDataSource.java | 15 +++++++++++++++ .../HttpShardedServiceFinderBuilder.java | 15 +++++++++++++++ .../HttpUnshardedServiceFinderBuilider.java | 15 +++++++++++++++ .../servicefinderhub/HttpServiceDataSource.java | 15 +++++++++++++++ .../HttpServiceFinderHubBuilder.java | 15 +++++++++++++++ .../HttpUnshardedServiceFinderFactory.java | 15 +++++++++++++++ .../http/serviceprovider/HttpNodeDataSink.java | 15 +++++++++++++++ .../HttpShardedServiceProviderBuilder.java | 15 +++++++++++++++ .../flipkart/ranger/http/ResourceHelper.java | 15 +++++++++++++++ .../common/HttpNodeDataStoreConnectorTest.java | 15 +++++++++++++++ .../http/config/HttpClientConfigTest.java | 15 +++++++++++++++ .../http/model/ServiceNodeResponseTest.java | 15 +++++++++++++++ .../model/ServiceRegistrationResponseTest.java | 15 +++++++++++++++ .../HttpShardedServiceFinderBuilderTest.java | 15 +++++++++++++++ .../HttpServiceDataSourceTest.java | 15 +++++++++++++++ .../HttpShardedServiceProviderBuilderTest.java | 15 +++++++++++++++ .../common/ZkNodeDataStoreConnector.java | 15 +++++++++++++++ .../zookeeper/serde/ZkNodeDataDeserializer.java | 15 +++++++++++++++ .../zookeeper/serde/ZkNodeDataSerializer.java | 15 +++++++++++++++ .../servicefinder/ZkNodeDataSource.java | 15 +++++++++++++++ .../ZkSimpleShardedServiceFinderBuilder.java | 15 +++++++++++++++ .../ZkSimpleUnshardedServiceFinderBuilder.java | 15 +++++++++++++++ .../signals/ZkWatcherRegistryUpdateSignal.java | 15 +++++++++++++++ .../ZKUnshardedServiceFinderFactory.java | 15 +++++++++++++++ .../servicefinderhub/ZkServiceDataSource.java | 15 +++++++++++++++ .../ZkServiceFinderHubBuilder.java | 15 +++++++++++++++ .../ZkShardedServiceFinderFactory.java | 15 +++++++++++++++ .../serviceprovider/ZkNodeDataSink.java | 15 +++++++++++++++ .../ZkServiceProviderBuilder.java | 15 +++++++++++++++ .../zookeeper/servicehub/ServiceHubTest.java | 15 +++++++++++++++ 72 files changed, 1066 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java index b25effc6..1aa9e27d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.serviceregistry.signal; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 61b7d2f0..d2034872 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 931c44a0..9d38f9a8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java index 7a014377..f5843d96 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 44562591..5740be83 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index a9e7bbb5..92a8daf1 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.finder.ServiceFinder; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 75144811..057b6489 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.model.Criteria; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java index 1953853b..12f16fb4 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finderhub; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java index f77f1efd..d4828f00 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.healthcheck; import lombok.Builder; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java index 42c24505..073cb465 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.healthcheck; import java.io.File; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java index 14acdaed..1ca3b35d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java @@ -14,6 +14,21 @@ * limitations under the License. */ +/** + * Copyright 2015 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 com.flipkart.ranger.core.healthservice.monitor.sample; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java index 5a2f9039..18230130 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java @@ -16,6 +16,21 @@ package com.flipkart.ranger.core.healthservice.monitor.sample; +/** + * Copyright 2015 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. + */ import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.healthservice.TimeEntity; import com.flipkart.ranger.core.healthservice.monitor.IsolatedHealthMonitor; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index 1cc72b62..3b5d9d4d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.model; @FunctionalInterface diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java index 92684451..2547e346 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.model; /** diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java index e11ccac9..75d3f6bd 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.model; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java index e2cab33a..a82aeb5a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.model; /** diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java index 2dc41acd..56e1436e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.signals; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java index 71b39886..8b8aeb62 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.signals; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java index 354b3d4a..2d11fb12 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.signals; import lombok.val; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java b/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java index 69f75f2f..31e245ce 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.util; /** diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java b/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java index 204dd4b5..a83278dc 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.util; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java index 34af52ab..8b6b2311 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core; import java.util.concurrent.TimeUnit; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 583418b8..df14bb2a 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index eef32ac0..2fe51303 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java index a533c41b..8a6492ce 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java @@ -1,4 +1,19 @@ -package com.flipkart.ranger.core.finder.nodeselector; + +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index d765a67e..c4752a2b 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java index 2568784c..06c6cd12 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index 1c8e352f..f11a6d63 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.finder.shardselector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java index ea430e70..81e73dc8 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.serviceprovider; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java index 024de9b0..43631057 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.units; import lombok.AllArgsConstructor; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index d16eb56b..b5262a45 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.utils; import com.flipkart.ranger.core.model.Criteria; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java index 5213d28d..22dc3568 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.core.utils; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java index 371f7538..769030b1 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http; import com.flipkart.ranger.core.model.Criteria; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java index cb134751..108b2a7b 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http; import com.flipkart.ranger.http.serviceprovider.HttpShardedServiceProviderBuilder; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index 8d22d5ba..9f346b33 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.common; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java index bd284bd1..7bda4e5c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.config; import lombok.*; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java index 285ab55c..613a1a74 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.model; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 35b03356..b7f7ff21 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.model; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java index cc3e5f76..9c040428 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.model; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java index 0cf065cb..4b35e950 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.serde; import com.flipkart.ranger.core.model.Deserializer; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java index 2ca42b57..badba832 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.serde; import com.flipkart.ranger.core.model.Serializer; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 5711c1fa..be15a2bd 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 064f036a..377c6b58 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index f07873e3..a0a465b3 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java index a33b273c..598db12c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinderhub; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index 44e67432..75645ef8 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index d1e7e966..03821433 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinderhub; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index 02be98c7..1ddfa458 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.serviceprovider; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java index 6153d7eb..9ec73abd 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.serviceprovider; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java b/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java index 9defe986..94dcacf0 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/ResourceHelper.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java index 0a328ed0..caf6d5fc 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnectorTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.common; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java index f2187f94..336fb925 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/config/HttpClientConfigTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.config; import com.flipkart.ranger.http.ResourceHelper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java index b55ff764..a26e70e6 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.model; import com.flipkart.ranger.core.model.ServiceNode; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java index 096f5608..42025c66 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceRegistrationResponseTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.model; import com.flipkart.ranger.http.ResourceHelper; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 969e8721..6139a2bd 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinder; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 99203676..e61485e3 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinderhub; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java index bff51890..574b7b7e 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.serviceprovider; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java index 28e981a9..bb7ab01c 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.common; import com.flipkart.ranger.core.model.NodeDataStoreConnector; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java index 11b22821..a07f2bac 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.serde; import com.flipkart.ranger.core.model.Deserializer; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java index 182f001b..fcf3f001 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.serde; import com.flipkart.ranger.core.model.Serializer; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index 065013a6..6a80a84b 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.model.NodeDataSource; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index b4ab8e58..87387762 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index 9051e3de..e17d3923 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java index 901c2c7b..1231d3e1 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinder.signals; import com.flipkart.ranger.core.model.NodeDataStoreConnector; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 8545d26b..08643cbd 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index a67d8589..d86f845d 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceDataSource; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 19d9eb5b..52b5da8d 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index 6dca3bcf..eda9744e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicefinderhub; import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java index b2e0d48e..39a0ef4e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.serviceprovider; import com.flipkart.ranger.core.model.NodeDataSink; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java index 0a37fd55..683ed0fd 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.serviceprovider; import com.flipkart.ranger.core.model.NodeDataSink; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index c468f61a..631b9785 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -1,3 +1,18 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.zookeeper.servicehub; import com.fasterxml.jackson.annotation.JsonProperty; From 1180c9bad887caf2223e885e60a96f2cfcb490c3 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 10:36:41 +0530 Subject: [PATCH 39/53] Added ranger clients. Http and zk, including the simple and http hub clients --- pom.xml | 3 + ranger-client/pom.xml | 37 +++++ .../ranger/client/AbstractHubClient.java | 99 +++++++++++++ .../com/flipkart/ranger/client/Constants.java | 7 + .../flipkart/ranger/client/RangerClient.java | 42 ++++++ .../ranger/client/RangerHubClient.java | 40 +++++ ranger-http-client/pom.xml | 33 +++++ .../client/http/AbstractHttpHubClient.java | 115 +++++++++++++++ .../client/http/ShardedHttpHubClient.java | 100 +++++++++++++ .../client/http/SimpleRangerHttpClient.java | 106 +++++++++++++ .../client/http/UnshardedHttpHubClient.java | 98 ++++++++++++ .../HttpShardedServiceFinderFactory.java | 76 ++++++++++ ranger-zk-client/pom.xml | 32 ++++ .../ranger/client/zk/AbstractZKHubClient.java | 90 ++++++++++++ .../ranger/client/zk/ShardedZKHubClient.java | 83 +++++++++++ .../client/zk/SimpleRangerZKClient.java | 139 ++++++++++++++++++ .../client/zk/UnshardedZKHubClient.java | 83 +++++++++++ .../BaseServiceProviderBuilderTest.java | 3 +- 18 files changed, 1185 insertions(+), 1 deletion(-) create mode 100644 ranger-client/pom.xml create mode 100644 ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java create mode 100644 ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java create mode 100644 ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java create mode 100644 ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java create mode 100644 ranger-http-client/pom.xml create mode 100644 ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java create mode 100644 ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java create mode 100644 ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java create mode 100644 ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java create mode 100644 ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java create mode 100644 ranger-zk-client/pom.xml create mode 100644 ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java create mode 100644 ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java create mode 100644 ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java create mode 100644 ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java diff --git a/pom.xml b/pom.xml index 1501e2a6..5e8c5b9c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,9 @@ ranger-core ranger-zookeeper ranger-http + ranger-client + ranger-zk-client + ranger-http-client diff --git a/ranger-client/pom.xml b/ranger-client/pom.xml new file mode 100644 index 00000000..39428abf --- /dev/null +++ b/ranger-client/pom.xml @@ -0,0 +1,37 @@ + + + + ranger + com.flipkart.ranger + 1.0-SNAPSHOT + + 4.0.0 + + ranger-client + + + 11 + 11 + + + + + com.flipkart.ranger + ranger-core + ${project.version} + + + com.flipkart.ranger + ranger-core + ${project.version} + test-jar + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + \ No newline at end of file diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java new file mode 100644 index 00000000..1ef00e93 --- /dev/null +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java @@ -0,0 +1,99 @@ +package com.flipkart.ranger.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceRegistry; +import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import java.util.List; +import java.util.Optional; + +@Slf4j +@Getter +public abstract class AbstractHubClient, R extends ServiceRegistry> implements RangerHubClient { + + private final String namespace; + private final String environment; + private final ObjectMapper mapper; + private final C criteria; + + private int refreshTimeMs; + private ServiceFinderHub hub; + + public AbstractHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + C criteria + ){ + this.namespace = namespace; + this.environment =environment; + this.mapper = mapper; + this.refreshTimeMs = refreshTimeMs; + this.criteria = criteria; + } + + public void start(){ + Preconditions.checkNotNull(mapper, "Mapper can't be null"); + Preconditions.checkNotNull(namespace, "namespace can't be null"); + Preconditions.checkNotNull(environment, "Environment can't be null"); + + if (this.refreshTimeMs < Constants.MINIMUM_REFRESH_TIME) { + log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", + this.refreshTimeMs, + Constants.MINIMUM_REFRESH_TIME); + } + this.refreshTimeMs = Math.max(Constants.MINIMUM_REFRESH_TIME, this.refreshTimeMs); + this.hub = buildHub(); + this.hub.start(); + } + + public void stop(){ + hub.stop(); + } + + public Optional> getNode( + final Service service + ){ + return getNode(service, criteria); + } + + public Optional>> getAllNodes( + final Service service + ){ + return getAllNodes(service, criteria); + } + + public Optional> getNode( + final Service service, + final C criteria + ){ + val optionalFinder = this.getHub().finder(service); + return optionalFinder.map(trcServiceFinder -> trcServiceFinder.get(criteria)); + } + + public Optional>> getAllNodes( + final Service service, + final C criteria + ){ + val optionalFinder = this.getHub().finder(service); + return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); + } + + public abstract ServiceFinderHub buildHub(); + + public abstract ServiceDataSource getServiceDataSource(); + + public abstract ServiceFinderFactory getFinderFactory(); + +} + diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java b/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java new file mode 100644 index 00000000..018aa9f3 --- /dev/null +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java @@ -0,0 +1,7 @@ +package com.flipkart.ranger.client; + +public class Constants { + + public static final int CONNECTION_RETRY_TIME = 5000; + public static final int MINIMUM_REFRESH_TIME = 5000; +} diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java new file mode 100644 index 00000000..5406b392 --- /dev/null +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java @@ -0,0 +1,42 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client; + +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.ServiceNode; + +import java.util.List; +import java.util.Optional; + +public interface RangerClient> { + + void start(); + + void stop(); + + Optional> getNode(); + + Optional> getNode( + final C criteria + ); + + Optional>> getAllNodes(); + + Optional>> getAllNodes( + final C criteria + ); +} diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java new file mode 100644 index 00000000..ec05a8fe --- /dev/null +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java @@ -0,0 +1,40 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client; + +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; + +import java.util.List; +import java.util.Optional; + +public interface RangerHubClient> { + + void start(); + + void stop(); + + Optional> getNode(final Service service); + + Optional> getNode(final Service service, final C criteria); + + Optional>> getAllNodes(final Service service); + + Optional>> getAllNodes(final Service service, final C criteria); + +} diff --git a/ranger-http-client/pom.xml b/ranger-http-client/pom.xml new file mode 100644 index 00000000..67adc469 --- /dev/null +++ b/ranger-http-client/pom.xml @@ -0,0 +1,33 @@ + + + + ranger + com.flipkart.ranger + 1.0-SNAPSHOT + + 4.0.0 + + ranger-http-client + + + + com.flipkart.ranger + ranger-http + ${project.version} + + + com.flipkart.ranger + ranger-client + ${project.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + + \ No newline at end of file diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java new file mode 100644 index 00000000..03fb5619 --- /dev/null +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java @@ -0,0 +1,115 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.Constants; +import com.flipkart.ranger.client.RangerHubClient; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.model.ServiceRegistry; +import com.google.common.base.Preconditions; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import java.util.List; +import java.util.Optional; + +@Slf4j +@Getter +public abstract class AbstractHttpHubClient, R extends ServiceRegistry> implements RangerHubClient { + + private ServiceFinderHub hub; + private String namespace; + private String environment; + private ObjectMapper mapper; + private int refreshTimeMs; + private C criteria; + + public AbstractHttpHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + C criteria + ){ + this.namespace = namespace; + this.environment =environment; + this.mapper = mapper; + this.refreshTimeMs = refreshTimeMs; + this.criteria = criteria; + } + + public void start(){ + Preconditions.checkNotNull(mapper, "Mapper can't be null"); + Preconditions.checkNotNull(namespace, "namespace can't be null"); + Preconditions.checkNotNull(environment, "Environment can't be null"); + + if (this.refreshTimeMs < Constants.MINIMUM_REFRESH_TIME) { + log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", + this.refreshTimeMs, + Constants.MINIMUM_REFRESH_TIME); + } + this.refreshTimeMs = Math.max(Constants.MINIMUM_REFRESH_TIME, this.refreshTimeMs); + this.hub = buildHub(); + this.hub.start(); + } + + public void stop(){ + hub.stop(); + } + + public Optional> getNode( + final Service service + ){ + return getNode(service, criteria); + } + + public Optional>> getAllNodes( + final Service service + ){ + return getAllNodes(service, criteria); + } + + public Optional> getNode( + final Service service, + final C criteria + ){ + val optionalFinder = this.getHub().finder(service); + return optionalFinder.map(trcServiceFinder -> trcServiceFinder.get(criteria)); + } + + public Optional>> getAllNodes( + final Service service, + final C criteria + ){ + val optionalFinder = this.getHub().finder(service); + return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); + } + + public abstract ServiceFinderHub buildHub(); + + public abstract ServiceDataSource getServiceDataSource(); + + public abstract ServiceFinderFactory getFinderFactory(); + +} + diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java new file mode 100644 index 00000000..1f6dca4d --- /dev/null +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java @@ -0,0 +1,100 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.http; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.StaticDataSource; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; +import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; +import com.flipkart.ranger.http.servicefinderhub.HttpShardedServiceFinderFactory; +import com.flipkart.ranger.http.servicefinderhub.HttpUnshardedServiceFinderFactory; +import lombok.Builder; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.List; + +@Slf4j +public class ShardedHttpHubClient> extends AbstractHttpHubClient> { + + private List services; + private final HttpClientConfig clientConfig; + + @Builder + public ShardedHttpHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + C criteria, + HttpClientConfig clientConfig, + List services + ) { + super(namespace, environment, mapper, refreshTimeMs, criteria); + this.clientConfig = clientConfig; + this.services = services; + } + + @Override + public ServiceFinderHub> buildHub() { + return new HttpServiceFinderHubBuilder>() + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withRefreshFrequencyMs(getRefreshTimeMs()) + .build(); + } + + /* + In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. + */ + @Override + public ServiceDataSource getServiceDataSource() { + return null != services && !services.isEmpty() ? + new StaticDataSource(services) : + new HttpServiceDataSource<>(clientConfig, getMapper()); + } + + @Override + public ServiceFinderFactory> getFinderFactory() { + return HttpShardedServiceFinderFactory.builder() + .httpClientConfig(clientConfig) + .nodeRefreshIntervalMs(getRefreshTimeMs()) + .deserializer(data -> { + try{ + return getMapper().readValue(data, new TypeReference>() {}); + }catch (IOException e){ + log.warn("Could not parse node data"); + } + return null; + }) + .shardSelector(new MatchingShardSelector<>()) + .nodeSelector(new RoundRobinServiceNodeSelector<>()) + .build(); + } +} diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java new file mode 100644 index 00000000..6c83d658 --- /dev/null +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java @@ -0,0 +1,106 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.http; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.RangerClient; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.http.HttpServiceFinderBuilders; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.google.common.base.Preconditions; +import lombok.Builder; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.List; +import java.util.Optional; + +@Slf4j +public class SimpleRangerHttpClient> implements RangerClient { + + private final C criteria; + private final SimpleUnshardedServiceFinder serviceFinder; + + @Builder + public SimpleRangerHttpClient( + String namespace, + String serviceName, + ObjectMapper mapper, + int refreshTimeMs, + HttpClientConfig clientConfig, + C criteria + ) { + Preconditions.checkNotNull(mapper, "Mapper can't be null"); + Preconditions.checkNotNull(namespace, "namespace can't be null"); + this.criteria = criteria; + + this.serviceFinder = HttpServiceFinderBuilders.httpUnshardedServiceFinderBuilider() + .withClientConfig(clientConfig) + .withServiceName(serviceName) + .withNamespace(namespace) + .withObjectMapper(mapper) + .withNodeRefreshIntervalMs(refreshTimeMs) + .withDeserializer(data -> { + try { + return mapper.readValue(data, new TypeReference>() { + }); + } catch (IOException e) { + log.warn("Could not parse node data"); + } + return null; + }) + .withShardSelector(new ListShardSelector<>()) + .build(); + } + + @Override + public void start() { + log.info("Starting the service finder"); + this.serviceFinder.start(); + } + + @Override + public void stop() { + log.info("Stopping the service finder"); + this.serviceFinder.stop(); + } + + @Override + public Optional> getNode() { + return getNode(criteria); + } + + @Override + public Optional>> getAllNodes() { + return getAllNodes(criteria); + } + + @Override + public Optional> getNode(C criteria) { + return Optional.ofNullable(this.serviceFinder.get(criteria)); + } + + @Override + public Optional>> getAllNodes(C criteria) { + return Optional.ofNullable(this.serviceFinder.getAll(criteria)); + } +} + diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java new file mode 100644 index 00000000..23ab3398 --- /dev/null +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java @@ -0,0 +1,98 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.http; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.RangerHubClient; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.StaticDataSource; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; +import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; +import com.flipkart.ranger.http.servicefinderhub.HttpUnshardedServiceFinderFactory; +import lombok.Builder; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.List; + +@Slf4j +public class UnshardedHttpHubClient> extends AbstractHttpHubClient> { + + private List services; + private final HttpClientConfig clientConfig; + + @Builder + public UnshardedHttpHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + C criteria, + HttpClientConfig clientConfig, + List services + ) { + super(namespace, environment, mapper, refreshTimeMs, criteria); + this.clientConfig = clientConfig; + this.services = services; + } + + @Override + public ServiceFinderHub> buildHub() { + return new HttpServiceFinderHubBuilder>() + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withRefreshFrequencyMs(getRefreshTimeMs()) + .build(); + } + + /* + In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. + */ + @Override + public ServiceDataSource getServiceDataSource() { + return null != services && !services.isEmpty() ? + new StaticDataSource(services) : + new HttpServiceDataSource<>(clientConfig, getMapper()); + } + + @Override + public ServiceFinderFactory> getFinderFactory() { + return HttpUnshardedServiceFinderFactory.builder() + .httpClientConfig(clientConfig) + .nodeRefreshIntervalMs(getRefreshTimeMs()) + .deserializer(data -> { + try{ + return getMapper().readValue(data, new TypeReference>() {}); + }catch (IOException e){ + log.warn("Could not parse node data"); + } + return null; + }) + .shardSelector(new ListShardSelector<>()) + .nodeSelector(new RoundRobinServiceNodeSelector<>()) + .build(); + } +} diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java new file mode 100644 index 00000000..da6dfc8f --- /dev/null +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java @@ -0,0 +1,76 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.http.servicefinderhub; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNodeSelector; +import com.flipkart.ranger.core.model.ShardSelector; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import com.flipkart.ranger.http.servicefinder.HttpShardedServiceFinderBuilder; +import lombok.Builder; +import lombok.Getter; +import lombok.val; + +@Getter +public class HttpShardedServiceFinderFactory > implements ServiceFinderFactory> { + + private final HttpClientConfig clientConfig; + private final ObjectMapper mapper; + private final HTTPResponseDataDeserializer deserializer; + private final ShardSelector> shardSelector; + private final ServiceNodeSelector nodeSelector; + private final int nodeRefreshIntervalMs; + + @Builder + public HttpShardedServiceFinderFactory( + HttpClientConfig httpClientConfig, + ObjectMapper mapper, + HTTPResponseDataDeserializer deserializer, + ShardSelector> shardSelector, + ServiceNodeSelector nodeSelector, + int nodeRefreshIntervalMs) + { + this.clientConfig = httpClientConfig; + this.mapper = mapper; + this.deserializer = deserializer; + this.shardSelector = shardSelector; + this.nodeSelector = nodeSelector; + this.nodeRefreshIntervalMs = nodeRefreshIntervalMs; + } + + @Override + public ServiceFinder> buildFinder(Service service) { + val serviceFinder = new HttpShardedServiceFinderBuilder() + .withClientConfig(clientConfig) + .withObjectMapper(mapper) + .withDeserializer(deserializer) + .withNamespace(service.getNamespace()) + .withServiceName(service.getServiceName()) + .withNodeRefreshIntervalMs(nodeRefreshIntervalMs) + .withShardSelector(shardSelector) + .withNodeSelector(nodeSelector) + .build(); + serviceFinder.start(); + return serviceFinder; + } +} diff --git a/ranger-zk-client/pom.xml b/ranger-zk-client/pom.xml new file mode 100644 index 00000000..11cf2772 --- /dev/null +++ b/ranger-zk-client/pom.xml @@ -0,0 +1,32 @@ + + + + ranger + com.flipkart.ranger + 1.0-SNAPSHOT + + 4.0.0 + + ranger-zk-client + + + + com.flipkart.ranger + ranger-zookeeper + ${project.version} + + + com.flipkart.ranger + ranger-client + ${project.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + \ No newline at end of file diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java new file mode 100644 index 00000000..fdb265c2 --- /dev/null +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -0,0 +1,90 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.AbstractHubClient; +import com.flipkart.ranger.core.finderhub.ServiceDataSource; +import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.StaticDataSource; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceRegistry; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryForever; + +import java.util.List; + +@Slf4j +@Getter +public abstract class AbstractZKHubClient, R extends ServiceRegistry> extends AbstractHubClient { + + private final boolean disablePushUpdaters; + private final String connectionString; + private final CuratorFramework curatorFramework; + private final List services; + + public AbstractZKHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + boolean disablePushUpdaters, + String connectionString, + CuratorFramework curatorFramework, + C criteria, + List services + ) { + super(namespace, environment, mapper, refreshTimeMs, criteria); + this.disablePushUpdaters = disablePushUpdaters; + this.connectionString = connectionString; + this.curatorFramework = null != curatorFramework ? curatorFramework : + CuratorFrameworkFactory.builder() + .namespace(namespace) + .connectString(this.connectionString) + .retryPolicy(new RetryForever(5000)) + .build(); + this.services = services; + } + + @Override + public ServiceFinderHub buildHub() { + return new ZkServiceFinderHubBuilder() + .withCuratorFramework(curatorFramework) + .withConnectionString(connectionString) + .withNamespace(getNamespace()) + .withRefreshFrequencyMs(getRefreshTimeMs()) + .withServiceDataSource(getServiceDataSource()) + .withServiceFinderFactory(getFinderFactory()) + .withExtraStartSignalConsumer(x -> curatorFramework.start()) + .withExtraStopSignalConsumer(x -> curatorFramework.start()) + .build(); + } + + @Override + public ServiceDataSource getServiceDataSource() { + return null != services && !services.isEmpty() ? + new StaticDataSource(services) : + new ZkServiceDataSource(getNamespace(), connectionString, curatorFramework); + } + +} + diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java new file mode 100644 index 00000000..82ae877c --- /dev/null +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -0,0 +1,83 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; +import lombok.Builder; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; + +import java.io.IOException; +import java.util.List; + +@Slf4j +public class ShardedZKHubClient> extends AbstractZKHubClient> { + + @Builder + public ShardedZKHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + boolean disablePushUpdaters, + String connectionString, + CuratorFramework curatorFramework, + C criteria, + List services + ) { + super( + namespace, + environment, + mapper, + refreshTimeMs, + disablePushUpdaters, + connectionString, + curatorFramework, + criteria, + services + ); + } + + @Override + public ServiceFinderFactory> getFinderFactory() { + return ZkShardedServiceFinderFactory.builder() + .curatorFramework(getCuratorFramework()) + .connectionString(getConnectionString()) + .nodeRefreshIntervalMs(getRefreshTimeMs()) + .disablePushUpdaters(isDisablePushUpdaters()) + .deserializer(data -> { + try{ + return getMapper().readValue(data, new TypeReference>() {}); + }catch (IOException e){ + log.warn("Could not parse node data"); + } + return null; + }) + .shardSelector(new MatchingShardSelector<>()) + .nodeSelector(new RoundRobinServiceNodeSelector<>()) + .build(); + } +} + diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java new file mode 100644 index 00000000..5a201111 --- /dev/null +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java @@ -0,0 +1,139 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.Constants; +import com.flipkart.ranger.client.RangerClient; +import com.flipkart.ranger.core.finder.SimpleShardedServiceFinder; +import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; +import com.google.common.base.Preconditions; +import lombok.Builder; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryForever; + +import java.io.IOException; +import java.util.List; +import java.util.Optional; + +@Slf4j +@Getter +public class SimpleRangerZKClient> implements RangerClient { + + private SimpleShardedServiceFinder serviceFinder; + private C criteria; + + @Builder(builderMethodName = "fromConnectionString", builderClassName = "FromConnectionStringBuilder") + public SimpleRangerZKClient( + String namespace, + String serviceName, + ObjectMapper mapper, + int refreshTimeMs, + boolean disableWatchers, + String connectionString, + C criteria + ){ + this( + namespace, + serviceName, + mapper, + refreshTimeMs, + disableWatchers, + CuratorFrameworkFactory.newClient(connectionString, new RetryForever(Constants.CONNECTION_RETRY_TIME)), + criteria + ); + } + + @Builder(builderMethodName = "fromCurator", builderClassName = "FromCuratorBuilder") + public SimpleRangerZKClient( + String namespace, + String serviceName, + ObjectMapper mapper, + int refreshTimeMs, + boolean disableWatchers, + CuratorFramework curatorFramework, + C criteria + ){ + Preconditions.checkNotNull(mapper, "Mapper can't be null"); + Preconditions.checkNotNull(namespace, "namespace can't be null"); + + int effectiveRefreshTime = refreshTimeMs; + if (effectiveRefreshTime < Constants.MINIMUM_REFRESH_TIME) { + effectiveRefreshTime = Constants.MINIMUM_REFRESH_TIME; + log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", + refreshTimeMs, + Constants.MINIMUM_REFRESH_TIME); + } + + this.criteria = criteria; + this.serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() + .withCuratorFramework(curatorFramework) + .withNamespace(namespace) + .withServiceName(serviceName) + .withDeserializer(data -> { + try{ + return mapper.readValue(data, new TypeReference>() { + }); + }catch (IOException e){ + log.info("Could not parse node data"); + return null; + } + }) + .withNodeRefreshIntervalMs(effectiveRefreshTime) + .withDisableWatchers(disableWatchers) + .withShardSelector(new MatchingShardSelector<>()) + .build(); + } + + @Override + public void start() { + log.info("Starting the service finder"); + this.serviceFinder.start(); + } + + @Override + public void stop() { + log.info("Stopping the service finder"); + this.serviceFinder.stop(); + } + + @Override + public Optional> getNode() { + return getNode(criteria); + } + + @Override + public Optional>> getAllNodes() { + return getAllNodes(criteria); + } + + @Override + public Optional> getNode(C criteria) { + return Optional.ofNullable(this.serviceFinder.get(criteria)); + } + + @Override + public Optional>> getAllNodes(C criteria) { + return Optional.ofNullable(this.serviceFinder.getAll(criteria)); + } +} diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java new file mode 100644 index 00000000..44c062aa --- /dev/null +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -0,0 +1,83 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.zookeeper.servicefinderhub.ZKUnshardedServiceFinderFactory; +import lombok.Builder; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; + +import java.io.IOException; +import java.util.List; + +@Slf4j +public class UnshardedZKHubClient> extends AbstractZKHubClient> { + + @Builder + public UnshardedZKHubClient( + String namespace, + String environment, + ObjectMapper mapper, + int refreshTimeMs, + boolean disablePushUpdaters, + String connectionString, + CuratorFramework curatorFramework, + C criteria, + List services + ) { + super( + namespace, + environment, + mapper, + refreshTimeMs, + disablePushUpdaters, + connectionString, + curatorFramework, + criteria, + services + ); + } + + @Override + public ServiceFinderFactory> getFinderFactory() { + return ZKUnshardedServiceFinderFactory.builder() + .curatorFramework(getCuratorFramework()) + .connectionString(getConnectionString()) + .nodeRefreshIntervalMs(getRefreshTimeMs()) + .disablePushUpdaters(isDisablePushUpdaters()) + .deserializer(data -> { + try{ + return getMapper().readValue(data, new TypeReference>() {}); + }catch (IOException e){ + log.warn("Could not parse node data"); + } + return null; + }) + .shardSelector(new ListShardSelector<>()) + .nodeSelector(new RoundRobinServiceNodeSelector<>()) + .build(); + } + +} diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java index 110f9dd7..9b8f23d3 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java @@ -52,7 +52,7 @@ public void stopTestCluster() throws Exception { } @Test - public void testbuilder() throws Exception { + public void testbuilder() { final String host = "localhost"; final int port = 9000; Exception exception = null; @@ -95,5 +95,6 @@ public void testbuilder() throws Exception { .withPort(port) .withHealthUpdateIntervalMs(1000) .build(); + serviceProvider.start(); } } \ No newline at end of file From f9a6150615549121e762c55c7f37923786992cf3 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 10:37:23 +0530 Subject: [PATCH 40/53] Optimized imports --- .../core/finder/shardselector/MatchingShardSelector.java | 1 - .../flipkart/ranger/core/finder/SimpleShardFinderTest.java | 1 - .../com/flipkart/ranger/client/http/ShardedHttpHubClient.java | 3 --- .../flipkart/ranger/client/http/UnshardedHttpHubClient.java | 1 - .../servicefinder/HttpUnshardedServiceFinderBuilider.java | 4 +++- .../servicefinderhub/HttpShardedServiceFinderFactory.java | 1 - .../servicefinder/HttpShardedServiceFinderBuilderTest.java | 3 --- 7 files changed, 3 insertions(+), 11 deletions(-) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index c9f4f0e3..7d3f0af3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -19,7 +19,6 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.model.ShardSelector; import java.util.List; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index df14bb2a..9cb5e4fd 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -19,7 +19,6 @@ import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceRegistry; import com.flipkart.ranger.core.model.ShardSelector; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.utils.CriteriaUtils; diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java index 1f6dca4d..b929d292 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java @@ -18,9 +18,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; -import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; @@ -33,7 +31,6 @@ import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; import com.flipkart.ranger.http.servicefinderhub.HttpShardedServiceFinderFactory; -import com.flipkart.ranger.http.servicefinderhub.HttpUnshardedServiceFinderFactory; import lombok.Builder; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java index 23ab3398..409570f6 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.client.RangerHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index a0a465b3..cf385cd9 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -18,7 +18,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.model.*; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.NodeDataSource; +import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java index da6dfc8f..ee12171a 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java @@ -17,7 +17,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.ServiceFinder; -import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.model.Criteria; diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index 6139a2bd..eaa3b709 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -23,7 +23,6 @@ import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.github.tomakehurst.wiremock.junit.WireMockRule; @@ -34,8 +33,6 @@ import org.junit.Test; import java.io.IOException; -import java.util.Map; -import java.util.stream.Collectors; import static com.github.tomakehurst.wiremock.client.WireMock.*; From 2165ae8a5d513ffd43631084799b67a208b8b43c Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 11:51:54 +0530 Subject: [PATCH 41/53] Added ranger server bundle to be used as a finder for any http service you may want to build --- pom.xml | 1 + .../ranger/client/AbstractHubClient.java | 6 +- .../core/finderhub/ServiceFinderHub.java | 1 + .../http/model/ServiceDataSourceResponse.java | 2 +- .../http/model/ServiceNodesResponse.java | 6 +- .../servicefinder/HttpNodeDataSource.java | 8 +- .../HttpServiceDataSource.java | 4 +- .../serviceprovider/HttpNodeDataSink.java | 2 +- .../http/model/ServiceNodeResponseTest.java | 10 +-- .../HttpServiceDataSourceTest.java | 2 +- .../fixtures/serviceNodesResponse.json | 2 +- ranger-server/pom.xml | 36 ++++++++ .../ranger/server/GenericResponse.java | 29 +++++++ .../ranger/server/RangerClientManager.java | 82 +++++++++++++++++++ .../ranger/server/RangerConfiguration.java | 51 ++++++++++++ .../ranger/server/RangerResource.java | 75 +++++++++++++++++ .../ranger/server/RangerServerBundle.java | 49 +++++++++++ .../ranger/client/zk/AbstractZKHubClient.java | 7 +- .../ranger/client/zk/ShardedZKHubClient.java | 2 - .../client/zk/UnshardedZKHubClient.java | 2 - 20 files changed, 346 insertions(+), 31 deletions(-) create mode 100644 ranger-server/pom.xml create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java create mode 100644 ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java diff --git a/pom.xml b/pom.xml index 5e8c5b9c..7cc0da22 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ ranger-client ranger-zk-client ranger-http-client + ranger-server diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java index 1ef00e93..6a51ce0f 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java @@ -21,7 +21,6 @@ public abstract class AbstractHubClient, R extends ServiceRegistry> implements RangerHubClient { private final String namespace; - private final String environment; private final ObjectMapper mapper; private final C criteria; @@ -30,13 +29,11 @@ public abstract class AbstractHubClient, R extends Serv public AbstractHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, C criteria ){ this.namespace = namespace; - this.environment =environment; this.mapper = mapper; this.refreshTimeMs = refreshTimeMs; this.criteria = criteria; @@ -45,7 +42,6 @@ public AbstractHubClient( public void start(){ Preconditions.checkNotNull(mapper, "Mapper can't be null"); Preconditions.checkNotNull(namespace, "namespace can't be null"); - Preconditions.checkNotNull(environment, "Environment can't be null"); if (this.refreshTimeMs < Constants.MINIMUM_REFRESH_TIME) { log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", @@ -91,7 +87,7 @@ public Optional>> getAllNodes( public abstract ServiceFinderHub buildHub(); - public abstract ServiceDataSource getServiceDataSource(); + public abstract ServiceDataSource buildServiceDataSource(); public abstract ServiceFinderFactory getFinderFactory(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index 92a8daf1..d41918b5 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -58,6 +58,7 @@ public class ServiceFinderHub, R extends ServiceRegistr private final List> refreshSignals = new ArrayList<>(); + @Getter private final ServiceDataSource serviceDataSource; private final ServiceFinderFactory finderFactory; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java index 613a1a74..bfd498b9 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java @@ -27,5 +27,5 @@ @Builder public class ServiceDataSourceResponse { private boolean success; - private List services; + private List data; } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index b7f7ff21..122ea4df 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -29,13 +29,13 @@ @Data public class ServiceNodesResponse { private final boolean success; - final List> nodes; + final List> data; @Builder public ServiceNodesResponse( @JsonProperty("success") boolean success, - @JsonProperty("nodes") @Singular List> nodes) { + @JsonProperty("data") @Singular List> data) { this.success = success; - this.nodes = nodes; + this.data = data; } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index be15a2bd..7dc6aa44 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -64,7 +64,7 @@ public Optional>> refresh(D deserializer) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/ranger/nodes/v1/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/v1/ranger/nodes/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val request = new Request.Builder() .url(httpUrl) @@ -88,11 +88,11 @@ public Optional>> refresh(D deserializer) { Exceptions.illegalState("Error fetching data from server: " + httpUrl, e); } - if (null != serviceNodesResponse && null != serviceNodesResponse.getNodes() && - !serviceNodesResponse.getNodes().isEmpty()) { + if (null != serviceNodesResponse && null != serviceNodesResponse.getData() && + !serviceNodesResponse.getData().isEmpty()) { return Optional.of(FinderUtils.filterValidNodes( service, - serviceNodesResponse.getNodes(), + serviceNodesResponse.getData(), healthcheckZombieCheckThresholdTime(service))); } return Optional.empty(); diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java index 598db12c..7772dc77 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -53,7 +53,7 @@ public Collection services() { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath("/ranger/services") + .encodedPath("/v1/ranger/services") .build(); val request = new Request.Builder() .url(httpUrl) @@ -70,7 +70,7 @@ public Collection services() { final byte[] bytes = body.bytes(); val serviceDataSourceResponse = mapper.readValue(bytes, ServiceDataSourceResponse.class); if(serviceDataSourceResponse.isSuccess()){ - return serviceDataSourceResponse.getServices(); + return serviceDataSourceResponse.getData(); } } } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index 1ddfa458..cb534049 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -58,7 +58,7 @@ public void updateState(S serializer, ServiceNode serviceNode) { .port(config.getPort() == 0 ? defaultPort() : config.getPort()) - .encodedPath(String.format("/ranger/nodes/v1/add/%s/%s", service.getNamespace(), service.getServiceName())) + .encodedPath(String.format("/v1/ranger/nodes/add/%s/%s", service.getNamespace(), service.getServiceName())) .build(); val requestBody = RequestBody.create(serializer.serialize(serviceNode)); val serviceRegistrationResponse = registerService(httpUrl, requestBody); diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java index a26e70e6..74cd0e5b 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java @@ -36,10 +36,10 @@ static class TestNodeInfo{ public void testServiceNodesResponse(){ val serviceNodesResponse = ResourceHelper.getResource("fixtures/serviceNodesResponse.json", ServiceNodesResponse.class); Assert.assertNotNull(serviceNodesResponse); - Assert.assertFalse(serviceNodesResponse.getNodes().isEmpty()); - Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getNodes().get(0)).getNodeData()); - Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getNodes().get(1)).getNodeData()); - Assert.assertEquals(((ServiceNode) serviceNodesResponse.getNodes().get(0)).getHost(), "localhost-1"); - Assert.assertEquals(((ServiceNode) serviceNodesResponse.getNodes().get(1)).getHost(), "localhost-2"); + Assert.assertFalse(serviceNodesResponse.getData().isEmpty()); + Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getData().get(0)).getNodeData()); + Assert.assertNotNull(((ServiceNode) serviceNodesResponse.getData().get(1)).getNodeData()); + Assert.assertEquals(((ServiceNode) serviceNodesResponse.getData().get(0)).getHost(), "localhost-1"); + Assert.assertEquals(((ServiceNode) serviceNodesResponse.getData().get(1)).getHost(), "localhost-2"); } } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index e61485e3..2863e62b 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -55,7 +55,7 @@ public TestNodeData(@JsonProperty("farmId") String farmId) { public void testServiceDataSource() throws IOException { val responseObj = ServiceDataSourceResponse.builder() .success(true) - .services(Lists.newArrayList( + .data(Lists.newArrayList( new Service("test-n", "test-s"), new Service("test-n", "test-s1"), new Service("test-n", "test-s2") diff --git a/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json index 8b8cb917..e5a60b29 100644 --- a/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json +++ b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json @@ -1,6 +1,6 @@ { "success" : true, - "nodes" : [ + "data" : [ { "host" : "localhost-1", "port" : 80, diff --git a/ranger-server/pom.xml b/ranger-server/pom.xml new file mode 100644 index 00000000..609cb589 --- /dev/null +++ b/ranger-server/pom.xml @@ -0,0 +1,36 @@ + + + + ranger + com.flipkart.ranger + 1.0-SNAPSHOT + + 4.0.0 + + ranger-server + + + 2.0.23 + + + + + com.flipkart.ranger + ranger-zk-client + ${project.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + io.dropwizard + dropwizard-core + ${dropwizard.version} + + + + \ No newline at end of file diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java b/ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java new file mode 100644 index 00000000..2fd4bb5b --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java @@ -0,0 +1,29 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.server; + +import lombok.*; + +@Builder +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class GenericResponse { + + private boolean success; + private T data; +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java new file mode 100644 index 00000000..c159c7ad --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java @@ -0,0 +1,82 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.server; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.Constants; +import com.flipkart.ranger.client.zk.UnshardedZKHubClient; +import com.flipkart.ranger.core.model.Criteria; +import com.google.common.base.Preconditions; +import io.dropwizard.lifecycle.Managed; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.RetryForever; + +import javax.inject.Inject; +import javax.inject.Singleton; + +@Slf4j +@Singleton +@Getter +public class RangerClientManager> implements Managed { + + private final RangerConfiguration rangerConfiguration; + + private UnshardedZKHubClient zkHubClient; + private CuratorFramework curatorFramework; + + @Inject + public RangerClientManager( + RangerConfiguration rangerConfiguration, + ObjectMapper mapper + ){ + this.rangerConfiguration = rangerConfiguration; + Preconditions.checkNotNull(rangerConfiguration, "Ranger configuration can't be null"); + Preconditions.checkNotNull(rangerConfiguration.getZookeeper(), "Zookeeper can't be null"); + Preconditions.checkNotNull(rangerConfiguration.getNamespace(), "Namespace can't be null"); + + curatorFramework = CuratorFrameworkFactory.newClient( + rangerConfiguration.getZookeeper(), + new RetryForever(Constants.CONNECTION_RETRY_TIME) + ); + zkHubClient = UnshardedZKHubClient.builder() + .connectionString(rangerConfiguration.getZookeeper()) + .curatorFramework(curatorFramework) + .disablePushUpdaters(rangerConfiguration.isDisablePushUpdaters()) + .mapper(mapper) + .services(rangerConfiguration.getServices()) + .refreshTimeMs(rangerConfiguration.getRefreshTimeMs()) + .build(); + } + + @Override + public void start() { + log.info("Starting the ranger client manager"); + curatorFramework.start(); + zkHubClient.start(); + log.info("Started the ranger client manager"); + } + + @Override + public void stop() { + log.info("Stopping the ranger client manager"); + zkHubClient.stop(); + curatorFramework.close(); + log.info("Stopped the ranger client manager"); + } +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java new file mode 100644 index 00000000..a1abee72 --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java @@ -0,0 +1,51 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.server; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.flipkart.ranger.client.Constants; +import com.flipkart.ranger.core.model.Service; +import lombok.*; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@Data +@Builder +@JsonIgnoreProperties(ignoreUnknown = true) +public class RangerConfiguration { + + @NotEmpty + @NotNull + private String zookeeper; + + @NotEmpty + @NotNull + private String namespace; + + @Min(1000) + private int refreshTimeMs = Constants.MINIMUM_REFRESH_TIME; + + private boolean disablePushUpdaters = true; + + private List services; // Specify these if you don't want to use the data source! +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java new file mode 100644 index 00000000..c4d2cadd --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java @@ -0,0 +1,75 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.server; + +import com.codahale.metrics.annotation.ExceptionMetered; +import com.codahale.metrics.annotation.Timed; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import lombok.extern.slf4j.Slf4j; +import lombok.val; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; + +@Slf4j +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +@Path("/v1/ranger") +public class RangerResource> { + + private final RangerClientManager clientManager; + + public RangerResource(RangerClientManager clientManager){ + this.clientManager = clientManager; + } + + @GET + @Path("/services") + @Timed + @ExceptionMetered + public GenericResponse> getServices() throws Exception { + val serviceDataSource = clientManager.getZkHubClient().getHub().getServiceDataSource(); + return GenericResponse.>builder() + .success(true) + .data(serviceDataSource.services()) + .build(); + } + + @GET + @Path("/nodes/{namespace}/{serviceName}") + @Timed + @ExceptionMetered + public GenericResponse>> getNodes( + @NotNull @NotEmpty @PathParam("namespace") final String namespace, + @NotNull @NotEmpty @PathParam("serviceName") final String serviceName + ){ + val service = new Service(namespace, serviceName); + Optional>> nodeList = clientManager.getZkHubClient().getAllNodes( + service, null); + return GenericResponse.>>builder() + .success(true) + .data(nodeList.orElse(Collections.emptyList())) + .build(); + } +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java new file mode 100644 index 00000000..2c141a52 --- /dev/null +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java @@ -0,0 +1,49 @@ +/** + * Copyright 2015 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 com.flipkart.ranger.server; + +import com.flipkart.ranger.client.zk.UnshardedZKHubClient; +import com.flipkart.ranger.core.model.Criteria; +import io.dropwizard.Configuration; +import io.dropwizard.ConfiguredBundle; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.apache.curator.framework.CuratorFramework; + +@Slf4j +public abstract class RangerServerBundle, U extends Configuration> implements ConfiguredBundle { + + private UnshardedZKHubClient zkHubClient; + private CuratorFramework curatorFramework; + + protected abstract RangerConfiguration getRangerConfiguration(U configuration); + + @Override + public void initialize(Bootstrap bootstrap) { + + } + + @Override + public void run(U configuration, Environment environment) { + val rangerConfiguration = getRangerConfiguration(configuration); + val clientManager = new RangerClientManager(rangerConfiguration, environment.getObjectMapper()); + val rangerResource = new RangerResource<>(clientManager); + environment.lifecycle().manage(clientManager); + environment.jersey().register(rangerResource); + } +} diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java index fdb265c2..d95b2d73 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -44,7 +44,6 @@ public abstract class AbstractZKHubClient, R extends Se public AbstractZKHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, boolean disablePushUpdaters, @@ -53,7 +52,7 @@ public AbstractZKHubClient( C criteria, List services ) { - super(namespace, environment, mapper, refreshTimeMs, criteria); + super(namespace, mapper, refreshTimeMs, criteria); this.disablePushUpdaters = disablePushUpdaters; this.connectionString = connectionString; this.curatorFramework = null != curatorFramework ? curatorFramework : @@ -72,7 +71,7 @@ public ServiceFinderHub buildHub() { .withConnectionString(connectionString) .withNamespace(getNamespace()) .withRefreshFrequencyMs(getRefreshTimeMs()) - .withServiceDataSource(getServiceDataSource()) + .withServiceDataSource(buildServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) .withExtraStartSignalConsumer(x -> curatorFramework.start()) .withExtraStopSignalConsumer(x -> curatorFramework.start()) @@ -80,7 +79,7 @@ public ServiceFinderHub buildHub() { } @Override - public ServiceDataSource getServiceDataSource() { + public ServiceDataSource buildServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new ZkServiceDataSource(getNamespace(), connectionString, curatorFramework); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java index 82ae877c..8be46bcd 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -38,7 +38,6 @@ public class ShardedZKHubClient> extends AbstractZKHubC @Builder public ShardedZKHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, boolean disablePushUpdaters, @@ -49,7 +48,6 @@ public ShardedZKHubClient( ) { super( namespace, - environment, mapper, refreshTimeMs, disablePushUpdaters, diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java index 44c062aa..eddee73b 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -38,7 +38,6 @@ public class UnshardedZKHubClient> extends AbstractZKHu @Builder public UnshardedZKHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, boolean disablePushUpdaters, @@ -49,7 +48,6 @@ public UnshardedZKHubClient( ) { super( namespace, - environment, mapper, refreshTimeMs, disablePushUpdaters, From 431ada04ec5f657f5af9ea00d800427c5af958e6 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 12:03:26 +0530 Subject: [PATCH 42/53] Optimized imports and fixed tests for URL path changes --- .../com/flipkart/ranger/http/model/ServiceNodesResponse.java | 2 +- .../flipkart/ranger/http/model/ServiceNodeResponseTest.java | 2 +- .../servicefinder/HttpShardedServiceFinderBuilderTest.java | 5 +++-- .../http/servicefinderhub/HttpServiceDataSourceTest.java | 2 +- .../HttpShardedServiceProviderBuilderTest.java | 2 +- .../src/test/resources/fixtures/serviceNodesResponse.json | 4 ++-- .../java/com/flipkart/ranger/server/RangerServerBundle.java | 5 ----- 7 files changed, 9 insertions(+), 13 deletions(-) diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 122ea4df..37c829de 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -34,7 +34,7 @@ public class ServiceNodesResponse { @Builder public ServiceNodesResponse( @JsonProperty("success") boolean success, - @JsonProperty("data") @Singular List> data) { + @JsonProperty("data") List> data) { this.success = success; this.data = data; } diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java index 74cd0e5b..8c1f6f40 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/model/ServiceNodeResponseTest.java @@ -29,7 +29,7 @@ public class ServiceNodeResponseTest { @Setter static class TestNodeInfo{ private int shardId; - private String farmId; + private String region; } @Test diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java index eaa3b709..e01acac9 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilderTest.java @@ -26,6 +26,7 @@ import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.google.common.collect.Lists; import lombok.Data; import lombok.val; import org.junit.Assert; @@ -63,10 +64,10 @@ public void testFinder() throws Exception { node.setLastUpdatedTimeStamp(System.currentTimeMillis()); val payload = MAPPER.writeValueAsBytes( ServiceNodesResponse.builder() - .node(node) + .data(Lists.newArrayList(node)) .success(true) .build()); - server.stubFor(get(urlEqualTo("/ranger/nodes/v1/testns/test")) + server.stubFor(get(urlEqualTo("/v1/ranger/nodes/testns/test")) .willReturn(aResponse() .withBody(payload) .withStatus(200))); diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java index 2863e62b..d5420f68 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSourceTest.java @@ -62,7 +62,7 @@ public void testServiceDataSource() throws IOException { )) .build(); val response = MAPPER.writeValueAsBytes(responseObj); - server.stubFor(get(urlEqualTo("/ranger/services")) + server.stubFor(get(urlEqualTo("/v1/ranger/services")) .willReturn(aResponse() .withBody(response) .withStatus(200))); diff --git a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java index 574b7b7e..3c325024 100644 --- a/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java +++ b/ranger-http/src/test/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilderTest.java @@ -58,7 +58,7 @@ public void testProvider() throws Exception { .success(true) .build()); byte[] requestBytes = MAPPER.writeValueAsBytes(testNode); - server.stubFor(post(urlEqualTo("/ranger/nodes/v1/add/testns/test")) + server.stubFor(post(urlEqualTo("/v1/ranger/nodes/add/testns/test")) .withRequestBody(binaryEqualTo(requestBytes)) .willReturn(aResponse() .withBody(response) diff --git a/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json index e5a60b29..7ac55a8e 100644 --- a/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json +++ b/ranger-http/src/test/resources/fixtures/serviceNodesResponse.json @@ -6,7 +6,7 @@ "port" : 80, "nodeData" : { "shardId" : 1, - "farmId" : "nb1" + "region" : "r1" }, "healthcheckStatus" : "healthy" }, @@ -15,7 +15,7 @@ "port" : 90, "nodeData" : { "shardId" : 2, - "farmId" : "nm5" + "region" : "r2" }, "healthcheckStatus" : "healthy" } diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java index 2c141a52..ad233a39 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.server; -import com.flipkart.ranger.client.zk.UnshardedZKHubClient; import com.flipkart.ranger.core.model.Criteria; import io.dropwizard.Configuration; import io.dropwizard.ConfiguredBundle; @@ -23,14 +22,10 @@ import io.dropwizard.setup.Environment; import lombok.extern.slf4j.Slf4j; import lombok.val; -import org.apache.curator.framework.CuratorFramework; @Slf4j public abstract class RangerServerBundle, U extends Configuration> implements ConfiguredBundle { - private UnshardedZKHubClient zkHubClient; - private CuratorFramework curatorFramework; - protected abstract RangerConfiguration getRangerConfiguration(U configuration); @Override From 20c73ee2e963bd7fe7f59c7041cd4d7b487c3d53 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 12:06:33 +0530 Subject: [PATCH 43/53] Changed the access qualifier to protected in clients --- .../java/com/flipkart/ranger/client/AbstractHubClient.java | 6 +++--- .../flipkart/ranger/client/http/AbstractHttpHubClient.java | 6 +++--- .../flipkart/ranger/client/http/ShardedHttpHubClient.java | 6 +++--- .../flipkart/ranger/client/http/UnshardedHttpHubClient.java | 6 +++--- .../com/flipkart/ranger/client/zk/AbstractZKHubClient.java | 4 ++-- .../com/flipkart/ranger/client/zk/ShardedZKHubClient.java | 2 +- .../com/flipkart/ranger/client/zk/UnshardedZKHubClient.java | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java index 6a51ce0f..1ba789e0 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java @@ -85,11 +85,11 @@ public Optional>> getAllNodes( return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); } - public abstract ServiceFinderHub buildHub(); + protected abstract ServiceFinderHub buildHub(); - public abstract ServiceDataSource buildServiceDataSource(); + protected abstract ServiceDataSource buildServiceDataSource(); - public abstract ServiceFinderFactory getFinderFactory(); + protected abstract ServiceFinderFactory getFinderFactory(); } diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java index 03fb5619..ea5fb4c4 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java @@ -105,11 +105,11 @@ public Optional>> getAllNodes( return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); } - public abstract ServiceFinderHub buildHub(); + protected abstract ServiceFinderHub buildHub(); - public abstract ServiceDataSource getServiceDataSource(); + protected abstract ServiceDataSource getServiceDataSource(); - public abstract ServiceFinderFactory getFinderFactory(); + protected abstract ServiceFinderFactory getFinderFactory(); } diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java index b929d292..279fbdc2 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java @@ -59,7 +59,7 @@ public ShardedHttpHubClient( } @Override - public ServiceFinderHub> buildHub() { + protected ServiceFinderHub> buildHub() { return new HttpServiceFinderHubBuilder>() .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) @@ -71,14 +71,14 @@ public ServiceFinderHub> buildHub() { In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. */ @Override - public ServiceDataSource getServiceDataSource() { + protected ServiceDataSource getServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new HttpServiceDataSource<>(clientConfig, getMapper()); } @Override - public ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> getFinderFactory() { return HttpShardedServiceFinderFactory.builder() .httpClientConfig(clientConfig) .nodeRefreshIntervalMs(getRefreshTimeMs()) diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java index 409570f6..82cb1ef4 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java @@ -59,7 +59,7 @@ public UnshardedHttpHubClient( } @Override - public ServiceFinderHub> buildHub() { + protected ServiceFinderHub> buildHub() { return new HttpServiceFinderHubBuilder>() .withServiceDataSource(getServiceDataSource()) .withServiceFinderFactory(getFinderFactory()) @@ -71,14 +71,14 @@ public ServiceFinderHub> buildHub() { In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. */ @Override - public ServiceDataSource getServiceDataSource() { + protected ServiceDataSource getServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new HttpServiceDataSource<>(clientConfig, getMapper()); } @Override - public ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> getFinderFactory() { return HttpUnshardedServiceFinderFactory.builder() .httpClientConfig(clientConfig) .nodeRefreshIntervalMs(getRefreshTimeMs()) diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java index d95b2d73..3fc32778 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -65,7 +65,7 @@ public AbstractZKHubClient( } @Override - public ServiceFinderHub buildHub() { + protected ServiceFinderHub buildHub() { return new ZkServiceFinderHubBuilder() .withCuratorFramework(curatorFramework) .withConnectionString(connectionString) @@ -79,7 +79,7 @@ public ServiceFinderHub buildHub() { } @Override - public ServiceDataSource buildServiceDataSource() { + protected ServiceDataSource buildServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new ZkServiceDataSource(getNamespace(), connectionString, curatorFramework); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java index 8be46bcd..bbf82ae0 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -59,7 +59,7 @@ public ShardedZKHubClient( } @Override - public ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> getFinderFactory() { return ZkShardedServiceFinderFactory.builder() .curatorFramework(getCuratorFramework()) .connectionString(getConnectionString()) diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java index eddee73b..ef83affd 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -59,7 +59,7 @@ public UnshardedZKHubClient( } @Override - public ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> getFinderFactory() { return ZKUnshardedServiceFinderFactory.builder() .curatorFramework(getCuratorFramework()) .connectionString(getConnectionString()) From 54fa826efe7daaa5067b06f6e6f58d9fcf057ea7 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 12:08:21 +0530 Subject: [PATCH 44/53] Restructured package structure for server bundle --- .../java/com/flipkart/ranger/server/RangerServerBundle.java | 3 +++ .../ranger/server/{ => config}/RangerConfiguration.java | 2 +- .../ranger/server/{ => manager}/RangerClientManager.java | 3 ++- .../flipkart/ranger/server/{ => model}/GenericResponse.java | 2 +- .../ranger/server/{ => resources}/RangerResource.java | 4 +++- 5 files changed, 10 insertions(+), 4 deletions(-) rename ranger-server/src/main/java/com/flipkart/ranger/server/{ => config}/RangerConfiguration.java (97%) rename ranger-server/src/main/java/com/flipkart/ranger/server/{ => manager}/RangerClientManager.java (96%) rename ranger-server/src/main/java/com/flipkart/ranger/server/{ => model}/GenericResponse.java (94%) rename ranger-server/src/main/java/com/flipkart/ranger/server/{ => resources}/RangerResource.java (94%) diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java index ad233a39..3c62e61b 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java @@ -16,6 +16,9 @@ package com.flipkart.ranger.server; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.server.config.RangerConfiguration; +import com.flipkart.ranger.server.manager.RangerClientManager; +import com.flipkart.ranger.server.resources.RangerResource; import io.dropwizard.Configuration; import io.dropwizard.ConfiguredBundle; import io.dropwizard.setup.Bootstrap; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java b/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java similarity index 97% rename from ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java rename to ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java index a1abee72..77df0f2a 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerConfiguration.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.flipkart.ranger.server; +package com.flipkart.ranger.server.config; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.flipkart.ranger.client.Constants; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java similarity index 96% rename from ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java rename to ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java index c159c7ad..a734e4d6 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerClientManager.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.flipkart.ranger.server; +package com.flipkart.ranger.server.manager; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.Constants; import com.flipkart.ranger.client.zk.UnshardedZKHubClient; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.server.config.RangerConfiguration; import com.google.common.base.Preconditions; import io.dropwizard.lifecycle.Managed; import lombok.Getter; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java b/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java similarity index 94% rename from ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java rename to ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java index 2fd4bb5b..29c8b576 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/GenericResponse.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.flipkart.ranger.server; +package com.flipkart.ranger.server.model; import lombok.*; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java similarity index 94% rename from ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java rename to ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java index c4d2cadd..47cdb7dd 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerResource.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java @@ -13,13 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.flipkart.ranger.server; +package com.flipkart.ranger.server.resources; import com.codahale.metrics.annotation.ExceptionMetered; import com.codahale.metrics.annotation.Timed; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.server.manager.RangerClientManager; +import com.flipkart.ranger.server.model.GenericResponse; import lombok.extern.slf4j.Slf4j; import lombok.val; From 75e0c8a94716f52889bad67ff3c284845dbb9cfd Mon Sep 17 00:00:00 2001 From: Koushik R Date: Sun, 17 Oct 2021 22:10:15 +0530 Subject: [PATCH 45/53] Added tests for abstract hub client test --- .../ranger/client/AbstractHubClient.java | 2 +- .../ranger/client/AbstractHubClientTest.java | 156 ++++++++++++++++++ .../ranger/client/zk/AbstractZKHubClient.java | 6 +- .../ranger/client/zk/ShardedZKHubClient.java | 2 +- .../client/zk/UnshardedZKHubClient.java | 2 +- 5 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java index 1ba789e0..cb9f3e72 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java @@ -89,7 +89,7 @@ public Optional>> getAllNodes( protected abstract ServiceDataSource buildServiceDataSource(); - protected abstract ServiceFinderFactory getFinderFactory(); + protected abstract ServiceFinderFactory buildFinderFactory(); } diff --git a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java new file mode 100644 index 00000000..47780131 --- /dev/null +++ b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java @@ -0,0 +1,156 @@ +package com.flipkart.ranger.client; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.finder.ServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; +import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; +import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; +import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; +import com.flipkart.ranger.core.finderhub.*; +import com.flipkart.ranger.core.model.*; +import com.google.common.collect.Lists; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.Optional; + +@Slf4j +public class AbstractHubClientTest { + + private static final ObjectMapper mapper = new ObjectMapper(); + private static final Service service = new Service("test-ns", "test-s"); + + @Data + @Builder + @AllArgsConstructor + private static class TestShardInfo{ + private int shardId; + } + + private static class TestCriteria implements Criteria{ + @Override + public boolean apply(TestShardInfo nodeData) { + return nodeData.getShardId() == 1; + } + } + + + @Data + @Builder + private static class TestSimpleUnshardedServiceFinder> + extends SimpleUnshardedServiceFinderBuilder, Deserializer, Criteria> { + + @Override + public SimpleUnshardedServiceFinder> build() { + if (null == shardSelector) { + shardSelector = new ListShardSelector<>(); + } + final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); + return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); + } + + @Override + protected NodeDataSource> dataSource(Service service) { + return new NodeDataSource>() { + @Override + public Optional>> refresh(Deserializer deserializer) { + return Optional.of( + Lists.newArrayList( + new ServiceNode<>("localhost", 9200, TestShardInfo.builder().shardId(1).build()) + ) + ); + } + + @Override + public void start() { + + } + + @Override + public void ensureConnected() { + + } + + @Override + public void stop() { + + } + + @Override + public boolean isActive() { + return true; + } + }; + } + } + + private static class TestServiceFinderFactory implements ServiceFinderFactory, ListBasedServiceRegistry>{ + + @Override + public ServiceFinder, ListBasedServiceRegistry> buildFinder(Service service) { + final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); + List> serviceNodes = Lists.newArrayList(); + serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestShardInfo.builder().shardId(1).build())); + serviceRegistry.updateNodes(serviceNodes); + + return new SimpleUnshardedServiceFinder>( + serviceRegistry, new ListShardSelector<>(), new RoundRobinServiceNodeSelector<>() + ); + } + } + + private static class TestAbstractHub extends AbstractHubClient, ListBasedServiceRegistry>{ + + public TestAbstractHub(String namespace, ObjectMapper mapper, int refreshTimeMs, Criteria criteria) { + super(namespace, mapper, refreshTimeMs, criteria); + } + + @Override + protected ServiceFinderHub, ListBasedServiceRegistry> buildHub() { + return new ServiceFinderHubBuilder, ListBasedServiceRegistry>() { + @Override + protected void preBuild() { + + } + + @Override + protected void postBuild(ServiceFinderHub, ListBasedServiceRegistry> serviceFinderHub) { + + } + }.withServiceDataSource(buildServiceDataSource()) + .withServiceFinderFactory(buildFinderFactory()) + .build(); + } + + @Override + protected ServiceDataSource buildServiceDataSource() { + return new StaticDataSource(Lists.newArrayList(service)); + } + + @Override + protected ServiceFinderFactory, ListBasedServiceRegistry> buildFinderFactory() { + return new TestServiceFinderFactory(); + } + } + + @Test + public void testAbstractHubClient() { + TestAbstractHub testAbstractHub = new TestAbstractHub(service.getNamespace(), mapper, 1000, new TestCriteria()); + testAbstractHub.start(); + + TestUtils.sleepForSeconds(3); + + Optional> node = testAbstractHub.getNode(service); + Assert.assertTrue(node.isPresent()); + Assert.assertTrue(node.get().getHost().equalsIgnoreCase("localhost-1")); + Assert.assertEquals(9000, node.get().getPort()); + Assert.assertEquals(1, node.get().getNodeData().getShardId()); + } +} diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java index 3fc32778..8f797d74 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -40,6 +40,10 @@ public abstract class AbstractZKHubClient, R extends Se private final boolean disablePushUpdaters; private final String connectionString; private final CuratorFramework curatorFramework; + /* + Use this if you don't want the datasource to fetch the entire list of services; + but know beforehand about the services you are going to build the hub for. + */ private final List services; public AbstractZKHubClient( @@ -72,7 +76,7 @@ protected ServiceFinderHub buildHub() { .withNamespace(getNamespace()) .withRefreshFrequencyMs(getRefreshTimeMs()) .withServiceDataSource(buildServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) + .withServiceFinderFactory(buildFinderFactory()) .withExtraStartSignalConsumer(x -> curatorFramework.start()) .withExtraStopSignalConsumer(x -> curatorFramework.start()) .build(); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java index bbf82ae0..b076f479 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -59,7 +59,7 @@ public ShardedZKHubClient( } @Override - protected ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> buildFinderFactory() { return ZkShardedServiceFinderFactory.builder() .curatorFramework(getCuratorFramework()) .connectionString(getConnectionString()) diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java index ef83affd..4cbb5cc6 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -59,7 +59,7 @@ public UnshardedZKHubClient( } @Override - protected ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> buildFinderFactory() { return ZKUnshardedServiceFinderFactory.builder() .curatorFramework(getCuratorFramework()) .connectionString(getConnectionString()) From b248b2e992be228f0c70112f84b26b6725827287 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 00:43:14 +0530 Subject: [PATCH 46/53] Added tests for sharded zk client --- .../ranger/client/AbstractHubClient.java | 13 +- .../flipkart/ranger/client/RangerClient.java | 3 +- .../ranger/client/RangerHubClient.java | 3 +- .../ranger/client/AbstractHubClientTest.java | 56 ++++--- .../shardselector/ListShardSelector.java | 2 +- .../shardselector/MatchingShardSelector.java | 3 +- .../MatchingShardSelectorTest.java | 9 +- .../ranger/core/units/TestNodeData.java | 4 + .../client/http/AbstractHttpHubClient.java | 115 -------------- .../client/http/ShardedHttpHubClient.java | 29 ++-- .../client/http/SimpleRangerHttpClient.java | 21 ++- .../client/http/UnshardedHttpHubClient.java | 29 ++-- .../HttpServiceFinderHubBuilder.java | 2 +- ranger-zk-client/pom.xml | 6 + .../ranger/client/zk/AbstractZKHubClient.java | 15 +- .../ranger/client/zk/ShardedZKHubClient.java | 14 +- .../client/zk/SimpleRangerZKClient.java | 25 ++-- .../client/zk/UnshardedZKHubClient.java | 14 +- .../client/zk/ShardedZKHubClientTest.java | 140 ++++++++++++++++++ .../servicefinderhub/ZkServiceDataSource.java | 6 +- 20 files changed, 274 insertions(+), 235 deletions(-) delete mode 100644 ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java create mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java index cb9f3e72..fae37f33 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java @@ -4,10 +4,7 @@ import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; -import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceRegistry; +import com.flipkart.ranger.core.model.*; import com.google.common.base.Preconditions; import lombok.Getter; import lombok.extern.slf4j.Slf4j; @@ -18,11 +15,12 @@ @Slf4j @Getter -public abstract class AbstractHubClient, R extends ServiceRegistry> implements RangerHubClient { +public abstract class AbstractHubClient, R extends ServiceRegistry, D extends Deserializer> implements RangerHubClient { private final String namespace; private final ObjectMapper mapper; private final C criteria; + private final D deserializer; private int refreshTimeMs; private ServiceFinderHub hub; @@ -31,17 +29,20 @@ public AbstractHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, - C criteria + C criteria, + D deserializer ){ this.namespace = namespace; this.mapper = mapper; this.refreshTimeMs = refreshTimeMs; this.criteria = criteria; + this.deserializer = deserializer; } public void start(){ Preconditions.checkNotNull(mapper, "Mapper can't be null"); Preconditions.checkNotNull(namespace, "namespace can't be null"); + Preconditions.checkNotNull(deserializer, "deserializer can't be null"); if (this.refreshTimeMs < Constants.MINIMUM_REFRESH_TIME) { log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java index 5406b392..616a9644 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java @@ -17,12 +17,13 @@ package com.flipkart.ranger.client; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.ServiceNode; import java.util.List; import java.util.Optional; -public interface RangerClient> { +public interface RangerClient, D extends Deserializer> { void start(); diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java index ec05a8fe..75917de5 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java @@ -17,13 +17,14 @@ package com.flipkart.ranger.client; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import java.util.List; import java.util.Optional; -public interface RangerHubClient> { +public interface RangerHubClient, D extends Deserializer> { void start(); diff --git a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java index 47780131..f93738a2 100644 --- a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java +++ b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java @@ -5,9 +5,7 @@ import com.flipkart.ranger.core.finder.ServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinderBuilder; -import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.finderhub.*; import com.flipkart.ranger.core.model.*; import com.google.common.collect.Lists; @@ -18,6 +16,7 @@ import org.junit.Assert; import org.junit.Test; +import java.io.IOException; import java.util.List; import java.util.Optional; @@ -49,11 +48,7 @@ private static class TestSimpleUnshardedServiceFinder> @Override public SimpleUnshardedServiceFinder> build() { - if (null == shardSelector) { - shardSelector = new ListShardSelector<>(); - } - final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); - return new SimpleUnshardedServiceFinder<>(serviceRegistry, shardSelector, nodeSelector); + return buildFinder(); } @Override @@ -95,21 +90,29 @@ private static class TestServiceFinderFactory implements ServiceFinderFactory, ListBasedServiceRegistry> buildFinder(Service service) { - final ListBasedServiceRegistry serviceRegistry = new ListBasedServiceRegistry<>(service); - List> serviceNodes = Lists.newArrayList(); - serviceNodes.add(new ServiceNode<>("localhost-1", 9000, TestShardInfo.builder().shardId(1).build())); - serviceRegistry.updateNodes(serviceNodes); - - return new SimpleUnshardedServiceFinder>( - serviceRegistry, new ListShardSelector<>(), new RoundRobinServiceNodeSelector<>() - ); + SimpleUnshardedServiceFinder> finder = new TestSimpleUnshardedServiceFinder>() + .withNamespace(service.getNamespace()) + .withServiceName(service.getServiceName()) + .withDeserializer(new Deserializer() { + @Override + public int hashCode() { + return super.hashCode(); + } + }) + .build(); + finder.start(); + return finder; } } - private static class TestAbstractHub extends AbstractHubClient, ListBasedServiceRegistry>{ + private static class TestDeserilizer implements Deserializer{ + + } - public TestAbstractHub(String namespace, ObjectMapper mapper, int refreshTimeMs, Criteria criteria) { - super(namespace, mapper, refreshTimeMs, criteria); + private static class TestAbstractHub extends AbstractHubClient, ListBasedServiceRegistry, TestDeserilizer>{ + + public TestAbstractHub(String namespace, ObjectMapper mapper, int refreshTimeMs, Criteria criteria, TestDeserilizer deserilizer) { + super(namespace, mapper, refreshTimeMs, criteria, deserilizer); } @Override @@ -142,15 +145,26 @@ protected ServiceFinderFactory, ListBased @Test public void testAbstractHubClient() { - TestAbstractHub testAbstractHub = new TestAbstractHub(service.getNamespace(), mapper, 1000, new TestCriteria()); + TestAbstractHub testAbstractHub = new TestAbstractHub(service.getNamespace(), mapper, 1000, new TestCriteria(), new TestDeserilizer<>()); testAbstractHub.start(); TestUtils.sleepForSeconds(3); Optional> node = testAbstractHub.getNode(service); Assert.assertTrue(node.isPresent()); - Assert.assertTrue(node.get().getHost().equalsIgnoreCase("localhost-1")); - Assert.assertEquals(9000, node.get().getPort()); + Assert.assertTrue(node.get().getHost().equalsIgnoreCase("localhost")); + Assert.assertEquals(9200, node.get().getPort()); Assert.assertEquals(1, node.get().getNodeData().getShardId()); + + node = testAbstractHub.getNode(new Service("test", "test")); + Assert.assertFalse(node.isPresent()); + + node = testAbstractHub.getNode(service, nodeData -> nodeData.getShardId() == 2); + Assert.assertFalse(node.isPresent()); + + node = testAbstractHub.getNode(new Service("test", "test"), nodeData -> nodeData.getShardId() == 1); + Assert.assertFalse(node.isPresent()); + + testAbstractHub.start(); } } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index d2034872..379f4a68 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -29,7 +29,7 @@ public class ListShardSelector> implements ShardSelecto public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) { if(null == criteria){ return serviceRegistry.nodeList(); - } + } return serviceRegistry.nodeList().stream().filter(node -> criteria.apply(node.getNodeData())).collect(Collectors.toList()); } diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 7d3f0af3..7fe8c271 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -20,6 +20,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; +import com.google.common.collect.Lists; import java.util.List; import java.util.Map; @@ -33,7 +34,7 @@ public List> nodes(C criteria, MapBasedServiceRegistry service return serviceRegistry.nodes() .entries() .stream() - .filter(each -> criteria.apply(each.getKey())) + .filter(e -> criteria.apply(e.getKey())) .map(Map.Entry::getValue) .collect(Collectors.toList()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index f11a6d63..f803ac2c 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -28,12 +28,19 @@ public class MatchingShardSelectorTest { + private static final class TestCriteria implements Criteria{ + @Override + public boolean apply(TestNodeData nodeData) { + return nodeData.getNodeId() == 1; + } + } + @Test public void testMatchingShardSelector(){ final MapBasedServiceRegistry serviceRegistry = RegistryTestUtils.getServiceRegistry(); final MatchingShardSelector> shardSelector = new MatchingShardSelector<>(); final List> nodes = shardSelector.nodes( - CriteriaUtils.getCriteria(1), serviceRegistry); + new TestCriteria(), serviceRegistry); Assert.assertFalse(nodes.isEmpty()); Assert.assertEquals("localhost-1", nodes.get(0).getHost()); } diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java index 43631057..a0debf37 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java @@ -15,14 +15,18 @@ */ package com.flipkart.ranger.core.units; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data @AllArgsConstructor +@NoArgsConstructor @Builder public class TestNodeData { + @JsonProperty private int nodeId; @Override diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java deleted file mode 100644 index ea5fb4c4..00000000 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/AbstractHttpHubClient.java +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Copyright 2015 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 com.flipkart.ranger.client.http; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.client.Constants; -import com.flipkart.ranger.client.RangerHubClient; -import com.flipkart.ranger.core.finderhub.ServiceDataSource; -import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; -import com.flipkart.ranger.core.finderhub.ServiceFinderHub; -import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.model.ServiceRegistry; -import com.google.common.base.Preconditions; -import lombok.Getter; -import lombok.extern.slf4j.Slf4j; -import lombok.val; - -import java.util.List; -import java.util.Optional; - -@Slf4j -@Getter -public abstract class AbstractHttpHubClient, R extends ServiceRegistry> implements RangerHubClient { - - private ServiceFinderHub hub; - private String namespace; - private String environment; - private ObjectMapper mapper; - private int refreshTimeMs; - private C criteria; - - public AbstractHttpHubClient( - String namespace, - String environment, - ObjectMapper mapper, - int refreshTimeMs, - C criteria - ){ - this.namespace = namespace; - this.environment =environment; - this.mapper = mapper; - this.refreshTimeMs = refreshTimeMs; - this.criteria = criteria; - } - - public void start(){ - Preconditions.checkNotNull(mapper, "Mapper can't be null"); - Preconditions.checkNotNull(namespace, "namespace can't be null"); - Preconditions.checkNotNull(environment, "Environment can't be null"); - - if (this.refreshTimeMs < Constants.MINIMUM_REFRESH_TIME) { - log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", - this.refreshTimeMs, - Constants.MINIMUM_REFRESH_TIME); - } - this.refreshTimeMs = Math.max(Constants.MINIMUM_REFRESH_TIME, this.refreshTimeMs); - this.hub = buildHub(); - this.hub.start(); - } - - public void stop(){ - hub.stop(); - } - - public Optional> getNode( - final Service service - ){ - return getNode(service, criteria); - } - - public Optional>> getAllNodes( - final Service service - ){ - return getAllNodes(service, criteria); - } - - public Optional> getNode( - final Service service, - final C criteria - ){ - val optionalFinder = this.getHub().finder(service); - return optionalFinder.map(trcServiceFinder -> trcServiceFinder.get(criteria)); - } - - public Optional>> getAllNodes( - final Service service, - final C criteria - ){ - val optionalFinder = this.getHub().finder(service); - return optionalFinder.map(trcServiceFinder -> trcServiceFinder.getAll(criteria)); - } - - protected abstract ServiceFinderHub buildHub(); - - protected abstract ServiceDataSource getServiceDataSource(); - - protected abstract ServiceFinderFactory getFinderFactory(); - -} - diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java index 279fbdc2..0d46565b 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; @@ -28,6 +29,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; import com.flipkart.ranger.http.servicefinderhub.HttpShardedServiceFinderFactory; @@ -38,7 +40,7 @@ import java.util.List; @Slf4j -public class ShardedHttpHubClient> extends AbstractHttpHubClient> { +public class ShardedHttpHubClient> extends AbstractHubClient, HTTPResponseDataDeserializer> { private List services; private final HttpClientConfig clientConfig; @@ -46,14 +48,14 @@ public class ShardedHttpHubClient> extends AbstractHttp @Builder public ShardedHttpHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, C criteria, + HTTPResponseDataDeserializer deserializer, HttpClientConfig clientConfig, List services ) { - super(namespace, environment, mapper, refreshTimeMs, criteria); + super(namespace, mapper, refreshTimeMs, criteria, deserializer); this.clientConfig = clientConfig; this.services = services; } @@ -61,37 +63,28 @@ public ShardedHttpHubClient( @Override protected ServiceFinderHub> buildHub() { return new HttpServiceFinderHubBuilder>() - .withServiceDataSource(getServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) + .withServiceDataSource(buildServiceDataSource()) + .withServiceFinderFactory(buildFinderFactory()) .withRefreshFrequencyMs(getRefreshTimeMs()) .build(); } - /* - In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. - */ @Override - protected ServiceDataSource getServiceDataSource() { + protected ServiceDataSource buildServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new HttpServiceDataSource<>(clientConfig, getMapper()); } @Override - protected ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> buildFinderFactory() { return HttpShardedServiceFinderFactory.builder() .httpClientConfig(clientConfig) .nodeRefreshIntervalMs(getRefreshTimeMs()) - .deserializer(data -> { - try{ - return getMapper().readValue(data, new TypeReference>() {}); - }catch (IOException e){ - log.warn("Could not parse node data"); - } - return null; - }) + .deserializer(getDeserializer()) .shardSelector(new MatchingShardSelector<>()) .nodeSelector(new RoundRobinServiceNodeSelector<>()) .build(); } + } diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java index 6c83d658..197ae19c 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java @@ -21,10 +21,12 @@ import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.http.HttpServiceFinderBuilders; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.google.common.base.Preconditions; import lombok.Builder; import lombok.extern.slf4j.Slf4j; @@ -34,9 +36,10 @@ import java.util.Optional; @Slf4j -public class SimpleRangerHttpClient> implements RangerClient { +public class SimpleRangerHttpClient, D extends HTTPResponseDataDeserializer> implements RangerClient { private final C criteria; + private final D deserializer; private final SimpleUnshardedServiceFinder serviceFinder; @Builder @@ -46,11 +49,15 @@ public SimpleRangerHttpClient( ObjectMapper mapper, int refreshTimeMs, HttpClientConfig clientConfig, - C criteria + C criteria, + D deserializer ) { Preconditions.checkNotNull(mapper, "Mapper can't be null"); Preconditions.checkNotNull(namespace, "namespace can't be null"); + Preconditions.checkNotNull(deserializer, "deserializer can't be null"); + this.criteria = criteria; + this.deserializer = deserializer; this.serviceFinder = HttpServiceFinderBuilders.httpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) @@ -58,15 +65,7 @@ public SimpleRangerHttpClient( .withNamespace(namespace) .withObjectMapper(mapper) .withNodeRefreshIntervalMs(refreshTimeMs) - .withDeserializer(data -> { - try { - return mapper.readValue(data, new TypeReference>() { - }); - } catch (IOException e) { - log.warn("Could not parse node data"); - } - return null; - }) + .withDeserializer(deserializer) .withShardSelector(new ListShardSelector<>()) .build(); } diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java index 82cb1ef4..60f7947a 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java @@ -17,6 +17,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; @@ -28,6 +29,7 @@ import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; import com.flipkart.ranger.http.servicefinderhub.HttpUnshardedServiceFinderFactory; @@ -38,7 +40,7 @@ import java.util.List; @Slf4j -public class UnshardedHttpHubClient> extends AbstractHttpHubClient> { +public class UnshardedHttpHubClient> extends AbstractHubClient, HTTPResponseDataDeserializer> { private List services; private final HttpClientConfig clientConfig; @@ -46,14 +48,14 @@ public class UnshardedHttpHubClient> extends AbstractHt @Builder public UnshardedHttpHubClient( String namespace, - String environment, ObjectMapper mapper, int refreshTimeMs, C criteria, + HTTPResponseDataDeserializer deserializer, HttpClientConfig clientConfig, List services ) { - super(namespace, environment, mapper, refreshTimeMs, criteria); + super(namespace, mapper, refreshTimeMs, criteria, deserializer); this.clientConfig = clientConfig; this.services = services; } @@ -61,37 +63,28 @@ public UnshardedHttpHubClient( @Override protected ServiceFinderHub> buildHub() { return new HttpServiceFinderHubBuilder>() - .withServiceDataSource(getServiceDataSource()) - .withServiceFinderFactory(getFinderFactory()) + .withServiceDataSource(buildServiceDataSource()) + .withServiceFinderFactory(buildFinderFactory()) .withRefreshFrequencyMs(getRefreshTimeMs()) .build(); } - /* - In case of http hub, if client could provide the services for which hub needs to be refreshed, use them instead. - */ @Override - protected ServiceDataSource getServiceDataSource() { + protected ServiceDataSource buildServiceDataSource() { return null != services && !services.isEmpty() ? new StaticDataSource(services) : new HttpServiceDataSource<>(clientConfig, getMapper()); } @Override - protected ServiceFinderFactory> getFinderFactory() { + protected ServiceFinderFactory> buildFinderFactory() { return HttpUnshardedServiceFinderFactory.builder() .httpClientConfig(clientConfig) .nodeRefreshIntervalMs(getRefreshTimeMs()) - .deserializer(data -> { - try{ - return getMapper().readValue(data, new TypeReference>() {}); - }catch (IOException e){ - log.warn("Could not parse node data"); - } - return null; - }) + .deserializer(getDeserializer()) .shardSelector(new ListShardSelector<>()) .nodeSelector(new RoundRobinServiceNodeSelector<>()) .build(); } + } diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index 75645ef8..5268c15c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -26,7 +26,7 @@ public class HttpServiceFinderHubBuilder, R extends Ser @Override protected void preBuild() { - log.info("No pre-ebuild actions necessary"); + log.info("No pre-build actions necessary"); } @Override diff --git a/ranger-zk-client/pom.xml b/ranger-zk-client/pom.xml index 11cf2772..768fbb7e 100644 --- a/ranger-zk-client/pom.xml +++ b/ranger-zk-client/pom.xml @@ -27,6 +27,12 @@ jackson-databind ${jackson.version} + + org.apache.curator + curator-test + ${curator.version} + test + \ No newline at end of file diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java index 8f797d74..4bfb56ad 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -19,10 +19,12 @@ import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; +import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; import com.flipkart.ranger.core.finderhub.StaticDataSource; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceRegistry; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceDataSource; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkServiceFinderHubBuilder; import lombok.Getter; @@ -35,7 +37,7 @@ @Slf4j @Getter -public abstract class AbstractZKHubClient, R extends ServiceRegistry> extends AbstractHubClient { +public abstract class AbstractZKHubClient, R extends ServiceRegistry, D extends ZkNodeDataDeserializer> extends AbstractHubClient { private final boolean disablePushUpdaters; private final String connectionString; @@ -54,31 +56,32 @@ public AbstractZKHubClient( String connectionString, CuratorFramework curatorFramework, C criteria, + D deserializer, List services ) { - super(namespace, mapper, refreshTimeMs, criteria); + super(namespace, mapper, refreshTimeMs, criteria, deserializer); this.disablePushUpdaters = disablePushUpdaters; this.connectionString = connectionString; + this.services = services; + this.curatorFramework = null != curatorFramework ? curatorFramework : CuratorFrameworkFactory.builder() .namespace(namespace) .connectString(this.connectionString) .retryPolicy(new RetryForever(5000)) .build(); - this.services = services; + } @Override protected ServiceFinderHub buildHub() { - return new ZkServiceFinderHubBuilder() + return new ZkServiceFinderHubBuilder() .withCuratorFramework(curatorFramework) .withConnectionString(connectionString) .withNamespace(getNamespace()) .withRefreshFrequencyMs(getRefreshTimeMs()) .withServiceDataSource(buildServiceDataSource()) .withServiceFinderFactory(buildFinderFactory()) - .withExtraStartSignalConsumer(x -> curatorFramework.start()) - .withExtraStopSignalConsumer(x -> curatorFramework.start()) .build(); } diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java index b076f479..b9d2e047 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; import lombok.Builder; import lombok.extern.slf4j.Slf4j; @@ -33,7 +34,7 @@ import java.util.List; @Slf4j -public class ShardedZKHubClient> extends AbstractZKHubClient> { +public class ShardedZKHubClient> extends AbstractZKHubClient, ZkNodeDataDeserializer> { @Builder public ShardedZKHubClient( @@ -44,6 +45,7 @@ public ShardedZKHubClient( String connectionString, CuratorFramework curatorFramework, C criteria, + ZkNodeDataDeserializer deserializer, List services ) { super( @@ -54,6 +56,7 @@ public ShardedZKHubClient( connectionString, curatorFramework, criteria, + deserializer, services ); } @@ -65,14 +68,7 @@ protected ServiceFinderFactory> buildFinderFact .connectionString(getConnectionString()) .nodeRefreshIntervalMs(getRefreshTimeMs()) .disablePushUpdaters(isDisablePushUpdaters()) - .deserializer(data -> { - try{ - return getMapper().readValue(data, new TypeReference>() {}); - }catch (IOException e){ - log.warn("Could not parse node data"); - } - return null; - }) + .deserializer(getDeserializer()) .shardSelector(new MatchingShardSelector<>()) .nodeSelector(new RoundRobinServiceNodeSelector<>()) .build(); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java index 5a201111..dddcc898 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.ServiceFinderBuilders; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.google.common.base.Preconditions; import lombok.Builder; import lombok.Getter; @@ -38,10 +39,11 @@ @Slf4j @Getter -public class SimpleRangerZKClient> implements RangerClient { +public class SimpleRangerZKClient, D extends ZkNodeDataDeserializer> implements RangerClient { private SimpleShardedServiceFinder serviceFinder; private C criteria; + private D deserializer; @Builder(builderMethodName = "fromConnectionString", builderClassName = "FromConnectionStringBuilder") public SimpleRangerZKClient( @@ -51,7 +53,8 @@ public SimpleRangerZKClient( int refreshTimeMs, boolean disableWatchers, String connectionString, - C criteria + C criteria, + D deserializer ){ this( namespace, @@ -60,7 +63,8 @@ public SimpleRangerZKClient( refreshTimeMs, disableWatchers, CuratorFrameworkFactory.newClient(connectionString, new RetryForever(Constants.CONNECTION_RETRY_TIME)), - criteria + criteria, + deserializer ); } @@ -72,10 +76,12 @@ public SimpleRangerZKClient( int refreshTimeMs, boolean disableWatchers, CuratorFramework curatorFramework, - C criteria + C criteria, + D deserializer ){ Preconditions.checkNotNull(mapper, "Mapper can't be null"); Preconditions.checkNotNull(namespace, "namespace can't be null"); + Preconditions.checkNotNull(deserializer, "deserializer can't be null"); int effectiveRefreshTime = refreshTimeMs; if (effectiveRefreshTime < Constants.MINIMUM_REFRESH_TIME) { @@ -86,19 +92,12 @@ public SimpleRangerZKClient( } this.criteria = criteria; + this.deserializer = deserializer; this.serviceFinder = ServiceFinderBuilders.shardedFinderBuilder() .withCuratorFramework(curatorFramework) .withNamespace(namespace) .withServiceName(serviceName) - .withDeserializer(data -> { - try{ - return mapper.readValue(data, new TypeReference>() { - }); - }catch (IOException e){ - log.info("Could not parse node data"); - return null; - } - }) + .withDeserializer(deserializer) .withNodeRefreshIntervalMs(effectiveRefreshTime) .withDisableWatchers(disableWatchers) .withShardSelector(new MatchingShardSelector<>()) diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java index 4cbb5cc6..d7329aa5 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -24,6 +24,7 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinderhub.ZKUnshardedServiceFinderFactory; import lombok.Builder; import lombok.extern.slf4j.Slf4j; @@ -33,7 +34,7 @@ import java.util.List; @Slf4j -public class UnshardedZKHubClient> extends AbstractZKHubClient> { +public class UnshardedZKHubClient> extends AbstractZKHubClient, ZkNodeDataDeserializer> { @Builder public UnshardedZKHubClient( @@ -44,6 +45,7 @@ public UnshardedZKHubClient( String connectionString, CuratorFramework curatorFramework, C criteria, + ZkNodeDataDeserializer deserializer, List services ) { super( @@ -54,6 +56,7 @@ public UnshardedZKHubClient( connectionString, curatorFramework, criteria, + deserializer, services ); } @@ -65,14 +68,7 @@ protected ServiceFinderFactory> buildFinderFac .connectionString(getConnectionString()) .nodeRefreshIntervalMs(getRefreshTimeMs()) .disablePushUpdaters(isDisablePushUpdaters()) - .deserializer(data -> { - try{ - return getMapper().readValue(data, new TypeReference>() {}); - }catch (IOException e){ - log.warn("Could not parse node data"); - } - return null; - }) + .deserializer(getDeserializer()) .shardSelector(new ListShardSelector<>()) .nodeSelector(new RoundRobinServiceNodeSelector<>()) .build(); diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java new file mode 100644 index 00000000..96b24fde --- /dev/null +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java @@ -0,0 +1,140 @@ +package com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.healthcheck.HealthcheckResult; +import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; +import lombok.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.test.TestingCluster; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; +import java.util.Date; +import java.util.Optional; + +@Slf4j +public class ShardedZKHubClientTest { + + @Data + @Builder + @AllArgsConstructor + private static class TestCriteria implements Criteria { + @Override + public boolean apply(TestNodeData nodeData) { + return nodeData.getNodeId() == 1; + } + } + + private TestingCluster testingCluster; + private ObjectMapper objectMapper = new ObjectMapper(); + private CuratorFramework curatorFramework; + + @Before + public void startTestCluster() throws Exception { + objectMapper = new ObjectMapper(); + testingCluster = new TestingCluster(3); + testingCluster.start(); + curatorFramework = CuratorFrameworkFactory.builder() + .namespace("test-n") + .connectString(testingCluster.getConnectString()) + .retryPolicy(new ExponentialBackoffRetry(1000, 100)) + .build(); + curatorFramework.start(); + curatorFramework.blockUntilConnected(); + log.debug("Started zk subsystem"); + } + + @After + public void stopTestCluster() throws Exception { + log.debug("Stopping zk subsystem"); + curatorFramework.close(); + if (null != testingCluster) { + testingCluster.close(); + } + } + + private ServiceNode read(final byte[] data) { + try { + return objectMapper.readValue(data, new TypeReference>() {}); + } + catch (IOException e) { + Exceptions.illegalState(e); + } + return null; + } + + private byte[] write(final ServiceNode node) { + try { + return objectMapper.writeValueAsBytes(node); + } + catch (IOException e) { + Exceptions.illegalState(e); + } + return null; + } + + @Test + public void testShardedHub(){ + val zkHubClient = ShardedZKHubClient.>builder() + .namespace("test-n") + .connectionString(testingCluster.getConnectString()) + .curatorFramework(curatorFramework) + .disablePushUpdaters(true) + .mapper(objectMapper) + .deserializer(this::read) + .build(); + zkHubClient.start(); + + ExternalTriggeredSignal refreshProviderSignal = new ExternalTriggeredSignal<>( + () -> HealthcheckResult.builder() + .status(HealthcheckStatus.healthy) + .updatedTime(new Date().getTime()) + .build(), Collections.emptyList()); + val provider1 = ServiceProviderBuilders.shardedServiceProviderBuilder() + .withHostname("localhost") + .withPort(1080) + .withNamespace("test-n") + .withServiceName("s1") + .withSerializer(this::write) + .withNodeData(new TestNodeData(1)) + .withHealthcheck(() -> HealthcheckStatus.healthy) + .withadditionalRefreshSignal(refreshProviderSignal) + .withCuratorFramework(curatorFramework) + .build(); + provider1.start(); + + refreshProviderSignal.trigger(); + + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "s1"); + Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); + Assert.assertTrue(node.isPresent()); + + node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 2); + Assert.assertFalse(node.isPresent()); + + zkHubClient.stop(); + provider1.stop(); + } +} diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index d86f845d..3fa71e3a 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -36,7 +36,7 @@ public class ZkServiceDataSource implements ServiceDataSource { private final String namespace; private String connectionString; private CuratorFramework curatorFramework; - private boolean manageCurator; + private boolean curatorProvided; public ZkServiceDataSource(String namespace, String connectionString, @@ -66,7 +66,7 @@ public void start() { .retryPolicy(new ExponentialBackoffRetry(1000, 100)) .build(); curatorFramework.start(); - manageCurator = true; + curatorProvided = false; } try { curatorFramework.blockUntilConnected(); @@ -80,7 +80,7 @@ public void start() { @Override public void stop() { log.info("Service data stopped"); - if(manageCurator) curatorFramework.close(); + if(!curatorProvided) curatorFramework.close(); log.info("Service data source stopped"); } } From 202c819947cd3b53c5a1309c2c221ed682a9be05 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 01:09:04 +0530 Subject: [PATCH 47/53] Added deserializer to the http bundle as well --- .../ranger/client/AbstractHubClientTest.java | 1 - .../shardselector/MatchingShardSelector.java | 1 - .../MatchingShardSelectorTest.java | 1 - .../client/http/ShardedHttpHubClient.java | 3 - .../client/http/SimpleRangerHttpClient.java | 4 - .../client/http/UnshardedHttpHubClient.java | 3 - .../http/model/ServiceNodesResponse.java | 1 - .../ranger/server/RangerServerBundle.java | 19 ++++- .../server/manager/RangerClientManager.java | 9 ++- .../server/resources/RangerResource.java | 7 +- .../ranger/client/zk/AbstractZKHubClient.java | 1 - .../ranger/client/zk/ShardedZKHubClient.java | 3 - .../client/zk/SimpleRangerZKClient.java | 2 - .../client/zk/UnshardedZKHubClient.java | 3 - .../ranger/client/zk/BaseZKHubTest.java | 61 ++++++++++++++++ ...edZKHubClientTest.java => BaseZKTest.java} | 73 +++++-------------- .../ranger/client/zk/ShardedZKHubTest.java | 21 ++++++ .../client/zk/SimpleRangerZKClienTest.java | 38 ++++++++++ .../ranger/client/zk/UnshardedZKHubTest.java | 21 ++++++ 19 files changed, 187 insertions(+), 85 deletions(-) create mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{ShardedZKHubClientTest.java => BaseZKTest.java} (59%) create mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java create mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java create mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java diff --git a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java index f93738a2..83cd882e 100644 --- a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java +++ b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java @@ -16,7 +16,6 @@ import org.junit.Assert; import org.junit.Test; -import java.io.IOException; import java.util.List; import java.util.Optional; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index 7fe8c271..ef7af4c7 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -20,7 +20,6 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.model.ShardSelector; -import com.google.common.collect.Lists; import java.util.List; import java.util.Map; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index f803ac2c..f35fe273 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -19,7 +19,6 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; -import com.flipkart.ranger.core.utils.CriteriaUtils; import com.flipkart.ranger.core.utils.RegistryTestUtils; import org.junit.Assert; import org.junit.Test; diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java index 0d46565b..406f8c2d 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.client.http; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; @@ -28,7 +27,6 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; -import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; @@ -36,7 +34,6 @@ import lombok.Builder; import lombok.extern.slf4j.Slf4j; -import java.io.IOException; import java.util.List; @Slf4j diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java index 197ae19c..7dd74f8d 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java @@ -15,23 +15,19 @@ */ package com.flipkart.ranger.client.http; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.RangerClient; import com.flipkart.ranger.core.finder.SimpleUnshardedServiceFinder; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.http.HttpServiceFinderBuilders; import com.flipkart.ranger.http.config.HttpClientConfig; -import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.google.common.base.Preconditions; import lombok.Builder; import lombok.extern.slf4j.Slf4j; -import java.io.IOException; import java.util.List; import java.util.Optional; diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java index 60f7947a..66f1b9ae 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.client.http; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; @@ -28,7 +27,6 @@ import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.http.config.HttpClientConfig; -import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; import com.flipkart.ranger.http.servicefinderhub.HttpServiceDataSource; import com.flipkart.ranger.http.servicefinderhub.HttpServiceFinderHubBuilder; @@ -36,7 +34,6 @@ import lombok.Builder; import lombok.extern.slf4j.Slf4j; -import java.io.IOException; import java.util.List; @Slf4j diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 37c829de..30aa47f4 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -19,7 +19,6 @@ import com.flipkart.ranger.core.model.ServiceNode; import lombok.Builder; import lombok.Data; -import lombok.Singular; import java.util.List; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java index 3c62e61b..e8aad075 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java @@ -19,6 +19,7 @@ import com.flipkart.ranger.server.config.RangerConfiguration; import com.flipkart.ranger.server.manager.RangerClientManager; import com.flipkart.ranger.server.resources.RangerResource; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import io.dropwizard.Configuration; import io.dropwizard.ConfiguredBundle; import io.dropwizard.setup.Bootstrap; @@ -27,9 +28,15 @@ import lombok.val; @Slf4j -public abstract class RangerServerBundle, U extends Configuration> implements ConfiguredBundle { +public abstract class RangerServerBundle< + T, + C extends Criteria, + U extends Configuration, + D extends ZkNodeDataDeserializer> implements ConfiguredBundle { - protected abstract RangerConfiguration getRangerConfiguration(U configuration); + protected abstract RangerConfiguration withRangerConfiguration(U configuration); + + protected abstract D withDeserializer(U configuration); @Override public void initialize(Bootstrap bootstrap) { @@ -38,8 +45,12 @@ public void initialize(Bootstrap bootstrap) { @Override public void run(U configuration, Environment environment) { - val rangerConfiguration = getRangerConfiguration(configuration); - val clientManager = new RangerClientManager(rangerConfiguration, environment.getObjectMapper()); + val rangerConfiguration = withRangerConfiguration(configuration); + val clientManager = new RangerClientManager( + rangerConfiguration, + environment.getObjectMapper(), + withDeserializer(configuration) + ); val rangerResource = new RangerResource<>(clientManager); environment.lifecycle().manage(clientManager); environment.jersey().register(rangerResource); diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java index a734e4d6..84a5a1b6 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java @@ -19,7 +19,9 @@ import com.flipkart.ranger.client.Constants; import com.flipkart.ranger.client.zk.UnshardedZKHubClient; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.server.config.RangerConfiguration; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.google.common.base.Preconditions; import io.dropwizard.lifecycle.Managed; import lombok.Getter; @@ -34,7 +36,7 @@ @Slf4j @Singleton @Getter -public class RangerClientManager> implements Managed { +public class RangerClientManager, D extends ZkNodeDataDeserializer> implements Managed { private final RangerConfiguration rangerConfiguration; @@ -44,12 +46,14 @@ public class RangerClientManager> implements Managed { @Inject public RangerClientManager( RangerConfiguration rangerConfiguration, - ObjectMapper mapper + ObjectMapper mapper, + D deserializer ){ this.rangerConfiguration = rangerConfiguration; Preconditions.checkNotNull(rangerConfiguration, "Ranger configuration can't be null"); Preconditions.checkNotNull(rangerConfiguration.getZookeeper(), "Zookeeper can't be null"); Preconditions.checkNotNull(rangerConfiguration.getNamespace(), "Namespace can't be null"); + Preconditions.checkNotNull(deserializer, "Deserializer can't be null"); curatorFramework = CuratorFrameworkFactory.newClient( rangerConfiguration.getZookeeper(), @@ -62,6 +66,7 @@ public RangerClientManager( .mapper(mapper) .services(rangerConfiguration.getServices()) .refreshTimeMs(rangerConfiguration.getRefreshTimeMs()) + .deserializer(deserializer) .build(); } diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java index 47cdb7dd..5033cc67 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java @@ -22,6 +22,7 @@ import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.server.manager.RangerClientManager; import com.flipkart.ranger.server.model.GenericResponse; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -38,11 +39,11 @@ @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Path("/v1/ranger") -public class RangerResource> { +public class RangerResource, D extends ZkNodeDataDeserializer> { - private final RangerClientManager clientManager; + private final RangerClientManager clientManager; - public RangerResource(RangerClientManager clientManager){ + public RangerResource(RangerClientManager clientManager){ this.clientManager = clientManager; } diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java index 4bfb56ad..8548de60 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java @@ -19,7 +19,6 @@ import com.flipkart.ranger.client.AbstractHubClient; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; -import com.flipkart.ranger.core.finderhub.ServiceFinderHubBuilder; import com.flipkart.ranger.core.finderhub.StaticDataSource; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java index b9d2e047..033ee15d 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.client.zk; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; @@ -23,14 +22,12 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinderhub.ZkShardedServiceFinderFactory; import lombok.Builder; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; -import java.io.IOException; import java.util.List; @Slf4j diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java index dddcc898..da9247d5 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.client.zk; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.Constants; import com.flipkart.ranger.client.RangerClient; @@ -33,7 +32,6 @@ import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.RetryForever; -import java.io.IOException; import java.util.List; import java.util.Optional; diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java index d7329aa5..006732a9 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java @@ -15,7 +15,6 @@ */ package com.flipkart.ranger.client.zk; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; @@ -23,14 +22,12 @@ import com.flipkart.ranger.core.finderhub.ServiceFinderFactory; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.flipkart.ranger.zookeeper.servicefinderhub.ZKUnshardedServiceFinderFactory; import lombok.Builder; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; -import java.io.IOException; import java.util.List; @Slf4j diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java new file mode 100644 index 00000000..47f85b59 --- /dev/null +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java @@ -0,0 +1,61 @@ +package com.flipkart.ranger.client.zk; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.healthcheck.HealthcheckResult; +import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; +import lombok.*; +import lombok.extern.slf4j.Slf4j; +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.CuratorFrameworkFactory; +import org.apache.curator.retry.ExponentialBackoffRetry; +import org.apache.curator.test.TestingCluster; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; +import java.util.Date; +import java.util.Optional; + +@Slf4j +@Getter +public abstract class BaseZKHubTest extends BaseZKTest{ + @Data + @Builder + @AllArgsConstructor + private static class TestCriteria implements Criteria { + @Override + public boolean apply(TestNodeData nodeData) { + return nodeData.getNodeId() == 1; + } + } + + protected abstract AbstractZKHubClient getClient(); + + @Test + public void testShardedHub(){ + val zkHubClient = getClient(); + zkHubClient.start(); + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "s1"); + Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); + Assert.assertTrue(node.isPresent()); + + node = zkHubClient.getNode(service, new TestCriteria()); + Assert.assertTrue(node.isPresent()); + + zkHubClient.stop(); + } +} diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java similarity index 59% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java index 96b24fde..ef24902a 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubClientTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java @@ -1,50 +1,38 @@ package com.flipkart.ranger.client.zk; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; -import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.serviceprovider.ServiceProvider; import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; -import lombok.*; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import lombok.val; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; import org.apache.curator.test.TestingCluster; import org.junit.After; -import org.junit.Assert; import org.junit.Before; -import org.junit.Test; import java.io.IOException; import java.util.Collections; import java.util.Date; -import java.util.Optional; @Slf4j -public class ShardedZKHubClientTest { - - @Data - @Builder - @AllArgsConstructor - private static class TestCriteria implements Criteria { - @Override - public boolean apply(TestNodeData nodeData) { - return nodeData.getNodeId() == 1; - } - } +@Getter +public abstract class BaseZKTest { private TestingCluster testingCluster; private ObjectMapper objectMapper = new ObjectMapper(); private CuratorFramework curatorFramework; + private ServiceProvider> provider; @Before public void startTestCluster() throws Exception { @@ -58,6 +46,7 @@ public void startTestCluster() throws Exception { .build(); curatorFramework.start(); curatorFramework.blockUntilConnected(); + initilizeProvider(); log.debug("Started zk subsystem"); } @@ -68,11 +57,14 @@ public void stopTestCluster() throws Exception { if (null != testingCluster) { testingCluster.close(); } + if(null != provider){ + provider.stop(); + } } - private ServiceNode read(final byte[] data) { + protected ServiceNode read(final byte[] data) { try { - return objectMapper.readValue(data, new TypeReference>() {}); + return getObjectMapper().readValue(data, new TypeReference>() {}); } catch (IOException e) { Exceptions.illegalState(e); @@ -80,9 +72,9 @@ private ServiceNode read(final byte[] data) { return null; } - private byte[] write(final ServiceNode node) { + protected byte[] write(final ServiceNode node) { try { - return objectMapper.writeValueAsBytes(node); + return getObjectMapper().writeValueAsBytes(node); } catch (IOException e) { Exceptions.illegalState(e); @@ -90,24 +82,13 @@ private byte[] write(final ServiceNode node) { return null; } - @Test - public void testShardedHub(){ - val zkHubClient = ShardedZKHubClient.>builder() - .namespace("test-n") - .connectionString(testingCluster.getConnectString()) - .curatorFramework(curatorFramework) - .disablePushUpdaters(true) - .mapper(objectMapper) - .deserializer(this::read) - .build(); - zkHubClient.start(); - + protected void initilizeProvider(){ ExternalTriggeredSignal refreshProviderSignal = new ExternalTriggeredSignal<>( () -> HealthcheckResult.builder() .status(HealthcheckStatus.healthy) .updatedTime(new Date().getTime()) .build(), Collections.emptyList()); - val provider1 = ServiceProviderBuilders.shardedServiceProviderBuilder() + provider = ServiceProviderBuilders.shardedServiceProviderBuilder() .withHostname("localhost") .withPort(1080) .withNamespace("test-n") @@ -116,25 +97,11 @@ public void testShardedHub(){ .withNodeData(new TestNodeData(1)) .withHealthcheck(() -> HealthcheckStatus.healthy) .withadditionalRefreshSignal(refreshProviderSignal) - .withCuratorFramework(curatorFramework) + .withCuratorFramework(getCuratorFramework()) .build(); - provider1.start(); - + provider.start(); refreshProviderSignal.trigger(); + } - TestUtils.sleepForSeconds(6); - - val service = new Service("test-n", "s1"); - Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); - Assert.assertTrue(node.isPresent()); - - node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 1); - Assert.assertTrue(node.isPresent()); - - node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 2); - Assert.assertFalse(node.isPresent()); - zkHubClient.stop(); - provider1.stop(); - } } diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java new file mode 100644 index 00000000..140e9ae5 --- /dev/null +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java @@ -0,0 +1,21 @@ +package com.flipkart.ranger.client.zk; + +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.units.TestNodeData; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ShardedZKHubTest extends BaseZKHubTest { + + @Override + protected AbstractZKHubClient getClient() { + return ShardedZKHubClient.>builder() + .namespace("test-n") + .connectionString(getTestingCluster().getConnectString()) + .curatorFramework(getCuratorFramework()) + .disablePushUpdaters(true) + .mapper(getObjectMapper()) + .deserializer(this::read) + .build(); + } +} diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java new file mode 100644 index 00000000..2b183c03 --- /dev/null +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java @@ -0,0 +1,38 @@ +package com.flipkart.ranger.client.zk; + +import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; + +public class SimpleRangerZKClienTest extends BaseZKTest{ + + @Test + public void testBaseClient(){ + val client = SimpleRangerZKClient., ZkNodeDataDeserializer>fromCurator() + .curatorFramework(getCuratorFramework()) + .deserializer(this::read) + .namespace("test-n") + .serviceName("s1") + .disableWatchers(true) + .mapper(getObjectMapper()) + .build(); + client.start(); + + Optional> node = client.getNode(); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(c -> c.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(c -> c.getNodeId() == 2); + Assert.assertFalse(node.isPresent()); + } +} diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java new file mode 100644 index 00000000..5d75aa1c --- /dev/null +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java @@ -0,0 +1,21 @@ +package com.flipkart.ranger.client.zk; + +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.units.TestNodeData; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class UnshardedZKHubTest extends BaseZKHubTest { + + @Override + protected AbstractZKHubClient getClient() { + return UnshardedZKHubClient.>builder() + .namespace("test-n") + .connectionString(getTestingCluster().getConnectString()) + .curatorFramework(getCuratorFramework()) + .disablePushUpdaters(true) + .mapper(getObjectMapper()) + .deserializer(this::read) + .build(); + } +} From ac1360a26673bd27588fcad4299e0097615d0a28 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 12:19:10 +0530 Subject: [PATCH 48/53] Added tests for ranger http client --- README.md | 1 - ...ient.java => AbstractRangerHubClient.java} | 4 +- ....java => AbstractRangerHubClientTest.java} | 8 +- .../ServiceRegistryUpdater.java | 2 +- ranger-http-client/pom.xml | 6 ++ ...t.java => ShardedRangerHttpHubClient.java} | 10 +- .../client/http/SimpleRangerHttpClient.java | 4 +- ...java => UnshardedRangerHttpHubClient.java} | 6 +- .../client/http/BaseRangerHttpClientTest.java | 94 +++++++++++++++++++ .../http/ShardedRangerHttpClientTest.java | 40 ++++++++ .../http/SimpleRangerHttpClientTest.java | 41 ++++++++ .../http/UnshardedRangerHttpClientTest.java | 40 ++++++++ .../server/manager/RangerClientManager.java | 7 +- ...nt.java => AbstractRangerZKHubClient.java} | 6 +- ...ent.java => ShardedRangerZKHubClient.java} | 4 +- .../client/zk/SimpleRangerZKClient.java | 10 +- ...t.java => UnshardedRangerZKHubClient.java} | 4 +- ...t.java => AbstractZKRangerClientTest.java} | 20 +--- ...KTest.java => BaseRangerZKClientTest.java} | 2 +- ...st.java => ShardedZKRangerClientTest.java} | 6 +- ...est.java => SimpleRangerZKClientTest.java} | 4 +- ....java => UnshardedZKRangerClientTest.java} | 6 +- 22 files changed, 265 insertions(+), 60 deletions(-) rename ranger-client/src/main/java/com/flipkart/ranger/client/{AbstractHubClient.java => AbstractRangerHubClient.java} (93%) rename ranger-client/src/test/java/com/flipkart/ranger/client/{AbstractHubClientTest.java => AbstractRangerHubClientTest.java} (91%) rename ranger-http-client/src/main/java/com/flipkart/ranger/client/http/{ShardedHttpHubClient.java => ShardedRangerHttpHubClient.java} (88%) rename ranger-http-client/src/main/java/com/flipkart/ranger/client/http/{UnshardedHttpHubClient.java => UnshardedRangerHttpHubClient.java} (92%) create mode 100644 ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java create mode 100644 ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java create mode 100644 ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java create mode 100644 ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java rename ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/{AbstractZKHubClient.java => AbstractRangerZKHubClient.java} (92%) rename ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/{ShardedZKHubClient.java => ShardedRangerZKHubClient.java} (93%) rename ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/{UnshardedZKHubClient.java => UnshardedRangerZKHubClient.java} (92%) rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{BaseZKHubTest.java => AbstractZKRangerClientTest.java} (57%) rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{BaseZKTest.java => BaseRangerZKClientTest.java} (98%) rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{ShardedZKHubTest.java => ShardedZKRangerClientTest.java} (70%) rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{SimpleRangerZKClienTest.java => SimpleRangerZKClientTest.java} (86%) rename ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/{UnshardedZKHubTest.java => UnshardedZKRangerClientTest.java} (70%) diff --git a/README.md b/README.md index 84f49451..1d2884ef 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,6 @@ Stop the finder once you are done. (Generally this is when process ends) ``` serviceFinder.stop() ``` - Version ---- diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java similarity index 93% rename from ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java rename to ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java index fae37f33..65861aa7 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java @@ -15,7 +15,7 @@ @Slf4j @Getter -public abstract class AbstractHubClient, R extends ServiceRegistry, D extends Deserializer> implements RangerHubClient { +public abstract class AbstractRangerHubClient, R extends ServiceRegistry, D extends Deserializer> implements RangerHubClient { private final String namespace; private final ObjectMapper mapper; @@ -25,7 +25,7 @@ public abstract class AbstractHubClient, R extends Serv private int refreshTimeMs; private ServiceFinderHub hub; - public AbstractHubClient( + public AbstractRangerHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, diff --git a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java similarity index 91% rename from ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java rename to ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java index 83cd882e..76cd9c9f 100644 --- a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractHubClientTest.java +++ b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java @@ -20,7 +20,7 @@ import java.util.Optional; @Slf4j -public class AbstractHubClientTest { +public class AbstractRangerHubClientTest { private static final ObjectMapper mapper = new ObjectMapper(); private static final Service service = new Service("test-ns", "test-s"); @@ -108,9 +108,9 @@ private static class TestDeserilizer implements Deserializer{ } - private static class TestAbstractHub extends AbstractHubClient, ListBasedServiceRegistry, TestDeserilizer>{ + private static class TestAbstractRangerHub extends AbstractRangerHubClient, ListBasedServiceRegistry, TestDeserilizer> { - public TestAbstractHub(String namespace, ObjectMapper mapper, int refreshTimeMs, Criteria criteria, TestDeserilizer deserilizer) { + public TestAbstractRangerHub(String namespace, ObjectMapper mapper, int refreshTimeMs, Criteria criteria, TestDeserilizer deserilizer) { super(namespace, mapper, refreshTimeMs, criteria, deserilizer); } @@ -144,7 +144,7 @@ protected ServiceFinderFactory, ListBased @Test public void testAbstractHubClient() { - TestAbstractHub testAbstractHub = new TestAbstractHub(service.getNamespace(), mapper, 1000, new TestCriteria(), new TestDeserilizer<>()); + TestAbstractRangerHub testAbstractHub = new TestAbstractRangerHub(service.getNamespace(), mapper, 1000, new TestCriteria(), new TestDeserilizer<>()); testAbstractHub.start(); TestUtils.sleepForSeconds(3); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 67ffe220..5cdddc35 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -126,7 +126,7 @@ private Void queryExecutor() { } } - private void updateRegistry() { + private void updateRegistry() throws InterruptedException { log.debug("Checking for updates on data source for service: {}", serviceRegistry.getService().getServiceName()); if(!nodeDataSource.isActive()) { diff --git a/ranger-http-client/pom.xml b/ranger-http-client/pom.xml index 67adc469..9041de0a 100644 --- a/ranger-http-client/pom.xml +++ b/ranger-http-client/pom.xml @@ -27,6 +27,12 @@ jackson-databind ${jackson.version} + + com.github.tomakehurst + wiremock + 2.25.1 + test + diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java similarity index 88% rename from ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java rename to ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java index 406f8c2d..58504ab9 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.client.http; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.client.AbstractHubClient; +import com.flipkart.ranger.client.AbstractRangerHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.MatchingShardSelector; @@ -37,13 +37,13 @@ import java.util.List; @Slf4j -public class ShardedHttpHubClient> extends AbstractHubClient, HTTPResponseDataDeserializer> { +public class ShardedRangerHttpHubClient> extends AbstractRangerHubClient, HTTPResponseDataDeserializer> { private List services; private final HttpClientConfig clientConfig; @Builder - public ShardedHttpHubClient( + public ShardedRangerHttpHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, @@ -66,6 +66,10 @@ protected ServiceFinderHub> buildHub() { .build(); } + /* + If the client knows the services for which a refresh ought to be run. Use that + information instead of a data source! Handy during service integrations! + */ @Override protected ServiceDataSource buildServiceDataSource() { return null != services && !services.isEmpty() ? diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java index 7dd74f8d..ed2464e4 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java @@ -43,7 +43,7 @@ public SimpleRangerHttpClient( String namespace, String serviceName, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, HttpClientConfig clientConfig, C criteria, D deserializer @@ -60,7 +60,7 @@ public SimpleRangerHttpClient( .withServiceName(serviceName) .withNamespace(namespace) .withObjectMapper(mapper) - .withNodeRefreshIntervalMs(refreshTimeMs) + .withNodeRefreshIntervalMs(nodeRefreshIntervalMs) .withDeserializer(deserializer) .withShardSelector(new ListShardSelector<>()) .build(); diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java similarity index 92% rename from ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java rename to ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java index 66f1b9ae..6ea0a5d2 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.client.http; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.client.AbstractHubClient; +import com.flipkart.ranger.client.AbstractRangerHubClient; import com.flipkart.ranger.core.finder.nodeselector.RoundRobinServiceNodeSelector; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; import com.flipkart.ranger.core.finder.shardselector.ListShardSelector; @@ -37,13 +37,13 @@ import java.util.List; @Slf4j -public class UnshardedHttpHubClient> extends AbstractHubClient, HTTPResponseDataDeserializer> { +public class UnshardedRangerHttpHubClient> extends AbstractRangerHubClient, HTTPResponseDataDeserializer> { private List services; private final HttpClientConfig clientConfig; @Builder - public UnshardedHttpHubClient( + public UnshardedRangerHttpHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java new file mode 100644 index 00000000..8803e6ff --- /dev/null +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java @@ -0,0 +1,94 @@ +package com.flipkart.ranger.client.http; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.flipkart.ranger.core.healthcheck.HealthcheckResult; +import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.serviceprovider.ServiceProvider; +import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.core.util.Exceptions; +import com.flipkart.ranger.http.config.HttpClientConfig; +import com.flipkart.ranger.http.model.ServiceDataSourceResponse; +import com.flipkart.ranger.http.model.ServiceNodesResponse; +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.google.common.collect.Lists; +import lombok.Data; +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; +import java.util.Collections; +import java.util.Date; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; + +@Slf4j +@Getter +public abstract class BaseRangerHttpClientTest { + + private final ObjectMapper objectMapper = new ObjectMapper(); + @Rule + public WireMockRule server = new WireMockRule(8888); + private HttpClientConfig httpClientConfig; + + @Before + public void startTestCluster() throws Exception { + final TestNodeData testNode = new TestNodeData(1); + final ServiceNode node = new ServiceNode<>("127.0.0.1", 80, testNode); + node.setHealthcheckStatus(HealthcheckStatus.healthy); + node.setLastUpdatedTimeStamp(System.currentTimeMillis()); + val payload = objectMapper.writeValueAsBytes( + ServiceNodesResponse.builder() + .data(Lists.newArrayList(node)) + .success(true) + .build()); + server.stubFor(get(urlEqualTo("/v1/ranger/nodes/test-n/test-s")) + .willReturn(aResponse() + .withBody(payload) + .withStatus(200))); + + val responseObj = ServiceDataSourceResponse.builder() + .success(true) + .data(Lists.newArrayList( + new Service("test-n", "test-s") + )) + .build(); + val response = objectMapper.writeValueAsBytes(responseObj); + server.stubFor(get(urlEqualTo("/v1/ranger/services")) + .willReturn(aResponse() + .withBody(response) + .withStatus(200))); + + httpClientConfig = HttpClientConfig.builder() + .host("127.0.0.1") + .port(server.port()) + .connectionTimeoutMs(30_000) + .operationTimeoutMs(30_000) + .build(); + log.debug("Started http subsystem"); + } + + @After + public void stopTestCluster() { + log.debug("Stopping http subsystem"); + } + + protected ServiceNodesResponse read(final byte[] data) { + try { + return getObjectMapper().readValue(data, new TypeReference>() {}); + } + catch (IOException e) { + Exceptions.illegalState(e); + } + return null; + } +} diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java new file mode 100644 index 00000000..52210b62 --- /dev/null +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java @@ -0,0 +1,40 @@ +package com.flipkart.ranger.client.http; + +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; + +public class ShardedRangerHttpClientTest extends BaseRangerHttpClientTest { + + @Test + public void testShardedHttpHubClient(){ + val client = ShardedRangerHttpHubClient.>builder() + .clientConfig(getHttpClientConfig()) + .namespace("test-n") + .deserializer(this::read) + .mapper(getObjectMapper()) + .build(); + client.start(); + + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "test-s"); + Optional> node = client.getNode(service); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(service, nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(service, nodeData -> nodeData.getNodeId() == 2); + Assert.assertFalse(node.isPresent()); + + client.stop(); + } +} diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java new file mode 100644 index 00000000..97255c3e --- /dev/null +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java @@ -0,0 +1,41 @@ +package com.flipkart.ranger.client.http; + +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import com.flipkart.ranger.http.serde.HTTPResponseDataDeserializer; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; + +public class SimpleRangerHttpClientTest extends BaseRangerHttpClientTest{ + + @Test + public void testSimpleHttpRangerClient(){ + val client = SimpleRangerHttpClient., HTTPResponseDataDeserializer>builder() + .clientConfig(getHttpClientConfig()) + .mapper(getObjectMapper()) + .deserializer(this::read) + .namespace("test-n") + .serviceName("test-s") + .refreshTimeMs(5000) + .build(); + client.start(); + + TestUtils.sleepForSeconds(6); + + Optional> node = client.getNode(); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(nodeData -> nodeData.getNodeId() == 2); + Assert.assertFalse(node.isPresent()); + + client.stop(); + } +} diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java new file mode 100644 index 00000000..f14841f5 --- /dev/null +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java @@ -0,0 +1,40 @@ +package com.flipkart.ranger.client.http; + +import com.flipkart.ranger.core.TestUtils; +import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; +import com.flipkart.ranger.core.units.TestNodeData; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; + +public class UnshardedRangerHttpClientTest extends BaseRangerHttpClientTest { + + @Test + public void testUnshardedRangerHubClient(){ + val client = UnshardedRangerHttpHubClient.>builder() + .clientConfig(getHttpClientConfig()) + .namespace("test-n") + .deserializer(this::read) + .mapper(getObjectMapper()) + .build(); + client.start(); + + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "test-s"); + Optional> node = client.getNode(service); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(service, nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + node = client.getNode(service, nodeData -> nodeData.getNodeId() == 2); + Assert.assertFalse(node.isPresent()); + + client.stop(); + } +} diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java index 84a5a1b6..25d35147 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java @@ -17,9 +17,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.client.Constants; -import com.flipkart.ranger.client.zk.UnshardedZKHubClient; +import com.flipkart.ranger.client.zk.UnshardedRangerZKHubClient; import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.server.config.RangerConfiguration; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; import com.google.common.base.Preconditions; @@ -40,7 +39,7 @@ public class RangerClientManager, D extends ZkNodeDataD private final RangerConfiguration rangerConfiguration; - private UnshardedZKHubClient zkHubClient; + private UnshardedRangerZKHubClient zkHubClient; private CuratorFramework curatorFramework; @Inject @@ -59,7 +58,7 @@ public RangerClientManager( rangerConfiguration.getZookeeper(), new RetryForever(Constants.CONNECTION_RETRY_TIME) ); - zkHubClient = UnshardedZKHubClient.builder() + zkHubClient = UnshardedRangerZKHubClient.builder() .connectionString(rangerConfiguration.getZookeeper()) .curatorFramework(curatorFramework) .disablePushUpdaters(rangerConfiguration.isDisablePushUpdaters()) diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java similarity index 92% rename from ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java rename to ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java index 8548de60..92fe45e0 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java @@ -16,7 +16,7 @@ package com.flipkart.ranger.client.zk; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.client.AbstractHubClient; +import com.flipkart.ranger.client.AbstractRangerHubClient; import com.flipkart.ranger.core.finderhub.ServiceDataSource; import com.flipkart.ranger.core.finderhub.ServiceFinderHub; import com.flipkart.ranger.core.finderhub.StaticDataSource; @@ -36,7 +36,7 @@ @Slf4j @Getter -public abstract class AbstractZKHubClient, R extends ServiceRegistry, D extends ZkNodeDataDeserializer> extends AbstractHubClient { +public abstract class AbstractRangerZKHubClient, R extends ServiceRegistry, D extends ZkNodeDataDeserializer> extends AbstractRangerHubClient { private final boolean disablePushUpdaters; private final String connectionString; @@ -47,7 +47,7 @@ public abstract class AbstractZKHubClient, R extends Se */ private final List services; - public AbstractZKHubClient( + public AbstractRangerZKHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java similarity index 93% rename from ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java rename to ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java index 033ee15d..a80f3c10 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java @@ -31,10 +31,10 @@ import java.util.List; @Slf4j -public class ShardedZKHubClient> extends AbstractZKHubClient, ZkNodeDataDeserializer> { +public class ShardedRangerZKHubClient> extends AbstractRangerZKHubClient, ZkNodeDataDeserializer> { @Builder - public ShardedZKHubClient( + public ShardedRangerZKHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java index da9247d5..13662e18 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java @@ -48,7 +48,7 @@ public SimpleRangerZKClient( String namespace, String serviceName, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, boolean disableWatchers, String connectionString, C criteria, @@ -58,7 +58,7 @@ public SimpleRangerZKClient( namespace, serviceName, mapper, - refreshTimeMs, + nodeRefreshIntervalMs, disableWatchers, CuratorFrameworkFactory.newClient(connectionString, new RetryForever(Constants.CONNECTION_RETRY_TIME)), criteria, @@ -71,7 +71,7 @@ public SimpleRangerZKClient( String namespace, String serviceName, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, boolean disableWatchers, CuratorFramework curatorFramework, C criteria, @@ -81,11 +81,11 @@ public SimpleRangerZKClient( Preconditions.checkNotNull(namespace, "namespace can't be null"); Preconditions.checkNotNull(deserializer, "deserializer can't be null"); - int effectiveRefreshTime = refreshTimeMs; + int effectiveRefreshTime = nodeRefreshIntervalMs; if (effectiveRefreshTime < Constants.MINIMUM_REFRESH_TIME) { effectiveRefreshTime = Constants.MINIMUM_REFRESH_TIME; log.warn("Node info update interval too low: {} ms. Has been upgraded to {} ms ", - refreshTimeMs, + nodeRefreshIntervalMs, Constants.MINIMUM_REFRESH_TIME); } diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java similarity index 92% rename from ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java rename to ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java index 006732a9..f4c90705 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java @@ -31,10 +31,10 @@ import java.util.List; @Slf4j -public class UnshardedZKHubClient> extends AbstractZKHubClient, ZkNodeDataDeserializer> { +public class UnshardedRangerZKHubClient> extends AbstractRangerZKHubClient, ZkNodeDataDeserializer> { @Builder - public UnshardedZKHubClient( + public UnshardedRangerZKHubClient( String namespace, ObjectMapper mapper, int refreshTimeMs, diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java similarity index 57% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java index 47f85b59..47577386 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKHubTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java @@ -1,36 +1,20 @@ package com.flipkart.ranger.client.zk; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; import com.flipkart.ranger.core.TestUtils; -import com.flipkart.ranger.core.healthcheck.HealthcheckResult; -import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.Criteria; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.units.TestNodeData; -import com.flipkart.ranger.core.util.Exceptions; -import com.flipkart.ranger.zookeeper.ServiceProviderBuilders; import lombok.*; import lombok.extern.slf4j.Slf4j; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; -import org.apache.curator.test.TestingCluster; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; -import java.io.IOException; -import java.util.Collections; -import java.util.Date; import java.util.Optional; @Slf4j @Getter -public abstract class BaseZKHubTest extends BaseZKTest{ +public abstract class AbstractZKRangerClientTest extends BaseRangerZKClientTest { @Data @Builder @AllArgsConstructor @@ -41,7 +25,7 @@ public boolean apply(TestNodeData nodeData) { } } - protected abstract AbstractZKHubClient getClient(); + protected abstract AbstractRangerZKHubClient getClient(); @Test public void testShardedHub(){ diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java similarity index 98% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java index ef24902a..66bc498f 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseZKTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java @@ -27,7 +27,7 @@ @Slf4j @Getter -public abstract class BaseZKTest { +public abstract class BaseRangerZKClientTest { private TestingCluster testingCluster; private ObjectMapper objectMapper = new ObjectMapper(); diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java similarity index 70% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java index 140e9ae5..59177563 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKHubTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java @@ -5,11 +5,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class ShardedZKHubTest extends BaseZKHubTest { +public class ShardedZKRangerClientTest extends AbstractZKRangerClientTest { @Override - protected AbstractZKHubClient getClient() { - return ShardedZKHubClient.>builder() + protected AbstractRangerZKHubClient getClient() { + return ShardedRangerZKHubClient.>builder() .namespace("test-n") .connectionString(getTestingCluster().getConnectString()) .curatorFramework(getCuratorFramework()) diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClientTest.java similarity index 86% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClientTest.java index 2b183c03..f2fa998e 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClienTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/SimpleRangerZKClientTest.java @@ -1,8 +1,6 @@ package com.flipkart.ranger.client.zk; -import com.flipkart.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.zookeeper.serde.ZkNodeDataDeserializer; @@ -12,7 +10,7 @@ import java.util.Optional; -public class SimpleRangerZKClienTest extends BaseZKTest{ +public class SimpleRangerZKClientTest extends BaseRangerZKClientTest { @Test public void testBaseClient(){ diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java similarity index 70% rename from ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java rename to ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java index 5d75aa1c..5af2fae6 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKHubTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java @@ -5,11 +5,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public class UnshardedZKHubTest extends BaseZKHubTest { +public class UnshardedZKRangerClientTest extends AbstractZKRangerClientTest { @Override - protected AbstractZKHubClient getClient() { - return UnshardedZKHubClient.>builder() + protected AbstractRangerZKHubClient getClient() { + return UnshardedRangerZKHubClient.>builder() .namespace("test-n") .connectionString(getTestingCluster().getConnectString()) .curatorFramework(getCuratorFramework()) From ab63403c23b38a51cef7ec943e2ebff84202f962 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 12:38:20 +0530 Subject: [PATCH 49/53] Simplified the extension tests in http module --- .../http/ShardedRangerHttpHubClient.java | 4 +- .../http/UnshardedRangerHttpHubClient.java | 4 +- .../http/ShardedRangerHttpClientTest.java | 1 + .../http/SimpleRangerHttpClientTest.java | 2 +- .../http/UnshardedRangerHttpClientTest.java | 1 + .../client/zk/AbstractZKRangerClientTest.java | 45 ------------------- .../client/zk/ShardedZKRangerClientTest.java | 28 ++++++++++-- .../zk/UnshardedZKRangerClientTest.java | 28 ++++++++++-- 8 files changed, 55 insertions(+), 58 deletions(-) delete mode 100644 ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java index 58504ab9..9db4e970 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java @@ -46,13 +46,13 @@ public class ShardedRangerHttpHubClient> extends Abstra public ShardedRangerHttpHubClient( String namespace, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, C criteria, HTTPResponseDataDeserializer deserializer, HttpClientConfig clientConfig, List services ) { - super(namespace, mapper, refreshTimeMs, criteria, deserializer); + super(namespace, mapper, nodeRefreshIntervalMs, criteria, deserializer); this.clientConfig = clientConfig; this.services = services; } diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java index 6ea0a5d2..1f9f7658 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java @@ -46,13 +46,13 @@ public class UnshardedRangerHttpHubClient> extends Abst public UnshardedRangerHttpHubClient( String namespace, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, C criteria, HTTPResponseDataDeserializer deserializer, HttpClientConfig clientConfig, List services ) { - super(namespace, mapper, refreshTimeMs, criteria, deserializer); + super(namespace, mapper, nodeRefreshIntervalMs, criteria, deserializer); this.clientConfig = clientConfig; this.services = services; } diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java index 52210b62..f42d8ec4 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java @@ -20,6 +20,7 @@ public void testShardedHttpHubClient(){ .namespace("test-n") .deserializer(this::read) .mapper(getObjectMapper()) + .nodeRefreshIntervalMs(5000) .build(); client.start(); diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java index 97255c3e..40315cd2 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java @@ -21,7 +21,7 @@ public void testSimpleHttpRangerClient(){ .deserializer(this::read) .namespace("test-n") .serviceName("test-s") - .refreshTimeMs(5000) + .nodeRefreshIntervalMs(5000) .build(); client.start(); diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java index f14841f5..135dce65 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java @@ -20,6 +20,7 @@ public void testUnshardedRangerHubClient(){ .namespace("test-n") .deserializer(this::read) .mapper(getObjectMapper()) + .nodeRefreshIntervalMs(5000) .build(); client.start(); diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java deleted file mode 100644 index 47577386..00000000 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/AbstractZKRangerClientTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.flipkart.ranger.client.zk; - -import com.flipkart.ranger.core.TestUtils; -import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Service; -import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.units.TestNodeData; -import lombok.*; -import lombok.extern.slf4j.Slf4j; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Optional; - -@Slf4j -@Getter -public abstract class AbstractZKRangerClientTest extends BaseRangerZKClientTest { - @Data - @Builder - @AllArgsConstructor - private static class TestCriteria implements Criteria { - @Override - public boolean apply(TestNodeData nodeData) { - return nodeData.getNodeId() == 1; - } - } - - protected abstract AbstractRangerZKHubClient getClient(); - - @Test - public void testShardedHub(){ - val zkHubClient = getClient(); - zkHubClient.start(); - TestUtils.sleepForSeconds(6); - - val service = new Service("test-n", "s1"); - Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); - Assert.assertTrue(node.isPresent()); - - node = zkHubClient.getNode(service, new TestCriteria()); - Assert.assertTrue(node.isPresent()); - - zkHubClient.stop(); - } -} diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java index 59177563..a67fda0c 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/ShardedZKRangerClientTest.java @@ -1,15 +1,23 @@ package com.flipkart.ranger.client.zk; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; @Slf4j -public class ShardedZKRangerClientTest extends AbstractZKRangerClientTest { +public class ShardedZKRangerClientTest extends BaseRangerZKClientTest { - @Override - protected AbstractRangerZKHubClient getClient() { - return ShardedRangerZKHubClient.>builder() + @Test + public void testShardedHub(){ + val zkHubClient = ShardedRangerZKHubClient.>builder() .namespace("test-n") .connectionString(getTestingCluster().getConnectString()) .curatorFramework(getCuratorFramework()) @@ -17,5 +25,17 @@ protected AbstractRangerZKHubClient getClient() { .mapper(getObjectMapper()) .deserializer(this::read) .build(); + + zkHubClient.start(); + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "s1"); + Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); + Assert.assertTrue(node.isPresent()); + + node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + zkHubClient.stop(); } } diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java index 5af2fae6..5dfe5e56 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/UnshardedZKRangerClientTest.java @@ -1,15 +1,23 @@ package com.flipkart.ranger.client.zk; +import com.flipkart.ranger.core.TestUtils; import com.flipkart.ranger.core.model.Criteria; +import com.flipkart.ranger.core.model.Service; +import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; import lombok.extern.slf4j.Slf4j; +import lombok.val; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Optional; @Slf4j -public class UnshardedZKRangerClientTest extends AbstractZKRangerClientTest { +public class UnshardedZKRangerClientTest extends BaseRangerZKClientTest { - @Override - protected AbstractRangerZKHubClient getClient() { - return UnshardedRangerZKHubClient.>builder() + @Test + public void testShardedHub(){ + val zkHubClient =UnshardedRangerZKHubClient.>builder() .namespace("test-n") .connectionString(getTestingCluster().getConnectString()) .curatorFramework(getCuratorFramework()) @@ -17,5 +25,17 @@ protected AbstractRangerZKHubClient getClient() { .mapper(getObjectMapper()) .deserializer(this::read) .build(); + + zkHubClient.start(); + TestUtils.sleepForSeconds(6); + + val service = new Service("test-n", "s1"); + Optional> node = zkHubClient.getNode(new Service("test-n", "s1")); + Assert.assertTrue(node.isPresent()); + + node = zkHubClient.getNode(service, nodeData -> nodeData.getNodeId() == 1); + Assert.assertTrue(node.isPresent()); + + zkHubClient.stop(); } } From 65582497b77c141dfbe2806bd5e0a5eb49d4b4dc Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 12:38:46 +0530 Subject: [PATCH 50/53] Optimized imports --- .../ranger/client/http/BaseRangerHttpClientTest.java | 8 -------- .../flipkart/ranger/client/zk/BaseRangerZKClientTest.java | 1 - 2 files changed, 9 deletions(-) diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java index 8803e6ff..68a87384 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java @@ -1,14 +1,10 @@ package com.flipkart.ranger.client.http; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.flipkart.ranger.core.healthcheck.HealthcheckResult; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; -import com.flipkart.ranger.core.serviceprovider.ServiceProvider; -import com.flipkart.ranger.core.signals.ExternalTriggeredSignal; import com.flipkart.ranger.core.units.TestNodeData; import com.flipkart.ranger.core.util.Exceptions; import com.flipkart.ranger.http.config.HttpClientConfig; @@ -16,18 +12,14 @@ import com.flipkart.ranger.http.model.ServiceNodesResponse; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.google.common.collect.Lists; -import lombok.Data; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import lombok.val; import org.junit.After; import org.junit.Before; import org.junit.Rule; -import org.junit.Test; import java.io.IOException; -import java.util.Collections; -import java.util.Date; import static com.github.tomakehurst.wiremock.client.WireMock.*; diff --git a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java index 66bc498f..40b74f08 100644 --- a/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java +++ b/ranger-zk-client/src/test/java/com/flipkart/ranger/client/zk/BaseRangerZKClientTest.java @@ -13,7 +13,6 @@ import com.flipkart.ranger.zookeeper.serde.ZkNodeDataSerializer; import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import lombok.val; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.retry.ExponentialBackoffRetry; From 5090dcf981172e7d65ae5de7a8e9fa84c42559be Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 12:45:55 +0530 Subject: [PATCH 51/53] Added changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29b..9de76ad8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1,8 @@ +## 1.0 SNAPSHOT + +* The nodeData T in the ServiceNode has been broken from the Criteria used in the shard selectors, to help for dynamic binding of criteria, so node filters can be dictated by the clients who are using the bundle, basis any of the client specific parameters. +* A service hub has been introduced to help with not having to do the boilerplate code everytime a finder is initialized. Particularly handy when there are tens of services to be initialized +* Signals have been introduced as a first class concept to help with the lifecycle management of serviceprovider and servicefinder +* The ranger module has been further broken down into ranger-core (To define the core framework of ranger), ranger-zk and ranger-http (To appropriate the ranger-core with the respective implementations for zk and http data sources). ranger-zk-client and ranger-http-client(To appropriate the finderhub implementations for zk and http data sources respectively) +* A sample ranger-server has been added to facilitate writing a http finder backend, atop a service huub (In this case the zk service hub) +* An extensive test suite to test the multiple modules has been added as well. \ No newline at end of file From 6eaad53b4885864aad400693f0304898534fdae0 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 13:02:18 +0530 Subject: [PATCH 52/53] Changed the refreshIntervalMs in AbstractZKClient to nodeRefreshIntervalMs to have it consistent with the rest of the code --- .../com/flipkart/ranger/client/AbstractRangerHubClient.java | 4 ++-- .../flipkart/ranger/client/zk/AbstractRangerZKHubClient.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java index 65861aa7..40cd5ffa 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java @@ -28,13 +28,13 @@ public abstract class AbstractRangerHubClient, R extend public AbstractRangerHubClient( String namespace, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshTimeMs, C criteria, D deserializer ){ this.namespace = namespace; this.mapper = mapper; - this.refreshTimeMs = refreshTimeMs; + this.refreshTimeMs = nodeRefreshTimeMs; this.criteria = criteria; this.deserializer = deserializer; } diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java index 92fe45e0..116352ea 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java @@ -50,7 +50,7 @@ public abstract class AbstractRangerZKHubClient, R exte public AbstractRangerZKHubClient( String namespace, ObjectMapper mapper, - int refreshTimeMs, + int nodeRefreshIntervalMs, boolean disablePushUpdaters, String connectionString, CuratorFramework curatorFramework, @@ -58,7 +58,7 @@ public AbstractRangerZKHubClient( D deserializer, List services ) { - super(namespace, mapper, refreshTimeMs, criteria, deserializer); + super(namespace, mapper, nodeRefreshIntervalMs, criteria, deserializer); this.disablePushUpdaters = disablePushUpdaters; this.connectionString = connectionString; this.services = services; From 1773c67b9008f835b9b672321ae6afe281343247 Mon Sep 17 00:00:00 2001 From: Koushik R Date: Mon, 18 Oct 2021 13:36:22 +0530 Subject: [PATCH 53/53] 1. Changed the license to javadoc format. 2. Made attributes final where acquired. 3. Addee license on the missing files. 4. Sonar fixes --- .../client/AbstractRangerHubClient.java | 17 ++++++++++++- .../com/flipkart/ranger/client/Constants.java | 15 ++++++++++++ .../flipkart/ranger/client/RangerClient.java | 4 ++-- .../ranger/client/RangerHubClient.java | 12 ++++------ .../client/AbstractRangerHubClientTest.java | 16 ++++++++++++- .../core/finder/BaseServiceFinderBuilder.java | 5 ++-- .../ranger/core/finder/ServiceFinder.java | 2 +- .../finder/SimpleShardedServiceFinder.java | 2 +- .../SimpleShardedServiceFinderBuilder.java | 2 +- .../finder/SimpleUnshardedServiceFinder.java | 8 +++---- .../SimpleUnshardedServiceFinderBuilder.java | 3 +-- .../RandomServiceNodeSelector.java | 3 +-- .../RoundRobinServiceNodeSelector.java | 3 +-- .../ListBasedServiceRegistry.java | 5 ++-- .../MapBasedServiceRegistry.java | 11 ++++----- .../ServiceRegistryUpdater.java | 17 +++++++------ .../signal/ScheduledRegistryUpdateSignal.java | 2 +- .../shardselector/ListShardSelector.java | 2 +- .../shardselector/MatchingShardSelector.java | 2 +- .../shardselector/NoopShardSelector.java | 3 +-- .../core/finderhub/ServiceDataSource.java | 8 +++---- .../core/finderhub/ServiceFinderFactory.java | 8 +++---- .../core/finderhub/ServiceFinderHub.java | 12 +++++----- .../finderhub/ServiceFinderHubBuilder.java | 14 +++++------ .../core/finderhub/StaticDataSource.java | 8 +++---- .../core/healthcheck/HealthChecker.java | 3 +-- .../ranger/core/healthcheck/Healthcheck.java | 8 +++---- .../core/healthcheck/HealthcheckResult.java | 8 +++---- .../core/healthcheck/HealthcheckStatus.java | 9 ++++--- .../ranger/core/healthcheck/Healthchecks.java | 8 +++---- .../core/healthservice/HealthService.java | 10 ++++---- .../ServiceHealthAggregator.java | 4 ++-- .../ranger/core/healthservice/TimeEntity.java | 11 ++++----- .../monitor/IsolatedHealthMonitor.java | 10 ++++---- .../core/healthservice/monitor/Monitor.java | 10 ++++---- .../core/healthservice/monitor/Monitors.java | 11 ++++----- .../monitor/RollingWindowHealthQueue.java | 10 ++++---- .../monitor/sample/CountMonitor.java | 24 ++++--------------- .../monitor/sample/DiskSpaceMonitor.java | 11 ++++----- .../monitor/sample/PingCheckMonitor.java | 11 ++++----- .../monitor/sample/RotationStatusMonitor.java | 10 ++++---- .../flipkart/ranger/core/model/Criteria.java | 8 +++---- .../ranger/core/model/Deserializer.java | 9 ++++--- .../ranger/core/model/NodeDataSink.java | 8 +++---- .../ranger/core/model/NodeDataSource.java | 8 +++---- .../core/model/NodeDataStoreConnector.java | 8 +++---- .../ranger/core/model/Serializer.java | 8 +++---- .../flipkart/ranger/core/model/Service.java | 9 ++++--- .../ranger/core/model/ServiceNode.java | 4 ++-- .../core/model/ServiceNodeSelector.java | 3 +-- .../ranger/core/model/ServiceRegistry.java | 9 ++++--- .../ranger/core/model/ShardSelector.java | 9 ++++--- .../BaseServiceProviderBuilder.java | 8 +++---- .../core/serviceprovider/ServiceProvider.java | 8 +++---- .../core/signals/ExternalTriggeredSignal.java | 8 +++---- .../ranger/core/signals/ScheduledSignal.java | 8 +++---- .../flipkart/ranger/core/signals/Signal.java | 8 +++---- .../flipkart/ranger/core/util/Exceptions.java | 8 +++---- .../ranger/core/util/FinderUtils.java | 8 +++---- .../com/flipkart/ranger/core/TestUtils.java | 8 +++---- .../core/finder/SimpleShardFinderTest.java | 8 +++---- .../finder/UnshardedClusterFinderTest.java | 8 +++---- .../RoundRobinServiceNodeSelectorTest.java | 12 +++++----- .../MapBasedServiceRegistryTest.java | 8 +++---- .../shardselector/ListShardSelectorTest.java | 8 +++---- .../MatchingShardSelectorTest.java | 8 +++---- .../serviceprovider/ServiceProviderTest.java | 8 +++---- .../ranger/core/units/TestNodeData.java | 8 +++---- .../ranger/core/utils/CriteriaUtils.java | 8 +++---- .../ranger/core/utils/RegistryTestUtils.java | 8 +++---- .../http/ShardedRangerHttpHubClient.java | 10 ++++---- .../client/http/SimpleRangerHttpClient.java | 12 ++++------ .../http/UnshardedRangerHttpHubClient.java | 10 ++++---- .../client/http/BaseRangerHttpClientTest.java | 15 ++++++++++++ .../http/ShardedRangerHttpClientTest.java | 15 ++++++++++++ .../http/SimpleRangerHttpClientTest.java | 15 ++++++++++++ .../http/UnshardedRangerHttpClientTest.java | 15 ++++++++++++ .../http/HttpServiceFinderBuilders.java | 8 +++---- .../http/HttpServiceProviderBuilders.java | 8 +++---- .../common/HttpNodeDataStoreConnector.java | 8 +++---- .../ranger/http/config/HttpClientConfig.java | 8 +++---- .../http/model/ServiceDataSourceResponse.java | 8 +++---- .../http/model/ServiceNodesResponse.java | 8 +++---- .../model/ServiceRegistrationResponse.java | 8 +++---- .../serde/HTTPResponseDataDeserializer.java | 8 +++---- .../http/serde/HttpRequestDataSerializer.java | 8 +++---- .../servicefinder/HttpNodeDataSource.java | 8 +++---- .../HttpShardedServiceFinderBuilder.java | 8 +++---- .../HttpUnshardedServiceFinderBuilider.java | 8 +++---- .../HttpServiceDataSource.java | 8 +++---- .../HttpServiceFinderHubBuilder.java | 8 +++---- .../HttpShardedServiceFinderFactory.java | 8 +++---- .../HttpUnshardedServiceFinderFactory.java | 8 +++---- .../serviceprovider/HttpNodeDataSink.java | 8 +++---- .../HttpShardedServiceProviderBuilder.java | 8 +++---- .../ranger/server/RangerServerBundle.java | 8 +++---- .../server/config/RangerConfiguration.java | 16 ++++++++++++- .../server/manager/RangerClientManager.java | 12 +++++----- .../ranger/server/model/GenericResponse.java | 8 +++---- .../server/resources/RangerResource.java | 8 +++---- .../client/zk/AbstractRangerZKHubClient.java | 2 +- .../client/zk/ShardedRangerZKHubClient.java | 2 +- .../client/zk/SimpleRangerZKClient.java | 16 ++++++------- .../client/zk/UnshardedRangerZKHubClient.java | 8 +++---- .../zookeeper/ServiceFinderBuilders.java | 9 ++++--- .../zookeeper/ServiceProviderBuilders.java | 8 +++---- .../common/ZkNodeDataStoreConnector.java | 8 +++---- .../serde/ZkNodeDataDeserializer.java | 8 +++---- .../zookeeper/serde/ZkNodeDataSerializer.java | 8 +++---- .../servicefinder/ZkNodeDataSource.java | 8 +++---- .../ZkSimpleShardedServiceFinderBuilder.java | 8 +++---- ...ZkSimpleUnshardedServiceFinderBuilder.java | 2 +- .../ZkWatcherRegistryUpdateSignal.java | 8 +++---- .../ZKUnshardedServiceFinderFactory.java | 8 +++---- .../servicefinderhub/ZkServiceDataSource.java | 8 +++---- .../ZkServiceFinderHubBuilder.java | 8 +++---- .../ZkShardedServiceFinderFactory.java | 8 +++---- .../serviceprovider/ZkNodeDataSink.java | 8 +++---- .../ZkServiceProviderBuilder.java | 8 +++---- .../ranger/zookeeper/util/PathBuilder.java | 8 +++---- .../ServiceHealthAggregatorTest.java | 11 ++++----- .../ServiceProviderIntegrationTest.java | 10 ++++---- .../monitor/RollingWindowHealthQueueTest.java | 11 ++++----- .../monitor/sample/DiskSpaceMonitorTest.java | 10 ++++---- .../monitor/sample/PingCheckMonitorTest.java | 11 ++++----- .../sample/RotationStatusMonitorTest.java | 11 ++++----- .../model/CustomShardSelectorTest.java | 9 ++++--- .../model/ServiceNoProviderTest.java | 3 +-- .../model/ServiceProviderExtCuratorTest.java | 9 ++++--- .../model/ServiceProviderHealthcheckTest.java | 8 +++---- .../zookeeper/model/ServiceProviderTest.java | 2 +- .../model/SimpleServiceProviderTest.java | 8 +++---- .../zookeeper/servicehub/ServiceHubTest.java | 2 +- .../BaseServiceProviderBuilderTest.java | 8 +++---- 134 files changed, 599 insertions(+), 526 deletions(-) diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java index 40cd5ffa..1d7584c2 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/AbstractRangerHubClient.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client; import com.fasterxml.jackson.databind.ObjectMapper; @@ -15,7 +30,7 @@ @Slf4j @Getter -public abstract class AbstractRangerHubClient, R extends ServiceRegistry, D extends Deserializer> implements RangerHubClient { +public abstract class AbstractRangerHubClient, R extends ServiceRegistry, D extends Deserializer> implements RangerHubClient { private final String namespace; private final ObjectMapper mapper; diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java b/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java index 018aa9f3..f1cf68f2 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/Constants.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client; public class Constants { diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java index 616a9644..cce0ca7d 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerClient.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,7 @@ import java.util.List; import java.util.Optional; -public interface RangerClient, D extends Deserializer> { +public interface RangerClient> { void start(); diff --git a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java index 75917de5..f9a2534f 100644 --- a/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java +++ b/ranger-client/src/main/java/com/flipkart/ranger/client/RangerHubClient.java @@ -1,30 +1,28 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.client; import com.flipkart.ranger.core.model.Criteria; -import com.flipkart.ranger.core.model.Deserializer; import com.flipkart.ranger.core.model.Service; import com.flipkart.ranger.core.model.ServiceNode; import java.util.List; import java.util.Optional; -public interface RangerHubClient, D extends Deserializer> { +public interface RangerHubClient> { void start(); diff --git a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java index 76cd9c9f..7e755cd1 100644 --- a/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java +++ b/ranger-client/src/test/java/com/flipkart/ranger/client/AbstractRangerHubClientTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client; import com.fasterxml.jackson.databind.ObjectMapper; @@ -40,7 +55,6 @@ public boolean apply(TestShardInfo nodeData) { } - @Data @Builder private static class TestSimpleUnshardedServiceFinder> extends SimpleUnshardedServiceFinderBuilder, Deserializer, Criteria> { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java index 73e04fad..a83df33c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/BaseServiceFinderBuilder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +33,7 @@ import java.util.function.Consumer; @Slf4j +@SuppressWarnings("unchecked") public abstract class BaseServiceFinderBuilder < T, @@ -153,7 +154,7 @@ protected F buildFinder() { log.debug("Added additional signal handlers"); } - val updater = new ServiceRegistryUpdater(registry, nodeDataSource, signalGenerators, deserializer); + val updater = new ServiceRegistryUpdater<>(registry, nodeDataSource, signalGenerators, deserializer); finder.getStartSignal() .registerConsumers(startSignalHandlers) .registerConsumer(x -> nodeDataSource.start()) diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java index 7a9a2194..0ab7ab8a 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/ServiceFinder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java index c77c8d15..44e66eb5 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java index 30dc076a..a6aafb65 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleShardedServiceFinderBuilder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java index ba652efb..783a7a1c 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java index 844bb912..7917b705 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/SimpleUnshardedServiceFinderBuilder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.finder; import com.flipkart.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java index 4e27abf4..6db1c034 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RandomServiceNodeSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java index 9073493b..99b81d14 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java index 77c0522d..c0e7f0ab 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ListBasedServiceRegistry.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.model.Service; @@ -26,7 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; public class ListBasedServiceRegistry extends ServiceRegistry { - private AtomicReference>> nodes + private final AtomicReference>> nodes = new AtomicReference<>(); public ListBasedServiceRegistry(Service service) { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java index 912f0b8b..afaf6fb3 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistry.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.model.Service; @@ -29,7 +28,7 @@ import java.util.concurrent.atomic.AtomicReference; public class MapBasedServiceRegistry extends ServiceRegistry { - private AtomicReference>> nodes = new AtomicReference<>(); + private final AtomicReference>> nodes = new AtomicReference<>(); public MapBasedServiceRegistry(Service service) { super(service); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java index 5cdddc35..5a5a2634 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/ServiceRegistryUpdater.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.finder.serviceregistry; import com.flipkart.ranger.core.model.Deserializer; @@ -44,13 +43,13 @@ public class ServiceRegistryUpdater> { private final NodeDataSource nodeDataSource; private final D deserializer; - private Lock checkLock = new ReentrantLock(); - private Condition checkCondition = checkLock.newCondition(); + private final Lock checkLock = new ReentrantLock(); + private final Condition checkCondition = checkLock.newCondition(); private boolean checkForUpdate = false; private Future queryThreadFuture; - private ExecutorService executorService = Executors.newFixedThreadPool(1); - private AtomicBoolean initialRefreshCompleted = new AtomicBoolean(false); + private final ExecutorService executorService = Executors.newFixedThreadPool(1); + private final AtomicBoolean initialRefreshCompleted = new AtomicBoolean(false); public ServiceRegistryUpdater( ServiceRegistry serviceRegistry, diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java index 1aa9e27d..c728f923 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/serviceregistry/signal/ScheduledRegistryUpdateSignal.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java index 379f4a68..d72fa6ae 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java index ef7af4c7..f94b2363 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java index 9d38f9a8..41d3c8fa 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finder/shardselector/NoopShardSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,7 +23,6 @@ import java.util.List; public class NoopShardSelector> implements ShardSelector> { - @Override public List> nodes(C criteria, ListBasedServiceRegistry serviceRegistry) { return serviceRegistry.nodeList(); diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java index f5843d96..dc579606 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java index 5740be83..d8b9c52e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderFactory.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java index d41918b5..d47298dc 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHub.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -47,7 +47,7 @@ public class ServiceFinderHub, R extends ServiceRegistr private final Lock updateLock = new ReentrantLock(); private final Condition updateCond = updateLock.newCondition(); private boolean updateAvailable = false; - private ExecutorService executorService = Executors.newFixedThreadPool(1); + private final ExecutorService executorService = Executors.newFixedThreadPool(1); @Getter private final ExternalTriggeredSignal startSignal @@ -62,7 +62,7 @@ public class ServiceFinderHub, R extends ServiceRegistr private final ServiceDataSource serviceDataSource; private final ServiceFinderFactory finderFactory; - private AtomicBoolean alreadyUpdating = new AtomicBoolean(false); + private final AtomicBoolean alreadyUpdating = new AtomicBoolean(false); private Future monitorFuture = null; public ServiceFinderHub( diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java index 057b6489..1b883e3b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/ServiceFinderHubBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -34,9 +34,9 @@ public abstract class ServiceFinderHubBuilder, R extend private ServiceDataSource serviceDataSource; private ServiceFinderFactory serviceFinderFactory; private long refreshFrequencyMs = 10_000; - private List> extraStartSignalConsumers = new ArrayList<>(); - private List> extraStopSignalConsumers = new ArrayList<>(); - private List> extraRefreshSignals = new ArrayList<>(); + private final List> extraStartSignalConsumers = new ArrayList<>(); + private final List> extraStopSignalConsumers = new ArrayList<>(); + private final List> extraRefreshSignals = new ArrayList<>(); public ServiceFinderHubBuilder withServiceDataSource(ServiceDataSource serviceDataSource) { this.serviceDataSource = serviceDataSource; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java index 12f16fb4..11ebe0e6 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/finderhub/StaticDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthChecker.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthChecker.java index 70d6cbb1..3d7dbd3b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthChecker.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthChecker.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.healthcheck; import lombok.extern.slf4j.Slf4j; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java index bd800f2e..100372f0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthcheck.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java index d4828f00..e7b38167 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckResult.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckStatus.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckStatus.java index 22ba575a..4b84fa68 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckStatus.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/HealthcheckStatus.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.healthcheck; public enum HealthcheckStatus { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java index 073cb465..a07cc271 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthcheck/Healthchecks.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/HealthService.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/HealthService.java index 02fa9802..3c79b04b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/HealthService.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/HealthService.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java index 68dee1ff..2468a633 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/ServiceHealthAggregator.java @@ -1,5 +1,5 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/TimeEntity.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/TimeEntity.java index ffdadefb..cde306cd 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/TimeEntity.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/TimeEntity.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.core.healthservice; import com.google.common.base.MoreObjects; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java index 0597d466..d3bf3bf6 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/IsolatedHealthMonitor.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitor.java index c74b31e0..2f2ab700 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitor.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitors.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitors.java index b4578a16..769ae8cd 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitors.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/Monitors.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.core.healthservice.monitor; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/RollingWindowHealthQueue.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/RollingWindowHealthQueue.java index 3fdb0b27..6a0aab1d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/RollingWindowHealthQueue.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/RollingWindowHealthQueue.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java index 1ca3b35d..de3e1551 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/CountMonitor.java @@ -1,28 +1,12 @@ -/** - * Copyright 2016 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. - */ - -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/DiskSpaceMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/DiskSpaceMonitor.java index 59088729..10cca535 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/DiskSpaceMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/DiskSpaceMonitor.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.core.healthservice.monitor.sample; import com.flipkart.ranger.core.healthservice.TimeEntity; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/PingCheckMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/PingCheckMonitor.java index 92fdb7c1..b9385320 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/PingCheckMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/PingCheckMonitor.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.core.healthservice.monitor.sample; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java index 18230130..655eadc0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/healthservice/monitor/sample/RotationStatusMonitor.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java index 3b5d9d4d..a9baf215 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Criteria.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Deserializer.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Deserializer.java index c4acf561..74aebe5e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Deserializer.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Deserializer.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.model; public interface Deserializer { diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java index 2547e346..2b6b8ac8 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSink.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java index 75d3f6bd..79f75a8d 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java index a82aeb5a..1b60442b 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/NodeDataStoreConnector.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Serializer.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Serializer.java index c4e8d401..ab37c6ad 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Serializer.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Serializer.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java index 3847f48c..a9f77786 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/Service.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.model; import lombok.AccessLevel; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNode.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNode.java index a0563f31..383c6a36 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNode.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNode.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,8 +12,8 @@ * 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 com.flipkart.ranger.core.model; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNodeSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNodeSelector.java index d655b7ff..786c03c4 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNodeSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceNodeSelector.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.core.model; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java index fe549220..60bd8041 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ServiceRegistry.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.model; import lombok.AccessLevel; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java index 9d3b0b8e..4053fe07 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/model/ShardSelector.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.model; import java.util.List; diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java index 602f5808..ff6c0597 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/BaseServiceProviderBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java index f388da3e..b2f381f0 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/serviceprovider/ServiceProvider.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java index 56e1436e..350a2005 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ExternalTriggeredSignal.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java index 8b8aeb62..ab6b93dd 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/ScheduledSignal.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java index 2d11fb12..cb03ff6f 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/signals/Signal.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java b/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java index 31e245ce..d93d167e 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/util/Exceptions.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java b/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java index a83278dc..54fa9545 100644 --- a/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java +++ b/ranger-core/src/main/java/com/flipkart/ranger/core/util/FinderUtils.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java index 8b6b2311..cde529a6 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/TestUtils.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java index 9cb5e4fd..404d92fa 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/SimpleShardFinderTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java index 2fe51303..ad35be35 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/UnshardedClusterFinderTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java index 8a6492ce..70563099 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/nodeselector/RoundRobinServiceNodeSelectorTest.java @@ -1,19 +1,19 @@ - -/** +/* * Copyright 2015 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 com.flipkart.ranger.core.finder.nodeselector; + */ +package com.flipkart.ranger.core.finder.nodeselector; import com.flipkart.ranger.core.model.ServiceNode; import com.flipkart.ranger.core.units.TestNodeData; diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java index c4752a2b..effc6f41 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/serviceregistry/MapBasedServiceRegistryTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java index 06c6cd12..1f747c24 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/ListShardSelectorTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java index f35fe273..ce53b3f9 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/finder/shardselector/MatchingShardSelectorTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java index 81e73dc8..50e470a7 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/serviceprovider/ServiceProviderTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java index a0debf37..c38eaa19 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/units/TestNodeData.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java index b5262a45..6231dce6 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/CriteriaUtils.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java index 22dc3568..5ea19537 100644 --- a/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java +++ b/ranger-core/src/test/java/com/flipkart/ranger/core/utils/RegistryTestUtils.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java index 9db4e970..be3fe927 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/ShardedRangerHttpHubClient.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -39,7 +39,7 @@ @Slf4j public class ShardedRangerHttpHubClient> extends AbstractRangerHubClient, HTTPResponseDataDeserializer> { - private List services; + private final List services; private final HttpClientConfig clientConfig; @Builder diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java index ed2464e4..8efb5b2b 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/SimpleRangerHttpClient.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -32,10 +32,9 @@ import java.util.Optional; @Slf4j -public class SimpleRangerHttpClient, D extends HTTPResponseDataDeserializer> implements RangerClient { +public class SimpleRangerHttpClient, D extends HTTPResponseDataDeserializer> implements RangerClient { private final C criteria; - private final D deserializer; private final SimpleUnshardedServiceFinder serviceFinder; @Builder @@ -53,7 +52,6 @@ public SimpleRangerHttpClient( Preconditions.checkNotNull(deserializer, "deserializer can't be null"); this.criteria = criteria; - this.deserializer = deserializer; this.serviceFinder = HttpServiceFinderBuilders.httpUnshardedServiceFinderBuilider() .withClientConfig(clientConfig) diff --git a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java index 1f9f7658..1aa506db 100644 --- a/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java +++ b/ranger-http-client/src/main/java/com/flipkart/ranger/client/http/UnshardedRangerHttpHubClient.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -39,7 +39,7 @@ @Slf4j public class UnshardedRangerHttpHubClient> extends AbstractRangerHubClient, HTTPResponseDataDeserializer> { - private List services; + private final List services; private final HttpClientConfig clientConfig; @Builder diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java index 68a87384..a9cf85f2 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/BaseRangerHttpClientTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client.http; import com.fasterxml.jackson.core.type.TypeReference; diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java index f42d8ec4..93596836 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/ShardedRangerHttpClientTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client.http; import com.flipkart.ranger.core.TestUtils; diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java index 40315cd2..c55b4971 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/SimpleRangerHttpClientTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client.http; import com.flipkart.ranger.core.TestUtils; diff --git a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java index 135dce65..10fd6017 100644 --- a/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java +++ b/ranger-http-client/src/test/java/com/flipkart/ranger/client/http/UnshardedRangerHttpClientTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2015 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 com.flipkart.ranger.client.http; import com.flipkart.ranger.core.TestUtils; diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java index 769030b1..f578937d 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceFinderBuilders.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java index 108b2a7b..605b3b36 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/HttpServiceProviderBuilders.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java index 9f346b33..4cb3bd7e 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/common/HttpNodeDataStoreConnector.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java index 7bda4e5c..bf1f2f4d 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/config/HttpClientConfig.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java index bfd498b9..59964417 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceDataSourceResponse.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java index 30aa47f4..0d713cff 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceNodesResponse.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java index 9c040428..897d760e 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/model/ServiceRegistrationResponse.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java index 4b35e950..df018a0c 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HTTPResponseDataDeserializer.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java index badba832..9a1d5184 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serde/HttpRequestDataSerializer.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java index 7dc6aa44..7ca0bfc0 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpNodeDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java index 377c6b58..bdb3b487 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpShardedServiceFinderBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java index cf385cd9..fbc1ece8 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinder/HttpUnshardedServiceFinderBuilider.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java index 7772dc77..cb0af3f7 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java index 5268c15c..2c100288 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpServiceFinderHubBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java index ee12171a..c5f7c340 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpShardedServiceFinderFactory.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java index 03821433..eeb63c76 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/servicefinderhub/HttpUnshardedServiceFinderFactory.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java index cb534049..92263bf8 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpNodeDataSink.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java index 9ec73abd..64160015 100644 --- a/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java +++ b/ranger-http/src/main/java/com/flipkart/ranger/http/serviceprovider/HttpShardedServiceProviderBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java index e8aad075..770d46f0 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/RangerServerBundle.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java b/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java index 77df0f2a..4ae90747 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/config/RangerConfiguration.java @@ -14,7 +14,21 @@ * limitations under the License. */ package com.flipkart.ranger.server.config; - +/* + * Copyright 2015 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. + */ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.flipkart.ranger.client.Constants; import com.flipkart.ranger.core.model.Service; diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java index 25d35147..5a0911f6 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/manager/RangerClientManager.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -39,8 +39,8 @@ public class RangerClientManager, D extends ZkNodeDataD private final RangerConfiguration rangerConfiguration; - private UnshardedRangerZKHubClient zkHubClient; - private CuratorFramework curatorFramework; + private final UnshardedRangerZKHubClient zkHubClient; + private final CuratorFramework curatorFramework; @Inject public RangerClientManager( diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java b/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java index 29c8b576..5b39c57d 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/model/GenericResponse.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java index 5033cc67..d5934761 100644 --- a/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java +++ b/ranger-server/src/main/java/com/flipkart/ranger/server/resources/RangerResource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java index 116352ea..92a438ab 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/AbstractRangerZKHubClient.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java index a80f3c10..9d01705b 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/ShardedRangerZKHubClient.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java index 13662e18..05088e38 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/SimpleRangerZKClient.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. @@ -37,11 +37,11 @@ @Slf4j @Getter -public class SimpleRangerZKClient, D extends ZkNodeDataDeserializer> implements RangerClient { +public class SimpleRangerZKClient, D extends ZkNodeDataDeserializer> implements RangerClient { - private SimpleShardedServiceFinder serviceFinder; - private C criteria; - private D deserializer; + private final SimpleShardedServiceFinder serviceFinder; + private final C criteria; + private final D deserializer; @Builder(builderMethodName = "fromConnectionString", builderClassName = "FromConnectionStringBuilder") public SimpleRangerZKClient( diff --git a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java index f4c90705..f6996565 100644 --- a/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java +++ b/ranger-zk-client/src/main/java/com/flipkart/ranger/client/zk/UnshardedRangerZKHubClient.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java index e9571310..179068c5 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceFinderBuilders.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.zookeeper; import com.flipkart.ranger.core.model.Criteria; diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java index 4a034f4c..e83abfbd 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/ServiceProviderBuilders.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java index bb7ab01c..79261dee 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/common/ZkNodeDataStoreConnector.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java index a07f2bac..2990943a 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataDeserializer.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java index fcf3f001..3a2db411 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serde/ZkNodeDataSerializer.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java index 6a80a84b..d2258dfc 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkNodeDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java index 87387762..fa055fe0 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleShardedServiceFinderBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java index e17d3923..640ebb68 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/ZkSimpleUnshardedServiceFinderBuilder.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java index 1231d3e1..8b5c5659 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinder/signals/ZkWatcherRegistryUpdateSignal.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java index 08643cbd..8539998b 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZKUnshardedServiceFinderFactory.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java index 3fa71e3a..e13fcaf1 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceDataSource.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java index 52b5da8d..aead107e 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkServiceFinderHubBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java index eda9744e..d36981ff 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/servicefinderhub/ZkShardedServiceFinderFactory.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java index 39a0ef4e..3792e731 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkNodeDataSink.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java index 683ed0fd..1a838324 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/serviceprovider/ZkServiceProviderBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/util/PathBuilder.java b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/util/PathBuilder.java index 02542579..3474c749 100644 --- a/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/util/PathBuilder.java +++ b/ranger-zookeeper/src/main/java/com/flipkart/ranger/zookeeper/util/PathBuilder.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java index 7e73331c..bc217329 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceHealthAggregatorTest.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.zookeeper.healthservice; import com.flipkart.ranger.core.TestUtils; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java index 6bb3edd5..3219233f 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/ServiceProviderIntegrationTest.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/RollingWindowHealthQueueTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/RollingWindowHealthQueueTest.java index 065cc7a3..34b58db5 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/RollingWindowHealthQueueTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/RollingWindowHealthQueueTest.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.zookeeper.healthservice.monitor; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/DiskSpaceMonitorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/DiskSpaceMonitorTest.java index 54ea08d5..be3c5e07 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/DiskSpaceMonitorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/DiskSpaceMonitorTest.java @@ -1,12 +1,12 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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. diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/PingCheckMonitorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/PingCheckMonitorTest.java index 2a4cb14f..d0e0a9cc 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/PingCheckMonitorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/PingCheckMonitorTest.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.zookeeper.healthservice.monitor.sample; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/RotationStatusMonitorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/RotationStatusMonitorTest.java index 22457cbb..63c4264a 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/RotationStatusMonitorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/healthservice/monitor/sample/RotationStatusMonitorTest.java @@ -1,19 +1,18 @@ -/** - * Copyright 2016 Flipkart Internet Pvt. Ltd. - * +/* + * Copyright 2015 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 com.flipkart.ranger.zookeeper.healthservice.monitor.sample; import com.flipkart.ranger.core.healthcheck.HealthcheckStatus; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java index d5d0d94f..d489e6b3 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/CustomShardSelectorTest.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.zookeeper.model; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java index e10ace89..ebee0623 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceNoProviderTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.flipkart.ranger.zookeeper.model; import com.fasterxml.jackson.core.type.TypeReference; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java index e8da9d45..68fbb4f6 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderExtCuratorTest.java @@ -1,19 +1,18 @@ -/** +/* * Copyright 2015 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 com.flipkart.ranger.zookeeper.model; import com.fasterxml.jackson.core.JsonProcessingException; diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java index 2c19abd6..bbeef818 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderHealthcheckTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java index 255c95eb..55041fd0 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/ServiceProviderTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. *

* Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java index 6800ebc1..e875c186 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/model/SimpleServiceProviderTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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. diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java index 631b9785..e563d2e2 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/servicehub/ServiceHubTest.java @@ -1,4 +1,4 @@ -/** +/* * Copyright 2015 Flipkart Internet Pvt. Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java index 9b8f23d3..06bb8f49 100644 --- a/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java +++ b/ranger-zookeeper/src/test/java/com/flipkart/ranger/zookeeper/serviceprovider/BaseServiceProviderBuilderTest.java @@ -1,12 +1,12 @@ -/** +/* * Copyright 2015 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.