@Override
  public CommandReport execute(ConcurrentMap<String, Object> requestSharedDataContext) throws
      AmbariException, InterruptedException {

    Cluster cluster = getCluster();

    if (cluster == null) {
      throw new AmbariException("Missing cluster object");
    }

    KerberosHelper kerberosHelper = getKerberosHelper();

    KerberosDescriptor kerberosDescriptor = getKerberosDescriptor(cluster, false);
    Map<String, String> commandParameters = getCommandParameters();
    OperationType operationType = getOperationType(getCommandParameters());

    Map<String, ? extends Collection<String>> serviceComponentFilter = getServiceComponentFilter();
    Collection<String> hostFilter = getHostFilter();
    Collection<String> identityFilter = getIdentityFilter();
    // If the operationType is default, use the getServiceComponentHostsToProcess method to determine
    // which ServiceComponentHosts to process based on the filters.  However if we are regenerating
    // keytabs for a specific set of components, build the identity filter below so we can
    // customized what needs to be done.
    List<ServiceComponentHost> schToProcess = kerberosHelper.getServiceComponentHostsToProcess(cluster, kerberosDescriptor,
        (operationType == OperationType.DEFAULT) ? serviceComponentFilter : null, hostFilter);

    String dataDirectory = getCommandParameterValue(commandParameters, DATA_DIRECTORY);
    Map<String, Map<String, String>> kerberosConfigurations = new HashMap<>();

    int schCount = schToProcess.size();
    if (schCount == 0) {
      actionLog.writeStdOut("There are no components to process");
    } else if (schCount == 1) {
      actionLog.writeStdOut(String.format("Processing %d component", schCount));
    } else {
      actionLog.writeStdOut(String.format("Processing %d components", schCount));
    }

    Set<String> services = cluster.getServices().keySet();
    Map<String, Set<String>> propertiesToRemove = new HashMap<>();
    Map<String, Set<String>> propertiesToIgnore = new HashMap<>();
    boolean includeAmbariIdentity = "true".equalsIgnoreCase(getCommandParameterValue(commandParameters, KerberosServerAction.INCLUDE_AMBARI_IDENTITY));

    // If we are including the Ambari identity; then ensure that if a host filter is set, do not the Ambari service identity.
    includeAmbariIdentity &= (hostFilter == null);

    if (serviceComponentFilter != null) {
      // If we are including the Ambari identity; then ensure that if a service/component filter is set,
      // it contains the AMBARI/AMBARI_SERVER component; else do not include the Ambari service identity.
      includeAmbariIdentity &= (serviceComponentFilter.get(RootService.AMBARI.name()) != null)
          && serviceComponentFilter.get(RootService.AMBARI.name()).contains(RootComponent.AMBARI_SERVER.name());

      if ((operationType != OperationType.DEFAULT)) {
        // Update the identity filter, if necessary
        identityFilter = updateIdentityFilter(kerberosDescriptor, identityFilter, serviceComponentFilter);
      }
    }

    // Calculate the current host-specific configurations. These will be used to replace
    // variables within the Kerberos descriptor data
    Map<String, Map<String, String>> configurations = kerberosHelper.calculateConfigurations(cluster, null, kerberosDescriptor, false, false, null);

    processServiceComponentHosts(cluster, kerberosDescriptor, schToProcess, identityFilter, dataDirectory,
        configurations, kerberosConfigurations, includeAmbariIdentity, propertiesToIgnore);

    UpdateConfigurationPolicy updateConfigurationPolicy = getUpdateConfigurationPolicy(commandParameters);

    if (updateConfigurationPolicy != UpdateConfigurationPolicy.NONE) {
      if (updateConfigurationPolicy.invokeStackAdvisor()) {
        kerberosHelper.applyStackAdvisorUpdates(cluster, services, configurations, kerberosConfigurations,
            propertiesToIgnore, propertiesToRemove, true);
      }

      // TODO: Determine if we need to do this again since it is done a few lines above.
      Map<String, Map<String, String>> calculatedConfigurations = kerberosHelper.calculateConfigurations(cluster, null, kerberosDescriptor, false, false, null);

      if (updateConfigurationPolicy.applyIdentityChanges()) {
        processAuthToLocalRules(cluster, calculatedConfigurations, kerberosDescriptor, schToProcess, kerberosConfigurations, getDefaultRealm(commandParameters), false);
      }

      processConfigurationChanges(dataDirectory, kerberosConfigurations, propertiesToRemove, kerberosDescriptor, updateConfigurationPolicy);
    }

    return createCommandReport(0, HostRoleStatus.COMPLETED, "{}", actionLog.getStdOut(), actionLog.getStdErr());
  }
Called to execute this action.  Upon invocation, calls
{@link KerberosServerAction#processIdentities(Map)}
to iterate through the Kerberos identity metadata and call
{@link PrepareKerberosIdentitiesServerAction#processIdentities(Map)}
for each identity to process.

@param requestSharedDataContext a Map to be used a shared data among all ServerActions related
                                to a given request
@return a CommandReport indicating the result of this action
@throws AmbariException
@throws InterruptedException
ambari-server/src/main/java/org/apache/ambari/server/serveraction/kerberos/PrepareKerberosIdentitiesServerAction.java