SchedulerApplicationAttempt implements SchedulableEntity { public void move(Queue newQueue) { try { writeLock.lock(); QueueMetrics oldMetrics = queue.getMetrics(); QueueMetrics newMetrics = newQueue.getMetrics(); String newQueueName = newQueue.getQueueName(); String user = getUser(); for (RMContainer liveContainer : liveContainers.values()) { Resource resource = liveContainer.getContainer().getResource(); ((RMContainerImpl) liveContainer).setQueueName(newQueueName); oldMetrics.releaseResources(liveContainer.getNodeLabelExpression(), user, 1, resource); newMetrics.allocateResources(liveContainer.getNodeLabelExpression(), user, 1, resource, false); } for (Map<NodeId, RMContainer> map : reservedContainers.values()) { for (RMContainer reservedContainer : map.values()) { ((RMContainerImpl) reservedContainer).setQueueName(newQueueName); Resource resource = reservedContainer.getReservedResource(); oldMetrics.unreserveResource( reservedContainer.getNodeLabelExpression(), user, resource); newMetrics.reserveResource( reservedContainer.getNodeLabelExpression(), user, resource); } } if (!isStopped) { appSchedulingInfo.move(newQueue); } this.queue = newQueue; } finally { writeLock.unlock(); } } SchedulerApplicationAttempt(ApplicationAttemptId applicationAttemptId, 
      String user, Queue queue, AbstractUsersManager abstractUsersManager,
      RMContext rmContext); void setOpportunisticContainerContext(
      OpportunisticContainerContext oppContext); OpportunisticContainerContext getOpportunisticContainerContext(); Collection<RMContainer> getLiveContainers(); AppSchedulingInfo getAppSchedulingInfo(); ContainerUpdateContext getUpdateContext(); boolean isPending(); ApplicationAttemptId getApplicationAttemptId(); ApplicationId getApplicationId(); String getUser(); Set<ContainerId> getPendingRelease(); long getNewContainerId(); Collection<SchedulerRequestKey> getSchedulerKeys(); PendingAsk getPendingAsk(
      SchedulerRequestKey schedulerKey, String resourceName); int getOutstandingAsksCount(SchedulerRequestKey schedulerKey); int getOutstandingAsksCount(SchedulerRequestKey schedulerKey,
      String resourceName); String getQueueName(); Resource getAMResource(); Resource getAMResource(String label); void setAMResource(Resource amResource); void setAMResource(String label, Resource amResource); boolean isAmRunning(); void setAmRunning(boolean bool); boolean getUnmanagedAM(); RMContainer getRMContainer(ContainerId id); void addRMContainer(
      ContainerId id, RMContainer rmContainer); void removeRMContainer(ContainerId containerId); int getReReservations(SchedulerRequestKey schedulerKey); @Stable @Private Resource getCurrentReservation(); Queue getQueue(); boolean updateResourceRequests(
      List<ResourceRequest> requests); boolean updateSchedulingRequests(
      List<SchedulingRequest> requests); void recoverResourceRequestsForContainer(
      ContainerRequest containerRequest); void stop(RMAppAttemptState rmAppAttemptFinalState); boolean isStopped(); List<RMContainer> getReservedContainers(); boolean reserveIncreasedContainer(SchedulerNode node,
      SchedulerRequestKey schedulerKey, RMContainer rmContainer,
      Resource reservedResource); RMContainer reserve(SchedulerNode node,
      SchedulerRequestKey schedulerKey, RMContainer rmContainer,
      Container container); void setHeadroom(Resource globalLimit); Resource getHeadroom(); int getNumReservedContainers(
      SchedulerRequestKey schedulerKey); @SuppressWarnings("unchecked") void containerLaunchedOnNode(ContainerId containerId,
      NodeId nodeId); void showRequests(); Resource getCurrentConsumption(); void updateNMTokens(Collection<Container> containers); List<Container> pullPreviousAttemptContainers(); List<Container> pullNewlyAllocatedContainers(); synchronized void addToNewlyDemotedContainers(ContainerId containerId,
      RMContainer rmContainer); synchronized void addToNewlyDecreasedContainers(
      ContainerId containerId, RMContainer rmContainer); List<Container> pullNewlyPromotedContainers(); List<Container> pullNewlyDemotedContainers(); List<Container> pullNewlyIncreasedContainers(); List<Container> pullNewlyDecreasedContainers(); List<UpdateContainerError> pullUpdateContainerErrors(); List<NMToken> pullUpdatedNMTokens(); boolean isWaitingForAMContainer(); void updateBlacklist(List<String> blacklistAdditions,
      List<String> blacklistRemovals); boolean isPlaceBlacklisted(String resourceName); int addMissedNonPartitionedRequestSchedulingOpportunity(
      SchedulerRequestKey schedulerKey); void resetMissedNonPartitionedRequestSchedulingOpportunity(
      SchedulerRequestKey schedulerKey); void addSchedulingOpportunity(
      SchedulerRequestKey schedulerKey); void subtractSchedulingOpportunity(
      SchedulerRequestKey schedulerKey); int getSchedulingOpportunities(
      SchedulerRequestKey schedulerKey); void resetSchedulingOpportunities(
      SchedulerRequestKey schedulerKey); void resetSchedulingOpportunities(SchedulerRequestKey schedulerKey,
      long currentTimeMs); ApplicationResourceUsageReport getResourceUsageReport(); @VisibleForTesting Map<ContainerId, RMContainer> getLiveContainersMap(); Map<SchedulerRequestKey, Long> getLastScheduledContainer(); void transferStateFromPreviousAttempt(
      SchedulerApplicationAttempt appAttempt); void move(Queue newQueue); void recoverContainer(SchedulerNode node,
      RMContainer rmContainer); void incNumAllocatedContainers(NodeType containerType,
      NodeType requestType); void setApplicationHeadroomForMetrics(Resource headroom); void recordContainerRequestTime(long value); void recordContainerAllocationTime(long value); Set<String> getBlacklistedNodes(); @Private boolean hasPendingResourceRequest(String nodePartition,
      SchedulingMode schedulingMode); @VisibleForTesting ResourceUsage getAppAttemptResourceUsage(); @Override Priority getPriority(); void setPriority(Priority appPriority); @Override String getId(); @Override int compareInputOrderTo(SchedulableEntity other); @Override ResourceUsage getSchedulingResourceUsage(); void setAppAMNodePartitionName(String partitionName); String getAppAMNodePartitionName(); void updateAMContainerDiagnostics(AMState state,
      String diagnosticMessage); ReentrantReadWriteLock.WriteLock getWriteLock(); @Override boolean isRecovering(); AppPlacementAllocator<N> getAppPlacementAllocator(
      SchedulerRequestKey schedulerRequestKey); void incUnconfirmedRes(Resource res); void decUnconfirmedRes(Resource res); @Override int hashCode(); @Override boolean equals(Object o); Map<String, String> getApplicationSchedulingEnvs();  }
