Search in sources :

Example 1 with ContainerNotFoundException

use of org.apache.hadoop.yarn.exceptions.ContainerNotFoundException in project hadoop by apache.

the class AppBlock method generateApplicationTable.

protected void generateApplicationTable(Block html, UserGroupInformation callerUGI, Collection<ApplicationAttemptReport> attempts) {
    // Application Attempt Table
    TBODY<TABLE<Hamlet>> tbody = html.table("#attempts").thead().tr().th(".id", "Attempt ID").th(".started", "Started").th(".node", "Node").th(".logs", "Logs")._()._().tbody();
    StringBuilder attemptsTableData = new StringBuilder("[\n");
    for (final ApplicationAttemptReport appAttemptReport : attempts) {
        AppAttemptInfo appAttempt = new AppAttemptInfo(appAttemptReport);
        ContainerReport containerReport;
        try {
            final GetContainerReportRequest request = GetContainerReportRequest.newInstance(appAttemptReport.getAMContainerId());
            if (callerUGI == null) {
                containerReport = appBaseProt.getContainerReport(request).getContainerReport();
            } else {
                containerReport = callerUGI.doAs(new PrivilegedExceptionAction<ContainerReport>() {

                    @Override
                    public ContainerReport run() throws Exception {
                        ContainerReport report = null;
                        if (request.getContainerId() != null) {
                            try {
                                report = appBaseProt.getContainerReport(request).getContainerReport();
                            } catch (ContainerNotFoundException ex) {
                                LOG.warn(ex.getMessage());
                            }
                        }
                        return report;
                    }
                });
            }
        } catch (Exception e) {
            String message = "Failed to read the AM container of the application attempt " + appAttemptReport.getApplicationAttemptId() + ".";
            LOG.error(message, e);
            html.p()._(message)._();
            return;
        }
        long startTime = 0L;
        String logsLink = null;
        String nodeLink = null;
        if (containerReport != null) {
            ContainerInfo container = new ContainerInfo(containerReport);
            startTime = container.getStartedTime();
            logsLink = containerReport.getLogUrl();
            nodeLink = containerReport.getNodeHttpAddress();
        }
        attemptsTableData.append("[\"<a href='").append(url("appattempt", appAttempt.getAppAttemptId())).append("'>").append(appAttempt.getAppAttemptId()).append("</a>\",\"").append(startTime).append("\",\"<a ").append(nodeLink == null ? "#" : "href='" + nodeLink).append("'>").append(nodeLink == null ? "N/A" : StringEscapeUtils.escapeJavaScript(StringEscapeUtils.escapeHtml(nodeLink))).append("</a>\",\"<a ").append(logsLink == null ? "#" : "href='" + logsLink).append("'>").append(logsLink == null ? "N/A" : "Logs").append("</a>\"],\n");
    }
    if (attemptsTableData.charAt(attemptsTableData.length() - 2) == ',') {
        attemptsTableData.delete(attemptsTableData.length() - 2, attemptsTableData.length() - 1);
    }
    attemptsTableData.append("]");
    html.script().$type("text/javascript")._("var attemptsTableData=" + attemptsTableData)._();
    tbody._()._();
}
Also used : AppAttemptInfo(org.apache.hadoop.yarn.server.webapp.dao.AppAttemptInfo) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest) 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) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)

Example 2 with ContainerNotFoundException

use of org.apache.hadoop.yarn.exceptions.ContainerNotFoundException in project hadoop by apache.

the class ApplicationHistoryManagerOnTimelineStore method getContainer.

@Override
public ContainerReport getContainer(ContainerId containerId) throws YarnException, IOException {
    ApplicationReportExt app = getApplication(containerId.getApplicationAttemptId().getApplicationId(), ApplicationReportField.USER_AND_ACLS);
    checkAccess(app);
    TimelineEntity entity = timelineDataManager.getEntity(ContainerMetricsConstants.ENTITY_TYPE, containerId.toString(), EnumSet.allOf(Field.class), UserGroupInformation.getLoginUser());
    if (entity == null) {
        throw new ContainerNotFoundException("The entity for container " + containerId + " doesn't exist in the timeline store");
    } else {
        return convertToContainerReport(entity, serverHttpAddress, app.appReport.getUser());
    }
}
Also used : Field(org.apache.hadoop.yarn.server.timeline.TimelineReader.Field) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)

Example 3 with ContainerNotFoundException

