Repository: ambari
Updated Branches:
  refs/heads/trunk 4ae8d6459 -> 5ba9a426e


AMBARI-10987. Error loading deferred resources when making metric API requests 
with null padding. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5ba9a426
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5ba9a426
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5ba9a426

Branch: refs/heads/trunk
Commit: 5ba9a426e93273ba3cc0c962804f2ca4894d3224
Parents: 4ae8d64
Author: Siddharth Wagle <swa...@hortonworks.com>
Authored: Tue May 12 16:14:14 2015 -0700
Committer: Siddharth Wagle <swa...@hortonworks.com>
Committed: Tue May 12 16:17:10 2015 -0700

----------------------------------------------------------------------
 .../MetricsDownsamplingMethodFactory.java       | 38 ++++++++++++++++----
 1 file changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5ba9a426/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsDownsamplingMethodFactory.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsDownsamplingMethodFactory.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsDownsamplingMethodFactory.java
index 2d22643..f7d3457 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsDownsamplingMethodFactory.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsDownsamplingMethodFactory.java
@@ -18,6 +18,7 @@
 package org.apache.ambari.server.controller.metrics;
 
 import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
+
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Map;
@@ -75,30 +76,55 @@ class MetricsAveragePerSecondDownsampling extends 
MetricsDownsamplingMethod {
     ArrayList<Accumulo> cache = new ArrayList<Accumulo>();
 
     final Iterator<Map.Entry<Long, Double>> ci = 
metricData.getMetricValues().entrySet().iterator();
-    if (ci.hasNext()) {
-      Map.Entry<Long, Double> e0 = ci.next();
+
+    // Skip null padding at the beginning of the series.
+    Map.Entry<Long, Double> e0 = null;
+    while (ci.hasNext()) {
+      e0 = ci.next();
+      if (e0.getValue() == null) {
+        cache.add(new Accumulo(e0.getKey() / 1000, null));
+      } else {
+        break;
+      }
+    }
+
+    if (e0 != null) {
       long t0 = e0.getKey() / 1000;
       Double s0 = e0.getValue();
       int nSamples = 1;
+      boolean lastNonNullEntryAdded = false;
 
       while(ci.hasNext()) {
         e0 = ci.next();
+        // Skip null padding at the end of the series.
+        if (e0.getValue() == null) {
+          if (!lastNonNullEntryAdded) {
+            // Add last non null entry
+            cache.add(new Accumulo(t0, dataTransferMethod.getData(s0 / 
nSamples)));
+            lastNonNullEntryAdded = true;
+          }
+          // We do not pad below an interval of a second.
+          // Add the null entry
+          cache.add(new Accumulo(e0.getKey() / 1000, null));
+          continue;
+        }
         long t = e0.getKey() / 1000;
 
         if (t != t0) {
-          cache.add(new Accumulo(t0, s0 != null ? 
dataTransferMethod.getData(s0 / nSamples) : null));
+          cache.add(new Accumulo(t0, dataTransferMethod.getData(s0 / 
nSamples)));
           t0 = t;
           s0 = e0.getValue();
           nSamples = 1;
         } else {
-          // Zero value contributes to nothing for downsampling method
-          s0 += e0.getValue() != null ? e0.getValue() : 0;
+          s0 += e0.getValue();
           nSamples++;
         }
       }
 
       //Add the last entry into the cache
-      cache.add(new Accumulo(t0, s0 != null ? dataTransferMethod.getData(s0 / 
nSamples) : null));
+      if (!lastNonNullEntryAdded) {
+        cache.add(new Accumulo(t0, dataTransferMethod.getData(s0 / nSamples)));
+      }
     }
 
     Number[][] datapointsArray = new Number[cache.size()][2];

Reply via email to