protected <T extends StackDefinitionModule<T, ?>> Collection<T> mergeChildModules(
      Map<String, StackModule> allStacks, Map<String, ServiceModule> commonServices, Map<String, ExtensionModule> extensions, Map<String, T> modules, Map<String, T> parentModules)
        throws AmbariException {
    Set<String> addedModules = new HashSet<>();
    Collection<T> mergedModules = new HashSet<>();

    for (T module : modules.values()) {
      String id = module.getId();
      addedModules.add(id);
      if (!module.isDeleted()) {
        if (parentModules.containsKey(id)) {
          module.resolve(parentModules.get(id), allStacks, commonServices, extensions);
        }
      }
      mergedModules.add(module);
    }

    // add non-overlapping parent modules
    for (T parentModule : parentModules.values()) {
      String id = parentModule.getId();
      if (!addedModules.contains(id)) {
        mergedModules.add(parentModule);
      }
    }
    return mergedModules;
  }
Merges child modules with the corresponding parent modules.

@param allStacks      collection of all stack module in stack definition
@param commonServices collection of all common service module in stack definition
@param modules        child modules of this module that are to be merged
@param parentModules  parent modules which the modules are to be merged with

@return collection of the merged modules
ambari-server/src/main/java/org/apache/ambari/server/stack/BaseModule.java