use of org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport in project hadoop by apache.
the class TestApplicationHistoryManagerOnTimelineStore method testGetApplicationReport.
@Test
public void testGetApplicationReport() throws Exception {
for (int i = 1; i <= 2; ++i) {
final ApplicationId appId = ApplicationId.newInstance(0, i);
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("test app", app.getName());
Assert.assertEquals("test app type", app.getApplicationType());
Assert.assertEquals("user1", app.getUser());
if (i == 2) {
// Change event is fired only in case of app with ID 2, hence verify
// with updated changes. And make sure last updated change is accepted.
Assert.assertEquals("changed queue1", app.getQueue());
Assert.assertEquals(Priority.newInstance(6), app.getPriority());
} else {
Assert.assertEquals("test queue", app.getQueue());
Assert.assertEquals(Priority.newInstance(0), app.getPriority());
}
Assert.assertEquals(Integer.MAX_VALUE + 2L + app.getApplicationId().getId(), app.getStartTime());
Assert.assertEquals(Integer.MAX_VALUE + 3L + +app.getApplicationId().getId(), app.getFinishTime());
Assert.assertTrue(Math.abs(app.getProgress() - 1.0F) < 0.0001);
Assert.assertEquals(2, app.getApplicationTags().size());
Assert.assertTrue(app.getApplicationTags().contains("Test_APP_TAGS_1"));
Assert.assertTrue(app.getApplicationTags().contains("Test_APP_TAGS_2"));
// Nobody except admin and owner has access to the details of the app.
if ((i == 1 && callerUGI != null && callerUGI.getShortUserName().equals("user3")) || (i == 2 && callerUGI != null && (callerUGI.getShortUserName().equals("user2") || callerUGI.getShortUserName().equals("user3")))) {
Assert.assertEquals(ApplicationAttemptId.newInstance(appId, -1), app.getCurrentApplicationAttemptId());
Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, app.getHost());
Assert.assertEquals(-1, app.getRpcPort());
Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, app.getTrackingUrl());
Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, app.getOriginalTrackingUrl());
Assert.assertEquals("", app.getDiagnostics());
} else {
Assert.assertEquals(ApplicationAttemptId.newInstance(appId, 1), app.getCurrentApplicationAttemptId());
Assert.assertEquals("test host", app.getHost());
Assert.assertEquals(100, app.getRpcPort());
Assert.assertEquals("test tracking url", app.getTrackingUrl());
Assert.assertEquals("test original tracking url", app.getOriginalTrackingUrl());
Assert.assertEquals("test diagnostics info", app.getDiagnostics());
}
ApplicationResourceUsageReport applicationResourceUsageReport = app.getApplicationResourceUsageReport();
Assert.assertEquals(123, applicationResourceUsageReport.getMemorySeconds());
Assert.assertEquals(345, applicationResourceUsageReport.getVcoreSeconds());
Assert.assertEquals(456, applicationResourceUsageReport.getPreemptedMemorySeconds());
Assert.assertEquals(789, applicationResourceUsageReport.getPreemptedVcoreSeconds());
Assert.assertEquals(FinalApplicationStatus.UNDEFINED, app.getFinalApplicationStatus());
Assert.assertEquals(YarnApplicationState.FINISHED, app.getYarnApplicationState());
}
}
use of org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport in project hadoop by apache.
the class RMAppAttemptMetrics method getAggregateAppResourceUsage.
public AggregateAppResourceUsage getAggregateAppResourceUsage() {
long memorySeconds = finishedMemorySeconds.get();
long vcoreSeconds = finishedVcoreSeconds.get();
// Only add in the running containers if this is the active attempt.
RMAppAttempt currentAttempt = rmContext.getRMApps().get(attemptId.getApplicationId()).getCurrentAppAttempt();
if (currentAttempt.getAppAttemptId().equals(attemptId)) {
ApplicationResourceUsageReport appResUsageReport = rmContext.getScheduler().getAppResourceUsageReport(attemptId);
if (appResUsageReport != null) {
memorySeconds += appResUsageReport.getMemorySeconds();
vcoreSeconds += appResUsageReport.getVcoreSeconds();
}
}
return new AggregateAppResourceUsage(memorySeconds, vcoreSeconds);
}
Aggregations