From b9e82e27f5b25ec3b44bc9862870c9750f06d8bb Mon Sep 17 00:00:00 2001 From: Devaraj K Date: Tue, 24 Feb 2015 12:04:06 +0530 Subject: [PATCH] YARN-2797. Add -help to yarn logs and nodes CLI command. Contributed by Jagadesh Kiran N. (cherry picked from commit b610c68d4423a5a1ab342dc490cd0064f8983c07) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../org/apache/hadoop/yarn/client/cli/LogsCLI.java | 11 +++++++++-- .../org/apache/hadoop/yarn/client/cli/NodeCLI.java | 4 ++++ .../apache/hadoop/yarn/client/cli/TestLogsCLI.java | 1 + .../apache/hadoop/yarn/client/cli/TestYarnCLI.java | 1 + 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 5a557cddf2d..5d97f2fa4e9 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -285,6 +285,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 diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java index 0b34a46281b..d3b44a7764a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java +++ b/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; diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java index 22c240f7e38..d6036262b0c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/NodeCLI.java @@ -68,6 +68,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 " + @@ -118,6 +119,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); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java index ef9439d1a77..7ee918ee387 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java +++ b/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 ContainerId (must be specified if node"); pw.println(" address is specified)"); + pw.println(" -help Displays help for all commands."); pw.println(" -nodeAddress NodeAddress in the format nodename:port"); pw.println(" (must be specified if container id is"); pw.println(" specified)"); 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 fa81f14eb64..088969f6b32 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 @@ -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.");