public void merge(Iterator<Grouping> iterator) throws AmbariException {
    Map<String, List<OrderService>> skippedServices = new HashMap<>();
    while (iterator.hasNext()) {
      Grouping group = iterator.next();

      boolean added = addGroupingServices(group.services, group.addAfterGroupEntry);
      if (added) {
        addSkippedServices(skippedServices, group.services);
      } else {
        // store these services until later
        if (skippedServices.containsKey(group.addAfterGroupEntry)) {
          List<OrderService> tmp = skippedServices.get(group.addAfterGroupEntry);
          tmp.addAll(group.services);
        } else {
          skippedServices.put(group.addAfterGroupEntry, group.services);
        }
      }
    }
  }
Merge the services of all the child groups, with the current services.
Keeping the order specified by the group.
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/Grouping.java