Explorar o código

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

Contributed by Siddharth Ahuja. Reviewed by Bilwa ST.
Prabhu Joseph %!s(int64=4) %!d(string=hai) anos
pai
achega
aa5afa72c5

+ 7 - 0
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.commons.lang3.StringUtils;
 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 class AppAttemptInfo {
         }
       }
       this.appAttemptId = attempt.getAppAttemptId().toString();
+      this.appAttemptState = attempt.getAppAttemptState();
     }
   }
 
@@ -115,4 +118,8 @@ public class AppAttemptInfo {
   public String getAppAttemptId() {
     return this.appAttemptId;
   }
+
+  public RMAppAttemptState getAppAttemptState() {
+    return this.appAttemptState;
+  }
 }

+ 9 - 4
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 @@ public class TestRMWebServicesAppAttempts extends JerseyTestBase {
               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 @@ public class TestRMWebServicesAppAttempts extends JerseyTestBase {
           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 @@ public class TestRMWebServicesAppAttempts extends JerseyTestBase {
     assertTrue(
             "logsLink doesn't contain user info", logsLink.endsWith("/"
                     + user));
+    assertEquals("appAttemptState doesn't match", appAttemptState, appAttempt
+            .getAppAttemptState().toString());
   }
 }

+ 4 - 1
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:
     <startTime>1326381444693</startTime>
     <containerId>container_1326821518301_0005_01_000001</containerId>
     <logsLink>http://host.domain.com:8042/node/containerlogs/container_1326821518301_0005_01_000001/user1</logsLink>
+    <appAttemptState>RUNNING</appAttemptState>
   </appAttempt>
 </appAttempts>
 ```