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-1198 - Support Ambari service discovery mappings override/augmentation with external config
Date Fri, 02 Mar 2018 16:43:11 GMT
Repository: knox
Updated Branches:
  refs/heads/master 64a762f53 -> c7da8f6b7


KNOX-1198 - Support Ambari service discovery mappings override/augmentation with external
config


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

Branch: refs/heads/master
Commit: c7da8f6b7d9d9296e453df2ab296f9fce4e76dfb
Parents: 64a762f
Author: Phil Zampino <pzampino@apache.org>
Authored: Thu Mar 1 16:01:55 2018 -0500
Committer: Phil Zampino <pzampino@apache.org>
Committed: Fri Mar 2 11:27:43 2018 -0500

----------------------------------------------------------------------
 .../discovery/ambari/AmbariCluster.java         |  14 +--
 .../ambari/AmbariDynamicServiceURLCreator.java  |  12 +-
 .../ambari/AmbariServiceDiscovery.java          |  43 +++++--
 .../ambari/ServiceURLPropertyConfig.java        |  50 +++++++-
 .../AmbariDynamicServiceURLCreatorTest.java     |  82 ++++++++++--
 .../ambari/AmbariServiceDiscoveryTest.java      | 126 +++++++++++++++++++
 6 files changed, 295 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/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 35a1206..e93992c 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
@@ -47,19 +47,15 @@ class AmbariCluster implements ServiceDiscovery.Cluster {
                 zooKeeperHAConfigMappings.setProperty(name, defaults.getProperty(name));
             }
 
