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/RouterWebServiceUtil.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServiceUtil.java index 6d7dc5f..6e4ca05 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServiceUtil.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServiceUtil.java @@ -42,6 +42,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.security.UserGroupInformation; +import org.apache.hadoop.security.authentication.server.PseudoAuthenticationHandler; import org.apache.hadoop.yarn.api.records.YarnApplicationState; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebAppUtil; @@ -112,6 +113,19 @@ } if (callerUGI == null) { + String authType = conf.get("hadoop.http.authentication.type"); + String allowAnonymous = conf.get("hadoop.http.authentication.simple.anonymous.allowed"); + if (PseudoAuthenticationHandler.TYPE.equalsIgnoreCase(authType)) + { + if (Boolean.parseBoolean(allowAnonymous)) + { + return invokeRMWebService(webApp, hsr, + returnType, method, + targetPath, formParam, + additionalParam, conf, client); + } + } + LOG.error("Unable to obtain user name, user not authenticated"); return null; } @@ -121,44 +135,10 @@ @SuppressWarnings("unchecked") @Override public T run() { - - Map paramMap = null; - - // We can have hsr or additionalParam. There are no case with both. - if (hsr != null) { - paramMap = hsr.getParameterMap(); - } else if (additionalParam != null) { - paramMap = additionalParam; - } - - ClientResponse response = RouterWebServiceUtil - .invokeRMWebService(webApp, targetPath, method, - (hsr == null) ? null : hsr.getPathInfo(), paramMap, formParam, - getMediaTypeFromHttpServletRequest(hsr, returnType), conf, - client); - if (Response.class.equals(returnType)) { - return (T) RouterWebServiceUtil.clientResponseToResponse(response); - } - - try { - // YARN RM can answer with Status.OK or it throws an exception - if (response.getStatus() == SC_OK) { - return response.getEntity(returnType); - } - if (response.getStatus() == SC_NO_CONTENT) { - try { - return returnType.getConstructor().newInstance(); - } catch (RuntimeException | ReflectiveOperationException e) { - LOG.error("Cannot create empty entity for {}", returnType, e); - } - } - RouterWebServiceUtil.retrieveException(response); - return null; - } finally { - if (response != null) { - response.close(); - } - } + return invokeRMWebService(webApp, hsr, + returnType, method, + targetPath, formParam, + additionalParam, conf, client); } }); } catch (InterruptedException e) { @@ -168,6 +148,69 @@ } } + + /** + * Creates and performs a REST call to RM WebService. + * + * @param webApp the address of the remote webap + * @param hsr the servlet request + * @param returnType the return type of the REST call + * @param Type of return object. + * @param method the HTTP method of the REST call + * @param targetPath additional path to add to the webapp address + * @param formParam the form parameters as input for a specific REST call + * @param additionalParam the query parameters as input for a specific REST + * call in case the call has no servlet request + * @param client same client used to reduce number of clients created + * @return the retrieved entity from the REST call + */ + @SuppressWarnings("unchecked") + private static T invokeRMWebService ( + final String webApp, final HttpServletRequest hsr, + final Class returnType, final HTTPMethods method, + final String targetPath, final Object formParam, + final Map additionalParam, Configuration conf, + Client client) + { + Map paramMap = null; + + // We can have hsr or additionalParam. There are no case with both. + if (hsr != null) { + paramMap = hsr.getParameterMap(); + } else if (additionalParam != null) { + paramMap = additionalParam; + } + + ClientResponse response = RouterWebServiceUtil + .invokeRMWebService(webApp, targetPath, method, + (hsr == null) ? null : hsr.getPathInfo(), paramMap, formParam, + getMediaTypeFromHttpServletRequest(hsr, returnType), conf, + client); + if (Response.class.equals(returnType)) { + return (T) RouterWebServiceUtil.clientResponseToResponse(response); + } + + try { + // YARN RM can answer with Status.OK or it throws an exception + if (response.getStatus() == SC_OK) { + return response.getEntity(returnType); + } + if (response.getStatus() == SC_NO_CONTENT) { + try { + return returnType.getConstructor().newInstance(); + } catch (RuntimeException | ReflectiveOperationException e) { + LOG.error("Cannot create empty entity for {}", returnType, e); + } + } + RouterWebServiceUtil.retrieveException(response); + return null; + } finally { + if (response != null) { + response.close(); + } + } + } + /** * Performs an invocation of a REST call on a remote RMWebService. * @param webApp the address of the remote webap