Search in sources :

Example 21 with ApplicationResourceUsageReport

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());
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationResourceUsageReport(org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 22 with ApplicationResourceUsageReport

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);
}
Also used : ApplicationResourceUsageReport(org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport)

Aggregations

ApplicationResourceUsageReport (org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport)22 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)10 Test (org.junit.Test)9 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)7 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)6 Resource (org.apache.hadoop.yarn.api.records.Resource)5 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)3 ApplicationTimeout (org.apache.hadoop.yarn.api.records.ApplicationTimeout)3 Container (org.apache.hadoop.yarn.api.records.Container)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)3 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)3 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)3 YarnScheduler (org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintWriter (java.io.PrintWriter)2 HashMap (java.util.HashMap)2 FinalApplicationStatus (org.apache.hadoop.yarn.api.records.FinalApplicationStatus)2 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)2 MockAM (org.apache.hadoop.yarn.server.resourcemanager.MockAM)2 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)2