use of org.apache.hadoop.yarn.exceptions.ContainerNotFoundException in project hadoop by apache.

the class TestApplicationHistoryClientService method testContainerNotFound.

@Test
public void testContainerNotFound() throws IOException, YarnException {
    ApplicationId appId = ApplicationId.newInstance(0, 1);
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newContainerId(appAttemptId, MAX_APPS + 1);
    GetContainerReportRequest request = GetContainerReportRequest.newInstance(containerId);
    try {
        @SuppressWarnings("unused") GetContainerReportResponse response = clientService.getContainerReport(request);
    } catch (ContainerNotFoundException e) {
        //This exception is expected
        Assert.assertTrue(e.getMessage().contains("doesn't exist in the timeline store"));
    } catch (Exception e) {
        Assert.fail("Undesired exception caught");
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) GetContainerReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetContainerReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest) Test(org.junit.Test)

Example 4 with ContainerNotFoundException

use of org.apache.hadoop.yarn.exceptions.ContainerNotFoundException in project hadoop by apache.

the class ClientRMService method getContainerReport.

/*
   * (non-Javadoc)
   * 
   * we're going to fix the issue of showing non-running containers of the
   * running application in YARN-1794
   */
@Override
public GetContainerReportResponse getContainerReport(GetContainerReportRequest request) throws YarnException, IOException {
    ContainerId containerId = request.getContainerId();
    ApplicationAttemptId appAttemptId = containerId.getApplicationAttemptId();
    ApplicationId appId = appAttemptId.getApplicationId();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(appId);
    if (application == null) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + appId + "' doesn't exist in RM. Please check that the job submission " + "was successful.");
    }
    boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
    GetContainerReportResponse response = null;
    if (allowAccess) {
        RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
        if (appAttempt == null) {
            throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + appAttemptId + "' doesn't exist in RM.");
        }
        RMContainer rmConatiner = this.rmContext.getScheduler().getRMContainer(containerId);
        if (rmConatiner == null) {
            throw new ContainerNotFoundException("Container with id '" + containerId + "' doesn't exist in RM.");
        }
        response = GetContainerReportResponse.newInstance(rmConatiner.createContainerReport());
    } else {
        throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilege to see this application " + appId);
    }
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetContainerReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 5 with ContainerNotFoundException

use of org.apache.hadoop.yarn.exceptions.ContainerNotFoundException in project hadoop by apache.

the class ApplicationCLI method printContainerReport.

/**
   * Prints the container report for an container id.
   * 
   * @param containerId
   * @return exitCode
   * @throws YarnException
   */
private int printContainerReport(String containerId) throws YarnException, IOException {
    ContainerReport containerReport = null;
    try {
        containerReport = client.getContainerReport(ContainerId.fromString(containerId));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ApplicationAttemptNotFoundException e) {
        sysout.println("Application Attempt for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ContainerNotFoundException e) {
        sysout.println("Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter containerReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (containerReport != null) {
        containerReportStr.println("Container Report : ");
        containerReportStr.print("\tContainer-Id : ");
        containerReportStr.println(containerReport.getContainerId());
        containerReportStr.print("\tStart-Time : ");
        containerReportStr.println(containerReport.getCreationTime());
        containerReportStr.print("\tFinish-Time : ");
        containerReportStr.println(containerReport.getFinishTime());
        containerReportStr.print("\tState : ");
        containerReportStr.println(containerReport.getContainerState());
        containerReportStr.print("\tLOG-URL : ");
        containerReportStr.println(containerReport.getLogUrl());
        containerReportStr.print("\tHost : ");
        containerReportStr.println(containerReport.getAssignedNode());
        containerReportStr.print("\tNodeHttpAddress : ");
        containerReportStr.println(containerReport.getNodeHttpAddress() == null ? "N/A" : containerReport.getNodeHttpAddress());
        containerReportStr.print("\tDiagnostics : ");
        containerReportStr.print(containerReport.getDiagnosticsInfo());
    } else {
        containerReportStr.print("Container with id '" + containerId + "' doesn't exist in Timeline Server.");
        containerReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    containerReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) PrintWriter(java.io.PrintWriter)

Aggregations

ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)6 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)4 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)4 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)3 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)3 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)3 IOException (java.io.IOException)2 GetContainerReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportRequest)2 GetContainerReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetContainerReportResponse)2 ContainerReport (org.apache.hadoop.yarn.api.records.ContainerReport)2 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)1 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1