Search in sources :

Example 6 with MeterStoreResult

use of org.onosproject.net.meter.MeterStoreResult in project onos by opennetworkinglab.

the class DistributedMeterStore method deleteMeterFeatures.

@Override
public MeterStoreResult deleteMeterFeatures(DeviceId deviceId) {
    MeterStoreResult result = MeterStoreResult.success();
    try {
        Set<MeterTableKey> keys = metersFeatures.keySet().stream().filter(key -> key.deviceId().equals(deviceId)).collect(Collectors.toUnmodifiableSet());
        keys.forEach(k -> metersFeatures.remove(k));
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        result = MeterStoreResult.fail(TIMEOUT);
    }
    return result;
}
Also used : ConsistentMap(org.onosproject.store.service.ConsistentMap) DefaultMeter(org.onosproject.net.meter.DefaultMeter) Collections2(com.google.common.collect.Collections2) DriverService(org.onosproject.net.driver.DriverService) MeterStoreDelegate(org.onosproject.net.meter.MeterStoreDelegate) PiMeterId(org.onosproject.net.pi.model.PiMeterId) RandomUtils(org.apache.commons.lang.math.RandomUtils) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) StorageService(org.onosproject.store.service.StorageService) MeterCellId(org.onosproject.net.meter.MeterCellId) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) DefaultDistributedSet(org.onosproject.store.primitives.DefaultDistributedSet) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) MeterFailReason(org.onosproject.net.meter.MeterFailReason) MeterQuery(org.onosproject.net.behaviour.MeterQuery) Band(org.onosproject.net.meter.Band) Serializer(org.onosproject.store.service.Serializer) ImmutableSet(com.google.common.collect.ImmutableSet) MeterEvent(org.onosproject.net.meter.MeterEvent) MeterScope(org.onosproject.net.meter.MeterScope) EventuallyConsistentMapEvent(org.onosproject.store.service.EventuallyConsistentMapEvent) MeterOperation(org.onosproject.net.meter.MeterOperation) Deactivate(org.osgi.service.component.annotations.Deactivate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) WallClockTimestamp(org.onosproject.store.service.WallClockTimestamp) AtomicCounterMap(org.onosproject.store.service.AtomicCounterMap) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Versioned(org.onosproject.store.service.Versioned) INDEX(org.onosproject.net.meter.MeterCellId.MeterCellType.INDEX) List(java.util.List) FIRST_FIT(org.onosproject.store.meter.impl.DistributedMeterStore.ReuseStrategy.FIRST_FIT) MeterKey(org.onosproject.net.meter.MeterKey) DeviceId(org.onosproject.net.DeviceId) MeterStore(org.onosproject.net.meter.MeterStore) Iterables(com.google.common.collect.Iterables) StorageException(org.onosproject.store.service.StorageException) MeterFeatures(org.onosproject.net.meter.MeterFeatures) MeterTableKey(org.onosproject.net.meter.MeterTableKey) PiMeterCellId(org.onosproject.net.pi.runtime.PiMeterCellId) MeterId(org.onosproject.net.meter.MeterId) CompletableFuture(java.util.concurrent.CompletableFuture) KryoNamespace(org.onlab.util.KryoNamespace) DistributedPrimitive(org.onosproject.store.service.DistributedPrimitive) MapEventListener(org.onosproject.store.service.MapEventListener) ConcurrentMap(java.util.concurrent.ConcurrentMap) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) FAIL(org.onosproject.net.meter.MeterStoreResult.Type.FAIL) Activate(org.osgi.service.component.annotations.Activate) EventuallyConsistentMap(org.onosproject.store.service.EventuallyConsistentMap) EventuallyConsistentMapListener(org.onosproject.store.service.EventuallyConsistentMapListener) Meter(org.onosproject.net.meter.Meter) Logger(org.slf4j.Logger) DefaultBand(org.onosproject.net.meter.DefaultBand) Maps(com.google.common.collect.Maps) MeterState(org.onosproject.net.meter.MeterState) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DriverHandler(org.onosproject.net.driver.DriverHandler) DistributedSet(org.onosproject.store.service.DistributedSet) TIMEOUT(org.onosproject.net.meter.MeterFailReason.TIMEOUT) DefaultMeterFeatures(org.onosproject.net.meter.DefaultMeterFeatures) MapEvent(org.onosproject.store.service.MapEvent) AbstractStore(org.onosproject.store.AbstractStore) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) PIPELINE_INDEPENDENT(org.onosproject.net.meter.MeterCellId.MeterCellType.PIPELINE_INDEPENDENT) MeterFeaturesFlag(org.onosproject.net.meter.MeterFeaturesFlag) Reference(org.osgi.service.component.annotations.Reference) MeterStoreResult(org.onosproject.net.meter.MeterStoreResult) MeterTableKey(org.onosproject.net.meter.MeterTableKey) StorageException(org.onosproject.store.service.StorageException)

