Search in sources :

Example 1 with RPCFileReadRequest

use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.

the class DataServerHandler method channelRead0.

@Override
public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg) throws IOException {
    LOG.debug("Enter: {}", msg);
    try {
        switch(msg.getType()) {
            case RPC_BLOCK_READ_REQUEST:
                assert msg instanceof RPCBlockReadRequest;
                mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
                break;
            case RPC_BLOCK_WRITE_REQUEST:
                assert msg instanceof RPCBlockWriteRequest;
                mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
                break;
            case RPC_FILE_READ_REQUEST:
                assert msg instanceof RPCFileReadRequest;
                mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
                break;
            case RPC_FILE_WRITE_REQUEST:
                assert msg instanceof RPCFileWriteRequest;
                mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
                break;
            case RPC_UFS_BLOCK_READ_REQUEST:
                assert msg instanceof RPCUnderFileSystemBlockReadRequest;
                mBlockHandler.handleUnderFileSystemBlockReadRequest(ctx, (RPCUnderFileSystemBlockReadRequest) msg);
                break;
            case RPC_ERROR_RESPONSE:
                assert msg instanceof RPCErrorResponse;
                LOG.error("Received an error response from the client: " + msg.toString());
                break;
            case RPC_READ_REQUEST:
            case RPC_WRITE_REQUEST:
            case RPC_RESPONSE:
                assert msg instanceof RPCProtoMessage;
                ctx.fireChannelRead(msg);
                break;
            default:
                RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
                ctx.writeAndFlush(resp);
                // TODO(peis): Fix this. We should not throw an exception here.
                throw new IllegalArgumentException("No handler implementation for " + msg.getType());
        }
    } catch (IllegalArgumentException | IOException e) {
        LOG.warn("{}, Error={}", msg, e.getMessage());
        LOG.debug("{}", msg, e);
        LOG.debug("Exit (Error): {}, Error={}", msg, e.getMessage());
        // Rethrow the exception to use Netty's control flow.
        throw e;
    }
    LOG.debug("Exit (OK): {}", msg);
}
Also used : RPCUnderFileSystemBlockReadRequest(alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest) RPCBlockWriteRequest(alluxio.network.protocol.RPCBlockWriteRequest) RPCBlockReadRequest(alluxio.network.protocol.RPCBlockReadRequest) RPCFileWriteRequest(alluxio.network.protocol.RPCFileWriteRequest) RPCErrorResponse(alluxio.network.protocol.RPCErrorResponse) RPCProtoMessage(alluxio.network.protocol.RPCProtoMessage) IOException(java.io.IOException) RPCFileReadRequest(alluxio.network.protocol.RPCFileReadRequest)

Example 2 with RPCFileReadRequest

use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.

the class NettyDataServerTest method readFile.

@Test
public void readFile() throws Exception {
    long tempUfsFileId = 1;
    long offset = 0;
    long length = 3;
    when(mFileSystemWorker.getUfsInputStream(tempUfsFileId, offset)).thenReturn(new ByteArrayInputStream("abc".getBytes(Charsets.UTF_8)));
    RPCResponse response = request(new RPCFileReadRequest(tempUfsFileId, offset, length));
    // Verify that the 3 bytes were read.
    assertEquals("abc", Charsets.UTF_8.decode(response.getPayloadDataBuffer().getReadOnlyByteBuffer()).toString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RPCResponse(alluxio.network.protocol.RPCResponse) RPCFileReadRequest(alluxio.network.protocol.RPCFileReadRequest) Test(org.junit.Test)

Example 3 with RPCFileReadRequest

use of alluxio.network.protocol.RPCFileReadRequest in project alluxio by Alluxio.

the class NettyDataServerTest method fileSystemWorkerExceptionCausesFailStatusOnRead.

@Test
public void fileSystemWorkerExceptionCausesFailStatusOnRead() throws Exception {
    when(mFileSystemWorker.getUfsInputStream(1, 0)).thenThrow(new RuntimeException());
    RPCResponse response = request(new RPCFileReadRequest(1, 0, 3));
    // Verify that the write request failed.
    assertEquals(RPCResponse.Status.UFS_READ_FAILED, response.getStatus());
}
Also used : RPCResponse(alluxio.network.protocol.RPCResponse) RPCFileReadRequest(alluxio.network.protocol.RPCFileReadRequest) Test(org.junit.Test)

Aggregations

RPCFileReadRequest (alluxio.network.protocol.RPCFileReadRequest)3 RPCResponse (alluxio.network.protocol.RPCResponse)2 Test (org.junit.Test)2 RPCBlockReadRequest (alluxio.network.protocol.RPCBlockReadRequest)1 RPCBlockWriteRequest (alluxio.network.protocol.RPCBlockWriteRequest)1 RPCErrorResponse (alluxio.network.protocol.RPCErrorResponse)1 RPCFileWriteRequest (alluxio.network.protocol.RPCFileWriteRequest)1 RPCProtoMessage (alluxio.network.protocol.RPCProtoMessage)1 RPCUnderFileSystemBlockReadRequest (alluxio.network.protocol.RPCUnderFileSystemBlockReadRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1