MAPREDUCE-6789. Fix TestAMWebApp failure. Contributed by Daniel Templeton.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/272a2174 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/272a2174 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/272a2174 Branch: refs/heads/YARN-2915 Commit: 272a21747e8a89b6daccc19b71c21de3d17b8d62 Parents: 2023254 Author: Akira Ajisaka <aajis...@apache.org> Authored: Thu Oct 6 15:57:15 2016 +0900 Committer: Akira Ajisaka <aajis...@apache.org> Committed: Thu Oct 6 15:57:15 2016 +0900 ---------------------------------------------------------------------- .../mapreduce/v2/app/webapp/TestAMWebApp.java | 8 +-- .../yarn/server/webproxy/ProxyUriUtils.java | 53 ++++++++++++++++---- 2 files changed, 48 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/272a2174/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebApp.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebApp.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebApp.java index acb31bd..21d37c8 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebApp.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-app/src/test/java/org/apache/hadoop/mapreduce/v2/app/webapp/TestAMWebApp.java @@ -247,9 +247,11 @@ public class TestAMWebApp { HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection(); conn.setInstanceFollowRedirects(false); conn.connect(); - String expectedURL = - scheme + conf.get(YarnConfiguration.PROXY_ADDRESS) - + ProxyUriUtils.getPath(app.getAppID(), "/mapreduce"); + + // Because we're not calling from the proxy's address, we'll be redirected + String expectedURL = scheme + conf.get(YarnConfiguration.PROXY_ADDRESS) + + ProxyUriUtils.getPath(app.getAppID(), "/mapreduce", true); + Assert.assertEquals(expectedURL, conn.getHeaderField(HttpHeaders.LOCATION)); Assert.assertEquals(HttpStatus.SC_MOVED_TEMPORARILY, http://git-wip-us.apache.org/repos/asf/hadoop/blob/272a2174/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/ProxyUriUtils.java ---------------------------------------------------------------------- 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/ProxyUriUtils.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/ProxyUriUtils.java index e130225..c656742 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/ProxyUriUtils.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-web-proxy/src/main/java/org/apache/hadoop/yarn/server/webproxy/ProxyUriUtils.java @@ -40,6 +40,8 @@ public class ProxyUriUtils { public static final String PROXY_SERVLET_NAME = "proxy"; /**Base path where the proxy servlet will handle requests.*/ public static final String PROXY_BASE = "/proxy/"; + /**Path component added when the proxy redirects the connection.*/ + public static final String REDIRECT = "redirect/"; /**Path Specification for the proxy servlet.*/ public static final String PROXY_PATH_SPEC = PROXY_BASE+"*"; /**Query Parameter indicating that the URI was approved.*/ @@ -57,27 +59,58 @@ public class ProxyUriUtils { /** * Get the proxied path for an application. - * @param id the application id to use. - * @return the base path to that application through the proxy. + * + * @param id the application id to use + * @return the base path to that application through the proxy */ public static String getPath(ApplicationId id) { - if(id == null) { + return getPath(id, false); + } + + /** + * Get the proxied path for an application. + * + * @param id the application id to use + * @param redirected whether the path should contain the redirect component + * @return the base path to that application through the proxy + */ + public static String getPath(ApplicationId id, boolean redirected) { + if (id == null) { throw new IllegalArgumentException("Application id cannot be null "); } - return ujoin(PROXY_BASE, uriEncode(id)); + + if (redirected) { + return ujoin(PROXY_BASE, REDIRECT, uriEncode(id)); + } else { + return ujoin(PROXY_BASE, uriEncode(id)); + } } /** * Get the proxied path for an application. - * @param id the application id to use. - * @param path the rest of the path to the application. - * @return the base path to that application through the proxy. + * + * @param id the application id to use + * @param path the rest of the path to the application + * @return the base path to that application through the proxy */ public static String getPath(ApplicationId id, String path) { - if(path == null) { - return getPath(id); + return getPath(id, path, false); + } + + /** + * Get the proxied path for an application. + * + * @param id the application id to use + * @param path the rest of the path to the application + * @param redirected whether the path should contain the redirect component + * @return the base path to that application through the proxy + */ + public static String getPath(ApplicationId id, String path, + boolean redirected) { + if (path == null) { + return getPath(id, redirected); } else { - return ujoin(getPath(id), path); + return ujoin(getPath(id, redirected), path); } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org