hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [11/21] hadoop git commit: YARN-6270. WebUtils.getRMWebAppURLWithScheme() needs to honor RM HA setting. Contributed by Xuan Gong
Date Mon, 06 Mar 2017 18:18:31 GMT
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/279d187f
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/279d187f
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/279d187f

Branch: refs/heads/YARN-5734
Commit: 279d187f723d01658ef8698a29263652e2a05618
Parents: 8db7a8c
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:24:04 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/279d187f/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 e412173..64a4b2b 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
@@ -89,21 +89,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/279d187f/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