private List<List<TaskWrapper>> organizeTaskWrappersBySyncRules(List<TaskWrapper> tasks) {
      List<List<TaskWrapper>> groupedTasks = new ArrayList<>();

      List<TaskWrapper> subTasks = new ArrayList<>();
      for (TaskWrapper tw : tasks) {
        // If an of this TaskWrapper's tasks must be on its own stage, write out the previous subtasks if possible into one complete stage.
        if (tw.isAnyTaskSequential()) {
          if (!subTasks.isEmpty()) {
            groupedTasks.add(subTasks);
            subTasks = new ArrayList<>();
          }
          groupedTasks.add(Collections.singletonList(tw));
        } else {
          subTasks.add(tw);
        }
      }

      if (!subTasks.isEmpty()) {
        groupedTasks.add(subTasks);
      }

      return groupedTasks;
    }
Split a list of TaskWrappers into a list of lists where a TaskWrapper that has any task with isSequential == true
must be a singleton in its own list.
@param tasks List of TaskWrappers to analyze
@return List of list of TaskWrappers, where each outer list is a separate stage.
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/Grouping.java