[ONOS-3536] Implement back-end metrics saving logic using RRD

Change-Id: I1b3c495380884571dc88d2f9fb3152fdf41ef655
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricsDatabase.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricsDatabase.java
new file mode 100644
index 0000000..a0e3679
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/MetricsDatabase.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.cpman;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Database for storing a metric.
+ */
+public interface MetricsDatabase {
+    /**
+     * Returns the metric name of this database.
+     *
+     * @return metric name
+     */
+    String metricName();
+
+    /**
+     * Update metric value by specifying metric type.
+     *
+     * @param metricType metric type (e.g., load, usage, etc.)
+     * @param value metric value
+     */
+    void updateMetric(String metricType, double value);
+
+    /**
+     * Update metric value by specifying metric type in a certain time.
+     *
+     * @param metricType metric type (e.g., load, usage, etc.)
+     * @param value metric value
+     * @param time update time in seconds
+     */
+    void updateMetric(String metricType, double value, long time);
+
+    /**
+     * Update metric values of a collection of metric types.
+     *
+     * @param metrics a collection of metrics which consists of a pair of
+     *                metric type and metric value
+     * @param time    update time in seconds
+     */
+    void updateMetrics(Map<String, Double> metrics, long time);
+
+    /**
+     * Update metric values of a collection of metric types.
+     *
+     * @param metrics a collection of metrics which consists of a pair of
+     *                metric type and metric value
+     */
+    void updateMetrics(Map<String, Double> metrics);
+
+    /**
+     * Returns most recent metric value of a given metric type.
+     *
+     * @param metricType metric type
+     * @return metric value
+     */
+    double recentMetric(String metricType);
+
+    /**
+     * Return most recent metric values of a given metric type for a given period.
+     *
+     * @param metricType metric type
+     * @param duration duration
+     * @param unit time unit
+     * @return a collection of metric value
+     */
+    double[] recentMetrics(String metricType, int duration, TimeUnit unit);
+
+    /**
+     * Returns minimum metric value of a given metric type.
+     *
+     * @param metricType metric type
+     * @return metric value
+     */
+    double minMetric(String metricType);
+
+    /**
+     * Returns maximum metric value of a given metric type.
+     *
+     * @param metricType metric type
+     * @return metric value
+     */
+    double maxMetric(String metricType);
+
+    /**
+     * Returns a collection of metric values of a given metric type for a day.
+     *
+     * @param metricType metric type
+     * @return a collection of metric value
+     */
+    double[] metrics(String metricType);
+
+    /**
+     * Returns a collection of metric values of a given metric type for
+     * a given period.
+     *
+     * @param metricType metric type
+     * @param startTime start time
+     * @param endTime end time
+     * @return a collection of metric value
+     */
+    double[] metrics(String metricType, long startTime, long endTime);
+
+    /**
+     * A builder of MetricsDatabase.
+     */
+    interface Builder {
+
+        /**
+         * Sets the metric name.
+         *
+         * @param metricName metric name
+         * @return builder object
+         */
+        Builder withMetricName(String metricName);
+
+        /**
+         * Add a new metric to be monitored.
+         *
+         * @param metricType control metric type
+         */
+        Builder addMetricType(String metricType);
+
+        /**
+         * Builds a MetricDatabase instance.
+         *
+         * @return MetricDatabase instance
+         */
+        MetricsDatabase build();
+    }
+}