-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-8900. [Router] Federation: routing getContainers REST invocations transparently to multiple RMs #4543
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
YARN-8900. [Router] Federation: routing getContainers REST invocations transparently to multiple RMs #4543
Changes from 7 commits
c1b44fa
efc1181
72a1849
e0902f5
210bfd1
ffd3eb4
a8cf91d
8810220
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 |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| package org.apache.hadoop.yarn.server.router.webapp; | ||
|
|
||
| import java.io.IOException; | ||
| import java.lang.reflect.Method; | ||
| import java.security.Principal; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
|
|
@@ -92,6 +93,7 @@ | |
| import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.SchedulerTypeInfo; | ||
| import org.apache.hadoop.yarn.server.router.RouterMetrics; | ||
| import org.apache.hadoop.yarn.server.router.RouterServerUtil; | ||
| import org.apache.hadoop.yarn.server.router.clientrm.ClientMethod; | ||
| import org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo; | ||
| import org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo; | ||
| import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo; | ||
|
|
@@ -1053,7 +1055,6 @@ public ClusterMetricsInfo call() { | |
| } | ||
|
|
||
| // Collect all the responses in parallel | ||
|
|
||
| for (int i = 0; i < subClustersActive.size(); i++) { | ||
| try { | ||
| Future<ClusterMetricsInfo> future = compSvc.take(); | ||
|
|
@@ -1336,7 +1337,33 @@ public AppAttemptInfo getAppAttempt(HttpServletRequest req, | |
| @Override | ||
| public ContainersInfo getContainers(HttpServletRequest req, | ||
| HttpServletResponse res, String appId, String appAttemptId) { | ||
| throw new NotImplementedException("Code is not implemented"); | ||
|
|
||
| ContainersInfo containersInfo = new ContainersInfo(); | ||
|
|
||
| Map<SubClusterId, SubClusterInfo> subClustersActive; | ||
| try { | ||
| subClustersActive = getActiveSubclusters(); | ||
| } catch (NotFoundException e) { | ||
| LOG.error("Get all active sub cluster(s) error.", e); | ||
| return containersInfo; | ||
| } | ||
|
|
||
| try { | ||
| 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); | ||
| Map<SubClusterInfo, ContainersInfo> containersInfoMap = | ||
| invokeConcurrent(subClustersActive.values(), remoteMethod, ContainersInfo.class); | ||
| if (containersInfoMap != null) { | ||
| containersInfoMap.values().forEach(containers -> | ||
| containersInfo.addAll(containers.getContainers())); | ||
| } | ||
| } catch (Exception ex) { | ||
| LOG.error("Failed to return GetContainers.", ex); | ||
| } | ||
|
|
||
| return containersInfo; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1366,4 +1393,42 @@ public void shutdown() { | |
| threadpool.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| private <R> Map<SubClusterInfo, R> invokeConcurrent(Collection<SubClusterInfo> clusterIds, | ||
| ClientMethod request, Class<R> clazz) { | ||
|
|
||
| Map<SubClusterInfo, R> results = new HashMap<>(); | ||
|
|
||
| // Send the requests in parallel | ||
| CompletionService<R> compSvc = new ExecutorCompletionService<>(this.threadpool); | ||
|
|
||
| for (final SubClusterInfo info : clusterIds) { | ||
| compSvc.submit(() -> { | ||
| DefaultRequestInterceptorREST interceptor = getOrCreateInterceptorForSubCluster( | ||
| info.getSubClusterId(), info.getRMWebServiceAddress()); | ||
| try { | ||
| Method method = DefaultRequestInterceptorREST.class. | ||
| getMethod(request.getMethodName(), request.getTypes()); | ||
| return (R) clazz.cast(method.invoke(interceptor, request.getParams())); | ||
| } catch (Exception e) { | ||
| LOG.error("SubCluster {} failed to call {} method.", info.getSubClusterId(), | ||
| request.getMethodName(), e); | ||
| return null; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| clusterIds.stream().forEach(clusterId -> { | ||
| try { | ||
| Future<R> future = compSvc.take(); | ||
| R response = future.get(); | ||
| if (response != null) { | ||
| results.put(clusterId, response); | ||
|
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. hi,@slfan1989,I have a question.
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. 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! |
||
| } | ||
| } catch (Throwable e) { | ||
| LOG.warn("SubCluster {} failed to {} report.", clusterId, request.getMethodName(), e); | ||
| } | ||
| }); | ||
| return results; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.