Addendum fix for: YARN-7269. Tracking URL in the app state does not get redirected to ApplicationMaster for Running applications. (Wangda Tan)

Change-Id: If1fe4a62e07b25e6f1b8ba803495da87e2cb2df6
(cherry picked from commit 87ea1dff9c)
This commit is contained in:
Wangda Tan 2017-10-14 10:41:58 -07:00
parent f2350f5120
commit 64170eb53c
2 changed files with 14 additions and 10 deletions

View File

@ -62,16 +62,20 @@ public class AmFilterInitializer extends FilterInitializer {
container.addFilter(FILTER_NAME, FILTER_CLASS, params); container.addFilter(FILTER_NAME, FILTER_CLASS, params);
// Handle RM HA urls // Handle RM HA urls
List<String> urls = new ArrayList<>();
// Include yarn-site.xml in the classpath // Include yarn-site.xml in the classpath
YarnConfiguration yarnConf = new YarnConfiguration(conf); YarnConfiguration yarnConf = new YarnConfiguration(conf);
for (String rmId : getRmIds(yarnConf)) { Collection<String> rmIds = getRmIds(yarnConf);
if (rmIds != null) {
List<String> urls = new ArrayList<>();
for (String rmId : rmIds) {
String url = getUrlByRmId(yarnConf, rmId); String url = getUrlByRmId(yarnConf, rmId);
urls.add(url); urls.add(url);
} }
if (!urls.isEmpty()) {
params.put(RM_HA_URLS, StringUtils.join(",", urls)); params.put(RM_HA_URLS, StringUtils.join(",", urls));
} }
}
}
private Collection<String> getRmIds(Configuration conf) { private Collection<String> getRmIds(Configuration conf) {
return conf.getStringCollection(YarnConfiguration.RM_HA_IDS); return conf.getStringCollection(YarnConfiguration.RM_HA_IDS);

View File

@ -53,11 +53,11 @@ public class TestAmFilterInitializer extends TestCase {
AmFilterInitializer afi = new MockAmFilterInitializer(); AmFilterInitializer afi = new MockAmFilterInitializer();
assertNull(con.givenParameters); assertNull(con.givenParameters);
afi.initFilter(con, conf); afi.initFilter(con, conf);
assertEquals(3, con.givenParameters.size()); assertEquals(2, con.givenParameters.size());
assertEquals("host1", con.givenParameters.get(AmIpFilter.PROXY_HOSTS)); assertEquals("host1", con.givenParameters.get(AmIpFilter.PROXY_HOSTS));
assertEquals("http://host1:1000/foo", assertEquals("http://host1:1000/foo",
con.givenParameters.get(AmIpFilter.PROXY_URI_BASES)); con.givenParameters.get(AmIpFilter.PROXY_URI_BASES));
assertEquals("", con.givenParameters.get(AmFilterInitializer.RM_HA_URLS)); assertEquals(null, con.givenParameters.get(AmFilterInitializer.RM_HA_URLS));
// Check a single RM_WEBAPP_ADDRESS // Check a single RM_WEBAPP_ADDRESS
con = new MockFilterContainer(); con = new MockFilterContainer();
@ -66,11 +66,11 @@ public class TestAmFilterInitializer extends TestCase {
afi = new MockAmFilterInitializer(); afi = new MockAmFilterInitializer();
assertNull(con.givenParameters); assertNull(con.givenParameters);
afi.initFilter(con, conf); afi.initFilter(con, conf);
assertEquals(3, con.givenParameters.size()); assertEquals(2, con.givenParameters.size());
assertEquals("host2", con.givenParameters.get(AmIpFilter.PROXY_HOSTS)); assertEquals("host2", con.givenParameters.get(AmIpFilter.PROXY_HOSTS));
assertEquals("http://host2:2000/foo", assertEquals("http://host2:2000/foo",
con.givenParameters.get(AmIpFilter.PROXY_URI_BASES)); con.givenParameters.get(AmIpFilter.PROXY_URI_BASES));
assertEquals("", con.givenParameters.get(AmFilterInitializer.RM_HA_URLS)); assertEquals(null, con.givenParameters.get(AmFilterInitializer.RM_HA_URLS));
// Check multiple RM_WEBAPP_ADDRESSes (RM HA) // Check multiple RM_WEBAPP_ADDRESSes (RM HA)
con = new MockFilterContainer(); con = new MockFilterContainer();