[ONOS-5155] Exposed delta statistics via northbound REST
Change-Id: I04d9ec04c92bccd7bd5b5fd23d61be241a67d524
Showing
1 changed file
with
86 additions
and
0 deletions
| ... | @@ -245,4 +245,90 @@ public class StatisticsWebResource extends AbstractWebResource { | ... | @@ -245,4 +245,90 @@ public class StatisticsWebResource extends AbstractWebResource { |
| 245 | return ok(root).build(); | 245 | return ok(root).build(); |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | + /** | ||
| 249 | + * Gets port delta statistics of all devices. | ||
| 250 | + * @onos.rsModel StatisticsPorts | ||
| 251 | + * @return 200 OK with JSON encoded array of port delta statistics | ||
| 252 | + */ | ||
| 253 | + @GET | ||
| 254 | + @Path("delta/ports") | ||
| 255 | + @Produces(MediaType.APPLICATION_JSON) | ||
| 256 | + public Response getPortDeltaStatistics() { | ||
| 257 | + final DeviceService service = get(DeviceService.class); | ||
| 258 | + final Iterable<Device> devices = service.getDevices(); | ||
| 259 | + final ObjectNode root = mapper().createObjectNode(); | ||
| 260 | + final ArrayNode rootArrayNode = root.putArray("statistics"); | ||
| 261 | + for (final Device device : devices) { | ||
| 262 | + final ObjectNode deviceStatsNode = mapper().createObjectNode(); | ||
| 263 | + deviceStatsNode.put("device", device.id().toString()); | ||
| 264 | + final ArrayNode statisticsNode = deviceStatsNode.putArray("ports"); | ||
| 265 | + final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(device.id()); | ||
| 266 | + if (portStatsEntries != null) { | ||
| 267 | + for (final PortStatistics entry : portStatsEntries) { | ||
| 268 | + statisticsNode.add(codec(PortStatistics.class).encode(entry, this)); | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + rootArrayNode.add(deviceStatsNode); | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + return ok(root).build(); | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * Gets port delta statistics of a specified devices. | ||
| 279 | + * @onos.rsModel StatisticsPorts | ||
| 280 | + * @param deviceId device ID | ||
| 281 | + * @return 200 OK with JSON encoded array of port delta statistics | ||
| 282 | + */ | ||
| 283 | + @GET | ||
| 284 | + @Path("delta/ports/{deviceId}") | ||
| 285 | + @Produces(MediaType.APPLICATION_JSON) | ||
| 286 | + public Response getPortDeltaStatisticsByDeviceId(@PathParam("deviceId") String deviceId) { | ||
| 287 | + final DeviceService service = get(DeviceService.class); | ||
| 288 | + final Iterable<PortStatistics> portStatsEntries = | ||
| 289 | + service.getPortDeltaStatistics(DeviceId.deviceId(deviceId)); | ||
| 290 | + final ObjectNode root = mapper().createObjectNode(); | ||
| 291 | + final ArrayNode rootArrayNode = root.putArray("statistics"); | ||
| 292 | + final ObjectNode deviceStatsNode = mapper().createObjectNode(); | ||
| 293 | + deviceStatsNode.put("device", deviceId); | ||
| 294 | + final ArrayNode statisticsNode = deviceStatsNode.putArray("ports"); | ||
| 295 | + if (portStatsEntries != null) { | ||
| 296 | + for (final PortStatistics entry : portStatsEntries) { | ||
| 297 | + statisticsNode.add(codec(PortStatistics.class).encode(entry, this)); | ||
| 298 | + } | ||
| 299 | + } | ||
| 300 | + rootArrayNode.add(deviceStatsNode); | ||
| 301 | + | ||
| 302 | + return ok(root).build(); | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + /** | ||
| 306 | + * Gets port delta statistics of a specified device and port. | ||
| 307 | + * @onos.rsModel StatisticsPorts | ||
| 308 | + * @param deviceId device ID | ||
| 309 | + * @param port port | ||
| 310 | + * @return 200 OK with JSON encoded array of port delta statistics for the specified port | ||
| 311 | + */ | ||
| 312 | + @GET | ||
| 313 | + @Path("delta/ports/{deviceId}/{port}") | ||
| 314 | + @Produces(MediaType.APPLICATION_JSON) | ||
| 315 | + public Response getPortDeltaStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId, | ||
| 316 | + @PathParam("port") String port) { | ||
| 317 | + final DeviceService service = get(DeviceService.class); | ||
| 318 | + final PortNumber portNumber = portNumber(port); | ||
| 319 | + final PortStatistics portStatsEntry = | ||
| 320 | + service.getDeltaStatisticsForPort(DeviceId.deviceId(deviceId), portNumber); | ||
| 321 | + final ObjectNode root = mapper().createObjectNode(); | ||
| 322 | + final ArrayNode rootArrayNode = root.putArray("statistics"); | ||
| 323 | + final ObjectNode deviceStatsNode = mapper().createObjectNode(); | ||
| 324 | + deviceStatsNode.put("device", deviceId); | ||
| 325 | + final ArrayNode statisticsNode = deviceStatsNode.putArray("ports"); | ||
| 326 | + if (portStatsEntry != null) { | ||
| 327 | + statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this)); | ||
| 328 | + } | ||
| 329 | + rootArrayNode.add(deviceStatsNode); | ||
| 330 | + | ||
| 331 | + return ok(root).build(); | ||
| 332 | + } | ||
| 333 | + | ||
| 248 | } | 334 | } | ... | ... |
-
Please register or login to post a comment