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

2015-05-12 Thread swagle
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 {
 ArrayListAccumulo cache = new ArrayListAccumulo();
 
 final IteratorMap.EntryLong, Double ci = 
metricData.getMetricValues().entrySet().iterator();
-if (ci.hasNext()) {
-  Map.EntryLong, Double e0 = ci.next();
+
+// Skip null padding at the beginning of the series.
+Map.EntryLong, 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];



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

2015-05-07 Thread swagle
Repository: ambari
Updated Branches:
  refs/heads/trunk 7b822e42b - 34c1e9b2c


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/34c1e9b2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34c1e9b2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34c1e9b2

Branch: refs/heads/trunk
Commit: 34c1e9b2c7726a92d18de68d5b292cb87e564740
Parents: 7b822e4
Author: Siddharth Wagle swa...@hortonworks.com
Authored: Thu May 7 10:34:33 2015 -0700
Committer: Siddharth Wagle swa...@hortonworks.com
Committed: Thu May 7 10:37:50 2015 -0700

--
 .../metrics/timeline/PhoenixHBaseAccessor.java  |  2 +
 .../query/render/MetricsPaddingRenderer.java| 46 +
 .../api/resources/BaseResourceDefinition.java   |  5 ++
 .../MetricsDownsamplingMethodFactory.java   | 14 ++--
 .../metrics/MetricsPropertyProvider.java| 20 --
 .../metrics/MetricsPropertyProviderProxy.java   | 13 
 .../render/MetricsPaddingRendererTest.java  | 69 
 7 files changed, 155 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/34c1e9b2/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixHBaseAccessor.java
--
diff --git 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixHBaseAccessor.java
 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixHBaseAccessor.java
index e27d9a9..7258cad 100644
--- 
a/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixHBaseAccessor.java
+++ 
b/ambari-metrics/ambari-metrics-timelineservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/metrics/timeline/PhoenixHBaseAccessor.java
@@ -309,6 +309,8 @@ public class PhoenixHBaseAccessor {
 clusterDailyTtl));
 
   conn.commit();
+
+  LOG.info(Metrics schema initialized.);
 } catch (SQLException sql) {
   if (sql.getErrorCode() ==
 SQLExceptionCode.SET_UNSUPPORTED_PROP_ON_ALTER_TABLE.getErrorCode()) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/34c1e9b2/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/MetricsPaddingRenderer.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/MetricsPaddingRenderer.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/MetricsPaddingRenderer.java
new file mode 100644
index 000..ff776c7
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/MetricsPaddingRenderer.java
@@ -0,0 +1,46 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * License); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.api.query.render;
+
+import org.apache.ambari.server.api.query.QueryInfo;
+import org.apache.ambari.server.api.util.TreeNode;
+import java.util.Set;
+
+import static 
org.apache.ambari.server.controller.metrics.MetricsPaddingMethod.PADDING_STRATEGY;
+
+public class MetricsPaddingRenderer extends DefaultRenderer {
+  PADDING_STRATEGY paddingMethod = PADDING_STRATEGY.ZEROS;
+
+  public MetricsPaddingRenderer(String paddingMethod) {
+if (paddingMethod.equalsIgnoreCase(null_padding)) {
+  this.paddingMethod = PADDING_STRATEGY.NULLS;
+} else if (paddingMethod.equalsIgnoreCase(no_padding)) {
+  this.paddingMethod = PADDING_STRATEGY.NONE;
+}
+  }
+
+  @Override
+  public TreeNodeSetString finalizeProperties(TreeNodeQueryInfo 
queryProperties,
+  boolean isCollection) {
+SetString properties =