hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jia...@apache.org
Subject hadoop git commit: YARN-5227. Yarn logs command: no need to specify applicationId when specifying containerId. Contributed by Gergely Novák
Date Wed, 06 Jul 2016 20:29:22 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 46f820499 -> ccb079190


YARN-5227. Yarn logs command: no need to specify applicationId when
specifying containerId. Contributed by Gergely Novák

(cherry picked from commit d169f5052fe83debcea7cf2f317dcd990890a857)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/ccb07919
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/ccb07919
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/ccb07919

Branch: refs/heads/branch-2
Commit: ccb07919044ed4e49a7fd24e4214342200da1fcd
Parents: 46f8204
Author: Jian He <jianhe@apache.org>
Authored: Wed Jul 6 10:37:44 2016 -0700
Committer: Jian He <jianhe@apache.org>
Committed: Wed Jul 6 13:29:12 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/ccb07919/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 9a520a1..ad4964a 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) {
@@ -628,11 +641,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/ccb07919/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: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message