YARN-2827. Fixed bugs in "yarn queue" CLI. Contributed by Wangda Tan.

This commit is contained in:
Vinod Kumar Vavilapalli 2014-11-07 11:56:11 -08:00
parent 2ac1be7dec
commit a71e9302a9
3 changed files with 43 additions and 20 deletions

View File

@ -898,6 +898,8 @@ Release 2.6.0 - UNRELEASED
not mapped to queues by making default capacities per label to be zero. not mapped to queues by making default capacities per label to be zero.
(Wangda Tan via vinodkv) (Wangda Tan via vinodkv)
YARN-2827. Fixed bugs in "yarn queue" CLI. (Wangda Tan via vinodkv)
Release 2.5.2 - UNRELEASED Release 2.5.2 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -52,16 +52,11 @@ public static void main(String[] args) throws Exception {
@Override @Override
public int run(String[] args) throws Exception { public int run(String[] args) throws Exception {
Options opts = new Options(); Options opts = new Options();
int exitCode = -1;
if (args.length > 0) { opts.addOption(STATUS_CMD, true,
opts.addOption(STATUS_CMD, true, "List queue information about given queue.");
"List queue information about given queue."); opts.addOption(HELP_CMD, false, "Displays help for all commands.");
opts.addOption(HELP_CMD, false, "Displays help for all commands."); opts.getOption(STATUS_CMD).setArgName("Queue Name");
opts.getOption(STATUS_CMD).setArgName("Queue Name");
} else {
syserr.println("Invalid Command usage. Command must start with 'queue'");
return exitCode;
}
CommandLine cliParser = null; CommandLine cliParser = null;
try { try {
@ -69,23 +64,23 @@ public int run(String[] args) throws Exception {
} catch (MissingArgumentException ex) { } catch (MissingArgumentException ex) {
sysout.println("Missing argument for options"); sysout.println("Missing argument for options");
printUsage(opts); printUsage(opts);
return exitCode; return -1;
} }
if (cliParser.hasOption(STATUS_CMD)) { if (cliParser.hasOption(STATUS_CMD)) {
if (args.length != 3) { if (args.length != 2) {
printUsage(opts); printUsage(opts);
return exitCode; return -1;
} }
listQueue(cliParser.getOptionValue(STATUS_CMD)); return listQueue(cliParser.getOptionValue(STATUS_CMD));
} else if (cliParser.hasOption(HELP_CMD)) { } else if (cliParser.hasOption(HELP_CMD)) {
printUsage(opts); printUsage(opts);
return 0; return 0;
} else { } else {
syserr.println("Invalid Command Usage : "); syserr.println("Invalid Command Usage : ");
printUsage(opts); printUsage(opts);
return -1;
} }
return 0;
} }
/** /**
@ -105,13 +100,22 @@ void printUsage(Options opts) {
* @throws YarnException * @throws YarnException
* @throws IOException * @throws IOException
*/ */
private void listQueue(String queueName) throws YarnException, IOException { private int listQueue(String queueName) throws YarnException, IOException {
int rc;
PrintWriter writer = new PrintWriter(sysout); PrintWriter writer = new PrintWriter(sysout);
QueueInfo queueInfo = client.getQueueInfo(queueName); QueueInfo queueInfo = client.getQueueInfo(queueName);
writer.println("Queue Information : "); if (queueInfo != null) {
printQueueInfo(writer, queueInfo); writer.println("Queue Information : ");
printQueueInfo(writer, queueInfo);
rc = 0;
} else {
writer.println("Cannot get queue from RM by queueName = " + queueName
+ ", please check.");
rc = -1;
}
writer.flush(); writer.flush();
return rc;
} }
private void printQueueInfo(PrintWriter writer, QueueInfo queueInfo) { private void printQueueInfo(PrintWriter writer, QueueInfo queueInfo) {

View File

@ -1247,7 +1247,7 @@ public void testGetQueueInfo() throws Exception {
QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f, QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f,
null, null, QueueState.RUNNING, nodeLabels, "GPU"); null, null, QueueState.RUNNING, nodeLabels, "GPU");
when(client.getQueueInfo(any(String.class))).thenReturn(queueInfo); when(client.getQueueInfo(any(String.class))).thenReturn(queueInfo);
int result = cli.run(new String[] { "queue", "-status", "queueA" }); int result = cli.run(new String[] { "-status", "queueA" });
assertEquals(0, result); assertEquals(0, result);
verify(client).getQueueInfo("queueA"); verify(client).getQueueInfo("queueA");
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -1271,7 +1271,7 @@ public void testGetQueueInfoWithEmptyNodeLabel() throws Exception {
QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f, QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f,
null, null, QueueState.RUNNING, null, null); null, null, QueueState.RUNNING, null, null);
when(client.getQueueInfo(any(String.class))).thenReturn(queueInfo); when(client.getQueueInfo(any(String.class))).thenReturn(queueInfo);
int result = cli.run(new String[] { "queue", "-status", "queueA" }); int result = cli.run(new String[] { "-status", "queueA" });
assertEquals(0, result); assertEquals(0, result);
verify(client).getQueueInfo("queueA"); verify(client).getQueueInfo("queueA");
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -1288,6 +1288,23 @@ public void testGetQueueInfoWithEmptyNodeLabel() throws Exception {
String queueInfoStr = baos.toString("UTF-8"); String queueInfoStr = baos.toString("UTF-8");
Assert.assertEquals(queueInfoStr, sysOutStream.toString()); Assert.assertEquals(queueInfoStr, sysOutStream.toString());
} }
@Test
public void testGetQueueInfoWithNonExistedQueue() throws Exception {
String queueName = "non-existed-queue";
QueueCLI cli = createAndGetQueueCLI();
when(client.getQueueInfo(any(String.class))).thenReturn(null);
int result = cli.run(new String[] { "-status", queueName });
assertEquals(-1, result);;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
pw.println("Cannot get queue from RM by queueName = " + queueName
+ ", please check.");
pw.close();
String queueInfoStr = baos.toString("UTF-8");
Assert.assertEquals(queueInfoStr, sysOutStream.toString());
}
private void verifyUsageInfo(YarnCLI cli) throws Exception { private void verifyUsageInfo(YarnCLI cli) throws Exception {
cli.setSysErrPrintStream(sysErr); cli.setSysErrPrintStream(sysErr);