KNOX-1352 - Service Discovery is not honoring the enabled attribute of HA Provider...
authorPhil Zampino <pzampino@apache.org>
Mon, 11 Jun 2018 15:30:10 +0000 (11:30 -0400)
committerPhil Zampino <pzampino@apache.org>
Mon, 11 Jun 2018 15:48:25 +0000 (11:48 -0400)
gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java

index 19521e3..f3bc172 100644 (file)
@@ -502,7 +502,7 @@ public class SimpleDescriptorHandler {
                 }
 
                 // If the service is configured for ZooKeeper-based HA
-                if (zkConf != null && zkConf.getEnsemble() != null) {
+                if (zkConf != null && zkConf.getEnsemble() != null && isServiceHaEnabled) {
                     String ensemble = zkConf.getEnsemble();
                     if (ensemble != null && !ensemble.isEmpty()) {
                         params.put("zookeeperEnsemble", ensemble);
index ec78155..58a6c72 100644 (file)
@@ -126,6 +126,7 @@ public class SimpleDescriptorHandlerTest {
             "            <param><name>WEBHDFS</name><value>enabled=true;retrySleep=40;maxRetryAttempts=5</value></param>\n" +
             "            <param><name>WEBHBASE</name><value>enabled=auto;retrySleep=30;maxRetryAttempts=3;maxFailoverAttempts=2;failoverSleep=10</value></param>\n" +
             "            <param><name>ATLAS</name><value>enabled=auto;retrySleep=30;maxRetryAttempts=3;maxFailoverAttempts=2;failoverSleep=10</value></param>\n" +
+            "            <param><name>ATLAS-API</name><value>enabled=false</value></param>\n" +
             "        </provider>\n" +
             "    </gateway>\n";
 
@@ -556,6 +557,8 @@ public class SimpleDescriptorHandlerTest {
         DISCOVERY_PROPERTIES.setProperty(clusterName + ".WEBHBASE.ensemble", WEBHBASE_HA_ENSEMBLE);
         DISCOVERY_PROPERTIES.setProperty(clusterName + ".ATLAS.haEnabled", ATLAS_HA_ENABLED);
         DISCOVERY_PROPERTIES.setProperty(clusterName + ".ATLAS.ensemble", ATLAS_HA_ENSEMBLE);
+        DISCOVERY_PROPERTIES.setProperty(clusterName + ".ATLAS-API.ensemble", ATLAS_HA_ENSEMBLE);
+        DISCOVERY_PROPERTIES.setProperty(clusterName + ".ATLAS-API.url", "http://atlasapihost:2222");
 
         try {
             DISCOVERY_PROPERTIES.store(new FileOutputStream(discoveryConfig), null);
@@ -568,6 +571,7 @@ public class SimpleDescriptorHandlerTest {
         serviceURLs.put("WEBHDFS", null);
         serviceURLs.put("RESOURCEMANAGER", null);
         serviceURLs.put("ATLAS", null);
+        serviceURLs.put("ATLAS-API", null);
         serviceURLs.put("HIVE", null);
 
         // Write the externalized provider config to a temp file
@@ -708,6 +712,31 @@ public class SimpleDescriptorHandlerTest {
                     assertNull(atlasServiceParams.get("zookeeperNamespace"));
                 }
 
+                // Validate the ATLAS service params
+                if ("ATLAS-API".equals(role)) {
+                    // Expecting non-HA-related service params
+                    NodeList paramNodes = (NodeList) xpath.compile("param").evaluate(serviceNode, XPathConstants.NODESET);
+                    assertNotNull(paramNodes);
+                    Map<String, String> atlasApiServiceParams = new HashMap<>();
+                    for (int paramNodeIndex=0; paramNodeIndex < paramNodes.getLength(); paramNodeIndex++) {
+                        Node paramNode = paramNodes.item(paramNodeIndex);
+                        Node nameNode = (Node) xpath.compile("name/text()").evaluate(paramNode, XPathConstants.NODE);
+                        assertNotNull(nameNode);
+                        Node valueNode = (Node) xpath.compile("value/text()").evaluate(paramNode, XPathConstants.NODE);
+                        assertNotNull(valueNode);
+                        atlasApiServiceParams.put(nameNode.getNodeValue(), valueNode.getNodeValue());
+                    }
+                    // There should be no HA-related params because the enabled attribute is false
+                    assertNull(atlasApiServiceParams.get("zookeeperEnsemble"));
+                    assertNull(atlasApiServiceParams.get("zookeeperNamespace"));
+
+                    // Instead, the URL should be declared for the service
+                    NodeList urlNodes = (NodeList) xpath.compile("url").evaluate(serviceNode, XPathConstants.NODESET);
+                    assertNotNull(urlNodes);
+                    assertEquals(1, urlNodes.getLength());
+                    assertEquals(DISCOVERY_PROPERTIES.getProperty(clusterName + ".ATLAS-API.url"), urlNodes.item(0).getTextContent());
+                }
+
                 // Validate the URLs
                 NodeList urlNodes = (NodeList) xpath.compile("url/text()").evaluate(serviceNode, XPathConstants.NODESET);
                 for(int urlNodeIndex = 0 ; urlNodeIndex < urlNodes.getLength(); urlNodeIndex++) {