YARN-8900. [Router] Federation: routing getContainers REST invocations transparently to multiple RMs#4543
Conversation
…s transparently to multiple RMs.
|
🎊 +1 overall
This message was automatically generated. |
| try { | ||
| subClustersActive = federationFacade.getSubClusters(true); | ||
| } catch (YarnException e) { | ||
| LOG.error(e.getLocalizedMessage()); |
There was a problem hiding this comment.
Thanks for your help reviewing the code, I will fix it asap.
There was a problem hiding this comment.
I will refactor this code to make it easier for other method calls.
|
🎊 +1 overall
This message was automatically generated. |
| return container; | ||
| } | ||
|
|
||
| public void addAll(ArrayList<ContainerInfo> containersInfo) { |
There was a problem hiding this comment.
Maybe just make this Collection<ContainerInfo>
There was a problem hiding this comment.
Thanks for helping to review the code, I will modify the code.
| containersInfo.addAll(containersResponse.getContainers()); | ||
| } | ||
| } catch (Throwable e) { | ||
| LOG.warn("Failed to get containers report. ", e); |
There was a problem hiding this comment.
Trim the space at the end of the string.
There was a problem hiding this comment.
OK, I will fix it.
| interceptor.getContainers(req, res, appId, appAttemptId); | ||
| return containers; | ||
| } catch (Exception e) { | ||
| LOG.error("SubCluster {} failed to return GetContainers.", |
| return containers; | ||
| } catch (Exception e) { | ||
| LOG.error("SubCluster {} failed to return GetContainers.", | ||
| info.getSubClusterId()); |
There was a problem hiding this comment.
Should we print the specific error?
| } | ||
|
|
||
| public void addAll(Collection<ContainerInfo> containersInfo) { | ||
| container.addAll(new ArrayList<>(containersInfo)); |
There was a problem hiding this comment.
You don't need to create the ArrayList.
public void addAll(Collection<ContainerInfo> containersInfo) {
container.addAll(containersInfo);
}
Should just work: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html#addAll(java.util.Collection)
There was a problem hiding this comment.
Thanks for the suggestion, I will modify the code.
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.*; |
| } | ||
|
|
||
| try { | ||
| ClientMethod remoteMethod = new ClientMethod("getContainers", |
There was a problem hiding this comment.
The code would look more intuitive as:
Class[] argsClasses = new Class[]{
HttpServletRequest.class, HttpServletResponse.class, String.class, String.class};
Object[] args = new Object[]{req, res, appId, appAttemptId}
ClientMethod remoteMethod = new ClientMethod("getContainers", argsClasses, args);
There was a problem hiding this comment.
your suggestion is great!
| // Send the requests in parallel | ||
| CompletionService<R> compSvc = new ExecutorCompletionService<>(this.threadpool); | ||
|
|
||
| for (final SubClusterInfo info : subClusterInfo) { |
There was a problem hiding this comment.
You could pass directly:
Collection<SubClusterInfo> clusterIds
No need to make it an array list.
There was a problem hiding this comment.
Thanks a lot for the advice, let me learn a lot, the code has been modified.
| try { | ||
| Method method = DefaultRequestInterceptorREST.class. | ||
| getMethod(request.getMethodName(), request.getTypes()); | ||
| return clazz.cast(method.invoke(interceptor, request.getParams())); |
There was a problem hiding this comment.
Extract to make it clear what type is each thing.
There was a problem hiding this comment.
I added cast to R.
| @Test | ||
| public void testGetContainersNotExists() { | ||
| ApplicationId appId = ApplicationId.newInstance(Time.now(), 1); | ||
| ContainersInfo response = |
|
|
||
| @Test | ||
| public void testGetContainersWrongFormat() { | ||
| ContainersInfo response = |
| ApplicationAttemptId appAttempt = | ||
| ApplicationAttemptId.newInstance(appId, 1); | ||
|
|
||
| ContainersInfo responseGet = interceptor.getContainers(null, null, |
There was a problem hiding this comment.
Move all the args to the second line:
ContainersInfo responseGet = interceptor.getContainers(
null, null, appId.toString(), appAttempt.toString());
| Assert.assertNotNull(response); | ||
| Assert.assertNotNull(stateStoreUtil.queryApplicationHomeSC(appId)); | ||
|
|
||
| ApplicationAttemptId appAttempt = |
| }); | ||
| } | ||
|
|
||
| for (int i = 0; i < subClusterInfo.size(); i++) { |
There was a problem hiding this comment.
This would be cleaner as:
for (final subClusterInfo : subClusterInfos) {
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
...test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java
Outdated
Show resolved
Hide resolved
|
🎊 +1 overall
This message was automatically generated. |
...ter/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java
Outdated
Show resolved
Hide resolved
...test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java
Outdated
Show resolved
Hide resolved
|
🎊 +1 overall
This message was automatically generated. |
|
@goiri Please help to review the code again,thank you very much! |
|
@goiri Can you help merge this pr into the trunk branch? I will continue to improve the REST APIs for Router. YARN-11212 This pr will be followed up. I need to use this method |
|
@goiri Thanks for your help reviewing the code! |
…s transparently to multiple RMs (apache#4543)
| Future<R> future = compSvc.take(); | ||
| R response = future.get(); | ||
| if (response != null) { | ||
| results.put(clusterId, response); |
There was a problem hiding this comment.
hi,@slfan1989,I have a question.
- Operation
compSvc.take()is not guaranteed to be in the same order as operationcompSvc.submit(), in addition, clusterIds type might be Set. So,clusterId->responsemaybe mistake? - Can we do this like
FederationClientInterceptor#invokeConcurrent?
There was a problem hiding this comment.
Thank you very much for your feedback, I agree with your description. For the results of the FederationInterceptorREST interface, we will integrate the results returned by all subClusters. This part does not care about the return order of multi-threads. I've submitted a Follow Up pr to fix this, thanks again!
JIRA: YARN-8900. [Router] Federation: routing getContainers REST invocations transparently to multiple RMs