Search in sources :

Example 1 with MoveBlockRequest

use of alluxio.grpc.MoveBlockRequest in project alluxio by Alluxio.

the class MoveDefinition method runTask.

/**
 * {@inheritDoc}
 *
 * This task will move the given block.
 */
@Override
public SerializableVoid runTask(MoveConfig config, SerializableVoid args, RunTaskContext context) throws Exception {
    long blockId = config.getBlockId();
    String localHostName = NetworkAddressUtils.getConnectHost(ServiceType.WORKER_RPC, ServerConfiguration.global());
    List<BlockWorkerInfo> workerInfoList = context.getFsContext().getCachedWorkers();
    WorkerNetAddress localNetAddress = null;
    for (BlockWorkerInfo workerInfo : workerInfoList) {
        if (workerInfo.getNetAddress().getHost().equals(localHostName)) {
            localNetAddress = workerInfo.getNetAddress();
            break;
        }
    }
    if (localNetAddress == null) {
        String message = String.format("Cannot find a local block worker to move block %d", blockId);
        throw new NotFoundException(message);
    }
    MoveBlockRequest request = MoveBlockRequest.newBuilder().setBlockId(blockId).setMediumType(config.getMediumType()).build();
    try (CloseableResource<BlockWorkerClient> blockWorker = context.getFsContext().acquireBlockWorkerClient(localNetAddress)) {
        blockWorker.get().moveBlock(request);
    }
    return null;
}
Also used : WorkerNetAddress(alluxio.wire.WorkerNetAddress) BlockWorkerInfo(alluxio.client.block.BlockWorkerInfo) MoveBlockRequest(alluxio.grpc.MoveBlockRequest) NotFoundException(alluxio.exception.status.NotFoundException) BlockWorkerClient(alluxio.client.block.stream.BlockWorkerClient)

Aggregations

BlockWorkerInfo (alluxio.client.block.BlockWorkerInfo)1 BlockWorkerClient (alluxio.client.block.stream.BlockWorkerClient)1 NotFoundException (alluxio.exception.status.NotFoundException)1 MoveBlockRequest (alluxio.grpc.MoveBlockRequest)1 WorkerNetAddress (alluxio.wire.WorkerNetAddress)1