@Test public void testMove() { final String user = "user1"; Queue parentQueue = createQueue("parent", null); Queue oldQueue = createQueue("old", parentQueue); Queue newQueue = createQueue("new", parentQueue); QueueMetrics parentMetrics = parentQueue.getMetrics(); QueueMetrics oldMetrics = oldQueue.getMetrics(); QueueMetrics newMetrics = newQueue.getMetrics(); ApplicationAttemptId appAttId = createAppAttemptId(0, 0); RMContext rmContext = mock(RMContext.class); when(rmContext.getEpoch()).thenReturn(3L); SchedulerApplicationAttempt app = new SchedulerApplicationAttempt(appAttId, user, oldQueue, oldQueue.getAbstractUsersManager(), rmContext); oldMetrics.submitApp(user); assertEquals(0x30000000001L, app.getNewContainerId()); Resource requestedResource = Resource.newInstance(1536, 2); Priority requestedPriority = Priority.newInstance(2); ResourceRequest request = ResourceRequest.newInstance(requestedPriority, ResourceRequest.ANY, requestedResource, 3); app.updateResourceRequests(Arrays.asList(request)); RMContainer container1 = createRMContainer(appAttId, 1, requestedResource); app.liveContainers.put(container1.getContainerId(), container1); SchedulerNode node = createNode(); app.appSchedulingInfo.allocate(NodeType.OFF_SWITCH, node, toSchedulerKey(requestedPriority), container1.getContainer()); Priority prio1 = Priority.newInstance(1); Resource reservedResource = Resource.newInstance(2048, 3); RMContainer container2 = createReservedRMContainer(appAttId, 1, reservedResource, node.getNodeID(), prio1); Map<NodeId, RMContainer> reservations = new HashMap<NodeId, RMContainer>(); reservations.put(node.getNodeID(), container2); app.reservedContainers.put(toSchedulerKey(prio1), reservations); oldMetrics.reserveResource(container2.getNodeLabelExpression(), user, reservedResource); checkQueueMetrics(oldMetrics, 1, 1, 1536, 2, 2048, 3, 3072, 4); checkQueueMetrics(newMetrics, 0, 0, 0, 0, 0, 0, 0, 0); checkQueueMetrics(parentMetrics, 1, 1, 1536, 2, 2048, 3, 3072, 4); app.move(newQueue); checkQueueMetrics(oldMetrics, 0, 0, 0, 0, 0, 0, 0, 0); checkQueueMetrics(newMetrics, 1, 1, 1536, 2, 2048, 3, 3072, 4); checkQueueMetrics(parentMetrics, 1, 1, 1536, 2, 2048, 3, 3072, 4); }