Search in sources :

Example 26 with ApplicationNotFoundException

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

the class DAGClientImpl method getDAGStatusViaRM.

/**
 * Get the DAG status via the YARN ResourceManager
 * @return the dag status, inferred from the RM App state. Does not return null.
 * @throws TezException
 * @throws IOException
 */
@VisibleForTesting
protected DAGStatus getDAGStatusViaRM() throws TezException, IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("GetDAGStatus via AM for app: " + appId + " dag:" + dagId);
    }
    ApplicationReport appReport;
    try {
        appReport = frameworkClient.getApplicationReport(appId);
    } catch (ApplicationNotFoundException e) {
        LOG.info("DAG is no longer running - application not found by YARN", e);
        throw new DAGNotRunningException(e);
    } catch (YarnException e) {
        throw new TezException(e);
    }
    if (appReport == null) {
        throw new TezException("Unknown/Invalid appId: " + appId);
    }
    DAGProtos.DAGStatusProto.Builder builder = DAGProtos.DAGStatusProto.newBuilder();
    DAGStatus dagStatus = new DAGStatus(builder, DagStatusSource.RM);
    DAGProtos.DAGStatusStateProto dagState;
    switch(appReport.getYarnApplicationState()) {
        case NEW:
        case NEW_SAVING:
        case SUBMITTED:
        case ACCEPTED:
            dagState = DAGProtos.DAGStatusStateProto.DAG_SUBMITTED;
            break;
        case RUNNING:
            dagState = DAGProtos.DAGStatusStateProto.DAG_RUNNING;
            break;
        case FAILED:
            dagState = DAGProtos.DAGStatusStateProto.DAG_FAILED;
            break;
        case KILLED:
            dagState = DAGProtos.DAGStatusStateProto.DAG_KILLED;
            break;
        case FINISHED:
            switch(appReport.getFinalApplicationStatus()) {
                case UNDEFINED:
                case FAILED:
                    dagState = DAGProtos.DAGStatusStateProto.DAG_FAILED;
                    break;
                case KILLED:
                    dagState = DAGProtos.DAGStatusStateProto.DAG_KILLED;
                    break;
                case SUCCEEDED:
                    dagState = DAGProtos.DAGStatusStateProto.DAG_SUCCEEDED;
                    break;
                default:
                    throw new TezUncheckedException("Encountered unknown final application" + " status from YARN" + ", appState=" + appReport.getYarnApplicationState() + ", finalStatus=" + appReport.getFinalApplicationStatus());
            }
            break;
        default:
            throw new TezUncheckedException("Encountered unknown application state" + " from YARN, appState=" + appReport.getYarnApplicationState());
    }
    builder.setState(dagState);
    // workaround before YARN-2560 is fixed
    if (appReport.getFinalApplicationStatus() == FinalApplicationStatus.FAILED || appReport.getFinalApplicationStatus() == FinalApplicationStatus.KILLED) {
        long startTime = System.currentTimeMillis();
        while ((appReport.getDiagnostics() == null || appReport.getDiagnostics().isEmpty()) && (System.currentTimeMillis() - startTime) < diagnoticsWaitTimeout) {
            try {
                Thread.sleep(100);
                appReport = frameworkClient.getApplicationReport(appId);
            } catch (YarnException e) {
                throw new TezException(e);
            } catch (InterruptedException e) {
                throw new TezException(e);
            }
        }
    }
    if (appReport.getDiagnostics() != null) {
        builder.addAllDiagnostics(Collections.singleton(appReport.getDiagnostics()));
    }
    return dagStatus;
}
Also used : TezException(org.apache.tez.dag.api.TezException) TezUncheckedException(org.apache.tez.dag.api.TezUncheckedException) DAGProtos(org.apache.tez.dag.api.records.DAGProtos) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) DAGNotRunningException(org.apache.tez.dag.api.DAGNotRunningException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 27 with ApplicationNotFoundException

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

the class ClientRMService method getApplicationReport.

/**
   * It gives response which includes application report if the application
   * present otherwise throws ApplicationNotFoundException.
   */
@Override
public GetApplicationReportResponse getApplicationReport(GetApplicationReportRequest request) throws YarnException {
    ApplicationId applicationId = request.getApplicationId();
    if (applicationId == null) {
        throw new ApplicationNotFoundException("Invalid application id: null");
    }
    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(applicationId);
    if (application == null) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + applicationId + "' doesn't exist in RM. Please check " + "that the job submission was successful.");
    }
    boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
    ApplicationReport report = application.createAndGetApplicationReport(callerUGI.getUserName(), allowAccess);
    GetApplicationReportResponse response = recordFactory.newRecordInstance(GetApplicationReportResponse.class);
    response.setApplicationReport(report);
    return response;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetApplicationReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 28 with ApplicationNotFoundException

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

the class ClientRMService method getContainers.

/*
   * (non-Javadoc)
   * 
   * we're going to fix the issue of showing non-running containers of the
   * running application in YARN-1794"
   */
