goiri commented on code in PR #4614:
URL: https://github.com/apache/hadoop/pull/4614#discussion_r928150558


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java:
##########
@@ -1172,7 +1172,28 @@ public ApplicationStatisticsInfo 
getAppStatistics(HttpServletRequest hsr,
   @Override
   public NodeToLabelsInfo getNodeToLabels(HttpServletRequest hsr)
       throws IOException {
-    throw new NotImplementedException("Code is not implemented");
+    NodeToLabelsInfo nodeToLabelsInfo = new NodeToLabelsInfo();
+    Map<SubClusterId, SubClusterInfo> subClustersActive;
+    try {
+      subClustersActive = getActiveSubclusters();
+    } catch (NotFoundException e) {
+      LOG.error("Get all active sub cluster(s) error.", e);
+      return nodeToLabelsInfo;
+    }
+
+    try {
+      final HttpServletRequest hsrCopy = clone(hsr);
+      Class[] argsClasses = new Class[]{HttpServletRequest.class};
+      Object[] args = new Object[]{hsrCopy};
+      ClientMethod remoteMethod = new ClientMethod("getNodeToLabels", 
argsClasses, args);
+      Map<SubClusterInfo, NodeToLabelsInfo> nodeToLabelsInfoMap =
+          invokeConcurrent(subClustersActive.values(), remoteMethod, 
NodeToLabelsInfo.class);
+      nodeToLabelsInfo = 
RouterWebServiceUtil.mergeNodeToLabels(nodeToLabelsInfoMap.values());

Review Comment:
   mergeNodeToLabels() could take Map<SubClusterInfo, NodeToLabelsInfo.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/test/java/org/apache/hadoop/yarn/server/router/webapp/MockDefaultRequestInterceptorREST.java:
##########
@@ -42,16 +43,7 @@
 import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo;
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppState;
-import 
org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ApplicationSubmissionContextInfo;
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppsInfo;
-import 
org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.ClusterMetricsInfo;
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NewApplication;
-import org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.NodeInfo;
-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.resourcemanager.webapp.dao.*;

Review Comment:
   Avoid



##########
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:
##########
@@ -33,7 +33,7 @@ public class NodeLabelsInfo {
 
   @XmlElement(name = "nodeLabelInfo")
   private ArrayList<NodeLabelInfo> nodeLabelsInfo =

Review Comment:
   Single line?



##########
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 +271,28 @@ public ContainersInfo getContainers(HttpServletRequest 
req, HttpServletResponse
 
     return containers;
   }
+
+  @Override
+  public NodeToLabelsInfo getNodeToLabels(HttpServletRequest hsr) throws 
IOException {
+    if (!isRunning) {
+      throw new RuntimeException("RM is stopped");
+    }
+    String cpuLabel = "CPU";
+    HashSet<String> cpuLabels = new HashSet<>();
+    cpuLabels.add(cpuLabel);
+
+    String gpuLabel = "GPU";
+    HashSet<String> gpuLabels = new HashSet<>();

Review Comment:
   I think we have hash constructors that already take the default values at 
construction instead of having to add.



##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-router/src/main/java/org/apache/hadoop/yarn/server/router/webapp/FederationInterceptorREST.java:
##########
@@ -1172,7 +1172,28 @@ public ApplicationStatisticsInfo 
getAppStatistics(HttpServletRequest hsr,
   @Override
   public NodeToLabelsInfo getNodeToLabels(HttpServletRequest hsr)
       throws IOException {
-    throw new NotImplementedException("Code is not implemented");
+    NodeToLabelsInfo nodeToLabelsInfo = new NodeToLabelsInfo();
+    Map<SubClusterId, SubClusterInfo> subClustersActive;
+    try {
+      subClustersActive = getActiveSubclusters();

Review Comment:
   You could do this in a single try, and catch the exception there.
   There is no best way to return the error than an empty NodeToLabelsInfo?



##########
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 +514,27 @@ protected static <T> String 
getMediaTypeFromHttpServletRequest(
     return header;
   }
 
+  public static NodeToLabelsInfo 
mergeNodeToLabels(Collection<NodeToLabelsInfo> nodeToLabelsInfos) {
+    NodeToLabelsInfo result = new NodeToLabelsInfo();
+    HashMap<String, NodeLabelsInfo> nodeToLabels = new HashMap<>();
+
+    nodeToLabelsInfos.stream().forEach(nodeToLabelsInfo ->{
+      for (Map.Entry<String, NodeLabelsInfo> item : 
nodeToLabelsInfo.getNodeToLabels().entrySet()) {
+        if (nodeToLabels.containsKey(item.getKey())) {

Review Comment:
   Extract item.getKey()



-- 
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]

Reply via email to