hadoop-yarn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vino...@apache.org
Subject svn commit: r1518732 - in /hadoop/common/branches/branch-2/hadoop-yarn-project: ./ hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/ hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/
Date Thu, 29 Aug 2013 17:56:18 GMT
Author: vinodkv
Date: Thu Aug 29 17:56:18 2013
New Revision: 1518732

URL: http://svn.apache.org/r1518732
Log:
YARN-1080. Improved help message for "yarn logs" command. Contributed by Xuan Gong.
svn merge --ignore-ancestry -c 1518731 ../../trunk/

Modified:
    hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogDumper.java
    hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestLogDumper.java

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt?rev=1518732&r1=1518731&r2=1518732&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt (original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/CHANGES.txt Thu Aug 29 17:56:18 2013
@@ -48,6 +48,9 @@ Release 2.1.1-beta - UNRELEASED
     YARN-1034. Remove "experimental" in the Fair Scheduler documentation.
     (Karthik Kambatla via Sandy Ryza)
 
+    YARN-1080. Improved help message for "yarn logs" command. (Xuan Gong via
+    vinodkv)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogDumper.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogDumper.java?rev=1518732&r1=1518731&r2=1518732&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogDumper.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/LogDumper.java
Thu Aug 29 17:56:18 2013
@@ -72,10 +72,18 @@ public class LogDumper extends Configure
       + "nodename:port (must be specified if container id is specified)");
     opts.addOption(APP_OWNER_OPTION, true,
       "AppOwner (assumed to be current user if not specified)");
+    opts.getOption(APPLICATION_ID_OPTION).setArgName("Application ID");
+    opts.getOption(CONTAINER_ID_OPTION).setArgName("Container ID");
+    opts.getOption(NODE_ADDRESS_OPTION).setArgName("Node Address");
+    opts.getOption(APP_OWNER_OPTION).setArgName("Application Owner");
+
+    Options printOpts = new Options();
+    printOpts.addOption(opts.getOption(CONTAINER_ID_OPTION));
+    printOpts.addOption(opts.getOption(NODE_ADDRESS_OPTION));
+    printOpts.addOption(opts.getOption(APP_OWNER_OPTION));
 
     if (args.length < 1) {
-      HelpFormatter formatter = new HelpFormatter();
-      formatter.printHelp("general options are: ", opts);
+      printHelpMessage(printOpts);
       return -1;
     }
 
@@ -92,16 +100,13 @@ public class LogDumper extends Configure
       appOwner = commandLine.getOptionValue(APP_OWNER_OPTION);
     } catch (ParseException e) {
       System.out.println("options parsing failed: " + e.getMessage());
-
-      HelpFormatter formatter = new HelpFormatter();
-      formatter.printHelp("general options are: ", opts);
+      printHelpMessage(printOpts);
       return -1;
     }
 
     if (appIdStr == null) {
       System.out.println("ApplicationId cannot be null!");
-      HelpFormatter formatter = new HelpFormatter();
-      formatter.printHelp("general options are: ", opts);
+      printHelpMessage(printOpts);
       return -1;
     }
 
@@ -119,8 +124,7 @@ public class LogDumper extends Configure
     } else if ((containerIdStr == null && nodeAddress != null)
         || (containerIdStr != null && nodeAddress == null)) {
       System.out.println("ContainerId or NodeAddress cannot be null!");
-      HelpFormatter formatter = new HelpFormatter();
-      formatter.printHelp("general options are: ", opts);
+      printHelpMessage(printOpts);
       resultCode = -1;
     } else {
       Path remoteRootLogDir =
@@ -255,4 +259,12 @@ public class LogDumper extends Configure
     int exitCode = logDumper.run(args);
     System.exit(exitCode);
   }
+
+  private void printHelpMessage(Options options) {
+    System.out.println("Retrieve logs for completed YARN applications.");
+    HelpFormatter formatter = new HelpFormatter();
+    formatter.printHelp("yarn logs -applicationId <application ID> [OPTIONS]", new
Options());
+    formatter.setSyntaxPrefix("");
+    formatter.printHelp("general options are:", options);
+  }
 }

Modified: hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestLogDumper.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestLogDumper.java?rev=1518732&r1=1518731&r2=1518732&view=diff
==============================================================================
--- hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestLogDumper.java
(original)
+++ hadoop/common/branches/branch-2/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/logaggregation/TestLogDumper.java
Thu Aug 29 17:56:18 2013
@@ -19,14 +19,30 @@
 package org.apache.hadoop.yarn.logaggregation;
 
 import static org.junit.Assert.assertTrue;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+import junit.framework.Assert;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.LocalFileSystem;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
+import org.junit.Before;
 import org.junit.Test;
 
 public class TestLogDumper {
+  ByteArrayOutputStream sysOutStream;
+  private PrintStream sysOut;
+
+  @Before
+  public void setUp() {
+    sysOutStream = new ByteArrayOutputStream();
+    sysOut =  new PrintStream(sysOutStream);
+    System.setOut(sysOut);
+  }
+
   @Test
   public void testFailResultCodes() throws Exception {
     Configuration conf = new YarnConfiguration();
@@ -44,4 +60,30 @@ public class TestLogDumper {
         "nonexistentnode:1234", "nobody");
     assertTrue("Should return an error code", exitCode != 0);
   }
+
+  @Test
+  public void testHelpMessage() throws Exception {
+    Configuration conf = new YarnConfiguration();
+    LogDumper dumper = new LogDumper();
+    dumper.setConf(conf);
+
+    int exitCode = dumper.run(new String[]{});
+    assertTrue(exitCode == -1);
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    PrintWriter pw = new PrintWriter(baos);
+    pw.println("Retrieve logs for completed YARN applications.");
+    pw.println("usage: yarn logs -applicationId <application ID> [OPTIONS]");
+    pw.println();
+    pw.println("general options are:");
+    pw.println(" -appOwner <Application Owner>   AppOwner (assumed to be current user
if");
+    pw.println("                                 not specified)");
+    pw.println(" -containerId <Container ID>     ContainerId (must be specified if
node");
+    pw.println("                                 address is specified)");
+    pw.println(" -nodeAddress <Node Address>     NodeAddress in the format nodename:port");
+    pw.println("                                 (must be specified if container id is");
+    pw.println("                                 specified)");
+    pw.close();
+    String appReportStr = baos.toString("UTF-8");
+    Assert.assertEquals(appReportStr, sysOutStream.toString());
+  }
 }



Mime
View raw message