Search in sources :

Example 1 with Builder

use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder in project ozone by apache.

the class ContainerTestHelper method newPutBlockRequestBuilder.

public static Builder newPutBlockRequestBuilder(Pipeline pipeline, ContainerProtos.WriteChunkRequestProtoOrBuilder writeRequest) throws IOException {
    LOG.trace("putBlock: {} to pipeline={}", writeRequest.getBlockID(), pipeline);
    ContainerProtos.PutBlockRequestProto.Builder putRequest = ContainerProtos.PutBlockRequestProto.newBuilder();
    BlockData blockData = new BlockData(BlockID.getFromProtobuf(writeRequest.getBlockID()));
    List<ContainerProtos.ChunkInfo> newList = new LinkedList<>();
    newList.add(writeRequest.getChunkData());
    blockData.setChunks(newList);
    blockData.setBlockCommitSequenceId(0);
    putRequest.setBlockData(blockData.getProtoBufMessage());
    Builder request = ContainerCommandRequestProto.newBuilder();
    request.setCmdType(ContainerProtos.Type.PutBlock);
    request.setContainerID(blockData.getContainerID());
    request.setPutBlock(putRequest);
    request.setDatanodeUuid(pipeline.getFirstNode().getUuidString());
    return request;
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder) BlockData(org.apache.hadoop.ozone.container.common.helpers.BlockData) LinkedList(java.util.LinkedList)

Example 2 with Builder

use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder in project ozone by apache.

the class ContainerTestHelper method getDummyCommandRequestProto.

/**
 * Construct fake protobuf messages for various types of requests.
 * This is tedious, however necessary to test. Protobuf classes are final
 * and cannot be mocked by Mockito.
 *
 * @param cmdType type of the container command.
 * @return
 */
public static ContainerCommandRequestProto getDummyCommandRequestProto(ContainerProtos.Type cmdType) {
    final Builder builder = ContainerCommandRequestProto.newBuilder().setCmdType(cmdType).setContainerID(DUMMY_CONTAINER_ID).setDatanodeUuid(DATANODE_UUID);
    final DatanodeBlockID fakeBlockId = DatanodeBlockID.newBuilder().setContainerID(DUMMY_CONTAINER_ID).setLocalID(1).setBlockCommitSequenceId(101).build();
    final ContainerProtos.ChunkInfo fakeChunkInfo = ContainerProtos.ChunkInfo.newBuilder().setChunkName("dummy").setOffset(0).setLen(100).setChecksumData(ContainerProtos.ChecksumData.newBuilder().setBytesPerChecksum(1).setType(ChecksumType.CRC32).build()).build();
    switch(cmdType) {
        case ReadContainer:
            builder.setReadContainer(ContainerProtos.ReadContainerRequestProto.newBuilder().build());
            break;
        case GetBlock:
            builder.setGetBlock(ContainerProtos.GetBlockRequestProto.newBuilder().setBlockID(fakeBlockId).build());
            break;
        case GetCommittedBlockLength:
            builder.setGetCommittedBlockLength(ContainerProtos.GetCommittedBlockLengthRequestProto.newBuilder().setBlockID(fakeBlockId).build());
            break;
        case ReadChunk:
            builder.setReadChunk(ContainerProtos.ReadChunkRequestProto.newBuilder().setBlockID(fakeBlockId).setChunkData(fakeChunkInfo).setReadChunkVersion(ContainerProtos.ReadChunkVersion.V1).build());
            break;
        case GetSmallFile:
            builder.setGetSmallFile(ContainerProtos.GetSmallFileRequestProto.newBuilder().setBlock(ContainerProtos.GetBlockRequestProto.newBuilder().setBlockID(fakeBlockId).build()).build());
            break;
        default:
            Assert.fail("Unhandled request type " + cmdType + " in unit test");
    }
    return builder.build();
}
Also used : ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder) DatanodeBlockID(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.DatanodeBlockID)

Example 3 with Builder

use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder in project ozone by apache.

the class ContainerTestHelper method newReadChunkRequestBuilder.

