|
@@ -19,10 +19,7 @@
|
|
|
package org.apache.hadoop.yarn.server.router.webapp;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
@@ -48,11 +45,8 @@ import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.http.JettyUtils;
|
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
import org.apache.hadoop.security.authorize.AuthorizationException;
|
|
|
-import org.apache.hadoop.util.ReflectionUtils;
|
|
|
-import org.apache.hadoop.util.StringUtils;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
-import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWSConsts;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServiceProtocol;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ActivitiesInfo;
|
|
@@ -86,6 +80,7 @@ import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceOptionIn
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.BulkActivitiesInfo;
|
|
|
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo;
|
|
|
import org.apache.hadoop.yarn.server.router.Router;
|
|
|
+import org.apache.hadoop.yarn.server.router.RouterServerUtil;
|
|
|
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
|
|
|
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
|
|
|
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
|
|
@@ -136,30 +131,7 @@ public class RouterWebServices implements RMWebServiceProtocol {
|
|
|
int maxCacheSize =
|
|
|
conf.getInt(YarnConfiguration.ROUTER_PIPELINE_CACHE_MAX_SIZE,
|
|
|
YarnConfiguration.DEFAULT_ROUTER_PIPELINE_CACHE_MAX_SIZE);
|
|
|
- this.userPipelineMap = Collections.synchronizedMap(
|
|
|
- new LRUCacheHashMap<String, RequestInterceptorChainWrapper>(
|
|
|
- maxCacheSize, true));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Returns the comma separated interceptor class names from the configuration.
|
|
|
- *
|
|
|
- * @param conf
|
|
|
- * @return the interceptor class names as an instance of ArrayList
|
|
|
- */
|
|
|
- private List<String> getInterceptorClassNames(Configuration config) {
|
|
|
- String configuredInterceptorClassNames =
|
|
|
- config.get(YarnConfiguration.ROUTER_WEBAPP_INTERCEPTOR_CLASS_PIPELINE,
|
|
|
- YarnConfiguration.DEFAULT_ROUTER_WEBAPP_INTERCEPTOR_CLASS);
|
|
|
-
|
|
|
- List<String> interceptorClassNames = new ArrayList<String>();
|
|
|
- Collection<String> tempList =
|
|
|
- StringUtils.getStringCollection(configuredInterceptorClassNames);
|
|
|
- for (String item : tempList) {
|
|
|
- interceptorClassNames.add(item.trim());
|
|
|
- }
|
|
|
-
|
|
|
- return interceptorClassNames;
|
|
|
+ this.userPipelineMap = Collections.synchronizedMap(new LRUCacheHashMap<>(maxCacheSize, true));
|
|
|
}
|
|
|
|
|
|
private void init() {
|
|
@@ -207,50 +179,16 @@ public class RouterWebServices implements RMWebServiceProtocol {
|
|
|
*/
|
|
|
@VisibleForTesting
|
|
|
protected RESTRequestInterceptor createRequestInterceptorChain() {
|
|
|
-
|
|
|
- List<String> interceptorClassNames = getInterceptorClassNames(conf);
|
|
|
-
|
|
|
- RESTRequestInterceptor pipeline = null;
|
|
|
- RESTRequestInterceptor current = null;
|
|
|
- for (String interceptorClassName : interceptorClassNames) {
|
|
|
- try {
|
|
|
- Class<?> interceptorClass = conf.getClassByName(interceptorClassName);
|
|
|
- if (RESTRequestInterceptor.class.isAssignableFrom(interceptorClass)) {
|
|
|
- RESTRequestInterceptor interceptorInstance =
|
|
|
- (RESTRequestInterceptor) ReflectionUtils
|
|
|
- .newInstance(interceptorClass, conf);
|
|
|
- if (pipeline == null) {
|
|
|
- pipeline = interceptorInstance;
|
|
|
- current = interceptorInstance;
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- current.setNextInterceptor(interceptorInstance);
|
|
|
- current = interceptorInstance;
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new YarnRuntimeException(
|
|
|
- "Class: " + interceptorClassName + " not instance of "
|
|
|
- + RESTRequestInterceptor.class.getCanonicalName());
|
|
|
- }
|
|
|
- } catch (ClassNotFoundException e) {
|
|
|
- throw new YarnRuntimeException(
|
|
|
- "Could not instantiate RESTRequestInterceptor: "
|
|
|
- + interceptorClassName,
|
|
|
- e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (pipeline == null) {
|
|
|
- throw new YarnRuntimeException(
|
|
|
- "RequestInterceptor pipeline is not configured in the system");
|
|
|
- }
|
|
|
- return pipeline;
|
|
|
+ return RouterServerUtil.createRequestInterceptorChain(conf,
|
|
|
+ YarnConfiguration.ROUTER_WEBAPP_INTERCEPTOR_CLASS_PIPELINE,
|
|
|
+ YarnConfiguration.DEFAULT_ROUTER_WEBAPP_INTERCEPTOR_CLASS,
|
|
|
+ RESTRequestInterceptor.class);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Initializes the request interceptor pipeline for the specified user.
|
|
|
*
|
|
|
- * @param user
|
|
|
+ * @param user specified user.
|
|
|
*/
|
|
|
private RequestInterceptorChainWrapper initializePipeline(String user) {
|
|
|
synchronized (this.userPipelineMap) {
|
|
@@ -265,14 +203,14 @@ public class RouterWebServices implements RMWebServiceProtocol {
|
|
|
try {
|
|
|
// We should init the pipeline instance after it is created and then
|
|
|
// add to the map, to ensure thread safe.
|
|
|
- LOG.info("Initializing request processing pipeline for user: {}", user);
|
|
|
+ LOG.info("Initializing request processing pipeline for user: {}.", user);
|
|
|
|
|
|
RESTRequestInterceptor interceptorChain =
|
|
|
this.createRequestInterceptorChain();
|
|
|
interceptorChain.init(user);
|
|
|
chainWrapper.init(interceptorChain);
|
|
|
} catch (Exception e) {
|
|
|
- LOG.error("Init RESTRequestInterceptor error for user: " + user, e);
|
|
|
+ LOG.error("Init RESTRequestInterceptor error for user: {}", user, e);
|
|
|
throw e;
|
|
|
}
|
|
|
|
|
@@ -338,7 +276,7 @@ public class RouterWebServices implements RMWebServiceProtocol {
|
|
|
@GET
|
|
|
@Path(RMWSConsts.CLUSTER_USER_INFO)
|
|
|
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
|
|
|
- MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
|
|
|
+ MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
|
|
|
@Override
|
|
|
public ClusterUserInfo getClusterUserInfo(@Context HttpServletRequest hsr) {
|
|
|
init();
|
|
@@ -834,10 +772,12 @@ public class RouterWebServices implements RMWebServiceProtocol {
|
|
|
@Override
|
|
|
public Response listReservation(
|
|
|
@QueryParam(RMWSConsts.QUEUE) @DefaultValue(DEFAULT_QUEUE) String queue,
|
|
|
- @QueryParam(RMWSConsts.RESERVATION_ID) @DefaultValue(DEFAULT_RESERVATION_ID) String reservationId,
|
|
|
+ @QueryParam(RMWSConsts.RESERVATION_ID)
|
|
|
+ @DefaultValue(DEFAULT_RESERVATION_ID) String reservationId,
|
|
|
@QueryParam(RMWSConsts.START_TIME) @DefaultValue(DEFAULT_START_TIME) long startTime,
|
|
|
@QueryParam(RMWSConsts.END_TIME) @DefaultValue(DEFAULT_END_TIME) long endTime,
|
|
|
- @QueryParam(RMWSConsts.INCLUDE_RESOURCE) @DefaultValue(DEFAULT_INCLUDE_RESOURCE) boolean includeResourceAllocations,
|
|
|
+ @QueryParam(RMWSConsts.INCLUDE_RESOURCE)
|
|
|
+ @DefaultValue(DEFAULT_INCLUDE_RESOURCE) boolean includeResourceAllocations,
|
|
|
@Context HttpServletRequest hsr) throws Exception {
|
|
|
init();
|
|
|
RequestInterceptorChainWrapper pipeline = getInterceptorChain(hsr);
|