From 1c49cfbeb7df7ad5466578bd470819bcedc612cf Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Fri, 21 Mar 2014 02:02:41 +0000 Subject: [PATCH] YARN-1859. Fixed WebAppProxyServlet to correctly handle applications absent on the ResourceManager. Contributed by Zhijie Shen. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1579866 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../yarn/server/webproxy/WebAppProxyServlet.java | 8 +++++++- .../server/webproxy/TestWebAppProxyServlet.java | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 279463fc4d..b9e00c1031 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -530,6 +530,9 @@ Release 2.4.0 - UNRELEASED and thus avoid the failure of TestRMFailover#testRMWebAppRedirect. (Zhijie Shen via vinodkv) + YARN-1859. Fixed WebAppProxyServlet to correctly handle applications absent + on the ResourceManager. (Zhijie Shen via vinodkv) + Release 2.3.1 - UNRELEASED INCOMPATIBLE CHANGES 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/WebAppProxyServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java index 25a4dabbee..19ae9dc08d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/WebAppProxyServlet.java @@ -50,6 +50,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.ApplicationReport; import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.util.Apps; import org.apache.hadoop.yarn.util.StringHelper; @@ -274,7 +275,12 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) boolean checkUser = securityEnabled && (!userWasWarned || !userApproved); - ApplicationReport applicationReport = getApplicationReport(id); + ApplicationReport applicationReport = null; + try { + applicationReport = getApplicationReport(id); + } catch (ApplicationNotFoundException e) { + applicationReport = null; + } if(applicationReport == null) { LOG.warn(req.getRemoteUser()+" Attempting to access "+id+ " that was not found"); 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/TestWebAppProxyServlet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java index c53d098f4b..1be0115c13 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/test/java/org/apache/hadoop/yarn/server/webproxy/TestWebAppProxyServlet.java @@ -52,6 +52,7 @@ import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.api.records.impl.pb.ApplicationReportPBImpl; import org.apache.hadoop.yarn.conf.YarnConfiguration; +import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException; import org.apache.hadoop.yarn.exceptions.YarnException; import org.apache.hadoop.yarn.exceptions.YarnRuntimeException; import org.apache.hadoop.yarn.webapp.util.WebAppUtils; @@ -149,11 +150,20 @@ public void testWebAppProxyServlet() throws Exception { assertEquals(HttpURLConnection.HTTP_OK, proxyConn.getResponseCode()); assertTrue(isResponseCookiePresent( proxyConn, "checked_application_0_0000", "true")); - // cannot found application + // cannot found application 1: null appReportFetcher.answer = 1; proxyConn = (HttpURLConnection) url.openConnection(); proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); proxyConn.connect(); + assertEquals(HttpURLConnection.HTTP_NOT_FOUND, + proxyConn.getResponseCode()); + assertFalse(isResponseCookiePresent( + proxyConn, "checked_application_0_0000", "true")); + // cannot found application 2: ApplicationNotFoundException + appReportFetcher.answer = 4; + proxyConn = (HttpURLConnection) url.openConnection(); + proxyConn.setRequestProperty("Cookie", "checked_application_0_0000=true"); + proxyConn.connect(); assertEquals(HttpURLConnection.HTTP_NOT_FOUND, proxyConn.getResponseCode()); assertFalse(isResponseCookiePresent( @@ -340,6 +350,8 @@ public ApplicationReport getApplicationReport(ApplicationId appId) ApplicationReport result = getDefaultApplicationReport(appId); result.setYarnApplicationState(YarnApplicationState.KILLED); return result; + } else if (answer == 4) { + throw new ApplicationNotFoundException("Application is not found"); } return null; }