Search in sources :

Example 1 with ResourceConsumerId

use of org.onosproject.net.resource.ResourceConsumerId in project onos by opennetworkinglab.

the class ConsistentResourceStore method release.

@Override
public boolean release(List<ResourceAllocation> allocations) {
    checkNotNull(allocations);
    while (true) {
        TransactionContext tx = service.transactionContextBuilder().build();
        tx.begin();
        TransactionalDiscreteResourceSubStore discreteTxStore = discreteStore.transactional(tx);
        TransactionalContinuousResourceSubStore continuousTxStore = continuousStore.transactional(tx);
        for (ResourceAllocation allocation : allocations) {
            Resource resource = allocation.resource();
            ResourceConsumerId consumerId = allocation.consumerId();
            if (resource instanceof DiscreteResource) {
                if (!discreteTxStore.release(consumerId, (DiscreteResource) resource)) {
                    return abortTransaction(tx);
                }
            } else if (resource instanceof ContinuousResource) {
                if (!continuousTxStore.release(consumerId, (ContinuousResource) resource)) {
                    return abortTransaction(tx);
                }
            }
        }
        try {
            if (commitTransaction(tx) == CommitStatus.SUCCESS) {
                return true;
            }
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            log.warn("Failed to release {}: {}", allocations, e);
            return false;
        }
    }
}
Also used : TransactionContext(org.onosproject.store.service.TransactionContext) Resource(org.onosproject.net.resource.Resource) ContinuousResource(org.onosproject.net.resource.ContinuousResource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) ResourceConsumerId(org.onosproject.net.resource.ResourceConsumerId) DiscreteResource(org.onosproject.net.resource.DiscreteResource) ExecutionException(java.util.concurrent.ExecutionException) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with ResourceConsumerId

use of org.onosproject.net.resource.ResourceConsumerId in project onos by opennetworkinglab.

the class TransactionalDiscreteResourceSubStore method allocate.

@Override
public boolean allocate(ResourceConsumerId consumerId, DiscreteResource resource) {
    // if the resource is not registered, then abort
    Optional<DiscreteResource> lookedUp = lookup(resource.id());
    if (!lookedUp.isPresent()) {
        return false;
    }
    ResourceConsumerId oldValue = consumers.put(resource.id(), consumerId);
    return oldValue == null;
}
Also used : DiscreteResource(org.onosproject.net.resource.DiscreteResource) ResourceConsumerId(org.onosproject.net.resource.ResourceConsumerId)

Aggregations

DiscreteResource (org.onosproject.net.resource.DiscreteResource)2 ResourceConsumerId (org.onosproject.net.resource.ResourceConsumerId)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ContinuousResource (org.onosproject.net.resource.ContinuousResource)1 Resource (org.onosproject.net.resource.Resource)1 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)1 TransactionContext (org.onosproject.store.service.TransactionContext)1