YARN-1080. Improved help message for "yarn logs" command. Contributed by Xuan Gong.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1518731 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c13893d5d9
commit
febedd64e9
@ -63,6 +63,9 @@ Release 2.1.1-beta - UNRELEASED
|
|||||||
YARN-1034. Remove "experimental" in the Fair Scheduler documentation.
|
YARN-1034. Remove "experimental" in the Fair Scheduler documentation.
|
||||||
(Karthik Kambatla via Sandy Ryza)
|
(Karthik Kambatla via Sandy Ryza)
|
||||||
|
|
||||||
|
YARN-1080. Improved help message for "yarn logs" command. (Xuan Gong via
|
||||||
|
vinodkv)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
@ -72,10 +72,18 @@ public int run(String[] args) throws Exception {
|
|||||||
+ "nodename:port (must be specified if container id is specified)");
|
+ "nodename:port (must be specified if container id is specified)");
|
||||||
opts.addOption(APP_OWNER_OPTION, true,
|
opts.addOption(APP_OWNER_OPTION, true,
|
||||||
"AppOwner (assumed to be current user if not specified)");
|
"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) {
|
if (args.length < 1) {
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
printHelpMessage(printOpts);
|
||||||
formatter.printHelp("general options are: ", opts);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,16 +100,13 @@ public int run(String[] args) throws Exception {
|
|||||||
appOwner = commandLine.getOptionValue(APP_OWNER_OPTION);
|
appOwner = commandLine.getOptionValue(APP_OWNER_OPTION);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
System.out.println("options parsing failed: " + e.getMessage());
|
System.out.println("options parsing failed: " + e.getMessage());
|
||||||
|
printHelpMessage(printOpts);
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
|
||||||
formatter.printHelp("general options are: ", opts);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appIdStr == null) {
|
if (appIdStr == null) {
|
||||||
System.out.println("ApplicationId cannot be null!");
|
System.out.println("ApplicationId cannot be null!");
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
printHelpMessage(printOpts);
|
||||||
formatter.printHelp("general options are: ", opts);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,8 +124,7 @@ public int run(String[] args) throws Exception {
|
|||||||
} else if ((containerIdStr == null && nodeAddress != null)
|
} else if ((containerIdStr == null && nodeAddress != null)
|
||||||
|| (containerIdStr != null && nodeAddress == null)) {
|
|| (containerIdStr != null && nodeAddress == null)) {
|
||||||
System.out.println("ContainerId or NodeAddress cannot be null!");
|
System.out.println("ContainerId or NodeAddress cannot be null!");
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
printHelpMessage(printOpts);
|
||||||
formatter.printHelp("general options are: ", opts);
|
|
||||||
resultCode = -1;
|
resultCode = -1;
|
||||||
} else {
|
} else {
|
||||||
Path remoteRootLogDir =
|
Path remoteRootLogDir =
|
||||||
@ -255,4 +259,12 @@ public static void main(String[] args) throws Exception {
|
|||||||
int exitCode = logDumper.run(args);
|
int exitCode = logDumper.run(args);
|
||||||
System.exit(exitCode);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,30 @@
|
|||||||
package org.apache.hadoop.yarn.logaggregation;
|
package org.apache.hadoop.yarn.logaggregation;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
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.conf.Configuration;
|
||||||
import org.apache.hadoop.fs.FileSystem;
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.fs.LocalFileSystem;
|
import org.apache.hadoop.fs.LocalFileSystem;
|
||||||
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestLogDumper {
|
public class TestLogDumper {
|
||||||
|
ByteArrayOutputStream sysOutStream;
|
||||||
|
private PrintStream sysOut;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
sysOutStream = new ByteArrayOutputStream();
|
||||||
|
sysOut = new PrintStream(sysOutStream);
|
||||||
|
System.setOut(sysOut);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailResultCodes() throws Exception {
|
public void testFailResultCodes() throws Exception {
|
||||||
Configuration conf = new YarnConfiguration();
|
Configuration conf = new YarnConfiguration();
|
||||||
@ -44,4 +60,30 @@ public void testFailResultCodes() throws Exception {
|
|||||||
"nonexistentnode:1234", "nobody");
|
"nonexistentnode:1234", "nobody");
|
||||||
assertTrue("Should return an error code", exitCode != 0);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user