private static KerberosServiceDescriptor processService(KerberosServiceDescriptor previousStackService,
                                                          KerberosServiceDescriptor newStackService,
                                                          KerberosServiceDescriptor userService) {

    KerberosServiceDescriptor updatedService = new KerberosServiceDescriptor(userService.toMap());

    updatedService.setAuthToLocalProperties(processAuthToLocalProperties(
        (previousStackService == null) ? null : previousStackService.getAuthToLocalProperties(),
        (newStackService == null) ? null : newStackService.getAuthToLocalProperties(),
        updatedService.getAuthToLocalProperties()));

    updatedService.setConfigurations(processConfigurations(
        (previousStackService == null) ? null : previousStackService.getConfigurations(),
        (newStackService == null) ? null : newStackService.getConfigurations(),
        updatedService.getConfigurations()));

    updatedService.setIdentities(processIdentities(
        (previousStackService == null) ? null : previousStackService.getIdentities(),
        (newStackService == null) ? null : newStackService.getIdentities(),
        updatedService.getIdentities()));

    Map<String, KerberosComponentDescriptor> userServiceComponents = updatedService.getComponents();
    Map<String, KerberosComponentDescriptor> newServiceComponents = (newStackService == null) ? null : newStackService.getComponents();
    Map<String, KerberosComponentDescriptor> oldServiceComponents = (previousStackService == null) ? null : previousStackService.getComponents();

    if (newServiceComponents == null) {
      newServiceComponents = Collections.emptyMap();
    }

    if (oldServiceComponents == null) {
      oldServiceComponents = Collections.emptyMap();
    }

    if (userServiceComponents != null) {
      Iterator<Map.Entry<String, KerberosComponentDescriptor>> iterator = userServiceComponents.entrySet().iterator();
      while (iterator.hasNext()) {
        Map.Entry<String, KerberosComponentDescriptor> entry = iterator.next();
        String name = entry.getKey();
        KerberosComponentDescriptor userValue = entry.getValue();

        if (userValue == null) {
          iterator.remove();  // This is a bad entry... remove it.
        } else if (newServiceComponents.containsKey(name)) {
          KerberosComponentDescriptor oldValue = oldServiceComponents.get(name);
          KerberosComponentDescriptor newValue = newServiceComponents.get(name);

          LOG.debug("Processing component {}/{} for modifications", updatedService.getName(), name);
          processComponent(oldValue, newValue, userValue);
        } else {
          LOG.debug("Removing component {}/{} from user-specified Kerberos Descriptor", updatedService.getName(), name);
          iterator.remove();
        }
      }
    }

    return updatedService;
  }
Processes a {@link KerberosServiceDescriptor} to change the user-supplied data based on the changes
observed between the previous stack version's data and the new stack version's data.

@param previousStackService a {@link KerberosServiceDescriptor} from the previous stack version's Kerberos descriptor
@param newStackService      a {@link KerberosServiceDescriptor} from the new stack version's Kerberos descriptor
@param userService          a {@link KerberosServiceDescriptor} from the user-specified Kerberos descriptor
@return the updated {@link KerberosServiceDescriptor}
ambari-server/src/main/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorUpdateHelper.java