RouterRMAdminService extends AbstractService implements ResourceManagerAdministrationProtocol { @VisibleForTesting protected RMAdminRequestInterceptor createRequestInterceptorChain() { Configuration conf = getConfig(); List<String> interceptorClassNames = getInterceptorClassNames(conf); RMAdminRequestInterceptor pipeline = null; RMAdminRequestInterceptor current = null; for (String interceptorClassName : interceptorClassNames) { try { Class<?> interceptorClass = conf.getClassByName(interceptorClassName); if (RMAdminRequestInterceptor.class .isAssignableFrom(interceptorClass)) { RMAdminRequestInterceptor interceptorInstance = (RMAdminRequestInterceptor) 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 " + RMAdminRequestInterceptor.class.getCanonicalName()); } } catch (ClassNotFoundException e) { throw new YarnRuntimeException( "Could not instantiate RMAdminRequestInterceptor: " + interceptorClassName, e); } } if (pipeline == null) { throw new YarnRuntimeException( "RequestInterceptor pipeline is not configured in the system"); } return pipeline; } RouterRMAdminService(); @VisibleForTesting Server getServer(); @Override String[] getGroupsForUser(String user); @Override RefreshQueuesResponse refreshQueues(RefreshQueuesRequest request); @Override RefreshNodesResponse refreshNodes(RefreshNodesRequest request); @Override RefreshSuperUserGroupsConfigurationResponse refreshSuperUserGroupsConfiguration(
      RefreshSuperUserGroupsConfigurationRequest request); @Override RefreshUserToGroupsMappingsResponse refreshUserToGroupsMappings(
      RefreshUserToGroupsMappingsRequest request); @Override RefreshAdminAclsResponse refreshAdminAcls(
      RefreshAdminAclsRequest request); @Override RefreshServiceAclsResponse refreshServiceAcls(
      RefreshServiceAclsRequest request); @Override UpdateNodeResourceResponse updateNodeResource(
      UpdateNodeResourceRequest request); @Override RefreshNodesResourcesResponse refreshNodesResources(
      RefreshNodesResourcesRequest request); @Override AddToClusterNodeLabelsResponse addToClusterNodeLabels(
      AddToClusterNodeLabelsRequest request); @Override RemoveFromClusterNodeLabelsResponse removeFromClusterNodeLabels(
      RemoveFromClusterNodeLabelsRequest request); @Override ReplaceLabelsOnNodeResponse replaceLabelsOnNode(
      ReplaceLabelsOnNodeRequest request); @Override CheckForDecommissioningNodesResponse checkForDecommissioningNodes(
      CheckForDecommissioningNodesRequest checkForDecommissioningNodesRequest); @Override RefreshClusterMaxPriorityResponse refreshClusterMaxPriority(
      RefreshClusterMaxPriorityRequest request); @Override NodesToAttributesMappingResponse mapAttributesToNodes(
      NodesToAttributesMappingRequest request);  }
@Test public void testRequestInterceptorChainCreation() throws Exception { RMAdminRequestInterceptor root = super.getRouterRMAdminService().createRequestInterceptorChain(); int index = 0; while (root != null) { switch (index) { case 0: case 1: case 2: Assert.assertEquals( PassThroughRMAdminRequestInterceptor.class.getName(), root.getClass().getName()); break; case 3: Assert.assertEquals(MockRMAdminRequestInterceptor.class.getName(), root.getClass().getName()); break; default: Assert.fail(); } root = root.getNextInterceptor(); index++; } Assert.assertEquals("The number of interceptors in chain does not match", 4, index); }