ambari git commit: AMBARI-10809. AMS: navigating graph time ranges are not correct. (swagle)

2015-04-29 Thread swagle
Repository: ambari
Updated Branches:
  refs/heads/trunk 6f00dd8a1 - 7f753b444


AMBARI-10809. AMS: navigating graph time ranges are not correct. (swagle)


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

Branch: refs/heads/trunk
Commit: 7f753b4448e4b370c100d663e8a4f4fd1f0ec5b0
Parents: 6f00dd8
Author: Siddharth Wagle swa...@hortonworks.com
Authored: Wed Apr 29 11:34:31 2015 -0700
Committer: Siddharth Wagle swa...@hortonworks.com
Committed: Wed Apr 29 11:34:31 2015 -0700

--
 .../metrics/MetricsPaddingMethod.java   | 106 ++
 .../metrics/MetricsPropertyProvider.java|  17 +-
 .../metrics/timeline/AMSPropertyProvider.java   |   4 +-
 .../timeline/MetricsPaddingMethodTest.java  | 208 +++
 4 files changed, 332 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/7f753b44/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
new file mode 100644
index 000..a78beee
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
@@ -0,0 +1,106 @@
+/**
+ * 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.controller.metrics;
+
+import org.apache.ambari.server.controller.spi.TemporalInfo;
+import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
+import java.util.Iterator;
+import java.util.TreeMap;
+
+public class MetricsPaddingMethod {
+  private final PADDING_STRATEGY strategy;
+  public static final String ZERO_PADDING_PARAM = params/padding;
+  public static enum PADDING_STRATEGY {
+ZEROS,
+NULLS,
+NONE
+  }
+
+  public MetricsPaddingMethod(PADDING_STRATEGY strategy) {
+this.strategy = strategy;
+  }
+
+  /**
+   * Adds zero/null values towards the end of metrics sequence as well as the
+   * beginning to support backward compatibility with Ganglia.
+   * We use step if only a single datapoint is found.
+   * It is assumed that @TimelineMetric.metricsValues are sorted in ascending
+   * order and thee is no padding between the interval.
+   *
+   * @param metric AMS @TimelineMetric
+   * @param temporalInfo @TemporalInfo Requested interval
+   */
+  public void applyPaddingStrategy(TimelineMetric metric, TemporalInfo 
temporalInfo) {
+if (strategy.equals(PADDING_STRATEGY.NONE) || temporalInfo == null) {
+  return;
+}
+
+// TODO: JSON dser returns LinkedHashMap that is not Navigable
+TreeMapLong, Double values = new TreeMapLong, 
Double(metric.getMetricValues());
+
+long dataInterval = getTimelineMetricInterval(values);
+
+if (dataInterval == -1) {
+  dataInterval = temporalInfo.getStep() != null ? temporalInfo.getStep() : 
-1;
+}
+// Unable to determine what interval to use for padding
+if (dataInterval == -1) {
+  return;
+}
+
+long intervalStartTime = longToMillis(temporalInfo.getStartTime());
+long intervalEndTime = longToMillis(temporalInfo.getEndTime());
+long dataStartTime = longToMillis(values.firstKey());
+long dataEndTime = longToMillis(values.lastKey());
+
+Double paddingValue = 0.0d;
+
+if (strategy.equals(PADDING_STRATEGY.NULLS)) {
+  paddingValue = null;
+}
+// Pad before data interval
+for (long counter = intervalStartTime; counter  dataStartTime; counter += 
dataInterval) {
+  // Until counter approaches or goes past dataStartTime : pad
+  values.put(counter, paddingValue);
+}
+// Pad after data interval
+for (long counter = dataEndTime + dataInterval; counter = 
intervalEndTime; 

ambari git commit: AMBARI-10809. AMS: navigating graph time ranges are not correct. (swagle)

2015-04-29 Thread swagle
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.maint 5eab7803f - fa96df533


AMBARI-10809. AMS: navigating graph time ranges are not correct. (swagle)


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

Branch: refs/heads/branch-2.0.maint
Commit: fa96df5332b0da27b51e76a018a9e5400f38b9ec
Parents: 5eab780
Author: Siddharth Wagle swa...@hortonworks.com
Authored: Wed Apr 29 13:50:05 2015 -0700
Committer: Siddharth Wagle swa...@hortonworks.com
Committed: Wed Apr 29 13:50:05 2015 -0700

--
 .../metrics/MetricsPaddingMethod.java   | 107 ++
 .../metrics/MetricsPropertyProvider.java|  17 +-
 .../metrics/timeline/AMSPropertyProvider.java   |   8 +-
 .../timeline/AMSPropertyProviderTest.java   |   2 +-
 .../timeline/MetricsPaddingMethodTest.java  | 208 +++
 .../resources/ams/multiple_host_metrics.json| 172 +++
 6 files changed, 422 insertions(+), 92 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/ambari/blob/fa96df53/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
--
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
new file mode 100644
index 000..6093aaf
--- /dev/null
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/metrics/MetricsPaddingMethod.java
@@ -0,0 +1,107 @@
+/**
+ * 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.controller.metrics;
+
+import org.apache.ambari.server.controller.spi.TemporalInfo;
+import org.apache.hadoop.metrics2.sink.timeline.TimelineMetric;
+import java.util.Iterator;
+import java.util.TreeMap;
+
+public class MetricsPaddingMethod {
+  private final PADDING_STRATEGY strategy;
+  private static final long MINIMUM_STEP_INTERVAL = 999l; // ~ 1 second
+  public static final String ZERO_PADDING_PARAM = params/padding;
+  public static enum PADDING_STRATEGY {
+ZEROS,
+NULLS,
+NONE
+  }
+
+  public MetricsPaddingMethod(PADDING_STRATEGY strategy) {
+this.strategy = strategy;
+  }
+
+  /**
+   * Adds zero/null values towards the end of metrics sequence as well as the
+   * beginning to support backward compatibility with Ganglia.
+   * We use step if only a single datapoint is found.
+   * It is assumed that @TimelineMetric.metricsValues are sorted in ascending
+   * order and thee is no padding between the interval.
+   *
+   * @param metric AMS @TimelineMetric
+   * @param temporalInfo @TemporalInfo Requested interval
+   */
+  public void applyPaddingStrategy(TimelineMetric metric, TemporalInfo 
temporalInfo) {
+if (strategy.equals(PADDING_STRATEGY.NONE) || temporalInfo == null) {
+  return;
+}
+
+// TODO: JSON dser returns LinkedHashMap that is not Navigable
+TreeMapLong, Double values = new TreeMapLong, 
Double(metric.getMetricValues());
+
+long dataInterval = getTimelineMetricInterval(values);
+
+if (dataInterval == -1 || dataInterval  MINIMUM_STEP_INTERVAL) {
+  dataInterval = temporalInfo.getStep() != null ? temporalInfo.getStep() : 
-1;
+}
+// Unable to determine what interval to use for padding
+if (dataInterval == -1) {
+  return;
+}
+
+long intervalStartTime = longToMillis(temporalInfo.getStartTime());
+long intervalEndTime = longToMillis(temporalInfo.getEndTime());
+long dataStartTime = longToMillis(values.firstKey());
+long dataEndTime = longToMillis(values.lastKey());
+
+Double paddingValue = 0.0d;
+
+if (strategy.equals(PADDING_STRATEGY.NULLS)) {
+  paddingValue = null;
+}
+// Pad before data interval
+for (long counter = intervalStartTime; counter