Search in sources :

Example 16 with ApplicationNotFoundException

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

the class AppReportFetcher method getApplicationReport.

/**
   * Get an application report for the specified application id from the RM and
   * fall back to the Application History Server if not found in RM.
   * @param appId id of the application to get.
   * @return the ApplicationReport for the appId.
   * @throws YarnException on any error.
   * @throws IOException
   */
public FetchedAppReport getApplicationReport(ApplicationId appId) throws YarnException, IOException {
    GetApplicationReportRequest request = recordFactory.newRecordInstance(GetApplicationReportRequest.class);
    request.setApplicationId(appId);
    ApplicationReport appReport;
    FetchedAppReport fetchedAppReport;
    try {
        appReport = applicationsManager.getApplicationReport(request).getApplicationReport();
        fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.RM);
    } catch (ApplicationNotFoundException e) {
        if (!isAHSEnabled) {
            // Just throw it as usual if historyService is not enabled.
            throw e;
        }
        //Fetch the application report from AHS
        appReport = historyManager.getApplicationReport(request).getApplicationReport();
        fetchedAppReport = new FetchedAppReport(appReport, AppReportSource.AHS);
    }
    return fetchedAppReport;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) GetApplicationReportRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)

Example 17 with ApplicationNotFoundException

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

the class HadoopArchiveLogs method filterAppsByAggregatedStatus.

@VisibleForTesting
void filterAppsByAggregatedStatus() throws IOException, YarnException {
    YarnClient client = YarnClient.createYarnClient();
    try {
        client.init(getConf());
        client.start();
        for (Iterator<AppInfo> it = eligibleApplications.iterator(); it.hasNext(); ) {
            AppInfo app = it.next();
            try {
                ApplicationReport report = client.getApplicationReport(ApplicationId.fromString(app.getAppId()));
                LogAggregationStatus aggStatus = report.getLogAggregationStatus();
                if (aggStatus.equals(LogAggregationStatus.RUNNING) || aggStatus.equals(LogAggregationStatus.RUNNING_WITH_FAILURE) || aggStatus.equals(LogAggregationStatus.NOT_START) || aggStatus.equals(LogAggregationStatus.DISABLED) || aggStatus.equals(LogAggregationStatus.FAILED)) {
                    if (verbose) {
                        LOG.info("Skipping " + app.getAppId() + " due to aggregation status being " + aggStatus);
                    }
                    it.remove();
                } else {
                    if (verbose) {
                        LOG.info(app.getAppId() + " has aggregation status " + aggStatus);
                    }
                    app.setFinishTime(report.getFinishTime());
                }
            } catch (ApplicationNotFoundException e) {
                // Assume the aggregation has finished
                if (verbose) {
                    LOG.info(app.getAppId() + " not in the ResourceManager");
                }
            }
        }
    } finally {
        if (client != null) {
            client.stop();
        }
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) LogAggregationStatus(org.apache.hadoop.yarn.api.records.LogAggregationStatus) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 18 with ApplicationNotFoundException

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

the class ClientRMService method moveApplicationAcrossQueues.

@SuppressWarnings("unchecked")
@Override
public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(MoveApplicationAcrossQueuesRequest request) throws YarnException {
    ApplicationId applicationId = request.getApplicationId();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        RMAuditLogger.logFailure("UNKNOWN", AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService", "Error getting UGI", applicationId);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(applicationId);
    if (application == null) {
        RMAuditLogger.logFailure(callerUGI.getUserName(), AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService", "Trying to move an absent application", applicationId);
        throw new ApplicationNotFoundException("Trying to move an absent" + " application " + applicationId);
    }
    if (!checkAccess(callerUGI, application.getUser(), ApplicationAccessType.MODIFY_APP, application)) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.MOVE_APP_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));
    }
    String targetQueue = request.getTargetQueue();
    if (!accessToTargetQueueAllowed(callerUGI, application, targetQueue)) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.MOVE_APP_REQUEST, "Target queue doesn't exist or user" + " doesn't have permissions to submit to target queue: " + targetQueue, "ClientRMService", AuditConstants.UNAUTHORIZED_USER, applicationId);
        throw RPCUtil.getRemoteException(new AccessControlException("User " + callerUGI.getShortUserName() + " cannot submit applications to" + " target queue or the target queue doesn't exist: " + targetQueue + " while moving " + applicationId));
    }
    // state.
    if (!ACTIVE_APP_STATES.contains(application.getState())) {
        String msg = "App in " + application.getState() + " state cannot be moved.";
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService", msg);
        throw new YarnException(msg);
    }
    try {
        this.rmAppManager.moveApplicationAcrossQueue(application.getApplicationId(), request.getTargetQueue());
    } catch (YarnException ex) {
        RMAuditLogger.logFailure(callerUGI.getShortUserName(), AuditConstants.MOVE_APP_REQUEST, "UNKNOWN", "ClientRMService", ex.getMessage());
        throw ex;
    }
    RMAuditLogger.logSuccess(callerUGI.getShortUserName(), AuditConstants.MOVE_APP_REQUEST, "ClientRMService", applicationId);
    MoveApplicationAcrossQueuesResponse response = recordFactory.newRecordInstance(MoveApplicationAcrossQueuesResponse.class);
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) MoveApplicationAcrossQueuesResponse(org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesResponse) AccessControlException(java.security.AccessControlException) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 19 with ApplicationNotFoundException

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

the class ClientRMService method getApplicationAttempts.

@Override
public GetApplicationAttemptsResponse getApplicationAttempts(GetApplicationAttemptsRequest request) throws YarnException, IOException {
    ApplicationId appId = request.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);
    GetApplicationAttemptsResponse response = null;
    if (allowAccess) {
        Map<ApplicationAttemptId, RMAppAttempt> attempts = application.getAppAttempts();
        List<ApplicationAttemptReport> listAttempts = new ArrayList<ApplicationAttemptReport>();
        Iterator<Map.Entry<ApplicationAttemptId, RMAppAttempt>> iter = attempts.entrySet().iterator();
        while (iter.hasNext()) {
            listAttempts.add(iter.next().getValue().createApplicationAttemptReport());
        }
        response = GetApplicationAttemptsResponse.newInstance(listAttempts);
    } 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) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) GetApplicationAttemptsResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptsResponse) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 20 with ApplicationNotFoundException

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

the class ClientRMService method getApplicationAttemptReport.

@Override
public GetApplicationAttemptReportResponse getApplicationAttemptReport(GetApplicationAttemptReportRequest request) throws YarnException, IOException {
    ApplicationAttemptId appAttemptId = request.getApplicationAttemptId();
    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(appAttemptId.getApplicationId());
    if (application == null) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + request.getApplicationAttemptId().getApplicationId() + "' doesn't exist in RM. Please check that the job " + "submission was successful.");
    }
    boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
    GetApplicationAttemptReportResponse 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.");
        }
        ApplicationAttemptReport attemptReport = appAttempt.createApplicationAttemptReport();
        response = GetApplicationAttemptReportResponse.newInstance(attemptReport);
    } else {
        throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilege to see this attempt " + appAttemptId);
    }
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetApplicationAttemptReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)

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