@Override
public GetContainersResponse getContainers(GetContainersRequest request) throws YarnException, IOException {
    ApplicationAttemptId appAttemptId = request.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);
    GetContainersResponse 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.");
        }
        Collection<RMContainer> rmContainers = Collections.emptyList();
        SchedulerAppReport schedulerAppReport = this.rmContext.getScheduler().getSchedulerAppInfo(appAttemptId);
        if (schedulerAppReport != null) {
            rmContainers = schedulerAppReport.getLiveContainers();
        }
        List<ContainerReport> listContainers = new ArrayList<ContainerReport>();
        for (RMContainer rmContainer : rmContainers) {
            listContainers.add(rmContainer.createContainerReport());
        }
        response = GetContainersResponse.newInstance(listContainers);
    } 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) ArrayList(java.util.ArrayList) GetContainersResponse(org.apache.hadoop.yarn.api.protocolrecords.GetContainersResponse) 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) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) SchedulerAppReport(org.apache.hadoop.yarn.server.resourcemanager.scheduler.SchedulerAppReport) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 29 with ApplicationNotFoundException

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

the class ClientRMService method failApplicationAttempt.

@SuppressWarnings("unchecked")
@Override
public FailApplicationAttemptResponse failApplicationAttempt(FailApplicationAttemptRequest request) throws YarnException {
    ApplicationAttemptId attemptId = request.getApplicationAttemptId();
    ApplicationId applicationId = attemptId.getApplicationId();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        RMAuditLogger.logFailure("UNKNOWN", AuditConstants.FAIL_ATTEMPT_REQUEST, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId, attemptId);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(applicationId);
    if (application == null) {
        RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "UNKNOWN", "ClientRMService", "Trying to fail an attempt of an absent application", applicationId, attemptId);
        throw new ApplicationNotFoundException("Trying to fail an attempt " + attemptId + " of an absent application " + applicationId);
    }
    RMAppAttempt appAttempt = application.getAppAttempts().get(attemptId);
    if (appAttempt == null) {
        throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + attemptId + "' doesn't exist in RM.");
    }
    if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId);
        throw RPCUtil.getRemoteException(new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
    }
    FailApplicationAttemptResponse response = recordFactory.newRecordInstance(FailApplicationAttemptResponse.class);
    if (!ACTIVE_APP_STATES.contains(application.getState())) {
        if (COMPLETED_APP_STATES.contains(application.getState())) {
            RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "ClientRMService", applicationId);
            return response;
        }
    }
    this.rmContext.getDispatcher().getEventHandler().handle(new RMAppAttemptEvent(attemptId, RMAppAttemptEventType.FAIL, "Attempt failed by user."));
    RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.FAIL_ATTEMPT_REQUEST, "ClientRMService", applicationId, attemptId);
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) AccessControlException(java.security.AccessControlException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) FailApplicationAttemptResponse(org.apache.hadoop.yarn.api.protocolrecords.FailApplicationAttemptResponse) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) RMAppAttemptEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptEvent)

Example 30 with ApplicationNotFoundException

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

the class ClientRMService method forceKillApplication.

@SuppressWarnings("unchecked")
@Override
public KillApplicationResponse forceKillApplication(KillApplicationRequest request) throws YarnException {
    ApplicationId applicationId = request.getApplicationId();
    CallerContext callerContext = CallerContext.getCurrent();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        RMAuditLogger.logFailure("UNKNOWN", AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId, callerContext);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(applicationId);
    if (application == null) {
        RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.KILL_APP_REQUEST, "UNKNOWN", "ClientRMService", "Trying to kill an absent application", applicationId, callerContext);
        throw new ApplicationNotFoundException("Trying to kill an absent" + " application " + applicationId);
    }
    if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.KILL_APP_REQUEST, "User doesn't have permissions to " + ApplicationAccessType.MODIFY_APP.toString(), "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId, callerContext);
        throw RPCUtil.getRemoteException(new AccessControlException("User " + callerUGI.getShortUserName() + " cannot perform operation " + ApplicationAccessType.MODIFY_APP.name() + " on " + applicationId));
    }
    if (application.isAppFinalStateStored()) {
        return KillApplicationResponse.newInstance(true);
    }
    StringBuilder message = new StringBuilder();
    message.append("Application ").append(applicationId).append(" was killed by user ").append(callerUGI.getShortUserName());
    InetAddress remoteAddress = Server.getRemoteIp();
    if (null != remoteAddress) {
        message.append(" at ").append(remoteAddress.getHostAddress());
    }
    String diagnostics = org.apache.commons.lang.StringUtils.trimToNull(request.getDiagnostics());
    if (diagnostics != null) {
        message.append(" with diagnostic message: ");
        message.append(diagnostics);
    }
    this.rmContext.getDispatcher().getEventHandler().handle(new RMAppKillByClientEvent(applicationId, message.toString(), callerUGI, remoteAddress));
    // For UnmanagedAMs, return true so they don't retry
    return KillApplicationResponse.newInstance(application.getApplicationSubmissionContext().getUnmanagedAM());
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) CallerContext(org.apache.hadoop.ipc.CallerContext) RMAppKillByClientEvent(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppKillByClientEvent) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) InetAddress(java.net.InetAddress) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

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