Search in sources :

Example 21 with ApplicationAttemptReport

use of org.apache.hadoop.yarn.api.records.ApplicationAttemptReport in project samza by apache.

the class YarnJobValidationTool method validateRunningAttemptId.

public ApplicationAttemptId validateRunningAttemptId(ApplicationId appId) throws Exception {
    ApplicationAttemptId attemptId = this.client.getApplicationReport(appId).getCurrentApplicationAttemptId();
    ApplicationAttemptReport attemptReport = this.client.getApplicationAttemptReport(attemptId);
    if (attemptReport.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) {
        log.info("Job is running. AttempId " + attemptId.toString());
        return attemptId;
    } else {
        throw new SamzaException("Job not running " + this.jobName);
    }
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) SamzaException(org.apache.samza.SamzaException)

Example 22 with ApplicationAttemptReport

use of org.apache.hadoop.yarn.api.records.ApplicationAttemptReport in project hadoop by apache.

the class ApplicationHistoryManagerOnTimelineStore method generateApplicationReport.

private ApplicationReportExt generateApplicationReport(TimelineEntity entity, ApplicationReportField field) throws YarnException, IOException {
    ApplicationReportExt app = convertToApplicationReport(entity, field);
    // control, we can return immediately
    if (field == ApplicationReportField.USER_AND_ACLS) {
        return app;
    }
    try {
        checkAccess(app);
        if (app.appReport.getCurrentApplicationAttemptId() != null) {
            ApplicationAttemptReport appAttempt = getApplicationAttempt(app.appReport.getCurrentApplicationAttemptId(), false);
            app.appReport.setHost(appAttempt.getHost());
            app.appReport.setRpcPort(appAttempt.getRpcPort());
            app.appReport.setTrackingUrl(appAttempt.getTrackingUrl());
            app.appReport.setOriginalTrackingUrl(appAttempt.getOriginalTrackingUrl());
        }
    } catch (AuthorizationException | ApplicationAttemptNotFoundException e) {
        // AuthorizationException is thrown because the user doesn't have access
        if (e instanceof AuthorizationException) {
            LOG.warn("Failed to authorize when generating application report for " + app.appReport.getApplicationId() + ". Use a placeholder for its latest attempt id. ", e);
        } else {
            // Attempt not found
            LOG.info("No application attempt found for " + app.appReport.getApplicationId() + ". Use a placeholder for its latest attempt id. ", e);
        }
        // It's possible that the app is finished before the first attempt is created.
        app.appReport.setDiagnostics(null);
        app.appReport.setCurrentApplicationAttemptId(null);
    }
    if (app.appReport.getCurrentApplicationAttemptId() == null) {
        app.appReport.setCurrentApplicationAttemptId(ApplicationAttemptId.newInstance(app.appReport.getApplicationId(), -1));
    }
    if (app.appReport.getHost() == null) {
        app.appReport.setHost(UNAVAILABLE);
    }
    if (app.appReport.getRpcPort() < 0) {
        app.appReport.setRpcPort(-1);
    }
    if (app.appReport.getTrackingUrl() == null) {
        app.appReport.setTrackingUrl(UNAVAILABLE);
    }
    if (app.appReport.getOriginalTrackingUrl() == null) {
        app.appReport.setOriginalTrackingUrl(UNAVAILABLE);
    }
    if (app.appReport.getDiagnostics() == null) {
        app.appReport.setDiagnostics("");
    }
    return app;
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)

Example 23 with ApplicationAttemptReport

use of org.apache.hadoop.yarn.api.records.ApplicationAttemptReport in project hadoop by apache.

the class TestApplicationHistoryManagerOnTimelineStore method testGetApplicationAttempts.

@Test
public void testGetApplicationAttempts() throws Exception {
    final ApplicationId appId = ApplicationId.newInstance(0, 1);
    Collection<ApplicationAttemptReport> appAttempts;
    if (callerUGI == null) {
        appAttempts = historyManager.getApplicationAttempts(appId).values();
    } else {
        try {
            appAttempts = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ApplicationAttemptReport>>() {

                @Override
                public Collection<ApplicationAttemptReport> run() throws Exception {
                    return historyManager.getApplicationAttempts(appId).values();
                }
            });
            if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
                // The exception is expected
                Assert.fail();
            }
        } catch (AuthorizationException e) {
            if (callerUGI != null && callerUGI.getShortUserName().equals("user3")) {
                // The exception is expected
                return;
            }
            throw e;
        }
    }
    Assert.assertNotNull(appAttempts);
    Assert.assertEquals(SCALE, appAttempts.size());
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Example 24 with ApplicationAttemptReport

