|
@@ -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<NodeReport> getNodeReports(int noOfNodes, NodeState state) {
|
|
|
+ return getNodeReports(noOfNodes, state, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<NodeReport> getNodeReports(int noOfNodes, NodeState state,
|
|
|
+ boolean emptyNodeLabel) {
|
|
|
List<NodeReport> nodeReports = new ArrayList<NodeReport>();
|
|
|
|
|
|
for (int i = 0; i < noOfNodes; i++) {
|
|
|
+ Set<String> 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;
|