public Collection<KerberosIdentityDescriptor> getServiceIdentities(String clusterName, Collection<String> services,
                                                                     @Nullable Map<String, DesiredConfig> desiredConfigs)
    throws AmbariException {

    final Collection<KerberosIdentityDescriptor> serviceIdentities = new ArrayList<>();
    Cluster cluster = clusters.getCluster(clusterName);

    if (desiredConfigs == null) {
      desiredConfigs = cluster.getDesiredConfigs();
    }

    KerberosDescriptor kerberosDescriptor = kerberosHelper.getKerberosDescriptor(cluster, false);
    KerberosDescriptor userDescriptor = kerberosHelper.getKerberosDescriptorUpdates(cluster);
    Map<String, Map<String, Map<String, String>>> hostConfigurations = new HashMap<>();
    Map<String, Host> hostMap = clusters.getHostsForCluster(clusterName);
    Set<String> hosts = new HashSet<>(hostMap.keySet());
    Map<String, String> componentHosts = new HashMap<>();

    for (String hostName: hosts) {
      hostConfigurations.put(
        hostName,
        kerberosHelper.calculateConfigurations(cluster, hostName, kerberosDescriptor, userDescriptor,
          false,false, componentHosts, desiredConfigs)
      );
    }

    // ambari-agent may not be installed on ambari-server. Add ambari-server after calculating configurations.
    // If not, HostNotFoundException will raise
    String ambariServerHostname = StageUtils.getHostName();
    hosts.add(ambariServerHostname);

    for (String service: services) {
      kerberosHelper.getActiveIdentities(clusterName,null, service, null,true,
        hostConfigurations,kerberosDescriptor, desiredConfigs).values().forEach(serviceIdentities::addAll);
    }
    return serviceIdentities;
  }
Adjust service component filter according to installed services

@param cluster                cluster
@param includeAmbariAsService
@param serviceComponentFilter
@return
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/stageutils/KerberosKeytabController.java