class PriorityRouterPolicy extends AbstractRouterPolicy {

  @Override
  public SubClusterId getHomeSubcluster(
      ApplicationSubmissionContext appSubmissionContext,
      List<SubClusterId> blacklist) throws YarnException {

    // null checks and default-queue behavior
    validate(appSubmissionContext);

    Map<SubClusterId, SubClusterInfo> activeSubclusters =
        getActiveSubclusters();

    FederationPolicyUtils.validateSubClusterAvailability(
        new ArrayList<SubClusterId>(activeSubclusters.keySet()), blacklist);

    // This finds the sub-cluster with the highest weight among the
    // currently active ones.
    Map<SubClusterIdInfo, Float> weights =
        getPolicyInfo().getRouterPolicyWeights();
    SubClusterId chosen = null;
    Float currentBest = Float.MIN_VALUE;
    for (SubClusterId id : activeSubclusters.keySet()) {
      SubClusterIdInfo idInfo = new SubClusterIdInfo(id);
      if (blacklist != null && blacklist.contains(id)) {
        continue;
      }
      if (weights.containsKey(idInfo) && weights.get(idInfo) > currentBest) {
        currentBest = weights.get(idInfo);
        chosen = id;
      }
    }

    return chosen;
  }

}