-
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 2 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 |
|---|---|---|
|
|
@@ -1336,7 +1336,51 @@ 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 = null; | ||
| try { | ||
| subClustersActive = federationFacade.getSubClusters(true); | ||
| } catch (YarnException e) { | ||
| LOG.error("Get All active sub cluster(s) error.", e); | ||
| return containersInfo; | ||
| } | ||
|
|
||
| // Send the requests in parallel | ||
| CompletionService<ContainersInfo> compSvc = | ||
| new ExecutorCompletionService<>(this.threadpool); | ||
|
|
||
| for (final SubClusterInfo info : subClustersActive.values()) { | ||
| compSvc.submit(() -> { | ||
| DefaultRequestInterceptorREST interceptor = | ||
| getOrCreateInterceptorForSubCluster(info.getSubClusterId(), info.getRMWebServiceAddress()); | ||
| try { | ||
| ContainersInfo containers = | ||
| interceptor.getContainers(req, res, appId, appAttemptId); | ||
| return containers; | ||
| } catch (Exception e) { | ||
| LOG.error("SubCluster {} failed to return GetContainers.", | ||
|
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. One line
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. |
||
| info.getSubClusterId()); | ||
|
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. Should we print the specific error? |
||
| return null; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Collect all the responses in parallel | ||
| for (int i = 0; i < subClustersActive.size(); i++) { | ||
| try { | ||
| Future<ContainersInfo> future = compSvc.take(); | ||
| ContainersInfo containersResponse = future.get(); | ||
|
|
||
| if (containersResponse != null) { | ||
| containersInfo.addAll(containersResponse.getContainers()); | ||
| } | ||
| } catch (Throwable e) { | ||
| LOG.warn("Failed to get containers report. ", e); | ||
|
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. Trim the space at the end of the string.
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. OK, I will fix it. |
||
| } | ||
| } | ||
|
|
||
| return containersInfo; | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,11 @@ | |
|
|
||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.apache.hadoop.util.Time; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationId; | ||
| import org.apache.hadoop.yarn.api.records.Resource; | ||
| import org.apache.hadoop.yarn.api.records.ResourceOption; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationAttemptId; | ||
| import org.apache.hadoop.yarn.conf.YarnConfiguration; | ||
| import org.apache.hadoop.yarn.exceptions.YarnException; | ||
| import org.apache.hadoop.yarn.server.federation.policies.manager.UniformBroadcastPolicyManager; | ||
|
|
@@ -47,6 +49,7 @@ | |
| import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodesInfo; | ||
| import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceInfo; | ||
| import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ResourceOptionInfo; | ||
| import org.apache.hadoop.yarn.server.webapp.dao.ContainersInfo; | ||
| import org.apache.hadoop.yarn.util.MonotonicClock; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
@@ -160,7 +163,7 @@ public void testSubmitApplication() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
|
|
||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
|
|
@@ -187,7 +190,7 @@ public void testSubmitApplicationMultipleSubmission() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
| context.setApplicationId(appId.toString()); | ||
|
|
@@ -259,7 +262,7 @@ public void testForceKillApplication() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
| context.setApplicationId(appId.toString()); | ||
|
|
@@ -286,7 +289,7 @@ public void testForceKillApplicationNotExists() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
| AppState appState = new AppState("KILLED"); | ||
|
|
||
| Response response = | ||
|
|
@@ -317,7 +320,7 @@ public void testForceKillApplicationWrongFormat() | |
| public void testForceKillApplicationEmptyRequest() | ||
| throws YarnException, IOException, InterruptedException { | ||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
|
|
||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
|
|
@@ -341,7 +344,7 @@ public void testGetApplicationReport() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
| context.setApplicationId(appId.toString()); | ||
|
|
@@ -478,7 +481,7 @@ public void testGetApplicationState() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
| ApplicationSubmissionContextInfo context = | ||
| new ApplicationSubmissionContextInfo(); | ||
| context.setApplicationId(appId.toString()); | ||
|
|
@@ -505,7 +508,7 @@ public void testGetApplicationStateNotExists() | |
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = | ||
| ApplicationId.newInstance(System.currentTimeMillis(), 1); | ||
| ApplicationId.newInstance(Time.now(), 1); | ||
|
|
||
| AppState response = interceptor.getAppState(null, appId.toString()); | ||
|
|
||
|
|
@@ -560,4 +563,27 @@ SubClusterState.SC_RUNNING, new MonotonicClock().getTime(), | |
| SubClusterRegisterRequest.newInstance(subClusterInfo)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetContainers() | ||
| throws YarnException, IOException, InterruptedException { | ||
|
|
||
| ApplicationId appId = ApplicationId.newInstance(Time.now(), 1); | ||
| ApplicationSubmissionContextInfo context = | ||
|
goiri marked this conversation as resolved.
|
||
| new ApplicationSubmissionContextInfo(); | ||
| context.setApplicationId(appId.toString()); | ||
|
|
||
| // Submit the application we want the report later | ||
| Response response = interceptor.submitApplication(context, null); | ||
|
|
||
| Assert.assertNotNull(response); | ||
| Assert.assertNotNull(stateStoreUtil.queryApplicationHomeSC(appId)); | ||
|
|
||
| ApplicationAttemptId appAttempt = | ||
|
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. One line |
||
| ApplicationAttemptId.newInstance(appId, 1); | ||
|
|
||
| ContainersInfo responseGet = interceptor.getContainers(null, null, | ||
|
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. Move all the args to the second line:
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. |
||
| appId.toString(), appAttempt.toString()); | ||
|
|
||
| Assert.assertEquals(4, responseGet.getContainers().size()); | ||
| } | ||
| } | ||
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.
Maybe just make this
Collection<ContainerInfo>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.
Thanks for helping to review the code, I will modify the code.