YARN-10381. Add application attempt state in AppAttempts RM REST API

Contributed by Siddharth Ahuja. Reviewed by Bilwa ST.
This commit is contained in:
Prabhu Joseph 2020-08-04 23:01:05 +05:30 committed by Prabhu Joseph
parent 2986058e7f
commit aa5afa72c5
3 changed files with 20 additions and 5 deletions

View File

@ -26,6 +26,7 @@
import org.apache.hadoop.yarn.api.records.Container; import org.apache.hadoop.yarn.api.records.Container;
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager; 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.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.AbstractYarnScheduler;
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt; import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt;
import org.apache.hadoop.yarn.webapp.util.WebAppUtils; import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
@ -45,6 +46,7 @@ public class AppAttemptInfo {
private String nodesBlacklistedBySystem; private String nodesBlacklistedBySystem;
protected String appAttemptId; protected String appAttemptId;
private String exportPorts; private String exportPorts;
private RMAppAttemptState appAttemptState;
public AppAttemptInfo() { public AppAttemptInfo() {
} }
@ -89,6 +91,7 @@ public AppAttemptInfo(ResourceManager rm, RMAppAttempt attempt, String user,
} }
} }
this.appAttemptId = attempt.getAppAttemptId().toString(); this.appAttemptId = attempt.getAppAttemptId().toString();
this.appAttemptState = attempt.getAppAttemptState();
} }
} }
@ -115,4 +118,8 @@ public String getLogsLink() {
public String getAppAttemptId() { public String getAppAttemptId() {
return this.appAttemptId; return this.appAttemptId;
} }
public RMAppAttemptState getAppAttemptState() {
return this.appAttemptState;
}
} }

View File

@ -381,7 +381,8 @@ private void verifyAppAttemptsXML(NodeList nodes, RMAppAttempt appAttempt,
WebServicesTestUtils.getXmlString(element, "nodeHttpAddress"), WebServicesTestUtils.getXmlString(element, "nodeHttpAddress"),
WebServicesTestUtils.getXmlString(element, "nodeId"), WebServicesTestUtils.getXmlString(element, "nodeId"),
WebServicesTestUtils.getXmlString(element, "logsLink"), user, 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) String user)
throws Exception { throws Exception {
assertEquals("incorrect number of elements", 11, info.length()); assertEquals("incorrect number of elements", 12, info.length());
verifyAppAttemptInfoGeneric(appAttempt, info.getInt("id"), verifyAppAttemptInfoGeneric(appAttempt, info.getInt("id"),
info.getLong("startTime"), info.getString("containerId"), info.getLong("startTime"), info.getString("containerId"),
info.getString("nodeHttpAddress"), info.getString("nodeId"), 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, private void verifyAppAttemptInfoGeneric(RMAppAttempt appAttempt, int id,
long startTime, String containerId, String nodeHttpAddress, String 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() assertEquals("id doesn't match", appAttempt.getAppAttemptId()
.getAttemptId(), id); .getAttemptId(), id);
@ -415,5 +418,7 @@ private void verifyAppAttemptInfoGeneric(RMAppAttempt appAttempt, int id,
assertTrue( assertTrue(
"logsLink doesn't contain user info", logsLink.endsWith("/" "logsLink doesn't contain user info", logsLink.endsWith("/"
+ user)); + user));
assertEquals("appAttemptState doesn't match", appAttemptState, appAttempt
.getAppAttemptState().toString());
} }
} }

View File

@ -2265,6 +2265,7 @@ appAttempts:
| logsLink | string | The http link to the app attempt logs | | logsLink | string | The http link to the app attempt logs |
| containerId | string | The id of the container for the app attempt | | containerId | string | The id of the container for the app attempt |
| startTime | long | The start time of the attempt (in ms since epoch) | | 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 ### Response Examples
@ -2293,7 +2294,8 @@ Response Body:
"startTime" : 1326381444693, "startTime" : 1326381444693,
"id" : 1, "id" : 1,
"logsLink" : "http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1", "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:
<startTime>1326381444693</startTime> <startTime>1326381444693</startTime>
<containerId>container_1326821518301_0005_01_000001</containerId> <containerId>container_1326821518301_0005_01_000001</containerId>
<logsLink>http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1</logsLink> <logsLink>http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1</logsLink>
<appAttemptState>RUNNING</appAttemptState>
</appAttempt> </appAttempt>
</appAttempts> </appAttempts>
``` ```