From 9b879d713a7896e65a9ad627229a66e23c4f1f71 Mon Sep 17 00:00:00 2001 From: Vinod Kumar Vavilapalli Date: Fri, 31 Oct 2014 10:11:59 -0700 Subject: [PATCH] YARN-2778. Moved node-lables' reports to the yarn nodes CLI from the admin CLI. Contributed by Wangda Tan. (cherry picked from commit b6c1188b855d636586cd8fd0fb6d8e984bbfb0f5) --- hadoop-yarn-project/CHANGES.txt | 3 ++ .../hadoop/yarn/api/records/NodeReport.java | 1 + .../hadoop/yarn/client/cli/NodeCLI.java | 10 ++++ .../hadoop/yarn/client/cli/TestYarnCLI.java | 50 ++++++++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index a78f51e5ce3..edff7e2e862 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -390,6 +390,9 @@ Release 2.6.0 - UNRELEASED YARN-2779. Fixed ResourceManager to not require delegation tokens for communicating with Timeline Service. (Zhijie Shen via vinodkv) + YARN-2778. Moved node-lables' reports to the yarn nodes CLI from the admin + CLI. (Wangda Tan via vinodkv) + OPTIMIZATIONS BUG FIXES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/NodeReport.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/NodeReport.java index 8d4fac6a68e..df188f9c68c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/NodeReport.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/NodeReport.java @@ -64,6 +64,7 @@ public abstract class NodeReport { nodeReport.setNumContainers(numContainers); nodeReport.setHealthReport(healthReport); nodeReport.setLastHealthReportTime(lastHealthReportTime); + nodeReport.setNodeLabels(nodeLabels); return nodeReport; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java index f77c56f927a..fa2779ebc65 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java @@ -20,6 +20,8 @@ package org.apache.hadoop.yarn.client.cli; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -31,6 +33,7 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.hadoop.classification.InterfaceAudience.Private; import org.apache.hadoop.classification.InterfaceStability.Unstable; @@ -199,6 +202,13 @@ public class NodeCLI extends YarnCLI { : (nodeReport.getUsed().getVirtualCores() + " vcores")); nodeReportStr.print("\tCPU-Capacity : "); nodeReportStr.println(nodeReport.getCapability().getVirtualCores() + " vcores"); + nodeReportStr.print("\tNode-Labels : "); + + // Create a List for node labels since we need it get sorted + List nodeLabelsList = + new ArrayList(report.getNodeLabels()); + Collections.sort(nodeLabelsList); + nodeReportStr.println(StringUtils.join(nodeLabelsList.iterator(), ',')); } if (nodeReport == null) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 8405cc00e27..19ded9c3483 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -1112,6 +1112,40 @@ public class TestYarnCLI { @Test public void testNodeStatus() throws Exception { + NodeId nodeId = NodeId.newInstance("host0", 0); + NodeCLI cli = new NodeCLI(); + when(client.getNodeReports()).thenReturn( + getNodeReports(3, NodeState.RUNNING, false)); + cli.setClient(client); + cli.setSysOutPrintStream(sysOut); + cli.setSysErrPrintStream(sysErr); + int result = cli.run(new String[] { "-status", nodeId.toString() }); + assertEquals(0, result); + verify(client).getNodeReports(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintWriter pw = new PrintWriter(baos); + pw.println("Node Report : "); + pw.println("\tNode-Id : host0:0"); + pw.println("\tRack : rack1"); + pw.println("\tNode-State : RUNNING"); + pw.println("\tNode-Http-Address : host1:8888"); + pw.println("\tLast-Health-Update : " + + DateFormatUtils.format(new Date(0), "E dd/MMM/yy hh:mm:ss:SSzz")); + pw.println("\tHealth-Report : "); + pw.println("\tContainers : 0"); + pw.println("\tMemory-Used : 0MB"); + pw.println("\tMemory-Capacity : 0MB"); + pw.println("\tCPU-Used : 0 vcores"); + pw.println("\tCPU-Capacity : 0 vcores"); + pw.println("\tNode-Labels : a,b,c,x,y,z"); + pw.close(); + String nodeStatusStr = baos.toString("UTF-8"); + verify(sysOut, times(1)).println(isA(String.class)); + verify(sysOut).println(nodeStatusStr); + } + + @Test + public void testNodeStatusWithEmptyNodeLabels() throws Exception { NodeId nodeId = NodeId.newInstance("host0", 0); NodeCLI cli = new NodeCLI(); when(client.getNodeReports()).thenReturn( @@ -1137,6 +1171,7 @@ public class TestYarnCLI { pw.println("\tMemory-Capacity : 0MB"); pw.println("\tCPU-Used : 0 vcores"); pw.println("\tCPU-Capacity : 0 vcores"); + pw.println("\tNode-Labels : "); pw.close(); String nodeStatusStr = baos.toString("UTF-8"); verify(sysOut, times(1)).println(isA(String.class)); @@ -1206,15 +1241,26 @@ public class TestYarnCLI { cli.run(new String[] { "application" }); verify(sysErr).println("Invalid Command Usage : "); } - + private List getNodeReports(int noOfNodes, NodeState state) { + return getNodeReports(noOfNodes, state, true); + } + + private List getNodeReports(int noOfNodes, NodeState state, + boolean emptyNodeLabel) { List nodeReports = new ArrayList(); for (int i = 0; i < noOfNodes; i++) { + Set nodeLabels = null; + if (!emptyNodeLabel) { + // node labels is not ordered, but when we output it, it should be + // ordered + nodeLabels = ImmutableSet.of("c", "b", "a", "x", "z", "y"); + } NodeReport nodeReport = NodeReport.newInstance(NodeId .newInstance("host" + i, 0), state, "host" + 1 + ":8888", "rack1", Records.newRecord(Resource.class), Records - .newRecord(Resource.class), 0, "", 0, null); + .newRecord(Resource.class), 0, "", 0, nodeLabels); nodeReports.add(nodeReport); } return nodeReports;