-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-11011. Make YARN Router throw Exception to client clearly. #6211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
bdcbfbd
f93538f
75e63b0
0599f31
14cfab9
32aa13d
aa883e8
69cfc27
4e87b7d
bdf07fb
e2a3b29
3fee020
515ac13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,13 @@ | |
| import org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
| import java.io.IOException; | ||
| import java.lang.reflect.Method; | ||
| import java.lang.reflect.InvocationTargetException; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Random; | ||
| import java.util.TreeMap; | ||
| import java.util.Set; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
@@ -842,13 +842,24 @@ <R> Collection<R> invokeConcurrent(ClientMethod request, Class<R> clazz) | |
| // Generate parallel Callable tasks | ||
| for (SubClusterId subClusterId : subClusterIds) { | ||
| callables.add(() -> { | ||
| ApplicationClientProtocol protocol = getClientRMProxyForSubCluster(subClusterId); | ||
| String methodName = request.getMethodName(); | ||
| Class<?>[] types = request.getTypes(); | ||
| Object[] params = request.getParams(); | ||
| Method method = ApplicationClientProtocol.class.getMethod(methodName, types); | ||
| Object result = method.invoke(protocol, params); | ||
| return Pair.of(subClusterId, result); | ||
| try { | ||
| ApplicationClientProtocol protocol = getClientRMProxyForSubCluster(subClusterId); | ||
| String methodName = request.getMethodName(); | ||
| Class<?>[] types = request.getTypes(); | ||
| Object[] params = request.getParams(); | ||
| Method method = ApplicationClientProtocol.class.getMethod(methodName, types); | ||
| Object result = method.invoke(protocol, params); | ||
| return Pair.of(subClusterId, result); | ||
| } catch (Exception e) { | ||
| Throwable cause = e.getCause(); | ||
| if (cause != null && cause instanceof InvocationTargetException) { | ||
| cause = cause.getCause(); | ||
| } | ||
| String errMsg = (cause.getMessage() != null) ? cause.getMessage() : "UNKNOWN"; | ||
| return Pair.of(subClusterId, new YarnException( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extract the exception for readability.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will improve this code. |
||
| String.format("subClusterId %s exec %s error %s.", subClusterId, | ||
| request.getMethodName(), errMsg), e)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -862,8 +873,11 @@ <R> Collection<R> invokeConcurrent(ClientMethod request, Class<R> clazz) | |
| Pair<SubClusterId, Object> pair = future.get(); | ||
| subClusterId = pair.getKey(); | ||
| Object result = pair.getValue(); | ||
| if(result instanceof YarnException) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Space
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix it. |
||
| throw YarnException.class.cast(result); | ||
| } | ||
| results.put(subClusterId, clazz.cast(result)); | ||
| } catch (InterruptedException | ExecutionException e) { | ||
| } catch (InterruptedException | ExecutionException | YarnException e) { | ||
| Throwable cause = e.getCause(); | ||
| LOG.error("Cannot execute {} on {} : {}", request.getMethodName(), | ||
| subClusterId.getId(), cause.getMessage()); | ||
|
|
@@ -877,9 +891,8 @@ <R> Collection<R> invokeConcurrent(ClientMethod request, Class<R> clazz) | |
| // All sub-clusters return results to be considered successful, | ||
| // otherwise an exception will be thrown. | ||
| if (exceptions != null && !exceptions.isEmpty()) { | ||
| Set<SubClusterId> subClusterIdSets = exceptions.keySet(); | ||
| throw new YarnException("invokeConcurrent Failed, An exception occurred in subClusterIds = " + | ||
| StringUtils.join(subClusterIdSets, ",")); | ||
| throw new YarnException("invokeConcurrent Failed = " + | ||
| StringUtils.join(exceptions.values(), ",")); | ||
| } | ||
|
|
||
| // return result | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,8 +35,7 @@ | |
| import org.apache.hadoop.test.GenericTestUtils; | ||
| import org.apache.hadoop.thirdparty.com.google.common.collect.ImmutableSet; | ||
| import org.apache.hadoop.yarn.api.ApplicationClientProtocol; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationResponse; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.*; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will fix it. |
||
| import org.apache.hadoop.yarn.api.records.NodeAttribute; | ||
| import org.apache.hadoop.yarn.api.records.NodeAttributeType; | ||
| import org.apache.hadoop.yarn.api.records.Resource; | ||
|
|
@@ -126,6 +125,11 @@ public SubmitApplicationResponse submitApplication( | |
| throw new ConnectException("RM is stopped"); | ||
| } | ||
|
|
||
| @Override | ||
| public GetClusterMetricsResponse getClusterMetrics(GetClusterMetricsRequest request) | ||
| throws YarnException { | ||
| throw new YarnException("RM is stopped"); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this cleaner?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your help in reviewing the code! I will improve this part of the code.