@Override
  public void merge(Iterator<Grouping> iterator) throws AmbariException {
    List<String> priorities = new ArrayList<>();
    priorities.addAll(getPriorities());
    Map<String, Set<String>> skippedPriorities = new HashMap<>();
    while (iterator.hasNext()) {
      Grouping next = iterator.next();
      if (!(next instanceof ServiceCheckGrouping)) {
        throw new AmbariException("Invalid group type " + next.getClass().getSimpleName() + " expected service check group");
      }
      ServiceCheckGrouping checkGroup = (ServiceCheckGrouping) next;
      getExcluded().addAll(checkGroup.getExcluded());

      boolean added = addPriorities(priorities, checkGroup.getPriorities(), checkGroup.addAfterGroupEntry);
      if (added) {
        addSkippedPriorities(priorities, skippedPriorities, checkGroup.getPriorities());
      }
      else {
        // store these services until later
        if (skippedPriorities.containsKey(checkGroup.addAfterGroupEntry)) {
          Set<String> tmp = skippedPriorities.get(checkGroup.addAfterGroupEntry);
          tmp.addAll(checkGroup.getPriorities());
        }
        else {
          skippedPriorities.put(checkGroup.addAfterGroupEntry, checkGroup.getPriorities());
        }
      }
    }
    getPriorities().clear();
    getPriorities().addAll(priorities);
  }
Attempts to merge all the service check groupings.  This merges the excluded list and
the priorities.  The priorities are merged in an order specific manner.
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/ServiceCheckGrouping.java