Repository: knox
Updated Branches:
  refs/heads/master 2df459905 -> 689d9bfd6


KNOX-1182 - For YARN HA, RESOURCEMANAGER service should have both active and 
standby endpoint URLs


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

Branch: refs/heads/master
Commit: 689d9bfd69de4afb544f76a97967ce0f4726a0dd
Parents: 2df4599
Author: Phil Zampino <pzamp...@apache.org>
Authored: Mon Apr 9 16:50:45 2018 -0400
Committer: Phil Zampino <pzamp...@apache.org>
Committed: Mon Apr 9 16:50:45 2018 -0400

----------------------------------------------------------------------
 .../ambari/AmbariDynamicServiceURLCreator.java  |  30 +++--
 .../discovery/ambari/HDFSURLCreatorBase.java    |   5 +-
 .../discovery/ambari/HdfsUIUrlCreator.java      |   6 +-
 .../discovery/ambari/NameNodeUrlCreator.java    |   7 +-
 .../ambari/ResourceManagerURLCreator.java       |  34 ++++++
 .../ambari/ResourceManagerURLCreatorBase.java   | 112 +++++++++++++++++++
 .../discovery/ambari/ServiceURLCreator.java     |  14 +++
 .../discovery/ambari/ServiceURLFactory.java     |  14 ++-
 .../discovery/ambari/WebHdfsUrlCreator.java     |   6 +-
 .../discovery/ambari/YarnUIURLCreator.java      |  34 ++++++
 .../discovery/ambari/YarnUIV2URLCreator.java    |  29 +++++
 ....topology.discovery.ambari.ServiceURLCreator |  24 ++++
 .../discovery/ambari/RMURLCreatorTestBase.java  | 102 +++++++++++++++++
 .../ambari/ResourceManagerURLCreatorTest.java   |  83 ++++++++++++++
 .../discovery/ambari/YarnUIURLCreatorTest.java  |  86 ++++++++++++++
 .../ambari/YarnUIV2URLCreatorTest.java          |  35 ++++++
 16 files changed, 599 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/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 9263896..5f1e8a4 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
