From aa5afa72c517f24f28189577dc611a51e4f3883b Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Tue, 4 Aug 2020 23:01:05 +0530 Subject: [PATCH] YARN-10381. Add application attempt state in AppAttempts RM REST API Contributed by Siddharth Ahuja. Reviewed by Bilwa ST. --- .../resourcemanager/webapp/dao/AppAttemptInfo.java | 7 +++++++ .../webapp/TestRMWebServicesAppAttempts.java | 13 +++++++++---- .../src/site/markdown/ResourceManagerRest.md | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/AppAttemptInfo.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/AppAttemptInfo.java index b41dc6b07a..66381f4e7e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/AppAttemptInfo.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/AppAttemptInfo.java @@ -26,6 +26,7 @@ import org.apache.hadoop.yarn.api.records.Container; import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt; +import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt; import org.apache.hadoop.yarn.webapp.util.WebAppUtils; @@ -45,6 +46,7 @@ public class AppAttemptInfo { private String nodesBlacklistedBySystem; protected String appAttemptId; private String exportPorts; + private RMAppAttemptState appAttemptState; public AppAttemptInfo() { } @@ -89,6 +91,7 @@ public AppAttemptInfo(ResourceManager rm, RMAppAttempt attempt, String user, } } this.appAttemptId = attempt.getAppAttemptId().toString(); + this.appAttemptState = attempt.getAppAttemptState(); } } @@ -115,4 +118,8 @@ public String getLogsLink() { public String getAppAttemptId() { return this.appAttemptId; } + + public RMAppAttemptState getAppAttemptState() { + return this.appAttemptState; + } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesAppAttempts.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesAppAttempts.java index ee6d018149..df168f757b 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesAppAttempts.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesAppAttempts.java @@ -381,7 +381,8 @@ private void verifyAppAttemptsXML(NodeList nodes, RMAppAttempt appAttempt, WebServicesTestUtils.getXmlString(element, "nodeHttpAddress"), WebServicesTestUtils.getXmlString(element, "nodeId"), WebServicesTestUtils.getXmlString(element, "logsLink"), user, - WebServicesTestUtils.getXmlString(element, "exportPorts")); + WebServicesTestUtils.getXmlString(element, "exportPorts"), + WebServicesTestUtils.getXmlString(element, "appAttemptState")); } } @@ -389,17 +390,19 @@ private void verifyAppAttemptsInfo(JSONObject info, RMAppAttempt appAttempt, String user) throws Exception { - assertEquals("incorrect number of elements", 11, info.length()); + assertEquals("incorrect number of elements", 12, info.length()); verifyAppAttemptInfoGeneric(appAttempt, info.getInt("id"), info.getLong("startTime"), info.getString("containerId"), info.getString("nodeHttpAddress"), info.getString("nodeId"), - info.getString("logsLink"), user, info.getString("exportPorts")); + info.getString("logsLink"), user, info.getString("exportPorts"), + info.getString("appAttemptState")); } private void verifyAppAttemptInfoGeneric(RMAppAttempt appAttempt, int id, long startTime, String containerId, String nodeHttpAddress, String - nodeId, String logsLink, String user, String exportPorts) { + nodeId, String logsLink, String user, String exportPorts, + String appAttemptState) { assertEquals("id doesn't match", appAttempt.getAppAttemptId() .getAttemptId(), id); @@ -415,5 +418,7 @@ private void verifyAppAttemptInfoGeneric(RMAppAttempt appAttempt, int id, assertTrue( "logsLink doesn't contain user info", logsLink.endsWith("/" + user)); + assertEquals("appAttemptState doesn't match", appAttemptState, appAttempt + .getAppAttemptState().toString()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md index 879075e794..375e69ac8c 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-site/src/site/markdown/ResourceManagerRest.md @@ -2265,6 +2265,7 @@ appAttempts: | logsLink | string | The http link to the app attempt logs | | containerId | string | The id of the container for the app attempt | | startTime | long | The start time of the attempt (in ms since epoch) | +| appAttemptState | string | The state of the application attempt - valid values are members of the RMAppAttemptState enum: NEW, SUBMITTED, SCHEDULED, ALLOCATED, LAUNCHED, FAILED, RUNNING, FINISHING, FINISHED, KILLED, ALLOCATED_SAVING, LAUNCHED_UNMANAGED_SAVING, FINAL_SAVING | ### Response Examples @@ -2293,7 +2294,8 @@ Response Body: "startTime" : 1326381444693, "id" : 1, "logsLink" : "http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1", - "containerId" : "container_1326821518301_0005_01_000001" + "containerId" : "container_1326821518301_0005_01_000001", + "appAttemptState" : "RUNNING" } ] } @@ -2326,6 +2328,7 @@ Response Body: 1326381444693 container_1326821518301_0005_01_000001 http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1 + RUNNING ```