use of org.apache.hadoop.yarn.api.records.ApplicationAttemptReport in project hadoop by apache.

the class AppAttemptBlock method render.

@Override
protected void render(Block html) {
    String attemptid = $(APPLICATION_ATTEMPT_ID);
    if (attemptid.isEmpty()) {
        puts("Bad request: requires application attempt ID");
        return;
    }
    try {
        appAttemptId = ApplicationAttemptId.fromString(attemptid);
    } catch (IllegalArgumentException e) {
        puts("Invalid application attempt ID: " + attemptid);
        return;
    }
    UserGroupInformation callerUGI = getCallerUGI();
    ApplicationAttemptReport appAttemptReport;
    try {
        final GetApplicationAttemptReportRequest request = GetApplicationAttemptReportRequest.newInstance(appAttemptId);
        if (callerUGI == null) {
            appAttemptReport = appBaseProt.getApplicationAttemptReport(request).getApplicationAttemptReport();
        } else {
            appAttemptReport = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationAttemptReport>() {

                @Override
                public ApplicationAttemptReport run() throws Exception {
                    return appBaseProt.getApplicationAttemptReport(request).getApplicationAttemptReport();
                }
            });
        }
    } catch (Exception e) {
        String message = "Failed to read the application attempt " + appAttemptId + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    if (appAttemptReport == null) {
        puts("Application Attempt not found: " + attemptid);
        return;
    }
    boolean exceptionWhenGetContainerReports = false;
    Collection<ContainerReport> containers = null;
    try {
        final GetContainersRequest request = GetContainersRequest.newInstance(appAttemptId);
        if (callerUGI == null) {
            containers = appBaseProt.getContainers(request).getContainerList();
        } else {
            containers = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ContainerReport>>() {

                @Override
                public Collection<ContainerReport> run() throws Exception {
                    return appBaseProt.getContainers(request).getContainerList();
                }
            });
        }
    } catch (RuntimeException e) {
        // have this block to suppress the findbugs warning
        exceptionWhenGetContainerReports = true;
    } catch (Exception e) {
        exceptionWhenGetContainerReports = true;
    }
    AppAttemptInfo appAttempt = new AppAttemptInfo(appAttemptReport);
    setTitle(join("Application Attempt ", attemptid));
    String node = "N/A";
    if (appAttempt.getHost() != null && appAttempt.getRpcPort() >= 0 && appAttempt.getRpcPort() < 65536) {
        node = appAttempt.getHost() + ":" + appAttempt.getRpcPort();
    }
    generateOverview(appAttemptReport, containers, appAttempt, node);
    if (exceptionWhenGetContainerReports) {
        html.p()._("Sorry, Failed to get containers for application attempt" + attemptid + ".")._();
        return;
    }
    createAttemptHeadRoomTable(html);
    html._(InfoBlock.class);
    createTablesForAttemptMetrics(html);
    // Container Table
    TBODY<TABLE<Hamlet>> tbody = html.table("#containers").thead().tr().th(".id", "Container ID").th(".node", "Node").th(".exitstatus", "Container Exit Status").th(".logs", "Logs")._()._().tbody();
    StringBuilder containersTableData = new StringBuilder("[\n");
    for (ContainerReport containerReport : containers) {
        ContainerInfo container = new ContainerInfo(containerReport);
        containersTableData.append("[\"<a href='").append(url("container", container.getContainerId())).append("'>").append(container.getContainerId()).append("</a>\",\"<a ").append(container.getNodeHttpAddress() == null ? "#" : "href='" + container.getNodeHttpAddress()).append("'>").append(container.getNodeHttpAddress() == null ? "N/A" : StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(container.getNodeHttpAddress()))).append("</a>\",\"").append(container.getContainerExitStatus()).append("\",\"<a href='").append(container.getLogUrl() == null ? "#" : container.getLogUrl()).append("'>").append(container.getLogUrl() == null ? "N/A" : "Logs").append("</a>\"],\n");
    }
    if (containersTableData.charAt(containersTableData.length() - 2) == ',') {
        containersTableData.delete(containersTableData.length() - 2, containersTableData.length() - 1);
    }
    containersTableData.append("]");
    html.script().$type("text/javascript")._("var containersTableData=" + containersTableData)._();
    tbody._()._();
}
Also used : AppAttemptInfo(org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) GetApplicationAttemptReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) TABLE(org.apache.hadoop.yarn.webapp.hamlet.Hamlet.TABLE) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ContainerInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerInfo) GetContainersRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainersRequest) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 25 with ApplicationAttemptReport

