private List<ServiceComponentHost> getServiceComponentHosts(Cluster cluster,
                                                              Command<Boolean, ServiceComponentHost> shouldIncludeCommand)
    throws AmbariException {
    List<ServiceComponentHost> serviceComponentHostsToProcess = new ArrayList<>();
    // Get the hosts in the cluster
    Collection<Host> hosts = cluster.getHosts();

    if ((hosts != null) && !hosts.isEmpty()) {
      // Iterate over the hosts in the cluster to find the components installed in each.
      for (Host host : hosts) {
        String hostname = host.getHostName();

        // Get a list of components on the current host
        List<ServiceComponentHost> serviceComponentHosts = cluster.getServiceComponentHosts(hostname);

        if ((serviceComponentHosts != null) && !serviceComponentHosts.isEmpty()) {
          // Iterate over the components installed on the current host and execute the shouldIncludeCommand
          // Command (if supplied) to get the desired ServiceComponentHost instances.
          for (ServiceComponentHost sch : serviceComponentHosts) {
            if ((shouldIncludeCommand == null) || shouldIncludeCommand.invoke(sch)) {
              serviceComponentHostsToProcess.add(sch);
            }
          }
        }
      }
    }

    return serviceComponentHostsToProcess;
  }
Find the {@link ServiceComponentHost}s for the cluster, filtering using the
supplied "should include" command (<code>shouldIncludeCommand</code>).
<p>
If <code>shouldIncludeCommand</code> is <code>null/code>, no filtering will be performed causing
all found {@link ServiceComponentHost}s to be returned.

@param cluster              the cluster
@param shouldIncludeCommand the filtering logic
@return a list of (filtered) {@link ServiceComponentHost}s
@throws AmbariException if an error occurs
ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java