use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.resourcemanager.rev160622.AllocateResourceOutput 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