YARN-7434. Router getApps REST invocation fails with multiple RMs. Contributed by Inigo Goiri.

This commit is contained in:
Inigo Goiri 2017-11-02 21:29:34 -07:00
parent e565b5277d
commit 6fc09beac4

View File

@ -682,10 +682,10 @@ public AppsInfo getApps(HttpServletRequest hsr, String stateQuery,
CompletionService<AppsInfo> 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<AppsInfo>() {
@Override
public AppsInfo call() {
@ -744,24 +744,32 @@ private HttpServletRequestWrapper clone(final HttpServletRequest hsr) {
if (hsr == null) {
return null;
}
@SuppressWarnings("unchecked")
final Map<String, String[]> parameterMap =
(Map<String, String[]>) 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) {
public Map<String, String[]> getParameterMap() {
return 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;
}