Skip to content

Commit 58555ba

Browse files
author
slfan1989
committed
YARN-6572. Refactoring Router services to use common util classes for pipeline creations.
1 parent e9dd485 commit 58555ba

File tree

4 files changed

+31
-54
lines changed

4 files changed

+31
-54
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/RouterServerUtil.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.hadoop.util.StringUtils;
2727
import org.apache.hadoop.yarn.exceptions.YarnException;
2828
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
29-
import org.apache.hadoop.yarn.server.router.clientrm.ClientMethod;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

@@ -72,8 +71,7 @@ public static void logAndThrowException(String errMsg, Throwable t)
7271
}
7372

7473
public static <R> R createRequestInterceptorChain(Configuration conf, String pipeLineClassName,
75-
String interceptorClassName, ClientMethod request, Class<R> clazz)
76-
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
74+
String interceptorClassName, Class<R> clazz) {
7775

7876
List<String> interceptorClassNames = getInterceptorClassNames(conf,
7977
pipeLineClassName, interceptorClassName);
@@ -91,7 +89,7 @@ public static <R> R createRequestInterceptorChain(Configuration conf, String pip
9189
current = clazz.cast(interceptorInstance);
9290
continue;
9391
} else {
94-
Method method = clazz.getMethod(request.getMethodName(), request.getTypes());
92+
Method method = clazz.getMethod("setNextInterceptor", clazz);
9593
method.invoke(current, interceptorInstance);
9694
current = clazz.cast(interceptorInstance);
9795
}
@@ -101,10 +99,30 @@ public static <R> R createRequestInterceptorChain(Configuration conf, String pip
10199
+ clazz.getCanonicalName());
102100
}
103101
} catch (ClassNotFoundException e) {
102+
LOG.error("Could not instantiate RequestInterceptor: {}", className, e);
104103
throw new YarnRuntimeException("Could not instantiate RequestInterceptor: " + className, e);
104+
} catch (InvocationTargetException e) {
105+
LOG.error("RequestInterceptor {} call setNextInterceptor error.", className, e);
106+
throw new YarnRuntimeException("RequestInterceptor " + className
107+
+ " call setNextInterceptor error.", e);
108+
} catch (NoSuchMethodException e) {
109+
LOG.error("RequestInterceptor {} does not contain the method setNextInterceptor.",
110+
className);
111+
throw new YarnRuntimeException("RequestInterceptor " + className +
112+
" does not contain the method setNextInterceptor.", e);
113+
} catch (IllegalAccessException e) {
114+
LOG.error("RequestInterceptor {} call the method setNextInterceptor " +
115+
"does not have access.", className);
116+
throw new YarnRuntimeException("RequestInterceptor "
117+
+ className + " call the method setNextInterceptor does not have access.", e);
105118
}
106119
}
107120

121+
if (pipeline == null) {
122+
throw new YarnRuntimeException(
123+
"RequestInterceptor pipeline is not configured in the system.");
124+
}
125+
108126
return pipeline;
109127
}
110128

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterClientRMService.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -480,27 +480,15 @@ protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
480480
@VisibleForTesting
481481
protected ClientRequestInterceptor createRequestInterceptorChain() {
482482
Configuration conf = getConfig();
483-
ClientRequestInterceptor pipeline = null;
484-
ClientMethod remoteMethod = null;
485483
try {
486-
remoteMethod = new ClientMethod("setNextInterceptor",
487-
new Class[]{ClientRequestInterceptor.class}, new Object[]{null});
488-
489-
pipeline = RouterServerUtil.createRequestInterceptorChain(conf,
484+
return RouterServerUtil.createRequestInterceptorChain(conf,
490485
YarnConfiguration.ROUTER_CLIENTRM_INTERCEPTOR_CLASS_PIPELINE,
491486
YarnConfiguration.DEFAULT_ROUTER_CLIENTRM_INTERCEPTOR_CLASS,
492-
remoteMethod, ClientRequestInterceptor.class);
493-
494-
if (pipeline == null) {
495-
throw new YarnRuntimeException(
496-
"RequestInterceptor pipeline is not configured in the system.");
497-
}
498-
} catch (IOException | InvocationTargetException | NoSuchMethodException | RuntimeException
499-
| IllegalAccessException ex) {
487+
ClientRequestInterceptor.class);
488+
} catch (YarnRuntimeException ex) {
500489
throw new YarnRuntimeException("RequestInterceptor pipeline is not configured in the system.",
501490
ex);
502491
}
503-
return pipeline;
504492
}
505493

