Browse Source

YARN-6973. Adding RM Cluster Id in ApplicationReport. Contributed by Bilwa S T.

Inigo Goiri 5 years ago
parent
commit
d125d39108

+ 13 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/ApplicationReport.java

@@ -539,4 +539,17 @@ public abstract class ApplicationReport {
   @Unstable
   public abstract void setApplicationTimeouts(
       Map<ApplicationTimeoutType, ApplicationTimeout> timeouts);
+
+  /**
+   * Get RM ClusterId.
+   *
+   * @return RM ClusterId
+   */
+  @Public
+  @Stable
+  public abstract String getRMClusterId();
+
+  @Public
+  @Stable
+  public abstract void setRMClusterId(String rmClusterId);
 }

+ 1 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/proto/yarn_protos.proto

@@ -288,6 +288,7 @@ message ApplicationReportProto {
   repeated AppTimeoutsMapProto appTimeouts = 26;
   optional int64 launchTime = 27;
   optional int64 submitTime = 28;
+  optional string rmClusterId = 29;
 }
 
 message AppTimeoutsMapProto {

+ 5 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/main/java/org/apache/hadoop/yarn/client/cli/ApplicationCLI.java

@@ -664,6 +664,11 @@ public class ApplicationCLI extends YarnCLI {
         appReportStr.println(
             "\tRemainingTime : " + timeout.getRemainingTime() + "seconds");
       }
+      String rmClusterId = appReport.getRMClusterId();
+      if (rmClusterId != null) {
+        appReportStr.print("\tRMClusterId : ");
+        appReportStr.println(rmClusterId);
+      }
     } else {
       appReportStr.print("Application with id '" + applicationId
           + "' doesn't exist in RM.");

+ 2 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestYarnCLI.java

@@ -147,6 +147,7 @@ public class TestYarnCLI {
           null, null, false, Priority.newInstance(0), "high-mem", "high-mem");
       newApplicationReport.setLogAggregationStatus(LogAggregationStatus.SUCCEEDED);
       newApplicationReport.setPriority(Priority.newInstance(0));
+      newApplicationReport.setRMClusterId("Cluster1");
       ApplicationTimeout timeout = ApplicationTimeout
           .newInstance(ApplicationTimeoutType.LIFETIME, "UNLIMITED", -1);
       newApplicationReport.setApplicationTimeouts(
@@ -186,6 +187,7 @@ public class TestYarnCLI {
       pw.print("\tTimeoutType : LIFETIME");
       pw.print("\tExpiryTime : UNLIMITED");
       pw.println("\tRemainingTime : -1seconds");
+      pw.println("\tRMClusterId : Cluster1");
       pw.println();
       pw.close();
       String appReportStr = baos.toString("UTF-8");

+ 19 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ApplicationReportPBImpl.java

@@ -787,4 +787,23 @@ public class ApplicationReportPBImpl extends ApplicationReport {
     this.builder.addAllAppTimeouts(values);
   }
 
+  @Override
+  public String getRMClusterId() {
+    ApplicationReportProtoOrBuilder p = viaProto ? proto : builder;
+    if (!p.hasRmClusterId()) {
+      return null;
+    }
+    return p.getRmClusterId();
+  }
+
+  @Override
+  public void setRMClusterId(String rmClusterId) {
+    maybeInitBuilder();
+    if (rmClusterId == null) {
+      builder.clearRmClusterId();
+      return;
+    }
+    builder.setRmClusterId((rmClusterId));
+  }
+
 }

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/rmapp/RMAppImpl.java

@@ -61,6 +61,7 @@ import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.hadoop.yarn.api.records.ResourceRequest;
 import org.apache.hadoop.yarn.api.records.YarnApplicationState;
 import org.apache.hadoop.yarn.client.api.AppAdminClient;
+import org.apache.hadoop.yarn.conf.HAUtil;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.event.Dispatcher;
 import org.apache.hadoop.yarn.event.EventHandler;
@@ -772,6 +773,9 @@ public class RMAppImpl implements RMApp, Recoverable {
       report.setUnmanagedApp(submissionContext.getUnmanagedAM());
       report.setAppNodeLabelExpression(getAppNodeLabelExpression());
       report.setAmNodeLabelExpression(getAmNodeLabelExpression());
+      if (HAUtil.isFederationEnabled(conf)) {
+        report.setRMClusterId(YarnConfiguration.getClusterId(conf));
+      }
 
       ApplicationTimeout timeout = ApplicationTimeout
           .newInstance(ApplicationTimeoutType.LIFETIME, UNLIMITED, UNKNOWN);