private void bootstrapStackTools(StackId stackId, Cluster cluster) throws AmbariException {
    // if the stack name is the same as the cluster's current stack name, then
    // there's no work to do
    if (StringUtils.equals(stackId.getStackName(),
        cluster.getCurrentStackVersion().getStackName())) {
      return;
    }

    ConfigHelper configHelper = configHelperProvider.get();

    // get the stack tools/features for the stack being distributed
    Map<String, Map<String, String>> defaultStackConfigurationsByType = configHelper.getDefaultStackProperties(stackId);

    Map<String, String> clusterEnvDefaults = defaultStackConfigurationsByType.get(
        ConfigHelper.CLUSTER_ENV);

    Config clusterEnv = cluster.getDesiredConfigByType(ConfigHelper.CLUSTER_ENV);
    Map<String, String> clusterEnvProperties = clusterEnv.getProperties();

    // the 4 properties we need to check and update
    Set<String> properties = Sets.newHashSet(ConfigHelper.CLUSTER_ENV_STACK_ROOT_PROPERTY,
        ConfigHelper.CLUSTER_ENV_STACK_TOOLS_PROPERTY,
        ConfigHelper.CLUSTER_ENV_STACK_FEATURES_PROPERTY,
        ConfigHelper.CLUSTER_ENV_STACK_PACKAGES_PROPERTY);

    // any updates are stored here and merged into the existing config type
    Map<String, String> updatedProperties = new HashMap<>();

    for (String property : properties) {
      // determine if the property exists in the stack being distributed (it
      // kind of has to, but we'll be safe if it's not found)
      String newStackDefaultJson = clusterEnvDefaults.get(property);
      if (StringUtils.isBlank(newStackDefaultJson)) {
        continue;
      }

      String existingPropertyJson = clusterEnvProperties.get(property);

      // if the stack tools/features property doesn't exist, then just set the
      // one from the new stack
      if (StringUtils.isBlank(existingPropertyJson)) {
        updatedProperties.put(property, newStackDefaultJson);
        continue;
      }

      // now is the hard part - we need to check to see if the new stack tools
      // exists alongside the current tools and if it doesn't, then add the new
      // tools in
      final Map<String, Object> existingJson;
      final Map<String, ?> newStackJsonAsObject;
      if (StringUtils.equals(property, ConfigHelper.CLUSTER_ENV_STACK_ROOT_PROPERTY)) {
        existingJson = gson.<Map<String, Object>> fromJson(existingPropertyJson, Map.class);
        newStackJsonAsObject = gson.<Map<String, String>> fromJson(newStackDefaultJson, Map.class);
      } else {
        existingJson = gson.<Map<String, Object>> fromJson(existingPropertyJson,
            Map.class);

        newStackJsonAsObject = gson.<Map<String, Map<Object, Object>>> fromJson(newStackDefaultJson,
            Map.class);
      }

      if (existingJson.keySet().contains(stackId.getStackName())) {
        continue;
      }

      existingJson.put(stackId.getStackName(), newStackJsonAsObject.get(stackId.getStackName()));

      String newJson = gson.toJson(existingJson);
      updatedProperties.put(property, newJson);
    }

    if (!updatedProperties.isEmpty()) {
      AmbariManagementController amc = getManagementController();
      String serviceNote = String.format(
          "Adding stack tools for %s while distributing a new repository", stackId.toString());

      configHelper.updateConfigType(cluster, stackId, amc, clusterEnv.getType(), updatedProperties,
          null, amc.getAuthName(), serviceNote);
    }
  }
Ensures that the stack tools and stack features are set on
{@link ConfigHelper#CLUSTER_ENV} for the stack of the repository being
distributed. This step ensures that the new repository can be distributed
with the correct tools.
<p/>
If the cluster's current stack name matches that of the new stack or the
new stack's tools are already added in the configuration, then this method
will not change anything.

@param stackId
         the stack of the repository being distributed (not {@code null}).
@param cluster
         the cluster the new stack/repo is being distributed for (not
         {@code null}).
@throws AmbariException
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterStackVersionResourceProvider.java