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();
}
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());
}
Aggregations