blob: 03cf8de5005bf9cc0682de06c643a489683fa359 [file] [log] [blame]
Jian Li0967cd72015-11-25 17:38:48 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jian Li0967cd72015-11-25 17:38:48 -08003 *
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 */
16package org.onosproject.cpman;
17
Jian Li89eeccd2016-05-06 02:10:33 -070018import com.google.common.collect.ImmutableSet;
19import org.onlab.util.Tools;
Jian Li0967cd72015-11-25 17:38:48 -080020import org.onosproject.cluster.NodeId;
21import org.onosproject.net.DeviceId;
22
23import java.util.Optional;
Jian Li85060ac2016-02-04 09:58:56 -080024import java.util.Set;
Jian Li23906cc2016-03-31 11:16:44 -070025import java.util.concurrent.CompletableFuture;
Jian Li67e1e152016-04-18 17:52:58 -070026import java.util.concurrent.TimeUnit;
Jian Li85060ac2016-02-04 09:58:56 -080027
Jian Li67e1e152016-04-18 17:52:58 -070028import static org.onosproject.cpman.ControlResource.Type;
Jian Li0967cd72015-11-25 17:38:48 -080029
30/**
31 * Control Plane Statistics Service Interface.
32 */
Jian Li60804322015-12-02 14:46:31 -080033public interface ControlPlaneMonitorService {
Jian Li0967cd72015-11-25 17:38:48 -080034
Jian Li89eeccd2016-05-06 02:10:33 -070035 long TIMEOUT_MILLIS = 2000;
36
Jian Li0967cd72015-11-25 17:38:48 -080037 /**
Jian Li60804322015-12-02 14:46:31 -080038 * Adds a new control metric value with a certain update interval.
Jian Li0967cd72015-11-25 17:38:48 -080039 *
Jian Li23906cc2016-03-31 11:16:44 -070040 * @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 Li0967cd72015-11-25 17:38:48 -080044 */
Jian Lic5cb4a12016-02-03 23:24:42 -080045 void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes,
46 Optional<DeviceId> deviceId);
Jian Li0967cd72015-11-25 17:38:48 -080047
48 /**
Jian Lie044d1a2016-01-25 09:01:20 -080049 * Adds a new control metric value with a certain update interval.
50 *
Jian Li23906cc2016-03-31 11:16:44 -070051 * @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 Lie044d1a2016-01-25 09:01:20 -080055 */
Jian Lic5cb4a12016-02-03 23:24:42 -080056 void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes,
57 String resourceName);
Jian Lie044d1a2016-01-25 09:01:20 -080058
59 /**
Jian Li67e1e152016-04-18 17:52:58 -070060 * Obtains snapshot of control plane load of a specific device.
Jian Li7d180c52016-02-01 21:53:08 -080061 * The metrics range from control messages and system metrics
Jian Li67e1e152016-04-18 17:52:58 -070062 * (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 Li23906cc2016-03-31 11:16:44 -070065 *
66 * @param nodeId node identifier
67 * @param type control metric type
68 * @param deviceId device identifier
Jian Li67e1e152016-04-18 17:52:58 -070069 * @return completable future object of control load snapshot
Jian Li23906cc2016-03-31 11:16:44 -070070 */
Jian Li67e1e152016-04-18 17:52:58 -070071 CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
72 ControlMetricType type,
73 Optional<DeviceId> deviceId);
Jian Li23906cc2016-03-31 11:16:44 -070074
75 /**
Jian Lif248aa22016-05-09 10:33:02 -070076 * 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 Li67e1e152016-04-18 17:52:58 -070096 * 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 Li23906cc2016-03-31 11:16:44 -070098 *
99 * @param nodeId node identifier
100 * @param type control metric type
101 * @param resourceName resource name
Jian Li67e1e152016-04-18 17:52:58 -0700102 * @return completable future object of control load snapshot
Jian Li23906cc2016-03-31 11:16:44 -0700103 */
Jian Li67e1e152016-04-18 17:52:58 -0700104 CompletableFuture<ControlLoadSnapshot> getLoad(NodeId nodeId,
105 ControlMetricType type,
106 String resourceName);
107
108 /**
Jian Lif248aa22016-05-09 10:33:02 -0700109 * 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 Li67e1e152016-04-18 17:52:58 -0700126 * 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 Lif248aa22016-05-09 10:33:02 -0700142 * 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 Li67e1e152016-04-18 17:52:58 -0700162 * 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 Li85060ac2016-02-04 09:58:56 -0800176
177 /**
Jian Lif248aa22016-05-09 10:33:02 -0700178 * 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 Li85060ac2016-02-04 09:58:56 -0800198 * Obtains a list of names of available resources.
199 *
Jian Li89eeccd2016-05-06 02:10:33 -0700200 * @param nodeId node identifier
Jian Li72b9b122016-02-11 15:58:51 -0800201 * @param resourceType resource type
Jian Li89eeccd2016-05-06 02:10:33 -0700202 * @return completable future object of a collection of available resource names
Jian Li85060ac2016-02-04 09:58:56 -0800203 */
Jian Li89eeccd2016-05-06 02:10:33 -0700204 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 Li0967cd72015-11-25 17:38:48 -0800218}