Repository: hadoop Updated Branches: refs/heads/trunk 04f6ebb66 -> d169f5052
YARN-5227. Yarn logs command: no need to specify applicationId when specifying containerId. Contributed by Gergely Novák Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/d169f505 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/d169f505 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/d169f505 Branch: refs/heads/trunk Commit: d169f5052fe83debcea7cf2f317dcd990890a857 Parents: 04f6ebb Author: Jian He <[email protected]> Authored: Wed Jul 6 10:37:44 2016 -0700 Committer: Jian He <[email protected]> Committed: Wed Jul 6 10:43:27 2016 -0700 ---------------------------------------------------------------------- .../apache/hadoop/yarn/client/cli/LogsCLI.java | 47 +++++++++++++------- .../hadoop/yarn/client/cli/TestLogsCLI.java | 26 +++++++++-- 2 files changed, 52 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/d169f505/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/LogsCLI.java ---------------------------------------------------------------------- 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 3cd3bcf..76d1fb3 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 @@ -145,18 +145,38 @@ public class LogsCLI extends Configured implements Tool { return -1; } - if (appIdStr == null) { - System.err.println("ApplicationId cannot be null!"); + if (appIdStr == null && containerIdStr == null) { + System.err.println("Both applicationId and containerId are missing, " + + " one of them must be specified."); printHelpMessage(printOpts); return -1; } ApplicationId appId = null; - try { - appId = ApplicationId.fromString(appIdStr); - } catch (Exception e) { - System.err.println("Invalid ApplicationId specified"); - return -1; + if (appIdStr != null) { + try { + appId = ApplicationId.fromString(appIdStr); + } catch (Exception e) { + System.err.println("Invalid ApplicationId specified"); + return -1; + } + } + + if (containerIdStr != null) { + try { + ContainerId containerId = ContainerId.fromString(containerIdStr); + if (appId == null) { + appId = containerId.getApplicationAttemptId().getApplicationId(); + } else if (!containerId.getApplicationAttemptId().getApplicationId() + .equals(appId)) { + System.err.println("The Application:" + appId + + " does not have the container:" + containerId); + return -1; + } + } catch (Exception e) { + System.err.println("Invalid ContainerId specified"); + return -1; + } } LogCLIHelpers logCliHelper = new LogCLIHelpers(); @@ -218,13 +238,6 @@ public class LogsCLI extends Configured implements Tool { int resultCode = 0; if (containerIdStr != null) { - ContainerId containerId = ContainerId.fromString(containerIdStr); - if (!containerId.getApplicationAttemptId().getApplicationId() - .equals(appId)) { - System.err.println("The Application:" + appId - + " does not have the container:" + containerId); - return -1; - } return fetchContainerLogs(request, logCliHelper); } else { if (nodeAddress == null) { @@ -629,11 +642,11 @@ public class LogsCLI extends Configured implements Tool { 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, "ContainerId. " - + "By default, it will only print syslog if the application is runing." - + " Work with -logFiles to get other logs."); + + "By default, it will only print syslog if the application is running." + + " Work with -logFiles to get other logs. If specified, the" + + " applicationId can be omitted"); opts.addOption(NODE_ADDRESS_OPTION, true, "NodeAddress in the format " + "nodename:port"); opts.addOption(APP_OWNER_OPTION, true, http://git-wip-us.apache.org/repos/asf/hadoop/blob/d169f505/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java ---------------------------------------------------------------------- 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 85287ea..34369ef 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 @@ -201,8 +201,9 @@ public class TestLogsCLI { pw.println(" not specified)"); pw.println(" -containerId <Container ID> ContainerId. By default, it will only"); pw.println(" print syslog if the application is"); - pw.println(" runing. Work with -logFiles to get other"); - pw.println(" logs."); + pw.println(" running. Work with -logFiles to get other"); + pw.println(" logs. If specified, the applicationId can"); + pw.println(" be omitted"); pw.println(" -help Displays help for all commands."); pw.println(" -list_nodes Show the list of nodes that successfully"); pw.println(" aggregated logs. This option can only be"); @@ -498,6 +499,24 @@ public class TestLogsCLI { containerId3 + " on " + LogAggregationUtils.getNodeString(nodeId))); sysOutStream.reset(); + // The same should also work without the applicationId + exitCode = + cli.run(new String[] { "-containerId", containerId3.toString() }); + assertTrue(exitCode == 0); + assertTrue(sysOutStream.toString().contains( + "Hello container_0_0001_01_000003 in syslog!")); + assertTrue(sysOutStream.toString().contains( + "Hello container_0_0001_01_000003 in stdout!")); + assertTrue(sysOutStream.toString().contains( + containerId3 + " on " + LogAggregationUtils.getNodeString(nodeId))); + sysOutStream.reset(); + + exitCode = cli.run(new String[] { "-containerId", "invalid_container" }); + assertTrue(exitCode == -1); + assertTrue(sysErrStream.toString().contains( + "Invalid ContainerId specified")); + sysErrStream.reset(); + fs.delete(new Path(remoteLogRootDir), true); fs.delete(new Path(rootLogDir), true); } @@ -863,8 +882,7 @@ public class TestLogsCLI { "-show_meta_info", "-nodeAddress", "localhost", "-containerId", "container_1234" }); assertTrue(sysErrStream.toString().contains( - "The container container_1234 couldn't be found on the node " - + "specified: localhost")); + "Invalid ContainerId specified")); sysErrStream.reset(); fs.delete(new Path(remoteLogRootDir), true); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
