diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java index 661a970..94252e3 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java @@ -97,6 +97,7 @@ = "show_container_log_info"; private static final String OUT_OPTION = "out"; private static final String SIZE_OPTION = "size"; + private static final String IGNORE_SIZE_OPTION = "ignore_size_limits"; public static final String HELP_CMD = "help"; private PrintStream outStream = System.out; private YarnClient yarnClient = null; @@ -138,7 +139,7 @@ private int runCommand(String[] args) throws Exception { String[] logFilesRegex = null; List amContainersList = new ArrayList(); String localDir = null; - long bytes = Long.MAX_VALUE; + long bytes = -4096; try { CommandLine commandLine = parser.parse(opts, args, false); appIdStr = commandLine.getOptionValue(APPLICATION_ID_OPTION); @@ -170,6 +171,9 @@ private int runCommand(String[] args) throws Exception { if (commandLine.hasOption(SIZE_OPTION)) { bytes = Long.parseLong(commandLine.getOptionValue(SIZE_OPTION)); } + if (commandLine.hasOption(IGNORE_SIZE_OPTION)) { + bytes = Long.MAX_VALUE; + } } catch (ParseException e) { System.err.println("options parsing failed: " + e.getMessage()); printHelpMessage(printOpts); @@ -858,7 +862,11 @@ private Options createCommandOpts() { + "node the container ran on."); opts.addOption(SIZE_OPTION, true, "Prints the log file's first 'n' bytes " + "or the last 'n' bytes. Use negative values as bytes to read from " - + "the end and positive values as bytes to read from the beginning."); + + "the end and positive values as bytes to read from the beginning. " + + "Work with --ignore_size_limits to print the full log. " + + "By default, we would only print the last 4096 bytes of the log."); + opts.addOption(IGNORE_SIZE_OPTION, false, "Work with -size to get the " + + "full log."); opts.getOption(APPLICATION_ID_OPTION).setArgName("Application ID"); opts.getOption(CONTAINER_ID_OPTION).setArgName("Container ID"); opts.getOption(NODE_ADDRESS_OPTION).setArgName("Node Address"); @@ -882,6 +890,7 @@ private Options createPrintOpts(Options commandOpts) { printOpts.addOption(commandOpts.getOption(SHOW_CONTAINER_LOG_INFO)); printOpts.addOption(commandOpts.getOption(OUT_OPTION)); printOpts.addOption(commandOpts.getOption(SIZE_OPTION)); + printOpts.addOption(commandOpts.getOption(IGNORE_SIZE_OPTION)); printOpts.addOption(commandOpts.getOption( PER_CONTAINER_LOG_FILES_REGEX_OPTION)); return printOpts; diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java index dec131b..2daeab6 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java @@ -232,6 +232,8 @@ public void testHelpMessage() throws Exception { pw.println(" specific logs. If specified, the"); pw.println(" applicationId can be omitted"); pw.println(" -help Displays help for all commands."); + pw.println(" -ignore_size_limits Work with -size to get the full"); + pw.println(" log."); pw.println(" -list_nodes Show the list of nodes that"); pw.println(" successfully aggregated logs."); pw.println(" This option can only be used with"); @@ -272,7 +274,11 @@ public void testHelpMessage() throws Exception { pw.println(" negative values as bytes to read"); pw.println(" from the end and positive values"); pw.println(" as bytes to read from the"); - pw.println(" beginning."); + pw.println(" beginning. Work with"); + pw.println(" --ignore_size_limits to print the"); + pw.println(" full log. By default, we would"); + pw.println(" only print the last 4096 bytes of"); + pw.println(" the log."); pw.close(); String appReportStr = baos.toString("UTF-8"); Assert.assertEquals(appReportStr, sysOutStream.toString()); @@ -515,6 +521,15 @@ public ContainerReport getContainerReport(String containerIdStr) (fullContextSize - fileContentSize - tailContentSize), 5)); sysOutStream.reset(); + // we specify the -ignore_size_limits option, we would ignore the value + // set for -size option and get the full log. + exitCode = cli.run(new String[] {"-applicationId", appId.toString(), + "-containerId", containerId3.toString(), "-log_files", "stdout", + "-size", "-5", "-ignore_size_limits"}); + assertTrue(exitCode == 0); + Assert.assertEquals(fullContext, sysOutStream.toString()); + sysOutStream.reset(); + long negative = (fullContextSize + 1000) * (-1); exitCode = cli.run(new String[] {"-applicationId", appId.toString(), "-containerId", containerId3.toString(), "-log_files", "stdout",