Skip to content

Commit

Permalink
YARN-10312. Add support for yarn logs -logFile to retain backward com…
Browse files Browse the repository at this point in the history
…patibility.

Contributed by Jim Brennan.
  • Loading branch information
ericbadger committed Jun 11, 2020
1 parent 93b121a commit fed6fec
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public class LogsCLI extends Configured implements Tool {
private static final String APP_OWNER_OPTION = "appOwner";
private static final String AM_CONTAINER_OPTION = "am";
private static final String PER_CONTAINER_LOG_FILES_OPTION = "log_files";
private static final String PER_CONTAINER_LOG_FILES_OLD_OPTION = "logFiles";
private static final String PER_CONTAINER_LOG_FILES_REGEX_OPTION
= "log_files_pattern";
private static final String LIST_NODES_OPTION = "list_nodes";
Expand Down Expand Up @@ -202,6 +203,12 @@ private int runCommand(String[] args) throws Exception {
}
if (commandLine.hasOption(PER_CONTAINER_LOG_FILES_OPTION)) {
logFiles = commandLine.getOptionValues(PER_CONTAINER_LOG_FILES_OPTION);
} else {
// For backward compatibility, we need to check for the old form of this
// command line option as well. New form takes precedent.
if (commandLine.hasOption(PER_CONTAINER_LOG_FILES_OLD_OPTION)) {
logFiles = commandLine.getOptionValues(PER_CONTAINER_LOG_FILES_OLD_OPTION);
}
}
if (commandLine.hasOption(PER_CONTAINER_LOG_FILES_REGEX_OPTION)) {
logFilesRegex = commandLine.getOptionValues(
Expand Down Expand Up @@ -937,6 +944,12 @@ private Options createCommandOpts() {
logFileOpt.setArgs(Option.UNLIMITED_VALUES);
logFileOpt.setArgName("Log File Name");
opts.addOption(logFileOpt);
Option oldLogFileOpt = new Option(PER_CONTAINER_LOG_FILES_OLD_OPTION, true,
"Deprecated name for log_files, please use log_files option instead");
oldLogFileOpt.setValueSeparator(',');
oldLogFileOpt.setArgs(Option.UNLIMITED_VALUES);
oldLogFileOpt.setArgName("Log File Name");
opts.addOption(oldLogFileOpt);
Option logFileRegexOpt = new Option(PER_CONTAINER_LOG_FILES_REGEX_OPTION,
true, "Specify comma-separated value "
+ "to get matched log files by using java regex. Use \".*\" to "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,48 @@ public ContainerReport getContainerReport(String containerIdStr)
createEmptyLog("empty")));
sysOutStream.reset();

// Check backward compatibility for -logFiles
exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
"-logFiles", "stdout"});
assertTrue("Failed with -logFiles", exitCode == 0);
assertFalse("Failed with -logFiles", sysOutStream.toString().contains(
logMessage(containerId1, "syslog")));
assertFalse("Failed with -logFiles", sysOutStream.toString().contains(
logMessage(containerId2, "syslog")));
assertFalse("Failed with -logFiles", sysOutStream.toString().contains(
logMessage(containerId3, "syslog")));
assertTrue("Failed with -logFiles", sysOutStream.toString().contains(
logMessage(containerId3, "stdout")));
assertFalse("Failed with -logFiles", sysOutStream.toString().contains(
logMessage(containerId3, "stdout1234")));
assertFalse("Failed with -logFiles", sysOutStream.toString().contains(
createEmptyLog("empty")));
sysOutStream.reset();

// Check -log_files supercedes -logFiles
exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
"-log_files", "stdout", "-logFiles", "syslog"});
assertTrue("Failed with -logFiles and -log_files", exitCode == 0);
assertFalse("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
logMessage(containerId1, "syslog")));
assertFalse("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
logMessage(containerId2, "syslog")));
assertFalse("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
logMessage(containerId3, "syslog")));
assertTrue("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
logMessage(containerId3, "stdout")));
assertFalse("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
logMessage(containerId3, "stdout1234")));
assertFalse("Failed with -logFiles and -log_files",
sysOutStream.toString().contains(
createEmptyLog("empty")));
sysOutStream.reset();

exitCode = cli.run(new String[] {"-applicationId", appId.toString(),
"-log_files_pattern", "std*"});
assertTrue(exitCode == 0);
Expand Down

0 comments on commit fed6fec

Please sign in to comment.