Viswanath KSP

Exposed the newly added port specific portStatistics API via REST

Change-Id: I12a59b950f2d9123afc048e126ad7b457e5d7188
......@@ -35,6 +35,7 @@ import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.device.PortStatistics;
import org.onosproject.net.flow.FlowRuleService;
......@@ -215,4 +216,33 @@ public class StatisticsWebResource extends AbstractWebResource {
return ok(root).build();
}
/**
* Gets port statistics of a specified device and port.
* @onos.rsModel StatisticsPorts
* @param deviceId device ID
* @param port port
* @return 200 OK with JSON encoded array of port statistics for the specified port
*/
@GET
@Path("ports/{deviceId}/{port}")
@Produces(MediaType.APPLICATION_JSON)
public Response getPortStatisticsByDeviceIdAndPort(@PathParam("deviceId") String deviceId,
@PathParam("port") String port) {
final DeviceService service = get(DeviceService.class);
final PortNumber portNumber = portNumber(port);
final PortStatistics portStatsEntry =
service.getStatisticsForPort(DeviceId.deviceId(deviceId), portNumber);
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 (portStatsEntry != null) {
statisticsNode.add(codec(PortStatistics.class).encode(portStatsEntry, this));
}
rootArrayNode.add(deviceStatsNode);
return ok(root).build();
}
}
......