use of org.onosproject.net.meter.MeterScope in project onos by opennetworkinglab.
the class MetersWebResource method getMeterByDeviceIdAndMeterCellId.
/**
* Returns a meter by the meter cell id.
*
* @param deviceId device identifier
* @param scope scope identifier
* @param index index
* @return 200 OK with a meter, return 404 if no entry has been found
* @onos.rsModel Meter
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{scope}/{index}")
public Response getMeterByDeviceIdAndMeterCellId(@PathParam("deviceId") String deviceId, @PathParam("scope") String scope, @PathParam("index") String index) {
DeviceId did = DeviceId.deviceId(deviceId);
MeterScope meterScope = MeterScope.of(scope);
long meterIndex = Long.parseLong(index);
MeterCellId meterCellId;
if (meterScope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(meterIndex);
} else {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(meterScope.id()), meterIndex);
}
MeterService meterService = get(MeterService.class);
final Meter meter = nullIsNotFound(meterService.getMeter(did, meterCellId), METER_NOT_FOUND + meterCellId);
metersNode.add(codec(Meter.class).encode(meter, this));
return ok(root).build();
}
use of org.onosproject.net.meter.MeterScope in project onos by opennetworkinglab.
the class MeterRemoveCommand method doExecute.
@Override
protected void doExecute() {
MeterService service = get(MeterService.class);
CoreService coreService = get(CoreService.class);
DeviceId deviceId = DeviceId.deviceId(uri);
MeterScope scope = MeterScope.globalScope();
if (!isNullOrEmpty(scopeString)) {
scope = MeterScope.of(scopeString);
}
MeterCellId meterCellId;
long index = Long.parseLong(indexString);
if (scope.equals(MeterScope.globalScope())) {
meterCellId = MeterId.meterId(index);
} else {
meterCellId = PiMeterCellId.ofIndirect(PiMeterId.of(scope.id()), index);
}
MeterRequest.Builder builder = DefaultMeterRequest.builder().forDevice(deviceId).fromApp(coreService.registerApplication(appId));
MeterRequest meterRequest = builder.remove();
service.withdraw(builder.remove(), meterCellId);
log.info("Requested meter {} removal: {}", meterCellId.toString(), meterRequest.toString());
print("Requested meter %s removal: %s", meterCellId.toString(), meterRequest.toString());
}
Aggregations