Jian Li
Committed by Gerrit Code Review

Enable to query the control metrics from remote node

Change-Id: Ifef1c6eafd7cc79ed99be51f7faa26d97aeb2f67
1 +/*
2 + * Copyright 2016-present Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cpman;
17 +
18 +import com.google.common.base.MoreObjects;
19 +
20 +import java.util.Objects;
21 +
22 +import static com.google.common.base.MoreObjects.toStringHelper;
23 +
24 +/**
25 + * A container class that is used to wrap the control metric response.
26 + */
27 +public class ControlLoadSnapshot {
28 +
29 + private final long latest;
30 + private final long average;
31 + private final long time;
32 +
33 + /**
34 + * Instantiates a new control metric response with given latest, average, time.
35 + *
36 + * @param latest latest value of control metric
37 + * @param average average value of control metric
38 + * @param time last logging time fo control metric
39 + */
40 + public ControlLoadSnapshot(long latest, long average, long time) {
41 + this.latest = latest;
42 + this.average = average;
43 + this.time = time;
44 + }
45 +
46 + /**
47 + * Returns latest value of control metric.
48 + *
49 + * @return latest value of control metric
50 + */
51 + public long latest() {
52 + return latest;
53 + }
54 +
55 + /**
56 + * Returns last logging time of control metric.
57 + *
58 + * @return last logging time of control metric
59 + */
60 + public long time() {
61 + return time;
62 + }
63 +
64 + /**
65 + * Returns average value of control metric.
66 + *
67 + * @return average value of control metric
68 + */
69 + public long average() {
70 + return average;
71 + }
72 +
73 + @Override
74 + public int hashCode() {
75 + return Objects.hash(latest, average, time);
76 + }
77 +
78 + @Override
79 + public boolean equals(Object obj) {
80 + if (this == obj) {
81 + return true;
82 + }
83 + if (obj instanceof ControlLoadSnapshot) {
84 + final ControlLoadSnapshot other = (ControlLoadSnapshot) obj;
85 + return Objects.equals(this.latest, other.latest) &&
86 + Objects.equals(this.average, other.average) &&
87 + Objects.equals(this.time, other.time);
88 + }
89 + return false;
90 + }
91 +
92 + @Override
93 + public String toString() {
94 + MoreObjects.ToStringHelper helper;
95 + helper = toStringHelper(this)
96 + .add("latest", latest)
97 + .add("average", average)
98 + .add("time", time);
99 + return helper.toString();
100 + }
101 +}
...@@ -13,14 +13,14 @@ ...@@ -13,14 +13,14 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.onosproject.cpman.impl; 16 +package org.onosproject.cpman;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 -import org.onosproject.cpman.ControlMetricType;
20 import org.onosproject.net.DeviceId; 19 import org.onosproject.net.DeviceId;
21 20
22 import java.util.Objects; 21 import java.util.Objects;
23 import java.util.Optional; 22 import java.util.Optional;
23 +import java.util.concurrent.TimeUnit;
24 24
25 import static com.google.common.base.MoreObjects.toStringHelper; 25 import static com.google.common.base.MoreObjects.toStringHelper;
26 26
...@@ -31,10 +31,12 @@ public class ControlMetricsRequest { ...@@ -31,10 +31,12 @@ public class ControlMetricsRequest {
31 private final ControlMetricType type; 31 private final ControlMetricType type;
32 private Optional<DeviceId> deviceId; 32 private Optional<DeviceId> deviceId;
33 private String resourceName; 33 private String resourceName;
34 + private int duration;
35 + private TimeUnit unit;
34 36
35 /** 37 /**
36 - * Instantiates a new control metric request with the given control metric 38 + * Instantiates a new control metric request of the control metric type and
37 - * type and device identifier. 39 + * device identifier.
38 * 40 *
39 * @param type control metric type 41 * @param type control metric type
40 * @param deviceId device identifier 42 * @param deviceId device identifier
...@@ -45,8 +47,25 @@ public class ControlMetricsRequest { ...@@ -45,8 +47,25 @@ public class ControlMetricsRequest {
45 } 47 }
46 48
47 /** 49 /**
48 - * Instantiates a new control metric request with the given control metric 50 + * Instantiates a new control metric request of the control metric type and
49 - * type and resource name. 51 + * device identifier with the given projected time range.
52 + *
53 + * @param type control metric type
54 + * @param duration projected time duration
55 + * @param unit projected time unit
56 + * @param deviceId device dientifer
57 + */
58 + public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit,
59 + Optional<DeviceId> deviceId) {
60 + this.type = type;
61 + this.deviceId = deviceId;
62 + this.duration = duration;
63 + this.unit = unit;
64 + }
65 +
66 + /**
67 + * Instantiates a new control metric request of the control metric type and
68 + * resource name.
50 * 69 *
51 * @param type control metric type 70 * @param type control metric type
52 * @param resourceName resource name 71 * @param resourceName resource name
...@@ -57,6 +76,23 @@ public class ControlMetricsRequest { ...@@ -57,6 +76,23 @@ public class ControlMetricsRequest {
57 } 76 }
58 77
59 /** 78 /**
79 + * Instantiates a new control metric request of the control metric type and
80 + * resource name with the given projected time range.
81 + *
82 + * @param type control metric type
83 + * @param duration projected time duration
84 + * @param unit projected time unit
85 + * @param resourceName resource name
86 + */
87 + public ControlMetricsRequest(ControlMetricType type, int duration, TimeUnit unit,
88 + String resourceName) {
89 + this.type = type;
90 + this.resourceName = resourceName;
91 + this.duration = duration;
92 + this.unit = unit;
93 + }
94 +
95 + /**
60 * Obtains control metric type. 96 * Obtains control metric type.
61 * 97 *
62 * @return control metric type 98 * @return control metric type
...@@ -83,9 +119,27 @@ public class ControlMetricsRequest { ...@@ -83,9 +119,27 @@ public class ControlMetricsRequest {
83 return deviceId; 119 return deviceId;
84 } 120 }
85 121
122 + /**
123 + * Obtains projected time duration.
124 + *
125 + * @return projected time duration
126 + */
127 + public int getDuration() {
128 + return duration;
129 + }
130 +
131 + /**
132 + * Obtains projected time unit.
133 + *
134 + * @return projected time unit
135 + */
136 + public TimeUnit getUnit() {
137 + return unit;
138 + }
139 +
86 @Override 140 @Override
87 public int hashCode() { 141 public int hashCode() {
88 - return Objects.hash(type, deviceId, resourceName); 142 + return Objects.hash(type, deviceId, resourceName, duration, unit.toString());
89 } 143 }
90 144
91 @Override 145 @Override
...@@ -97,7 +151,9 @@ public class ControlMetricsRequest { ...@@ -97,7 +151,9 @@ public class ControlMetricsRequest {
97 final ControlMetricsRequest other = (ControlMetricsRequest) obj; 151 final ControlMetricsRequest other = (ControlMetricsRequest) obj;
98 return Objects.equals(this.type, other.type) && 152 return Objects.equals(this.type, other.type) &&
99 Objects.equals(this.deviceId, other.deviceId) && 153 Objects.equals(this.deviceId, other.deviceId) &&
100 - Objects.equals(this.resourceName, other.resourceName); 154 + Objects.equals(this.resourceName, other.resourceName) &&
155 + Objects.equals(this.duration, other.duration) &&
156 + Objects.equals(this.unit, other.unit);
101 } 157 }
102 return false; 158 return false;
103 } 159 }
...@@ -107,7 +163,9 @@ public class ControlMetricsRequest { ...@@ -107,7 +163,9 @@ public class ControlMetricsRequest {
107 MoreObjects.ToStringHelper helper; 163 MoreObjects.ToStringHelper helper;
108 helper = toStringHelper(this) 164 helper = toStringHelper(this)
109 .add("type", type) 165 .add("type", type)
110 - .add("resourceName", resourceName); 166 + .add("resourceName", resourceName)
167 + .add("duration", duration)
168 + .add("timeUnit", unit);
111 if (deviceId != null) { 169 if (deviceId != null) {
112 helper.add("deviceId", deviceId.get()); 170 helper.add("deviceId", deviceId.get());
113 } 171 }
......
...@@ -21,8 +21,9 @@ import org.onosproject.net.DeviceId; ...@@ -21,8 +21,9 @@ import org.onosproject.net.DeviceId;
21 import java.util.Optional; 21 import java.util.Optional;
22 import java.util.Set; 22 import java.util.Set;
23 import java.util.concurrent.CompletableFuture; 23 import java.util.concurrent.CompletableFuture;
24 +import java.util.concurrent.TimeUnit;
24 25
25 -import static org.onosproject.cpman.ControlResource.*; 26 +import static org.onosproject.cpman.ControlResource.Type;
26 27
27 /** 28 /**
28 * Control Plane Statistics Service Interface. 29 * Control Plane Statistics Service Interface.
...@@ -52,50 +53,65 @@ public interface ControlPlaneMonitorService { ...@@ -52,50 +53,65 @@ public interface ControlPlaneMonitorService {
52 String resourceName); 53 String resourceName);
53 54
54 /** 55 /**
55 - * Obtains local control plane load of a specific device. 56 + * Obtains snapshot of control plane load of a specific device.
56 * The metrics range from control messages and system metrics 57 * The metrics range from control messages and system metrics
57 - * (e.g., CPU and memory info) 58 + * (e.g., CPU and memory info).
59 + * If the device id is not specified, it returns system metrics, otherwise,
60 + * it returns control message stats of the given device.
58 * 61 *
62 + * @param nodeId node identifier
59 * @param type control metric type 63 * @param type control metric type
60 * @param deviceId device identifier 64 * @param deviceId device identifier
61 - * @return control plane load 65 + * @return completable future object of control load snapshot
62 */ 66 */
63 - ControlLoad getLocalLoad(ControlMetricType type, Optional<DeviceId> deviceId); 67 + CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
68 + ControlMetricType type,
69 + Optional<DeviceId> deviceId);
64 70
65 /** 71 /**
66 - * Obtains local control plane load of a specific resource. 72 + * Obtains snapshot of control plane load of a specific resource.
67 - * The metrics range from I/O device metrics 73 + * The metrics include I/O device metrics (e.g., disk and network metrics).
68 - * (e.g., disk and network interface)
69 * 74 *
75 + * @param nodeId node identifier
70 * @param type control metric type 76 * @param type control metric type
71 * @param resourceName resource name 77 * @param resourceName resource name
72 - * @return control plane load 78 + * @return completable future object of control load snapshot
73 */ 79 */
74 - ControlLoad getLocalLoad(ControlMetricType type, String resourceName); 80 + CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
81 + ControlMetricType type,
82 + String resourceName);
75 83
76 /** 84 /**
77 - * Obtains remote control plane load of a specific device. 85 + * Obtains snapshot of control plane load of a specific device with the
86 + * projected range.
78 * 87 *
79 * @param nodeId node identifier 88 * @param nodeId node identifier
80 * @param type control metric type 89 * @param type control metric type
90 + * @param duration projected duration
91 + * @param unit projected time unit
81 * @param deviceId device identifier 92 * @param deviceId device identifier
82 - * @return completable future object of control load 93 + * @return completable future object of control load snapshot
83 */ 94 */
84 - CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 95 + CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
85 - ControlMetricType type, 96 + ControlMetricType type,
86 - Optional<DeviceId> deviceId); 97 + int duration, TimeUnit unit,
98 + Optional<DeviceId> deviceId);
87 99
88 /** 100 /**
89 - * Obtains remote control plane load of a specific resource. 101 + * Obtains snapshot of control plane load of a specific resource with the
102 + * projected range.
90 * 103 *
91 * @param nodeId node identifier 104 * @param nodeId node identifier
92 * @param type control metric type 105 * @param type control metric type
106 + * @param duration projected duration
107 + * @param unit projected time unit
93 * @param resourceName resource name 108 * @param resourceName resource name
94 - * @return completable future object of control load 109 + * @return completable future object of control load snapshot
95 */ 110 */
96 - CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 111 + CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
97 - ControlMetricType type, 112 + ControlMetricType type,
98 - String resourceName); 113 + int duration, TimeUnit unit,
114 + String resourceName);
99 115
100 /** 116 /**
101 * Obtains a list of names of available resources. 117 * Obtains a list of names of available resources.
......
...@@ -17,16 +17,18 @@ package org.onosproject.cpman.cli; ...@@ -17,16 +17,18 @@ package org.onosproject.cpman.cli;
17 17
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 +import org.onlab.util.Tools;
20 import org.onosproject.cli.AbstractShellCommand; 21 import org.onosproject.cli.AbstractShellCommand;
21 -import org.onosproject.cluster.ClusterService;
22 import org.onosproject.cluster.NodeId; 22 import org.onosproject.cluster.NodeId;
23 -import org.onosproject.cpman.ControlLoad; 23 +import org.onosproject.cpman.ControlLoadSnapshot;
24 import org.onosproject.cpman.ControlMetricType; 24 import org.onosproject.cpman.ControlMetricType;
25 import org.onosproject.cpman.ControlPlaneMonitorService; 25 import org.onosproject.cpman.ControlPlaneMonitorService;
26 import org.onosproject.net.DeviceId; 26 import org.onosproject.net.DeviceId;
27 27
28 import java.util.Optional; 28 import java.util.Optional;
29 import java.util.Set; 29 import java.util.Set;
30 +import java.util.concurrent.CompletableFuture;
31 +import java.util.concurrent.TimeUnit;
30 32
31 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS; 33 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS;
32 import static org.onosproject.cpman.ControlResource.CPU_METRICS; 34 import static org.onosproject.cpman.ControlResource.CPU_METRICS;
...@@ -45,20 +47,25 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand { ...@@ -45,20 +47,25 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand {
45 "averageValue=%d, latestTime=%s"; 47 "averageValue=%d, latestTime=%s";
46 private static final String INVALID_TYPE = "Invalid control resource type."; 48 private static final String INVALID_TYPE = "Invalid control resource type.";
47 49
48 - @Argument(index = 0, name = "type", 50 + private static final long TIMEOUT_MILLIS = 3000;
51 +
52 + @Argument(index = 0, name = "node", description = "ONOS node identifier",
53 + required = true, multiValued = false)
54 + String node = null;
55 +
56 + @Argument(index = 1, name = "type",
49 description = "Resource type (cpu|memory|disk|network|control_message)", 57 description = "Resource type (cpu|memory|disk|network|control_message)",
50 required = true, multiValued = false) 58 required = true, multiValued = false)
51 String type = null; 59 String type = null;
52 60
53 - @Argument(index = 1, name = "name", description = "Resource name (or Device Id)", 61 + @Argument(index = 2, name = "name", description = "Resource name (or Device Id)",
54 required = false, multiValued = false) 62 required = false, multiValued = false)
55 String name = null; 63 String name = null;
56 64
57 @Override 65 @Override
58 protected void execute() { 66 protected void execute() {
59 ControlPlaneMonitorService service = get(ControlPlaneMonitorService.class); 67 ControlPlaneMonitorService service = get(ControlPlaneMonitorService.class);
60 - ClusterService clusterService = get(ClusterService.class); 68 + NodeId nodeId = NodeId.nodeId(node);
61 - NodeId nodeId = clusterService.getLocalNode().id();
62 switch (type) { 69 switch (type) {
63 case "cpu": 70 case "cpu":
64 printMetricsStats(service, nodeId, CPU_METRICS); 71 printMetricsStats(service, nodeId, CPU_METRICS);
...@@ -74,7 +81,8 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand { ...@@ -74,7 +81,8 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand {
74 break; 81 break;
75 case "control_message": 82 case "control_message":
76 if (name != null) { 83 if (name != null) {
77 - printMetricsStats(service, nodeId, CONTROL_MESSAGE_METRICS, DeviceId.deviceId(name)); 84 + printMetricsStats(service, nodeId, CONTROL_MESSAGE_METRICS,
85 + DeviceId.deviceId(name));
78 } 86 }
79 break; 87 break;
80 default: 88 default:
...@@ -89,8 +97,8 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand { ...@@ -89,8 +97,8 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand {
89 } 97 }
90 98
91 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, 99 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId,
92 - Set<ControlMetricType> typeSet, String name) { 100 + Set<ControlMetricType> typeSet, String resName) {
93 - printMetricsStats(service, nodeId, typeSet, name, null); 101 + printMetricsStats(service, nodeId, typeSet, resName, null);
94 } 102 }
95 103
96 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, 104 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId,
...@@ -99,19 +107,39 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand { ...@@ -99,19 +107,39 @@ public class ControlMetricsStatsListCommand extends AbstractShellCommand {
99 } 107 }
100 108
101 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId, 109 private void printMetricsStats(ControlPlaneMonitorService service, NodeId nodeId,
102 - Set<ControlMetricType> typeSet, String name, DeviceId did) { 110 + Set<ControlMetricType> typeSet, String resName, DeviceId did) {
103 - if (name == null && did == null) { 111 + if (resName == null && did == null) {
104 - typeSet.forEach(s -> print(s, service.getLocalLoad(s, Optional.ofNullable(null)))); 112 + typeSet.forEach(s -> {
105 - } else if (name == null && did != null) { 113 + CompletableFuture<ControlLoadSnapshot> cf =
106 - typeSet.forEach(s -> print(s, service.getLocalLoad(s, Optional.of(did)))); 114 + service.getLoad(nodeId, s, Optional.empty());
107 - } else if (name != null && did == null) { 115 + ControlLoadSnapshot cmr =
108 - typeSet.forEach(s -> print(s, service.getLocalLoad(s, name))); 116 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
117 + printRemote(s, cmr);
118 + });
119 + } else if (resName == null && did != null) {
120 + typeSet.forEach(s -> {
121 + CompletableFuture<ControlLoadSnapshot> cf =
122 + service.getLoad(nodeId, s, Optional.of(did));
123 + ControlLoadSnapshot cmr =
124 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
125 + printRemote(s, cmr);
126 + });
127 + } else if (resName != null && did == null) {
128 + typeSet.forEach(s -> {
129 + CompletableFuture<ControlLoadSnapshot> cf =
130 + service.getLoad(nodeId, s, resName);
131 + ControlLoadSnapshot cmr =
132 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
133 + printRemote(s, cmr);
134 + });
109 } 135 }
110 } 136 }
111 137
112 - private void print(ControlMetricType type, ControlLoad cl) { 138 + private void printRemote(ControlMetricType cmType, ControlLoadSnapshot cls) {
113 - if (cl != null) { 139 + if (cls != null) {
114 - print(FMT, type.toString(), cl.latest(), cl.average(), cl.time()); 140 + print(FMT, cmType.toString(), cls.latest(), cls.average(), cls.time());
141 + } else {
142 + print("Failed to retrieve metric value for type {}", cmType.toString());
115 } 143 }
116 } 144 }
117 } 145 }
......
...@@ -18,22 +18,22 @@ package org.onosproject.cpman.codec; ...@@ -18,22 +18,22 @@ package org.onosproject.cpman.codec;
18 import com.fasterxml.jackson.databind.node.ObjectNode; 18 import com.fasterxml.jackson.databind.node.ObjectNode;
19 import org.onosproject.codec.CodecContext; 19 import org.onosproject.codec.CodecContext;
20 import org.onosproject.codec.JsonCodec; 20 import org.onosproject.codec.JsonCodec;
21 -import org.onosproject.cpman.ControlLoad; 21 +import org.onosproject.cpman.ControlLoadSnapshot;
22 22
23 /** 23 /**
24 - * Control load codec. 24 + * Control load snapshot codec.
25 */ 25 */
26 -public final class ControlLoadCodec extends JsonCodec<ControlLoad> { 26 +public final class ControlLoadSnapshotCodec extends JsonCodec<ControlLoadSnapshot> {
27 27
28 private static final String TIME = "time"; 28 private static final String TIME = "time";
29 private static final String LATEST = "latest"; 29 private static final String LATEST = "latest";
30 private static final String AVERAGE = "average"; 30 private static final String AVERAGE = "average";
31 31
32 @Override 32 @Override
33 - public ObjectNode encode(ControlLoad controlLoad, CodecContext context) { 33 + public ObjectNode encode(ControlLoadSnapshot controlLoadSnapshot, CodecContext context) {
34 return context.mapper().createObjectNode() 34 return context.mapper().createObjectNode()
35 - .put(TIME, controlLoad.time()) 35 + .put(TIME, controlLoadSnapshot.time())
36 - .put(LATEST, controlLoad.latest()) 36 + .put(LATEST, controlLoadSnapshot.latest())
37 - .put(AVERAGE, controlLoad.average()); 37 + .put(AVERAGE, controlLoadSnapshot.average());
38 } 38 }
39 } 39 }
......
...@@ -29,8 +29,10 @@ import org.onlab.util.KryoNamespace; ...@@ -29,8 +29,10 @@ import org.onlab.util.KryoNamespace;
29 import org.onosproject.cluster.ClusterService; 29 import org.onosproject.cluster.ClusterService;
30 import org.onosproject.cluster.NodeId; 30 import org.onosproject.cluster.NodeId;
31 import org.onosproject.cpman.ControlLoad; 31 import org.onosproject.cpman.ControlLoad;
32 +import org.onosproject.cpman.ControlLoadSnapshot;
32 import org.onosproject.cpman.ControlMetric; 33 import org.onosproject.cpman.ControlMetric;
33 import org.onosproject.cpman.ControlMetricType; 34 import org.onosproject.cpman.ControlMetricType;
35 +import org.onosproject.cpman.ControlMetricsRequest;
34 import org.onosproject.cpman.ControlPlaneMonitorService; 36 import org.onosproject.cpman.ControlPlaneMonitorService;
35 import org.onosproject.cpman.MetricsDatabase; 37 import org.onosproject.cpman.MetricsDatabase;
36 import org.onosproject.net.DeviceId; 38 import org.onosproject.net.DeviceId;
...@@ -45,12 +47,10 @@ import java.util.Map; ...@@ -45,12 +47,10 @@ import java.util.Map;
45 import java.util.Optional; 47 import java.util.Optional;
46 import java.util.Set; 48 import java.util.Set;
47 import java.util.concurrent.CompletableFuture; 49 import java.util.concurrent.CompletableFuture;
48 -import java.util.concurrent.ExecutorService; 50 +import java.util.concurrent.TimeUnit;
49 -import java.util.concurrent.Executors;
50 import java.util.stream.Collectors; 51 import java.util.stream.Collectors;
51 52
52 import static com.google.common.base.Preconditions.checkArgument; 53 import static com.google.common.base.Preconditions.checkArgument;
53 -import static org.onlab.util.Tools.groupedThreads;
54 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS; 54 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS;
55 import static org.onosproject.cpman.ControlResource.CPU_METRICS; 55 import static org.onosproject.cpman.ControlResource.CPU_METRICS;
56 import static org.onosproject.cpman.ControlResource.DISK_METRICS; 56 import static org.onosproject.cpman.ControlResource.DISK_METRICS;
...@@ -84,7 +84,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -84,7 +84,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
84 ImmutableSet.of(Type.CONTROL_MESSAGE, Type.DISK, Type.NETWORK); 84 ImmutableSet.of(Type.CONTROL_MESSAGE, Type.DISK, Type.NETWORK);
85 85
86 private static final MessageSubject CONTROL_STATS = 86 private static final MessageSubject CONTROL_STATS =
87 - new MessageSubject("control-plane-stats"); 87 + new MessageSubject("control-plane-stats");
88 88
89 private Map<ControlMetricType, Double> cpuBuf; 89 private Map<ControlMetricType, Double> cpuBuf;
90 private Map<ControlMetricType, Double> memoryBuf; 90 private Map<ControlMetricType, Double> memoryBuf;
...@@ -95,19 +95,16 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -95,19 +95,16 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
95 private Map<Type, Set<String>> availableResourceMap; 95 private Map<Type, Set<String>> availableResourceMap;
96 private Set<DeviceId> availableDeviceIdSet; 96 private Set<DeviceId> availableDeviceIdSet;
97 97
98 - private ExecutorService messageHandlingExecutor;
99 -
100 private static final String METRIC_TYPE_NULL = "Control metric type cannot be null"; 98 private static final String METRIC_TYPE_NULL = "Control metric type cannot be null";
101 99
102 - Set<Map<ControlMetricType, Double>> debugSets = Sets.newHashSet();
103 -
104 private static final Serializer SERIALIZER = Serializer 100 private static final Serializer SERIALIZER = Serializer
105 .using(new KryoNamespace.Builder() 101 .using(new KryoNamespace.Builder()
106 .register(KryoNamespaces.API) 102 .register(KryoNamespaces.API)
103 + .register(KryoNamespaces.BASIC)
107 .register(ControlMetricsRequest.class) 104 .register(ControlMetricsRequest.class)
108 - .register(DefaultControlLoad.class) 105 + .register(ControlLoadSnapshot.class)
109 - .register(DefaultMetricsDatabase.class)
110 .register(ControlMetricType.class) 106 .register(ControlMetricType.class)
107 + .register(TimeUnit.class)
111 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).build()); 108 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID).build());
112 109
113 @Activate 110 @Activate
...@@ -127,11 +124,8 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -127,11 +124,8 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
127 availableResourceMap = Maps.newConcurrentMap(); 124 availableResourceMap = Maps.newConcurrentMap();
128 availableDeviceIdSet = Sets.newConcurrentHashSet(); 125 availableDeviceIdSet = Sets.newConcurrentHashSet();
129 126
130 - messageHandlingExecutor = Executors.newSingleThreadScheduledExecutor( 127 + communicationService.<ControlMetricsRequest, ControlLoadSnapshot>addSubscriber(CONTROL_STATS,
131 - groupedThreads("onos/app/cpman", "message-handlers", log)); 128 + SERIALIZER::decode, this::handleRequest, SERIALIZER::encode);
132 -
133 - communicationService.addSubscriber(CONTROL_STATS,
134 - SERIALIZER::decode, this::handleRequest, messageHandlingExecutor);
135 129
136 log.info("Started"); 130 log.info("Started");
137 } 131 }
...@@ -243,58 +237,55 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -243,58 +237,55 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
243 } 237 }
244 238
245 @Override 239 @Override
246 - public ControlLoad getLocalLoad(ControlMetricType type, 240 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
247 - Optional<DeviceId> deviceId) { 241 + ControlMetricType type,
248 - if (deviceId.isPresent()) { 242 + Optional<DeviceId> deviceId) {
249 - if (CONTROL_MESSAGE_METRICS.contains(type) && 243 + if (clusterService.getLocalNode().id().equals(nodeId)) {
250 - availableDeviceIdSet.contains(deviceId.get())) { 244 + return CompletableFuture.completedFuture(snapshot(getLocalLoad(type, deviceId)));
251 - return new DefaultControlLoad(controlMessageMap.get(deviceId.get()), type);
252 - }
253 } else { 245 } else {
254 - // returns controlLoad of CPU metrics 246 + return communicationService.sendAndReceive(createRequest(type, deviceId),
255 - if (CPU_METRICS.contains(type)) { 247 + CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId);
256 - return new DefaultControlLoad(cpuMetrics, type);
257 - }
258 -
259 - // returns memoryLoad of memory metrics
260 - if (MEMORY_METRICS.contains(type)) {
261 - return new DefaultControlLoad(memoryMetrics, type);
262 - }
263 } 248 }
264 - return null;
265 } 249 }
266 250
267 @Override 251 @Override
268 - public ControlLoad getLocalLoad(ControlMetricType type, String resourceName) { 252 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
269 - if (DISK_METRICS.contains(type) && 253 + ControlMetricType type,
270 - availableResources(Type.DISK).contains(resourceName)) { 254 + String resourceName) {
271 - return new DefaultControlLoad(diskMetricsMap.get(resourceName), type); 255 + if (clusterService.getLocalNode().id().equals(nodeId)) {
272 - } 256 + return CompletableFuture.completedFuture(snapshot(getLocalLoad(type, resourceName)));
273 - 257 + } else {
274 - if (NETWORK_METRICS.contains(type) && 258 + return communicationService.sendAndReceive(createRequest(type, resourceName),
275 - availableResources(Type.NETWORK).contains(resourceName)) { 259 + CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId);
276 - return new DefaultControlLoad(networkMetricsMap.get(resourceName), type);
277 } 260 }
278 - return null;
279 } 261 }
280 262
281 @Override 263 @Override
282 - public CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 264 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
283 - ControlMetricType type, 265 + ControlMetricType type,
284 - Optional<DeviceId> deviceId) { 266 + int duration, TimeUnit unit,
285 - return communicationService.sendAndReceive(createRequest(type, deviceId), 267 + Optional<DeviceId> deviceId) {
286 - CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId); 268 + if (clusterService.getLocalNode().id().equals(nodeId)) {
269 + return CompletableFuture.completedFuture(snapshot(getLocalLoad(type, deviceId), duration, unit));
270 + } else {
271 + return communicationService.sendAndReceive(createRequest(type, duration, unit, deviceId),
272 + CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId);
273 + }
287 } 274 }
288 275
289 @Override 276 @Override
290 - public CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 277 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
291 - ControlMetricType type, 278 + ControlMetricType type,
292 - String resourceName) { 279 + int duration, TimeUnit unit,
293 - return communicationService.sendAndReceive(createRequest(type, resourceName), 280 + String resourceName) {
294 - CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId); 281 + if (clusterService.getLocalNode().id().equals(nodeId)) {
282 + return CompletableFuture.completedFuture(snapshot(getLocalLoad(type, resourceName), duration, unit));
283 + } else {
284 + return communicationService.sendAndReceive(createRequest(type, duration, unit, resourceName),
285 + CONTROL_STATS, SERIALIZER::encode, SERIALIZER::decode, nodeId);
286 + }
295 } 287 }
296 288
297 -
298 @Override 289 @Override
299 public Set<String> availableResources(Type resourceType) { 290 public Set<String> availableResources(Type resourceType) {
300 if (RESOURCE_TYPE_SET.contains(resourceType)) { 291 if (RESOURCE_TYPE_SET.contains(resourceType)) {
...@@ -309,6 +300,15 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -309,6 +300,15 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
309 return ImmutableSet.of(); 300 return ImmutableSet.of();
310 } 301 }
311 302
303 + /**
304 + * Builds and returns metric database instance with given resource name,
305 + * resource type and metric type.
306 + *
307 + * @param resourceName resource name
308 + * @param resourceType resource type
309 + * @param metricTypes metric type
310 + * @return metric database instance
311 + */
312 private MetricsDatabase genMDbBuilder(String resourceName, 312 private MetricsDatabase genMDbBuilder(String resourceName,
313 Type resourceType, 313 Type resourceType,
314 Set<ControlMetricType> metricTypes) { 314 Set<ControlMetricType> metricTypes) {
...@@ -319,56 +319,218 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -319,56 +319,218 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
319 return builder.build(); 319 return builder.build();
320 } 320 }
321 321
322 + /**
323 + * Updates network metrics with given metric map and resource name.
324 + *
325 + * @param metricMap a metric map which is comprised of metric type and value
326 + * @param resourceName resource name
327 + */
322 private void updateNetworkMetrics(Map<ControlMetricType, Double> metricMap, 328 private void updateNetworkMetrics(Map<ControlMetricType, Double> metricMap,
323 - String resName) { 329 + String resourceName) {
324 - networkMetricsMap.putIfAbsent(resName, genMDbBuilder(resName, 330 + networkMetricsMap.putIfAbsent(resourceName, genMDbBuilder(resourceName,
325 Type.NETWORK, NETWORK_METRICS)); 331 Type.NETWORK, NETWORK_METRICS));
326 - networkMetricsMap.get(resName).updateMetrics(convertMap(metricMap)); 332 + networkMetricsMap.get(resourceName).updateMetrics(convertMap(metricMap));
327 } 333 }
328 334
335 + /**
336 + * Updates disk metrics with given metric map and resource name.
337 + *
338 + * @param metricMap a metric map which is comprised of metric type and value
339 + * @param resourceName resource name
340 + */
329 private void updateDiskMetrics(Map<ControlMetricType, Double> metricMap, 341 private void updateDiskMetrics(Map<ControlMetricType, Double> metricMap,
330 - String resName) { 342 + String resourceName) {
331 - diskMetricsMap.putIfAbsent(resName, genMDbBuilder(resName, 343 + diskMetricsMap.putIfAbsent(resourceName, genMDbBuilder(resourceName,
332 Type.DISK, DISK_METRICS)); 344 Type.DISK, DISK_METRICS));
333 - diskMetricsMap.get(resName).updateMetrics(convertMap(metricMap)); 345 + diskMetricsMap.get(resourceName).updateMetrics(convertMap(metricMap));
334 } 346 }
335 347
348 + /**
349 + * Updates control message metrics with given metric map and device identifier.
350 + *
351 + * @param metricMap a metric map which is comprised of metric type and value
352 + * @param deviceId device identifier
353 + */
336 private void updateControlMessages(Map<ControlMetricType, Double> metricMap, 354 private void updateControlMessages(Map<ControlMetricType, Double> metricMap,
337 - DeviceId devId) { 355 + DeviceId deviceId) {
338 - controlMessageMap.putIfAbsent(devId, genMDbBuilder(devId.toString(), 356 + controlMessageMap.putIfAbsent(deviceId, genMDbBuilder(deviceId.toString(),
339 Type.CONTROL_MESSAGE, CONTROL_MESSAGE_METRICS)); 357 Type.CONTROL_MESSAGE, CONTROL_MESSAGE_METRICS));
340 - controlMessageMap.get(devId).updateMetrics(convertMap(metricMap)); 358 + controlMessageMap.get(deviceId).updateMetrics(convertMap(metricMap));
341 } 359 }
342 360
343 - private Map convertMap(Map<ControlMetricType, Double> map) { 361 + /**
344 - if (map == null) { 362 + * Converts metric map into a new map which contains string formatted metric type as key.
363 + *
364 + * @param metricMap metric map in which ControlMetricType is key
365 + * @return a new map in which string formatted metric type is key
366 + */
367 + private Map<String, Double> convertMap(Map<ControlMetricType, Double> metricMap) {
368 + if (metricMap == null) {
345 return ImmutableMap.of(); 369 return ImmutableMap.of();
346 } 370 }
347 Map newMap = Maps.newConcurrentMap(); 371 Map newMap = Maps.newConcurrentMap();
348 - map.forEach((k, v) -> newMap.putIfAbsent(k.toString(), v)); 372 + metricMap.forEach((k, v) -> newMap.putIfAbsent(k.toString(), v));
349 return newMap; 373 return newMap;
350 } 374 }
351 375
352 - private CompletableFuture<ControlLoad> handleRequest(ControlMetricsRequest request) { 376 + /**
377 + * Handles control metric request from remote node.
378 + *
379 + * @param request control metric request
380 + * @return completable future object of control load snapshot
381 + */
382 + private CompletableFuture<ControlLoadSnapshot> handleRequest(ControlMetricsRequest request) {
353 383
354 checkArgument(request.getType() != null, METRIC_TYPE_NULL); 384 checkArgument(request.getType() != null, METRIC_TYPE_NULL);
355 385
356 ControlLoad load; 386 ControlLoad load;
357 - if (request.getResourceName() != null) { 387 + if (request.getResourceName() != null && request.getUnit() != null) {
358 load = getLocalLoad(request.getType(), request.getResourceName()); 388 load = getLocalLoad(request.getType(), request.getResourceName());
359 } else { 389 } else {
360 load = getLocalLoad(request.getType(), request.getDeviceId()); 390 load = getLocalLoad(request.getType(), request.getDeviceId());
361 } 391 }
362 - return CompletableFuture.completedFuture(load); 392 +
393 + long average;
394 + if (request.getUnit() != null) {
395 + average = load.average(request.getDuration(), request.getUnit());
396 + } else {
397 + average = load.average();
398 + }
399 + ControlLoadSnapshot resp =
400 + new ControlLoadSnapshot(load.latest(), average, load.time());
401 + return CompletableFuture.completedFuture(resp);
363 } 402 }
364 403
404 + /**
405 + * Generates a control metric request.
406 + *
407 + * @param type control metric type
408 + * @param deviceId device identifier
409 + * @return control metric request instance
410 + */
365 private ControlMetricsRequest createRequest(ControlMetricType type, 411 private ControlMetricsRequest createRequest(ControlMetricType type,
366 Optional<DeviceId> deviceId) { 412 Optional<DeviceId> deviceId) {
367 return new ControlMetricsRequest(type, deviceId); 413 return new ControlMetricsRequest(type, deviceId);
368 } 414 }
369 415
416 + /**
417 + * Generates a control metric request with given projected time range.
418 + *
419 + * @param type control metric type
420 + * @param duration projected time duration
421 + * @param unit projected time unit
422 + * @param deviceId device identifier
423 + * @return control metric request instance
424 + */
425 + private ControlMetricsRequest createRequest(ControlMetricType type,
426 + int duration, TimeUnit unit,
427 + Optional<DeviceId> deviceId) {
428 + return new ControlMetricsRequest(type, duration, unit, deviceId);
429 + }
430 +
431 + /**
432 + * Generates a control metric request.
433 + *
434 + * @param type control metric type
435 + * @param resourceName resource name
436 + * @return control metric request instance
437 + */
370 private ControlMetricsRequest createRequest(ControlMetricType type, 438 private ControlMetricsRequest createRequest(ControlMetricType type,
371 String resourceName) { 439 String resourceName) {
372 return new ControlMetricsRequest(type, resourceName); 440 return new ControlMetricsRequest(type, resourceName);
373 } 441 }
442 +
443 + /**
444 + * Generates a control metric request with given projected time range.
445 + *
446 + * @param type control metric type
447 + * @param duration projected time duration
448 + * @param unit projected time unit
449 + * @param resourceName resource name
450 + * @return control metric request instance
451 + */
452 + private ControlMetricsRequest createRequest(ControlMetricType type,
453 + int duration, TimeUnit unit,
454 + String resourceName) {
455 + return new ControlMetricsRequest(type, duration, unit, resourceName);
456 + }
457 +
458 + /**
459 + * Returns a snapshot of control load.
460 + *
461 + * @param cl control load
462 + * @return a snapshot of control load
463 + */
464 + private ControlLoadSnapshot snapshot(ControlLoad cl) {
465 + if (cl != null) {
466 + return new ControlLoadSnapshot(cl.latest(), cl.average(), cl.time());
467 + }
468 + return null;
469 + }
470 +
471 + /**
472 + * Returns a snapshot of control load with given projected time range.
473 + *
474 + * @param cl control load
475 + * @param duration projected time duration
476 + * @param unit projected time unit
477 + * @return a snapshot of control load
478 + */
479 + private ControlLoadSnapshot snapshot(ControlLoad cl, int duration, TimeUnit unit) {
480 + if (cl != null) {
481 + return new ControlLoadSnapshot(cl.latest(), cl.average(duration, unit), cl.time());
482 + }
483 + return null;
484 + }
485 +
486 + /**
487 + * Returns local control load.
488 + *
489 + * @param type metric type
490 + * @param deviceId device identifier
491 + * @return control load
492 + */
493 + private ControlLoad getLocalLoad(ControlMetricType type,
494 + Optional<DeviceId> deviceId) {
495 + if (deviceId.isPresent()) {
496 + // returns control message stats
497 + if (CONTROL_MESSAGE_METRICS.contains(type) &&
498 + availableDeviceIdSet.contains(deviceId.get())) {
499 + return new DefaultControlLoad(controlMessageMap.get(deviceId.get()), type);
500 + }
501 + } else {
502 + // returns controlLoad of CPU metrics
503 + if (CPU_METRICS.contains(type)) {
504 + return new DefaultControlLoad(cpuMetrics, type);
505 + }
506 +
507 + // returns memoryLoad of memory metrics
508 + if (MEMORY_METRICS.contains(type)) {
509 + return new DefaultControlLoad(memoryMetrics, type);
510 + }
511 + }
512 + return null;
513 + }
514 +
515 + /**
516 + * Returns local control load.
517 + *
518 + * @param type metric type
519 + * @param resourceName resource name
520 + * @return control load
521 + */
522 + private ControlLoad getLocalLoad(ControlMetricType type, String resourceName) {
523 + // returns disk I/O stats
524 + if (DISK_METRICS.contains(type) &&
525 + availableResources(Type.DISK).contains(resourceName)) {
526 + return new DefaultControlLoad(diskMetricsMap.get(resourceName), type);
527 + }
528 +
529 + // returns network I/O stats
530 + if (NETWORK_METRICS.contains(type) &&
531 + availableResources(Type.NETWORK).contains(resourceName)) {
532 + return new DefaultControlLoad(networkMetricsMap.get(resourceName), type);
533 + }
534 + return null;
535 + }
374 } 536 }
......
...@@ -21,8 +21,8 @@ import org.apache.felix.scr.annotations.Deactivate; ...@@ -21,8 +21,8 @@ import org.apache.felix.scr.annotations.Deactivate;
21 import org.apache.felix.scr.annotations.Reference; 21 import org.apache.felix.scr.annotations.Reference;
22 import org.apache.felix.scr.annotations.ReferenceCardinality; 22 import org.apache.felix.scr.annotations.ReferenceCardinality;
23 import org.onosproject.codec.CodecService; 23 import org.onosproject.codec.CodecService;
24 -import org.onosproject.cpman.ControlLoad; 24 +import org.onosproject.cpman.ControlLoadSnapshot;
25 -import org.onosproject.cpman.codec.ControlLoadCodec; 25 +import org.onosproject.cpman.codec.ControlLoadSnapshotCodec;
26 import org.slf4j.Logger; 26 import org.slf4j.Logger;
27 27
28 import static org.slf4j.LoggerFactory.getLogger; 28 import static org.slf4j.LoggerFactory.getLogger;
...@@ -40,14 +40,14 @@ public class CPManCodecRegistrator { ...@@ -40,14 +40,14 @@ public class CPManCodecRegistrator {
40 40
41 @Activate 41 @Activate
42 public void activate() { 42 public void activate() {
43 - codecService.registerCodec(ControlLoad.class, new ControlLoadCodec()); 43 + codecService.registerCodec(ControlLoadSnapshot.class, new ControlLoadSnapshotCodec());
44 44
45 log.info("Started"); 45 log.info("Started");
46 } 46 }
47 47
48 @Deactivate 48 @Deactivate
49 public void deactivate() { 49 public void deactivate() {
50 - codecService.unregisterCodec(ControlLoad.class); 50 + codecService.unregisterCodec(ControlLoadSnapshot.class);
51 51
52 log.info("Stopped"); 52 log.info("Stopped");
53 } 53 }
......
...@@ -18,9 +18,10 @@ package org.onosproject.cpman.rest; ...@@ -18,9 +18,10 @@ package org.onosproject.cpman.rest;
18 import com.fasterxml.jackson.databind.node.ArrayNode; 18 import com.fasterxml.jackson.databind.node.ArrayNode;
19 import com.fasterxml.jackson.databind.node.ObjectNode; 19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
21 +import org.onlab.util.Tools;
21 import org.onosproject.cluster.ClusterService; 22 import org.onosproject.cluster.ClusterService;
22 import org.onosproject.cluster.NodeId; 23 import org.onosproject.cluster.NodeId;
23 -import org.onosproject.cpman.ControlLoad; 24 +import org.onosproject.cpman.ControlLoadSnapshot;
24 import org.onosproject.cpman.ControlMetricType; 25 import org.onosproject.cpman.ControlMetricType;
25 import org.onosproject.cpman.ControlPlaneMonitorService; 26 import org.onosproject.cpman.ControlPlaneMonitorService;
26 import org.onosproject.net.DeviceId; 27 import org.onosproject.net.DeviceId;
...@@ -34,6 +35,8 @@ import javax.ws.rs.core.MediaType; ...@@ -34,6 +35,8 @@ import javax.ws.rs.core.MediaType;
34 import javax.ws.rs.core.Response; 35 import javax.ws.rs.core.Response;
35 import java.util.Optional; 36 import java.util.Optional;
36 import java.util.Set; 37 import java.util.Set;
38 +import java.util.concurrent.CompletableFuture;
39 +import java.util.concurrent.TimeUnit;
37 40
38 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS; 41 import static org.onosproject.cpman.ControlResource.CONTROL_MESSAGE_METRICS;
39 import static org.onosproject.cpman.ControlResource.CPU_METRICS; 42 import static org.onosproject.cpman.ControlResource.CPU_METRICS;
...@@ -55,6 +58,7 @@ public class ControlMetricsWebResource extends AbstractWebResource { ...@@ -55,6 +58,7 @@ public class ControlMetricsWebResource extends AbstractWebResource {
55 private final ClusterService clusterService = get(ClusterService.class); 58 private final ClusterService clusterService = get(ClusterService.class);
56 private final NodeId localNodeId = clusterService.getLocalNode().id(); 59 private final NodeId localNodeId = clusterService.getLocalNode().id();
57 private final ObjectNode root = mapper().createObjectNode(); 60 private final ObjectNode root = mapper().createObjectNode();
61 + private static final long TIMEOUT_MILLIS = 1000;
58 62
59 /** 63 /**
60 * Returns control message metrics of all devices. 64 * Returns control message metrics of all devices.
...@@ -248,31 +252,51 @@ public class ControlMetricsWebResource extends AbstractWebResource { ...@@ -248,31 +252,51 @@ public class ControlMetricsWebResource extends AbstractWebResource {
248 if (name == null && did == null) { 252 if (name == null && did == null) {
249 typeSet.forEach(type -> { 253 typeSet.forEach(type -> {
250 ObjectNode metricNode = mapper().createObjectNode(); 254 ObjectNode metricNode = mapper().createObjectNode();
251 - ControlLoad load = service.getLocalLoad(type, Optional.ofNullable(null)); 255 + CompletableFuture<ControlLoadSnapshot> cf =
252 - if (load != null) { 256 + service.getLoad(nodeId, type, Optional.empty());
253 - metricNode.set(toCamelCase(type.toString(), true), codec(ControlLoad.class) 257 +
254 - .encode(service.getLocalLoad(type, Optional.ofNullable(null)), this)); 258 + if (cf != null) {
255 - metricsNode.add(metricNode); 259 + ControlLoadSnapshot cmr =
260 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
261 +
262 + if (cmr != null) {
263 + metricNode.set(toCamelCase(type.toString(), true),
264 + codec(ControlLoadSnapshot.class).encode(cmr, this));
265 + metricsNode.add(metricNode);
266 + }
256 } 267 }
257 }); 268 });
258 } else if (name == null) { 269 } else if (name == null) {
259 typeSet.forEach(type -> { 270 typeSet.forEach(type -> {
260 ObjectNode metricNode = mapper().createObjectNode(); 271 ObjectNode metricNode = mapper().createObjectNode();
261 - ControlLoad load = service.getLocalLoad(type, Optional.of(did)); 272 + CompletableFuture<ControlLoadSnapshot> cf =
262 - if (load != null) { 273 + service.getLoad(nodeId, type, Optional.of(did));
263 - metricNode.set(toCamelCase(type.toString(), true), 274 +
264 - codec(ControlLoad.class).encode(load, this)); 275 + if (cf != null) {
265 - metricsNode.add(metricNode); 276 + ControlLoadSnapshot cmr =
277 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
278 + if (cmr != null) {
279 + metricNode.set(toCamelCase(type.toString(), true),
280 + codec(ControlLoadSnapshot.class).encode(cmr, this));
281 + metricsNode.add(metricNode);
282 + }
266 } 283 }
284 +
267 }); 285 });
268 } else if (did == null) { 286 } else if (did == null) {
269 typeSet.forEach(type -> { 287 typeSet.forEach(type -> {
270 ObjectNode metricNode = mapper().createObjectNode(); 288 ObjectNode metricNode = mapper().createObjectNode();
271 - ControlLoad load = service.getLocalLoad(type, name); 289 + CompletableFuture<ControlLoadSnapshot> cf =
272 - if (load != null) { 290 + service.getLoad(nodeId, type, name);
273 - metricNode.set(toCamelCase(type.toString(), true), 291 +
274 - codec(ControlLoad.class).encode(load, this)); 292 + if (cf != null) {
275 - metricsNode.add(metricNode); 293 + ControlLoadSnapshot cmr =
294 + Tools.futureGetOrElse(cf, TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null);
295 + if (cmr != null) {
296 + metricNode.set(toCamelCase(type.toString(), true),
297 + codec(ControlLoadSnapshot.class).encode(cmr, this));
298 + metricsNode.add(metricNode);
299 + }
276 } 300 }
277 }); 301 });
278 } 302 }
......
...@@ -106,31 +106,31 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -106,31 +106,31 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
106 long cpuIdleTime = nullIsIllegal(jsonTree.get("cpuIdleTime").asLong(), INVALID_REQUEST); 106 long cpuIdleTime = nullIsIllegal(jsonTree.get("cpuIdleTime").asLong(), INVALID_REQUEST);
107 107
108 aggregator.setMetricsService(metricsService); 108 aggregator.setMetricsService(metricsService);
109 - aggregator.addMetrics(Optional.ofNullable(null), SYSTEM_TYPE); 109 + aggregator.addMetrics(Optional.empty(), SYSTEM_TYPE);
110 110
111 cm = new ControlMetric(ControlMetricType.CPU_LOAD, 111 cm = new ControlMetric(ControlMetricType.CPU_LOAD,
112 new MetricValue.Builder().load(cpuLoad).add()); 112 new MetricValue.Builder().load(cpuLoad).add());
113 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 113 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
114 aggregator.increment(ControlMetricType.CPU_LOAD, cpuLoad); 114 aggregator.increment(ControlMetricType.CPU_LOAD, cpuLoad);
115 115
116 cm = new ControlMetric(ControlMetricType.TOTAL_CPU_TIME, 116 cm = new ControlMetric(ControlMetricType.TOTAL_CPU_TIME,
117 new MetricValue.Builder().load(totalCpuTime).add()); 117 new MetricValue.Builder().load(totalCpuTime).add());
118 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 118 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
119 aggregator.increment(ControlMetricType.TOTAL_CPU_TIME, totalCpuTime); 119 aggregator.increment(ControlMetricType.TOTAL_CPU_TIME, totalCpuTime);
120 120
121 cm = new ControlMetric(ControlMetricType.SYS_CPU_TIME, 121 cm = new ControlMetric(ControlMetricType.SYS_CPU_TIME,
122 new MetricValue.Builder().load(sysCpuTime).add()); 122 new MetricValue.Builder().load(sysCpuTime).add());
123 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 123 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
124 aggregator.increment(ControlMetricType.SYS_CPU_TIME, sysCpuTime); 124 aggregator.increment(ControlMetricType.SYS_CPU_TIME, sysCpuTime);
125 125
126 cm = new ControlMetric(ControlMetricType.USER_CPU_TIME, 126 cm = new ControlMetric(ControlMetricType.USER_CPU_TIME,
127 new MetricValue.Builder().load(userCpuTime).add()); 127 new MetricValue.Builder().load(userCpuTime).add());
128 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 128 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
129 aggregator.increment(ControlMetricType.USER_CPU_TIME, userCpuTime); 129 aggregator.increment(ControlMetricType.USER_CPU_TIME, userCpuTime);
130 130
131 cm = new ControlMetric(ControlMetricType.CPU_IDLE_TIME, 131 cm = new ControlMetric(ControlMetricType.CPU_IDLE_TIME,
132 new MetricValue.Builder().load(cpuIdleTime).add()); 132 new MetricValue.Builder().load(cpuIdleTime).add());
133 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 133 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
134 aggregator.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime); 134 aggregator.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime);
135 135
136 } catch (IOException e) { 136 } catch (IOException e) {
...@@ -167,26 +167,26 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -167,26 +167,26 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
167 long memFreeRatio = memTotal == 0L ? 0L : (memFree * PERCENT_CONSTANT) / memTotal; 167 long memFreeRatio = memTotal == 0L ? 0L : (memFree * PERCENT_CONSTANT) / memTotal;
168 168
169 aggregator.setMetricsService(metricsService); 169 aggregator.setMetricsService(metricsService);
170 - aggregator.addMetrics(Optional.ofNullable(null), SYSTEM_TYPE); 170 + aggregator.addMetrics(Optional.empty(), SYSTEM_TYPE);
171 171
172 cm = new ControlMetric(ControlMetricType.MEMORY_USED_RATIO, 172 cm = new ControlMetric(ControlMetricType.MEMORY_USED_RATIO,
173 new MetricValue.Builder().load(memUsedRatio).add()); 173 new MetricValue.Builder().load(memUsedRatio).add());
174 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 174 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
175 aggregator.increment(ControlMetricType.MEMORY_USED_RATIO, memUsedRatio); 175 aggregator.increment(ControlMetricType.MEMORY_USED_RATIO, memUsedRatio);
176 176
177 cm = new ControlMetric(ControlMetricType.MEMORY_FREE_RATIO, 177 cm = new ControlMetric(ControlMetricType.MEMORY_FREE_RATIO,
178 new MetricValue.Builder().load(memFreeRatio).add()); 178 new MetricValue.Builder().load(memFreeRatio).add());
179 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 179 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
180 aggregator.increment(ControlMetricType.MEMORY_FREE_RATIO, memFreeRatio); 180 aggregator.increment(ControlMetricType.MEMORY_FREE_RATIO, memFreeRatio);
181 181
182 cm = new ControlMetric(ControlMetricType.MEMORY_USED, 182 cm = new ControlMetric(ControlMetricType.MEMORY_USED,
183 new MetricValue.Builder().load(memUsed).add()); 183 new MetricValue.Builder().load(memUsed).add());
184 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 184 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
185 aggregator.increment(ControlMetricType.MEMORY_USED, memUsed); 185 aggregator.increment(ControlMetricType.MEMORY_USED, memUsed);
186 186
187 cm = new ControlMetric(ControlMetricType.MEMORY_FREE, 187 cm = new ControlMetric(ControlMetricType.MEMORY_FREE,
188 new MetricValue.Builder().load(memFree).add()); 188 new MetricValue.Builder().load(memFree).add());
189 - monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 189 + monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.empty());
190 aggregator.increment(ControlMetricType.MEMORY_FREE, memFree); 190 aggregator.increment(ControlMetricType.MEMORY_FREE, memFree);
191 191
192 } catch (IOException e) { 192 } catch (IOException e) {
......
...@@ -19,12 +19,14 @@ ...@@ -19,12 +19,14 @@
19 <command> 19 <command>
20 <action class="org.onosproject.cpman.cli.ControlMetricsStatsListCommand"/> 20 <action class="org.onosproject.cpman.cli.ControlMetricsStatsListCommand"/>
21 <completers> 21 <completers>
22 + <ref component-id="nodeIdCompleter"/>
22 <ref component-id="controlResourceTypeCompleter"/> 23 <ref component-id="controlResourceTypeCompleter"/>
23 <ref component-id="resourceNameCompleter"/> 24 <ref component-id="resourceNameCompleter"/>
24 </completers> 25 </completers>
25 </command> 26 </command>
26 </command-bundle> 27 </command-bundle>
27 28
29 + <bean id="nodeIdCompleter" class="org.onosproject.cli.NodeIdCompleter"/>
28 <bean id="controlResourceTypeCompleter" class="org.onosproject.cpman.cli.ControlResourceTypeCompleter"/> 30 <bean id="controlResourceTypeCompleter" class="org.onosproject.cpman.cli.ControlResourceTypeCompleter"/>
29 <bean id="resourceNameCompleter" class="org.onosproject.cpman.cli.ResourceNameCompleter"/> 31 <bean id="resourceNameCompleter" class="org.onosproject.cpman.cli.ResourceNameCompleter"/>
30 </blueprint> 32 </blueprint>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -31,6 +31,7 @@ import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapte ...@@ -31,6 +31,7 @@ import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapte
31 31
32 import java.util.Optional; 32 import java.util.Optional;
33 import java.util.Set; 33 import java.util.Set;
34 +import java.util.concurrent.ExecutionException;
34 35
35 import static org.easymock.EasyMock.anyObject; 36 import static org.easymock.EasyMock.anyObject;
36 import static org.easymock.EasyMock.createMock; 37 import static org.easymock.EasyMock.createMock;
...@@ -109,11 +110,17 @@ public class ControlPlaneMonitorTest { ...@@ -109,11 +110,17 @@ public class ControlPlaneMonitorTest {
109 110
110 private void testUpdateMetricWithoutId(ControlMetricType cmt, MetricValue mv) { 111 private void testUpdateMetricWithoutId(ControlMetricType cmt, MetricValue mv) {
111 ControlMetric cm = new ControlMetric(cmt, mv); 112 ControlMetric cm = new ControlMetric(cmt, mv);
112 - monitor.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null)); 113 + monitor.updateMetric(cm, UPDATE_INTERVAL, Optional.empty());
113 } 114 }
114 115
115 - private void testLoadMetricWithoutId(ControlMetricType cmt, MetricValue mv) { 116 + private void testLoadMetric(NodeId nodeId, ControlMetricType cmt, MetricValue mv) {
116 - assertThat(monitor.getLocalLoad(cmt, Optional.ofNullable(null)).latest(), is(mv.getLoad())); 117 + try {
118 + assertThat(monitor.getLoad(nodeId, cmt, Optional.empty()).get().latest(), is(mv.getLoad()));
119 + } catch (InterruptedException e) {
120 + e.printStackTrace();
121 + } catch (ExecutionException e) {
122 + e.printStackTrace();
123 + }
117 } 124 }
118 125
119 private void testUpdateMetricWithResource(ControlMetricType cmt, MetricValue mv, String resourceName) { 126 private void testUpdateMetricWithResource(ControlMetricType cmt, MetricValue mv, String resourceName) {
...@@ -121,8 +128,14 @@ public class ControlPlaneMonitorTest { ...@@ -121,8 +128,14 @@ public class ControlPlaneMonitorTest {
121 monitor.updateMetric(cm, UPDATE_INTERVAL, resourceName); 128 monitor.updateMetric(cm, UPDATE_INTERVAL, resourceName);
122 } 129 }
123 130
124 - private void testLoadMetricWithResource(ControlMetricType cmt, MetricValue mv, String resourceName) { 131 + private void testLoadMetricWithResource(NodeId nodeId, ControlMetricType cmt, MetricValue mv, String resourceName) {
125 - assertThat(monitor.getLocalLoad(cmt, resourceName).latest(), is(mv.getLoad())); 132 + try {
133 + assertThat(monitor.getLoad(nodeId, cmt, resourceName).get().latest(), is(mv.getLoad()));
134 + } catch (InterruptedException e) {
135 + e.printStackTrace();
136 + } catch (ExecutionException e) {
137 + e.printStackTrace();
138 + }
126 } 139 }
127 140
128 private void testUpdateMetricWithId(ControlMetricType cmt, MetricValue mv, DeviceId did) { 141 private void testUpdateMetricWithId(ControlMetricType cmt, MetricValue mv, DeviceId did) {
...@@ -130,8 +143,14 @@ public class ControlPlaneMonitorTest { ...@@ -130,8 +143,14 @@ public class ControlPlaneMonitorTest {
130 monitor.updateMetric(cm, UPDATE_INTERVAL, Optional.of(did)); 143 monitor.updateMetric(cm, UPDATE_INTERVAL, Optional.of(did));
131 } 144 }
132 145
133 - private void testLoadMetricWithId(ControlMetricType cmt, MetricValue mv, DeviceId did) { 146 + private void testLoadMetricWithId(NodeId nodeId, ControlMetricType cmt, MetricValue mv, DeviceId did) {
134 - assertThat(monitor.getLocalLoad(cmt, Optional.of(did)).latest(), is(mv.getLoad())); 147 + try {
148 + assertThat(monitor.getLoad(nodeId, cmt, Optional.of(did)).get().latest(), is(mv.getLoad()));
149 + } catch (InterruptedException e) {
150 + e.printStackTrace();
151 + } catch (ExecutionException e) {
152 + e.printStackTrace();
153 + }
135 } 154 }
136 155
137 /** 156 /**
...@@ -142,7 +161,7 @@ public class ControlPlaneMonitorTest { ...@@ -142,7 +161,7 @@ public class ControlPlaneMonitorTest {
142 MetricValue mv = new MetricValue.Builder().load(30).add(); 161 MetricValue mv = new MetricValue.Builder().load(30).add();
143 162
144 CPU_METRICS.forEach(cmt -> testUpdateMetricWithoutId(cmt, mv)); 163 CPU_METRICS.forEach(cmt -> testUpdateMetricWithoutId(cmt, mv));
145 - CPU_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); 164 + CPU_METRICS.forEach(cmt -> testLoadMetric(nodeId, cmt, mv));
146 } 165 }
147 166
148 /** 167 /**
...@@ -153,7 +172,7 @@ public class ControlPlaneMonitorTest { ...@@ -153,7 +172,7 @@ public class ControlPlaneMonitorTest {
153 MetricValue mv = new MetricValue.Builder().load(40).add(); 172 MetricValue mv = new MetricValue.Builder().load(40).add();
154 173
155 MEMORY_METRICS.forEach(cmt -> testUpdateMetricWithoutId(cmt, mv)); 174 MEMORY_METRICS.forEach(cmt -> testUpdateMetricWithoutId(cmt, mv));
156 - MEMORY_METRICS.forEach(cmt -> testLoadMetricWithoutId(cmt, mv)); 175 + MEMORY_METRICS.forEach(cmt -> testLoadMetric(nodeId, cmt, mv));
157 } 176 }
158 177
159 /** 178 /**
...@@ -169,7 +188,7 @@ public class ControlPlaneMonitorTest { ...@@ -169,7 +188,7 @@ public class ControlPlaneMonitorTest {
169 testUpdateMetricWithResource(cmt, mv, disk))); 188 testUpdateMetricWithResource(cmt, mv, disk)));
170 189
171 set.forEach(disk -> DISK_METRICS.forEach(cmt -> 190 set.forEach(disk -> DISK_METRICS.forEach(cmt ->
172 - testLoadMetricWithResource(cmt, mv, disk))); 191 + testLoadMetricWithResource(nodeId, cmt, mv, disk)));
173 } 192 }
174 193
175 /** 194 /**
...@@ -185,7 +204,7 @@ public class ControlPlaneMonitorTest { ...@@ -185,7 +204,7 @@ public class ControlPlaneMonitorTest {
185 testUpdateMetricWithResource(cmt, mv, network))); 204 testUpdateMetricWithResource(cmt, mv, network)));
186 205
187 set.forEach(network -> NETWORK_METRICS.forEach(cmt -> 206 set.forEach(network -> NETWORK_METRICS.forEach(cmt ->
188 - testLoadMetricWithResource(cmt, mv, network))); 207 + testLoadMetricWithResource(nodeId, cmt, mv, network)));
189 } 208 }
190 209
191 /** 210 /**
...@@ -201,7 +220,7 @@ public class ControlPlaneMonitorTest { ...@@ -201,7 +220,7 @@ public class ControlPlaneMonitorTest {
201 testUpdateMetricWithId(cmt, mv, devId))); 220 testUpdateMetricWithId(cmt, mv, devId)));
202 221
203 set.forEach(devId -> CONTROL_MESSAGE_METRICS.forEach(cmt -> 222 set.forEach(devId -> CONTROL_MESSAGE_METRICS.forEach(cmt ->
204 - testLoadMetricWithId(cmt, mv, devId))); 223 + testLoadMetricWithId(nodeId, cmt, mv, devId)));
205 } 224 }
206 225
207 /** 226 /**
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
16 package org.onosproject.cpman.impl.message; 16 package org.onosproject.cpman.impl.message;
17 17
18 import org.onosproject.cluster.NodeId; 18 import org.onosproject.cluster.NodeId;
19 -import org.onosproject.cpman.ControlLoad; 19 +import org.onosproject.cpman.ControlLoadSnapshot;
20 import org.onosproject.cpman.ControlMetric; 20 import org.onosproject.cpman.ControlMetric;
21 import org.onosproject.cpman.ControlMetricType; 21 import org.onosproject.cpman.ControlMetricType;
22 import org.onosproject.cpman.ControlPlaneMonitorService; 22 import org.onosproject.cpman.ControlPlaneMonitorService;
...@@ -26,6 +26,7 @@ import org.onosproject.net.DeviceId; ...@@ -26,6 +26,7 @@ import org.onosproject.net.DeviceId;
26 import java.util.Optional; 26 import java.util.Optional;
27 import java.util.Set; 27 import java.util.Set;
28 import java.util.concurrent.CompletableFuture; 28 import java.util.concurrent.CompletableFuture;
29 +import java.util.concurrent.TimeUnit;
29 30
30 /** 31 /**
31 * Test adapter control plane monitoring service. 32 * Test adapter control plane monitoring service.
...@@ -44,27 +45,32 @@ public class ControlPlaneMonitorServiceAdaptor implements ControlPlaneMonitorSer ...@@ -44,27 +45,32 @@ public class ControlPlaneMonitorServiceAdaptor implements ControlPlaneMonitorSer
44 } 45 }
45 46
46 @Override 47 @Override
47 - public ControlLoad getLocalLoad(ControlMetricType type, 48 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
48 - Optional<DeviceId> deviceId) { 49 + ControlMetricType type,
50 + Optional<DeviceId> deviceId) {
49 return null; 51 return null;
50 } 52 }
51 53
52 @Override 54 @Override
53 - public ControlLoad getLocalLoad(ControlMetricType type, String resourceName) { 55 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
56 + ControlMetricType type,
57 + String resourceName) {
54 return null; 58 return null;
55 } 59 }
56 60
57 @Override 61 @Override
58 - public CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 62 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
59 - ControlMetricType type, 63 + ControlMetricType type,
60 - Optional<DeviceId> deviceId) { 64 + int duration, TimeUnit unit,
65 + Optional<DeviceId> deviceId) {
61 return null; 66 return null;
62 } 67 }
63 68
64 @Override 69 @Override
65 - public CompletableFuture<ControlLoad> getRemoteLoad(NodeId nodeId, 70 + public CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
66 - ControlMetricType type, 71 + ControlMetricType type,
67 - String resourceName) { 72 + int duration, TimeUnit unit,
73 + String resourceName) {
68 return null; 74 return null;
69 } 75 }
70 76
......
...@@ -15,11 +15,7 @@ ...@@ -15,11 +15,7 @@
15 */ 15 */
16 package org.onosproject.cpman.rest; 16 package org.onosproject.cpman.rest;
17 17
18 -import java.util.Set; 18 +import com.google.common.collect.ImmutableSet;
19 -import java.util.concurrent.TimeUnit;
20 -
21 -import javax.ws.rs.client.WebTarget;
22 -
23 import org.glassfish.jersey.server.ResourceConfig; 19 import org.glassfish.jersey.server.ResourceConfig;
24 import org.junit.Before; 20 import org.junit.Before;
25 import org.junit.Test; 21 import org.junit.Test;
...@@ -33,11 +29,14 @@ import org.onosproject.cluster.NodeId; ...@@ -33,11 +29,14 @@ import org.onosproject.cluster.NodeId;
33 import org.onosproject.codec.CodecService; 29 import org.onosproject.codec.CodecService;
34 import org.onosproject.codec.impl.CodecManager; 30 import org.onosproject.codec.impl.CodecManager;
35 import org.onosproject.cpman.ControlLoad; 31 import org.onosproject.cpman.ControlLoad;
32 +import org.onosproject.cpman.ControlLoadSnapshot;
36 import org.onosproject.cpman.ControlPlaneMonitorService; 33 import org.onosproject.cpman.ControlPlaneMonitorService;
37 -import org.onosproject.cpman.codec.ControlLoadCodec; 34 +import org.onosproject.cpman.codec.ControlLoadSnapshotCodec;
38 import org.onosproject.rest.resources.ResourceTest; 35 import org.onosproject.rest.resources.ResourceTest;
39 36
40 -import com.google.common.collect.ImmutableSet; 37 +import javax.ws.rs.client.WebTarget;
38 +import java.util.Set;
39 +import java.util.concurrent.TimeUnit;
41 40
42 import static org.easymock.EasyMock.anyObject; 41 import static org.easymock.EasyMock.anyObject;
43 import static org.easymock.EasyMock.anyString; 42 import static org.easymock.EasyMock.anyString;
...@@ -145,7 +144,7 @@ public class ControlMetricsResourceTest extends ResourceTest { ...@@ -145,7 +144,7 @@ public class ControlMetricsResourceTest extends ResourceTest {
145 public void setUpTest() { 144 public void setUpTest() {
146 final CodecManager codecService = new CodecManager(); 145 final CodecManager codecService = new CodecManager();
147 codecService.activate(); 146 codecService.activate();
148 - codecService.registerCodec(ControlLoad.class, new ControlLoadCodec()); 147 + codecService.registerCodec(ControlLoadSnapshot.class, new ControlLoadSnapshotCodec());
149 ServiceDirectory testDirectory = 148 ServiceDirectory testDirectory =
150 new TestServiceDirectory() 149 new TestServiceDirectory()
151 .add(ControlPlaneMonitorService.class, 150 .add(ControlPlaneMonitorService.class,
...@@ -184,7 +183,7 @@ public class ControlMetricsResourceTest extends ResourceTest { ...@@ -184,7 +183,7 @@ public class ControlMetricsResourceTest extends ResourceTest {
184 public void testResourcePopulatedArray() { 183 public void testResourcePopulatedArray() {
185 expect(mockControlPlaneMonitorService.availableResources(anyObject())) 184 expect(mockControlPlaneMonitorService.availableResources(anyObject()))
186 .andReturn(resourceSet).once(); 185 .andReturn(resourceSet).once();
187 - expect(mockControlPlaneMonitorService.getLocalLoad(anyObject(), 186 + expect(mockControlPlaneMonitorService.getLoad(anyObject(), anyObject(),
188 anyString())).andReturn(null).times(4); 187 anyString())).andReturn(null).times(4);
189 replay(mockControlPlaneMonitorService); 188 replay(mockControlPlaneMonitorService);
190 189
......