use of org.apache.hadoop.yarn.api.records.ApplicationAttemptReport in project hadoop by apache.

the class AppBlock method render.

@Override
protected void render(Block html) {
    String webUiType = $(WEB_UI_TYPE);
    String aid = $(APPLICATION_ID);
    if (aid.isEmpty()) {
        puts("Bad request: requires Application ID");
        return;
    }
    try {
        appID = Apps.toAppID(aid);
    } catch (Exception e) {
        puts("Invalid Application ID: " + aid);
        return;
    }
    UserGroupInformation callerUGI = getCallerUGI();
    ApplicationReport appReport;
    try {
        final GetApplicationReportRequest request = GetApplicationReportRequest.newInstance(appID);
        if (callerUGI == null) {
            throw new AuthenticationException("Failed to get user name from request");
        } else {
            appReport = callerUGI.doAs(new PrivilegedExceptionAction<ApplicationReport>() {

                @Override
                public ApplicationReport run() throws Exception {
                    return appBaseProt.getApplicationReport(request).getApplicationReport();
                }
            });
        }
    } catch (Exception e) {
        String message = "Failed to read the application " + appID + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    if (appReport == null) {
        puts("Application not found: " + aid);
        return;
    }
    AppInfo app = new AppInfo(appReport);
    setTitle(join("Application ", aid));
    if (webUiType != null && webUiType.equals(YarnWebParams.RM_WEB_UI) && conf.getBoolean(YarnConfiguration.RM_WEBAPP_UI_ACTIONS_ENABLED, YarnConfiguration.DEFAULT_RM_WEBAPP_UI_ACTIONS_ENABLED)) {
        // Application Kill
        html.div().button().$onclick("confirmAction()").b("Kill Application")._()._();
        StringBuilder script = new StringBuilder();
        script.append("function confirmAction() {").append(" b = confirm(\"Are you sure?\");").append(" if (b == true) {").append(" $.ajax({").append(" type: 'PUT',").append(" url: '/ws/v1/cluster/apps/").append(aid).append("/state',").append(" contentType: 'application/json',").append(getCSRFHeaderString(conf)).append(" data: '{\"state\":\"KILLED\"}',").append(" dataType: 'json'").append(" }).done(function(data){").append(" setTimeout(function(){").append(" location.href = '/cluster/app/").append(aid).append("';").append(" }, 1000);").append(" }).fail(function(data){").append(" console.log(data);").append(" });").append(" }").append("}");
        html.script().$type("text/javascript")._(script.toString())._();
    }
    String schedulerPath = WebAppUtils.getResolvedRMWebAppURLWithScheme(conf) + "/cluster/scheduler?openQueues=" + app.getQueue();
    generateOverviewTable(app, schedulerPath, webUiType, appReport);
    Collection<ApplicationAttemptReport> attempts;
    try {
        final GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.newInstance(appID);
        attempts = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ApplicationAttemptReport>>() {

            @Override
            public Collection<ApplicationAttemptReport> run() throws Exception {
                return appBaseProt.getApplicationAttempts(request).getApplicationAttemptList();
            }
        });
    } catch (Exception e) {
        String message = "Failed to read the attempts of the application " + appID + ".";
        LOG.error(message, e);
        html.p()._(message)._();
        return;
    }
    createApplicationMetricsTable(html);
    html._(InfoBlock.class);
    generateApplicationTable(html, callerUGI, attempts);
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) GetApplicationAttemptsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsRequest) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo)

Aggregations

ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)35 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)18 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)17 Test (org.junit.Test)15 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)8 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)7 Configuration (org.apache.hadoop.conf.Configuration)6 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)6 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)5 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)5 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)5 PrintWriter (java.io.PrintWriter)4 ArrayList (java.util.ArrayList)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)4 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 GetApplicationAttemptReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportRequest)3