@SuppressWarnings("unchecked")
    public Collection<Resource> populateResources() throws SystemException, IOException {
      // No open ended query support.
      if (temporalInfo != null && (temporalInfo.getStartTime() == null
          || temporalInfo.getEndTime() == null)) {
        return Collections.emptySet();
      }

      for (Map.Entry<String, Set<Resource>> resourceEntry : resources.entrySet()) {
        String componentName = resourceEntry.getKey();
        Set<Resource> resourceSet = resourceEntry.getValue();

        TimelineMetrics timelineMetrics = new TimelineMetrics();

        Set<String> nonHostComponentMetrics = componentMetricMap.get(componentName);
        if (nonHostComponentMetrics == null) {
          nonHostComponentMetrics = new HashSet<>();
        }
        nonHostComponentMetrics.removeAll(hostComponentHostMetrics);
        Set<String> hostNamesBatches = splitHostNamesInBatches(getHostnames(resources.get(componentName)), HOST_NAMES_BATCH_REQUEST_SIZE);
        Map<String, Set<TimelineMetric>> metricsMap = new HashMap<>();

        // split requests on few Batches to ensure url is not too long for large clusters
        for (String hostNamesBatch : hostNamesBatches) {
          // Allow for multiple requests since host metrics for a
          // hostcomponent need the HOST appId
          try {
            if (!hostComponentHostMetrics.isEmpty()) {
              String hostComponentHostMetricParams = getSetString(processRegexps(hostComponentHostMetrics), -1);
              setQueryParams(hostComponentHostMetricParams, hostNamesBatch, true, componentName);
              TimelineMetrics metricsResponse = getTimelineMetricsFromCache(
                getTimelineAppMetricCacheKey(hostComponentHostMetrics,
                  componentName, hostNamesBatch, uriBuilder.toString()), componentName);

              if (metricsResponse != null) {
                timelineMetrics.getMetrics().addAll(metricsResponse.getMetrics());
              }
            }

            if (!nonHostComponentMetrics.isEmpty()) {
              String nonHostComponentHostMetricParams = getSetString(processRegexps(nonHostComponentMetrics), -1);
              setQueryParams(nonHostComponentHostMetricParams, hostNamesBatch, false, componentName);
              TimelineMetrics metricsResponse = getTimelineMetricsFromCache(
                getTimelineAppMetricCacheKey(nonHostComponentMetrics,
                  componentName, hostNamesBatch, uriBuilder.toString()), componentName);

              if (metricsResponse != null) {
                timelineMetrics.getMetrics().addAll(metricsResponse.getMetrics());
              }
            }
          } catch (IOException io) {
            if (io instanceof SocketTimeoutException || io instanceof ConnectException) {
              if (ambariEventPublisher != null) {
                ambariEventPublisher.publish(new MetricsCollectorHostDownEvent(clusterName, uriBuilder.getHost()));
              }
              throw io;
            }
          }

          Set<String> patterns = createPatterns(metrics.keySet());

          if (!timelineMetrics.getMetrics().isEmpty()) {
            for (TimelineMetric metric : timelineMetrics.getMetrics()) {
              if (metric.getMetricName() != null
                      && metric.getMetricValues() != null
                      && checkMetricName(patterns, metric.getMetricName())) {
                String hostnameTmp = metric.getHostName();
                if (!metricsMap.containsKey(hostnameTmp)) {
                  metricsMap.put(hostnameTmp, new HashSet<>());
                }
                metricsMap.get(hostnameTmp).add(metric);
              }
            }
            for (Resource resource : resourceSet) {
              String hostnameTmp = getHostName(resource);
              if (metricsMap.containsKey(hostnameTmp)) {
                for (TimelineMetric metric : metricsMap.get(hostnameTmp)) {
                  // 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);
                  populateResource(resource, timelineMetricClone, temporalInfo);
                }
              }
            }
          }
        }
      }

      return Collections.emptySet();
    }
Populate the associated resources by making a call to the Metrics
service.

@return a collection of populated resources
@throws SystemException if unable to populate the resources
ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/timeline/AMSPropertyProvider.java