浏览代码

YARN-1787. Fixed help messages for applicationattempt and container sub-commands in bin/yarn. Contributed by Zhijie Shen.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1575482 13f79535-47bb-0310-9956-ffa450edef68
Vinod Kumar Vavilapalli 11 年之前
父节点
当前提交
874cc955e0

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -428,6 +428,9 @@ Release 2.4.0 - UNRELEASED
     completed container statuses when NodeManager is forced to resync by the
     completed container statuses when NodeManager is forced to resync by the
     ResourceManager. (Jian He via vinodkv) 
     ResourceManager. (Jian He via vinodkv) 
 
 
+    YARN-1787. Fixed help messages for applicationattempt and container
+    sub-commands in bin/yarn. (Zhijie Shen via vinodkv)
+
 Release 2.3.1 - UNRELEASED
 Release 2.3.1 - UNRELEASED
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 75 - 70
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java

@@ -80,47 +80,59 @@ public class ApplicationCLI extends YarnCLI {
 
 
   @Override
   @Override
   public int run(String[] args) throws Exception {
   public int run(String[] args) throws Exception {
-
     Options opts = new Options();
     Options opts = new Options();
-    opts.addOption(STATUS_CMD, true,
-        "Prints the status of the application.");
-    if (args.length > 0
-        && args[0].compareToIgnoreCase(APPLICATION_ATTEMPT) == 0) {
-      opts.addOption(LIST_CMD, true,
-          "List application attempts for aplication from AHS. ");
-    } else if (args.length > 0 && args[0].compareToIgnoreCase("container") == 0) {
-      opts.addOption(LIST_CMD, true,
-          "List containers for application attempts from AHS. ");
-    } else {
-      opts.addOption(LIST_CMD, false, "List applications from the RM. "
+    String title = null;
+    if (args.length > 0 && args[0].equalsIgnoreCase(APPLICATION)) {
+      title = APPLICATION;
+      opts.addOption(STATUS_CMD, true,
+          "Prints the status of the application.");
+      opts.addOption(LIST_CMD, false, "List applications. "
           + "Supports optional use of -appTypes to filter applications "
           + "Supports optional use of -appTypes to filter applications "
           + "based on application type, "
           + "based on application type, "
-          + "and -appStates to filter applications based on application state");
+          + "and -appStates to filter applications based on application state.");
+      opts.addOption(KILL_CMD, true, "Kills the application.");
+      opts.addOption(MOVE_TO_QUEUE_CMD, true, "Moves the application to a "
+          + "different queue.");
+      opts.addOption(QUEUE_CMD, true, "Works with the movetoqueue command to"
+          + " specify which queue to move an application to.");
+      opts.addOption(HELP_CMD, false, "Displays help for all commands.");
+      Option appTypeOpt = new Option(APP_TYPE_CMD, true, "Works with -list to "
+          + "filter applications based on "
+          + "input comma-separated list of application types.");
+      appTypeOpt.setValueSeparator(',');
+      appTypeOpt.setArgs(Option.UNLIMITED_VALUES);
+      appTypeOpt.setArgName("Types");
+      opts.addOption(appTypeOpt);
+      Option appStateOpt = new Option(APP_STATE_CMD, true, "Works with -list "
+          + "to filter applications based on input comma-separated list of "
+          + "application states. " + getAllValidApplicationStates());
+      appStateOpt.setValueSeparator(',');
+      appStateOpt.setArgs(Option.UNLIMITED_VALUES);
+      appStateOpt.setArgName("States");
+      opts.addOption(appStateOpt);
+      opts.getOption(KILL_CMD).setArgName("Application ID");
+      opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID");
+      opts.getOption(QUEUE_CMD).setArgName("Queue Name");
+      opts.getOption(STATUS_CMD).setArgName("Application ID");
+    } else if (args.length > 0 && args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
+      title = APPLICATION_ATTEMPT;
+      opts.addOption(STATUS_CMD, true,
+          "Prints the status of the application attempt.");
+      opts.addOption(LIST_CMD, true,
+          "List application attempts for aplication.");
+      opts.addOption(HELP_CMD, false, "Displays help for all commands.");
+      opts.getOption(STATUS_CMD).setArgName("Application Attempt ID");
+      opts.getOption(LIST_CMD).setArgName("Application ID");
+    } else if (args.length > 0 && args[0].equalsIgnoreCase(CONTAINER)) {
+      title = CONTAINER;
+      opts.addOption(STATUS_CMD, true,
+          "Prints the status of the container.");
+      opts.addOption(LIST_CMD, true,
+          "List containers for application attempt.");
+      opts.addOption(HELP_CMD, false, "Displays help for all commands.");
+      opts.getOption(STATUS_CMD).setArgName("Container ID");
+      opts.getOption(LIST_CMD).setArgName("Application Attempt ID");
     }
     }
-    opts.addOption(KILL_CMD, true, "Kills the application.");
-    opts.addOption(MOVE_TO_QUEUE_CMD, true, "Moves the application to a "
-        + "different queue.");
-    opts.addOption(QUEUE_CMD, true, "Works with the movetoqueue command to"
-        + " specify which queue to move an application to.");
-    opts.addOption(HELP_CMD, false, "Displays help for all commands.");
-    Option appTypeOpt = new Option(APP_TYPE_CMD, true, "Works with -list to "
-        + "filter applications based on "
-        + "input comma-separated list of application types.");
-    appTypeOpt.setValueSeparator(',');
-    appTypeOpt.setArgs(Option.UNLIMITED_VALUES);
-    appTypeOpt.setArgName("Types");
-    opts.addOption(appTypeOpt);
-    Option appStateOpt = new Option(APP_STATE_CMD, true, "Works with -list "
-        + "to filter applications based on input comma-separated list of "
-        + "application states. " + getAllValidApplicationStates());
-    appStateOpt.setValueSeparator(',');
-    appStateOpt.setArgs(Option.UNLIMITED_VALUES);
-    appStateOpt.setArgName("States");
-    opts.addOption(appStateOpt);
-    opts.getOption(KILL_CMD).setArgName("Application ID");
-    opts.getOption(MOVE_TO_QUEUE_CMD).setArgName("Application ID");
-    opts.getOption(QUEUE_CMD).setArgName("Queue Name");
-    opts.getOption(STATUS_CMD).setArgName("Application ID");
 
 
     int exitCode = -1;
     int exitCode = -1;
     CommandLine cliParser = null;
     CommandLine cliParser = null;
@@ -128,43 +140,24 @@ public class ApplicationCLI extends YarnCLI {
       cliParser = new GnuParser().parse(opts, args);
       cliParser = new GnuParser().parse(opts, args);
     } catch (MissingArgumentException ex) {
     } catch (MissingArgumentException ex) {
       sysout.println("Missing argument for options");
       sysout.println("Missing argument for options");
-      printUsage(opts);
+      printUsage(title, opts);
       return exitCode;
       return exitCode;
     }
     }
 
 
     if (cliParser.hasOption(STATUS_CMD)) {
     if (cliParser.hasOption(STATUS_CMD)) {
-      if ((args[0].compareToIgnoreCase(APPLICATION) == 0)
-          || (args[0].compareToIgnoreCase(APPLICATION_ATTEMPT) == 0)
-          || (args[0].compareToIgnoreCase(CONTAINER) == 0)) {
-        if (args.length != 3) {
-          printUsage(opts);
-          return exitCode;
-        }
-      } else if (args.length != 2) {
-        printUsage(opts);
+      if (args.length != 3) {
+        printUsage(title, opts);
         return exitCode;
         return exitCode;
       }
       }
-      if (args[0].compareToIgnoreCase(APPLICATION_ATTEMPT) == 0) {
+      if (args[0].equalsIgnoreCase(APPLICATION)) {
+        printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
+      } else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
         printApplicationAttemptReport(cliParser.getOptionValue(STATUS_CMD));
         printApplicationAttemptReport(cliParser.getOptionValue(STATUS_CMD));
-      } else if (args[0].compareToIgnoreCase(CONTAINER) == 0) {
+      } else if (args[0].equalsIgnoreCase(CONTAINER)) {
         printContainerReport(cliParser.getOptionValue(STATUS_CMD));
         printContainerReport(cliParser.getOptionValue(STATUS_CMD));
-      } else {
-        printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
       }
       }
     } else if (cliParser.hasOption(LIST_CMD)) {
     } else if (cliParser.hasOption(LIST_CMD)) {
-      if (args[0].compareToIgnoreCase(APPLICATION_ATTEMPT) == 0) {
-        if (args.length != 3) {
-          printUsage(opts);
-          return exitCode;
-        }
-        listApplicationAttempts(cliParser.getOptionValue(LIST_CMD));
-      } else if (args[0].compareToIgnoreCase(CONTAINER) == 0) {
-        if (args.length != 3) {
-          printUsage(opts);
-          return exitCode;
-        }
-        listContainers(cliParser.getOptionValue(LIST_CMD));
-      } else {
+      if (args[0].equalsIgnoreCase(APPLICATION)) {
         allAppStates = false;
         allAppStates = false;
         Set<String> appTypes = new HashSet<String>();
         Set<String> appTypes = new HashSet<String>();
         if (cliParser.hasOption(APP_TYPE_CMD)) {
         if (cliParser.hasOption(APP_TYPE_CMD)) {
@@ -203,10 +196,22 @@ public class ApplicationCLI extends YarnCLI {
           }
           }
         }
         }
         listApplications(appTypes, appStates);
         listApplications(appTypes, appStates);
+      } else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
+        if (args.length != 3) {
+          printUsage(title, opts);
+          return exitCode;
+        }
+        listApplicationAttempts(cliParser.getOptionValue(LIST_CMD));
+      } else if (args[0].equalsIgnoreCase(CONTAINER)) {
+        if (args.length != 3) {
+          printUsage(title, opts);
+          return exitCode;
+        }
+        listContainers(cliParser.getOptionValue(LIST_CMD));
       }
       }
     } else if (cliParser.hasOption(KILL_CMD)) {
     } else if (cliParser.hasOption(KILL_CMD)) {
       if (args.length != 3) {
       if (args.length != 3) {
-        printUsage(opts);
+        printUsage(title, opts);
         return exitCode;
         return exitCode;
       }
       }
       try{
       try{
@@ -216,17 +221,17 @@ public class ApplicationCLI extends YarnCLI {
       }
       }
     } else if (cliParser.hasOption(MOVE_TO_QUEUE_CMD)) {
     } else if (cliParser.hasOption(MOVE_TO_QUEUE_CMD)) {
       if (!cliParser.hasOption(QUEUE_CMD)) {
       if (!cliParser.hasOption(QUEUE_CMD)) {
-        printUsage(opts);
+        printUsage(title, opts);
         return exitCode;
         return exitCode;
       }
       }
       moveApplicationAcrossQueues(cliParser.getOptionValue(MOVE_TO_QUEUE_CMD),
       moveApplicationAcrossQueues(cliParser.getOptionValue(MOVE_TO_QUEUE_CMD),
           cliParser.getOptionValue(QUEUE_CMD));
           cliParser.getOptionValue(QUEUE_CMD));
     } else if (cliParser.hasOption(HELP_CMD)) {
     } else if (cliParser.hasOption(HELP_CMD)) {
-      printUsage(opts);
+      printUsage(title, opts);
       return 0;
       return 0;
     } else {
     } else {
       syserr.println("Invalid Command Usage : ");
       syserr.println("Invalid Command Usage : ");
-      printUsage(opts);
+      printUsage(title, opts);
     }
     }
     return 0;
     return 0;
   }
   }
