Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 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 | |
Jian Li | 89eeccd | 2016-05-06 02:10:33 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import org.onlab.util.Tools; |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 20 | import org.onosproject.cluster.NodeId; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import java.util.Optional; |
Jian Li | 85060ac | 2016-02-04 09:58:56 -0800 | [diff] [blame] | 24 | import java.util.Set; |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 25 | import java.util.concurrent.CompletableFuture; |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 26 | import java.util.concurrent.TimeUnit; |
Jian Li | 85060ac | 2016-02-04 09:58:56 -0800 | [diff] [blame] | 27 | |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 28 | import static org.onosproject.cpman.ControlResource.Type; |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Control Plane Statistics Service Interface. |
| 32 | */ |
Jian Li | 6080432 | 2015-12-02 14:46:31 -0800 | [diff] [blame] | 33 | public interface ControlPlaneMonitorService { |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 34 | |
Jian Li | 89eeccd | 2016-05-06 02:10:33 -0700 | [diff] [blame] | 35 | long TIMEOUT_MILLIS = 2000; |
| 36 | |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 37 | /** |
Jian Li | 6080432 | 2015-12-02 14:46:31 -0800 | [diff] [blame] | 38 | * Adds a new control metric value with a certain update interval. |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 39 | * |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 40 | * @param controlMetric control plane metric (e.g., control |
| 41 | * message rate, cpu, memory, etc.) |
| 42 | * @param updateIntervalInMinutes value update interval (in minute) |
| 43 | * @param deviceId device identifier |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 44 | */ |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 45 | void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes, |
| 46 | Optional<DeviceId> deviceId); |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
Jian Li | e044d1a | 2016-01-25 09:01:20 -0800 | [diff] [blame] | 49 | * Adds a new control metric value with a certain update interval. |
| 50 | * |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 51 | * @param controlMetric control plane metric (e.g., disk and |
| 52 | * network metrics) |
| 53 | * @param updateIntervalInMinutes value update interval (in minute) |
| 54 | * @param resourceName resource name |
Jian Li | e044d1a | 2016-01-25 09:01:20 -0800 | [diff] [blame] | 55 | */ |
Jian Li | c5cb4a1 | 2016-02-03 23:24:42 -0800 | [diff] [blame] | 56 | void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes, |
| 57 | String resourceName); |
Jian Li | e044d1a | 2016-01-25 09:01:20 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 60 | * Obtains snapshot of control plane load of a specific device. |
Jian Li | 7d180c5 | 2016-02-01 21:53:08 -0800 | [diff] [blame] | 61 | * The metrics range from control messages and system metrics |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 62 | * (e.g., CPU and memory info). |
| 63 | * If the device id is not specified, it returns system metrics, otherwise, |
| 64 | * it returns control message stats of the given device. |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 65 | * |
| 66 | * @param nodeId node identifier |
| 67 | * @param type control metric type |
| 68 | * @param deviceId device identifier |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 69 | * @return completable future object of control load snapshot |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 70 | */ |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 71 | CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId, |
| 72 | ControlMetricType type, |
| 73 | Optional<DeviceId> deviceId); |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
Jian Li | f248aa2 | 2016-05-09 10:33:02 -0700 | [diff] [blame] | 76 | * Synchronous version of getLoad. |
| 77 | * Obtains snapshot of control plane load of a specific device. |
| 78 | * The metrics range from control messages and system metrics |
| 79 | * (e.g., CPU and memory info). |
| 80 | * If the device id is not specified, it returns system metrics, otherwise, |
| 81 | * it returns control message stats of the given device. |
| 82 | * |
| 83 | * @param nodeId node identifier |
| 84 | * @param type control metric type |
| 85 | * @param deviceId device identifier |
| 86 | * @return control load snapshot |
| 87 | */ |
| 88 | default ControlLoadSnapshot getLoadSync(NodeId nodeId, |
| 89 | ControlMetricType type, |
| 90 | Optional<DeviceId> deviceId) { |
| 91 | return Tools.futureGetOrElse(getLoad(nodeId, type, deviceId), |
| 92 | TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null); |
| 93 | } |
| 94 | |
| 95 | /** |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 96 | * Obtains snapshot of control plane load of a specific resource. |
| 97 | * The metrics include I/O device metrics (e.g., disk and network metrics). |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 98 | * |
| 99 | * @param nodeId node identifier |
| 100 | * @param type control metric type |
| 101 | * @param resourceName resource name |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 102 | * @return completable future object of control load snapshot |
Jian Li | 23906cc | 2016-03-31 11:16:44 -0700 | [diff] [blame] | 103 | */ |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 104 | CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId, |
| 105 | ControlMetricType type, |
| 106 | String resourceName); |
| 107 | |
| 108 | /** |
Jian Li | f248aa2 | 2016-05-09 10:33:02 -0700 | [diff] [blame] | 109 | * Synchronous version of getLoad. |
| 110 | * Obtains snapshot of control plane load of a specific resource. |
| 111 | * The metrics include I/O device metrics (e.g., disk and network metrics). |
| 112 | * |
| 113 | * @param nodeId node identifier |
| 114 | * @param type control metric type |
| 115 | * @param resourceName resource name |
| 116 | * @return control load snapshot |
| 117 | */ |
| 118 | default ControlLoadSnapshot getLoadSync(NodeId nodeId, |
| 119 | ControlMetricType type, |
| 120 | String resourceName) { |
| 121 | return Tools.futureGetOrElse(getLoad(nodeId, type, resourceName), |
| 122 | TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null); |
| 123 | } |
| 124 | |
| 125 | /** |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 126 | * Obtains snapshot of control plane load of a specific device with the |
| 127 | * projected range. |
| 128 | * |
| 129 | * @param nodeId node identifier |
| 130 | * @param type control metric type |
| 131 | * @param duration projected duration |
| 132 | * @param unit projected time unit |
| 133 | * @param deviceId device identifier |
| 134 | * @return completable future object of control load snapshot |
| 135 | */ |
| 136 | CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId, |
| 137 | ControlMetricType type, |
| 138 | int duration, TimeUnit unit, |
| 139 | Optional<DeviceId> deviceId); |
| 140 | |
| 141 | /** |
Jian Li | f248aa2 | 2016-05-09 10:33:02 -0700 | [diff] [blame] | 142 | * Synchronous version of getLoad. |
| 143 | * Obtains snapshot of control plane load of a specific device with the |
| 144 | * projected range. |
| 145 | * |
| 146 | * @param nodeId node identifier |
| 147 | * @param type control metric type |
| 148 | * @param duration projected duration |
| 149 | * @param unit projected time unit |
| 150 | * @param deviceId device identifier |
| 151 | * @return control load snapshot |
| 152 | */ |
| 153 | default ControlLoadSnapshot getLoadSync(NodeId nodeId, |
| 154 | ControlMetricType type, |
| 155 | int duration, TimeUnit unit, |
| 156 | Optional<DeviceId> deviceId) { |
| 157 | return Tools.futureGetOrElse(getLoad(nodeId, type, duration, unit, deviceId), |
| 158 | TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null); |
| 159 | } |
| 160 | |
| 161 | /** |
Jian Li | 67e1e15 | 2016-04-18 17:52:58 -0700 | [diff] [blame] | 162 | * Obtains snapshot of control plane load of a specific resource with the |
| 163 | * projected range. |
| 164 | * |
| 165 | * @param nodeId node identifier |
| 166 | * @param type control metric type |
| 167 | * @param duration projected duration |
| 168 | * @param unit projected time unit |
| 169 | * @param resourceName resource name |
| 170 | * @return completable future object of control load snapshot |
| 171 | */ |
| 172 | CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId, |
| 173 | ControlMetricType type, |
| 174 | int duration, TimeUnit unit, |
| 175 | String resourceName); |
Jian Li | 85060ac | 2016-02-04 09:58:56 -0800 | [diff] [blame] | 176 | |
| 177 | /** |
Jian Li | f248aa2 | 2016-05-09 10:33:02 -0700 | [diff] [blame] | 178 | * Synchronous version of getLoad. |
| 179 | * Obtains snapshot of control plane load of a specific resource with the |
| 180 | * projected range. |
| 181 | * |
| 182 | * @param nodeId node identifier |
| 183 | * @param type control metric type |
| 184 | * @param duration projected duration |
| 185 | * @param unit projected time unit |
| 186 | * @param resourceName resource name |
| 187 | * @return control load snapshot |
| 188 | */ |
| 189 | default ControlLoadSnapshot getLoadSync(NodeId nodeId, |
| 190 | ControlMetricType type, |
| 191 | int duration, TimeUnit unit, |
| 192 | String resourceName) { |
| 193 | return Tools.futureGetOrElse(getLoad(nodeId, type, duration, unit, resourceName), |
| 194 | TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, null); |
| 195 | } |
| 196 | |
| 197 | /** |
Jian Li | 85060ac | 2016-02-04 09:58:56 -0800 | [diff] [blame] | 198 | * Obtains a list of names of available resources. |
| 199 | * |
Jian Li | 89eeccd | 2016-05-06 02:10:33 -0700 | [diff] [blame] | 200 | * @param nodeId node identifier |
Jian Li | 72b9b12 | 2016-02-11 15:58:51 -0800 | [diff] [blame] | 201 | * @param resourceType resource type |
Jian Li | 89eeccd | 2016-05-06 02:10:33 -0700 | [diff] [blame] | 202 | * @return completable future object of a collection of available resource names |
Jian Li | 85060ac | 2016-02-04 09:58:56 -0800 | [diff] [blame] | 203 | */ |
Jian Li | 89eeccd | 2016-05-06 02:10:33 -0700 | [diff] [blame] | 204 | CompletableFuture<Set<String>> availableResources(NodeId nodeId, Type resourceType); |
| 205 | |
| 206 | /** |
| 207 | * Synchronous version of availableResource. |
| 208 | * Obtains a list of names of available resources. |
| 209 | * |
| 210 | * @param nodeId node identifier |
| 211 | * @param resourceType resource type |
| 212 | * @return a collection of available resource names |
| 213 | */ |
| 214 | default Set<String> availableResourcesSync(NodeId nodeId, Type resourceType) { |
| 215 | return Tools.futureGetOrElse(availableResources(nodeId, resourceType), |
| 216 | TIMEOUT_MILLIS, TimeUnit.MILLISECONDS, ImmutableSet.of()); |
| 217 | } |
Jian Li | 0967cd7 | 2015-11-25 17:38:48 -0800 | [diff] [blame] | 218 | } |