knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [knox] branch master updated: KNOX-1851 - Fix NPE in Zookeeper Remote Alias Service (#86)
Date Thu, 11 Apr 2019 03:59:15 GMT
This is an automated email from the ASF dual-hosted git repository.

more pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 9b611ae  KNOX-1851 - Fix NPE in Zookeeper Remote Alias Service (#86)
9b611ae is described below

commit 9b611aea89a7ff0ef9205e071e076c92b4afccdf
Author: Sandeep Moré <moresandeep@gmail.com>
AuthorDate: Wed Apr 10 23:59:11 2019 -0400

    KNOX-1851 - Fix NPE in Zookeeper Remote Alias Service (#86)
---
 gateway-server/pom.xml                             |  4 ++++
 .../impl/ZookeeperRemoteAliasServiceProvider.java  | 28 +++++++++++++++++++---
 .../java/org/apache/knox/gateway/util/KnoxCLI.java |  2 +-
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/gateway-server/pom.xml b/gateway-server/pom.xml
index 28d07b8..1d43d9b 100644
--- a/gateway-server/pom.xml
+++ b/gateway-server/pom.xml
@@ -354,6 +354,10 @@
             <groupId>com.sun.xml.bind</groupId>
             <artifactId>jaxb-impl</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.knox</groupId>
+            <artifactId>gateway-util-configinjector</artifactId>
+        </dependency>
 
         <!-- ********** ********** ********** ********** ********** ********** -->
         <!-- ********** Test Dependencies                           ********** -->
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceProvider.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceProvider.java
index 5fc37b5..52c4462 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceProvider.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/ZookeeperRemoteAliasServiceProvider.java
@@ -17,10 +17,18 @@
  */
 package org.apache.knox.gateway.services.security.impl;
 
+import org.apache.knox.gateway.GatewayServer;
+import org.apache.knox.gateway.config.ConfigurationException;
 import org.apache.knox.gateway.security.RemoteAliasServiceProvider;
-import org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientServiceProvider;
+import org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientService;
+import org.apache.knox.gateway.services.GatewayServices;
+import org.apache.knox.gateway.services.ServiceType;
+import org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService;
 import org.apache.knox.gateway.services.security.AliasService;
 import org.apache.knox.gateway.services.security.MasterService;
+import org.apache.knox.gateway.util.KnoxCLI;
+
+import java.util.Locale;
 
 public class ZookeeperRemoteAliasServiceProvider implements RemoteAliasServiceProvider {
   @Override
@@ -30,7 +38,21 @@ public class ZookeeperRemoteAliasServiceProvider implements RemoteAliasServicePr
 
   @Override
   public AliasService newInstance(AliasService localAliasService, MasterService ms) {
-    return new ZookeeperRemoteAliasService(localAliasService, ms,
-        new ZooKeeperClientServiceProvider().newInstance());
+
+    final GatewayServices services = GatewayServer.getGatewayServices() != null ? GatewayServer.getGatewayServices()
: KnoxCLI.getGatewayServices();
+
+    if(services != null) {
+      final RemoteConfigurationRegistryClientService registryClientService = services
+          .getService(ServiceType.REMOTE_REGISTRY_CLIENT_SERVICE);
+
+      /* Check to see if we already have ZooKeeperClientService instance, if so use it */
+      if (registryClientService instanceof ZooKeeperClientService) {
+        return new ZookeeperRemoteAliasService(localAliasService, ms,
+            registryClientService);
+
+      }
+    }
+
+    throw new ConfigurationException(String.format(Locale.ROOT,"%s service not configured",
ZooKeeperClientService.TYPE));
   }
 }
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
index 6413315..daae9f3 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
@@ -171,7 +171,7 @@ public class KnoxCLI extends Configured implements Tool {
     return exitCode;
   }
 
-  GatewayServices getGatewayServices() {
+  public static synchronized GatewayServices getGatewayServices() {
     return services;
   }
 


Mime
View raw message