2020
2121import  java .io .IOException ;
2222import  java .net .InetSocketAddress ;
23- import  java .util .ArrayList ;
24- import  java .util .Collection ;
2523import  java .util .Collections ;
26- import  java .util .List ;
2724import  java .util .Map ;
2825
2926import  org .apache .hadoop .classification .InterfaceAudience .Private ;
3330import  org .apache .hadoop .security .UserGroupInformation ;
3431import  org .apache .hadoop .security .authorize .PolicyProvider ;
3532import  org .apache .hadoop .service .AbstractService ;
36- import  org .apache .hadoop .util .ReflectionUtils ;
37- import  org .apache .hadoop .util .StringUtils ;
3833import  org .apache .hadoop .yarn .api .ApplicationClientProtocol ;
3934import  org .apache .hadoop .yarn .api .protocolrecords .CancelDelegationTokenRequest ;
4035import  org .apache .hadoop .yarn .api .protocolrecords .CancelDelegationTokenResponse ;
108103import  org .apache .hadoop .yarn .api .protocolrecords .UpdateApplicationTimeoutsResponse ;
109104import  org .apache .hadoop .yarn .conf .YarnConfiguration ;
110105import  org .apache .hadoop .yarn .exceptions .YarnException ;
111- import  org .apache .hadoop .yarn .exceptions .YarnRuntimeException ;
112106import  org .apache .hadoop .yarn .ipc .YarnRPC ;
107+ import  org .apache .hadoop .yarn .server .router .RouterServerUtil ;
113108import  org .apache .hadoop .yarn .server .router .security .authorize .RouterPolicyProvider ;
114109import  org .apache .hadoop .yarn .util .LRUCacheHashMap ;
115110import  org .slf4j .Logger ;
@@ -147,7 +142,7 @@ public RouterClientRMService() {
147142
148143  @ Override 
149144  protected  void  serviceStart () throws  Exception  {
150-     LOG .info ("Starting Router ClientRMService" );
145+     LOG .info ("Starting Router ClientRMService. " );
151146    Configuration  conf  = getConfig ();
152147    YarnRPC  rpc  = YarnRPC .create (conf );
153148    UserGroupInformation .setConfiguration (conf );
@@ -161,9 +156,7 @@ protected void serviceStart() throws Exception {
161156    int  maxCacheSize  =
162157        conf .getInt (YarnConfiguration .ROUTER_PIPELINE_CACHE_MAX_SIZE ,
163158            YarnConfiguration .DEFAULT_ROUTER_PIPELINE_CACHE_MAX_SIZE );
164-     this .userPipelineMap  = Collections .synchronizedMap (
165-         new  LRUCacheHashMap <String , RequestInterceptorChainWrapper >(
166-             maxCacheSize , true ));
159+     this .userPipelineMap  = Collections .synchronizedMap (new  LRUCacheHashMap <>(maxCacheSize , true ));
167160
168161    Configuration  serverConf  = new  Configuration (conf );
169162
@@ -181,14 +174,13 @@ protected void serviceStart() throws Exception {
181174    }
182175
183176    this .server .start ();
184-     LOG .info ("Router ClientRMService listening on address: " 
185-         + this .server .getListenerAddress ());
177+     LOG .info ("Router ClientRMService listening on address: {}." , this .server .getListenerAddress ());
186178    super .serviceStart ();
187179  }
188180
189181  @ Override 
190182  protected  void  serviceStop () throws  Exception  {
191-     LOG .info ("Stopping Router ClientRMService" );
183+     LOG .info ("Stopping Router ClientRMService. " );
192184    if  (this .server  != null ) {
193185      this .server .stop ();
194186    }
@@ -201,27 +193,6 @@ public Server getServer() {
201193    return  this .server ;
202194  }
203195
204-   /** 
205-    * Returns the comma separated interceptor class names from the configuration. 
206-    * 
207-    * @param conf 
208-    * @return the interceptor 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- 
225196  @ Override 
226197  public  GetNewApplicationResponse  getNewApplication (
227198      GetNewApplicationRequest  request ) throws  YarnException , IOException  {
@@ -507,44 +478,10 @@ protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
507478  @ VisibleForTesting 
508479  protected  ClientRequestInterceptor  createRequestInterceptorChain () {
509480    Configuration  conf  = getConfig ();
510- 
511-     List <String > interceptorClassNames  = getInterceptorClassNames (conf );
512- 
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 ) {
536-         throw  new  YarnRuntimeException (
537-             "Could not instantiate ApplicationClientRequestInterceptor: " 
538-                 + interceptorClassName ,
539-             e );
540-       }
541-     }
542- 
543-     if  (pipeline  == null ) {
544-       throw  new  YarnRuntimeException (
545-           "RequestInterceptor pipeline is not configured in the system" );
546-     }
547-     return  pipeline ;
481+     return  RouterServerUtil .createRequestInterceptorChain (conf ,
482+         YarnConfiguration .ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE ,
483+         YarnConfiguration .DEFAULT_ROUTER_CLIENTRM_INTERCEPTOR_CLASS ,
484+         ClientRequestInterceptor .class );
548485  }
549486
550487  /** 
@@ -565,15 +502,15 @@ private RequestInterceptorChainWrapper initializePipeline(String user) {
565502      try  {
566503        // We should init the pipeline instance after it is created and then 
567504        // add to the map, to ensure thread safe. 
568-         LOG .info ("Initializing request processing pipeline for application "  
569-             +  "for the user: {}" ,  user );
505+         LOG .info ("Initializing request processing pipeline for application for the user: {}."  , 
506+             user );
570507
571508        ClientRequestInterceptor  interceptorChain  =
572509            this .createRequestInterceptorChain ();
573510        interceptorChain .init (user );
574511        chainWrapper .init (interceptorChain );
575512      } catch  (Exception  e ) {
576-         LOG .error ("Init ClientRequestInterceptor error for user: "   +  user , e );
513+         LOG .error ("Init ClientRequestInterceptor error for user: {}."  ,  user , e );
577514        throw  e ;
578515      }
579516
0 commit comments