knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pzamp...@apache.org
Subject knox git commit: KNOX-1239 - HBaseZookeeperURLManager ignores configured ZooKeeper namespace
Date Thu, 05 Apr 2018 15:10:37 GMT
Repository: knox
Updated Branches:
  refs/heads/master 8257ed443 -> 84aa9565f


KNOX-1239 - HBaseZookeeperURLManager ignores configured ZooKeeper namespace


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/84aa9565
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/84aa9565
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/84aa9565

Branch: refs/heads/master
Commit: 84aa9565f6ada9f991f0184815f4ba2f04c2fdfe
Parents: 8257ed4
Author: Phil Zampino <pzampino@apache.org>
Authored: Thu Apr 5 10:47:27 2018 -0400
Committer: Phil Zampino <pzampino@apache.org>
Committed: Thu Apr 5 10:47:27 2018 -0400

----------------------------------------------------------------------
 .../provider/impl/BaseZookeeperURLManager.java  | 12 +++--
 .../provider/impl/HBaseZookeeperURLManager.java | 31 +++++++----
 .../impl/HBaseZookeeperURLManagerTest.java      | 54 +++++++++++++++-----
 3 files changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/84aa9565/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/BaseZookeeperURLManager.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/BaseZookeeperURLManager.java
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/BaseZookeeperURLManager.java
index 2b18fc1..868fda8 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/BaseZookeeperURLManager.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/BaseZookeeperURLManager.java
@@ -49,6 +49,7 @@ public abstract class BaseZookeeperURLManager implements URLManager {
 	private static final int TIMEOUT = 2000;
 
 	private String zooKeeperEnsemble;
+	private String zooKeeperNamespace;
 	private ConcurrentLinkedQueue<String> urls = new ConcurrentLinkedQueue<String>();
 
 	// -------------------------------------------------------------------------------------
@@ -65,13 +66,14 @@ public abstract class BaseZookeeperURLManager implements URLManager {
 		if (zookeeperEnsemble != null && zookeeperEnsemble.trim().length() > 0) {
 			return true;
 		}
-		
+
 		return false;
 	}
 
 	@Override
 	public void setConfig(HaServiceConfig config) {
-		zooKeeperEnsemble = config.getZookeeperEnsemble();
+		zooKeeperEnsemble  = config.getZookeeperEnsemble();
+		zooKeeperNamespace = config.getZookeeperNamespace();
 		setURLs(lookupURLs());
 	}
 
@@ -138,7 +140,11 @@ public abstract class BaseZookeeperURLManager implements URLManager {
 	protected String getZookeeperEnsemble() {
 		return zooKeeperEnsemble;
 	}
-	
+
+	protected String getZookeeperNamespace() {
+		return zooKeeperNamespace;
+	}
+
 	/**
 	 * Validate access to hosts using simple light weight ping style REST call.
 	 * 

http://git-wip-us.apache.org/repos/asf/knox/blob/84aa9565/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManager.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManager.java
b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManager.java
index 461ea98..d2053cd 100644
--- a/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManager.java
+++ b/gateway-provider-ha/src/main/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManager.java
@@ -43,9 +43,9 @@ public class HBaseZookeeperURLManager extends BaseZookeeperURLManager {
 	 * Default Port Number for HBase REST Server
 	 */
 	private static final int PORT_NUMBER = 8080;
-	
-	private String zookeeperNamespace = "hbase-unsecure";
-	
+
+	private static final String DEFAULT_ZOOKEEPER_NAMESPACE = "/hbase-unsecure";
+
 	// -------------------------------------------------------------------------------------
 	// Abstract methods
 	// -------------------------------------------------------------------------------------
@@ -75,6 +75,12 @@ public class HBaseZookeeperURLManager extends BaseZookeeperURLManager {
 		return "WEBHBASE";
 	};
 
+	@Override
+	protected String getZookeeperNamespace() {
+		String ns = super.getZookeeperNamespace();
+		return (ns == null || ns.isEmpty()) ? DEFAULT_ZOOKEEPER_NAMESPACE : ns;
+	}
+
 	// -------------------------------------------------------------------------------------
 	// Private methods
 	// -------------------------------------------------------------------------------------
@@ -86,16 +92,21 @@ public class HBaseZookeeperURLManager extends BaseZookeeperURLManager
{
 	{
 		List<String> serverHosts = new ArrayList<>();
 		
-		CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder()
-				.connectString(getZookeeperEnsemble())
-				.retryPolicy(new ExponentialBackoffRetry(1000, 3))
-				.build();
-		
+		CuratorFramework zooKeeperClient =
+                    CuratorFrameworkFactory.builder().connectString(getZookeeperEnsemble())
+                                                     .retryPolicy(new ExponentialBackoffRetry(1000,
3))
+                                                     .build();
+
 		try {
 			zooKeeperClient.start();
-			
+
+			String namespace = getZookeeperNamespace();
+			if (!namespace.startsWith("/")) {
+				namespace = "/" + namespace;
+			}
+
 			// Retrieve list of all region server hosts
-			List<String> serverNodes = zooKeeperClient.getChildren().forPath("/" + zookeeperNamespace
+ "/rs");
+			List<String> serverNodes = zooKeeperClient.getChildren().forPath(namespace + "/rs");
 			
 			for (String serverNode : serverNodes) {
 				String serverURL = constructURL(serverNode);

http://git-wip-us.apache.org/repos/asf/knox/blob/84aa9565/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java
----------------------------------------------------------------------
diff --git a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java
b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java
index b08576d..1869890 100644
--- a/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java
+++ b/gateway-provider-ha/src/test/java/org/apache/knox/gateway/ha/provider/impl/HBaseZookeeperURLManagerTest.java
@@ -31,28 +31,24 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
+import static org.junit.Assert.fail;
+
 /**
  * Simple unit tests for HBaseZookeeperURLManager.
  * 
  * @see HBaseZookeeperURLManager
  */
 public class HBaseZookeeperURLManagerTest {
-	
+
+  private static final String UNSECURE_NS = "/hbase-unsecure";
+  private static final String SECURE_NS   = "/hbase-secure";
+
   private TestingCluster cluster;
 
   @Before
   public void setup() throws Exception {
     cluster = new TestingCluster(3);
     cluster.start();
-
-    CuratorFramework zooKeeperClient =
-        CuratorFrameworkFactory.builder().connectString(cluster.getConnectString())
-            .retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
-
-    zooKeeperClient.start();
-    zooKeeperClient.create().forPath("/hbase-unsecure");
-    zooKeeperClient.create().forPath("/hbase-unsecure/rs");
-    zooKeeperClient.close();
   }
 
   @After
@@ -61,12 +57,46 @@ public class HBaseZookeeperURLManagerTest {
   }
 
   @Test
-  public void testHBaseZookeeperURLManagerLoading() {
+  public void testHBaseZookeeperURLManagerLoading() throws Exception {
+    createZNodes(UNSECURE_NS);
+    doTest(null);
+  }
+
+  @Test
+  public void testSecureNSHBaseZookeeperURLManagerLoading() throws Exception {
+    createZNodes(SECURE_NS);
+    doTest(SECURE_NS);
+  }
+
+  @Test
+  public void testSecureNSHBaseZookeeperURLManagerLoadingNoLeadingSlash() throws Exception
{
+    createZNodes(SECURE_NS);
+    doTest(SECURE_NS.substring(1)); // Omit the leading slash from the namespace
+  }
+
+  private void doTest(String namespace) throws Exception {
     HaServiceConfig config = new DefaultHaServiceConfig("WEBHBASE");
     config.setEnabled(true);
     config.setZookeeperEnsemble(cluster.getConnectString());
-    URLManager manager = URLManagerLoader.loadURLManager(config);
+    config.setZookeeperNamespace(namespace);
+    URLManager manager = null;
+    try {
+      manager = URLManagerLoader.loadURLManager(config);
+    } catch (Exception e) {
+      fail(e.getMessage());
+    }
     Assert.assertNotNull(manager);
     Assert.assertTrue(manager instanceof HBaseZookeeperURLManager);
   }
+
+  private void createZNodes(String namespace) throws Exception {
+    CuratorFramework zooKeeperClient =
+                          CuratorFrameworkFactory.builder().connectString(cluster.getConnectString())
+                                                           .retryPolicy(new ExponentialBackoffRetry(1000,
3)).build();
+    zooKeeperClient.start();
+    zooKeeperClient.create().forPath(namespace);
+    zooKeeperClient.create().forPath(namespace + "/rs");
+    zooKeeperClient.close();
+  }
+
 }


Mime
View raw message