You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2018/03/15 16:20:28 UTC

knox git commit: KNOX-1208 - Fix WEBHBASE ZooKeeper ensemble discovery when proxying HA HBase

Repository: knox
Updated Branches:
  refs/heads/master 2e8716d89 -> 76df40b95


KNOX-1208 - Fix WEBHBASE ZooKeeper ensemble discovery when proxying HA HBase


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

Branch: refs/heads/master
Commit: 76df40b9535fbbaf8fd826dc35f15b585e81fa36
Parents: 2e8716d
Author: Phil Zampino <pz...@apache.org>
Authored: Thu Mar 15 10:37:39 2018 -0400
Committer: Phil Zampino <pz...@apache.org>
Committed: Thu Mar 15 10:37:39 2018 -0400

----------------------------------------------------------------------
 .../discovery/ambari/AmbariCluster.java         | 29 +++++++++++++++++---
 ...rvice-discovery-zk-config-mapping.properties |  1 +
 .../discovery/ambari/AmbariClusterTest.java     | 20 ++++++++++++++
 3 files changed, 46 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/76df40b9/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariCluster.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariCluster.java b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariCluster.java
index e93992c..b5e4cff 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariCluster.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariCluster.java
@@ -144,14 +144,16 @@ class AmbariCluster implements ServiceDiscovery.Cluster {
             if (parts.length == 2) {
                 ServiceConfiguration sc = getServiceConfiguration(parts[0], parts[1]);
                 if (sc != null) {
-                    String enabledProp = zooKeeperHAConfigMappings.getProperty(serviceName + ".enabled");
-                    String ensembleProp = zooKeeperHAConfigMappings.getProperty(serviceName + ".ensemble");
+                    String enabledProp   = zooKeeperHAConfigMappings.getProperty(serviceName + ".enabled");
+                    String ensembleProp  = zooKeeperHAConfigMappings.getProperty(serviceName + ".ensemble");
+                    String portProp      = zooKeeperHAConfigMappings.getProperty(serviceName + ".port");
                     String namespaceProp = zooKeeperHAConfigMappings.getProperty(serviceName + ".namespace");
                     Map<String, String> scProps = sc.getProperties();
                     if (scProps != null) {
                         result =
                             new ZooKeeperConfiguration(enabledProp != null ? scProps.get(enabledProp) : null,
                                                        ensembleProp != null ? scProps.get(ensembleProp) : null,
+                                                       portProp != null ? scProps.get(portProp) : null,
                                                        namespaceProp != null ? scProps.get(namespaceProp) : null);
                     }
                 }
@@ -193,9 +195,9 @@ class AmbariCluster implements ServiceDiscovery.Cluster {
         String ensemble;
         String namespace;
 
-        ZooKeeperConfiguration(String enabled, String ensemble, String namespace) {
+        ZooKeeperConfiguration(String enabled, String ensemble, String port, String namespace) {
             this.namespace = namespace;
-            this.ensemble = ensemble;
+            this.ensemble = (port == null) ? ensemble : applyPortToEnsemble(ensemble, port);
             this.isEnabled = (enabled != null ? Boolean.valueOf(enabled) : true);
         }
 
@@ -213,5 +215,24 @@ class AmbariCluster implements ServiceDiscovery.Cluster {
         public String getNamespace() {
             return namespace;
         }
+
+        private String applyPortToEnsemble(String ensemble, String port) {
+            String updatedEnsemble = "";
+
+            String[] hosts = ensemble.split(",");
+            int index = 0;
+            for (String host : hosts) {
+                int portIndex = host.indexOf(':');
+                if (portIndex > 0) {
+                    host = host.substring(0, portIndex);
+                }
+                updatedEnsemble += host + ":" + port;
+                if (++index < hosts.length) {
+                    updatedEnsemble += ",";
+                }
+            }
+
+            return updatedEnsemble;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/76df40b9/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-zk-config-mapping.properties
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-zk-config-mapping.properties b/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-zk-config-mapping.properties
index 2f5e4ba..0a5faae 100644
--- a/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-zk-config-mapping.properties
+++ b/gateway-discovery-ambari/src/main/resources/ambari-service-discovery-zk-config-mapping.properties
@@ -25,6 +25,7 @@ HIVE.namespace=hive.server2.zookeeper.namespace
 # HBASE
 WEBHBASE.config=HBASE:hbase-site
 WEBHBASE.ensemble=hbase.zookeeper.quorum
+WEBHBASE.port=hbase.zookeeper.property.clientPort
 WEBHBASE.namespace=zookeeper.znode.parent
 
 # KAFKA

http://git-wip-us.apache.org/repos/asf/knox/blob/76df40b9/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClusterTest.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClusterTest.java b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClusterTest.java
index 260051b..abec9d9 100644
--- a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClusterTest.java
+++ b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClusterTest.java
@@ -123,6 +123,26 @@ public class AmbariClusterTest {
     assertEquals(namespace, config.getNamespace());
   }
 
+  @Test
+  public void testHBaseZooKeeperConfiguration() throws Exception {
+
+    final boolean isEnabled = true;
+    final String ensemble = "host1:2181,host2:2181,host3:2181";
+    final String namespace = "/hbase-secure";
+
+    Map<String, String> serviceConfigProps = new HashMap<>();
+    serviceConfigProps.put("hbase.zookeeper.quorum", "host1,host2,host3");
+    serviceConfigProps.put("hbase.zookeeper.property.clientPort", "2181");
+    serviceConfigProps.put("zookeeper.znode.parent", namespace);
+
+    AmbariCluster.ZooKeeperConfig config = getZooKeeperConfiguration("WEBHBASE", "HBASE", "hbase-site", serviceConfigProps);
+    assertNotNull(config);
+    assertEquals(isEnabled, config.isEnabled());
+    assertEquals(ensemble, config.getEnsemble());
+    assertEquals(namespace, config.getNamespace());
+  }
+
+
 
   private ServiceDiscovery.Cluster.ZooKeeperConfig getZooKeeperConfiguration(final String              serviceName,
                                                                              final String              configType,