private Map<String, Map<TemporalInfo, MetricsRequest>> getMetricsRequests(
              Set<Resource> resources, Request request, Set<String> ids) throws SystemException {

    Map<String, Map<TemporalInfo, MetricsRequest>> requestMap =
      new HashMap<>();

    String collectorPort = null;
    Map<String, Boolean> clusterCollectorComponentLiveMap = new HashMap<>();
    Map<String, Boolean> clusterCollectorHostLiveMap = new HashMap<>();

    for (Resource resource : resources) {
      String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
      // If a resource is not part of a cluster, do not return metrics since
      // we cannot decide which collector to reach
      if (StringUtils.isEmpty(clusterName)) {
        continue;
      }

      // Check liveliness of host
      boolean clusterCollectorHostLive;
      if (clusterCollectorHostLiveMap.containsKey(clusterName)) {
        clusterCollectorHostLive = clusterCollectorHostLiveMap.get(clusterName);
      } else {
        clusterCollectorHostLive = hostProvider.isCollectorComponentLive(clusterName, TIMELINE_METRICS);
        clusterCollectorHostLiveMap.put(clusterName, clusterCollectorHostLive);
      }
      if (!clusterCollectorHostLive) {
        if (printSkipPopulateMsgHostCounter.getAndIncrement() == 0) {
          LOG.info("METRICS_COLLECTOR host is not live. Skip populating " +
            "resources with metrics, next message will be logged after 1000 " +
            "attempts.");
        } else {
          printSkipPopulateMsgHostCounter.compareAndSet(1000, 0);
        }
        continue;
      }
      // reset
      printSkipPopulateMsgHostCounter.set(0);

      // Check liveliness of Collector
      boolean clusterCollectorComponentLive;
      if (clusterCollectorComponentLiveMap.containsKey(clusterName)) {
        clusterCollectorComponentLive = clusterCollectorComponentLiveMap.get(clusterName);
      } else {
        clusterCollectorComponentLive = hostProvider.isCollectorComponentLive(clusterName, TIMELINE_METRICS);
        clusterCollectorComponentLiveMap.put(clusterName, clusterCollectorComponentLive);
      }
      if (!clusterCollectorComponentLive) {
        if (printSkipPopulateMsgHostCompCounter.getAndIncrement() == 0) {
          LOG.info("METRICS_COLLECTOR is not live. Skip populating resources " +
            "with metrics., next message will be logged after 1000 " +
            "attempts.");
        } else {
          printSkipPopulateMsgHostCompCounter.compareAndSet(1000, 0);
        }
        continue;
      }
      // reset
      printSkipPopulateMsgHostCompCounter.set(0);

      Map<TemporalInfo, MetricsRequest> requests = requestMap.get(clusterName);
      if (requests == null) {
        requests = new HashMap<>();
        requestMap.put(clusterName, requests);
      }

      String collectorHost = hostProvider.getCollectorHostName(clusterName, TIMELINE_METRICS);

      if (collectorPort == null) {
        collectorPort = hostProvider.getCollectorPort(clusterName, TIMELINE_METRICS);
      }

      for (String id : ids) {
        Map<String, PropertyInfo> propertyInfoMap = new HashMap<>();

        String componentName = getOverridenComponentName(resource);

        Map<String, PropertyInfo> componentMetricMap = getComponentMetrics().get(componentName);

        // Not all components have metrics
        if (componentMetricMap != null && !componentMetricMap.containsKey(id)) {
          updateComponentMetricMap(componentMetricMap, id);
        }

        updatePropertyInfoMap(componentName, id, propertyInfoMap);

        for (Map.Entry<String, PropertyInfo> entry : propertyInfoMap.entrySet()) {
          String propertyId = entry.getKey();
          PropertyInfo propertyInfo = entry.getValue();
          TemporalInfo temporalInfo = request.getTemporalInfo(id);

          if ((temporalInfo == null && propertyInfo.isPointInTime()) ||
            (temporalInfo != null && propertyInfo.isTemporal())) {

            MetricsRequest metricsRequest = requests.get(temporalInfo);
            if (metricsRequest == null) {
              metricsRequest = new MetricsRequest(temporalInfo,
                getAMSUriBuilder(collectorHost,
                  collectorPort != null ? Integer.parseInt(collectorPort) : COLLECTOR_DEFAULT_PORT,
                  configuration.isHttpsEnabled()),
                  (String) resource.getPropertyValue(clusterNamePropertyId));
              requests.put(temporalInfo, metricsRequest);
            }
            metricsRequest.putResource(getComponentName(resource), resource);
            metricsRequest.putPropertyId(
              preprocessPropertyId(propertyInfo.getPropertyId(), getComponentName(resource)),
              propertyId);
            metricsRequest.linkResourceToMetric(getComponentName(resource), preprocessPropertyId(propertyInfo.getPropertyId(), getComponentName(resource)));
            // If request is for a host metric we need to create multiple requests
            if (propertyInfo.isAmsHostMetric()) {
              metricsRequest.putHosComponentHostMetric(propertyInfo.getPropertyId());
            }
          }
        }
      }
    }

    return requestMap;
  }
Return a set of @MetricsRequest object for each cluster.

@param resources Set of resources asked to populate
@param request Original Request object used to check properties
@param ids Property ids to populate on the resource
@throws SystemException
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java