private List<TaskWrapper> buildTaskWrappers(String service, String component,
      List<Task> tasks, Set<String> hosts, boolean firstHost) {

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

    tasks.forEach(task -> {
      // server side actions should run only run once (the first host)
      if (task.getType().isServerAction()) {
        if (firstHost) {
          String ambariServerHostname = StageUtils.getHostName();
          results.add(new TaskWrapper(service, component, Collections.singleton(ambariServerHostname), task));
        }
        return;
      }

      // FIXME how to handle master-only types

      // !!! the first host has already run tasks that are singular
      if (!firstHost && task.getType() == Type.EXECUTE) {
        ExecuteTask et = (ExecuteTask) task;

        // !!! singular types have already run when firstHost is true
        if (et.hosts != ExecuteHostType.ALL) {
          return;
        }
      }

      results.add(new TaskWrapper(service, component, hosts, task));
    });

    return results;
  }
Build the wrappers for the tasks.

@param service
         the service name
@param component
         the component name
@param tasks
         the tasks to wrap
@param hosts
         the hosts where the tasks should run
@param firstHost
         {@code true} if these wrappers are for the first host
@return
       the list if task wrappers
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/orchestrate/ParallelClientGroupingBuilder.java