/**
   * @Title: handOver @Description: replace on chosen spot type with another unchosen spot type
   *
   * @param oldChosenType the old spot type
   * @param newChosenType the new unchosen spot type
   * @throws
   */
  public synchronized void handOver(
      InstanceTemplate oldChosenType, InstanceTemplate newChosenType) {
    if (!spotGroups.containsKey(oldChosenType)) {
      throw new IllegalArgumentException(oldChosenType.toString() + " not chosen");
    }

    if (spotGroups.containsKey(newChosenType)) {
      throw new IllegalArgumentException(newChosenType.toString() + " already chosen");
    }

    Set<InstanceStatus> instances = spotGroups.remove(oldChosenType);
    spotGroups.put(newChosenType, instances);
  }
  /**
   * @Title: moveOrphanToType @Description: assign orphan in the spot type
   *
   * @param type the spot type to move to
   * @return whether the operation is successful
   * @throws
   */
  public synchronized boolean moveOrphanToType(InstanceTemplate type) {
    Set<InstanceStatus> group = spotGroups.get(type);
    if (group == null) {
      throw new IllegalArgumentException("non chosen spot type " + type.toString());
    }

    if (hasOrphan()) {
      InstanceStatus instanceStatus = orphans.poll();
      group.add(instanceStatus);
      return true;
    }
    return false;
  }