public static Builder newReadChunkRequestBuilder(Pipeline pipeline, ContainerProtos.WriteChunkRequestProtoOrBuilder writeChunk) throws IOException {
    LOG.trace("readChunk blockID={} from pipeline={}", writeChunk.getBlockID(), pipeline);
    ContainerProtos.ReadChunkRequestProto.Builder readRequest = ContainerProtos.ReadChunkRequestProto.newBuilder();
    readRequest.setBlockID(writeChunk.getBlockID());
    readRequest.setChunkData(writeChunk.getChunkData());
    readRequest.setReadChunkVersion(ContainerProtos.ReadChunkVersion.V1);
    Builder newRequest = ContainerCommandRequestProto.newBuilder();
    newRequest.setCmdType(ContainerProtos.Type.ReadChunk);
    newRequest.setContainerID(readRequest.getBlockID().getContainerID());
    newRequest.setReadChunk(readRequest);
    newRequest.setDatanodeUuid(pipeline.getFirstNode().getUuidString());
    return newRequest;
}
Also used : Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder)

Example 4 with Builder

use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder in project ozone by apache.

the class ContainerTestHelper method newGetBlockRequestBuilder.

public static Builder newGetBlockRequestBuilder(Pipeline pipeline, ContainerProtos.PutBlockRequestProtoOrBuilder putBlock) throws IOException {
    DatanodeBlockID blockID = putBlock.getBlockData().getBlockID();
    ContainerProtos.GetBlockRequestProto.Builder getRequest = ContainerProtos.GetBlockRequestProto.newBuilder();
    getRequest.setBlockID(blockID);
    Builder request = ContainerCommandRequestProto.newBuilder();
    request.setCmdType(ContainerProtos.Type.GetBlock);
    request.setContainerID(blockID.getContainerID());
    request.setGetBlock(getRequest);
    request.setDatanodeUuid(pipeline.getFirstNode().getUuidString());
    return request;
}
Also used : Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder) DatanodeBlockID(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.DatanodeBlockID)

Example 5 with Builder

use of org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder in project ozone by apache.

the class ContainerTestHelper method newWriteChunkRequestBuilder.

public static Builder newWriteChunkRequestBuilder(Pipeline pipeline, BlockID blockID, int datalen, int seq) throws IOException {
    LOG.trace("writeChunk {} (blockID={}) to pipeline={}", datalen, blockID, pipeline);
    ContainerProtos.WriteChunkRequestProto.Builder writeRequest = ContainerProtos.WriteChunkRequestProto.newBuilder();
    writeRequest.setBlockID(blockID.getDatanodeBlockIDProtobuf());
    ChunkBuffer data = getData(datalen);
    ChunkInfo info = getChunk(blockID.getLocalID(), seq, 0, datalen);
    setDataChecksum(info, data);
    writeRequest.setChunkData(info.getProtoBufMessage());
    writeRequest.setData(data.toByteString());
    Builder request = ContainerCommandRequestProto.newBuilder();
    request.setCmdType(ContainerProtos.Type.WriteChunk);
    request.setContainerID(blockID.getContainerID());
    request.setWriteChunk(writeRequest);
    request.setDatanodeUuid(pipeline.getFirstNode().getUuidString());
    return request;
}
Also used : ChunkInfo(org.apache.hadoop.ozone.container.common.helpers.ChunkInfo) Builder(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder) ChunkBuffer(org.apache.hadoop.ozone.common.ChunkBuffer)

Aggregations

Builder (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto.Builder)10 ChunkInfo (org.apache.hadoop.ozone.container.common.helpers.ChunkInfo)3 LinkedList (java.util.LinkedList)2 DatanodeBlockID (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.DatanodeBlockID)2 ChunkBuffer (org.apache.hadoop.ozone.common.ChunkBuffer)2 BlockData (org.apache.hadoop.ozone.container.common.helpers.BlockData)2 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)1 ContainerCommandRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto)1 KeyValue (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.KeyValue)1 MockPipeline (org.apache.hadoop.hdds.scm.pipeline.MockPipeline)1 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)1