From e75799d5fd2dbcbb9529ee733182139b069dc336 Mon Sep 17 00:00:00 2001 From: Rohith Sharma K S Date: Mon, 26 Oct 2015 11:56:36 +0530 Subject: [PATCH] YARN-4246. NPE while listing app attempt. (Nijel S F via rohithsharmaks) (cherry picked from commit b57f08c0d2dae57b545a3baa213e18464060ae3b) --- hadoop-yarn-project/CHANGES.txt | 2 ++ .../yarn/client/cli/ApplicationCLI.java | 6 +++-- .../hadoop/yarn/client/cli/TestYarnCLI.java | 23 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index 3fcea51a598..2c4c4fe2a99 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -945,6 +945,8 @@ Release 2.8.0 - UNRELEASED YARN-3724. Use POSIX nftw(3) instead of fts(3) (Alan Burlison via aw) + YARN-4246. NPE while listing app attempt. (Nijel S F via rohithsharmaks) + Release 2.7.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java index e34675a086c..b4860748a2d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java @@ -349,8 +349,9 @@ public class ApplicationCLI extends YarnCLI { appAttemptReportStr.println(appAttemptReport .getYarnApplicationAttemptState()); appAttemptReportStr.print("\tAMContainer : "); - appAttemptReportStr.println(appAttemptReport.getAMContainerId() - .toString()); + appAttemptReportStr + .println(appAttemptReport.getAMContainerId() == null ? "N/A" + : appAttemptReport.getAMContainerId().toString()); appAttemptReportStr.print("\tTracking-URL : "); appAttemptReportStr.println(appAttemptReport.getTrackingUrl()); appAttemptReportStr.print("\tRPC Port : "); @@ -667,6 +668,7 @@ public class ApplicationCLI extends YarnCLI { writer.printf(APPLICATION_ATTEMPTS_PATTERN, appAttemptReport .getApplicationAttemptId(), appAttemptReport .getYarnApplicationAttemptState(), appAttemptReport + .getAMContainerId() == null ? "N/A" : appAttemptReport .getAMContainerId().toString(), appAttemptReport.getTrackingUrl()); } writer.flush(); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java index 069ff7d2efb..3dab504e05a 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java @@ -1590,4 +1590,27 @@ public class TestYarnCLI { private static String normalize(String s) { return SPACES_PATTERN.matcher(s).replaceAll(" "); // single space } + + @Test + public void testAppAttemptReportWhileContainerIsNotAssigned() + throws Exception { + ApplicationCLI cli = createAndGetAppCLI(); + ApplicationId applicationId = ApplicationId.newInstance(1234, 5); + ApplicationAttemptId attemptId = + ApplicationAttemptId.newInstance(applicationId, 1); + ApplicationAttemptReport attemptReport = + ApplicationAttemptReport.newInstance(attemptId, "host", 124, "url", + "oUrl", "diagnostics", YarnApplicationAttemptState.SCHEDULED, null, + 1000l, 2000l); + when(client.getApplicationAttemptReport(any(ApplicationAttemptId.class))) + .thenReturn(attemptReport); + int result = + cli.run(new String[] { "applicationattempt", "-status", + attemptId.toString() }); + assertEquals(0, result); + result = + cli.run(new String[] { "applicationattempt", "-list", + applicationId.toString() }); + assertEquals(0, result); + } }