Example 7 with MeterStoreResult

use of org.onosproject.net.meter.MeterStoreResult in project onos by opennetworkinglab.

the class DistributedMeterStore method addOrUpdateMeter.

@Override
public CompletableFuture<MeterStoreResult> addOrUpdateMeter(Meter meter) {
    checkArgument(validIndex(meter), "Meter index is not valid");
    CompletableFuture<MeterStoreResult> future = new CompletableFuture<>();
    MeterKey key = MeterKey.key(meter.deviceId(), meter.meterCellId());
    MeterData data = new MeterData(meter, null);
    futures.put(key, future);
    try {
        meters.compute(key, (k, v) -> data);
    } catch (StorageException e) {
        log.error("{} thrown a storage exception: {}", e.getStackTrace()[0].getMethodName(), e.getMessage(), e);
        futures.remove(key);
        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 8 with MeterStoreResult

use of org.onosproject.net.meter.MeterStoreResult in project onos by opennetworkinglab.

the class DistributedMeterStore method storeMeterFeatures.

@Override
public MeterStoreResult storeMeterFeatures(MeterFeatures meterfeatures) {
    // Store meter features, this is done once for each features of every device
    MeterStoreResult result = MeterStoreResult.success();
    MeterTableKey key = MeterTableKey.key(meterfeatures.deviceId(), meterfeatures.scope());
    try {
        metersFeatures.put(key, meterfeatures);
    } 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) StorageException(org.onosproject.store.service.StorageException)

Example 9 with MeterStoreResult

use of org.onosproject.net.meter.MeterStoreResult in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method updateMeter.

@Override
public CompletableFuture<MeterStoreResult> updateMeter(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 {
        if (meters.computeIfPresent(key, (k, v) -> data) == null) {
            future.complete(MeterStoreResult.fail(MeterFailReason.INVALID_METER));
        }
    } 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 10 with MeterStoreResult

use of org.onosproject.net.meter.MeterStoreResult in project onos by opennetworkinglab.

the class SimpleVirtualMeterStore method storeMeterFeatures.

@Override
public MeterStoreResult storeMeterFeatures(NetworkId networkId, MeterFeatures meterfeatures) {
    ConcurrentMap<MeterFeaturesKey, MeterFeatures> meterFeatures = getMeterFeaturesByNetwork(networkId);
    MeterStoreResult result = MeterStoreResult.success();
    MeterFeaturesKey key = MeterFeaturesKey.key(meterfeatures.deviceId());
    try {
        meterFeatures.putIfAbsent(key, meterfeatures);
    } 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)

Aggregations

MeterStoreResult (org.onosproject.net.meter.MeterStoreResult)10 StorageException (org.onosproject.store.service.StorageException)10 CompletableFuture (java.util.concurrent.CompletableFuture)6 MeterFeatures (org.onosproject.net.meter.MeterFeatures)6 MeterKey (org.onosproject.net.meter.MeterKey)6 DefaultMeter (org.onosproject.net.meter.DefaultMeter)4 MeterFeaturesKey (org.onosproject.net.meter.MeterFeaturesKey)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 MeterStoreDelegate (org.onosproject.net.meter.MeterStoreDelegate)3 MeterTableKey (org.onosproject.net.meter.MeterTableKey)3