Skip to content

Commit ff96a2b

Browse files
slfan1989HarshitGupta11
authored andcommitted
YARN-6972. Adding RM ClusterId in AppInfo. (apache#4673)
1 parent a2a500b commit ff96a2b

File tree

2 files changed

+28
-1
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src

2 files changed

+28
-1
lines changed

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/main/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/dao/AppInfo.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import javax.xml.bind.annotation.XmlRootElement;
2828
import javax.xml.bind.annotation.XmlTransient;
2929

30+
import org.apache.hadoop.HadoopIllegalArgumentException;
31+
import org.apache.hadoop.conf.Configuration;
3032
import org.apache.hadoop.yarn.api.records.ApplicationId;
3133
import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport;
3234
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
@@ -38,6 +40,8 @@
3840
import org.apache.hadoop.yarn.api.records.ResourceRequest;
3941
import org.apache.hadoop.yarn.api.records.SchedulingRequest;
4042
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
43+
import org.apache.hadoop.yarn.conf.YarnConfiguration;
44+
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
4145
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
4246
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp;
4347
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppMetrics;
@@ -69,6 +73,8 @@ public class AppInfo {
6973
protected ApplicationId applicationId;
7074
@XmlTransient
7175
private String schemePrefix;
76+
@XmlTransient
77+
private SubClusterIdInfo subClusterId;
7278

7379
// these are ok for any user to see
7480
protected String id;
@@ -82,6 +88,7 @@ public class AppInfo {
8288
protected String trackingUrl;
8389
protected String diagnostics;
8490
protected long clusterId;
91+
protected String rmClusterId;
8592
protected String applicationType;
8693
protected String applicationTags = "";
8794
protected int priority;
@@ -182,6 +189,16 @@ public AppInfo(ResourceManager rm, RMApp app, Boolean hasAccess,
182189
this.finalStatus = app.getFinalApplicationStatus();
183190
this.clusterId = ResourceManager.getClusterTimeStamp();
184191
if (hasAccess) {
192+
if (rm != null && rm.getConfig() != null) {
193+
try {
194+
Configuration yarnConfig = rm.getConfig();
195+
subClusterId = new SubClusterIdInfo(YarnConfiguration.getClusterId(yarnConfig));
196+
rmClusterId = this.subClusterId.toId().toString();
197+
} catch (HadoopIllegalArgumentException e) {
198+
subClusterId = null;
199+
rmClusterId = null;
200+
}
201+
}
185202
this.startedTime = app.getStartTime();
186203
this.launchTime = app.getLaunchTime();
187204
this.finishedTime = app.getFinishTime();
@@ -454,6 +471,14 @@ public long getClusterId() {
454471
return this.clusterId;
455472
}
456473

474+
public SubClusterIdInfo getSubClusterIdInfo() {
475+
return this.subClusterId;
476+
}
477+
478+
public String getRmClusterId() {
479+
return this.rmClusterId;
480+
}
481+
457482
public String getApplicationType() {
458483
return this.applicationType;
459484
}

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/webapp/TestRMWebServicesApps.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected void configureServlets() {
103103
YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
104104
conf.setClass(YarnConfiguration.RM_SCHEDULER, scheduler,
105105
ResourceScheduler.class);
106+
conf.set(YarnConfiguration.RM_CLUSTER_ID, "subCluster1");
106107
rm = new MockRM(conf);
107108
bind(ResourceManager.class).toInstance(rm);
108109
serve("/*").with(GuiceContainer.class);
@@ -1805,7 +1806,7 @@ public void verifyAppsXML(NodeList nodes, RMApp app, boolean hasResourceReq)
18051806
public void verifyAppInfo(JSONObject info, RMApp app, boolean hasResourceReqs)
18061807
throws JSONException, Exception {
18071808

1808-
int expectedNumberOfElements = 40 + (hasResourceReqs ? 2 : 0);
1809+
int expectedNumberOfElements = 41 + (hasResourceReqs ? 2 : 0);
18091810
String appNodeLabelExpression = null;
18101811
String amNodeLabelExpression = null;
18111812
if (app.getApplicationSubmissionContext()
@@ -1825,6 +1826,7 @@ public void verifyAppInfo(JSONObject info, RMApp app, boolean hasResourceReqs)
18251826
}
18261827
assertEquals("incorrect number of elements", expectedNumberOfElements,
18271828
info.length());
1829+
assertEquals("rmClusterId is incorrect", "subCluster1", info.getString("rmClusterId"));
18281830
verifyAppInfoGeneric(app, info.getString("id"), info.getString("user"),
18291831
info.getString("name"), info.getString("applicationType"),
18301832
info.getString("queue"), info.getInt("priority"),

0 commit comments

Comments
 (0)