From 87ea1dff9c431fb88e064e497b35fc17c65f1d53 Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Sat, 14 Oct 2017 10:41:58 -0700 Subject: [PATCH] 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 --- .../webproxy/amfilter/AmFilterInitializer.java | 16 ++++++++++------ .../amfilter/TestAmFilterInitializer.java | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/amfilter/AmFilterInitializer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/amfilter/AmFilterInitializer.java index fa54c794a7..c3ddc54f3e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/amfilter/AmFilterInitializer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/amfilter/AmFilterInitializer.java @@ -62,15 +62,19 @@ public void initFilter(FilterContainer container, Configuration conf) { container.addFilter(FILTER_NAME, FILTER_CLASS, params); // Handle RM HA urls - List urls = new ArrayList<>(); - // Include yarn-site.xml in the classpath YarnConfiguration yarnConf = new YarnConfiguration(conf); - for (String rmId : getRmIds(yarnConf)) { - String url = getUrlByRmId(yarnConf, rmId); - urls.add(url); + Collection rmIds = getRmIds(yarnConf); + if (rmIds != null) { + List urls = new ArrayList<>(); + for (String rmId : rmIds) { + String url = getUrlByRmId(yarnConf, rmId); + urls.add(url); + } + if (!urls.isEmpty()) { + params.put(RM_HA_URLS, StringUtils.join(",", urls)); + } } - params.put(RM_HA_URLS, StringUtils.join(",", urls)); } private Collection getRmIds(Configuration conf) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java index b621012099..97625ac088 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/amfilter/TestAmFilterInitializer.java @@ -56,11 +56,11 @@ public void testInitFilter() { AmFilterInitializer afi = new MockAmFilterInitializer(); assertNull(con.givenParameters); afi.initFilter(con, conf); - assertEquals(3, con.givenParameters.size()); + assertEquals(2, con.givenParameters.size()); assertEquals("host1", con.givenParameters.get(AmIpFilter.PROXY_HOSTS)); assertEquals("http://host1:1000/foo", 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 con = new MockFilterContainer(); @@ -69,11 +69,11 @@ public void testInitFilter() { afi = new MockAmFilterInitializer(); assertNull(con.givenParameters); afi.initFilter(con, conf); - assertEquals(3, con.givenParameters.size()); + assertEquals(2, con.givenParameters.size()); assertEquals("host2", con.givenParameters.get(AmIpFilter.PROXY_HOSTS)); assertEquals("http://host2:2000/foo", 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) con = new MockFilterContainer();