goiri commented on code in PR #4594:
URL: https://github.com/apache/hadoop/pull/4594#discussion_r926043147


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/RouterRMAdminService.java:
##########
@@ -215,43 +190,24 @@ protected Map<String, RequestInterceptorChainWrapper> 
getPipelines() {
   @VisibleForTesting
   protected RMAdminRequestInterceptor createRequestInterceptorChain() {
     Configuration conf = getConfig();
+    RMAdminRequestInterceptor pipeline = null;
+    ClientMethod remoteMethod = null;
+    try {
+      remoteMethod = new ClientMethod("setNextInterceptor",

Review Comment:
   Declare it directly here:
   ```
   ClientMethod remoteMethod = new ClientMethod("setNextInterceptor",
   ```



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterClientRMService.java:
##########
@@ -566,14 +522,14 @@ private RequestInterceptorChainWrapper 
initializePipeline(String user) {
         // 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 application "
-            + "for the user: {}", user);
+            + "for the user: {}.", user);

Review Comment:
   We could put the string in a single line.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/RouterRMAdminService.java:
##########
@@ -215,43 +190,24 @@ protected Map<String, RequestInterceptorChainWrapper> 
getPipelines() {
   @VisibleForTesting
   protected RMAdminRequestInterceptor createRequestInterceptorChain() {
     Configuration conf = getConfig();
+    RMAdminRequestInterceptor pipeline = null;
+    ClientMethod remoteMethod = null;
+    try {
+      remoteMethod = new ClientMethod("setNextInterceptor",
+              new Class[]{RMAdminRequestInterceptor.class}, new 
Object[]{null});
 
-    List<String> interceptorClassNames = getInterceptorClassNames(conf);
+      pipeline = RouterServerUtil.createRequestInterceptorChain(conf,
+          YarnConfiguration.ROUTER_RMADMIN_INTERCEPTOR_CLASS_PIPELINE,
+          YarnConfiguration.DEFAULT_ROUTER_RMADMIN_INTERCEPTOR_CLASS,
+          remoteMethod, RMAdminRequestInterceptor.class);
 
-    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) {
+      if (pipeline == null) {
         throw new YarnRuntimeException(
-            "Could not instantiate RMAdminRequestInterceptor: "
-                + interceptorClassName,
-            e);
+            "RequestInterceptor pipeline is not configured in the system.");
       }
-    }
-
-    if (pipeline == null) {
-      throw new YarnRuntimeException(
-          "RequestInterceptor pipeline is not configured in the system");
+    } catch (IOException | InvocationTargetException | NoSuchMethodException | 
RuntimeException
+             | IllegalAccessException ex) {
+      throw new YarnRuntimeException("Create RequestInterceptor Chain error.", 
ex);
     }
     return pipeline;

Review Comment:
   Given that if error we always return exception, can we define the `pipeline` 
inside of the try and do the exception returns properly?



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServices.java:
##########
@@ -206,50 +181,33 @@ protected Map<String, RequestInterceptorChainWrapper> 
getPipelines() {
    */
   @VisibleForTesting
   protected RESTRequestInterceptor createRequestInterceptorChain() {
+    RESTRequestInterceptor pipeline = null;

Review Comment:
   This code is very similar to the other one.
   As we are refactoring, can we clean this up?



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterClientRMService.java:
##########
@@ -507,42 +480,25 @@ protected Map<String, RequestInterceptorChainWrapper> 
getPipelines() {
   @VisibleForTesting
   protected ClientRequestInterceptor createRequestInterceptorChain() {
     Configuration conf = getConfig();
+    ClientRequestInterceptor pipeline = null;
+    ClientMethod remoteMethod = null;
+    try {
+      remoteMethod = new ClientMethod("setNextInterceptor",
+           new Class[]{ClientRequestInterceptor.class}, new Object[]{null});
 
-    List<String> interceptorClassNames = getInterceptorClassNames(conf);
+      pipeline = RouterServerUtil.createRequestInterceptorChain(conf,
+              YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE,
+              YarnConfiguration.DEFAULT_ROUTER_CLIENTRM_INTERCEPTOR_CLASS,
+              remoteMethod, ClientRequestInterceptor.class);
 
-    ClientRequestInterceptor pipeline = null;
-    ClientRequestInterceptor current = null;
-    for (String interceptorClassName : interceptorClassNames) {
-      try {
-        Class<?> interceptorClass = conf.getClassByName(interceptorClassName);
-        if (ClientRequestInterceptor.class.isAssignableFrom(interceptorClass)) 
{
-          ClientRequestInterceptor interceptorInstance =
-              (ClientRequestInterceptor) 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 "
-                  + ClientRequestInterceptor.class.getCanonicalName());
-        }
-      } catch (ClassNotFoundException e) {
+      if (pipeline == null) {
         throw new YarnRuntimeException(
-            "Could not instantiate ApplicationClientRequestInterceptor: "
-                + interceptorClassName,
-            e);
+            "RequestInterceptor pipeline is not configured in the system.");
       }
-    }
-
-    if (pipeline == null) {
-      throw new YarnRuntimeException(
-          "RequestInterceptor pipeline is not configured in the system");
+    } catch (IOException | InvocationTargetException | NoSuchMethodException | 
RuntimeException

Review Comment:
   At this point we better catch Exception



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to