goiri commented on code in PR #4614:
URL: https://github.com/apache/hadoop/pull/4614#discussion_r930268100
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/RouterWebServiceUtil.java:
##########
@@ -509,4 +515,30 @@ protected static <T> String
getMediaTypeFromHttpServletRequest(
return header;
}
+ public static NodeToLabelsInfo mergeNodeToLabels(
+ Map<SubClusterInfo, NodeToLabelsInfo> nodeToLabelsInfoMap) {
+
+ NodeToLabelsInfo result = new NodeToLabelsInfo();
+ HashMap<String, NodeLabelsInfo> nodeToLabels = new HashMap<>();
+ Collection<NodeToLabelsInfo> nodeToLabelsInfos =
nodeToLabelsInfoMap.values();
+
+ nodeToLabelsInfos.stream().forEach(nodeToLabelsInfo -> {
+ for (Map.Entry<String, NodeLabelsInfo> item :
nodeToLabelsInfo.getNodeToLabels().entrySet()) {
+ String key = item.getKey();
+ NodeLabelsInfo itemValue = item.getValue();
+ NodeLabelsInfo nodeToLabelsValue =
nodeToLabels.getOrDefault(item.getKey(), null);
+ HashSet<NodeLabel> hashSet = new HashSet<>();
+ if (itemValue != null) {
+ hashSet.addAll(itemValue.getNodeLabels());
+ }
+ if (nodeToLabelsValue != null) {
+ hashSet.addAll(nodeToLabelsValue.getNodeLabels());
+ }
+ nodeToLabels.put(key, new NodeLabelsInfo(hashSet));
+ }
+ });
+
+ result.setNodeToLabels(nodeToLabels);
+ return result;
Review Comment:
It seems cleaner to do:
```
return new NodeToLabelsInfo(nodeToLabels);
```
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java:
##########
@@ -279,4 +283,20 @@ public ContainersInfo getContainers(HttpServletRequest
req, HttpServletResponse
return containers;
}
+
+ @Override
+ public NodeToLabelsInfo getNodeToLabels(HttpServletRequest hsr) throws
IOException {
+ if (!isRunning) {
+ throw new RuntimeException("RM is stopped");
+ }
+ NodeLabelsInfo cpuNode = new NodeLabelsInfo(Collections.singleton("CPU"));
+ NodeLabelsInfo gpuNode = new NodeLabelsInfo(Collections.singleton("GPU"));
+
+ NodeToLabelsInfo info = new NodeToLabelsInfo();
+ HashMap<String, NodeLabelsInfo> nodeLabels = new HashMap<>();
+ nodeLabels.put("node1", cpuNode);
+ nodeLabels.put("node2", gpuNode);
+ info.setNodeToLabels(nodeLabels);
+ return info;
Review Comment:
```
return new NodeToLabelsInfo(nodeLabels);
```
##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/NodeLabelsInfo.java:
##########
@@ -44,25 +43,32 @@ public NodeLabelsInfo(ArrayList<NodeLabelInfo> nodeLabels) {
}
public NodeLabelsInfo(List<NodeLabel> nodeLabels) {
- this.nodeLabelsInfo = new ArrayList<NodeLabelInfo>();
+ this.nodeLabelsInfo = new ArrayList<>();
for (NodeLabel label : nodeLabels) {
this.nodeLabelsInfo.add(new NodeLabelInfo(label));
}
}
public NodeLabelsInfo(Set<String> nodeLabelsName) {
- this.nodeLabelsInfo = new ArrayList<NodeLabelInfo>();
+ this.nodeLabelsInfo = new ArrayList<>();
for (String labelName : nodeLabelsName) {
this.nodeLabelsInfo.add(new NodeLabelInfo(labelName));
}
}
+ public NodeLabelsInfo(HashSet<NodeLabel> nodeLabels) {
Review Comment:
`Set<NodeLabel> nodeLabels` or `Collection<NodeLabel> nodeLabels`
--
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]