Search in sources :

Example 1 with AllocateScmBlockResponseProto

use of org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockResponseProto in project ozone by apache.

the class ScmBlockLocationProtocolServerSideTranslatorPB method allocateScmBlock.

public AllocateScmBlockResponseProto allocateScmBlock(AllocateScmBlockRequestProto request, int clientVersion) throws IOException {
    List<AllocatedBlock> allocatedBlocks = impl.allocateBlock(request.getSize(), request.getNumBlocks(), ReplicationConfig.fromProtoTypeAndFactor(request.getType(), request.getFactor()), request.getOwner(), ExcludeList.getFromProtoBuf(request.getExcludeList()));
    AllocateScmBlockResponseProto.Builder builder = AllocateScmBlockResponseProto.newBuilder();
    if (allocatedBlocks.size() < request.getNumBlocks()) {
        throw new SCMException("Allocated " + allocatedBlocks.size() + " blocks. Requested " + request.getNumBlocks() + " blocks", SCMException.ResultCodes.FAILED_TO_ALLOCATE_ENOUGH_BLOCKS);
    }
    for (AllocatedBlock block : allocatedBlocks) {
        builder.addBlocks(AllocateBlockResponse.newBuilder().setContainerBlockID(block.getBlockID().getProtobuf()).setPipeline(block.getPipeline().getProtobufMessage(clientVersion)));
    }
    return builder.build();
}
Also used : AllocateScmBlockResponseProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockResponseProto) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException)

Example 2 with AllocateScmBlockResponseProto

use of org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockResponseProto in project ozone by apache.

the class ScmBlockLocationProtocolClientSideTranslatorPB method allocateBlock.

/**
 * Asks SCM where a block should be allocated. SCM responds with the
 * set of datanodes that should be used creating this block.
 *
 * @param size              - size of the block.
 * @param num               - number of blocks.
 * @param replicationConfig - replication configuration of the blocks.
 * @param excludeList       - exclude list while allocating blocks.
 * @return allocated block accessing info (key, pipeline).
 * @throws IOException
 */
@Override
public List<AllocatedBlock> allocateBlock(long size, int num, ReplicationConfig replicationConfig, String owner, ExcludeList excludeList) throws IOException {
    Preconditions.checkArgument(size > 0, "block size must be greater than 0");
    final AllocateScmBlockRequestProto.Builder requestBuilder = AllocateScmBlockRequestProto.newBuilder().setSize(size).setNumBlocks(num).setType(replicationConfig.getReplicationType()).setOwner(owner).setExcludeList(excludeList.getProtoBuf());
    switch(replicationConfig.getReplicationType()) {
        case STAND_ALONE:
            requestBuilder.setFactor(((StandaloneReplicationConfig) replicationConfig).getReplicationFactor());
            break;
        case RATIS:
            requestBuilder.setFactor(((RatisReplicationConfig) replicationConfig).getReplicationFactor());
            break;
        default:
            throw new IllegalArgumentException("Unsupported replication type " + replicationConfig.getReplicationType());
    }
    AllocateScmBlockRequestProto request = requestBuilder.build();
    SCMBlockLocationRequest wrapper = createSCMBlockRequest(Type.AllocateScmBlock).setAllocateScmBlockRequest(request).build();
    final SCMBlockLocationResponse wrappedResponse = handleError(submitRequest(wrapper));
    final AllocateScmBlockResponseProto response = wrappedResponse.getAllocateScmBlockResponse();
    List<AllocatedBlock> blocks = new ArrayList<>(response.getBlocksCount());
    for (AllocateBlockResponse resp : response.getBlocksList()) {
        AllocatedBlock.Builder builder = new AllocatedBlock.Builder().setContainerBlockID(ContainerBlockID.getFromProtobuf(resp.getContainerBlockID())).setPipeline(Pipeline.getFromProtobuf(resp.getPipeline()));
        blocks.add(builder.build());
    }
    return blocks;
}
Also used : SCMBlockLocationRequest(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationRequest) AllocateScmBlockResponseProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockResponseProto) AllocateBlockResponse(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateBlockResponse) SCMBlockLocationResponse(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationResponse) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) ArrayList(java.util.ArrayList) AllocateScmBlockRequestProto(org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockRequestProto)

Aggregations

AllocateScmBlockResponseProto (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockResponseProto)2 AllocatedBlock (org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock)2 ArrayList (java.util.ArrayList)1 AllocateBlockResponse (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateBlockResponse)1 AllocateScmBlockRequestProto (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.AllocateScmBlockRequestProto)1 SCMBlockLocationRequest (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationRequest)1 SCMBlockLocationResponse (org.apache.hadoop.hdds.protocol.proto.ScmBlockLocationProtocolProtos.SCMBlockLocationResponse)1 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)1