YARN-3393. Getting application(s) goes wrong when app finishes before

starting the attempt. Contributed by Zhijie Shen

(cherry picked from commit 9fae455e26)
This commit is contained in:
Xuan 2015-03-23 20:33:16 -07:00
parent 01c0bcb176
commit cbdcdfad6d
3 changed files with 42 additions and 13 deletions

View File

@ -783,6 +783,9 @@ Release 2.7.0 - UNRELEASED
YARN-3336. FileSystem memory leak in DelegationTokenRenewer. YARN-3336. FileSystem memory leak in DelegationTokenRenewer.
(Zhihai Xu via cnauroth) (Zhihai Xu via cnauroth)
YARN-3393. Getting application(s) goes wrong when app finishes before
starting the attempt. (Zhijie Shen via xgong)
Release 2.6.0 - 2014-11-18 Release 2.6.0 - 2014-11-18
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -517,15 +517,14 @@ public class ApplicationHistoryManagerOnTimelineStore extends AbstractService
if (app.appReport.getCurrentApplicationAttemptId() != null) { if (app.appReport.getCurrentApplicationAttemptId() != null) {
ApplicationAttemptReport appAttempt = ApplicationAttemptReport appAttempt =
getApplicationAttempt(app.appReport.getCurrentApplicationAttemptId()); getApplicationAttempt(app.appReport.getCurrentApplicationAttemptId());
if (appAttempt != null) { app.appReport.setHost(appAttempt.getHost());
app.appReport.setHost(appAttempt.getHost()); app.appReport.setRpcPort(appAttempt.getRpcPort());
app.appReport.setRpcPort(appAttempt.getRpcPort()); app.appReport.setTrackingUrl(appAttempt.getTrackingUrl());
app.appReport.setTrackingUrl(appAttempt.getTrackingUrl()); app.appReport.setOriginalTrackingUrl(appAttempt.getOriginalTrackingUrl());
app.appReport.setOriginalTrackingUrl(appAttempt.getOriginalTrackingUrl());
}
} }
} catch (AuthorizationException e) { } catch (AuthorizationException | ApplicationAttemptNotFoundException e) {
// AuthorizationException is thrown because the user doesn't have access // AuthorizationException is thrown because the user doesn't have access
// It's possible that the app is finished before the first attempt is created.
app.appReport.setDiagnostics(null); app.appReport.setDiagnostics(null);
app.appReport.setCurrentApplicationAttemptId(null); app.appReport.setCurrentApplicationAttemptId(null);
} }

View File

@ -76,6 +76,10 @@ public class TestApplicationHistoryManagerOnTimelineStore {
@BeforeClass @BeforeClass
public static void prepareStore() throws Exception { public static void prepareStore() throws Exception {
store = createStore(SCALE); store = createStore(SCALE);
TimelineEntities entities = new TimelineEntities();
entities.addEntity(createApplicationTimelineEntity(
ApplicationId.newInstance(0, SCALE + 1), true, false));
store.put(entities);
} }
public static TimelineStore createStore(int scale) throws Exception { public static TimelineStore createStore(int scale) throws Exception {
@ -129,9 +133,9 @@ public class TestApplicationHistoryManagerOnTimelineStore {
TimelineEntities entities = new TimelineEntities(); TimelineEntities entities = new TimelineEntities();
ApplicationId appId = ApplicationId.newInstance(0, i); ApplicationId appId = ApplicationId.newInstance(0, i);
if (i == 2) { if (i == 2) {
entities.addEntity(createApplicationTimelineEntity(appId, true)); entities.addEntity(createApplicationTimelineEntity(appId, true, true));
} else { } else {
entities.addEntity(createApplicationTimelineEntity(appId, false)); entities.addEntity(createApplicationTimelineEntity(appId, false, true));
} }
store.put(entities); store.put(entities);
for (int j = 1; j <= scale; ++j) { for (int j = 1; j <= scale; ++j) {
@ -215,6 +219,27 @@ public class TestApplicationHistoryManagerOnTimelineStore {
} }
} }
@Test
public void testGetApplicationReportWithNotAttempt() throws Exception {
final ApplicationId appId = ApplicationId.newInstance(0, SCALE + 1);
ApplicationReport app;
if (callerUGI == null) {
app = historyManager.getApplication(appId);
} else {
app =
callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport> () {
@Override
public ApplicationReport run() throws Exception {
return historyManager.getApplication(appId);
}
});
}
Assert.assertNotNull(app);
Assert.assertEquals(appId, app.getApplicationId());
Assert.assertEquals(ApplicationAttemptId.newInstance(appId, -1),
app.getCurrentApplicationAttemptId());
}
@Test @Test
public void testGetApplicationAttemptReport() throws Exception { public void testGetApplicationAttemptReport() throws Exception {
final ApplicationAttemptId appAttemptId = final ApplicationAttemptId appAttemptId =
@ -308,7 +333,7 @@ public class TestApplicationHistoryManagerOnTimelineStore {
Collection<ApplicationReport> apps = Collection<ApplicationReport> apps =
historyManager.getAllApplications().values(); historyManager.getAllApplications().values();
Assert.assertNotNull(apps); Assert.assertNotNull(apps);
Assert.assertEquals(SCALE, apps.size()); Assert.assertEquals(SCALE + 1, apps.size());
} }
@Test @Test
@ -408,7 +433,7 @@ public class TestApplicationHistoryManagerOnTimelineStore {
} }
private static TimelineEntity createApplicationTimelineEntity( private static TimelineEntity createApplicationTimelineEntity(
ApplicationId appId, boolean emptyACLs) { ApplicationId appId, boolean emptyACLs, boolean noAttempt) {
TimelineEntity entity = new TimelineEntity(); TimelineEntity entity = new TimelineEntity();
entity.setEntityType(ApplicationMetricsConstants.ENTITY_TYPE); entity.setEntityType(ApplicationMetricsConstants.ENTITY_TYPE);
entity.setEntityId(appId.toString()); entity.setEntityId(appId.toString());
@ -447,8 +472,10 @@ public class TestApplicationHistoryManagerOnTimelineStore {
FinalApplicationStatus.UNDEFINED.toString()); FinalApplicationStatus.UNDEFINED.toString());
eventInfo.put(ApplicationMetricsConstants.STATE_EVENT_INFO, eventInfo.put(ApplicationMetricsConstants.STATE_EVENT_INFO,
YarnApplicationState.FINISHED.toString()); YarnApplicationState.FINISHED.toString());
eventInfo.put(ApplicationMetricsConstants.LATEST_APP_ATTEMPT_EVENT_INFO, if (noAttempt) {
ApplicationAttemptId.newInstance(appId, 1)); eventInfo.put(ApplicationMetricsConstants.LATEST_APP_ATTEMPT_EVENT_INFO,
ApplicationAttemptId.newInstance(appId, 1));
}
tEvent.setEventInfo(eventInfo); tEvent.setEventInfo(eventInfo);
entity.addEvent(tEvent); entity.addEvent(tEvent);
return entity; return entity;