Search in sources :

Example 1 with MoveApplicationAcrossQueuesResponse

use of org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesResponse 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)

Aggregations

IOException (java.io.IOException)1 AccessControlException (java.security.AccessControlException)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1 MoveApplicationAcrossQueuesResponse (org.apache.hadoop.yarn.api.protocolrecords.MoveApplicationAcrossQueuesResponse)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)1