String getHostsInformation(StackAdvisorRequest request) throws StackAdvisorException {
    List<String> hostNames = new ArrayList<>(request.getHosts());

    // retrieve cached info
    List<JsonNode> resultInfos = new ArrayList<>();
    if (hostInfoCache != null && !hostInfoCache.isEmpty()) {
      Iterator<String> hostNamesIterator = hostNames.iterator();
      while(hostNamesIterator.hasNext()) {
        String hostName = hostNamesIterator.next();
        JsonNode node = hostInfoCache.get(hostName);
        if (node != null) {
          resultInfos.add(node);
          hostNamesIterator.remove();
        }
      }
    }
    String hostsJSON = null;

    // get hosts info for not cached hosts only
    if (!hostNames.isEmpty()) {
      LOG.info(String.format("Fire host info request for hosts: " + hostNames.toString()));
      String hostsURI = String.format(GET_HOSTS_INFO_URI, String.join(",", hostNames));

      Response response = handleRequest(null, null, new LocalUriInfo(hostsURI), Request.Type.GET,
          createHostResource());

      if (response.getStatus() != Status.OK.getStatusCode()) {
        String message = String.format(
            "Error occured during hosts information retrieving, status=%s, response=%s",
            response.getStatus(), (String) response.getEntity());
        LOG.warn(message);
        throw new StackAdvisorException(message);
      }

      hostsJSON = (String) response.getEntity();
      if (LOG.isDebugEnabled()) {
        LOG.debug("Hosts information: {}", hostsJSON);
      }
    }

    // when cache is used we should merge cached info with just got
    if (hostInfoCache != null) {
      if (hostsJSON != null && !hostsJSON.isEmpty()) {
        try {
          JsonNode root = mapper.readTree(hostsJSON);
          Iterator<JsonNode> iterator = root.get("items").elements();
          while (iterator.hasNext()) {
            JsonNode next = iterator.next();
            String hostName = next.get("Hosts").get("host_name").asText();
            hostInfoCache.put(hostName, next);
            resultInfos.add(next);
          }
        } catch (IOException e) {
          throw new StackAdvisorException("Error occured during parsing result host infos", e);
        }
      }

      String fullHostsURI = String.format(GET_HOSTS_INFO_URI, request.getHostsCommaSeparated());
      JsonNodeFactory f = JsonNodeFactory.instance;
      ObjectNode resultRoot = f.objectNode();
      resultRoot.put("href", fullHostsURI);
      ArrayNode resultArray = resultRoot.putArray("items");
      resultArray.addAll(resultInfos);

      hostsJSON = resultRoot.toString();

    }

    Collection<String> unregistered = getUnregisteredHosts(hostsJSON, request.getHosts());
    if (unregistered.size() > 0) {
      String message = String.format("There are unregistered hosts in the request, %s",
          Arrays.toString(unregistered.toArray()));
      LOG.warn(message);
      throw new StackAdvisorException(message);
    }

    return hostsJSON;
  }
Deletes folders older than (now - recommendationsArtifactsLifetime)
ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java