-
Notifications
You must be signed in to change notification settings - Fork 9.2k
YARN-11212. [Federation] Add getNodeToLabels REST APIs for Router. #4614
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
Conversation
|
🎊 +1 overall
This message was automatically generated. |
| public class NodeLabelsInfo { | ||
|
|
||
| @XmlElement(name = "nodeLabelInfo") | ||
| private ArrayList<NodeLabelInfo> nodeLabelsInfo = |
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.
Single line?
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.
Thanks for your help reviewing the code, I will fix it.
| ClientMethod remoteMethod = new ClientMethod("getNodeToLabels", argsClasses, args); | ||
| Map<SubClusterInfo, NodeToLabelsInfo> nodeToLabelsInfoMap = | ||
| invokeConcurrent(subClustersActive.values(), remoteMethod, NodeToLabelsInfo.class); | ||
| nodeToLabelsInfo = RouterWebServiceUtil.mergeNodeToLabels(nodeToLabelsInfoMap.values()); |
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.
mergeNodeToLabels() could take Map<SubClusterInfo, NodeToLabelsInfo.
| NodeToLabelsInfo nodeToLabelsInfo = new NodeToLabelsInfo(); | ||
| Map<SubClusterId, SubClusterInfo> subClustersActive; | ||
| try { | ||
| subClustersActive = getActiveSubclusters(); |
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.
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?
|
|
||
| nodeToLabelsInfos.stream().forEach(nodeToLabelsInfo ->{ | ||
| for (Map.Entry<String, NodeLabelsInfo> item : nodeToLabelsInfo.getNodeToLabels().entrySet()) { | ||
| if (nodeToLabels.containsKey(item.getKey())) { |
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.
Extract item.getKey()
| 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.*; |
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.
Avoid
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.
I will fix it.
| cpuLabels.add(cpuLabel); | ||
|
|
||
| String gpuLabel = "GPU"; | ||
| HashSet<String> gpuLabels = new HashSet<>(); |
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.
I think we have hash constructors that already take the default values at construction instead of having to add.
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.
Thanks for your suggestion, I will modify the code.
|
💔 -1 overall
This message was automatically generated. |
|
💔 -1 overall
This message was automatically generated. |
|
💔 -1 overall
This message was automatically generated. |
|
💔 -1 overall
This message was automatically generated. |
| ClientMethod remoteMethod = new ClientMethod("getNodeToLabels", argsClasses, args); | ||
| Map<SubClusterInfo, NodeToLabelsInfo> nodeToLabelsInfoMap = | ||
| invokeConcurrent(subClustersActive.values(), remoteMethod, NodeToLabelsInfo.class); | ||
| nodeToLabelsInfo = RouterWebServiceUtil.mergeNodeToLabels(nodeToLabelsInfoMap); |
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.
What if we just do:
return RouterWebServiceUtil.mergeNodeToLabels(nodeToLabelsInfoMap);
Not sure what the default case would look like; but I think the exception should just surface.
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.
I refactored part of the code to print and throw exceptions, so that once an exception occurs, users can immediately find the problem.
|
🎊 +1 overall
This message was automatically generated. |
|
💔 -1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
@goiri please help me review the code again, thank you very much! |
| subClustersActive = getActiveSubclusters(); | ||
| } catch (Exception e) { | ||
| LOG.error("Cannot get nodes: {}", e.getMessage()); | ||
| LOG.error("Cannot get nodes: {}", e.getMessage(), e); |
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.
Do we need the full stack trace?
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.
This part does not require full stack trace. I will refactor this part of the code to use invokeConcurrent.
|
🎊 +1 overall
This message was automatically generated. |
|
@goiri Please help me review the code again, thank you very much! |
| }); | ||
|
|
||
| result.setNodeToLabels(nodeToLabels); | ||
| return result; |
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.
It seems cleaner to do:
return new NodeToLabelsInfo(nodeToLabels);
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.
I will fix it.
| nodeLabels.put("node1", cpuNode); | ||
| nodeLabels.put("node2", gpuNode); | ||
| info.setNodeToLabels(nodeLabels); | ||
| return info; |
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.
return new NodeToLabelsInfo(nodeLabels);
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.
I will fix it.
| } | ||
| } | ||
|
|
||
| public NodeLabelsInfo(HashSet<NodeLabel> nodeLabels) { |
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.
Set<NodeLabel> nodeLabels or Collection<NodeLabel> nodeLabels
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.
Thanks for your suggestion, I will fix it.
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.
Refactor this method using Collection.
|
💔 -1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
|
@goiri Please help me to review the code again, thank you very much! |
|
@goiri Thanks a lot for your help reviewing the code, I'll follow up with YARN-11220 after this pr is done. |
|
@goiri Thanks for your help reviewing the code! |
JIRA:YARN-11212. [Federation] Add getNodeToLabels REST APIs for Router.