@Override
    public void add(UpgradeContext context, HostsType hostsType, String service,
       boolean clientOnly, ProcessingComponent pc, Map<String, String> params) {

      // Construct the pre tasks during Upgrade/Downgrade direction.
      // Buckets are grouped by the type, e.g., bucket of all Execute tasks, or all Configure tasks.
      List<TaskBucket> buckets = buckets(resolveTasks(context, true, pc));
      for (TaskBucket bucket : buckets) {
        // The TaskWrappers take into account if a task is meant to run on all, any, or master.
        // A TaskWrapper may contain multiple tasks, but typically only one, and they all run on the same set of hosts.
        // Generate a task wrapper for every task in the bucket
        List<TaskWrapper> preTasks = TaskWrapperBuilder.getTaskList(service, pc.name, hostsType, bucket.tasks, params);
        List<List<TaskWrapper>> organizedTasks = organizeTaskWrappersBySyncRules(preTasks);
        for (List<TaskWrapper> tasks : organizedTasks) {
          addTasksToStageInBatches(tasks, "Preparing", context, service, pc, params);
        }
      }

      // Add the processing component
      Task t = resolveTask(context, pc);
      if (null != t) {
        TaskWrapper tw = new TaskWrapper(service, pc.name, hostsType.getHosts(), params, Collections.singletonList(t));
        addTasksToStageInBatches(Collections.singletonList(tw), t.getActionVerb(), context, service, pc, params);
      }

      // Construct the post tasks during Upgrade/Downgrade direction.
      buckets = buckets(resolveTasks(context, false, pc));
      for (TaskBucket bucket : buckets) {
        List<TaskWrapper> postTasks = TaskWrapperBuilder.getTaskList(service, pc.name, hostsType, bucket.tasks, params);
        List<List<TaskWrapper>> organizedTasks = organizeTaskWrappersBySyncRules(postTasks);
        for (List<TaskWrapper> tasks : organizedTasks) {
          addTasksToStageInBatches(tasks, "Completing", context, service, pc, params);
        }
      }

      // Potentially add a service check
      if (m_serviceCheck && !clientOnly) {
        m_servicesToCheck.add(service);
      }
    }
Add stages where the restart stages are ordered
E.g., preupgrade, restart hosts(0), ..., restart hosts(n-1), postupgrade
@param context the context
@param hostsType the order collection of hosts, which may have a master and secondary
@param service the service name
@param pc the ProcessingComponent derived from the upgrade pack.
@param params additional parameters
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/Grouping.java