Search in sources :

Example 1 with AllocateIdRangeInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeInputBuilder 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)1 AllocateIdRangeInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeInputBuilder)1 AllocateIdRangeOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdRangeOutput)1 AllocateResourceOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.AllocateResourceOutput)1 AllocateResourceOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.AllocateResourceOutputBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1