-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-10829. Support getApplications API in FederationClientInterceptor #3135
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a3283a6
Adding implementation for getApplications API in FederationClientInte…
akshatb1 c10cb69
Merge branch 'trunk' of https://github.com/akshatb1/hadoop into trunk
akshatb1 8e3e392
Fixing EOL Blanks
akshatb1 2eaaf53
Addressing checkstyle issues
akshatb1 d662c59
Addressing review comments
akshatb1 0497bfc
Addressing review comments and some other formatting issues
akshatb1 709efc4
Addressing review comments
akshatb1 b79c9e2
Fixing issue with mergeUamWithUam method
akshatb1 5992557
Using only managed AM tags
akshatb1 67155ef
Using isUnmanagedApp to determine managed/unmanaged app instead of ge…
akshatb1 1ce22f1
Removing empty line
akshatb1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,25 @@ | |
| package org.apache.hadoop.yarn.server.router.clientrm; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsResponse; | ||
| import org.apache.hadoop.yarn.api.protocolrecords.GetClusterMetricsResponse; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationId; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationReport; | ||
| import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport; | ||
| import org.apache.hadoop.yarn.api.records.YarnClusterMetrics; | ||
| import org.apache.hadoop.yarn.server.uam.UnmanagedApplicationManager; | ||
| import org.apache.hadoop.yarn.util.resource.Resources; | ||
|
|
||
| /** | ||
| * Util class for Router Yarn client API calls. | ||
| */ | ||
| public final class RouterYarnClientUtils { | ||
|
|
||
| private final static String PARTIAL_REPORT = "Partial Report "; | ||
|
|
||
| private RouterYarnClientUtils() { | ||
|
|
||
| } | ||
|
|
@@ -52,4 +63,130 @@ public static GetClusterMetricsResponse merge( | |
| } | ||
| return GetClusterMetricsResponse.newInstance(tmp); | ||
| } | ||
|
|
||
| /** | ||
| * Merges a list of ApplicationReports grouping by ApplicationId. | ||
| * Our current policy is to merge the application reports from the reachable | ||
| * SubClusters. | ||
| * @param responses a list of ApplicationResponse to merge | ||
| * @param returnPartialResult if the merge ApplicationReports should contain | ||
| * partial result or not | ||
| * @return the merged ApplicationsResponse | ||
| */ | ||
| public static GetApplicationsResponse mergeApplications( | ||
goiri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Collection<GetApplicationsResponse> responses, | ||
| boolean returnPartialResult){ | ||
| Map<ApplicationId, ApplicationReport> federationAM = new HashMap<>(); | ||
| Map<ApplicationId, ApplicationReport> federationUAMSum = new HashMap<>(); | ||
|
|
||
| for (GetApplicationsResponse appResponse : responses){ | ||
| for (ApplicationReport appReport : appResponse.getApplicationList()){ | ||
| ApplicationId appId = appReport.getApplicationId(); | ||
| // Check if this ApplicationReport is an AM | ||
| if (!appReport.isUnmanagedApp()) { | ||
| // Insert in the list of AM | ||
| federationAM.put(appId, appReport); | ||
| // Check if there are any UAM found before | ||
| if (federationUAMSum.containsKey(appId)) { | ||
| // Merge the current AM with the found UAM | ||
| mergeAMWithUAM(appReport, federationUAMSum.get(appId)); | ||
| // Remove the sum of the UAMs | ||
| federationUAMSum.remove(appId); | ||
| } | ||
| // This ApplicationReport is an UAM | ||
| } else if (federationAM.containsKey(appId)) { | ||
| // Merge the current UAM with its own AM | ||
| mergeAMWithUAM(federationAM.get(appId), appReport); | ||
| } else if (federationUAMSum.containsKey(appId)) { | ||
| // Merge the current UAM with its own UAM and update the list of UAM | ||
| ApplicationReport mergedUAMReport = | ||
| mergeUAMWithUAM(federationUAMSum.get(appId), appReport); | ||
| federationUAMSum.put(appId, mergedUAMReport); | ||
| } else { | ||
| // Insert in the list of UAM | ||
| federationUAMSum.put(appId, appReport); | ||
| } | ||
| } | ||
| } | ||
| // Check the remaining UAMs are depending or not from federation | ||
| for (ApplicationReport appReport : federationUAMSum.values()) { | ||
| if (mergeUamToReport(appReport.getName(), returnPartialResult)) { | ||
| federationAM.put(appReport.getApplicationId(), appReport); | ||
| } | ||
| } | ||
|
|
||
| return GetApplicationsResponse.newInstance(federationAM.values()); | ||
| } | ||
|
|
||
| private static ApplicationReport mergeUAMWithUAM(ApplicationReport uam1, | ||
bibinchundatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ApplicationReport uam2){ | ||
| uam1.setName(PARTIAL_REPORT + uam1.getApplicationId()); | ||
|
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. Can we test for this kind of name?
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. Added test for checking UAM merge. |
||
| mergeAMWithUAM(uam1, uam2); | ||
| return uam1; | ||
| } | ||
|
|
||
| private static void mergeAMWithUAM(ApplicationReport am, | ||
| ApplicationReport uam){ | ||
| ApplicationResourceUsageReport amResourceReport = | ||
bibinchundatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| am.getApplicationResourceUsageReport(); | ||
|
|
||
| ApplicationResourceUsageReport uamResourceReport = | ||
| uam.getApplicationResourceUsageReport(); | ||
|
|
||
| amResourceReport.setNumUsedContainers( | ||
| amResourceReport.getNumUsedContainers() + | ||
| uamResourceReport.getNumUsedContainers()); | ||
|
|
||
| amResourceReport.setNumReservedContainers( | ||
| amResourceReport.getNumReservedContainers() + | ||
| uamResourceReport.getNumReservedContainers()); | ||
|
|
||
| amResourceReport.setUsedResources(Resources.add( | ||
| amResourceReport.getUsedResources(), | ||
| uamResourceReport.getUsedResources())); | ||
|
|
||
| amResourceReport.setReservedResources(Resources.add( | ||
| amResourceReport.getReservedResources(), | ||
| uamResourceReport.getReservedResources())); | ||
|
|
||
| amResourceReport.setNeededResources(Resources.add( | ||
| amResourceReport.getNeededResources(), | ||
| uamResourceReport.getNeededResources())); | ||
|
|
||
| amResourceReport.setMemorySeconds( | ||
| amResourceReport.getMemorySeconds() + | ||
| uamResourceReport.getMemorySeconds()); | ||
|
|
||
| amResourceReport.setVcoreSeconds( | ||
| amResourceReport.getVcoreSeconds() + | ||
| uamResourceReport.getVcoreSeconds()); | ||
|
|
||
| amResourceReport.setQueueUsagePercentage( | ||
| amResourceReport.getQueueUsagePercentage() + | ||
| uamResourceReport.getQueueUsagePercentage()); | ||
|
|
||
| amResourceReport.setClusterUsagePercentage( | ||
| amResourceReport.getClusterUsagePercentage() + | ||
| uamResourceReport.getClusterUsagePercentage()); | ||
|
|
||
| am.setApplicationResourceUsageReport(amResourceReport); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether or not to add an unmanaged application to the report. | ||
| * @param appName Application Name | ||
| * @param returnPartialResult if the merge ApplicationReports should contain | ||
| * partial result or not | ||
| */ | ||
| private static boolean mergeUamToReport(String appName, | ||
| boolean returnPartialResult){ | ||
| if (returnPartialResult) { | ||
| return true; | ||
| } | ||
| if (appName == null) { | ||
| return false; | ||
| } | ||
| return !(appName.startsWith(UnmanagedApplicationManager.APP_NAME) || | ||
| appName.startsWith(PARTIAL_REPORT)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Add break line right before the method definition.