Skip to content

Commit 9445abb

Browse files
author
Prabhu Josephraj
committed
YARN-10792. Set Completed AppAttempt LogsLink to Log Server URL. Contributed by Abhinaba Sarkar
1 parent ec16b1d commit 9445abb

File tree

2 files changed

+61
-5
lines changed
  • hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src

2 files changed

+61
-5
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/AppAttemptInfo.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323

2424
import com.google.gson.Gson;
2525
import org.apache.commons.lang3.StringUtils;
26+
import org.apache.hadoop.conf.Configuration;
2627
import org.apache.hadoop.yarn.api.records.Container;
28+
import org.apache.hadoop.yarn.conf.YarnConfiguration;
2729
import org.apache.hadoop.yarn.server.resourcemanager.ResourceManager;
2830
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt;
2931
import org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptState;
3032
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler;
3133
import org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerApplicationAttempt;
3234
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
3335

36+
import static org.apache.hadoop.yarn.util.StringHelper.PATH_JOINER;
37+
3438
@XmlRootElement(name = "appAttempt")
3539
@XmlAccessorType(XmlAccessType.FIELD)
3640
public class AppAttemptInfo {
@@ -64,15 +68,29 @@ public AppAttemptInfo(ResourceManager rm, RMAppAttempt attempt,
6468
this.id = attempt.getAppAttemptId().getAttemptId();
6569
this.startTime = attempt.getStartTime();
6670
this.finishedTime = attempt.getFinishTime();
71+
this.appAttemptState = attempt.getAppAttemptState();
72+
this.appAttemptId = attempt.getAppAttemptId().toString();
6773
Container masterContainer = attempt.getMasterContainer();
6874
if (masterContainer != null && hasAccess) {
6975
this.containerId = masterContainer.getId().toString();
7076
this.nodeHttpAddress = masterContainer.getNodeHttpAddress();
7177
this.nodeId = masterContainer.getNodeId().toString();
72-
this.logsLink = WebAppUtils.getRunningLogURL(schemePrefix
73-
+ masterContainer.getNodeHttpAddress(),
74-
masterContainer.getId().toString(), user);
7578

79+
Configuration conf = rm.getRMContext().getYarnConfiguration();
80+
String logServerUrl = conf.get(YarnConfiguration.YARN_LOG_SERVER_URL);
81+
if ((this.appAttemptState == RMAppAttemptState.FAILED ||
82+
this.appAttemptState == RMAppAttemptState.FINISHED ||
83+
this.appAttemptState == RMAppAttemptState.KILLED) &&
84+
logServerUrl != null) {
85+
this.logsLink = PATH_JOINER.join(logServerUrl,
86+
masterContainer.getNodeId().toString(),
87+
masterContainer.getId().toString(),
88+
masterContainer.getId().toString(), user);
89+
} else {
90+
this.logsLink = WebAppUtils.getRunningLogURL(schemePrefix
91+
+ masterContainer.getNodeHttpAddress(),
92+
masterContainer.getId().toString(), user);
93+
}
7694
Gson gson = new Gson();
7795
this.exportPorts = gson.toJson(masterContainer.getExposedPorts());
7896

@@ -90,8 +108,6 @@ public AppAttemptInfo(ResourceManager rm, RMAppAttempt attempt,
90108
}
91109
}
92110
}
93-
this.appAttemptId = attempt.getAppAttemptId().toString();
94-
this.appAttemptState = attempt.getAppAttemptState();
95111
}
96112
}
97113

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.assertResponseStatusCode;
6262
import static org.apache.hadoop.yarn.webapp.WebServicesTestUtils.checkStringMatch;
63+
import static org.assertj.core.api.Assertions.assertThat;
6364
import static org.junit.Assert.assertEquals;
6465
import static org.junit.Assert.assertTrue;
6566
import static org.junit.Assert.fail;
@@ -124,6 +125,45 @@ public void testAppAttempts() throws Exception {
124125
rm.stop();
125126
}
126127

128+
@Test (timeout = 20000)
129+
public void testCompletedAppAttempt() throws Exception {
130+
Configuration conf = rm.getConfig();
131+
String logServerUrl = "http://localhost:19888/jobhistory/logs";
132+
conf.set(YarnConfiguration.YARN_LOG_SERVER_URL, logServerUrl);
133+
conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
134+
rm.start();
135+
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 8192);
136+
MockRMAppSubmissionData data =
137+
MockRMAppSubmissionData.Builder.createWithMemory(CONTAINER_MB, rm)
138+
.withAppName("testwordcount")
139+
.withUser("user1")
140+
.build();
141+
RMApp app1 = MockRMAppSubmitter.submit(rm, data);
142+
MockAM am = MockRM.launchAndRegisterAM(app1, rm, amNodeManager);
143+
// fail the AM by sending CONTAINER_FINISHED event without registering.
144+
amNodeManager.nodeHeartbeat(am.getApplicationAttemptId(), 1,
145+
ContainerState.COMPLETE);
146+
rm.waitForState(am.getApplicationAttemptId(), RMAppAttemptState.FAILED);
147+
rm.waitForState(app1.getApplicationId(), RMAppState.FAILED);
148+
149+
WebResource r = resource();
150+
ClientResponse response = r.path("ws").path("v1").path("cluster")
151+
.path("apps").path(app1.getApplicationId().toString())
152+
.path("appattempts").accept(MediaType.APPLICATION_JSON)
153+
.get(ClientResponse.class);
154+
JSONObject json = response.getEntity(JSONObject.class);
155+
JSONObject jsonAppAttempts = json.getJSONObject("appAttempts");
156+
JSONArray jsonArray = jsonAppAttempts.getJSONArray("appAttempt");
157+
JSONObject info = jsonArray.getJSONObject(0);
158+
String logsLink = info.getString("logsLink");
159+
String containerId = app1.getCurrentAppAttempt().getMasterContainer()
160+
.getId().toString();
161+
assertThat(logsLink).isEqualTo(logServerUrl
162+
+ "/127.0.0.1:1234/" + containerId + "/" + containerId + "/"
163+
+ "user1");
164+
rm.stop();
165+
}
166+
127167
@Test (timeout = 20000)
128168
public void testMultipleAppAttempts() throws Exception {
129169
rm.start();

0 commit comments

Comments
 (0)