YARN-390. Merge r1449980 from trunk.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1449986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c9ceb03b2
commit
dbb624ed74
|
@ -24,6 +24,9 @@ Release 2.0.4-beta - UNRELEASED
|
|||
YARN-391. Formatting fixes for LCEResourceHandler classes.
|
||||
(Steve Loughran via sseth)
|
||||
|
||||
YARN-390. ApplicationCLI and NodeCLI hard-coded platform-specific line
|
||||
separator causes test failures on Windows. (Chris Nauroth via suresh)
|
||||
|
||||
Release 2.0.3-alpha - 2013-02-06
|
||||
|
||||
INCOMPATIBLE CHANGES
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package org.apache.hadoop.yarn.client.cli;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -31,7 +33,9 @@ import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
|
|||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
|
||||
public class ApplicationCLI extends YarnCLI {
|
||||
private static final String APPLICATIONS_PATTERN = "%30s\t%20s\t%10s\t%10s\t%18s\t%18s\t%35s\n";
|
||||
private static final String APPLICATIONS_PATTERN =
|
||||
"%30s\t%20s\t%10s\t%10s\t%18s\t%18s\t%35s" +
|
||||
System.getProperty("line.separator");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
ApplicationCLI cli = new ApplicationCLI();
|
||||
|
@ -123,37 +127,40 @@ public class ApplicationCLI extends YarnCLI {
|
|||
* @throws YarnRemoteException
|
||||
*/
|
||||
private void printApplicationReport(String applicationId)
|
||||
throws YarnRemoteException {
|
||||
throws YarnRemoteException, IOException {
|
||||
ApplicationReport appReport = client.getApplicationReport(ConverterUtils
|
||||
.toApplicationId(applicationId));
|
||||
StringBuffer appReportStr = new StringBuffer();
|
||||
// Use PrintWriter.println, which uses correct platform line ending.
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter appReportStr = new PrintWriter(baos);
|
||||
if (appReport != null) {
|
||||
appReportStr.append("Application Report : ");
|
||||
appReportStr.append("\n\tApplication-Id : ");
|
||||
appReportStr.append(appReport.getApplicationId());
|
||||
appReportStr.append("\n\tApplication-Name : ");
|
||||
appReportStr.append(appReport.getName());
|
||||
appReportStr.append("\n\tUser : ");
|
||||
appReportStr.append(appReport.getUser());
|
||||
appReportStr.append("\n\tQueue : ");
|
||||
appReportStr.append(appReport.getQueue());
|
||||
appReportStr.append("\n\tStart-Time : ");
|
||||
appReportStr.append(appReport.getStartTime());
|
||||
appReportStr.append("\n\tFinish-Time : ");
|
||||
appReportStr.append(appReport.getFinishTime());
|
||||
appReportStr.append("\n\tState : ");
|
||||
appReportStr.append(appReport.getYarnApplicationState());
|
||||
appReportStr.append("\n\tFinal-State : ");
|
||||
appReportStr.append(appReport.getFinalApplicationStatus());
|
||||
appReportStr.append("\n\tTracking-URL : ");
|
||||
appReportStr.append(appReport.getOriginalTrackingUrl());
|
||||
appReportStr.append("\n\tDiagnostics : ");
|
||||
appReportStr.append(appReport.getDiagnostics());
|
||||
appReportStr.println("Application Report : ");
|
||||
appReportStr.print("\tApplication-Id : ");
|
||||
appReportStr.println(appReport.getApplicationId());
|
||||
appReportStr.print("\tApplication-Name : ");
|
||||
appReportStr.println(appReport.getName());
|
||||
appReportStr.print("\tUser : ");
|
||||
appReportStr.println(appReport.getUser());
|
||||
appReportStr.print("\tQueue : ");
|
||||
appReportStr.println(appReport.getQueue());
|
||||
appReportStr.print("\tStart-Time : ");
|
||||
appReportStr.println(appReport.getStartTime());
|
||||
appReportStr.print("\tFinish-Time : ");
|
||||
appReportStr.println(appReport.getFinishTime());
|
||||
appReportStr.print("\tState : ");
|
||||
appReportStr.println(appReport.getYarnApplicationState());
|
||||
appReportStr.print("\tFinal-State : ");
|
||||
appReportStr.println(appReport.getFinalApplicationStatus());
|
||||
appReportStr.print("\tTracking-URL : ");
|
||||
appReportStr.println(appReport.getOriginalTrackingUrl());
|
||||
appReportStr.print("\tDiagnostics : ");
|
||||
appReportStr.print(appReport.getDiagnostics());
|
||||
} else {
|
||||
appReportStr.append("Application with id '" + applicationId
|
||||
appReportStr.print("Application with id '" + applicationId
|
||||
+ "' doesn't exist in RM.");
|
||||
}
|
||||
sysout.println(appReportStr.toString());
|
||||
appReportStr.close();
|
||||
sysout.println(baos.toString("UTF-8"));
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
package org.apache.hadoop.yarn.client.cli;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -31,7 +33,9 @@ import org.apache.hadoop.yarn.exceptions.YarnRemoteException;
|
|||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||
|
||||
public class NodeCLI extends YarnCLI {
|
||||
private static final String NODES_PATTERN = "%16s\t%10s\t%17s\t%26s\t%18s\n";
|
||||
private static final String NODES_PATTERN = "%16s\t%10s\t%17s\t%26s\t%18s" +
|
||||
System.getProperty("line.separator");
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
NodeCLI cli = new NodeCLI();
|
||||
cli.setSysOutPrintStream(System.out);
|
||||
|
@ -100,48 +104,51 @@ public class NodeCLI extends YarnCLI {
|
|||
* @param nodeIdStr
|
||||
* @throws YarnRemoteException
|
||||
*/
|
||||
private void printNodeStatus(String nodeIdStr) throws YarnRemoteException {
|
||||
private void printNodeStatus(String nodeIdStr) throws YarnRemoteException,
|
||||
IOException {
|
||||
NodeId nodeId = ConverterUtils.toNodeId(nodeIdStr);
|
||||
List<NodeReport> nodesReport = client.getNodeReports();
|
||||
StringBuffer nodeReportStr = new StringBuffer();
|
||||
// Use PrintWriter.println, which uses correct platform line ending.
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter nodeReportStr = new PrintWriter(baos);
|
||||
NodeReport nodeReport = null;
|
||||
for (NodeReport report : nodesReport) {
|
||||
if (!report.getNodeId().equals(nodeId)) {
|
||||
continue;
|
||||
}
|
||||
nodeReport = report;
|
||||
nodeReportStr.append("Node Report : ");
|
||||
nodeReportStr.append("\n\tNode-Id : ");
|
||||
nodeReportStr.append(nodeReport.getNodeId());
|
||||
nodeReportStr.append("\n\tRack : ");
|
||||
nodeReportStr.append(nodeReport.getRackName());
|
||||
nodeReportStr.append("\n\tNode-State : ");
|
||||
nodeReportStr.append(nodeReport.getNodeState());
|
||||
nodeReportStr.append("\n\tNode-Http-Address : ");
|
||||
nodeReportStr.append(nodeReport.getHttpAddress());
|
||||
nodeReportStr.append("\n\tHealth-Status(isNodeHealthy) : ");
|
||||
nodeReportStr.append(nodeReport.getNodeHealthStatus()
|
||||
nodeReportStr.println("Node Report : ");
|
||||
nodeReportStr.print("\tNode-Id : ");
|
||||
nodeReportStr.println(nodeReport.getNodeId());
|
||||
nodeReportStr.print("\tRack : ");
|
||||
nodeReportStr.println(nodeReport.getRackName());
|
||||
nodeReportStr.print("\tNode-State : ");
|
||||
nodeReportStr.println(nodeReport.getNodeState());
|
||||
nodeReportStr.print("\tNode-Http-Address : ");
|
||||
nodeReportStr.println(nodeReport.getHttpAddress());
|
||||
nodeReportStr.print("\tHealth-Status(isNodeHealthy) : ");
|
||||
nodeReportStr.println(nodeReport.getNodeHealthStatus()
|
||||
.getIsNodeHealthy());
|
||||
nodeReportStr.append("\n\tLast-Last-Health-Update : ");
|
||||
nodeReportStr.append(nodeReport.getNodeHealthStatus()
|
||||
nodeReportStr.print("\tLast-Last-Health-Update : ");
|
||||
nodeReportStr.println(nodeReport.getNodeHealthStatus()
|
||||
.getLastHealthReportTime());
|
||||
nodeReportStr.append("\n\tHealth-Report : ");
|
||||
nodeReportStr.print("\tHealth-Report : ");
|
||||
nodeReportStr
|
||||
.append(nodeReport.getNodeHealthStatus().getHealthReport());
|
||||
nodeReportStr.append("\n\tContainers : ");
|
||||
nodeReportStr.append(nodeReport.getNumContainers());
|
||||
nodeReportStr.append("\n\tMemory-Used : ");
|
||||
nodeReportStr.append((nodeReport.getUsed() == null) ? "0M"
|
||||
.println(nodeReport.getNodeHealthStatus().getHealthReport());
|
||||
nodeReportStr.print("\tContainers : ");
|
||||
nodeReportStr.println(nodeReport.getNumContainers());
|
||||
nodeReportStr.print("\tMemory-Used : ");
|
||||
nodeReportStr.println((nodeReport.getUsed() == null) ? "0M"
|
||||
: (nodeReport.getUsed().getMemory() + "M"));
|
||||
nodeReportStr.append("\n\tMemory-Capacity : ");
|
||||
nodeReportStr.append(nodeReport.getCapability().getMemory());
|
||||
nodeReportStr.print("\tMemory-Capacity : ");
|
||||
nodeReportStr.println(nodeReport.getCapability().getMemory());
|
||||
}
|
||||
|
||||
if (nodeReport == null) {
|
||||
nodeReportStr.append("Could not find the node report for node id : "
|
||||
nodeReportStr.print("Could not find the node report for node id : "
|
||||
+ nodeIdStr);
|
||||
}
|
||||
|
||||
sysout.println(nodeReportStr.toString());
|
||||
nodeReportStr.close();
|
||||
sysout.println(baos.toString("UTF-8"));
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import static org.mockito.Mockito.when;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -79,12 +80,21 @@ public class TestYarnCLI {
|
|||
int result = cli.run(new String[] { "-status", applicationId.toString() });
|
||||
assertEquals(0, result);
|
||||
verify(client).getApplicationReport(applicationId);
|
||||
String appReportStr = "Application Report : \n\t"
|
||||
+ "Application-Id : application_1234_0005\n\t"
|
||||
+ "Application-Name : appname\n\tUser : user\n\t"
|
||||
+ "Queue : queue\n\tStart-Time : 0\n\tFinish-Time : 0\n\t"
|
||||
+ "State : FINISHED\n\tFinal-State : SUCCEEDED\n\t"
|
||||
+ "Tracking-URL : N/A\n\tDiagnostics : diagnostics\n";
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter pw = new PrintWriter(baos);
|
||||
pw.println("Application Report : ");
|
||||
pw.println("\tApplication-Id : application_1234_0005");
|
||||
pw.println("\tApplication-Name : appname");
|
||||
pw.println("\tUser : user");
|
||||
pw.println("\tQueue : queue");
|
||||
pw.println("\tStart-Time : 0");
|
||||
pw.println("\tFinish-Time : 0");
|
||||
pw.println("\tState : FINISHED");
|
||||
pw.println("\tFinal-State : SUCCEEDED");
|
||||
pw.println("\tTracking-URL : N/A");
|
||||
pw.println("\tDiagnostics : diagnostics");
|
||||
pw.close();
|
||||
String appReportStr = baos.toString("UTF-8");
|
||||
Assert.assertEquals(appReportStr, sysOutStream.toString());
|
||||
verify(sysOut, times(1)).println(isA(String.class));
|
||||
}
|
||||
|
@ -105,16 +115,18 @@ public class TestYarnCLI {
|
|||
assertEquals(0, result);
|
||||
verify(client).getApplicationList();
|
||||
|
||||
StringBuffer appsReportStrBuf = new StringBuffer();
|
||||
appsReportStrBuf.append("Total Applications:1\n");
|
||||
appsReportStrBuf
|
||||
.append(" Application-Id\t Application-Name"
|
||||
+ "\t User\t Queue\t State\t "
|
||||
+ "Final-State\t Tracking-URL\n");
|
||||
appsReportStrBuf.append(" application_1234_0005\t "
|
||||
+ "appname\t user\t queue\t FINISHED\t "
|
||||
+ "SUCCEEDED\t N/A\n");
|
||||
Assert.assertEquals(appsReportStrBuf.toString(), sysOutStream.toString());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter pw = new PrintWriter(baos);
|
||||
pw.println("Total Applications:1");
|
||||
pw.print(" Application-Id\t Application-Name");
|
||||
pw.print("\t User\t Queue\t State\t ");
|
||||
pw.println("Final-State\t Tracking-URL");
|
||||
pw.print(" application_1234_0005\t ");
|
||||
pw.print("appname\t user\t queue\t FINISHED\t ");
|
||||
pw.println("SUCCEEDED\t N/A");
|
||||
pw.close();
|
||||
String appsReportStr = baos.toString("UTF-8");
|
||||
Assert.assertEquals(appsReportStr, sysOutStream.toString());
|
||||
verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
|
@ -137,18 +149,20 @@ public class TestYarnCLI {
|
|||
int result = cli.run(new String[] { "-list" });
|
||||
assertEquals(0, result);
|
||||
verify(client).getNodeReports();
|
||||
StringBuffer nodesReportStr = new StringBuffer();
|
||||
nodesReportStr.append("Total Nodes:3");
|
||||
nodesReportStr
|
||||
.append("\n Node-Id\tNode-State\tNode-Http-Address\t"
|
||||
+ "Health-Status(isNodeHealthy)\tRunning-Containers");
|
||||
nodesReportStr.append("\n host0:0\t RUNNING\t host1:8888"
|
||||
+ "\t false\t 0");
|
||||
nodesReportStr.append("\n host1:0\t RUNNING\t host1:8888"
|
||||
+ "\t false\t 0");
|
||||
nodesReportStr.append("\n host2:0\t RUNNING\t host1:8888"
|
||||
+ "\t false\t 0\n");
|
||||
Assert.assertEquals(nodesReportStr.toString(), sysOutStream.toString());
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
PrintWriter pw = new PrintWriter(baos);
|
||||
pw.println("Total Nodes:3");
|
||||
pw.print(" Node-Id\tNode-State\tNode-Http-Address\t");
|
||||
pw.println("Health-Status(isNodeHealthy)\tRunning-Containers");
|
||||
pw.print(" host0:0\t RUNNING\t host1:8888");
|
||||
pw.println("\t false\t 0");
|
||||
pw.print(" host1:0\t RUNNING\t host1:8888");
|
||||
pw.println("\t false\t 0");
|
||||
pw.print(" host2:0\t RUNNING\t host1:8888");
|
||||
pw.println("\t false\t 0");
|
||||
pw.close();
|
||||
String nodesReportStr = baos.toString("UTF-8");
|
||||
Assert.assertEquals(nodesReportStr, sysOutStream.toString());
|
||||
verify(sysOut, times(1)).write(any(byte[].class), anyInt(), anyInt());
|
||||
}
|
||||
|
||||
|
@ -163,11 +177,21 @@ public class TestYarnCLI {
|
|||
int result = cli.run(new String[] { "-status", nodeId.toString() });
|
||||
assertEquals(0, result);
|
||||
verify(client).getNodeReports();
|
||||
String nodeStatusStr = "Node Report : \n\tNode-Id : host0:0\n\t"
|
||||
+ "Rack : rack1\n\tNode-State : RUNNING\n\t"
|
||||
+ "Node-Http-Address : host1:8888\n\tHealth-Status(isNodeHealthy) "
|
||||
+ ": false\n\tLast-Last-Health-Update : 0\n\tHealth-Report : null"
|
||||
+ "\n\tContainers : 0\n\tMemory-Used : 0M\n\tMemory-Capacity : 0";
|
||||
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("\tHealth-Status(isNodeHealthy) : false");
|
||||
pw.println("\tLast-Last-Health-Update : 0");
|
||||
pw.println("\tHealth-Report : null");
|
||||
pw.println("\tContainers : 0");
|
||||
pw.println("\tMemory-Used : 0M");
|
||||
pw.println("\tMemory-Capacity : 0");
|
||||
pw.close();
|
||||
String nodeStatusStr = baos.toString("UTF-8");
|
||||
verify(sysOut, times(1)).println(isA(String.class));
|
||||
verify(sysOut).println(nodeStatusStr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue