hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vinayakum...@apache.org
Subject [17/30] hadoop git commit: YARN-2827. Fixed bugs in "yarn queue" CLI. Contributed by Wangda Tan.
Date Sun, 09 Nov 2014 16:54:19 GMT
YARN-2827. Fixed bugs in "yarn queue" CLI. Contributed by Wangda Tan.


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a71e9302
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a71e9302
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a71e9302

Branch: refs/heads/HDFS-EC
Commit: a71e9302a9dbbb702c8c50a4fdaa508f912561d6
Parents: 2ac1be7
Author: Vinod Kumar Vavilapalli <vinodkv@apache.org>
Authored: Fri Nov 7 11:56:11 2014 -0800
Committer: Vinod Kumar Vavilapalli <vinodkv@apache.org>
Committed: Fri Nov 7 11:56:11 2014 -0800

----------------------------------------------------------------------
 hadoop-yarn-project/CHANGES.txt                 |  2 +
 .../apache/hadoop/yarn/client/cli/QueueCLI.java | 40 +++++++++++---------
 .../hadoop/yarn/client/cli/TestYarnCLI.java     | 21 +++++++++-
 3 files changed, 43 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/a71e9302/hadoop-yarn-project/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt
index c48fb4f..a26bfb2 100644
--- a/hadoop-yarn-project/CHANGES.txt
+++ b/hadoop-yarn-project/CHANGES.txt
@@ -898,6 +898,8 @@ Release 2.6.0 - UNRELEASED
     not mapped to queues by making default capacities per label to be zero.
     (Wangda Tan via vinodkv)
 
+    YARN-2827. Fixed bugs in "yarn queue" CLI. (Wangda Tan via vinodkv)
+
 Release 2.5.2 - UNRELEASED
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a71e9302/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/QueueCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/QueueCLI.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/QueueCLI.java
index 3c74f13..4d50e7f 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/QueueCLI.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/QueueCLI.java
@@ -52,16 +52,11 @@ public class QueueCLI extends YarnCLI {
   @Override
   public int run(String[] args) throws Exception {
     Options opts = new Options();
-    int exitCode = -1;
-    if (args.length > 0) {
-      opts.addOption(STATUS_CMD, true,
-          "List queue information about given queue.");
-      opts.addOption(HELP_CMD, false, "Displays help for all commands.");
-      opts.getOption(STATUS_CMD).setArgName("Queue Name");
-    } else {
-      syserr.println("Invalid Command usage. Command must start with 'queue'");
-      return exitCode;
-    }
+
+    opts.addOption(STATUS_CMD, true,
+        "List queue information about given queue.");
+    opts.addOption(HELP_CMD, false, "Displays help for all commands.");
+    opts.getOption(STATUS_CMD).setArgName("Queue Name");
 
     CommandLine cliParser = null;
     try {
@@ -69,23 +64,23 @@ public class QueueCLI extends YarnCLI {
     } catch (MissingArgumentException ex) {
       sysout.println("Missing argument for options");
       printUsage(opts);
-      return exitCode;
+      return -1;
     }
 
     if (cliParser.hasOption(STATUS_CMD)) {
-      if (args.length != 3) {
+      if (args.length != 2) {
         printUsage(opts);
-        return exitCode;
+        return -1;
       }
-      listQueue(cliParser.getOptionValue(STATUS_CMD));
+      return listQueue(cliParser.getOptionValue(STATUS_CMD));
     } else if (cliParser.hasOption(HELP_CMD)) {
       printUsage(opts);
       return 0;
     } else {
       syserr.println("Invalid Command Usage : ");
       printUsage(opts);
+      return -1;
     }
-    return 0;
   }
 
   /**
@@ -105,13 +100,22 @@ public class QueueCLI extends YarnCLI {
    * @throws YarnException
    * @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);
 
     QueueInfo queueInfo = client.getQueueInfo(queueName);
-    writer.println("Queue Information : ");
-    printQueueInfo(writer, queueInfo);
+    if (queueInfo != null) {
+      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();
+    return rc;
   }
 
   private void printQueueInfo(PrintWriter writer, QueueInfo queueInfo) {

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a71e9302/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java
----------------------------------------------------------------------
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 adb58e8..d87277a 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
@@ -1247,7 +1247,7 @@ public class TestYarnCLI {
     QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f,
         null, null, QueueState.RUNNING, nodeLabels, "GPU");
     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);
     verify(client).getQueueInfo("queueA");
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -1271,7 +1271,7 @@ public class TestYarnCLI {
     QueueInfo queueInfo = QueueInfo.newInstance("queueA", 0.4f, 0.8f, 0.5f,
         null, null, QueueState.RUNNING, null, null);
     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);
     verify(client).getQueueInfo("queueA");
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -1288,6 +1288,23 @@ public class TestYarnCLI {
     String queueInfoStr = baos.toString("UTF-8");
     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 {
     cli.setSysErrPrintStream(sysErr);


Mime
View raw message