private void populateComponentHostsMap(ObjectNode root, Map<String, Set<String>> componentHostsMap) {
    ArrayNode services = (ArrayNode) root.get(SERVICES_PROPERTY);
    Iterator<JsonNode> servicesIter = services.elements();

    while (servicesIter.hasNext()) {
      JsonNode service = servicesIter.next();
      ArrayNode components = (ArrayNode) service.get(SERVICES_COMPONENTS_PROPERTY);
      Iterator<JsonNode> componentsIter = components.elements();

      while (componentsIter.hasNext()) {
        JsonNode component = componentsIter.next();
        ObjectNode componentInfo = (ObjectNode) component.get(COMPONENT_INFO_PROPERTY);
        String componentName = componentInfo.get(COMPONENT_NAME_PROPERTY).asText();

        Set<String> componentHosts = componentHostsMap.get(componentName);
        ArrayNode hostnames = componentInfo.putArray(COMPONENT_HOSTNAMES_PROPERTY);
        if (null != componentHosts) {
          for (String hostName : componentHosts) {
            hostnames.add(hostName);
          }
        }
      }
    }
  }
Retrieves the Ambari configuration if exists and adds it to services.json

@param root The JSON document that will become service.json when passed to the stack advisor engine
ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java