Enable to query the control metrics from remote node
Change-Id: Ifef1c6eafd7cc79ed99be51f7faa26d97aeb2f67
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoadSnapshot.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoadSnapshot.java
new file mode 100644
index 0000000..36e436a
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlLoadSnapshot.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2016-present 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 com.google.common.base.MoreObjects;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * A container class that is used to wrap the control metric response.
+ */
+public class ControlLoadSnapshot {
+
+ private final long latest;
+ private final long average;
+ private final long time;
+
+ /**
+ * Instantiates a new control metric response with given latest, average, time.
+ *
+ * @param latest latest value of control metric
+ * @param average average value of control metric
+ * @param time last logging time fo control metric
+ */
+ public ControlLoadSnapshot(long latest, long average, long time) {
+ this.latest = latest;
+ this.average = average;
+ this.time = time;
+ }
+
+ /**
+ * Returns latest value of control metric.
+ *
+ * @return latest value of control metric
+ */
+ public long latest() {
+ return latest;
+ }
+
+ /**
+ * Returns last logging time of control metric.
+ *
+ * @return last logging time of control metric
+ */
+ public long time() {
+ return time;
+ }
+
+ /**
+ * Returns average value of control metric.
+ *
+ * @return average value of control metric
+ */
+ public long average() {
+ return average;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(latest, average, time);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ControlLoadSnapshot) {
+ final ControlLoadSnapshot other = (ControlLoadSnapshot) obj;
+ return Objects.equals(this.latest, other.latest) &&
+ Objects.equals(this.average, other.average) &&
+ Objects.equals(this.time, other.time);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ MoreObjects.ToStringHelper helper;
+ helper = toStringHelper(this)
+ .add("latest", latest)
+ .add("average", average)
+ .add("time", time);
+ return helper.toString();
+ }
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricsRequest.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricsRequest.java
new file mode 100644
index 0000000..8ee505a
--- /dev/null
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlMetricsRequest.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2016-present 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 com.google.common.base.MoreObjects;
+import org.onosproject.net.DeviceId;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * A container class that is used to request control metric of remote node.
+ */
+public class ControlMetricsRequest {
+ private final ControlMetricType type;
+ private Optional<DeviceId> deviceId;
+ private String resourceName;
+ private int duration;
+ private TimeUnit unit;
+
+ /**
+ * Instantiates a new control metric request of the control metric type and
+ * device identifier.
+ *
+ * @param type control metric type
+ * @param deviceId device identifier
+ */
+ public ControlMetricsRequest(ControlMetricType type, Optional<DeviceId> deviceId) {
+ this.type = type;
+ this.deviceId = deviceId;
+ }
+
+ /**
+ * Instantiates a new control metric request of the control metric type and
+ * device identifier with the given projected time range.
+ *
+ * @param type control metric type
+ * @param duration projected time duration
+ * @param unit projected time unit
+ * @param deviceId device dientifer
+ */
+ public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit,
+ Optional<DeviceId> deviceId) {
+ this.type = type;
+ this.deviceId = deviceId;
+ this.duration = duration;
+ this.unit = unit;
+ }
+
+ /**
+ * Instantiates a new control metric request of the control metric type and
+ * resource name.
+ *
+ * @param type control metric type
+ * @param resourceName resource name
+ */
+ public ControlMetricsRequest(ControlMetricType type, String resourceName) {
+ this.type = type;
+ this.resourceName = resourceName;
+ }
+
+ /**
+ * Instantiates a new control metric request of the control metric type and
+ * resource name with the given projected time range.
+ *
+ * @param type control metric type
+ * @param duration projected time duration
+ * @param unit projected time unit
+ * @param resourceName resource name
+ */
+ public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit,
+ String resourceName) {
+ this.type = type;
+ this.resourceName = resourceName;
+ this.duration = duration;
+ this.unit = unit;
+ }
+
+ /**
+ * Obtains control metric type.
+ *
+ * @return control metric type
+ */
+ public ControlMetricType getType() {
+ return type;
+ }
+
+ /**
+ * Obtains resource name.
+ *
+ * @return resource name
+ */
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ /**
+ * Obtains device identifier.
+ *
+ * @return device identifier
+ */
+ public Optional<DeviceId> getDeviceId() {
+ return deviceId;
+ }
+
+ /**
+ * Obtains projected time duration.
+ *
+ * @return projected time duration
+ */
+ public int getDuration() {
+ return duration;
+ }
+
+ /**
+ * Obtains projected time unit.
+ *
+ * @return projected time unit
+ */
+ public TimeUnit getUnit() {
+ return unit;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, deviceId, resourceName, duration, unit.toString());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof ControlMetricsRequest) {
+ final ControlMetricsRequest other = (ControlMetricsRequest) obj;
+ return Objects.equals(this.type, other.type) &&
+ Objects.equals(this.deviceId, other.deviceId) &&
+ Objects.equals(this.resourceName, other.resourceName) &&
+ Objects.equals(this.duration, other.duration) &&
+ Objects.equals(this.unit, other.unit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ MoreObjects.ToStringHelper helper;
+ helper = toStringHelper(this)
+ .add("type", type)
+ .add("resourceName", resourceName)
+ .add("duration", duration)
+ .add("timeUnit", unit);
+ if (deviceId != null) {
+ helper.add("deviceId", deviceId.get());
+ }
+ return helper.toString();
+ }
+}
diff --git a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
index 9a9930f..32ccdd6 100644
--- a/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
+++ b/apps/cpman/api/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
@@ -21,8 +21,9 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
-import static org.onosproject.cpman.ControlResource.*;
+import static org.onosproject.cpman.ControlResource.Type;
/**
* Control Plane Statistics Service Interface.
@@ -52,50 +53,65 @@
String resourceName);
/**
- * Obtains local control plane load of a specific device.
+ * Obtains snapshot of control plane load of a specific device.
* The metrics range from control messages and system metrics
- * (e.g., CPU and memory info)
- *
- * @param type control metric type
- * @param deviceId device identifier
- * @return control plane load
- */
- ControlLoad getLocalLoad(ControlMetricType type, Optional<DeviceId> deviceId);
-
- /**
- * Obtains local control plane load of a specific resource.
- * The metrics range from I/O device metrics
- * (e.g., disk and network interface)
- *
- * @param type control metric type
- * @param resourceName resource name
- * @return control plane load
- */
- ControlLoad getLocalLoad(ControlMetricType type, String resourceName);
-
- /**
- * Obtains remote control plane load of a specific device.
+ * (e.g., CPU and memory info).
+ * If the device id is not specified, it returns system metrics, otherwise,
+ * it returns control message stats of the given device.
*
* @param nodeId node identifier
* @param type control metric type
* @param deviceId device identifier
- * @return completable future object of control load
+ * @return completable future object of control load snapshot
*/
- CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId,
- ControlMetricType type,
- Optional<DeviceId> deviceId);
+ CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
+ ControlMetricType type,
+ Optional<DeviceId> deviceId);
/**
- * Obtains remote control plane load of a specific resource.
+ * Obtains snapshot of control plane load of a specific resource.
+ * The metrics include I/O device metrics (e.g., disk and network metrics).
*
* @param nodeId node identifier
* @param type control metric type
* @param resourceName resource name
- * @return completable future object of control load
+ * @return completable future object of control load snapshot
*/
- CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId,
- ControlMetricType type,
- String resourceName);
+ CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
+ ControlMetricType type,
+ String resourceName);
+
+ /**
+ * Obtains snapshot of control plane load of a specific device with the
+ * projected range.
+ *
+ * @param nodeId node identifier
+ * @param type control metric type
+ * @param duration projected duration
+ * @param unit projected time unit
+ * @param deviceId device identifier
+ * @return completable future object of control load snapshot
+ */
+ CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
+ ControlMetricType type,
+ int duration, TimeUnit unit,
+ Optional<DeviceId> deviceId);
+
+ /**
+ * Obtains snapshot of control plane load of a specific resource with the
+ * projected range.
+ *
+ * @param nodeId node identifier
+ * @param type control metric type
+ * @param duration projected duration
+ * @param unit projected time unit
+ * @param resourceName resource name
+ * @return completable future object of control load snapshot
+ */
+ CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
+ ControlMetricType type,
+ int duration, TimeUnit unit,
+ String resourceName);
/**
* Obtains a list of names of available resources.