-            // Attempt to apply overriding or additional mappings
+            // Attempt to apply overriding or additional mappings from external source
             String overridesPath = System.getProperty(ZK_CONFIG_MAPPING_SYSTEM_PROPERTY);
             if (overridesPath != null) {
                 Properties overrides = new Properties();
-                InputStream in = new FileInputStream(overridesPath);
-                try {
+                try (InputStream in = new FileInputStream(overridesPath)) {
                     overrides.load(in);
-                } finally {
-                    in.close();
-                }
-
-                for (String name : overrides.stringPropertyNames()) {
-                    zooKeeperHAConfigMappings.setProperty(name, overrides.getProperty(name));
+                    for (String name : overrides.stringPropertyNames()) {
+                        zooKeeperHAConfigMappings.setProperty(name, overrides.getProperty(name));
+                    }
                 }
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java
index ceb7b50..96d462b 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreator.java
@@ -40,23 +40,23 @@ class AmbariDynamicServiceURLCreator implements ServiceURLCreator {
     AmbariDynamicServiceURLCreator(AmbariCluster cluster) {
         this.cluster = cluster;
 
+        // Load the default internal configuration
+        config = new ServiceURLPropertyConfig();
+
+        // Attempt to apply overriding or additional mappings from external source
         String mappingConfiguration = System.getProperty(MAPPING_CONFIG_OVERRIDE_PROPERTY);
         if (mappingConfiguration != null) {
             File mappingConfigFile = new File(mappingConfiguration);
             if (mappingConfigFile.exists()) {
                 try {
-                    config = new ServiceURLPropertyConfig(mappingConfigFile);
+                    ServiceURLPropertyConfig overrides = new ServiceURLPropertyConfig(mappingConfigFile);
                     log.loadedComponentConfigMappings(mappingConfigFile.getAbsolutePath());
+                    config.setAll(overrides); // Apply overrides/additions
                 } catch (Exception e) {
                     log.failedToLoadComponentConfigMappings(mappingConfigFile.getAbsolutePath(),
e);
                 }
             }
         }
-
-        // If there is no valid override configured, fall-back to the internal mapping configuration
-        if (config == null) {
-            config = new ServiceURLPropertyConfig();
-        }
     }
 
     AmbariDynamicServiceURLCreator(AmbariCluster cluster, File mappingConfiguration) throws
IOException {

http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
index 6a6a888..80009cc 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
@@ -16,6 +16,8 @@
  */
 package org.apache.knox.gateway.topology.discovery.ambari;
 
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -45,6 +47,9 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
 
     static final String AMBARI_SERVICECONFIGS_URI = AmbariClientCommon.AMBARI_SERVICECONFIGS_URI;
 
+    static final String COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY =
+                                                  "org.apache.knox.gateway.topology.discovery.ambari.component.mapping";
+
     private static final String COMPONENT_CONFIG_MAPPING_FILE =
                                                         "ambari-service-discovery-component-config-mapping.properties";
 
@@ -56,15 +61,7 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
     // Map of component names to service configuration types
     private static Map<String, String> componentServiceConfigs = new HashMap<>();
     static {
-        try {
-            Properties configMapping = new Properties();
-            configMapping.load(AmbariServiceDiscovery.class.getClassLoader().getResourceAsStream(COMPONENT_CONFIG_MAPPING_FILE));
-            for (String componentName : configMapping.stringPropertyNames()) {
-                componentServiceConfigs.put(componentName, configMapping.getProperty(componentName));
-            }
-        } catch (Exception e) {
-            log.failedToLoadServiceDiscoveryURLDefConfiguration(COMPONENT_CONFIG_MAPPING_FILE,
e);
-        }
+        initializeComponentConfigMappings();
     }
 
     @GatewayService
@@ -78,6 +75,34 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
 
     private boolean isInitialized = false;
 
+    //
+    static void initializeComponentConfigMappings(){
+        try {
+            componentServiceConfigs.clear();
+
+            Properties configMapping = new Properties();
+            configMapping.load(AmbariServiceDiscovery.class.getClassLoader().getResourceAsStream(COMPONENT_CONFIG_MAPPING_FILE));
+            for (String componentName : configMapping.stringPropertyNames()) {
+                componentServiceConfigs.put(componentName, configMapping.getProperty(componentName));
+            }
+
+            // Attempt to apply overriding or additional mappings from external source
+            String overridesPath = System.getProperty(COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY);
+            if (overridesPath != null) {
+                Properties overrides = new Properties();
+                try (InputStream in = new FileInputStream(overridesPath)) {
+                    overrides.load(in);
+                    for (String name : overrides.stringPropertyNames()) {
+                        componentServiceConfigs.put(name, overrides.getProperty(name));
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.failedToLoadServiceDiscoveryURLDefConfiguration(COMPONENT_CONFIG_MAPPING_FILE,
e);
+        }
+    }
+
+
     AmbariServiceDiscovery() {
     }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLPropertyConfig.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLPropertyConfig.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLPropertyConfig.java
index 9f3da3d..58096e9 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLPropertyConfig.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLPropertyConfig.java
@@ -131,8 +131,56 @@ class ServiceURLPropertyConfig {
         return urlPatterns.get(service);
     }
 
+
+    void setAll(ServiceURLPropertyConfig overrides) {
+        if (overrides != null) {
+            // URL patterns
+            if (overrides.urlPatterns != null) {
+                for (String service : overrides.urlPatterns.keySet()) {
+                    URLPattern overridePattern = overrides.urlPatterns.get(service);
+                    if (this.urlPatterns.containsKey(service)) {
+                        this.urlPatterns.replace(service, overridePattern);
+                    } else {
+                        this.urlPatterns.put(service, overridePattern);
+                    }
+                }
+            }
+
+            // Properties
+            for (String service : overrides.properties.keySet()) {
+                Map<String, Property> serviceProperties = overrides.properties.get(service);
+                if (serviceProperties != null) {
+                    // Remove the original property set for this service
+                    Map<String, Property> existingServiceProps = this.properties.get(service);
+                    if (existingServiceProps != null) {
+                        existingServiceProps.clear();
+                    }
+
+                    // Add the override properties
+                    for (String propertyName : serviceProperties.keySet()) {
+                        setConfigProperty(service, propertyName, serviceProperties.get(propertyName));
+                    }
+                }
+            }
+        }
+    }
+
+    void setConfigProperty(String service, String name, Property value) {
+        Map<String, Property> serviceProperties = properties.get(service);
+        if (serviceProperties == null) {
+            serviceProperties = new HashMap<>();
+            properties.put(service, serviceProperties);
+        }
+        serviceProperties.put(name, value);
+    }
+
     Property getConfigProperty(String service, String property) {
-        return properties.get(service).get(property);
+        Property result = null;
+        Map<String, Property> serviceProperties = properties.get(service);
+        if (serviceProperties != null) {
+            result = serviceProperties.get(property);
+        }
+        return result;
     }
 
     static class URLPattern {

http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java
index 23a5f5a..9f4ea59 100644
--- a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java
+++ b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java
@@ -16,6 +16,7 @@
  */
 package org.apache.knox.gateway.topology.discovery.ambari;
 
+import org.apache.commons.io.FileUtils;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
@@ -312,11 +313,28 @@ public class AmbariDynamicServiceURLCreatorTest {
     }
 
     @Test
+    public void testOozieURLFromInternalMappingWithExternalOverrides() throws Exception {
+        File tmpFile = File.createTempFile("knox-discovery-external-url-mapping", ".xml");
+        System.setProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY,
tmpFile.getAbsolutePath());
+        try {
+            FileUtils.writeStringToFile(tmpFile, OOZIE_OVERRIDE_MAPPING_FILE_CONTENTS, java.nio.charset.Charset.forName("utf-8"));
+            testOozieURL(null, "OOZIE", "http://host3:2222/OVERRIDE");
+        } finally {
+            System.clearProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY);
+            FileUtils.deleteQuietly(tmpFile);
+        }
+    }
+
+    @Test
     public void testOozieUIURLFromInternalMapping() throws Exception {
         testOozieURL(null, "OOZIEUI");
     }
 
     private void testOozieURL(Object mappingConfiguration, String serviceName) throws Exception
{
+        testOozieURL(mappingConfiguration, serviceName, null);
+    }
+
+    private void testOozieURL(Object mappingConfiguration, String serviceName, String altExpectation)
throws Exception {
         final String URL = "http://host3:2222";
 
         AmbariComponent oozieServer = EasyMock.createNiceMock(AmbariComponent.class);
@@ -333,7 +351,7 @@ public class AmbariDynamicServiceURLCreatorTest {
         assertNotNull(urls);
         assertFalse(urls.isEmpty());
         String url = urls.get(0);
-        assertEquals(URL, url);
+        assertEquals((altExpectation != null ? altExpectation : URL), url);
     }
 
     @Test
@@ -1209,6 +1227,42 @@ public class AmbariDynamicServiceURLCreatorTest {
         assertEquals("http://{HOST}:{PORT}/{PATH}", urls.get(0));
     }
 
+    @Test
+    public void testExtensionServiceURLFromOverride() throws Exception {
+        File tmpFile = File.createTempFile("knox-discovery-url-mapping-extension", ".xml");
+        System.setProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY,
tmpFile.getAbsolutePath());
+        try {
+            FileUtils.writeStringToFile(tmpFile, CUSTOM_AUGMENT_MAPPING_FILE_CONTENTS, java.nio.charset.Charset.forName("utf-8"));
+
+            final String[] HOSTNAMES = {"host2", "host4"};
+
+            // The extension service URL mapping leverages the HBase master config properties
for convenience
+            final String HBASE_MASTER_PORT_PROPERTY = "hbase.master.info.port";
+
+            AmbariComponent hbaseMaster = EasyMock.createNiceMock(AmbariComponent.class);
+            Map<String, String> hbaseMasterConfig = new HashMap<>();
+            hbaseMasterConfig.put(HBASE_MASTER_PORT_PROPERTY, "60080");
+            EasyMock.expect(hbaseMaster.getConfigProperties()).andReturn(hbaseMasterConfig).anyTimes();
+            EasyMock.expect(hbaseMaster.getConfigProperty(HBASE_MASTER_PORT_PROPERTY))
+                .andReturn(hbaseMasterConfig.get(HBASE_MASTER_PORT_PROPERTY)).anyTimes();
+            List<String> hbaseMasterHosts = Arrays.asList(HOSTNAMES);
+            EasyMock.expect(hbaseMaster.getHostNames()).andReturn(hbaseMasterHosts).anyTimes();
+            EasyMock.replay(hbaseMaster);
+
+            AmbariCluster cluster = EasyMock.createNiceMock(AmbariCluster.class);
+            EasyMock.expect(cluster.getComponent("HBASE_MASTER")).andReturn(hbaseMaster).anyTimes();
+            EasyMock.replay(cluster);
+
+            // Run the test
+            AmbariDynamicServiceURLCreator builder = newURLCreator(cluster, null);
+            List<String> urls = builder.create("DISCOVERYTEST", null);
+            validateServiceURLs(urls, HOSTNAMES, "http", "1234", "discoveryTest");
+        } finally {
+            System.clearProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY);
+            FileUtils.deleteQuietly(tmpFile);
+        }
+    }
+
 
     /**
      * Convenience method for creating AmbariDynamicServiceURLCreator instances from different
mapping configuration
@@ -1415,18 +1469,32 @@ public class AmbariDynamicServiceURLCreatorTest {
             "</service-discovery-url-mappings>\n";
 
 
-    private static final String OVERRIDE_MAPPING_FILE_CONTENTS =
+    private static final String OOZIE_OVERRIDE_MAPPING_FILE_CONTENTS =
             "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
             "<service-discovery-url-mappings>\n" +
-            "  <service name=\"WEBHDFS\">\n" +
-            "    <url-pattern>http://{WEBHDFS_ADDRESS}/webhdfs/OVERRIDE</url-pattern>\n"
+
+            "  <service name=\"OOZIE\">\n" +
+            "    <url-pattern>{OOZIE_URL}/OVERRIDE</url-pattern>\n" +
             "    <properties>\n" +
-            "      <property name=\"WEBHDFS_ADDRESS\">\n" +
-            "        <service-config name=\"HDFS\">hdfs-site</service-config>\n"
+
-            "        <config-property>dfs.namenode.http-address</config-property>\n"
+
+            "      <property name=\"OOZIE_URL\">\n" +
+            "        <component>OOZIE_SERVER</component>\n" +
+            "        <config-property>oozie.base.url</config-property>\n" +
             "      </property>\n" +
             "    </properties>\n" +
             "  </service>\n" +
             "</service-discovery-url-mappings>\n";
 
+    private static final String CUSTOM_AUGMENT_MAPPING_FILE_CONTENTS =
+            "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+            "<service-discovery-url-mappings>\n" +
+            "  <service name=\"DISCOVERYTEST\">\n" +
+            "    <url-pattern>http://{HOST}:1234/discoveryTest</url-pattern>\n"
+
+            "    <properties>\n" +
+            "      <property name=\"HOST\">\n" +
+            "        <component>HBASE_MASTER</component>\n" +
+            "        <hostname/>\n" +
+            "      </property>\n" +
+            "    </properties>\n" +
+            "  </service>\n" +
+            "</service-discovery-url-mappings>\n";
 }
+

http://git-wip-us.apache.org/repos/asf/knox/blob/c7da8f6b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
index 05fc4eb..c93e8cf 100644
--- a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
+++ b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
@@ -18,14 +18,18 @@ package org.apache.knox.gateway.topology.discovery.ambari;
 
 import net.minidev.json.JSONObject;
 import net.minidev.json.JSONValue;
+import org.apache.commons.io.FileUtils;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertEquals;
@@ -85,6 +89,73 @@ public class AmbariServiceDiscoveryTest {
     }
 
 
+    @Test
+    public void testClusterDiscoveryWithExternalComponentConfigAugmentation() throws Exception
{
+        final String discoveryAddress = "http://ambarihost:8080";
+        final String clusterName = "myCluster";
+
+        // Create component config mapping override
+        Properties compConfOverrideProps = new Properties();
+        compConfOverrideProps.setProperty("DISCOVERY_TEST", "test-site");
+        File compConfOverrides = File.createTempFile(getClass().getName()+"component-conf-overrides",
".properties");
+        compConfOverrideProps.store(new FileOutputStream(compConfOverrides), "Test Config
Overrides");
+        System.setProperty(AmbariServiceDiscovery.COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY,
+                           compConfOverrides.getAbsolutePath());
+
+        // Create URL mapping override
+        final String URL_MAPPING_OVERRIDES =
+                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+                "<service-discovery-url-mappings>\n" +
+                "  <service name=\"DISCOVERYTEST\">\n" +
+                "    <url-pattern>{TEST_ADDRESS}/discoveryTest</url-pattern>\n"
+
+                "    <properties>\n" +
+                "      <property name=\"TEST_ADDRESS\">\n" +
+                "        <component>DISCOVERY_TEST</component>\n" +
+                "        <config-property>discovery.test.base.url</config-property>\n"
+
+                "      </property>\n" +
+                "    </properties>\n" +
+                "  </service>\n" +
+                "</service-discovery-url-mappings>\n";
+
+        File urlMappingOverrides = File.createTempFile(getClass().getName()+"_url-overrides",
".xml");
+        FileUtils.writeStringToFile(urlMappingOverrides,
+                                    URL_MAPPING_OVERRIDES,
+                                    java.nio.charset.Charset.forName("utf-8"));
+        System.setProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY,
+                           urlMappingOverrides.getAbsolutePath());
+
+        // Re-initialize the component config mappings to include the extension
+        AmbariServiceDiscovery.initializeComponentConfigMappings();
+
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
+
+        ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+        EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
+        EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+        EasyMock.replay(sdc);
+
+        try {
+            ServiceDiscovery.Cluster cluster = sd.discover(sdc, clusterName);
+            assertNotNull(cluster);
+            assertEquals(clusterName, cluster.getName());
+            assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
+            assertEquals(7, ((AmbariCluster) cluster).getComponents().size());
+
+            List<String> discTestURLs = cluster.getServiceURLs("DISCOVERYTEST");
+            assertNotNull(discTestURLs);
+            assertEquals(1, discTestURLs.size());
+            assertEquals("http://c6402.ambari.apache.org:11999/discoveryTest", discTestURLs.get(0));
+        } finally {
+            System.clearProperty(AmbariDynamicServiceURLCreator.MAPPING_CONFIG_OVERRIDE_PROPERTY);
+            System.clearProperty(AmbariServiceDiscovery.COMPONENT_CONFIG_MAPPING_SYSTEM_PROPERTY);
+            FileUtils.deleteQuietly(compConfOverrides);
+
+            // Re-initialize the component config mappings without the extension
+            AmbariServiceDiscovery.initializeComponentConfigMappings();
+        }
+    }
+
+
     private static void printServiceURLs(ServiceDiscovery.Cluster cluster) {
         final String[] services = new String[]{"NAMENODE",
                                                "JOBTRACKER",
@@ -478,6 +549,36 @@ public class AmbariServiceDiscoveryTest {
     "      ]\n" +
     "    },\n" +
     "    {\n" +
+    "      \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/services/DISCOVERYTEST\",\n"
+
+    "      \"ServiceInfo\" : {\n" +
+    "        \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
+    "        \"service_name\" : \"DISCOVERYTEST\"\n" +
+    "      },\n" +
+    "      \"components\" : [\n" +
+    "        {\n" +
+    "          \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/services/DISCOVERYTEST/components/DISCOVERY_TEST\",\n"
+
+    "          \"ServiceComponentInfo\" : {\n" +
+    "            \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
+    "            \"component_name\" : \"DISCOVERY_TEST\",\n" +
+    "            \"service_name\" : \"DISCOVERYTEST\"\n" +
+    "          },\n" +
+    "          \"host_components\" : [\n" +
+    "            {\n" +
+    "              \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/hosts/c6402.ambari.apache.org/host_components/DISCOVERY_TEST\",\n"
+
+    "              \"HostRoles\" : {\n" +
+    "                \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
+    "                \"component_name\" : \"DISCOVERY_TEST\",\n" +
+    "                \"host_name\" : \"c6402.ambari.apache.org\",\n" +
+    "                \"public_host_name\" : \"c6402.ambari.apache.org\",\n" +
+    "                \"service_name\" : \"DISCOVERYTEST\",\n" +
+    "                \"stack_id\" : \"HDP-2.6\"\n" +
+    "              }\n" +
+    "            }\n" +
+    "          ]\n" +
+    "        }\n" +
+    "      ]\n" +
+    "    },\n" +
+    "    {\n" +
     "      \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/services/ZOOKEEPER\",\n"
+
     "      \"ServiceInfo\" : {\n" +
     "        \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
@@ -796,6 +897,30 @@ public class AmbariServiceDiscoveryTest {
     "      \"user\" : \"admin\"\n" +
     "    },\n" +
     "    {\n" +
+    "      \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/configurations/service_config_versions?service_name=DISCOVERYTEST&service_config_version=3\",\n"
+
+    "      \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
+    "      \"configurations\" : [\n" +
+    "        {\n" +
+    "          \"Config\" : {\n" +
+    "            \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
+    "            \"stack_id\" : \"HDP-2.6\"\n" +
+    "          },\n" +
+    "          \"type\" : \"test-site\",\n" +
+    "          \"tag\" : \"version1502131137103\",\n" +
+    "          \"version\" : 3,\n" +
+    "          \"properties\" : {\n" +
+    "            \"discovery.test.base.url\" : \"http://c6402.ambari.apache.org:11999\",\n"
+
+    "          },\n" +
+    "          \"properties_attributes\" : { }\n" +
+    "        }\n" +
+    "      ],\n" +
+    "      \"is_current\" : true,\n" +
+    "      \"service_config_version\" : 3,\n" +
+    "      \"service_name\" : \"DISCOVERYTEST\",\n" +
+    "      \"stack_id\" : \"HDP-2.6\",\n" +
+    "      \"user\" : \"admin\"\n" +
+    "    },\n" +
+    "    {\n" +
     "      \"href\" : \"http://c6401.ambari.apache.org:8080/api/v1/clusters/"+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"/configurations/service_config_versions?service_name=TEZ&service_config_version=1\",\n"
+
     "      \"cluster_name\" : \""+TestAmbariServiceDiscovery.CLUSTER_PLACEHOLDER+"\",\n"
+
     "      \"configurations\" : [\n" +
@@ -867,4 +992,5 @@ public class AmbariServiceDiscoveryTest {
     "  ]\n" +
     "}";
 
+
 }


Mime
View raw message