private void setProperties(Resource resource, String clusterName,
                            Request request, Set<String> ids) throws SystemException {

    Map<String, MetricReportRequest> reportRequestMap = getPropertyIdMaps(request, ids);
    String host = hostProvider.getCollectorHostName(clusterName, TIMELINE_METRICS);
    String port = hostProvider.getCollectorPort(clusterName, TIMELINE_METRICS);
    URIBuilder uriBuilder = AMSPropertyProvider.getAMSUriBuilder(host,
      port != null ? Integer.parseInt(port) : 6188, configuration.isHttpsEnabled());

    for (Map.Entry<String, MetricReportRequest> entry : reportRequestMap.entrySet()) {
      MetricReportRequest reportRequest = entry.getValue();
      TemporalInfo temporalInfo = reportRequest.getTemporalInfo();
      Map<String, String> propertyIdMap = reportRequest.getPropertyIdMap();

      uriBuilder.removeQuery();
      // Call with hostname = null
      uriBuilder.addParameter("metricNames",
        MetricsPropertyProvider.getSetString(propertyIdMap.keySet(), -1));

      uriBuilder.setParameter("appId", "HOST");

      if (clusterName != null && hostProvider.isCollectorHostExternal(clusterName)) {
        uriBuilder.setParameter("instanceId", clusterName);
      }

      long startTime = temporalInfo.getStartTime();
      if (startTime != -1) {
        uriBuilder.setParameter("startTime", String.valueOf(startTime));
      }

      long endTime = temporalInfo.getEndTime();
      if (endTime != -1) {
        uriBuilder.setParameter("endTime", String.valueOf(endTime));
      }

      TimelineAppMetricCacheKey metricCacheKey =
        new TimelineAppMetricCacheKey(propertyIdMap.keySet(), "HOST", temporalInfo);

      metricCacheKey.setSpec(uriBuilder.toString());

      // Self populating cache updates itself on every get with latest results
      TimelineMetrics timelineMetrics;
      try {
        if (metricCache != null && metricCacheKey.getTemporalInfo() != null) {
          timelineMetrics = metricCache.getAppTimelineMetricsFromCache(metricCacheKey);
        } else {
          timelineMetrics = requestHelper.fetchTimelineMetrics(uriBuilder,
            temporalInfo.getStartTimeMillis(),
            temporalInfo.getEndTimeMillis());
        }
      } catch (IOException io) {
        timelineMetrics = null;
        if (io instanceof SocketTimeoutException || io instanceof ConnectException) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Skip populating metrics on socket timeout exception.");
          }
          if (ambariEventPublisher != null) {
            ambariEventPublisher.publish(new MetricsCollectorHostDownEvent(clusterName, host));
          }
          break;
        }
      }

      if (timelineMetrics != null) {
        for (TimelineMetric metric : timelineMetrics.getMetrics()) {
          if (metric.getMetricName() != null && metric.getMetricValues() != null) {
            // Pad zeros or nulls if needed to a clone so we do not cache
            // padded values
            TimelineMetric timelineMetricClone = new TimelineMetric(metric);
            metricsPaddingMethod.applyPaddingStrategy(timelineMetricClone, temporalInfo);

            String propertyId = propertyIdMap.get(metric.getMetricName());
            if (propertyId != null) {
              resource.setProperty(propertyId, getValue(timelineMetricClone, temporalInfo));
            }
          }
        }
      }
    }
  }
Populate a resource by obtaining the requested Ganglia RESOURCE_METRICS.

@param resource  the resource to be populated
@param request   the request
@param predicate the predicate

@return true if the resource was successfully populated with the requested properties

@throws SystemException if unable to populate the resource
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSReportPropertyProvider.java