akshatb1 commented on a change in pull request #3135:
URL: https://github.com/apache/hadoop/pull/3135#discussion_r658480814
##########
File path:
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterYarnClientUtils.java
##########
@@ -52,4 +65,110 @@ 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(
+ 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.getHost() != null) {
+ // 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
+ federationUAMSum.put(appId,
+ mergeUAMWithUAM(federationUAMSum.get(appId), appReport));
+ } 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 (returnPartialResult || appReport.getName() != null
+ && !(appReport.getName()
+ .startsWith(UnmanagedApplicationManager.APP_NAME)
+ || appReport.getName()
+ .startsWith(PARTIAL_REPORT))) {
+ federationAM.put(appReport.getApplicationId(), appReport);
+ }
+ }
+
+ List<ApplicationReport> appList = new ArrayList<>(federationAM.values());
+ return GetApplicationsResponse.newInstance(appList);
+ }
+
+ private static ApplicationReport mergeUAMWithUAM(ApplicationReport uam1,
+ ApplicationReport uam2){
+ uam1.setName(PARTIAL_REPORT + uam1.getApplicationId());
+ mergeAMWithUAM(uam1, uam1);
+ mergeAMWithUAM(uam1, uam2);
+ return uam1;
+ }
+
+ private static void mergeAMWithUAM(ApplicationReport am,
+ ApplicationReport uam){
+ ApplicationResourceUsageReport resourceUsageReport =
+ am.getApplicationResourceUsageReport();
+ resourceUsageReport.setNumUsedContainers(
+ resourceUsageReport.getNumUsedContainers() +
+ uam.getApplicationResourceUsageReport()
Review comment:
Extracted uamresourceReport to make it more readable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]