KNOX-1374 - Ranger service discovery should use ranger.externalurl property
authorPhil Zampino <pzampino@apache.org>
Tue, 3 Jul 2018 19:30:57 +0000 (15:30 -0400)
committerPhil Zampino <pzampino@apache.org>
Tue, 3 Jul 2018 19:46:29 +0000 (15:46 -0400)
gateway-discovery-ambari/src/main/resources/ambari-service-discovery-url-mappings.xml
gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariDynamicServiceURLCreatorTest.java

index 1ad7fc5..8165b79 100644 (file)
     </service>
 
     <service name="RANGER">
-        <url-pattern>{SCHEME}://{HOST}:{PORT}</url-pattern>
+        <url-pattern>{RANGER_EXTERNAL_URL}</url-pattern>
         <properties>
-            <property name="HOST">
-                <component>RANGER_ADMIN</component>
-                <hostname/>
-            </property>
-            <property name="SSL">
-                <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.https.attrib.ssl.enabled</config-property>
-            </property>
-            <property name="HTTPS_PORT">
-                <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.https.port</config-property>
-            </property>
-            <property name="HTTP_PORT">
-                <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.http.port</config-property>
-            </property>
-            <property name="SCHEME">
-                <config-property>
-                    <if property="SSL" value="true">
-                        <then>https</then>
-                        <else>http</else>
-                    </if>
-                </config-property>
-            </property>
-            <property name="PORT">
-                <config-property>
-                    <if property="SSL" value="true">
-                        <then>HTTPS_PORT</then>
-                        <else>HTTP_PORT</else>
-                    </if>
-                </config-property>
-            </property>
+          <property name="RANGER_EXTERNAL_URL">
+            <component>RANGER_ADMIN</component>
+            <config-property>ranger.externalurl</config-property>
+          </property>
         </properties>
     </service>
 
     <service name="RANGERUI">
-        <url-pattern>{SCHEME}://{HOST}:{PORT}</url-pattern>
+        <url-pattern>{RANGER_EXTERNAL_URL}</url-pattern>
         <properties>
-            <property name="HOST">
-                <component>RANGER_ADMIN</component>
-                <hostname/>
-            </property>
-            <property name="SSL">
+            <property name="RANGER_EXTERNAL_URL">
                 <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.https.attrib.ssl.enabled</config-property>
-            </property>
-            <property name="HTTPS_PORT">
-                <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.https.port</config-property>
-            </property>
-            <property name="HTTP_PORT">
-                <component>RANGER_ADMIN</component>
-                <config-property>ranger.service.http.port</config-property>
-            </property>
-            <property name="SCHEME">
-                <config-property>
-                    <if property="SSL" value="true">
-                        <then>https</then>
-                        <else>http</else>
-                    </if>
-                </config-property>
-            </property>
-            <property name="PORT">
-                <config-property>
-                    <if property="SSL" value="true">
-                        <then>HTTPS_PORT</then>
-                        <else>HTTP_PORT</else>
-                    </if>
-                </config-property>
+                <config-property>ranger.externalurl</config-property>
             </property>
         </properties>
     </service>
index 2a63535..554fe88 100644 (file)
@@ -902,6 +902,7 @@ public class AmbariDynamicServiceURLCreatorTest {
     private void doTestRangerURLs(String serviceName) throws Exception {
         final String HTTP_PORT = "6080";
         final String HTTPS_PORT = "6182";
+        final String EXT_URL = "http://host2:" + HTTP_PORT;
 
         final String[] HOSTNAMES = {"host1", "host3"};
         final List<String> rangerServerHosts = Arrays.asList(HOSTNAMES);
@@ -911,6 +912,7 @@ public class AmbariDynamicServiceURLCreatorTest {
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.https.attrib.ssl.enabled")).andReturn("false").anyTimes();
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.http.port")).andReturn(HTTP_PORT).anyTimes();
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.https.port")).andReturn(HTTPS_PORT).anyTimes();
+        EasyMock.expect(rangerAdmin.getConfigProperty("ranger.externalurl")).andReturn(EXT_URL).anyTimes();
         EasyMock.replay(rangerAdmin);
 
         AmbariCluster cluster = EasyMock.createNiceMock(AmbariCluster.class);
@@ -920,17 +922,22 @@ public class AmbariDynamicServiceURLCreatorTest {
         AmbariDynamicServiceURLCreator builder = newURLCreator(cluster, null);
 
         // Run the test
-        validateServiceURLs(builder.create(serviceName, null), HOSTNAMES, "http", HTTP_PORT, null);
+        List<String> urls = builder.create(serviceName, null);
+        assertEquals(1, urls.size());
+        assertEquals(EXT_URL, urls.get(0));
 
         EasyMock.reset(rangerAdmin);
         EasyMock.expect(rangerAdmin.getHostNames()).andReturn(rangerServerHosts).anyTimes();
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.https.attrib.ssl.enabled")).andReturn("true").anyTimes();
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.http.port")).andReturn(HTTP_PORT).anyTimes();
         EasyMock.expect(rangerAdmin.getConfigProperty("ranger.service.https.port")).andReturn(HTTPS_PORT).anyTimes();
+        EasyMock.expect(rangerAdmin.getConfigProperty("ranger.externalurl")).andReturn(EXT_URL).anyTimes();
         EasyMock.replay(rangerAdmin);
 
-        // Run the test
-        validateServiceURLs(builder.create(serviceName, null), HOSTNAMES, "https", HTTPS_PORT, null);
+        // Run the test, making sure that the external URL is the result
+        urls = builder.create(serviceName, null);
+        assertEquals(1, urls.size());
+        assertEquals(EXT_URL, urls.get(0));
     }