From 0bf359dd9f87dd45ef28dd2ea603cb54bd7419c5 Mon Sep 17 00:00:00 2001 From: chaitanyachavali Date: Thu, 17 Aug 2023 20:12:58 +0530 Subject: [PATCH 1/4] merge zk and http server bundles to one and made one hetrogeneous bundle remove the server modules since they are not direct consumables --- pom.xml | 5 +- ranger-http-server-bundle/pom.xml | 47 ------ .../http/server/bundle/HttpServerBundle.java | 72 --------- .../config/RangerHttpConfiguration.java | 42 ----- ranger-http-server/config/local.yml | 38 ----- ranger-http-server/pom.xml | 46 ------ .../io/appform/ranger/http/server/App.java | 44 ----- .../http/server/HttpAppConfiguration.java | 40 ----- ranger-hub-server-bundle/pom.xml | 52 ++++++ .../hub/server/bundle/HubServerBundle.java | 152 ++++++++++++++++++ .../configuration/RangerConfiguration.java | 50 ++++++ .../RangerHttpConfiguration.java | 35 ++-- .../configuration/RangerZkConfiguration.java | 30 ++-- .../bundle/healthcheck/RangerHealthCheck.java | 23 ++- .../bundle/lifecycle/CuratorLifecycle.java | 49 +++--- .../hub/server/bundle/models/BackendType.java | 40 +++++ ranger-zk-server-bundle/pom.xml | 47 ------ .../ranger/server/bundle/ZKServerBundle.java | 93 ----------- .../bundle/config/RangerConfiguration.java | 40 ----- ranger-zk-server/config/local.yml | 36 ----- ranger-zk-server/pom.xml | 46 ------ .../java/io/appform/ranger/zk/server/App.java | 46 ------ 22 files changed, 362 insertions(+), 711 deletions(-) delete mode 100644 ranger-http-server-bundle/pom.xml delete mode 100644 ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/HttpServerBundle.java delete mode 100644 ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/config/RangerHttpConfiguration.java delete mode 100644 ranger-http-server/config/local.yml delete mode 100644 ranger-http-server/pom.xml delete mode 100644 ranger-http-server/src/main/java/io/appform/ranger/http/server/App.java delete mode 100644 ranger-http-server/src/main/java/io/appform/ranger/http/server/HttpAppConfiguration.java create mode 100644 ranger-hub-server-bundle/pom.xml create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java rename ranger-zk-server/src/main/java/io/appform/ranger/zk/server/AppConfiguration.java => ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java (55%) rename ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/healthcheck/RangerHttpHealthCheck.java => ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java (55%) rename {ranger-zk-server-bundle/src/main/java/io/appform/ranger => ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub}/server/bundle/healthcheck/RangerHealthCheck.java (65%) rename {ranger-zk-server-bundle/src/main/java/io/appform/ranger => ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub}/server/bundle/lifecycle/CuratorLifecycle.java (56%) create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/models/BackendType.java delete mode 100644 ranger-zk-server-bundle/pom.xml delete mode 100644 ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/ZKServerBundle.java delete mode 100644 ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/config/RangerConfiguration.java delete mode 100644 ranger-zk-server/config/local.yml delete mode 100644 ranger-zk-server/pom.xml delete mode 100644 ranger-zk-server/src/main/java/io/appform/ranger/zk/server/App.java diff --git a/pom.xml b/pom.xml index 0600aa8b..5d49531d 100644 --- a/pom.xml +++ b/pom.xml @@ -22,11 +22,8 @@ ranger-http-client ranger-server-common ranger-server-bundle - ranger-zk-server - ranger-http-server ranger-http-model - ranger-http-server-bundle - ranger-zk-server-bundle + ranger-hub-server-bundle diff --git a/ranger-http-server-bundle/pom.xml b/ranger-http-server-bundle/pom.xml deleted file mode 100644 index 5a736364..00000000 --- a/ranger-http-server-bundle/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - ranger - io.appform.ranger - 1.0-RC12 - - 4.0.0 - - ranger-http-server-bundle - - - 2.0.23 - - - - - io.appform.ranger - ranger-http-client - ${project.version} - - - io.appform.ranger - ranger-server-bundle - ${project.version} - - - io.appform.ranger - ranger-server-common - ${project.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - io.dropwizard - dropwizard-core - ${dropwizard.version} - provided - - - - \ No newline at end of file diff --git a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/HttpServerBundle.java b/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/HttpServerBundle.java deleted file mode 100644 index 159ad237..00000000 --- a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/HttpServerBundle.java +++ /dev/null @@ -1,72 +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 io.appform.ranger.http.server.bundle; - -import com.codahale.metrics.health.HealthCheck; -import com.fasterxml.jackson.core.type.TypeReference; -import com.google.common.collect.ImmutableList; -import io.appform.ranger.client.RangerHubClient; -import io.appform.ranger.client.http.ShardedRangerHttpHubClient; -import io.appform.ranger.client.http.UnshardedRangerHttpHubClient; -import io.appform.ranger.common.server.ShardInfo; -import io.appform.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import io.appform.ranger.core.finder.serviceregistry.MapBasedServiceRegistry; -import io.appform.ranger.http.model.ServiceNodesResponse; -import io.appform.ranger.http.server.bundle.config.RangerHttpConfiguration; -import io.appform.ranger.http.server.bundle.healthcheck.RangerHttpHealthCheck; -import io.appform.ranger.server.bundle.RangerServerBundle; -import io.dropwizard.Configuration; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import lombok.val; - -import javax.inject.Singleton; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; - -@Slf4j -@Singleton -@NoArgsConstructor -@SuppressWarnings("unused") -public abstract class HttpServerBundle extends RangerServerBundle, U> { - - protected abstract RangerHttpConfiguration getRangerConfiguration(U configuration); - - @Override - protected List>> withHubs(U configuration) { - val rangerConfiguration = getRangerConfiguration(configuration); - return rangerConfiguration.getHttpClientConfigs().stream().map(clientConfig -> UnshardedRangerHttpHubClient.builder() - .namespace(rangerConfiguration.getNamespace()) - .mapper(getMapper()) - .clientConfig(clientConfig) - .nodeRefreshTimeMs(rangerConfiguration.getNodeRefreshTimeMs()) - .deserializer(data -> { - try { - return getMapper().readValue(data, new TypeReference>() { - }); - } catch (IOException e) { - log.warn("Error parsing node data with value {}", new String(data)); - } - return null; - }) - .build()).collect(Collectors.toList()); - } - - protected List withHealthChecks(U configuration) { - return ImmutableList.of(new RangerHttpHealthCheck()); - } -} diff --git a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/config/RangerHttpConfiguration.java b/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/config/RangerHttpConfiguration.java deleted file mode 100644 index 7d23a892..00000000 --- a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/config/RangerHttpConfiguration.java +++ /dev/null @@ -1,42 +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 io.appform.ranger.http.server.bundle.config; - -import io.appform.ranger.client.RangerClientConstants; -import io.appform.ranger.http.config.HttpClientConfig; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.util.List; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class RangerHttpConfiguration { - - @NotEmpty - @NotNull - String namespace; - @NotEmpty - @NotNull - List httpClientConfigs; - @Min(RangerClientConstants.MINIMUM_REFRESH_TIME) - int nodeRefreshTimeMs = RangerClientConstants.MINIMUM_REFRESH_TIME; -} diff --git a/ranger-http-server/config/local.yml b/ranger-http-server/config/local.yml deleted file mode 100644 index 67d450c5..00000000 --- a/ranger-http-server/config/local.yml +++ /dev/null @@ -1,38 +0,0 @@ - -name: ranger-http-server -initialRotationStatus: false - -rangerConfiguration: - namespace: test - httpClientConfigs: - - host: localhost - port: 7080 - -server: - maxThreads: 128 - minThreads: 128 - applicationConnectors: - - type: http - port: 6080 - adminConnectors: - - type: http - port: 6081 - applicationContextPath: / - requestLog: - appenders: - - type: console - timeZone: IST - -logging: - level: INFO - - loggers: - io.appform.ranger.http.server: DEBUG - - appenders: - - type: console - threshold: INFO - timeZone: IST - logFormat: "%(%-5level) [%date] [%thread] [%logger{0}]: %message%n" - - diff --git a/ranger-http-server/pom.xml b/ranger-http-server/pom.xml deleted file mode 100644 index 7d2c576f..00000000 --- a/ranger-http-server/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - ranger - io.appform.ranger - 1.0-RC12 - - 4.0.0 - - ranger-http-server - - - 2.0.23 - - - - - io.appform.ranger - ranger-http-server-bundle - ${project.version} - - - io.dropwizard - dropwizard-core - ${dropwizard.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - - \ No newline at end of file diff --git a/ranger-http-server/src/main/java/io/appform/ranger/http/server/App.java b/ranger-http-server/src/main/java/io/appform/ranger/http/server/App.java deleted file mode 100644 index 75698075..00000000 --- a/ranger-http-server/src/main/java/io/appform/ranger/http/server/App.java +++ /dev/null @@ -1,44 +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 io.appform.ranger.http.server; - -import io.appform.ranger.http.server.bundle.HttpServerBundle; -import io.appform.ranger.http.server.bundle.config.RangerHttpConfiguration; -import io.dropwizard.Application; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; - -public class App extends Application { - - public static void main(String[] args) throws Exception { - new App().run(args); - } - - @Override - public void initialize(Bootstrap bootstrap) { - bootstrap.addBundle(new HttpServerBundle() { - @Override - protected RangerHttpConfiguration getRangerConfiguration(HttpAppConfiguration configuration) { - return configuration.getRangerConfiguration(); - } - }); - } - - @Override - public void run(HttpAppConfiguration appConfiguration, Environment environment) { - //Nothing to do in run! - } -} diff --git a/ranger-http-server/src/main/java/io/appform/ranger/http/server/HttpAppConfiguration.java b/ranger-http-server/src/main/java/io/appform/ranger/http/server/HttpAppConfiguration.java deleted file mode 100644 index 259a915c..00000000 --- a/ranger-http-server/src/main/java/io/appform/ranger/http/server/HttpAppConfiguration.java +++ /dev/null @@ -1,40 +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 io.appform.ranger.http.server; - -import io.appform.ranger.http.server.bundle.config.RangerHttpConfiguration; -import io.dropwizard.Configuration; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; - -import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class HttpAppConfiguration extends Configuration { - @NotEmpty - @NotNull - String name; - @Valid - @NotNull - RangerHttpConfiguration rangerConfiguration; -} diff --git a/ranger-hub-server-bundle/pom.xml b/ranger-hub-server-bundle/pom.xml new file mode 100644 index 00000000..17d5cbf1 --- /dev/null +++ b/ranger-hub-server-bundle/pom.xml @@ -0,0 +1,52 @@ + + + + ranger + io.appform.ranger + 1.0-RC12 + + 4.0.0 + + ranger-hub-server-bundle + + + 2.0.23 + + + + + io.appform.ranger + ranger-http-client + ${project.version} + + + io.appform.ranger + ranger-zk-client + ${project.version} + + + io.appform.ranger + ranger-server-bundle + ${project.version} + + + io.appform.ranger + ranger-server-common + ${project.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + io.dropwizard + dropwizard-core + ${dropwizard.version} + provided + + + + \ No newline at end of file diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java new file mode 100644 index 00000000..4b2a050c --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java @@ -0,0 +1,152 @@ +/* + * 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 io.appform.ranger.hub.server.bundle; + +import com.codahale.metrics.health.HealthCheck; +import com.fasterxml.jackson.core.type.TypeReference; +import io.appform.ranger.client.RangerClientConstants; +import io.appform.ranger.client.RangerHubClient; +import io.appform.ranger.client.http.UnshardedRangerHttpHubClient; +import io.appform.ranger.client.zk.UnshardedRangerZKHubClient; +import io.appform.ranger.common.server.ShardInfo; +import io.appform.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import io.appform.ranger.core.model.ServiceNode; +import io.appform.ranger.core.signals.Signal; +import io.appform.ranger.http.config.HttpClientConfig; +import io.appform.ranger.http.model.ServiceNodesResponse; +import io.appform.ranger.hub.server.bundle.configuration.RangerConfiguration; +import io.appform.ranger.hub.server.bundle.configuration.RangerHttpConfiguration; +import io.appform.ranger.hub.server.bundle.configuration.RangerZkConfiguration; +import io.appform.ranger.hub.server.bundle.healthcheck.RangerHealthCheck; +import io.appform.ranger.hub.server.bundle.lifecycle.CuratorLifecycle; +import io.appform.ranger.hub.server.bundle.models.BackendType.BackendTypeVisitor; +import io.appform.ranger.server.bundle.RangerServerBundle; +import io.dropwizard.Configuration; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import lombok.NoArgsConstructor; +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.RetryForever; + +@Slf4j +@SuppressWarnings("unused") +@NoArgsConstructor +public abstract class HubServerBundle extends + RangerServerBundle, U> { + + protected abstract List getRangerConfiguration(U configuration); + + private final List curatorFrameworks = new ArrayList<>(); + + @Override + protected List>> withHubs( + U configuration) { + return getRangerConfiguration(configuration).stream() + .map(rangerConfiguration -> rangerConfiguration.getType().accept(new HubCreatorVisitor(), rangerConfiguration)) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + @Override + protected List> withLifecycleSignals(U configuration) { + return curatorFrameworks.stream() + .map(curatorFramework -> (Signal) new CuratorLifecycle(curatorFramework)) + .collect(Collectors.toList()); + } + + @Override + protected List withHealthChecks(U configuration) { + return curatorFrameworks.stream() + .map(curatorFramework -> (HealthCheck) new RangerHealthCheck(curatorFramework)) + .collect(Collectors.toList()); + } + + private class HubCreatorVisitor implements + BackendTypeVisitor>>, RangerConfiguration> { + + @Override + public List>> visitZK( + RangerConfiguration configuration) { + val zkConfiguration = (RangerZkConfiguration) configuration; + return zkConfiguration.getZookeepers().stream() + .map(zk -> addCuratorAndGetZkHubClient(zk, zkConfiguration)) + .collect(Collectors.toList()); + } + + @Override + public List>> visitHTTP( + RangerConfiguration configuration) { + val httpConfiguration = (RangerHttpConfiguration) configuration; + return httpConfiguration.getHttpClientConfigs().stream() + .map(http -> getHttpHubClient(http, httpConfiguration)) + .collect(Collectors.toList()); + } + + private RangerHubClient> addCuratorAndGetZkHubClient( + String zookeeper, RangerZkConfiguration zkConfiguration) { + val curatorFramework = CuratorFrameworkFactory.builder() + .connectString(zookeeper) + .namespace(zkConfiguration.getNamespace()) + .retryPolicy(new RetryForever(RangerClientConstants.CONNECTION_RETRY_TIME)) + .build(); + curatorFrameworks.add(curatorFramework); + return UnshardedRangerZKHubClient.builder() + .namespace(zkConfiguration.getNamespace()) + .connectionString(zookeeper) + .curatorFramework(curatorFramework) + .disablePushUpdaters(zkConfiguration.isDisablePushUpdaters()) + .mapper(getMapper()) + .nodeRefreshTimeMs(zkConfiguration.getNodeRefreshTimeMs()) + .deserializer(data -> { + try { + return getMapper().readValue(data, new TypeReference>() { + }); + } catch (IOException e) { + log.warn("Error parsing node data with value {}", new String(data)); + } + return null; + }) + .build(); + } + + private RangerHubClient> getHttpHubClient( + HttpClientConfig httpClientConfig, RangerHttpConfiguration httpConfiguration) { + return UnshardedRangerHttpHubClient.builder() + .namespace(httpConfiguration.getNamespace()) + .mapper(getMapper()) + .clientConfig(httpClientConfig) + .nodeRefreshTimeMs(httpConfiguration.getNodeRefreshTimeMs()) + .deserializer(data -> { + try { + return getMapper().readValue(data, + new TypeReference>() { + }); + } catch (IOException e) { + log.warn("Error parsing node data with value {}", new String(data)); + } + return null; + }) + .build(); + } + } + +} diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java new file mode 100644 index 00000000..bedc3fbc --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java @@ -0,0 +1,50 @@ +/* + * 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 io.appform.ranger.hub.server.bundle.configuration; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import io.appform.ranger.client.RangerClientConstants; +import io.appform.ranger.hub.server.bundle.models.BackendType; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true) +@JsonSubTypes({ + @JsonSubTypes.Type(value = RangerHttpConfiguration.class, name = "HTTP"), + @JsonSubTypes.Type(value = RangerZkConfiguration.class, name = "ZK") +}) +@Getter +public abstract class RangerConfiguration { + + @NotNull + private BackendType type; + + @NotEmpty + private String namespace; + + @Min(RangerClientConstants.MINIMUM_REFRESH_TIME) + private int nodeRefreshTimeMs = RangerClientConstants.MINIMUM_REFRESH_TIME; + + protected RangerConfiguration(BackendType type) { + this.type = type; + } + +} diff --git a/ranger-zk-server/src/main/java/io/appform/ranger/zk/server/AppConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java similarity index 55% rename from ranger-zk-server/src/main/java/io/appform/ranger/zk/server/AppConfiguration.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java index e9583ad5..cd189291 100644 --- a/ranger-zk-server/src/main/java/io/appform/ranger/zk/server/AppConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java @@ -13,28 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.appform.ranger.zk.server; - -import io.appform.ranger.server.bundle.config.RangerConfiguration; -import io.dropwizard.Configuration; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NoArgsConstructor; +package io.appform.ranger.hub.server.bundle.configuration; +import io.appform.ranger.http.config.HttpClientConfig; +import io.appform.ranger.hub.server.bundle.models.BackendType; +import java.util.List; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import lombok.Getter; + +@Getter +public class RangerHttpConfiguration extends RangerConfiguration { + + @NotEmpty + @Valid + private List httpClientConfigs; -@Data -@AllArgsConstructor -@NoArgsConstructor -@EqualsAndHashCode(callSuper = true) -public class AppConfiguration extends Configuration { - @NotEmpty - @NotNull - String name; - @Valid - @NotNull - RangerConfiguration rangerConfiguration; + public RangerHttpConfiguration() { + super(BackendType.HTTP); + } } diff --git a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/healthcheck/RangerHttpHealthCheck.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java similarity index 55% rename from ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/healthcheck/RangerHttpHealthCheck.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java index af0508d7..37ae4100 100644 --- a/ranger-http-server-bundle/src/main/java/io/appform/ranger/http/server/bundle/healthcheck/RangerHttpHealthCheck.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java @@ -13,20 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.appform.ranger.http.server.bundle.healthcheck; +package io.appform.ranger.hub.server.bundle.configuration; -import com.codahale.metrics.health.HealthCheck; -import lombok.Data; -import lombok.EqualsAndHashCode; +import io.appform.ranger.hub.server.bundle.models.BackendType; +import java.util.List; +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import lombok.Getter; -import javax.inject.Singleton; +@Getter +public class RangerZkConfiguration extends RangerConfiguration { -@EqualsAndHashCode(callSuper = true) -@Singleton -@Data -public class RangerHttpHealthCheck extends HealthCheck { - @Override - protected Result check() { - return HealthCheck.Result.healthy("Healthy"); - } + @NotEmpty + @Valid + private List zookeepers; + + private boolean disablePushUpdaters; + + protected RangerZkConfiguration() { + super(BackendType.ZK); + } } diff --git a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/healthcheck/RangerHealthCheck.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java similarity index 65% rename from ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/healthcheck/RangerHealthCheck.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java index 71f5daec..38b0c08d 100644 --- a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/healthcheck/RangerHealthCheck.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/healthcheck/RangerHealthCheck.java @@ -13,27 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.appform.ranger.server.bundle.healthcheck; +package io.appform.ranger.hub.server.bundle.healthcheck; import com.codahale.metrics.health.HealthCheck; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; -import javax.inject.Singleton; - @Singleton @Slf4j public class RangerHealthCheck extends HealthCheck { - private final CuratorFramework curatorFramework; + private final CuratorFramework curatorFramework; - public RangerHealthCheck(CuratorFramework curatorFramework){ - this.curatorFramework = curatorFramework; - } + public RangerHealthCheck(CuratorFramework curatorFramework){ + this.curatorFramework = curatorFramework; + } - @Override - protected Result check() { - return curatorFramework.getZookeeperClient().isConnected() ? - Result.healthy("Service is healthy") : Result.unhealthy("Can't connect to zookeeper"); - } + @Override + protected Result check() { + return curatorFramework.getZookeeperClient().isConnected() ? + Result.healthy("Service is healthy") : Result.unhealthy("Can't connect to zookeeper"); + } } diff --git a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/lifecycle/CuratorLifecycle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/lifecycle/CuratorLifecycle.java similarity index 56% rename from ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/lifecycle/CuratorLifecycle.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/lifecycle/CuratorLifecycle.java index aef364ad..f81b1c9f 100644 --- a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/lifecycle/CuratorLifecycle.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/lifecycle/CuratorLifecycle.java @@ -13,44 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.appform.ranger.server.bundle.lifecycle; +package io.appform.ranger.hub.server.bundle.lifecycle; import io.appform.ranger.common.server.ShardInfo; import io.appform.ranger.core.signals.Signal; +import java.util.Collections; +import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import org.apache.curator.framework.CuratorFramework; -import javax.inject.Singleton; -import java.util.Collections; - @Slf4j @Singleton public class CuratorLifecycle extends Signal { - private final CuratorFramework curatorFramework; + private final CuratorFramework curatorFramework; - public CuratorLifecycle(CuratorFramework curatorFramework) { - super(() -> null, Collections.emptyList()); - this.curatorFramework = curatorFramework; - } + public CuratorLifecycle(CuratorFramework curatorFramework) { + super(() -> null, Collections.emptyList()); + this.curatorFramework = curatorFramework; + } - @Override - public void start() { - log.info("Starting the curator"); + @Override + public void start() { + log.info("Starting the curator"); - curatorFramework.start(); - try { - curatorFramework.blockUntilConnected(); - } - catch (InterruptedException e) { - log.error("Curator block interrupted", e); - Thread.currentThread().interrupt(); - } - log.info("Started the curator"); + curatorFramework.start(); + try { + curatorFramework.blockUntilConnected(); } - - @Override - public void stop() { - curatorFramework.close(); + catch (InterruptedException e) { + log.error("Curator block interrupted", e); + Thread.currentThread().interrupt(); } + log.info("Started the curator"); + } + + @Override + public void stop() { + curatorFramework.close(); + } } diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/models/BackendType.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/models/BackendType.java new file mode 100644 index 00000000..decab595 --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/models/BackendType.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 io.appform.ranger.hub.server.bundle.models; + +public enum BackendType { + ZK() { + @Override + public U accept(BackendTypeVisitor visitor, R input) { + return visitor.visitZK(input); + } + }, + HTTP() { + @Override + public U accept(BackendTypeVisitor visitor, R input) { + return visitor.visitHTTP(input); + } + }; + + public abstract U accept(BackendTypeVisitor visitor, R input); + + public interface BackendTypeVisitor { + + U visitZK(R input); + + U visitHTTP(R input); + } +} diff --git a/ranger-zk-server-bundle/pom.xml b/ranger-zk-server-bundle/pom.xml deleted file mode 100644 index 9c41dfbd..00000000 --- a/ranger-zk-server-bundle/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - ranger - io.appform.ranger - 1.0-RC12 - - 4.0.0 - - ranger-zk-server-bundle - - - 2.0.23 - - - - - io.appform.ranger - ranger-zk-client - ${project.version} - - - io.appform.ranger - ranger-server-bundle - ${project.version} - - - io.appform.ranger - ranger-server-common - ${project.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - io.dropwizard - dropwizard-core - ${dropwizard.version} - provided - - - - \ No newline at end of file diff --git a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/ZKServerBundle.java b/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/ZKServerBundle.java deleted file mode 100644 index d3d02eb2..00000000 --- a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/ZKServerBundle.java +++ /dev/null @@ -1,93 +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 io.appform.ranger.server.bundle; - -import com.codahale.metrics.health.HealthCheck; -import com.fasterxml.jackson.core.type.TypeReference; -import com.google.common.collect.ImmutableList; -import io.appform.ranger.client.RangerClientConstants; -import io.appform.ranger.client.RangerHubClient; -import io.appform.ranger.client.zk.UnshardedRangerZKHubClient; -import io.appform.ranger.common.server.ShardInfo; -import io.appform.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import io.appform.ranger.core.model.ServiceNode; -import io.appform.ranger.core.signals.Signal; -import io.appform.ranger.server.bundle.config.RangerConfiguration; -import io.appform.ranger.server.bundle.healthcheck.RangerHealthCheck; -import io.appform.ranger.server.bundle.lifecycle.CuratorLifecycle; -import io.dropwizard.Configuration; -import lombok.NoArgsConstructor; -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.RetryForever; - -import javax.inject.Singleton; -import java.io.IOException; -import java.util.List; - -@Slf4j -@Singleton -@NoArgsConstructor -public abstract class ZKServerBundle extends RangerServerBundle, U> { - - private CuratorFramework curatorFramework; - - protected abstract RangerConfiguration getRangerConfiguration(U configuration); - - @Override - protected void preBundle(U configuration) { - val rangerConfiguration = getRangerConfiguration(configuration); - curatorFramework = CuratorFrameworkFactory.builder() - .connectString(rangerConfiguration.getZookeeper()) - .namespace(rangerConfiguration.getNamespace()) - .retryPolicy(new RetryForever(RangerClientConstants.CONNECTION_RETRY_TIME)) - .build(); - } - - @Override - protected List>> withHubs(U configuration) { - val rangerConfiguration = getRangerConfiguration(configuration); - return ImmutableList.of(UnshardedRangerZKHubClient.builder() - .namespace(rangerConfiguration.getNamespace()) - .connectionString(rangerConfiguration.getZookeeper()) - .curatorFramework(curatorFramework) - .disablePushUpdaters(rangerConfiguration.isDisablePushUpdaters()) - .mapper(getMapper()) - .nodeRefreshTimeMs(rangerConfiguration.getNodeRefreshTimeMs()) - .deserializer(data -> { - try { - return getMapper().readValue(data, new TypeReference>() { - }); - } catch (IOException e) { - log.warn("Error parsing node data with value {}", new String(data)); - } - return null; - }) - .build()); - } - - protected List> withLifecycleSignals(U configuration) { - return ImmutableList.of( - new CuratorLifecycle(curatorFramework) - ); - } - - protected List withHealthChecks(U configuration) { - return ImmutableList.of(new RangerHealthCheck(curatorFramework)); - } -} diff --git a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/config/RangerConfiguration.java b/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/config/RangerConfiguration.java deleted file mode 100644 index 01a61fe2..00000000 --- a/ranger-zk-server-bundle/src/main/java/io/appform/ranger/server/bundle/config/RangerConfiguration.java +++ /dev/null @@ -1,40 +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 io.appform.ranger.server.bundle.config; - -import io.appform.ranger.client.RangerClientConstants; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class RangerConfiguration { - @NotEmpty - @NotNull - String namespace; - @NotEmpty - @NotNull - String zookeeper; - boolean disablePushUpdaters; - @Min(1000) - int nodeRefreshTimeMs = RangerClientConstants.MINIMUM_REFRESH_TIME; -} diff --git a/ranger-zk-server/config/local.yml b/ranger-zk-server/config/local.yml deleted file mode 100644 index ee2f0adc..00000000 --- a/ranger-zk-server/config/local.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: ranger-server -initialRotationStatus: false - -rangerConfiguration: - namespace: test - zookeeper: localhost:2181 - disablePushUpdaters: true - -server: - maxThreads: 128 - minThreads: 128 - applicationConnectors: - - type: http - port: 7080 - adminConnectors: - - type: http - port: 7081 - applicationContextPath: / - requestLog: - appenders: - - type: console - timeZone: IST - -logging: - level: INFO - - loggers: - io.appform.ranger.server: DEBUG - - appenders: - - type: console - threshold: INFO - timeZone: IST - logFormat: "%(%-5level) [%date] [%thread] [%logger{0}]: %message%n" - - diff --git a/ranger-zk-server/pom.xml b/ranger-zk-server/pom.xml deleted file mode 100644 index a3907e48..00000000 --- a/ranger-zk-server/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - ranger - io.appform.ranger - 1.0-RC12 - - 4.0.0 - - ranger-zk-server - - - 2.0.23 - - - - - io.appform.ranger - ranger-zk-server-bundle - ${project.version} - - - io.dropwizard - dropwizard-core - ${dropwizard.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - - \ No newline at end of file diff --git a/ranger-zk-server/src/main/java/io/appform/ranger/zk/server/App.java b/ranger-zk-server/src/main/java/io/appform/ranger/zk/server/App.java deleted file mode 100644 index 4c8b0b6e..00000000 --- a/ranger-zk-server/src/main/java/io/appform/ranger/zk/server/App.java +++ /dev/null @@ -1,46 +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 io.appform.ranger.zk.server; - -import io.appform.ranger.server.bundle.ZKServerBundle; -import io.appform.ranger.server.bundle.config.RangerConfiguration; -import io.dropwizard.Application; -import io.dropwizard.setup.Bootstrap; -import io.dropwizard.setup.Environment; - -public class App extends Application { - - public static void main(String[] args) throws Exception { - new App().run(args); - } - - @Override - public void initialize(Bootstrap bootstrap) { - bootstrap.addBundle(new ZKServerBundle() { - @Override - protected RangerConfiguration getRangerConfiguration(AppConfiguration configuration) { - return configuration.getRangerConfiguration(); - } - }); - } - - @Override - public void run(AppConfiguration appConfiguration, Environment environment) { - /* - Nothing to do here. - */ - } -} From b6573ba843cabe9a4ba83df504dc721a5807e5c8 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Tue, 28 May 2024 12:54:55 +0530 Subject: [PATCH 2/4] Working server with deduplication --- pom.xml | 1 + ...e.id.IdGeneratorPerfTest.testGenerate.json | 2 +- ...dGeneratorPerfTest.testGenerateBase36.json | 2 +- .../bundle/ServiceDiscoveryBundle.java | 2 +- ranger-hub-server-bundle/pom.xml | 19 ++- .../hub/server/bundle/HubServerBundle.java | 152 ----------------- .../server/bundle/RangerHubServerBundle.java | 155 ++++++++++++++++++ .../RangerConfigurationVisitor.java | 10 ++ ...a => RangerHttpUpstreamConfiguration.java} | 17 +- .../RangerServerConfiguration.java | 26 +++ ....java => RangerUpstreamConfiguration.java} | 18 +- ...ava => RangerZkUpstreamConfiguration.java} | 17 +- .../server/bundle/RangerServerBundle.java | 3 +- .../bundle/resources/RangerResource.java | 29 ++-- ranger-server/pom.xml | 64 ++++++++ .../java/io/appform/ranger/server/App.java | 46 ++++++ .../io/appform/ranger/server/AppConfig.java | 22 +++ 17 files changed, 394 insertions(+), 191 deletions(-) delete mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java rename ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/{RangerHttpConfiguration.java => RangerHttpUpstreamConfiguration.java} (73%) create mode 100644 ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java rename ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/{RangerConfiguration.java => RangerUpstreamConfiguration.java} (79%) rename ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/{RangerZkConfiguration.java => RangerZkUpstreamConfiguration.java} (73%) create mode 100644 ranger-server/pom.xml create mode 100644 ranger-server/src/main/java/io/appform/ranger/server/App.java create mode 100644 ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java diff --git a/pom.xml b/pom.xml index 7e77da9a..6b8ebe66 100644 --- a/pom.xml +++ b/pom.xml @@ -24,6 +24,7 @@ ranger-server-bundle ranger-http-model ranger-hub-server-bundle + ranger-server diff --git a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json index 821a9eb4..0889793b 100644 --- a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json +++ b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerate.json @@ -4,5 +4,5 @@ "iterations" : 4, "threads" : 1, "forks" : 3, - "mean_ops" : 773920.400092714 + "mean_ops" : 763105.9286163104 } \ No newline at end of file diff --git a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json index 3e347303..9093e40c 100644 --- a/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json +++ b/ranger-discovery-bundle/perf/results/io.appform.ranger.discovery.bundle.id.IdGeneratorPerfTest.testGenerateBase36.json @@ -4,5 +4,5 @@ "iterations" : 4, "threads" : 1, "forks" : 3, - "mean_ops" : 600324.2457100645 + "mean_ops" : 608727.2211847006 } \ No newline at end of file diff --git a/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/ServiceDiscoveryBundle.java b/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/ServiceDiscoveryBundle.java index c9397312..9d67ec8e 100644 --- a/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/ServiceDiscoveryBundle.java +++ b/ranger-discovery-bundle/src/main/java/io/appform/ranger/discovery/bundle/ServiceDiscoveryBundle.java @@ -246,7 +246,7 @@ private RangerClient> buildDiscove .readValue(data, new TypeReference>() { }); } catch (IOException e) { - log.warn("Error parsing node data with value {}", new String(data)); + log.warn("Error parsing node data with value {} for service: {}", new String(data), serviceName); } return null; }) diff --git a/ranger-hub-server-bundle/pom.xml b/ranger-hub-server-bundle/pom.xml index 17d5cbf1..ef2f6904 100644 --- a/ranger-hub-server-bundle/pom.xml +++ b/ranger-hub-server-bundle/pom.xml @@ -5,8 +5,20 @@ ranger io.appform.ranger - 1.0-RC12 + 1.0-RC17 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + + + 4.0.0 ranger-hub-server-bundle @@ -36,11 +48,6 @@ ranger-server-common ${project.version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - io.dropwizard dropwizard-core diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java deleted file mode 100644 index 4b2a050c..00000000 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/HubServerBundle.java +++ /dev/null @@ -1,152 +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 io.appform.ranger.hub.server.bundle; - -import com.codahale.metrics.health.HealthCheck; -import com.fasterxml.jackson.core.type.TypeReference; -import io.appform.ranger.client.RangerClientConstants; -import io.appform.ranger.client.RangerHubClient; -import io.appform.ranger.client.http.UnshardedRangerHttpHubClient; -import io.appform.ranger.client.zk.UnshardedRangerZKHubClient; -import io.appform.ranger.common.server.ShardInfo; -import io.appform.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; -import io.appform.ranger.core.model.ServiceNode; -import io.appform.ranger.core.signals.Signal; -import io.appform.ranger.http.config.HttpClientConfig; -import io.appform.ranger.http.model.ServiceNodesResponse; -import io.appform.ranger.hub.server.bundle.configuration.RangerConfiguration; -import io.appform.ranger.hub.server.bundle.configuration.RangerHttpConfiguration; -import io.appform.ranger.hub.server.bundle.configuration.RangerZkConfiguration; -import io.appform.ranger.hub.server.bundle.healthcheck.RangerHealthCheck; -import io.appform.ranger.hub.server.bundle.lifecycle.CuratorLifecycle; -import io.appform.ranger.hub.server.bundle.models.BackendType.BackendTypeVisitor; -import io.appform.ranger.server.bundle.RangerServerBundle; -import io.dropwizard.Configuration; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import lombok.NoArgsConstructor; -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.RetryForever; - -@Slf4j -@SuppressWarnings("unused") -@NoArgsConstructor -public abstract class HubServerBundle extends - RangerServerBundle, U> { - - protected abstract List getRangerConfiguration(U configuration); - - private final List curatorFrameworks = new ArrayList<>(); - - @Override - protected List>> withHubs( - U configuration) { - return getRangerConfiguration(configuration).stream() - .map(rangerConfiguration -> rangerConfiguration.getType().accept(new HubCreatorVisitor(), rangerConfiguration)) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } - - @Override - protected List> withLifecycleSignals(U configuration) { - return curatorFrameworks.stream() - .map(curatorFramework -> (Signal) new CuratorLifecycle(curatorFramework)) - .collect(Collectors.toList()); - } - - @Override - protected List withHealthChecks(U configuration) { - return curatorFrameworks.stream() - .map(curatorFramework -> (HealthCheck) new RangerHealthCheck(curatorFramework)) - .collect(Collectors.toList()); - } - - private class HubCreatorVisitor implements - BackendTypeVisitor>>, RangerConfiguration> { - - @Override - public List>> visitZK( - RangerConfiguration configuration) { - val zkConfiguration = (RangerZkConfiguration) configuration; - return zkConfiguration.getZookeepers().stream() - .map(zk -> addCuratorAndGetZkHubClient(zk, zkConfiguration)) - .collect(Collectors.toList()); - } - - @Override - public List>> visitHTTP( - RangerConfiguration configuration) { - val httpConfiguration = (RangerHttpConfiguration) configuration; - return httpConfiguration.getHttpClientConfigs().stream() - .map(http -> getHttpHubClient(http, httpConfiguration)) - .collect(Collectors.toList()); - } - - private RangerHubClient> addCuratorAndGetZkHubClient( - String zookeeper, RangerZkConfiguration zkConfiguration) { - val curatorFramework = CuratorFrameworkFactory.builder() - .connectString(zookeeper) - .namespace(zkConfiguration.getNamespace()) - .retryPolicy(new RetryForever(RangerClientConstants.CONNECTION_RETRY_TIME)) - .build(); - curatorFrameworks.add(curatorFramework); - return UnshardedRangerZKHubClient.builder() - .namespace(zkConfiguration.getNamespace()) - .connectionString(zookeeper) - .curatorFramework(curatorFramework) - .disablePushUpdaters(zkConfiguration.isDisablePushUpdaters()) - .mapper(getMapper()) - .nodeRefreshTimeMs(zkConfiguration.getNodeRefreshTimeMs()) - .deserializer(data -> { - try { - return getMapper().readValue(data, new TypeReference>() { - }); - } catch (IOException e) { - log.warn("Error parsing node data with value {}", new String(data)); - } - return null; - }) - .build(); - } - - private RangerHubClient> getHttpHubClient( - HttpClientConfig httpClientConfig, RangerHttpConfiguration httpConfiguration) { - return UnshardedRangerHttpHubClient.builder() - .namespace(httpConfiguration.getNamespace()) - .mapper(getMapper()) - .clientConfig(httpClientConfig) - .nodeRefreshTimeMs(httpConfiguration.getNodeRefreshTimeMs()) - .deserializer(data -> { - try { - return getMapper().readValue(data, - new TypeReference>() { - }); - } catch (IOException e) { - log.warn("Error parsing node data with value {}", new String(data)); - } - return null; - }) - .build(); - } - } - -} diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java new file mode 100644 index 00000000..00141e19 --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java @@ -0,0 +1,155 @@ +/* + * 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 io.appform.ranger.hub.server.bundle; + +import com.codahale.metrics.health.HealthCheck; +import com.fasterxml.jackson.core.type.TypeReference; +import io.appform.ranger.client.RangerClientConstants; +import io.appform.ranger.client.RangerHubClient; +import io.appform.ranger.client.http.UnshardedRangerHttpHubClient; +import io.appform.ranger.client.zk.UnshardedRangerZKHubClient; +import io.appform.ranger.common.server.ShardInfo; +import io.appform.ranger.core.finder.serviceregistry.ListBasedServiceRegistry; +import io.appform.ranger.core.model.ServiceNode; +import io.appform.ranger.core.signals.Signal; +import io.appform.ranger.http.config.HttpClientConfig; +import io.appform.ranger.http.model.ServiceNodesResponse; +import io.appform.ranger.hub.server.bundle.configuration.*; +import io.appform.ranger.hub.server.bundle.healthcheck.RangerHealthCheck; +import io.appform.ranger.hub.server.bundle.lifecycle.CuratorLifecycle; +import io.appform.ranger.server.bundle.RangerServerBundle; +import io.dropwizard.Configuration; +import lombok.NoArgsConstructor; +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.RetryForever; + +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +@Slf4j +@SuppressWarnings("unused") +@NoArgsConstructor +public abstract class RangerHubServerBundle + extends RangerServerBundle, U> { + + protected abstract RangerServerConfiguration getRangerConfiguration(U configuration); + + private final List curatorFrameworks = new ArrayList<>(); + + @Override + protected List>> withHubs(U configuration) { + val serverConfig = getRangerConfiguration(configuration); + val upstreams = Objects.>requireNonNullElse( + serverConfig.getUpstreams(), Collections.emptyList()); + return upstreams.stream() + .map(rangerUpstreamConfiguration -> rangerUpstreamConfiguration.accept(new HubCreatorVisitor(serverConfig.getNamespace()))) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + @Override + protected List> withLifecycleSignals(U configuration) { + return curatorFrameworks.stream() + .map(curatorFramework -> (Signal) new CuratorLifecycle(curatorFramework)) + .collect(Collectors.toList()); + } + + @Override + protected List withHealthChecks(U configuration) { + return curatorFrameworks.stream() + .map(curatorFramework -> (HealthCheck) new RangerHealthCheck(curatorFramework)) + .collect(Collectors.toList()); + } + + private class HubCreatorVisitor + implements RangerConfigurationVisitor>>> { + private final String namespace; + + public HubCreatorVisitor(String namespace) { + this.namespace = namespace; + } + + private RangerHubClient> addCuratorAndGetZkHubClient( + String zookeeper, RangerZkUpstreamConfiguration zkConfiguration) { + val curatorFramework = CuratorFrameworkFactory.builder() + .connectString(zookeeper) + .namespace(namespace) + .retryPolicy(new RetryForever(RangerClientConstants.CONNECTION_RETRY_TIME)) + .build(); + curatorFrameworks.add(curatorFramework); + return UnshardedRangerZKHubClient.builder() + .namespace(namespace) + .connectionString(zookeeper) + .curatorFramework(curatorFramework) + .disablePushUpdaters(zkConfiguration.isDisablePushUpdaters()) + .mapper(getMapper()) + .nodeRefreshTimeMs(zkConfiguration.getNodeRefreshTimeMs()) + .deserializer(data -> { + try { + return getMapper().readValue(data, new TypeReference>() { + }); + } + catch (IOException e) { + log.warn("Error parsing service data with value {}", new String(data)); + } + return null; + }) + .build(); + } + + private RangerHubClient> getHttpHubClient( + HttpClientConfig httpClientConfig, RangerHttpUpstreamConfiguration httpConfiguration) { + return UnshardedRangerHttpHubClient.builder() + .namespace(namespace) + .mapper(getMapper()) + .clientConfig(httpClientConfig) + .nodeRefreshTimeMs(httpConfiguration.getNodeRefreshTimeMs()) + .deserializer(data -> { + try { + return getMapper().readValue(data, + new TypeReference>() { + }); + } + catch (IOException e) { + log.warn("Error parsing service data with value {}", new String(data)); + } + return null; + }) + .build(); + } + + @Override + public List>> visit( + RangerHttpUpstreamConfiguration rangerHttpConfiguration) { + return rangerHttpConfiguration.getHttpClientConfigs().stream() + .map(http -> getHttpHubClient(http, rangerHttpConfiguration)) + .collect(Collectors.toList()); + } + + @Override + public List>> visit(RangerZkUpstreamConfiguration rangerZkConfiguration) { + return rangerZkConfiguration.getZookeepers().stream() + .map(zk -> addCuratorAndGetZkHubClient(zk, rangerZkConfiguration)) + .collect(Collectors.toList()); + } + } + +} diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java new file mode 100644 index 00000000..67f189d7 --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java @@ -0,0 +1,10 @@ +package io.appform.ranger.hub.server.bundle.configuration; + +/** + * + */ +public interface RangerConfigurationVisitor { + T visit(RangerHttpUpstreamConfiguration rangerHttpConfiguration); + + T visit(RangerZkUpstreamConfiguration rangerZkConfiguration); +} diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpUpstreamConfiguration.java similarity index 73% rename from ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpUpstreamConfiguration.java index e8c6c626..26cf595d 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerHttpUpstreamConfiguration.java @@ -19,21 +19,30 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import io.appform.ranger.http.config.HttpClientConfig; import io.appform.ranger.hub.server.bundle.models.BackendType; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import java.util.List; -@Getter +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) @JsonIgnoreProperties(ignoreUnknown = true) -public class RangerHttpConfiguration extends RangerConfiguration { +public class RangerHttpUpstreamConfiguration extends RangerUpstreamConfiguration { @NotEmpty @Valid private List httpClientConfigs; - public RangerHttpConfiguration() { + public RangerHttpUpstreamConfiguration() { super(BackendType.HTTP); } + + @Override + public T accept(RangerConfigurationVisitor visitor) { + return visitor.visit(this); + } } diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java new file mode 100644 index 00000000..bf1fcdec --- /dev/null +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java @@ -0,0 +1,26 @@ +package io.appform.ranger.hub.server.bundle.configuration; + +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +/** + * + */ +@Value +@Jacksonized +@Builder +public class RangerServerConfiguration { + @NotNull + @NotEmpty + String namespace; + + @NotEmpty + @Valid + List upstreams; +} diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java similarity index 79% rename from ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java index bedc3fbc..c8549e03 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerUpstreamConfiguration.java @@ -19,32 +19,30 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; import io.appform.ranger.client.RangerClientConstants; import io.appform.ranger.hub.server.bundle.models.BackendType; -import javax.validation.constraints.Min; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import lombok.AllArgsConstructor; import lombok.Getter; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + @AllArgsConstructor @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type", visible = true) @JsonSubTypes({ - @JsonSubTypes.Type(value = RangerHttpConfiguration.class, name = "HTTP"), - @JsonSubTypes.Type(value = RangerZkConfiguration.class, name = "ZK") + @JsonSubTypes.Type(value = RangerHttpUpstreamConfiguration.class, name = "HTTP"), + @JsonSubTypes.Type(value = RangerZkUpstreamConfiguration.class, name = "ZK") }) @Getter -public abstract class RangerConfiguration { +public abstract class RangerUpstreamConfiguration { @NotNull private BackendType type; - @NotEmpty - private String namespace; - @Min(RangerClientConstants.MINIMUM_REFRESH_TIME) private int nodeRefreshTimeMs = RangerClientConstants.MINIMUM_REFRESH_TIME; - protected RangerConfiguration(BackendType type) { + protected RangerUpstreamConfiguration(BackendType type) { this.type = type; } + public abstract T accept(final RangerConfigurationVisitor visitor); } diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkUpstreamConfiguration.java similarity index 73% rename from ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java rename to ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkUpstreamConfiguration.java index e04a6835..6ef21c8e 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerZkUpstreamConfiguration.java @@ -17,15 +17,19 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import io.appform.ranger.hub.server.bundle.models.BackendType; -import lombok.Getter; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import java.util.List; -@Getter +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) @JsonIgnoreProperties(ignoreUnknown = true) -public class RangerZkConfiguration extends RangerConfiguration { +public class RangerZkUpstreamConfiguration extends RangerUpstreamConfiguration { @NotEmpty @Valid @@ -33,7 +37,12 @@ public class RangerZkConfiguration extends RangerConfiguration { private boolean disablePushUpdaters; - protected RangerZkConfiguration() { + protected RangerZkUpstreamConfiguration() { super(BackendType.ZK); } + + @Override + public T accept(RangerConfigurationVisitor visitor) { + return visitor.visit(this); + } } diff --git a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/RangerServerBundle.java b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/RangerServerBundle.java index 561ef599..29d5f3f7 100644 --- a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/RangerServerBundle.java +++ b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/RangerServerBundle.java @@ -37,6 +37,7 @@ import java.util.List; +@Getter @Slf4j public abstract class RangerServerBundle< T, @@ -51,9 +52,7 @@ public abstract class RangerServerBundle< You could also define your custom aggregation by using the {@link RangerHubClient} */ - @Getter private List> hubs; - @Getter private ObjectMapper mapper; protected void preBundle(U configuration){ diff --git a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java index 854d3d2a..2c5c269b 100644 --- a/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java +++ b/ranger-server-bundle/src/main/java/io/appform/ranger/server/bundle/resources/RangerResource.java @@ -15,7 +15,6 @@ */ package io.appform.ranger.server.bundle.resources; -import com.codahale.metrics.annotation.Metered; import com.codahale.metrics.annotation.Timed; import io.appform.ranger.client.RangerHubClient; import io.appform.ranger.core.model.Service; @@ -33,6 +32,7 @@ import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.function.Function; import java.util.stream.Collectors; @Slf4j @@ -44,7 +44,7 @@ public class RangerResource> { private final List> rangerHubs; @Inject - public RangerResource(List> rangerHubs){ + public RangerResource(List> rangerHubs) { this.rangerHubs = rangerHubs; } @@ -53,22 +53,31 @@ public RangerResource(List> rangerHubs){ @Timed public GenericResponse> getServices() { return GenericResponse.>builder() - .data(rangerHubs.stream().map(RangerHubClient::getRegisteredServices) - .flatMap(Collection::stream).collect(Collectors.toSet())) + .data(rangerHubs.stream() + .map(RangerHubClient::getRegisteredServices) + .flatMap(Collection::stream) + .collect(Collectors.toSet())) .build(); } @GET @Path("/nodes/v1/{namespace}/{serviceName}") @Timed - public GenericResponse>> getNodes( + public GenericResponse>> getNodes( @NotNull @NotEmpty @PathParam("namespace") final String namespace, - @NotNull @NotEmpty @PathParam("serviceName") final String serviceName - ){ + @NotNull @NotEmpty @PathParam("serviceName") final String serviceName) { val service = Service.builder().namespace(namespace).serviceName(serviceName).build(); - return GenericResponse.>>builder() - .data(rangerHubs.stream().map(hub -> hub.getAllNodes(service)) - .flatMap(List::stream).collect(Collectors.toList())) + return GenericResponse.>>builder() + .data(rangerHubs.stream() + .map(hub -> hub.getAllNodes(service)) + .flatMap(List::stream) + .collect(Collectors.toMap(node -> node.getHost() + ":" + node.getPort(), + Function.identity(), + (oldV, newV) -> + oldV.getLastUpdatedTimeStamp() > newV.getLastUpdatedTimeStamp() + ? oldV + : newV)) + .values()) .build(); } } diff --git a/ranger-server/pom.xml b/ranger-server/pom.xml new file mode 100644 index 00000000..e959523a --- /dev/null +++ b/ranger-server/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + + io.appform.ranger + ranger + 1.0-RC17 + + + ranger-server + + + + io.appform.ranger + ranger-hub-server-bundle + ${project.version} + + + io.dropwizard + dropwizard-core + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + false + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + package + + shade + + + + + + io.appform.ranger.server.App + + + + + + + + + \ No newline at end of file diff --git a/ranger-server/src/main/java/io/appform/ranger/server/App.java b/ranger-server/src/main/java/io/appform/ranger/server/App.java new file mode 100644 index 00000000..c57a4fb6 --- /dev/null +++ b/ranger-server/src/main/java/io/appform/ranger/server/App.java @@ -0,0 +1,46 @@ +package io.appform.ranger.server; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; +import io.appform.ranger.hub.server.bundle.RangerHubServerBundle; +import io.appform.ranger.hub.server.bundle.configuration.RangerServerConfiguration; +import io.dropwizard.Application; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; +import lombok.SneakyThrows; +import lombok.val; + +/** + * + */ +public class App extends Application { + + @Override + public void initialize(Bootstrap bootstrap) { + bootstrap.addBundle(new RangerHubServerBundle() { + @Override + protected RangerServerConfiguration getRangerConfiguration(AppConfig configuration) { + return configuration.getRanger(); + } + }); + } + + @Override + public void run(AppConfig appConfig, Environment environment) throws Exception { + val objectMapper = environment.getObjectMapper(); + objectMapper.registerModule(new ParameterNamesModule()); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); + objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS); + } + + @SneakyThrows + public static void main(String[] args) { + new App().run(args); + } +} diff --git a/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java b/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java new file mode 100644 index 00000000..b77dbb01 --- /dev/null +++ b/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java @@ -0,0 +1,22 @@ +package io.appform.ranger.server; + +import io.appform.ranger.hub.server.bundle.configuration.RangerServerConfiguration; +import io.dropwizard.Configuration; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +/** + * + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class AppConfig extends Configuration { + @NotNull + @Valid + RangerServerConfiguration ranger; +} From d4aaae4604e1b7bf6a8db6ebbaa3cbf98716d173 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Tue, 4 Jun 2024 09:46:23 +0530 Subject: [PATCH 3/4] Updated sonatype plugin version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 19c770d3..321afcd6 100644 --- a/pom.xml +++ b/pom.xml @@ -241,7 +241,7 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.13 + 1.7.0 true ossrh From dc3b31bf45d3ef1dade09c7ea66b2d3d23e413a1 Mon Sep 17 00:00:00 2001 From: Santanu Sinha Date: Wed, 12 Jun 2024 16:23:05 +0530 Subject: [PATCH 4/4] Fixes for comments --- .../server/bundle/RangerHubServerBundle.java | 8 ++------ .../RangerConfigurationVisitor.java | 17 ++++++++++++++++- .../RangerServerConfiguration.java | 15 +++++++++++++++ .../main/java/io/appform/ranger/server/App.java | 16 ++++++++++++++++ .../io/appform/ranger/server/AppConfig.java | 16 ++++++++++++++++ 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java index 00141e19..5ce111f0 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/RangerHubServerBundle.java @@ -32,9 +32,8 @@ import io.appform.ranger.hub.server.bundle.lifecycle.CuratorLifecycle; import io.appform.ranger.server.bundle.RangerServerBundle; import io.dropwizard.Configuration; -import lombok.NoArgsConstructor; +import lombok.*; 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.RetryForever; @@ -78,15 +77,12 @@ protected List withHealthChecks(U configuration) { .collect(Collectors.toList()); } + @AllArgsConstructor private class HubCreatorVisitor implements RangerConfigurationVisitor>>> { private final String namespace; - public HubCreatorVisitor(String namespace) { - this.namespace = namespace; - } - private RangerHubClient> addCuratorAndGetZkHubClient( String zookeeper, RangerZkUpstreamConfiguration zkConfiguration) { val curatorFramework = CuratorFrameworkFactory.builder() diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java index 67f189d7..37508b78 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerConfigurationVisitor.java @@ -1,7 +1,22 @@ +/* + * 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 io.appform.ranger.hub.server.bundle.configuration; /** - * + * For handling configuration level handling */ public interface RangerConfigurationVisitor { T visit(RangerHttpUpstreamConfiguration rangerHttpConfiguration); diff --git a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java index bf1fcdec..80a98cfb 100644 --- a/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java +++ b/ranger-hub-server-bundle/src/main/java/io/appform/ranger/hub/server/bundle/configuration/RangerServerConfiguration.java @@ -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 io.appform.ranger.hub.server.bundle.configuration; import lombok.Builder; diff --git a/ranger-server/src/main/java/io/appform/ranger/server/App.java b/ranger-server/src/main/java/io/appform/ranger/server/App.java index c57a4fb6..4bdf2ecd 100644 --- a/ranger-server/src/main/java/io/appform/ranger/server/App.java +++ b/ranger-server/src/main/java/io/appform/ranger/server/App.java @@ -1,3 +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 io.appform.ranger.server; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java b/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java index b77dbb01..99c6fee3 100644 --- a/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java +++ b/ranger-server/src/main/java/io/appform/ranger/server/AppConfig.java @@ -1,3 +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 io.appform.ranger.server; import io.appform.ranger.hub.server.bundle.configuration.RangerServerConfiguration;