Search in sources :

Example 6 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method storeMeter.

@Override
public CompletableFuture<MeterStoreResult> storeMeter(NetworkId networkId, Meter meter) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);
    MeterData data = new MeterData(meter, null, local);
    try {
        meters.put(key, data);
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Example 7 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method deleteMeter.

@Override
public CompletableFuture<MeterStoreResult> deleteMeter(NetworkId networkId, Meter meter) {
    ConcurrentMap<MeterKey, MeterData> meters = getMetersByNetwork(networkId);
    ConcurrentMap<MeterKey, CompletableFuture<MeterStoreResult>> futures = getFuturesByNetwork(networkId);
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.id());
    futures.put(key, future);
    MeterData data = new MeterData(meter, null, local);
    // that it has been removed from the dataplane.
    try {
        if (meters.computeIfPresent(key, (k, v) -> data) == null) {
            future.complete(MeterStoreResult.success());
        }
    } catch (StorageException e) {
        future.completeExceptionally(e);
    }
    return future;
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) StorageException(org.onosproject.store.service.StorageException) DefaultMeter(org.onosproject.net.meter.DefaultMeter) MeterFeatures(org.onosproject.net.meter.MeterFeatures) CompletableFuture(java.util.concurrent.CompletableFuture) Collections2(com.google.common.collect.Collections2) MeterStoreDelegate(org.onosproject.net.meter.MeterStoreDelegate) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) Activate(org.osgi.service.component.annotations.Activate) MeterFailReason(org.onosproject.net.meter.MeterFailReason) NodeId(org.onosproject.cluster.NodeId) Meter(org.onosproject.net.meter.Meter) MeterEvent(org.onosproject.net.meter.MeterEvent) Logger(org.slf4j.Logger) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterOperation(org.onosproject.net.meter.MeterOperation) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Maps(com.google.common.collect.Maps) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) VirtualNetworkMeterStore(org.onosproject.incubator.net.virtual.VirtualNetworkMeterStore) TIMEOUT(org.onosproject.net.meter.MeterFailReason.TIMEOUT) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) MeterKey(org.onosproject.net.meter.MeterKey) ClusterService(org.onosproject.cluster.ClusterService) DeviceId(org.onosproject.net.DeviceId) Reference(org.osgi.service.component.annotations.Reference) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) CompletableFuture(java.util.concurrent.CompletableFuture) StorageException(org.onosproject.store.service.StorageException)

Example 8 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method deleteMeterFeatures.

@Override
public MeterStoreResult deleteMeterFeatures(NetworkId networkId, DeviceId deviceId) {
    ConcurrentMap<MeterFeaturesKey, MeterFeatures> meterFeatures = getMeterFeaturesByNetwork(networkId);
    MeterStoreResult result = MeterStoreResult.success();
    MeterFeaturesKey key = MeterFeaturesKey.key(deviceId);
    try {
        meterFeatures.remove(key);
    } catch (StorageException e) {
        result = MeterStoreResult.fail(TIMEOUT);
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterFeaturesKey(org.onosproject.net.meter.MeterFeaturesKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures) StorageException(org.onosproject.store.service.StorageException)

Example 9 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedMeterStore method deleteMeterFeatures.

@Override
public MeterStoreResult deleteMeterFeatures(Collection<MeterFeatures> meterfeatures) {
    // Same logic of storeMeterFeatures
    MeterStoreResult result = MeterStoreResult.success();
    for (MeterFeatures mf : meterfeatures) {
        try {
            MeterTableKey key = MeterTableKey.key(mf.deviceId(), mf.scope());
            metersFeatures.remove(key);
        } catch (StorageException e) {
            log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
            result = MeterStoreResult.fail(TIMEOUT);
        }
    }
    return result;
}
Also used : MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterTableKey(org.onosproject.net.meter.MeterTableKey) MeterFeatures(org.onosproject.net.meter.MeterFeatures) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) StorageException(org.onosproject.store.service.StorageException)

Example 10 with StorageException

use of org.onosproject.store.service.StorageException in project onos by opennetworkinglab.

the class DistributedMeterStore method purgeMeter.

@Override
public void purgeMeter(Meter m) {
    // Once we receive the ack from the sb, create the key
    // remove definitely the meter and free the id
    MeterKey key = MeterKey.key(m.deviceId(), m.meterCellId());
    try {
        if (Versioned.valueOrNull(meters.remove(key)) != null) {
            MeterScope scope;
            if (m.meterCellId().type() == PIPELINE_INDEPENDENT) {
                PiMeterCellId piMeterCellId = (PiMeterCellId) m.meterCellId();
                scope = MeterScope.of(piMeterCellId.meterId().id());
            } else {
                scope = MeterScope.globalScope();
            }
            MeterTableKey meterTableKey = MeterTableKey.key(m.deviceId(), scope);
            freeMeterId(meterTableKey, m.meterCellId());
        }
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
    }
}
Also used : MeterKey(org.onosproject.net.meter.MeterKey) MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterScope(org.onosproject.net.meter.MeterScope) StorageException(org.onosproject.store.service.StorageException)

Aggregations

StorageException (org.onosproject.store.service.StorageException)18 MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)10 CompletableFuture (java.util.concurrent.CompletableFuture)8 MeterKey (org.onosproject.net.meter.MeterKey)7 MeterFeatures (org.onosproject.net.meter.MeterFeatures)6 DefaultMeter (org.onosproject.net.meter.DefaultMeter)4 MeterFeaturesKey (org.onosproject.net.meter.MeterFeaturesKey)4 MeterTableKey (org.onosproject.net.meter.MeterTableKey)4 Activate (org.osgi.service.component.annotations.Activate)4 Collections2 (com.google.common.collect.Collections2)3 Maps (com.google.common.collect.Maps)3 Collection (java.util.Collection)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 DeviceId (org.onosproject.net.DeviceId)3 Meter (org.onosproject.net.meter.Meter)3 MeterEvent (org.onosproject.net.meter.MeterEvent)3 MeterFailReason (org.onosproject.net.meter.MeterFailReason)3 TIMEOUT (org.onosproject.net.meter.MeterFailReason.TIMEOUT)3 MeterOperation (org.onosproject.net.meter.MeterOperation)3