ClientRMService extends AbstractService implements
    ApplicationClientProtocol { @SuppressWarnings("unchecked") @Override public MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues( MoveApplicationAcrossQueuesRequest request) throws YarnException { ApplicationId applicationId = request.getApplicationId(); UserGroupInformation callerUGI = getCallerUgi(applicationId, AuditConstants.MOVE_APP_REQUEST); RMApp application = verifyUserAccessForRMApp(applicationId, callerUGI, AuditConstants.MOVE_APP_REQUEST, ApplicationAccessType.MODIFY_APP, true); 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)); } 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); return recordFactory .newRecordInstance(MoveApplicationAcrossQueuesResponse.class); } ClientRMService(RMContext rmContext, YarnScheduler scheduler,
      RMAppManager rmAppManager, ApplicationACLsManager applicationACLsManager,
      QueueACLsManager queueACLsManager,
      RMDelegationTokenSecretManager rmDTSecretManager);  ClientRMService(RMContext rmContext, YarnScheduler scheduler,
      RMAppManager rmAppManager, ApplicationACLsManager applicationACLsManager,
      QueueACLsManager queueACLsManager,
      RMDelegationTokenSecretManager rmDTSecretManager, Clock clock); @Private InetSocketAddress getBindAddress(); @Override GetNewApplicationResponse getNewApplication(
      GetNewApplicationRequest request); @Override GetApplicationReportResponse getApplicationReport(
      GetApplicationReportRequest request); @Override GetApplicationAttemptReportResponse getApplicationAttemptReport(
      GetApplicationAttemptReportRequest request); @Override GetApplicationAttemptsResponse getApplicationAttempts(
      GetApplicationAttemptsRequest request); @Override GetContainerReportResponse getContainerReport(
      GetContainerReportRequest request); @Override GetContainersResponse getContainers(GetContainersRequest request); @Override SubmitApplicationResponse submitApplication(
      SubmitApplicationRequest request); @SuppressWarnings("unchecked") @Override FailApplicationAttemptResponse failApplicationAttempt(
      FailApplicationAttemptRequest request); @SuppressWarnings("unchecked") @Override KillApplicationResponse forceKillApplication(
      KillApplicationRequest request); @Override GetClusterMetricsResponse getClusterMetrics(
      GetClusterMetricsRequest request); @Override GetApplicationsResponse getApplications(GetApplicationsRequest request); @Override GetClusterNodesResponse getClusterNodes(GetClusterNodesRequest request); @Override GetQueueInfoResponse getQueueInfo(GetQueueInfoRequest request); @Override GetQueueUserAclsInfoResponse getQueueUserAcls(
      GetQueueUserAclsInfoRequest request); @Override GetDelegationTokenResponse getDelegationToken(
      GetDelegationTokenRequest request); @Override RenewDelegationTokenResponse renewDelegationToken(
      RenewDelegationTokenRequest request); @Override CancelDelegationTokenResponse cancelDelegationToken(
      CancelDelegationTokenRequest request); @SuppressWarnings("unchecked") @Override MoveApplicationAcrossQueuesResponse moveApplicationAcrossQueues(
      MoveApplicationAcrossQueuesRequest request); @VisibleForTesting Server getServer(); @Override GetNewReservationResponse getNewReservation(
      GetNewReservationRequest request); @Override ReservationSubmissionResponse submitReservation(
      ReservationSubmissionRequest request); @Override ReservationUpdateResponse updateReservation(
      ReservationUpdateRequest request); @Override ReservationDeleteResponse deleteReservation(
      ReservationDeleteRequest request); @Override ReservationListResponse listReservations(
        ReservationListRequest requestInfo); @Override GetNodesToLabelsResponse getNodeToLabels(
      GetNodesToLabelsRequest request); @Override GetLabelsToNodesResponse getLabelsToNodes(
      GetLabelsToNodesRequest request); @Override GetClusterNodeLabelsResponse getClusterNodeLabels(
      GetClusterNodeLabelsRequest request); @Override UpdateApplicationPriorityResponse updateApplicationPriority(
      UpdateApplicationPriorityRequest request); @SuppressWarnings("unchecked") @Override SignalContainerResponse signalToContainer(
      SignalContainerRequest request); @Override UpdateApplicationTimeoutsResponse updateApplicationTimeouts(
      UpdateApplicationTimeoutsRequest request); @Override GetAllResourceProfilesResponse getResourceProfiles(
      GetAllResourceProfilesRequest request); @Override GetResourceProfileResponse getResourceProfile(
      GetResourceProfileRequest request); @Override GetAllResourceTypeInfoResponse getResourceTypeInfo(
      GetAllResourceTypeInfoRequest request); @Override GetAttributesToNodesResponse getAttributesToNodes(
      GetAttributesToNodesRequest request); @Override GetClusterNodeAttributesResponse getClusterNodeAttributes(
      GetClusterNodeAttributesRequest request); @Override GetNodesToAttributesResponse getNodesToAttributes(
      GetNodesToAttributesRequest request); @VisibleForTesting void setDisplayPerUserApps(boolean displayPerUserApps);  }
