AddServiceInfo recommendConfigurations(AddServiceInfo info) {
    Configuration config = info.getConfig();
    if (info.getRequest().getRecommendationStrategy().shouldUseStackAdvisor()) {
      LayoutRecommendationInfo layoutInfo = getLayoutRecommendationInfo(info);

      Map<String, Set<String>> componentHostMap = getComponentHostMap(layoutInfo.getAllServiceLayouts());
      Map<String, Set<String>> hostComponentMap = getHostComponentMap(componentHostMap);
      StackAdvisorRequest request = StackAdvisorRequest.StackAdvisorRequestBuilder
        .forStack(info.getStack().getStackId())
        .ofType(StackAdvisorRequest.StackAdvisorRequestType.CONFIGURATIONS)
        .forHosts(layoutInfo.getHosts())
        .forServices(layoutInfo.getAllServiceLayouts().keySet())
        .forHostComponents(hostComponentMap)
        .forHostsGroupBindings(layoutInfo.getHostGroups())
        .withComponentHostsMap(componentHostMap)
        .withConfigurations(config)
        .withGPLLicenseAccepted(serverConfig.getGplLicenseAccepted())
        .build();
      RecommendationResponse response;
      try {
        response = stackAdvisorHelper.recommend(request);
      }
      catch (StackAdvisorException|AmbariException ex) {
        throw new IllegalArgumentException("Configuration recommendation failed.", ex);
      }
      Map<String, RecommendationResponse.BlueprintConfigurations> configRecommendations = response.getRecommendations().getBlueprint().getConfigurations();

      // remove recommendations for existing services
      configRecommendations.keySet().removeIf(configType -> !info.newServices().containsKey(info.getStack().getServiceForConfigType(configType)));

      if (info.getRequest().getRecommendationStrategy() == ConfigRecommendationStrategy.ONLY_STACK_DEFAULTS_APPLY) {
        removeNonStackConfigRecommendations(info.getConfig().getParentConfiguration().getParentConfiguration(), configRecommendations);
      }

      Configuration recommendedConfig = toConfiguration(configRecommendations);

      Configuration userConfig = config;
      Configuration clusterAndStackConfig = userConfig.getParentConfiguration();

      if (info.getRequest().getRecommendationStrategy().shouldOverrideCustomValues()) {
        config = recommendedConfig;
        config.setParentConfiguration(userConfig);
      } else {
        config.setParentConfiguration(recommendedConfig);
        recommendedConfig.setParentConfiguration(clusterAndStackConfig);
      }

      StackAdvisorRequest validationRequest = request.builder().withConfigurations(config).build();
      validate(validationRequest);
    }

    UnitUpdater.updateUnits(config, info.getStack());
    return info.withConfig(config);
  }
Gets all services from the cluster together together with services from AddServiceInfo.
@param info
@return A map of <i>service name -> component name -> hosts</i> for all services in the cluster and the input
 AddServiceInfo combined.
ambari-server/src/main/java/org/apache/ambari/server/topology/addservice/StackAdvisorAdapter.java