use of org.onosproject.net.meter.MeterState in project onos by opennetworkinglab.
the class DistributedMeterStore method updateMeterState.
@Override
public Meter updateMeterState(Meter meter) {
// Update meter if present (stats workflow)
MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
Versioned<MeterData> value = meters.computeIfPresent(key, (k, v) -> {
DefaultMeter m = (DefaultMeter) v.meter();
MeterState meterState = m.state();
if (meterState == MeterState.PENDING_ADD) {
m.setState(meter.state());
}
m.setProcessedPackets(meter.packetsSeen());
m.setProcessedBytes(meter.bytesSeen());
m.setLife(meter.life());
// TODO: Prune if drops to zero.
m.setReferenceCount(meter.referenceCount());
return new MeterData(m, null);
});
return value != null ? value.value().meter() : null;
}
use of org.onosproject.net.meter.MeterState in project onos by opennetworkinglab.
the class DistributedMeterStore method deleteMeter.
@Override
public CompletableFuture<MeterStoreResult> deleteMeter(Meter meter) {
CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
futures.put(key, future);
// that it has been removed from the dataplane.
try {
Versioned<MeterData> versionedData = meters.computeIfPresent(key, (k, v) -> {
DefaultMeter m = (DefaultMeter) v.meter();
MeterState meterState = m.state();
if (meterState == MeterState.PENDING_REMOVE) {
return v;
}
m.setState(meter.state());
return new MeterData(m, v.reason().isPresent() ? v.reason().get() : null);
});
// If it does not exist in the system, completes immediately
if (versionedData == null) {
futures.remove(key);
future.complete(MeterStoreResult.success());
}
} catch (StorageException e) {
log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
futures.remove(key);
future.completeExceptionally(e);
}
return future;
}
Aggregations