use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.
the class BlockOutStream method createRemoteBlockOutStream.
/**
* Creates a new remote block output stream.
*
* @param blockId the block id
* @param blockSize the block size
* @param workerNetAddress the worker network address
* @param context the file system context
* @param options the options
* @throws IOException if an I/O error occurs
* @return the {@link BlockOutStream} instance created
*/
public static BlockOutStream createRemoteBlockOutStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, OutStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient client = closer.register(context.createBlockWorkerClient(workerNetAddress));
PacketOutStream outStream = PacketOutStream.createNettyPacketOutStream(context, client.getDataServerAddress(), client.getSessionId(), blockId, blockSize, options.getWriteTier(), Protocol.RequestType.ALLUXIO_BLOCK);
closer.register(outStream);
return new BlockOutStream(outStream, blockId, blockSize, client, options);
} catch (IOException e) {
closer.close();
throw e;
}
}
use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.
the class BlockWorkerClientAuthenticationIntegrationTest method authenticationOperationTest.
/**
* Tests Alluxio Worker client connects or disconnects to the Worker.
*/
private void authenticationOperationTest() throws Exception {
BlockWorkerClient blockWorkerClient = FileSystemContext.INSTANCE.createBlockWorkerClient(mLocalAlluxioClusterResource.get().getWorkerAddress(), (long) 1);
blockWorkerClient.close();
}
use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.
the class BlockOutStream method createLocalBlockOutStream.
/**
* Creates a new local block output stream.
*
* @param blockId the block id
* @param blockSize the block size
* @param workerNetAddress the worker network address
* @param context the file system context
* @param options the options
* @throws IOException if an I/O error occurs
* @return the {@link BlockOutStream} instance created
*/
public static BlockOutStream createLocalBlockOutStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, OutStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient client = closer.register(context.createBlockWorkerClient(workerNetAddress));
PacketOutStream outStream = PacketOutStream.createLocalPacketOutStream(client, blockId, blockSize, options.getWriteTier());
closer.register(outStream);
return new BlockOutStream(outStream, blockId, blockSize, client, options);
} catch (IOException e) {
closer.close();
throw e;
}
}
use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.
the class PacketOutStream method createReplicatedPacketOutStream.
/**
* Creates a {@link PacketOutStream} that writes to a list of locations.
*
* @param context the file system context
* @param clients a list of block worker clients
* @param id the ID (block ID or UFS file ID)
* @param length the block or file length
* @param tier the target tier
* @param type the request type (either block write or UFS file write)
* @return the {@link PacketOutStream} created
* @throws IOException if it fails to create the object
*/
public static PacketOutStream createReplicatedPacketOutStream(FileSystemContext context, List<BlockWorkerClient> clients, long id, long length, int tier, Protocol.RequestType type) throws IOException {
String localHost = NetworkAddressUtils.getClientHostName();
List<PacketWriter> packetWriters = new ArrayList<>();
for (BlockWorkerClient client : clients) {
if (client.getWorkerNetAddress().getHost().equals(localHost)) {
packetWriters.add(LocalFilePacketWriter.create(client, id, tier));
} else {
packetWriters.add(new NettyPacketWriter(context, client.getDataServerAddress(), id, length, client.getSessionId(), tier, type));
}
}
return new PacketOutStream(packetWriters, length);
}
use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.
the class BlockInStream method createRemoteBlockInStream.
/**
* Creates an instance of remote {@link BlockInStream} that reads from a remote worker.
*
* @param blockId the block ID
* @param blockSize the block size
* @param workerNetAddress the worker network address
* @param context the file system context
* @param options the options
* @throws IOException if it fails to create an instance
* @return the {@link BlockInStream} created
*/
// TODO(peis): Use options idiom (ALLUXIO-2579).
public static BlockInStream createRemoteBlockInStream(long blockId, long blockSize, WorkerNetAddress workerNetAddress, FileSystemContext context, InStreamOptions options) throws IOException {
Closer closer = Closer.create();
try {
BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
LockBlockResource lockBlockResource = closer.register(blockWorkerClient.lockBlock(blockId, LockBlockOptions.defaults()));
PacketInStream inStream = closer.register(PacketInStream.createNettyPacketInStream(context, blockWorkerClient.getDataServerAddress(), blockId, lockBlockResource.getResult().getLockId(), blockWorkerClient.getSessionId(), blockSize, false, Protocol.RequestType.ALLUXIO_BLOCK));
blockWorkerClient.accessBlock(blockId);
return new BlockInStream(inStream, blockWorkerClient, closer, options);
} catch (AlluxioException | IOException e) {
CommonUtils.closeQuitely(closer);
throw CommonUtils.castToIOException(e);
}
}
Aggregations