private List<StageWrapper> buildStageWrappers(UpgradeContext upgradeContext, String service,
      HostHolder holder, List<Task> tasks, boolean firstHost, String prefix) {

    if (CollectionUtils.isEmpty(tasks)) {
      return Collections.emptyList();
    }

    Set<String> hosts = firstHost ? Collections.singleton(holder.m_firstHost) :
      holder.m_remainingHosts;

    String component = holder.m_component;
    String componentDisplay = upgradeContext.getComponentDisplay(service, component);
    String text = getStageText(prefix, componentDisplay, hosts);

    List<TaskWrapper> wrappers = buildTaskWrappers(service, component, tasks, hosts, firstHost);

    List<StageWrapper> results = new ArrayList<>();

    wrappers.forEach(task -> {
      // !!! there should only be one task per wrapper, so this assumption is ok for now
      StageWrapper.Type type = task.getTasks().get(0).getStageWrapperType();

      StageWrapper stage = new StageWrapper(type, text, new HashMap<>(),
          Collections.singletonList(task));
      results.add(stage);
    });

    return results;
  }
Builds the stages for the components
@param upgradeContext
         the upgrade context
@param service
         the service name
@param holder
         the holder of component and hosts
@param tasks
         the tasks to wrap
@param firstHost
         {@code true} if wrapping for the first host
@param prefix
         the text prefix for the stage
@return
         the list of stage wrappers
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/orchestrate/ParallelClientGroupingBuilder.java