hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jia...@apache.org
Subject hadoop git commit: YARN-6270. WebUtils.getRMWebAppURLWithScheme() needs to honor RM HA setting. Contributed by Xuan Gong
Date Fri, 03 Mar 2017 23:25:14 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2.8.0 68c78205e -> 58fa75c64


YARN-6270. WebUtils.getRMWebAppURLWithScheme() needs to honor RM HA setting. Contributed by
Xuan Gong


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

Branch: refs/heads/branch-2.8.0
Commit: 58fa75c64c0309bcff0ccdee81c393545e02e29c
Parents: 68c7820
Author: Jian He <jianhe@apache.org>
Authored: Fri Mar 3 15:23:33 2017 -0800
Committer: Jian He <jianhe@apache.org>
Committed: Fri Mar 3 15:25:06 2017 -0800

----------------------------------------------------------------------
 .../hadoop/yarn/webapp/util/WebAppUtils.java    | 43 ++++++++++++++++----
 .../hadoop/yarn/conf/TestYarnConfiguration.java | 16 ++++++++
 2 files changed, 50 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/58fa75c6/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java
index 03588f1..f45465a 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/util/WebAppUtils.java
@@ -87,21 +87,46 @@ public class WebAppUtils {
           hostName + ":" + port);
     }
   }
-  
-  public static String getRMWebAppURLWithScheme(Configuration conf) {
-    return getHttpSchemePrefix(conf) + getRMWebAppURLWithoutScheme(conf);
-  }
-  
-  public static String getRMWebAppURLWithoutScheme(Configuration conf) {
-    if (YarnConfiguration.useHttps(conf)) {
-      return conf.get(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
+
+  public static String getRMWebAppURLWithoutScheme(Configuration conf,
+      boolean isHAEnabled)  {
+    YarnConfiguration yarnConfig = new YarnConfiguration(conf);
+    // set RM_ID if we have not configure it.
+    if (isHAEnabled) {
+      String rmId = yarnConfig.get(YarnConfiguration.RM_HA_ID);
+      if (rmId == null || rmId.isEmpty()) {
+        List<String> rmIds = new ArrayList<>(HAUtil.getRMHAIds(conf));
+        if (rmIds != null && !rmIds.isEmpty()) {
+          yarnConfig.set(YarnConfiguration.RM_HA_ID, rmIds.get(0));
+        }
+      }
+    }
+    if (YarnConfiguration.useHttps(yarnConfig)) {
+      if (isHAEnabled) {
+        return HAUtil.getConfValueForRMInstance(
+            YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS, yarnConfig);
+      }
+      return yarnConfig.get(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
           YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS);
     }else {
-      return conf.get(YarnConfiguration.RM_WEBAPP_ADDRESS,
+      if (isHAEnabled) {
+        return HAUtil.getConfValueForRMInstance(
+            YarnConfiguration.RM_WEBAPP_ADDRESS, yarnConfig);
+      }
+      return yarnConfig.get(YarnConfiguration.RM_WEBAPP_ADDRESS,
           YarnConfiguration.DEFAULT_RM_WEBAPP_ADDRESS);
     }
   }
 
+  public static String getRMWebAppURLWithScheme(Configuration conf) {
+    return getHttpSchemePrefix(conf) + getRMWebAppURLWithoutScheme(
+        conf, HAUtil.isHAEnabled(conf));
+  }
+
+  public static String getRMWebAppURLWithoutScheme(Configuration conf) {
+    return getRMWebAppURLWithoutScheme(conf, false);
+  }
+
   public static List<String> getProxyHostsAndPortsForAmFilter(
       Configuration conf) {
     List<String> addrs = new ArrayList<String>();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/58fa75c6/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfiguration.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfiguration.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfiguration.java
index 2e76865..7389423 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfiguration.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/conf/TestYarnConfiguration.java
@@ -41,6 +41,22 @@ public class TestYarnConfiguration {
     // specifically add slashes and Jetty doesn't handle double slashes.
     Assert.assertNotSame("RM Web Url is not correct", "http://0.0.0.0:8088",
         rmWebUrl);
+
+    // test it in HA scenario
+    conf.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
+    conf.set(YarnConfiguration.RM_HA_IDS, "rm1, rm2");
+    conf.set("yarn.resourcemanager.webapp.address.rm1", "10.10.10.10:18088");
+    conf.set("yarn.resourcemanager.webapp.address.rm2", "20.20.20.20:28088");
+    String rmWebUrlinHA = WebAppUtils.getRMWebAppURLWithScheme(conf);
+    Assert.assertEquals("http://10.10.10.10:18088", rmWebUrlinHA);
+
+    YarnConfiguration conf2 = new YarnConfiguration();
+    conf2.setBoolean(YarnConfiguration.RM_HA_ENABLED, true);
+    conf2.set(YarnConfiguration.RM_HA_IDS, "rm1, rm2");
+    conf2.set("yarn.resourcemanager.hostname.rm1", "30.30.30.30");
+    conf2.set("yarn.resourcemanager.hostname.rm2", "40.40.40.40");
+    String rmWebUrlinHA2 = WebAppUtils.getRMWebAppURLWithScheme(conf2);
+    Assert.assertEquals("http://30.30.30.30:8088", rmWebUrlinHA2);
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message