private RMContainer createReservedRMContainer(
     ApplicationAttemptId appAttId,
     int id,
     Resource resource,
     NodeId nodeId,
     Priority reservedPriority) {
   RMContainer container = createRMContainer(appAttId, id, resource);
   when(container.getReservedResource()).thenReturn(resource);
   when(container.getReservedPriority()).thenReturn(reservedPriority);
   when(container.getReservedNode()).thenReturn(nodeId);
   return container;
 }
  public synchronized void reserveResource(
      SchedulerApplicationAttempt application, Priority priority, RMContainer reservedContainer) {
    // Check if it's already reserved
    if (this.reservedContainer != null) {
      // Sanity check
      if (!reservedContainer.getContainer().getNodeId().equals(getNodeID())) {
        throw new IllegalStateException(
            "Trying to reserve"
                + " container "
                + reservedContainer
                + " on node "
                + reservedContainer.getReservedNode()
                + " when currently"
                + " reserved resource "
                + this.reservedContainer
                + " on node "
                + this.reservedContainer.getReservedNode());
      }

      // Cannot reserve more than one application attempt on a given node!
      // Reservation is still against attempt.
      if (!this.reservedContainer
          .getContainer()
          .getId()
          .getApplicationAttemptId()
          .equals(reservedContainer.getContainer().getId().getApplicationAttemptId())) {
        throw new IllegalStateException(
            "Trying to reserve"
                + " container "
                + reservedContainer
                + " for application "
                + application.getApplicationAttemptId()
                + " when currently"
                + " reserved container "
                + this.reservedContainer
                + " on node "
                + this);
      }

      if (LOG.isDebugEnabled()) {
        LOG.debug(
            "Updated reserved container "
                + reservedContainer.getContainer().getId()
                + " on node "
                + this
                + " for application attempt "
                + application.getApplicationAttemptId());
      }
    } else {
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            "Reserved container "
                + reservedContainer.getContainer().getId()
                + " on node "
                + this
                + " for application attempt "
                + application.getApplicationAttemptId());
      }
    }
    this.reservedContainer = reservedContainer;
  }