private Map<String, Map<String, String>> addConfigurationsForPreProcessedServices(Map<String, Map<String, String>> configurations,
                                                                                    Cluster cluster,
                                                                                    @Nullable KerberosDescriptor kerberosDescriptor,
                                                                                    boolean calculateClusterHostInfo)
    throws AmbariException {

    Map<String, KerberosServiceDescriptor> serviceDescriptorMap = kerberosDescriptor.getServices();

    if (serviceDescriptorMap != null) {
      Map<String, Service> existingServices = cluster.getServices();
      Set<String> allServices = new HashSet<>(existingServices.keySet());
      Set<String> componentFilter = new HashSet<>();
      StackId stackVersion = cluster.getCurrentStackVersion();

      for (KerberosServiceDescriptor serviceDescriptor : serviceDescriptorMap.values()) {
        String serviceName = serviceDescriptor.getName();
        boolean shouldPreconfigure = serviceDescriptor.shouldPreconfigure();

        if (shouldPreconfigure && !existingServices.containsKey(serviceName)) {
          if (ambariMetaInfo.isValidService(stackVersion.getStackName(), stackVersion.getStackVersion(), serviceName)) {
            ServiceInfo serviceInfo = ambariMetaInfo.getService(stackVersion.getStackName(), stackVersion.getStackVersion(), serviceName);

            Collection<PropertyInfo> servicePropertiesInfos = serviceInfo.getProperties();
            if (servicePropertiesInfos != null) {
              Map<String, Map<String, String>> propertiesToAdd = new HashMap<>();

              for (PropertyInfo propertyInfo : servicePropertiesInfos) {
                String type = ConfigHelper.fileNameToConfigType(propertyInfo.getFilename());

                Map<String, String> map = propertiesToAdd.get(type);
                if (map == null) {
                  map = new HashMap<>();
                  propertiesToAdd.put(type, map);
                }
                map.put(propertyInfo.getName(), propertyInfo.getValue());
              }

              for (Map.Entry<String, Map<String, String>> entry : propertiesToAdd.entrySet()) {
                if (!configurations.containsKey(entry.getKey())) {
                  configurations.put(entry.getKey(), entry.getValue());
                }
              }
            }

            // This is only needed if the Stack Advisor is being called to get recommended host
            // for components
            if (calculateClusterHostInfo) {
              // Add the service to preconfigure to the all services set for use later
              allServices.add(serviceName);

              // Add the components for the service to preconfigure to the component filter
              List<ComponentInfo> componentInfos = serviceInfo.getComponents();
              if (componentInfos != null) {
                for (ComponentInfo componentInfo : componentInfos) {
                  componentFilter.add(componentInfo.getName());
                }
              }
            }
          }
        }
      }

      if (calculateClusterHostInfo && (allServices.size() > existingServices.size())) {
        applyStackAdvisorHostRecommendations(cluster, allServices, componentFilter, configurations);
      }
    }

    return configurations;
  }
Gathers the Kerberos-related configurations for services not yet installed, but flagged to be
preconfigured.
<p>
Only existing configuration types will be updated, new types will not be added since they are
expected only when the relevant service has been installed. This is to help reduce the number
of service restarts when new services are added to clusters where Kerberos has been enabled.
<p>
If desired, the Stack Advisor will be invoked to request recommended hosts for the component.
This is needed to fill out the clusterHostInfo structure in the configuration map. For example,
<code>clusterHostInfo/knox_gateway_hosts</code>

@param configurations           the existing configurations (updated in-place)
@param cluster                  the cluster
@param kerberosDescriptor       the kerberos descriptor
@param calculateClusterHostInfo true, to query the Stack Advisor for recommended hosts for the
                                preconfigured services and components; false, otherwise
@return the updated configuration map
@throws AmbariException if an error occurs
ambari-server/src/main/java/org/apache/ambari/server/controller/KerberosHelperImpl.java