Search in sources :

Example 31 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException 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 32 with ApplicationNotFoundException

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

the class TestClientServiceDelegate method getRMDelegate.

private ResourceMgrDelegate getRMDelegate() throws IOException {
    ResourceMgrDelegate rm = mock(ResourceMgrDelegate.class);
    try {
        ApplicationId appId = jobId.getAppId();
        when(rm.getApplicationReport(appId)).thenThrow(new ApplicationNotFoundException(appId + " not found"));
    } catch (YarnException e) {
        throw new IOException(e);
    }
    return rm;
}
Also used : ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 33 with ApplicationNotFoundException

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

the class YarnClientImpl method getApplicationReport.

@Override
public ApplicationReport getApplicationReport(ApplicationId appId) throws YarnException, IOException {
    GetApplicationReportResponse response = null;
    try {
        GetApplicationReportRequest request = Records.newRecord(GetApplicationReportRequest.class);
        request.setApplicationId(appId);
        response = rmClient.getApplicationReport(request);
    } catch (ApplicationNotFoundException e) {
        if (!historyServiceEnabled) {
            // Just throw it as usual if historyService is not enabled.
            throw e;
        }
        return historyClient.getApplicationReport(appId);
    }
    return response.getApplicationReport();
}
Also used : GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetApplicationReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)

Example 34 with ApplicationNotFoundException

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

the class YarnClientImpl method submitApplication.

@Override
public ApplicationId submitApplication(ApplicationSubmissionContext appContext) throws YarnException, IOException {
    ApplicationId applicationId = appContext.getApplicationId();
    if (applicationId == null) {
        throw new ApplicationIdNotProvidedException("ApplicationId is not provided in ApplicationSubmissionContext");
    }
    SubmitApplicationRequest request = Records.newRecord(SubmitApplicationRequest.class);
    request.setApplicationSubmissionContext(appContext);
    // Only when the security and the timeline service are both enabled
    if (isSecurityEnabled() && timelineV1ServiceEnabled) {
        addTimelineDelegationToken(appContext.getAMContainerSpec());
    }
    //TODO: YARN-1763:Handle RM failovers during the submitApplication call.
    rmClient.submitApplication(request);
    int pollCount = 0;
    long startTime = System.currentTimeMillis();
    EnumSet<YarnApplicationState> waitingStates = EnumSet.of(YarnApplicationState.NEW, YarnApplicationState.NEW_SAVING, YarnApplicationState.SUBMITTED);
    EnumSet<YarnApplicationState> failToSubmitStates = EnumSet.of(YarnApplicationState.FAILED, YarnApplicationState.KILLED);
    while (true) {
        try {
            ApplicationReport appReport = getApplicationReport(applicationId);
            YarnApplicationState state = appReport.getYarnApplicationState();
            if (!waitingStates.contains(state)) {
                if (failToSubmitStates.contains(state)) {
                    throw new YarnException("Failed to submit " + applicationId + " to YARN : " + appReport.getDiagnostics());
                }
                LOG.info("Submitted application " + applicationId);
                break;
            }
            long elapsedMillis = System.currentTimeMillis() - startTime;
            if (enforceAsyncAPITimeout() && elapsedMillis >= asyncApiPollTimeoutMillis) {
                throw new YarnException("Timed out while waiting for application " + applicationId + " to be submitted successfully");
            }
            // is blocked here too long.
            if (++pollCount % 10 == 0) {
                LOG.info("Application submission is not finished, " + "submitted application " + applicationId + " is still in " + state);
            }
            try {
                Thread.sleep(submitPollIntervalMillis);
            } catch (InterruptedException ie) {
                String msg = "Interrupted while waiting for application " + applicationId + " to be successfully submitted.";
                LOG.error(msg);
                throw new YarnException(msg, ie);
            }
        } catch (ApplicationNotFoundException ex) {
            // FailOver or RM restart happens before RMStateStore saves
            // ApplicationState
            LOG.info("Re-submit application " + applicationId + "with the " + "same ApplicationSubmissionContext");
            rmClient.submitApplication(request);
        }
    }
    return applicationId;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ApplicationIdNotProvidedException(org.apache.hadoop.yarn.exceptions.ApplicationIdNotProvidedException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) SubmitApplicationRequest(org.apache.hadoop.yarn.api.protocolrecords.SubmitApplicationRequest) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 35 with ApplicationNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException 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

ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)50 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)28 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)21 Test (org.junit.Test)21 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)20 IOException (java.io.IOException)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)12 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)11 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)7 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)6 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)6 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)5 TezException (org.apache.tez.dag.api.TezException)5 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ServiceException (com.google.protobuf.ServiceException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3