Search in sources :

Example 46 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortStatisticsByDeviceId.

/**
 * Gets port statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port statistics
 */
@GET
@Path("ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries = service.getPortStatistics(DeviceId.deviceId(deviceId));
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntries != null) {
        for (final PortStatistics entry : portStatsEntries) {
            statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
        }
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 47 with PortStatistics

use of org.onosproject.net.device.PortStatistics in project onos by opennetworkinglab.

the class StatisticsWebResource method getPortDeltaStatisticsByDeviceId.

/**
 * Gets port delta statistics of a specified devices.
 * @onos.rsModel StatisticsPorts
 * @param deviceId device ID
 * @return 200 OK with JSON encoded array of port delta statistics
 */
@GET
@Path("delta/ports/{deviceId}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortDeltaStatisticsByDeviceId(@PathParam("deviceId") String deviceId) {
    final DeviceService service = get(DeviceService.class);
    final Iterable<PortStatistics> portStatsEntries = service.getPortDeltaStatistics(DeviceId.deviceId(deviceId));
    final ObjectNode root = mapper().createObjectNode();
    final ArrayNode rootArrayNode = root.putArray("statistics");
    final ObjectNode deviceStatsNode = mapper().createObjectNode();
    deviceStatsNode.put("device", deviceId);
    final ArrayNode statisticsNode = deviceStatsNode.putArray("ports");
    if (portStatsEntries != null) {
        for (final PortStatistics entry : portStatsEntries) {
            statisticsNode.add(codec(PortStatistics.class).encode(entry, this));
        }
    }
    rootArrayNode.add(deviceStatsNode);
    return ok(root).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortStatistics(org.onosproject.net.device.PortStatistics) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

PortStatistics (org.onosproject.net.device.PortStatistics)47 DefaultPortStatistics (org.onosproject.net.device.DefaultPortStatistics)26 PortNumber (org.onosproject.net.PortNumber)14 DeviceService (org.onosproject.net.device.DeviceService)14 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 DeviceId (org.onosproject.net.DeviceId)11 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 Device (org.onosproject.net.Device)8 Port (org.onosproject.net.Port)7 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 PortStatisticsDiscovery (org.onosproject.net.device.PortStatisticsDiscovery)6 ConnectPoint (org.onosproject.net.ConnectPoint)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Maps (com.google.common.collect.Maps)4 Collection (java.util.Collection)4 Set (java.util.Set)4