goiri commented on code in PR #4317:
URL: https://github.com/apache/hadoop/pull/4317#discussion_r875217639
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -870,19 +870,88 @@ public ReservationDeleteResponse deleteReservation(
@Override
public GetNodesToLabelsResponse getNodeToLabels(
GetNodesToLabelsRequest request) throws YarnException, IOException {
- throw new NotImplementedException("Code is not implemented");
+ if (request == null) {
+ routerMetrics.incrNodeToLabelsFailedRetrieved();
+ RouterServerUtil.logAndThrowException("Missing getNodesToLabels
request.", null);
+ }
+ long startTime = clock.getTime();
+ Map<SubClusterId, SubClusterInfo> subClusters =
+ federationFacade.getSubClusters(true);
+ Map<SubClusterId, GetNodesToLabelsResponse> clusterNodes =
Maps.newHashMap();
+ for (SubClusterId subClusterId : subClusters.keySet()) {
+ ApplicationClientProtocol client;
+ try {
+ client = getClientRMProxyForSubCluster(subClusterId);
Review Comment:
ApplicationClientProtocol client inside the try
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/FederationClientInterceptor.java:
##########
@@ -870,19 +870,88 @@ public ReservationDeleteResponse deleteReservation(
@Override
public GetNodesToLabelsResponse getNodeToLabels(
GetNodesToLabelsRequest request) throws YarnException, IOException {
- throw new NotImplementedException("Code is not implemented");
+ if (request == null) {
+ routerMetrics.incrNodeToLabelsFailedRetrieved();
+ RouterServerUtil.logAndThrowException("Missing getNodesToLabels
request.", null);
+ }
+ long startTime = clock.getTime();
+ Map<SubClusterId, SubClusterInfo> subClusters =
+ federationFacade.getSubClusters(true);
Review Comment:
It looks like we do this pattern a bunch of time.
Maybe we can generalizer this with some lambda passed as a parameter?
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/clientrm/RouterYarnClientUtils.java:
##########
@@ -218,4 +225,75 @@ public static GetClusterNodesResponse
mergeClusterNodesResponse(
clusterNodesResponse.setNodeReports(nodeReports);
return clusterNodesResponse;
}
+
+ /**
+ * Merges a list of GetNodesToLabelsResponse.
+ *
+ * @param responses a list of GetNodesToLabelsResponse to merge.
+ * @return the merged GetNodesToLabelsResponse.
+ */
+ public static GetNodesToLabelsResponse mergeNodesToLabelsResponse(
+ Collection<GetNodesToLabelsResponse> responses) {
+ GetNodesToLabelsResponse nodesToLabelsResponse = Records.newRecord(
+ GetNodesToLabelsResponse.class);
+ Map<NodeId, Set<String>> nodesToLabelMap = new HashMap<>();
+ for (GetNodesToLabelsResponse response : responses) {
+ if (response != null && response.getNodeToLabels() != null) {
+ nodesToLabelMap.putAll(response.getNodeToLabels());
+ }
+ }
+ nodesToLabelsResponse.setNodeToLabels(nodesToLabelMap);
+ return nodesToLabelsResponse;
+ }
+
+ /**
+ * Merges a list of GetLabelsToNodesResponse.
+ *
+ * @param responses a list of GetLabelsToNodesResponse to merge.
+ * @return the merged GetLabelsToNodesResponse.
+ */
+ public static GetLabelsToNodesResponse mergeLabelsToNodes(
+ Collection<GetLabelsToNodesResponse> responses){
+ GetLabelsToNodesResponse labelsToNodesResponse = Records.newRecord(
+ GetLabelsToNodesResponse.class);
+ Map<String, Set<NodeId>> labelsToNodesMap = new HashMap<>();
+ for (GetLabelsToNodesResponse response : responses) {
+ if (response != null && response.getLabelsToNodes() != null) {
+ Map<String, Set<NodeId>> clusterLabelsToNodesMap =
response.getLabelsToNodes();
+ for (Map.Entry<String, Set<NodeId>> entry :
clusterLabelsToNodesMap.entrySet()) {
+ String label = entry.getKey();
+ Set<NodeId> clusterNodes = entry.getValue();
+ if (labelsToNodesMap.containsKey(label)) {
+ Set<NodeId> allNodes = labelsToNodesMap.get(label);
+ allNodes.addAll(clusterNodes);
+ } else {
+ labelsToNodesMap.put(label, clusterNodes);
+ }
+ }
+ }
+ }
+ labelsToNodesResponse.setLabelsToNodes(labelsToNodesMap);
+ return labelsToNodesResponse;
+ }
+
+ /**
+ * Merges a list of GetClusterNodeLabelsResponse.
+ *
+ * @param responses a list of GetClusterNodeLabelsResponse to merge.
+ * @return the merged GetClusterNodeLabelsResponse.
+ */
+ public static GetClusterNodeLabelsResponse mergeClusterNodeLabelsResponse(
Review Comment:
Can we add a few independent unit tests for these merge methods?
Covering null cases and other corner cases.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]