Browse Source

YARN-2797. Add -help to yarn logs and nodes CLI command. Contributed by
Jagadesh Kiran N.

Devaraj K 10 years ago
parent
commit
b610c68d44

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

@@ -321,6 +321,9 @@ Release 2.7.0 - UNRELEASED
     YARN-2797. TestWorkPreservingRMRestart should use ParametrizedSchedulerTestBase
     (Karthik Kambatla via xgong)
 
+    YARN-2797. Add -help to yarn logs and nodes CLI command. 
+    (Jagadesh Kiran N via devaraj)
+
   OPTIMIZATIONS
 
     YARN-2990. FairScheduler's delay-scheduling always waits for node-local and 

+ 9 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java

@@ -51,12 +51,15 @@ public class LogsCLI extends Configured implements Tool {
   private static final String APPLICATION_ID_OPTION = "applicationId";
   private static final String NODE_ADDRESS_OPTION = "nodeAddress";
   private static final String APP_OWNER_OPTION = "appOwner";
+  public static final String HELP_CMD = "help";
 
   @Override
   public int run(String[] args) throws Exception {
 
     Options opts = new Options();
-    Option appIdOpt = new Option(APPLICATION_ID_OPTION, true, "ApplicationId (required)");
+    opts.addOption(HELP_CMD, false, "Displays help for all commands.");
+    Option appIdOpt =
+        new Option(APPLICATION_ID_OPTION, true, "ApplicationId (required)");
     appIdOpt.setRequired(true);
     opts.addOption(appIdOpt);
     opts.addOption(CONTAINER_ID_OPTION, true,
@@ -71,6 +74,7 @@ public class LogsCLI extends Configured implements Tool {
     opts.getOption(APP_OWNER_OPTION).setArgName("Application Owner");
 
     Options printOpts = new Options();
+    printOpts.addOption(opts.getOption(HELP_CMD));
     printOpts.addOption(opts.getOption(CONTAINER_ID_OPTION));
     printOpts.addOption(opts.getOption(NODE_ADDRESS_OPTION));
     printOpts.addOption(opts.getOption(APP_OWNER_OPTION));
@@ -79,7 +83,10 @@ public class LogsCLI extends Configured implements Tool {
       printHelpMessage(printOpts);
       return -1;
     }
-
+    if (args[0].equals("-help")) {
+      printHelpMessage(printOpts);
+      return 0;
+    }
     CommandLineParser parser = new GnuParser();
     String appIdStr = null;
     String containerIdStr = null;

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java

@@ -69,6 +69,7 @@ public class NodeCLI extends YarnCLI {
   public int run(String[] args) throws Exception {
 
     Options opts = new Options();
+    opts.addOption(HELP_CMD, false, "Displays help for all commands.");
     opts.addOption(STATUS_CMD, true, "Prints the status report of the node.");
     opts.addOption(LIST_CMD, false, "List all running nodes. " +
         "Supports optional use of -states to filter nodes " +
@@ -120,6 +121,9 @@ public class NodeCLI extends YarnCLI {
         nodeStates.add(NodeState.RUNNING);
       }
       listClusterNodes(nodeStates);
+    } else if (cliParser.hasOption(HELP_CMD)) {
+      printUsage(opts);
+      return 0;
     } else {
       syserr.println("Invalid Command Usage : ");
       printUsage(opts);

+ 1 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java

@@ -149,6 +149,7 @@ public class TestLogsCLI {
     pw.println("                                 not specified)");
     pw.println(" -containerId <Container ID>     ContainerId (must be specified if node");
     pw.println("                                 address is specified)");
+    pw.println(" -help                           Displays help for all commands.");
     pw.println(" -nodeAddress <Node Address>     NodeAddress in the format nodename:port");
     pw.println("                                 (must be specified if container id is");
     pw.println("                                 specified)");

+ 1 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java

@@ -1500,6 +1500,7 @@ public class TestYarnCLI {
     PrintWriter pw = new PrintWriter(baos);
     pw.println("usage: node");
     pw.println(" -all               Works with -list to list all nodes.");
+    pw.println(" -help              Displays help for all commands.");
     pw.println(" -list              List all running nodes. Supports optional use of");
     pw.println("                    -states to filter nodes based on node state, all -all");
     pw.println("                    to list all nodes.");