506494
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/rmadmin/RouterRMAdminService.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.hadoop.yarn.server.router.rmadmin;
2020

2121
import java.io.IOException;
22-
import java.lang.reflect.InvocationTargetException;
2322
import java.net.InetSocketAddress;
2423
import java.util.Collections;
2524
import java.util.Map;
@@ -66,7 +65,6 @@
6665
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceRequest;
6766
import org.apache.hadoop.yarn.server.api.protocolrecords.UpdateNodeResourceResponse;
6867
import org.apache.hadoop.yarn.server.router.RouterServerUtil;
69-
import org.apache.hadoop.yarn.server.router.clientrm.ClientMethod;
7068
import org.apache.hadoop.yarn.server.router.security.authorize.RouterPolicyProvider;
7169
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
7270
import org.slf4j.Logger;
@@ -190,26 +188,14 @@ protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
190188
@VisibleForTesting
191189
protected RMAdminRequestInterceptor createRequestInterceptorChain() {
192190
Configuration conf = getConfig();
193-
RMAdminRequestInterceptor pipeline = null;
194-
ClientMethod remoteMethod = null;
195191
try {
196-
remoteMethod = new ClientMethod("setNextInterceptor",
197-
new Class[]{RMAdminRequestInterceptor.class}, new Object[]{null});
198-
199-
pipeline = RouterServerUtil.createRequestInterceptorChain(conf,
192+
return RouterServerUtil.createRequestInterceptorChain(conf,
200193
YarnConfiguration.ROUTER_RMADMIN_INTERCEPTOR_CLASS_PIPELINE,
201194
YarnConfiguration.DEFAULT_ROUTER_RMADMIN_INTERCEPTOR_CLASS,
202-
remoteMethod, RMAdminRequestInterceptor.class);
203-
204-
if (pipeline == null) {
205-
throw new YarnRuntimeException(
206-
"RequestInterceptor pipeline is not configured in the system.");
207-
}
208-
} catch (IOException | InvocationTargetException | NoSuchMethodException | RuntimeException
209-
| IllegalAccessException ex) {
195+
RMAdminRequestInterceptor.class);
196+
} catch (YarnRuntimeException ex) {
210197
throw new YarnRuntimeException("Create RequestInterceptor Chain error.", ex);
211198
}
212-
return pipeline;
213199
}
214200

215201
/**

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServices.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.hadoop.yarn.server.router.webapp;
2020

2121
import java.io.IOException;
22-
import java.lang.reflect.InvocationTargetException;
2322
import java.util.Collections;
2423
import java.util.Map;
2524
import java.util.Set;
@@ -83,7 +82,6 @@
8382
import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo;
8483
import org.apache.hadoop.yarn.server.router.Router;
8584
import org.apache.hadoop.yarn.server.router.RouterServerUtil;
86-
import org.apache.hadoop.yarn.server.router.clientrm.ClientMethod;
8785
import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo;
8886
import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo;
8987
import org.apache.hadoop.yarn.util.LRUCacheHashMap;
@@ -181,27 +179,14 @@ protected Map<String, RequestInterceptorChainWrapper> getPipelines() {
181179
*/
182180
@VisibleForTesting
183181
protected RESTRequestInterceptor createRequestInterceptorChain() {
184-
RESTRequestInterceptor pipeline = null;
185-
ClientMethod remoteMethod = null;
186182
try {
187-
remoteMethod = new ClientMethod("setNextInterceptor",
188-
new Class[]{RESTRequestInterceptor.class}, new Object[]{null});
189-
190-
pipeline = RouterServerUtil.createRequestInterceptorChain(conf,
183+
return RouterServerUtil.createRequestInterceptorChain(conf,
191184
YarnConfiguration.ROUTER_WEBAPP_INTERCEPTOR_CLASS_PIPELINE,
192185
YarnConfiguration.DEFAULT_ROUTER_WEBAPP_INTERCEPTOR_CLASS,
193-
remoteMethod, RESTRequestInterceptor.class);
194-
195-
if (pipeline == null) {
196-
throw new YarnRuntimeException(
197-
"RequestInterceptor pipeline is not configured in the system.");
198-
}
199-
} catch (IOException | InvocationTargetException | NoSuchMethodException | RuntimeException
200-
| IllegalAccessException ex) {
186+
RESTRequestInterceptor.class);
187+
} catch (YarnRuntimeException ex) {
201188
throw new YarnRuntimeException("Create RequestInterceptor Chain error.", ex);
202189
}
203-
204-
return pipeline;
205190
}
206191

207192
/**

0 commit comments

Comments
 (0)