From 2d8d420f26ef897b19f89139fcd1238283b36de1 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Thu, 2 Nov 2017 21:29:34 -0700 Subject: [PATCH] YARN-7434. Router getApps REST invocation fails with multiple RMs. Contributed by Inigo Goiri. (cherry picked from commit 6e2259264ad9525eeec2a14055d53236711659d7) --- .../webapp/FederationInterceptorREST.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java index 2860d109623..a890ff3a800 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java @@ -684,10 +684,10 @@ public class FederationInterceptorREST extends AbstractRESTRequestInterceptor { CompletionService compSvc = new ExecutorCompletionService<>(this.threadpool); + // HttpServletRequest does not work with ExecutorCompletionService. + // Create a duplicate hsr. + final HttpServletRequest hsrCopy = clone(hsr); for (final SubClusterInfo info : subClustersActive.values()) { - // HttpServletRequest does not work with ExecutorCompletionService. - // Create a duplicate hsr. - final HttpServletRequest hsrCopy = clone(hsr); compSvc.submit(new Callable() { @Override public AppsInfo call() { @@ -746,25 +746,33 @@ public class FederationInterceptorREST extends AbstractRESTRequestInterceptor { if (hsr == null) { return null; } + @SuppressWarnings("unchecked") + final Map parameterMap = + (Map) hsr.getParameterMap(); + final String pathInfo = hsr.getPathInfo(); + final String user = hsr.getRemoteUser(); + final Principal principal = hsr.getUserPrincipal(); + final String mediaType = + RouterWebServiceUtil.getMediaTypeFromHttpServletRequest( + hsr, AppsInfo.class); return new HttpServletRequestWrapper(hsr) { @SuppressWarnings("unchecked") public Map getParameterMap() { - return (Map) hsr.getParameterMap(); + return parameterMap; } public String getPathInfo() { - return hsr.getPathInfo(); + return pathInfo; } public String getRemoteUser() { - return hsr.getRemoteUser(); + return user; } public Principal getUserPrincipal() { - return hsr.getUserPrincipal(); + return principal; } public String getHeader(String value) { // we override only Accept if (value.equals(HttpHeaders.ACCEPT)) { - return RouterWebServiceUtil.getMediaTypeFromHttpServletRequest( - hsr, AppsInfo.class); + return mediaType; } return null; }