@@ -237,8 +242,8 @@ public class ApplicationCLI extends YarnCLI {
    * @param opts
    * @param opts
    */
    */
   @VisibleForTesting
   @VisibleForTesting
-  void printUsage(Options opts) {
-    new HelpFormatter().printHelp("application", opts);
+  void printUsage(String title, Options opts) {
+    new HelpFormatter().printHelp(title, opts);
   }
   }
 
 
   /**
   /**

+ 133 - 33
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java

@@ -94,7 +94,7 @@ public class TestYarnCLI {
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
         newApplicationReport);
         newApplicationReport);
-    int result = cli.run(new String[] { "-status", applicationId.toString() });
+    int result = cli.run(new String[] { "application", "-status", applicationId.toString() });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplicationReport(applicationId);
     verify(client).getApplicationReport(applicationId);
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -289,7 +289,7 @@ public class TestYarnCLI {
         new ApplicationNotFoundException("History file for application"
         new ApplicationNotFoundException("History file for application"
             + applicationId + " is not found"));
             + applicationId + " is not found"));
     try {
     try {
-      cli.run(new String[] { "-status", applicationId.toString() });
+      cli.run(new String[] { "application", "-status", applicationId.toString() });
       Assert.fail();
       Assert.fail();
     } catch (Exception ex) {
     } catch (Exception ex) {
       Assert.assertTrue(ex instanceof ApplicationNotFoundException);
       Assert.assertTrue(ex instanceof ApplicationNotFoundException);
@@ -368,7 +368,7 @@ public class TestYarnCLI {
     appState1.add(YarnApplicationState.SUBMITTED);
     appState1.add(YarnApplicationState.SUBMITTED);
     when(client.getApplications(appType1, appState1)).thenReturn(
     when(client.getApplications(appType1, appState1)).thenReturn(
         getApplicationReports(applicationReports, appType1, appState1, false));
         getApplicationReports(applicationReports, appType1, appState1, false));
-    int result = cli.run(new String[] { "-list" });
+    int result = cli.run(new String[] { "application", "-list" });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType1, appState1);
     verify(client).getApplications(appType1, appState1);
 
 
@@ -423,8 +423,8 @@ public class TestYarnCLI {
     when(client.getApplications(appType2, appState2)).thenReturn(
     when(client.getApplications(appType2, appState2)).thenReturn(
         getApplicationReports(applicationReports, appType2, appState2, false));
         getApplicationReports(applicationReports, appType2, appState2, false));
     result =
     result =
-        cli.run(new String[] { "-list", "-appTypes", "YARN, ,,  NON-YARN",
-            "   ,, ,," });
+        cli.run(new String[] { "application", "-list", "-appTypes",
+            "YARN, ,,  NON-YARN", "   ,, ,," });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType2, appState2);
     verify(client).getApplications(appType2, appState2);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
@@ -458,8 +458,8 @@ public class TestYarnCLI {
     when(client.getApplications(appType3, appState3)).thenReturn(
     when(client.getApplications(appType3, appState3)).thenReturn(
         getApplicationReports(applicationReports, appType3, appState3, false));
         getApplicationReports(applicationReports, appType3, appState3, false));
     result =
     result =
-        cli.run(new String[] { "-list", "--appStates", "FINISHED ,, , FAILED",
-            ",,FINISHED" });
+        cli.run(new String[] { "application", "-list", "--appStates",
+            "FINISHED ,, , FAILED", ",,FINISHED" });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType3, appState3);
     verify(client).getApplications(appType3, appState3);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
@@ -501,8 +501,8 @@ public class TestYarnCLI {
     when(client.getApplications(appType4, appState4)).thenReturn(
     when(client.getApplications(appType4, appState4)).thenReturn(
         getApplicationReports(applicationReports, appType4, appState4, false));
         getApplicationReports(applicationReports, appType4, appState4, false));
     result =
     result =
-        cli.run(new String[] { "-list", "--appTypes", "YARN,NON-YARN",
-        "--appStates", "FINISHED ,, , FAILED" });
+        cli.run(new String[] { "application", "-list", "--appTypes",
+            "YARN,NON-YARN", "--appStates", "FINISHED ,, , FAILED" });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType2, appState2);
     verify(client).getApplications(appType2, appState2);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
@@ -527,7 +527,8 @@ public class TestYarnCLI {
     //Test command yarn application -list --appStates with invalid appStates
     //Test command yarn application -list --appStates with invalid appStates
     sysOutStream.reset();
     sysOutStream.reset();
     result =
     result =
-        cli.run(new String[] { "-list", "--appStates", "FINISHED ,, , INVALID" });
+        cli.run(new String[] { "application", "-list", "--appStates",
+            "FINISHED ,, , INVALID" });
     assertEquals(-1, result);
     assertEquals(-1, result);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
     pw = new PrintWriter(baos);
     pw = new PrintWriter(baos);
@@ -555,7 +556,8 @@ public class TestYarnCLI {
     when(client.getApplications(appType5, appState5)).thenReturn(
     when(client.getApplications(appType5, appState5)).thenReturn(
         getApplicationReports(applicationReports, appType5, appState5, true));
         getApplicationReports(applicationReports, appType5, appState5, true));
     result =
     result =
-        cli.run(new String[] { "-list", "--appStates", "FINISHED ,, , ALL" });
+        cli.run(new String[] { "application", "-list", "--appStates",
+            "FINISHED ,, , ALL" });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType5, appState5);
     verify(client).getApplications(appType5, appState5);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
@@ -614,8 +616,8 @@ public class TestYarnCLI {
     when(client.getApplications(appType6, appState6)).thenReturn(
     when(client.getApplications(appType6, appState6)).thenReturn(
         getApplicationReports(applicationReports, appType6, appState6, false));
         getApplicationReports(applicationReports, appType6, appState6, false));
     result =
     result =
-        cli.run(new String[] { "-list", "-appTypes", "YARN, ,,  NON-YARN",
-            "--appStates", "finished" });
+        cli.run(new String[] { "application", "-list", "-appTypes",
+            "YARN, ,,  NON-YARN", "--appStates", "finished" });
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).getApplications(appType6, appState6);
     verify(client).getApplications(appType6, appState6);
     baos = new ByteArrayOutputStream();
     baos = new ByteArrayOutputStream();
@@ -672,28 +674,88 @@ public class TestYarnCLI {
   public void testAppsHelpCommand() throws Exception {
   public void testAppsHelpCommand() throws Exception {
     ApplicationCLI cli = createAndGetAppCLI();
     ApplicationCLI cli = createAndGetAppCLI();
     ApplicationCLI spyCli = spy(cli);
     ApplicationCLI spyCli = spy(cli);
-    int result = spyCli.run(new String[] { "-help" });
+    int result = spyCli.run(new String[] { "application", "-help" });
     Assert.assertTrue(result == 0);
     Assert.assertTrue(result == 0);
-    verify(spyCli).printUsage(any(Options.class));
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
     Assert.assertEquals(createApplicationCLIHelpMessage(),
     Assert.assertEquals(createApplicationCLIHelpMessage(),
         sysOutStream.toString());
         sysOutStream.toString());
 
 
     sysOutStream.reset();
     sysOutStream.reset();
     ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
     ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
-    result =
-        cli.run(new String[] {"application", "-kill", applicationId.toString(), "args" });
-    verify(spyCli).printUsage(any(Options.class));
+    result = cli.run(
+        new String[] {"application", "-kill", applicationId.toString(), "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
     Assert.assertEquals(createApplicationCLIHelpMessage(),
     Assert.assertEquals(createApplicationCLIHelpMessage(),
         sysOutStream.toString());
         sysOutStream.toString());
 
 
     sysOutStream.reset();
     sysOutStream.reset();
     NodeId nodeId = NodeId.newInstance("host0", 0);
     NodeId nodeId = NodeId.newInstance("host0", 0);
-    result = cli.run(new String[] { "-status", nodeId.toString(), "args" });
-    verify(spyCli).printUsage(any(Options.class));
+    result = cli.run(
+        new String[] { "application", "-status", nodeId.toString(), "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
     Assert.assertEquals(createApplicationCLIHelpMessage(),
     Assert.assertEquals(createApplicationCLIHelpMessage(),
         sysOutStream.toString());
         sysOutStream.toString());
   }
   }
 
 
+  @Test (timeout = 10000)
+  public void testAppAttemptsHelpCommand() throws Exception {
+    ApplicationCLI cli = createAndGetAppCLI();
+    ApplicationCLI spyCli = spy(cli);
+    int result = spyCli.run(new String[] { "applicationattempt", "-help" });
+    Assert.assertTrue(result == 0);
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createApplicationAttemptCLIHelpMessage(),
+        sysOutStream.toString());
+
+    sysOutStream.reset();
+    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
+    result = cli.run(
+        new String[] {"applicationattempt", "-list", applicationId.toString(),
+            "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createApplicationAttemptCLIHelpMessage(),
+        sysOutStream.toString());
+
+    sysOutStream.reset();
+    ApplicationAttemptId appAttemptId =
+        ApplicationAttemptId.newInstance(applicationId, 6);
+    result = cli.run(
+        new String[] { "applicationattempt", "-status", appAttemptId.toString(),
+            "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createApplicationAttemptCLIHelpMessage(),
+        sysOutStream.toString());
+  }
+
+  @Test (timeout = 10000)
+  public void testContainersHelpCommand() throws Exception {
+    ApplicationCLI cli = createAndGetAppCLI();
+    ApplicationCLI spyCli = spy(cli);
+    int result = spyCli.run(new String[] { "container", "-help" });
+    Assert.assertTrue(result == 0);
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createContainerCLIHelpMessage(),
+        sysOutStream.toString());
+
+    sysOutStream.reset();
+    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
+    ApplicationAttemptId appAttemptId =
+        ApplicationAttemptId.newInstance(applicationId, 6);
+    result = cli.run(
+        new String[] {"container", "-list", appAttemptId.toString(), "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createContainerCLIHelpMessage(),
+        sysOutStream.toString());
+
+    sysOutStream.reset();
+    ContainerId containerId = ContainerId.newInstance(appAttemptId, 7);
+    result = cli.run(
+        new String[] { "container", "-status", containerId.toString(), "args" });
+    verify(spyCli).printUsage(any(String.class), any(Options.class));
+    Assert.assertEquals(createContainerCLIHelpMessage(),
+        sysOutStream.toString());
+  }
+
   @Test (timeout = 5000)
   @Test (timeout = 5000)
   public void testNodesHelpCommand() throws Exception {
   public void testNodesHelpCommand() throws Exception {
     NodeCLI nodeCLI = new NodeCLI();
     NodeCLI nodeCLI = new NodeCLI();
@@ -765,8 +827,8 @@ public class TestYarnCLI {
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
         newApplicationReport2);
         newApplicationReport2);
-    int result = cli.run(new String[] { "-movetoqueue", applicationId.toString(),
-        "-queue", "targetqueue"});
+    int result = cli.run(new String[] { "application", "-movetoqueue",
+        applicationId.toString(), "-queue", "targetqueue"});
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client, times(0)).moveApplicationAcrossQueues(
     verify(client, times(0)).moveApplicationAcrossQueues(
         any(ApplicationId.class), any(String.class));
         any(ApplicationId.class), any(String.class));
@@ -780,8 +842,8 @@ public class TestYarnCLI {
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
         FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
     when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(
         newApplicationReport);
         newApplicationReport);
-    result = cli.run(new String[] { "-movetoqueue", applicationId.toString(),
-        "-queue", "targetqueue"});
+    result = cli.run(new String[] { "application", "-movetoqueue",
+        applicationId.toString(), "-queue", "targetqueue"});
     assertEquals(0, result);
     assertEquals(0, result);
     verify(client).moveApplicationAcrossQueues(any(ApplicationId.class),
     verify(client).moveApplicationAcrossQueues(any(ApplicationId.class),
         any(String.class));
         any(String.class));
@@ -793,8 +855,8 @@ public class TestYarnCLI {
         .moveApplicationAcrossQueues(applicationId, "targetqueue");
         .moveApplicationAcrossQueues(applicationId, "targetqueue");
     cli = createAndGetAppCLI();
     cli = createAndGetAppCLI();
     try {
     try {
-      result = cli.run(new String[] { "-movetoqueue", applicationId.toString(),
-          "-queue", "targetqueue"});
+      result = cli.run(new String[] { "application", "-movetoqueue",
+          applicationId.toString(), "-queue", "targetqueue"});
       Assert.fail();
       Assert.fail();
     } catch (Exception ex) {
     } catch (Exception ex) {
       Assert.assertTrue(ex instanceof ApplicationNotFoundException);
       Assert.assertTrue(ex instanceof ApplicationNotFoundException);
@@ -1095,11 +1157,23 @@ public class TestYarnCLI {
   @Test
   @Test
   public void testMissingArguments() throws Exception {
   public void testMissingArguments() throws Exception {
     ApplicationCLI cli = createAndGetAppCLI();
     ApplicationCLI cli = createAndGetAppCLI();
-    int result = cli.run(new String[] { "-status" });
+    int result = cli.run(new String[] { "application", "-status" });
     Assert.assertEquals(result, -1);
     Assert.assertEquals(result, -1);
     Assert.assertEquals(String.format("Missing argument for options%n%1s",
     Assert.assertEquals(String.format("Missing argument for options%n%1s",
         createApplicationCLIHelpMessage()), sysOutStream.toString());
         createApplicationCLIHelpMessage()), sysOutStream.toString());
 
 
+    sysOutStream.reset();
+    result = cli.run(new String[] { "applicationattempt", "-status" });
+    Assert.assertEquals(result, -1);
+    Assert.assertEquals(String.format("Missing argument for options%n%1s",
+        createApplicationAttemptCLIHelpMessage()), sysOutStream.toString());
+
+    sysOutStream.reset();
+    result = cli.run(new String[] { "container", "-status" });
+    Assert.assertEquals(result, -1);
+    Assert.assertEquals(String.format("Missing argument for options%n%1s",
+        createContainerCLIHelpMessage()), sysOutStream.toString());
+
     sysOutStream.reset();
     sysOutStream.reset();
     NodeCLI nodeCLI = new NodeCLI();
     NodeCLI nodeCLI = new NodeCLI();
     nodeCLI.setClient(client);
     nodeCLI.setClient(client);
@@ -1113,7 +1187,7 @@ public class TestYarnCLI {
 
 
   private void verifyUsageInfo(YarnCLI cli) throws Exception {
   private void verifyUsageInfo(YarnCLI cli) throws Exception {
     cli.setSysErrPrintStream(sysErr);
     cli.setSysErrPrintStream(sysErr);
-    cli.run(new String[0]);
+    cli.run(new String[] { "application" });
     verify(sysErr).println("Invalid Command Usage : ");
     verify(sysErr).println("Invalid Command Usage : ");
   }
   }
 
 
@@ -1152,11 +1226,11 @@ public class TestYarnCLI {
     pw.println("                                 application types.");
     pw.println("                                 application types.");
     pw.println(" -help                           Displays help for all commands.");
     pw.println(" -help                           Displays help for all commands.");
     pw.println(" -kill <Application ID>          Kills the application.");
     pw.println(" -kill <Application ID>          Kills the application.");
-    pw.println(" -list                           List applications from the RM. Supports");
-    pw.println("                                 optional use of -appTypes to filter");
-    pw.println("                                 applications based on application type,");
-    pw.println("                                 and -appStates to filter applications");
-    pw.println("                                 based on application state");
+    pw.println(" -list                           List applications. Supports optional use");
+    pw.println("                                 of -appTypes to filter applications based");
+    pw.println("                                 on application type, and -appStates to");
+    pw.println("                                 filter applications based on application");
+    pw.println("                                 state.");
     pw.println(" -movetoqueue <Application ID>   Moves the application to a different");
     pw.println(" -movetoqueue <Application ID>   Moves the application to a different");
     pw.println("                                 queue.");
     pw.println("                                 queue.");
     pw.println(" -queue <Queue Name>             Works with the movetoqueue command to");
     pw.println(" -queue <Queue Name>             Works with the movetoqueue command to");
@@ -1168,6 +1242,32 @@ public class TestYarnCLI {
     return appsHelpStr;
     return appsHelpStr;
   }
   }
 
 
+  private String createApplicationAttemptCLIHelpMessage() throws IOException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    PrintWriter pw = new PrintWriter(baos);
+    pw.println("usage: applicationattempt");
+    pw.println(" -help                              Displays help for all commands.");
+    pw.println(" -list <Application ID>             List application attempts for");
+    pw.println("                                    aplication.");
+    pw.println(" -status <Application Attempt ID>   Prints the status of the application");
+    pw.println("                                    attempt.");
+    pw.close();
+    String appsHelpStr = baos.toString("UTF-8");
+    return appsHelpStr;
+  }
+
+  private String createContainerCLIHelpMessage() throws IOException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    PrintWriter pw = new PrintWriter(baos);
+    pw.println("usage: container");
+    pw.println(" -help                            Displays help for all commands.");
+    pw.println(" -list <Application Attempt ID>   List containers for application attempt.");
+    pw.println(" -status <Container ID>           Prints the status of the container.");
+    pw.close();
+    String appsHelpStr = baos.toString("UTF-8");
+    return appsHelpStr;
+  }
+
   private String createNodeCLIHelpMessage() throws IOException {
   private String createNodeCLIHelpMessage() throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     PrintWriter pw = new PrintWriter(baos);
     PrintWriter pw = new PrintWriter(baos);