Skip to content

Commit

Permalink
YARN-8103. Add CLI interface to query node attributes. Contributed by…
Browse files Browse the repository at this point in the history
… Bibin A Chundatt.
  • Loading branch information
naga-apache authored and sunilgovind committed Sep 12, 2018
1 parent 7618342 commit eb08543
Show file tree
Hide file tree
Showing 23 changed files with 1,049 additions and 452 deletions.
Expand Up @@ -19,6 +19,7 @@
package org.apache.hadoop.yarn.sls.nodemanager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -220,16 +221,9 @@ public Map<String, Long> getAllocationTagsWithCount() {
return null;
}


@Override
public void setNodeAttributes(String prefix,
Set<NodeAttribute> nodeAttributes) {

}

@Override
public Map<String, Set<NodeAttribute>> getAllNodeAttributes() {
return null;
public Set<NodeAttribute> getAllNodeAttributes() {
return Collections.emptySet();
}

@Override
Expand Down
Expand Up @@ -209,13 +209,7 @@ public Map<String, Long> getAllocationTagsWithCount() {
}

@Override
public void setNodeAttributes(String prefix,
Set<NodeAttribute> nodeAttributes) {
node.setNodeAttributes(prefix, nodeAttributes);
}

@Override
public Map<String, Set<NodeAttribute>> getAllNodeAttributes() {
public Set<NodeAttribute> getAllNodeAttributes() {
return node.getAllNodeAttributes();
}

Expand Down
4 changes: 2 additions & 2 deletions hadoop-yarn-project/hadoop-yarn/bin/yarn
Expand Up @@ -55,7 +55,7 @@ function hadoop_usage
hadoop_add_subcommand "timelinereader" client "run the timeline reader server"
hadoop_add_subcommand "timelineserver" daemon "run the timeline server"
hadoop_add_subcommand "top" client "view cluster information"
hadoop_add_subcommand "node-attributes" "map node to attibutes"
hadoop_add_subcommand "nodeattributes" client "node attributes cli client"
hadoop_add_subcommand "version" client "print the version"
hadoop_generate_usage "${HADOOP_SHELL_EXECNAME}" true
}
Expand Down Expand Up @@ -187,7 +187,7 @@ ${HADOOP_COMMON_HOME}/${HADOOP_COMMON_LIB_JARS_DIR}"
hadoop_add_classpath "$HADOOP_YARN_HOME/$YARN_DIR/timelineservice/lib/*"
HADOOP_CLASSNAME='org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderServer'
;;
node-attributes)
nodeattributes)
HADOOP_SUBCMD_SUPPORTDAEMONIZATION="false"
HADOOP_CLASSNAME='org.apache.hadoop.yarn.client.cli.NodeAttributesCLI'
;;
Expand Down
Expand Up @@ -258,4 +258,17 @@ public NodeUpdateType getNodeUpdateType() {
* Set the node update type (null indicates absent node update type).
* */
public void setNodeUpdateType(NodeUpdateType nodeUpdateType) {}

/**
* Set the node attributes of node.
*
* @param nodeAttributes set of node attributes.
*/
public abstract void setNodeAttributes(Set<NodeAttribute> nodeAttributes);

/**
* Get node attributes of node.
* @return the set of node attributes.
*/
public abstract Set<NodeAttribute> getNodeAttributes();
}
Expand Up @@ -355,6 +355,7 @@ message NodeReportProto {
optional ResourceUtilizationProto node_utilization = 12;
optional uint32 decommissioning_timeout = 13;
optional NodeUpdateTypeProto node_update_type = 14;
repeated NodeAttributeProto node_attributes = 15;
}

message NodeIdToLabelsProto {
Expand Down
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.yarn.api.records.NodeAttributeInfo;
import org.apache.hadoop.yarn.api.records.NodeLabel;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.exceptions.YarnException;
Expand All @@ -52,6 +53,7 @@ public class ClusterCLI extends YarnCLI {
public static final String LIST_LABELS_CMD = "list-node-labels";
public static final String DIRECTLY_ACCESS_NODE_LABEL_STORE =
"directly-access-node-label-store";
public static final String LIST_CLUSTER_ATTRIBUTES="list-node-attributes";
public static final String CMD = "cluster";
private boolean accessLocal = false;
static CommonNodeLabelsManager localNodeLabelsManager = null;
Expand All @@ -71,6 +73,8 @@ public int run(String[] args) throws Exception {

opts.addOption("lnl", LIST_LABELS_CMD, false,
"List cluster node-label collection");
opts.addOption("lna", LIST_CLUSTER_ATTRIBUTES, false,
"List cluster node-attribute collection");
opts.addOption("h", HELP_CMD, false, "Displays help for all commands.");
opts.addOption("dnl", DIRECTLY_ACCESS_NODE_LABEL_STORE, false,
"This is DEPRECATED, will be removed in future releases. Directly access node label store, "
Expand Down Expand Up @@ -102,6 +106,8 @@ public int run(String[] args) throws Exception {

if (parsedCli.hasOption(LIST_LABELS_CMD)) {
printClusterNodeLabels();
} else if(parsedCli.hasOption(LIST_CLUSTER_ATTRIBUTES)){
printClusterNodeAttributes();
} else if (parsedCli.hasOption(HELP_CMD)) {
printUsage(opts);
return 0;
Expand All @@ -112,6 +118,17 @@ public int run(String[] args) throws Exception {
return 0;
}

private void printClusterNodeAttributes() throws IOException, YarnException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(
new OutputStreamWriter(baos, Charset.forName("UTF-8")));
for (NodeAttributeInfo attribute : client.getClusterAttributes()) {
pw.println(attribute.toString());
}
pw.close();
sysout.println(baos.toString("UTF-8"));
}

void printClusterNodeLabels() throws YarnException, IOException {
List<NodeLabel> nodeLabels = null;
if (accessLocal) {
Expand Down

0 comments on commit eb08543

Please sign in to comment.