1919package org .apache .hadoop .yarn .server .router .clientrm ;
2020
2121import java .io .IOException ;
22+ import java .lang .reflect .InvocationTargetException ;
2223import java .net .InetSocketAddress ;
2324import java .util .ArrayList ;
2425import java .util .Collection ;
110111import org .apache .hadoop .yarn .exceptions .YarnException ;
111112import org .apache .hadoop .yarn .exceptions .YarnRuntimeException ;
112113import org .apache .hadoop .yarn .ipc .YarnRPC ;
114+ import org .apache .hadoop .yarn .server .router .RouterServerUtil ;
113115import org .apache .hadoop .yarn .server .router .security .authorize .RouterPolicyProvider ;
114116import org .apache .hadoop .yarn .util .LRUCacheHashMap ;
115117import org .slf4j .Logger ;
@@ -147,7 +149,7 @@ public RouterClientRMService() {
147149
148150 @ Override
149151 protected void serviceStart () throws Exception {
150- LOG .info ("Starting Router ClientRMService" );
152+ LOG .info ("Starting Router ClientRMService. " );
151153 Configuration conf = getConfig ();
152154 YarnRPC rpc = YarnRPC .create (conf );
153155 UserGroupInformation .setConfiguration (conf );
@@ -161,9 +163,7 @@ protected void serviceStart() throws Exception {
161163 int maxCacheSize =
162164 conf .getInt (YarnConfiguration .ROUTER_PIPELINE_CACHE_MAX_SIZE ,
163165 YarnConfiguration .DEFAULT_ROUTER_PIPELINE_CACHE_MAX_SIZE );
164- this .userPipelineMap = Collections .synchronizedMap (
165- new LRUCacheHashMap <String , RequestInterceptorChainWrapper >(
166- maxCacheSize , true ));
166+ this .userPipelineMap = Collections .synchronizedMap (new LRUCacheHashMap <>(maxCacheSize , true ));
167167
168168 Configuration serverConf = new Configuration (conf );
169169
@@ -181,14 +181,13 @@ protected void serviceStart() throws Exception {
181181 }
182182
183183 this .server .start ();
184- LOG .info ("Router ClientRMService listening on address: "
185- + this .server .getListenerAddress ());
184+ LOG .info ("Router ClientRMService listening on address: {}." , this .server .getListenerAddress ());
186185 super .serviceStart ();
187186 }
188187
189188 @ Override
190189 protected void serviceStop () throws Exception {
191- LOG .info ("Stopping Router ClientRMService" );
190+ LOG .info ("Stopping Router ClientRMService. " );
192191 if (this .server != null ) {
193192 this .server .stop ();
194193 }
@@ -201,27 +200,6 @@ public Server getServer() {
201200 return this .server ;
202201 }
203202
204- /**
205- * Returns the comma separated intercepter class names from the configuration.
206- *
207- * @param conf
208- * @return the intercepter class names as an instance of ArrayList
209- */
210- private List <String > getInterceptorClassNames (Configuration conf ) {
211- String configuredInterceptorClassNames =
212- conf .get (YarnConfiguration .ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE ,
213- YarnConfiguration .DEFAULT_ROUTER_CLIENTRM_INTERCEPTOR_CLASS );
214-
215- List <String > interceptorClassNames = new ArrayList <String >();
216- Collection <String > tempList =
217- StringUtils .getStringCollection (configuredInterceptorClassNames );
218- for (String item : tempList ) {
219- interceptorClassNames .add (item .trim ());
220- }
221-
222- return interceptorClassNames ;
223- }
224-
225203 @ Override
226204 public GetNewApplicationResponse getNewApplication (
227205 GetNewApplicationRequest request ) throws YarnException , IOException {
@@ -507,42 +485,25 @@ protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
507485 @ VisibleForTesting
508486 protected ClientRequestInterceptor createRequestInterceptorChain () {
509487 Configuration conf = getConfig ();
488+ ClientRequestInterceptor pipeline = null ;
489+ ClientMethod remoteMethod = null ;
490+ try {
491+ remoteMethod = new ClientMethod ("setNextInterceptor" ,
492+ new Class []{ClientRequestInterceptor .class }, new Object []{null });
510493
511- List <String > interceptorClassNames = getInterceptorClassNames (conf );
494+ pipeline = RouterServerUtil .createRequestInterceptorChain (conf ,
495+ YarnConfiguration .ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE ,
496+ YarnConfiguration .DEFAULT_ROUTER_CLIENTRM_INTERCEPTOR_CLASS ,
497+ remoteMethod , ClientRequestInterceptor .class );
512498
513- ClientRequestInterceptor pipeline = null ;
514- ClientRequestInterceptor current = null ;
515- for (String interceptorClassName : interceptorClassNames ) {
516- try {
517- Class <?> interceptorClass = conf .getClassByName (interceptorClassName );
518- if (ClientRequestInterceptor .class .isAssignableFrom (interceptorClass )) {
519- ClientRequestInterceptor interceptorInstance =
520- (ClientRequestInterceptor ) ReflectionUtils
521- .newInstance (interceptorClass , conf );
522- if (pipeline == null ) {
523- pipeline = interceptorInstance ;
524- current = interceptorInstance ;
525- continue ;
526- } else {
527- current .setNextInterceptor (interceptorInstance );
528- current = interceptorInstance ;
529- }
530- } else {
531- throw new YarnRuntimeException (
532- "Class: " + interceptorClassName + " not instance of "
533- + ClientRequestInterceptor .class .getCanonicalName ());
534- }
535- } catch (ClassNotFoundException e ) {
499+ if (pipeline == null ) {
536500 throw new YarnRuntimeException (
537- "Could not instantiate ApplicationClientRequestInterceptor: "
538- + interceptorClassName ,
539- e );
501+ "RequestInterceptor pipeline is not configured in the system." );
540502 }
541- }
542-
543- if (pipeline == null ) {
544- throw new YarnRuntimeException (
545- "RequestInterceptor pipeline is not configured in the system" );
503+ } catch (IOException | InvocationTargetException | NoSuchMethodException | RuntimeException
504+ | IllegalAccessException ex ) {
505+ throw new YarnRuntimeException ("RequestInterceptor pipeline is not configured in the system." ,
506+ ex );
546507 }
547508 return pipeline ;
548509 }
@@ -566,14 +527,14 @@ private RequestInterceptorChainWrapper initializePipeline(String user) {
566527 // We should init the pipeline instance after it is created and then
567528 // add to the map, to ensure thread safe.
568529 LOG .info ("Initializing request processing pipeline for application "
569- + "for the user: {}" , user );
530+ + "for the user: {}. " , user );
570531
571532 ClientRequestInterceptor interceptorChain =
572533 this .createRequestInterceptorChain ();
573534 interceptorChain .init (user );
574535 chainWrapper .init (interceptorChain );
575536 } catch (Exception e ) {
576- LOG .error ("Init ClientRequestInterceptor error for user: " + user , e );
537+ LOG .error ("Init ClientRequestInterceptor error for user: {}." , user , e );
577538 throw e ;
578539 }
579540
0 commit comments