public synchronized T invoke(StackAdvisorRequest request, ServiceInfo.ServiceAdvisorType serviceAdvisorType) throws StackAdvisorException {
    validate(request);
    String hostsJSON = getHostsInformation(request);
    String servicesJSON = getServicesInformation(request);

    StackAdvisorData adjusted = adjust(new StackAdvisorData(hostsJSON, servicesJSON), request);

    try {
      createRequestDirectory();

      FileUtils.writeStringToFile(new File(requestDirectory, "hosts.json"), adjusted.hostsJSON,
              Charset.defaultCharset());
      FileUtils
              .writeStringToFile(new File(requestDirectory, "services.json"), adjusted.servicesJSON,
                      Charset.defaultCharset());

      saRunner.runScript(serviceAdvisorType, getCommandType(), requestDirectory);
      String result = FileUtils.readFileToString(new File(requestDirectory, getResultFileName()),
              Charset.defaultCharset());

      T response = this.mapper.readValue(result, this.type);
      return updateResponse(request, setRequestId(response));
    } catch (StackAdvisorException ex) {
      throw ex;
    } catch (Exception e) {
      String message = "Error occured during stack advisor command invocation: ";
      LOG.warn(message, e);
      throw new StackAdvisorException(message + e.getMessage());
    }
  }
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