YARN-6270. WebUtils.getRMWebAppURLWithScheme() needs to honor RM HA setting. Contributed by Xuan Gong
This commit is contained in:
parent
a58dfcb421
commit
712434e744
|
@ -89,21 +89,46 @@ public class WebAppUtils {
|
||||||
hostName + ":" + port);
|
hostName + ":" + port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getRMWebAppURLWithScheme(Configuration conf) {
|
public static String getRMWebAppURLWithoutScheme(Configuration conf,
|
||||||
return getHttpSchemePrefix(conf) + getRMWebAppURLWithoutScheme(conf);
|
boolean isHAEnabled) {
|
||||||
}
|
YarnConfiguration yarnConfig = new YarnConfiguration(conf);
|
||||||
|
// set RM_ID if we have not configure it.
|
||||||
public static String getRMWebAppURLWithoutScheme(Configuration conf) {
|
if (isHAEnabled) {
|
||||||
if (YarnConfiguration.useHttps(conf)) {
|
String rmId = yarnConfig.get(YarnConfiguration.RM_HA_ID);
|
||||||
return conf.get(YarnConfiguration.RM_WEBAPP_HTTPS_ADDRESS,
|
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);
|
YarnConfiguration.DEFAULT_RM_WEBAPP_HTTPS_ADDRESS);
|
||||||
}else {
|
}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);
|
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(
|
public static List<String> getProxyHostsAndPortsForAmFilter(
|
||||||
Configuration conf) {
|
Configuration conf) {
|
||||||
List<String> addrs = new ArrayList<String>();
|
List<String> addrs = new ArrayList<String>();
|
||||||
|
|
|
@ -41,6 +41,22 @@ public class TestYarnConfiguration {
|
||||||
// specifically add slashes and Jetty doesn't handle double slashes.
|
// specifically add slashes and Jetty doesn't handle double slashes.
|
||||||
Assert.assertNotSame("RM Web Url is not correct", "http://0.0.0.0:8088",
|
Assert.assertNotSame("RM Web Url is not correct", "http://0.0.0.0:8088",
|
||||||
rmWebUrl);
|
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
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue