Search in sources :

Example 1 with AllocateIdRangeOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput in project genius by opendaylight.

the class IdManager method allocateIdRange.

@Override
public Future<RpcResult<AllocateIdRangeOutput>> allocateIdRange(AllocateIdRangeInput input) {
    String idKey = input.getIdKey();
    String poolName = input.getPoolName();
    long size = input.getSize();
    String localPoolName = idUtils.getLocalPoolName(poolName);
    AllocateIdRangeOutputBuilder output = new AllocateIdRangeOutputBuilder();
    return FutureRpcResults.fromBuilder(LOG, "allocateIdRange", input, () -> {
        List<Long> newIdValuesList = allocateIdFromLocalPool(poolName, localPoolName, idKey, size);
        Collections.sort(newIdValuesList);
        output.setIdValues(newIdValuesList);
        return output;
    }).onFailure(e -> completeExceptionallyIfPresent(poolName, idKey, e)).build();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) LoggerFactory(org.slf4j.LoggerFactory) CONFIGURATION(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION) Timer(java.util.Timer) DataImportBootReady(org.opendaylight.daexim.DataImportBootReady) PreDestroy(javax.annotation.PreDestroy) Future(java.util.concurrent.Future) CleanUpJob(org.opendaylight.genius.idmanager.jobs.CleanUpJob) Optional(com.google.common.base.Optional) Map(java.util.Map) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) TimerTask(java.util.TimerTask) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) ChildPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ChildPools) AllocateIdRangeInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeInput) AvailableIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolderBuilder) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) OsgiService(org.ops4j.pax.cdi.api.OsgiService) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) OperationFailedException(org.opendaylight.yangtools.yang.common.OperationFailedException) IdHolderSyncJob(org.opendaylight.genius.idmanager.jobs.IdHolderSyncJob) CountDownLatch(java.util.concurrent.CountDownLatch) IdManagerMonitor(org.opendaylight.genius.idmanager.api.IdManagerMonitor) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) AllocateIdOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder) DelayedIdEntry(org.opendaylight.genius.idmanager.ReleasedIdHolder.DelayedIdEntry) IdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries) AllocateIdRangeOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutputBuilder) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) FutureRpcResults(org.opendaylight.genius.infra.FutureRpcResults) DelayedIdEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.released.ids.DelayedIdEntries) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) Collectors.toCollection(java.util.stream.Collectors.toCollection) UpdateIdEntryJob(org.opendaylight.genius.idmanager.jobs.UpdateIdEntryJob) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) Comparator.comparing(java.util.Comparator.comparing) LinkedList(java.util.LinkedList) LockManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService) AllocateIdRangeOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput) Logger(org.slf4j.Logger) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) ReleasedIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolder) LocalPoolCreateJob(org.opendaylight.genius.idmanager.jobs.LocalPoolCreateJob) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) Futures(com.google.common.util.concurrent.Futures) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) LocalPoolDeleteJob(org.opendaylight.genius.idmanager.jobs.LocalPoolDeleteJob) DeleteIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.DeleteIdPoolInput) ReleasedIdsHolderBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.ReleasedIdsHolderBuilder) AvailableIdsHolder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.AvailableIdsHolder) IdPoolBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder) Collections(java.util.Collections) LogLevel(org.opendaylight.genius.infra.FutureRpcResults.LogLevel) AllocateIdRangeOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutputBuilder)

Example 2 with AllocateIdRangeOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput in project genius by opendaylight.

the class ResourceManager method allocateResource.

@Override
public Future<RpcResult<AllocateResourceOutput>> allocateResource(AllocateResourceInput input) {
    Objects.requireNonNull(input.getResourceType(), RESOURCE_TYPE_CANNOT_BE_NULL);
    Objects.requireNonNull(input.getIdKey(), RESOURCE_ID_CANNOT_BE_NULL);
    Objects.requireNonNull(input.getSize(), RESOURCE_SIZE_CANNOT_BE_NULL);
    Objects.requireNonNull(resourcesCache.get(input.getResourceType()), RESOURCE_TYPE_NOT_FOUND);
    AllocateIdRangeInputBuilder allocateIdRangeBuilder = new AllocateIdRangeInputBuilder();
    allocateIdRangeBuilder.setIdKey(input.getIdKey()).setPoolName(resourcesCache.get(input.getResourceType())).setSize(input.getSize());
    Future<RpcResult<AllocateIdRangeOutput>> output = idManager.allocateIdRange(allocateIdRangeBuilder.build());
    AllocateResourceOutputBuilder allocateResourceOutputBuilder = new AllocateResourceOutputBuilder();
    RpcResultBuilder<AllocateResourceOutput> allocateResourceOutputRpcBuilder = null;
    try {
        if (output.get().isSuccessful()) {
            AllocateIdRangeOutput allocateIdRangeOutput = output.get().getResult();
            List<Long> idValues = allocateIdRangeOutput.getIdValues();
            allocateResourceOutputBuilder.setIdValues(idValues);
            allocateResourceOutputRpcBuilder = RpcResultBuilder.success();
            allocateResourceOutputRpcBuilder.withResult(allocateResourceOutputBuilder.build());
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("Allocate Resource failed for resource {} due to ", input.getResourceType(), e);
        allocateResourceOutputRpcBuilder = RpcResultBuilder.failed();
        allocateResourceOutputRpcBuilder.withError(RpcError.ErrorType.APPLICATION, e.getMessage());
    }
    if (allocateResourceOutputRpcBuilder == null) {
        allocateResourceOutputRpcBuilder = RpcResultBuilder.failed();
        allocateResourceOutputRpcBuilder.withError(RpcError.ErrorType.APPLICATION, "Resource cannot be  allocated");
    }
    return Futures.immediateFuture(allocateResourceOutputRpcBuilder.build());
}
Also used : AllocateIdRangeInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeInputBuilder) AllocateIdRangeOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput) AllocateResourceOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.AllocateResourceOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AllocateResourceOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.AllocateResourceOutput) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)2 AllocateIdRangeOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Optional (com.google.common.base.Optional)1 Futures (com.google.common.util.concurrent.Futures)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator.comparing (java.util.Comparator.comparing)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1