@Test (expected = ApplicationNotFoundException.class) public void testMoveAbsentApplication() throws YarnException { RMContext rmContext = mock(RMContext.class); when(rmContext.getRMApps()).thenReturn( new ConcurrentHashMap<ApplicationId, RMApp>()); ClientRMService rmService = new ClientRMService(rmContext, null, null, null, null, null); ApplicationId applicationId = BuilderUtils.newApplicationId(System.currentTimeMillis(), 0); MoveApplicationAcrossQueuesRequest request = MoveApplicationAcrossQueuesRequest.newInstance(applicationId, "newqueue"); rmService.moveApplicationAcrossQueues(request); }
@Test public void testMoveApplicationSubmitTargetQueue() throws Exception { ApplicationId applicationId = getApplicationId(1); UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser(); QueueACLsManager queueACLsManager = getQueueAclManager("allowed_queue", QueueACL.SUBMIT_APPLICATIONS, aclUGI); ApplicationACLsManager appAclsManager = getAppAclManager(); ClientRMService rmService = createClientRMServiceForMoveApplicationRequest( applicationId, aclUGI.getShortUserName(), appAclsManager, queueACLsManager); MoveApplicationAcrossQueuesRequest moveAppRequest = MoveApplicationAcrossQueuesRequest. newInstance(applicationId, "allowed_queue"); rmService.moveApplicationAcrossQueues(moveAppRequest); moveAppRequest = MoveApplicationAcrossQueuesRequest.newInstance( applicationId, "not_allowed"); try { rmService.moveApplicationAcrossQueues(moveAppRequest); Assert.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { Assert.assertTrue("AccessControlException is expected", rex.getCause() instanceof AccessControlException); } aclUGI = UserGroupInformation.createUserForTesting("moveuser", new String[]{}); queueACLsManager = getQueueAclManager("move_queue", QueueACL.SUBMIT_APPLICATIONS, aclUGI); appAclsManager = getAppAclManager(); ClientRMService rmService2 = createClientRMServiceForMoveApplicationRequest(applicationId, aclUGI.getShortUserName(), appAclsManager, queueACLsManager); MoveApplicationAcrossQueuesRequest moveAppRequest2 = MoveApplicationAcrossQueuesRequest. newInstance(applicationId, "move_queue"); try { rmService2.moveApplicationAcrossQueues(moveAppRequest2); Assert.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { Assert.assertTrue("AccessControlException is expected", rex.getCause() instanceof AccessControlException); } aclUGI.doAs(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { return rmService2.moveApplicationAcrossQueues(moveAppRequest2); } }); }
@Test public void testMoveApplicationAdminTargetQueue() throws Exception { ApplicationId applicationId = getApplicationId(1); UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser(); QueueACLsManager queueAclsManager = getQueueAclManager("allowed_queue", QueueACL.ADMINISTER_QUEUE, aclUGI); ApplicationACLsManager appAclsManager = getAppAclManager(); ClientRMService rmService = createClientRMServiceForMoveApplicationRequest(applicationId, aclUGI.getShortUserName(), appAclsManager, queueAclsManager); MoveApplicationAcrossQueuesRequest moveAppRequest = MoveApplicationAcrossQueuesRequest.newInstance(applicationId, "allowed_queue"); rmService.moveApplicationAcrossQueues(moveAppRequest); moveAppRequest = MoveApplicationAcrossQueuesRequest.newInstance( applicationId, "not_allowed"); try { rmService.moveApplicationAcrossQueues(moveAppRequest); Assert.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { Assert.assertTrue("AccessControlException is expected", rex.getCause() instanceof AccessControlException); } aclUGI = UserGroupInformation.createUserForTesting("moveuser", new String[]{}); queueAclsManager = getQueueAclManager("move_queue", QueueACL.ADMINISTER_QUEUE, aclUGI); appAclsManager = getAppAclManager(); ClientRMService rmService2 = createClientRMServiceForMoveApplicationRequest(applicationId, aclUGI.getShortUserName(), appAclsManager, queueAclsManager); MoveApplicationAcrossQueuesRequest moveAppRequest2 = MoveApplicationAcrossQueuesRequest. newInstance(applicationId, "move_queue"); try { rmService2.moveApplicationAcrossQueues(moveAppRequest2); Assert.fail("The request should fail with an AccessControlException"); } catch (YarnException rex) { Assert.assertTrue("AccessControlException is expected", rex.getCause() instanceof AccessControlException); } aclUGI.doAs(new PrivilegedExceptionAction<Object>() { @Override public Object run() throws Exception { return rmService2.moveApplicationAcrossQueues(moveAppRequest2); } }); }
@Test (expected = YarnException.class) public void testNonExistingQueue() throws Exception { ApplicationId applicationId = getApplicationId(1); UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser(); QueueACLsManager queueAclsManager = getQueueAclManager(); ApplicationACLsManager appAclsManager = getAppAclManager(); ClientRMService rmService = createClientRMServiceForMoveApplicationRequest(applicationId, aclUGI.getShortUserName(), appAclsManager, queueAclsManager); MoveApplicationAcrossQueuesRequest moveAppRequest = MoveApplicationAcrossQueuesRequest.newInstance(applicationId, "unknown_queue"); rmService.moveApplicationAcrossQueues(moveAppRequest); }