@@ -41,7 +41,27 @@ class AmbariDynamicServiceURLCreator implements 
ServiceURLCreator {
     private AmbariCluster cluster = null;
     private ServiceURLPropertyConfig config;
 
+    AmbariDynamicServiceURLCreator() {
+    }
+
     AmbariDynamicServiceURLCreator(AmbariCluster cluster) {
+        this();
+        init(cluster);
+    }
+
+    AmbariDynamicServiceURLCreator(AmbariCluster cluster, File 
mappingConfiguration) throws IOException {
+        this.cluster = cluster;
+        config = new ServiceURLPropertyConfig(new 
FileInputStream(mappingConfiguration));
+    }
+
+    AmbariDynamicServiceURLCreator(AmbariCluster cluster, String mappings) {
+        this.cluster = cluster;
+        config = new ServiceURLPropertyConfig(new 
ByteArrayInputStream(mappings.getBytes()));
+    }
+
+
+    @Override
+    public void init(AmbariCluster cluster) {
         this.cluster = cluster;
 
         // Load the default internal configuration
@@ -79,14 +99,10 @@ class AmbariDynamicServiceURLCreator implements 
ServiceURLCreator {
         }
     }
 
-    AmbariDynamicServiceURLCreator(AmbariCluster cluster, File 
mappingConfiguration) throws IOException {
-        this.cluster = cluster;
-        config = new ServiceURLPropertyConfig(new 
FileInputStream(mappingConfiguration));
-    }
 
-    AmbariDynamicServiceURLCreator(AmbariCluster cluster, String mappings) {
-        this.cluster = cluster;
-        config = new ServiceURLPropertyConfig(new 
ByteArrayInputStream(mappings.getBytes()));
+    @Override
+    public String getTargetService() {
+        return null;
     }
 
     public List<String> create(String serviceName, Map<String, String> 
serviceParams) {

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java
index 59d8d7f..c6142df 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java
@@ -34,7 +34,7 @@ public abstract class HDFSURLCreatorBase implements 
ServiceURLCreator {
   private AmbariCluster cluster = null;
 
 
-  HDFSURLCreatorBase(AmbariCluster cluster) {
+  public void init(AmbariCluster cluster) {
     this.cluster = cluster;
   }
 
@@ -145,9 +145,6 @@ public abstract class HDFSURLCreatorBase implements 
ServiceURLCreator {
   }
 
 
-  protected abstract String getTargetService();
-
-
   protected abstract String createURL(String address);
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HdfsUIUrlCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HdfsUIUrlCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HdfsUIUrlCreator.java
index 10d7ede..24a1f28 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HdfsUIUrlCreator.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HdfsUIUrlCreator.java
@@ -24,12 +24,12 @@ public class HdfsUIUrlCreator extends HDFSURLCreatorBase {
   private static final String SERVICE = "HDFSUI";
 
 
-  HdfsUIUrlCreator(AmbariCluster cluster) {
-    super(cluster);
+  public void init(AmbariCluster cluster) {
+    super.init(cluster);
   }
 
   @Override
-  protected String getTargetService() {
+  public String getTargetService() {
     return SERVICE;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NameNodeUrlCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NameNodeUrlCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NameNodeUrlCreator.java
index e387b67..478d12f 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NameNodeUrlCreator.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/NameNodeUrlCreator.java
@@ -33,11 +33,16 @@ public class NameNodeUrlCreator implements 
ServiceURLCreator {
 
   private AmbariCluster cluster = null;
 
-  NameNodeUrlCreator(AmbariCluster cluster) {
+  public void init(AmbariCluster cluster) {
     this.cluster = cluster;
   }
 
   @Override
+  public String getTargetService() {
+    return SERVICE;
+  }
+
+  @Override
   public List<String> create(String service, Map<String, String> 
serviceParams) {
     List<String> urls = new ArrayList<>();
 

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreator.java
new file mode 100644
index 0000000..3a5ae2f
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreator.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+public class ResourceManagerURLCreator extends ResourceManagerURLCreatorBase {
+
+  private static final String SERVICE = "RESOURCEMANAGER";
+
+
+  @Override
+  public String getTargetService() {
+    return SERVICE;
+  }
+
+  @Override
+  protected String createURL(String address) {
+    return getURLScheme() + "://" + address + "/ws";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorBase.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorBase.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorBase.java
new file mode 100644
index 0000000..e405f47
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorBase.java
@@ -0,0 +1,112 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public abstract class ResourceManagerURLCreatorBase implements 
ServiceURLCreator {
+
+  static final String CONFIG_SERVICE = "YARN";
+  static final String CONFIG_TYPE    = "yarn-site";
+
+  static final String WEBAPP_ADDRESS_HTTP  = 
"yarn.resourcemanager.webapp.address";
+  static final String WEBAPP_ADDRESS_HTTPS = 
"yarn.resourcemanager.webapp.https.address";
+
+  static final String SCHEME_HTTP  = "http";
+  static final String SCHEME_HTTPS = "https";
+
+  protected AmbariServiceDiscoveryMessages log = 
MessagesFactory.get(AmbariServiceDiscoveryMessages.class);
+
+  private AmbariCluster cluster = null;
+
+
+  public void init(AmbariCluster cluster) {
+    this.cluster = cluster;
+  }
+
+  @Override
+  public List<String> create(String service, Map<String, String> 
serviceParams) {
+    List<String> urls = new ArrayList<>();
+
+    if (getTargetService().equals(service)) {
+      AmbariCluster.ServiceConfiguration sc = 
cluster.getServiceConfiguration(CONFIG_SERVICE, CONFIG_TYPE);
+      if (sc != null) {
+        Map<String, String> configProps = sc.getProperties();
+
+        String httpPolicy = getHttpPolicy(configProps);
+
+        // First, check if it's HA config
+        boolean isHAEnabled = 
Boolean.parseBoolean(configProps.get("yarn.resourcemanager.ha.enabled"));
+        if (isHAEnabled) {
+          String rmSet = configProps.get("yarn.resourcemanager.ha.rm-ids");
+          if (rmSet != null) {
+            String[] rmIds = rmSet.split(",");
+            for (String rmId : rmIds) {
+              String address = 
configProps.get(getWebAppAddressPropertyName(httpPolicy) + "." + rmId.trim());
+              if (address != null && !address.isEmpty()) {
+                urls.add(createURL(address));
+              }
+            }
+          }
+        }
+
+        // If no HA URLs were identified, then add the default webapp address 
URL
+        if (urls.isEmpty()) {
+          
urls.add(createURL(configProps.get(getWebAppAddressPropertyName(httpPolicy))));
+        }
+
+      }
+    }
+
+    return urls;
+  }
+
+
+  protected abstract String createURL(String address);
+
+
+  String getURLScheme() {
+    return isHttps(getHttpPolicy()) ? SCHEME_HTTPS : SCHEME_HTTP;
+  }
+
+
+  private String getHttpPolicy() {
+    String httpPolicy = null;
+    AmbariCluster.ServiceConfiguration sc = 
cluster.getServiceConfiguration(CONFIG_SERVICE, CONFIG_TYPE);
+    if (sc != null) {
+      httpPolicy = getHttpPolicy(sc.getProperties());
+    }
+    return httpPolicy;
+  }
+
+  private String getHttpPolicy(Map<String, String> configProps) {
+      return configProps.get("yarn.http.policy");
+  }
+
+  private boolean isHttps(String httpPolicy) {
+    return "HTTPS_ONLY".equalsIgnoreCase(httpPolicy);
+  }
+
+  private String getWebAppAddressPropertyName(String httpPolicy) {
+    return isHttps(httpPolicy) ? WEBAPP_ADDRESS_HTTPS : WEBAPP_ADDRESS_HTTP;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLCreator.java
index 2984b44..199aa16 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLCreator.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLCreator.java
@@ -22,6 +22,20 @@ import java.util.Map;
 public interface ServiceURLCreator {
 
   /**
+   *
+   * @return The name of the service for which the implementation is able to 
create URLs.
+   */
+  String getTargetService();
+
+
+  /**
+   *
+   * @param cluster the cluster from which the service URLs will be derived.
+   */
+  void init(AmbariCluster cluster);
+
+
+  /**
    * Creates one or more cluster-specific URLs for the specified service.
    *
    * @param service       The service identifier.

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLFactory.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLFactory.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLFactory.java
index e976022..a05f06b 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLFactory.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/ServiceURLFactory.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 
 /**
  * Factory for creating cluster-specific service URLs.
@@ -35,10 +36,15 @@ public class ServiceURLFactory {
     // Default URL creator
     defaultURLCreator = new AmbariDynamicServiceURLCreator(cluster);
 
-    // Custom (internal) URL creators
-    urlCreators.put("NAMENODE", new NameNodeUrlCreator(cluster));
-    urlCreators.put("WEBHDFS", new WebHdfsUrlCreator(cluster));
-    urlCreators.put("HDFSUI", new HdfsUIUrlCreator(cluster));
+    // Custom URL creators (too complex for simple mapping configuration)
+    ServiceLoader<ServiceURLCreator> creators = 
ServiceLoader.load(ServiceURLCreator.class);
+    for (ServiceURLCreator creator : creators) {
+      String type = creator.getTargetService();
+      if (type != null && !type.isEmpty()) {
+        creator.init(cluster);
+        urlCreators.put(creator.getTargetService(), creator);
+      }
+    }
   }
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/WebHdfsUrlCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/WebHdfsUrlCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/WebHdfsUrlCreator.java
index d17e87e..bceb116 100644
--- 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/WebHdfsUrlCreator.java
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/WebHdfsUrlCreator.java
@@ -24,12 +24,12 @@ public class WebHdfsUrlCreator extends HDFSURLCreatorBase {
   private static final String SERVICE = "WEBHDFS";
 
 
-  WebHdfsUrlCreator(AmbariCluster cluster) {
-    super(cluster);
+  public void init(AmbariCluster cluster) {
+    super.init(cluster);
   }
 
   @Override
-  protected String getTargetService() {
+  public String getTargetService() {
     return SERVICE;
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreator.java
new file mode 100644
index 0000000..d9b0665
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreator.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+public class YarnUIURLCreator extends ResourceManagerURLCreatorBase {
+
+  private static final String SERVICE = "YARNUI";
+
+
+  @Override
+  public String getTargetService() {
+    return SERVICE;
+  }
+
+  @Override
+  protected String createURL(String address) {
+    return getURLScheme() + "://" + address;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreator.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreator.java
 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreator.java
new file mode 100644
index 0000000..b6b6b93
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreator.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+public class YarnUIV2URLCreator extends YarnUIURLCreator {
+
+  private static final String SERVICE = "YARNUIV2";
+
+
+  @Override
+  public String getTargetService() {
+    return SERVICE;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
 
b/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
new file mode 100644
index 0000000..a6e2a7e
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/main/resources/META-INF/services/org.apache.knox.gateway.topology.discovery.ambari.ServiceURLCreator
@@ -0,0 +1,24 @@
+##########################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##########################################################################
+
+org.apache.knox.gateway.topology.discovery.ambari.NameNodeUrlCreator
+org.apache.knox.gateway.topology.discovery.ambari.WebHdfsUrlCreator
+org.apache.knox.gateway.topology.discovery.ambari.HdfsUIUrlCreator
+org.apache.knox.gateway.topology.discovery.ambari.ResourceManagerURLCreator
+org.apache.knox.gateway.topology.discovery.ambari.YarnUIURLCreator
+org.apache.knox.gateway.topology.discovery.ambari.YarnUIV2URLCreator
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/RMURLCreatorTestBase.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/RMURLCreatorTestBase.java
 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/RMURLCreatorTestBase.java
new file mode 100644
index 0000000..b3f2af2
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/RMURLCreatorTestBase.java
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+import org.easymock.EasyMock;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+abstract class RMURLCreatorTestBase {
+
+  abstract String getTargetService();
+
+
+  abstract ServiceURLCreator getServiceURLCreator(AmbariCluster cluster);
+
+
+  String doTestCreateSingleURL(final String httpPolicy, final String 
httpAddress, final String httpsAddress) {
+    AmbariCluster.ServiceConfiguration rmSvcConfig = 
EasyMock.createNiceMock(AmbariCluster.ServiceConfiguration.class);
+
+    Map<String, String> configProps = new HashMap<>();
+    configProps.put("yarn.http.policy", httpPolicy);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTP, 
httpAddress);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTPS, 
httpsAddress);
+
+    
EasyMock.expect(rmSvcConfig.getProperties()).andReturn(configProps).anyTimes();
+    EasyMock.replay(rmSvcConfig);
+
+    AmbariCluster cluster = EasyMock.createNiceMock(AmbariCluster.class);
+    
EasyMock.expect(cluster.getServiceConfiguration(ResourceManagerURLCreatorBase.CONFIG_SERVICE,
+                                                    
ResourceManagerURLCreatorBase.CONFIG_TYPE))
+            .andReturn(rmSvcConfig)
+            .anyTimes();
+    EasyMock.replay(cluster);
+
+    List<String> urls = doTestCreateURLs(cluster);
+    assertEquals(1, urls.size());
+    return urls.get(0);
+  }
+
+
+  List<String> doTestCreateHAURLs(final String httpPolicy,
+                                          final String activeHttpAddress,
+                                          final String stdbyHttpAddress,
+                                          final String activeHttpsAddress,
+                                          final String stdbyHttpsAddress) {
+    AmbariCluster.ServiceConfiguration rmSvcConfig = 
EasyMock.createNiceMock(AmbariCluster.ServiceConfiguration.class);
+
+    Map<String, String> configProps = new HashMap<>();
+    configProps.put("yarn.http.policy", httpPolicy);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTP, 
activeHttpAddress);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTPS, 
activeHttpsAddress);
+    configProps.put("yarn.resourcemanager.ha.enabled", "true");
+    configProps.put("yarn.resourcemanager.ha.rm-ids", "rmOne,rm2");
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTP  + 
".rmOne", activeHttpAddress);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTP  + 
".rm2",   stdbyHttpAddress);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTPS + 
".rmOne", stdbyHttpsAddress);
+    configProps.put(ResourceManagerURLCreatorBase.WEBAPP_ADDRESS_HTTPS + 
".rm2",   activeHttpsAddress);
+
+    
EasyMock.expect(rmSvcConfig.getProperties()).andReturn(configProps).anyTimes();
+    EasyMock.replay(rmSvcConfig);
+
+    AmbariCluster cluster = EasyMock.createNiceMock(AmbariCluster.class);
+    
EasyMock.expect(cluster.getServiceConfiguration(ResourceManagerURLCreatorBase.CONFIG_SERVICE,
+                                                    
ResourceManagerURLCreatorBase.CONFIG_TYPE))
+            .andReturn(rmSvcConfig)
+            .anyTimes();
+    EasyMock.replay(cluster);
+
+    List<String> urls = doTestCreateURLs(cluster);
+    assertEquals(2, urls.size());
+    return urls;
+  }
+
+
+  private List<String> doTestCreateURLs(AmbariCluster cluster) {
+    ServiceURLCreator rmc = getServiceURLCreator(cluster);
+    List<String> urls = rmc.create(getTargetService(), Collections.emptyMap());
+    assertNotNull(urls);
+    return urls;
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorTest.java
 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorTest.java
new file mode 100644
index 0000000..297b7ab
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/ResourceManagerURLCreatorTest.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ResourceManagerURLCreatorTest extends RMURLCreatorTestBase {
+
+  @Override
+  String getTargetService() {
+    return "RESOURCEMANAGER";
+  }
+
+  @Override
+  ServiceURLCreator getServiceURLCreator(AmbariCluster cluster) {
+    ServiceURLCreator creator = new ResourceManagerURLCreator();
+    creator.init(cluster);
+    return creator;
+  }
+
+  @Test
+  public void testCreateHttpURLs() {
+    final String expectedAddress = "test.host.unsecure:8088";
+    String url = doTestCreateSingleURL("HTTP_ONLY", expectedAddress, 
"test.host.secure:8088");
+    assertEquals(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" + 
expectedAddress + "/ws", url);
+  }
+
+
+  @Test
+  public void testCreateHAHttpURLs() {
+    final String activeHttpAddress = "test.host.unsecure.active:8088";
+    final String stdbyHttpAddress  = "test.host.unsecure.stdby:8088";
+    List<String> urls = doTestCreateHAURLs("HTTP_ONLY",
+                                           activeHttpAddress,
+                                           stdbyHttpAddress,
+                                           "test.host.secure.active:8088",
+                                           "test.host.secure.stdby:8088");
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" 
+ activeHttpAddress + "/ws"));
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" 
+ stdbyHttpAddress + "/ws"));
+  }
+
+
+  @Test
+  public void testCreateHttpsURLs() {
+    final String expectedAddress = "test.host.secure:8088";
+    String url = doTestCreateSingleURL("HTTPS_ONLY", 
"test.host.unsecure:8088", expectedAddress);
+    assertEquals(ResourceManagerURLCreatorBase.SCHEME_HTTPS + "://" + 
expectedAddress + "/ws", url);
+  }
+
+
+  @Test
+  public void testCreateHAHttpsURLs() {
+    final String activeHttpsAddress = "test.host.secure.active:8088";
+    final String stdbyHttpsAddress  = "test.host.secure.stdby:8088";
+    List<String> urls = doTestCreateHAURLs("HTTPS_ONLY",
+                                           "test.host.unsecure.active:8088",
+                                           "test.host.unsecure.stdby:8088",
+                                           stdbyHttpsAddress,
+                                           activeHttpsAddress);
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTPS + 
"://" + activeHttpsAddress + "/ws"));
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTPS + 
"://" + stdbyHttpsAddress + "/ws"));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreatorTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreatorTest.java
 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreatorTest.java
new file mode 100644
index 0000000..15a5c42
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIURLCreatorTest.java
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class YarnUIURLCreatorTest extends RMURLCreatorTestBase {
+
+  @Override
+  String getTargetService() {
+    return "YARNUI";
+  }
+
+
+  @Override
+  ServiceURLCreator getServiceURLCreator(AmbariCluster cluster) {
+    ServiceURLCreator creator = new YarnUIURLCreator();
+    creator.init(cluster);
+    return creator;
+  }
+
+
+  @Test
+  public void testCreateHttpURLs() throws Exception {
+    final String expectedAddress = "test.host.unsecure:8088";
+    String url = doTestCreateSingleURL("HTTP_ONLY", expectedAddress, 
"test.host.secure:8088");
+    assertEquals(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" + 
expectedAddress, url);
+  }
+
+
+  @Test
+  public void testCreateHAHttpURLs() throws Exception {
+    final String activeHttpAddress = "test.host.unsecure.active:8088";
+    final String stdbyHttpAddress  = "test.host.unsecure.stdby:8088";
+    List<String> urls = doTestCreateHAURLs("HTTP_ONLY",
+                                           activeHttpAddress,
+                                           stdbyHttpAddress,
+                                           "test.host.secure.active:8088",
+                                           "test.host.secure.stdby:8088");
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" 
+ activeHttpAddress));
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTP + "://" 
+ stdbyHttpAddress));
+  }
+
+
+  @Test
+  public void testCreateHttpsURLs() throws Exception {
+    final String expectedAddress = "test.host.secure:8088";
+    String url = doTestCreateSingleURL("HTTPS_ONLY", 
"test.host.unsecure:8088", expectedAddress);
+    assertEquals(ResourceManagerURLCreatorBase.SCHEME_HTTPS + "://" + 
expectedAddress, url);
+  }
+
+
+  @Test
+  public void testCreateHAHttpsURLs() throws Exception {
+    final String activeHttpsAddress = "test.host.secure.active:8088";
+    final String stdbyHttpsAddress  = "test.host.secure.stdby:8088";
+    List<String> urls = doTestCreateHAURLs("HTTPS_ONLY",
+                                           "test.host.unsecure.active:8088",
+                                           "test.host.unsecure.stdby:8088",
+                                           stdbyHttpsAddress,
+                                           activeHttpsAddress);
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTPS + 
"://" + activeHttpsAddress));
+    assertTrue(urls.contains(ResourceManagerURLCreatorBase.SCHEME_HTTPS + 
"://" + stdbyHttpsAddress));
+  }
+
+
+}

http://git-wip-us.apache.org/repos/asf/knox/blob/689d9bfd/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
----------------------------------------------------------------------
diff --git 
a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
new file mode 100644
index 0000000..6cf1ef3
--- /dev/null
+++ 
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/YarnUIV2URLCreatorTest.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.knox.gateway.topology.discovery.ambari;
+
+
+public class YarnUIV2URLCreatorTest extends YarnUIURLCreatorTest {
+
+  @Override
+  String getTargetService() {
+    return "YARNUIV2";
+  }
+
+
+  @Override
+  ServiceURLCreator getServiceURLCreator(AmbariCluster cluster) {
+    ServiceURLCreator creator = new YarnUIV2URLCreator();
+    creator.init(cluster);
+    return creator;
+  }
+
+}

Reply via email to