private boolean addGroupingServices(List<OrderService> servicesToAdd, String after) {
    if (after == null) {
      services.addAll(servicesToAdd);
      return true;
    }
    else {
      // Check the current services, if the "after" service is there then add these
      for (int index = services.size() - 1; index >= 0; index--) {
        OrderService service = services.get(index);
        if (service.serviceName.equals(after)) {
          services.addAll(index + 1, servicesToAdd);
          return true;
        }
      }
    }
    return false;
  }
Merge the services to add after a particular service name
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/Grouping.java