Search in sources :

Example 6 with BlockWorkerClient

use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.

the class BlockInStream method createUfsBlockInStream.

/**
   * Creates an instance of {@link BlockInStream}.
   *
   * This method keeps polling the block worker until the block is cached to Alluxio or
   * it successfully acquires a UFS read token with a timeout.
   * (1) If the block is cached to Alluxio after polling, it returns {@link BlockInStream}
   *     to read the block from Alluxio storage.
   * (2) If a UFS read token is acquired after polling, it returns {@link BlockInStream}
   *     to read the block from an Alluxio worker that reads the block from UFS.
   * (3) If the polling times out, an {@link IOException} with cause
   *     {@link alluxio.exception.UfsBlockAccessTokenUnavailableException} is thrown.
   *
   * @param context the file system context
   * @param ufsPath the UFS path
   * @param blockId the block ID
   * @param blockSize the block size
   * @param blockStart the position at which the block starts in the file
   * @param workerNetAddress the worker network address
   * @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 createUfsBlockInStream(FileSystemContext context, String ufsPath, long blockId, long blockSize, long blockStart, WorkerNetAddress workerNetAddress, InStreamOptions options) throws IOException {
    Closer closer = Closer.create();
    try {
        BlockWorkerClient blockWorkerClient = closer.register(context.createBlockWorkerClient(workerNetAddress));
        LockBlockOptions lockBlockOptions = LockBlockOptions.defaults().setUfsPath(ufsPath).setOffset(blockStart).setBlockSize(blockSize).setMaxUfsReadConcurrency(options.getMaxUfsReadConcurrency());
        LockBlockResult lockBlockResult = closer.register(blockWorkerClient.lockUfsBlock(blockId, lockBlockOptions)).getResult();
        PacketInStream inStream;
        if (lockBlockResult.getLockBlockStatus().blockInAlluxio()) {
            boolean local = blockWorkerClient.getDataServerAddress().getHostName().equals(NetworkAddressUtils.getLocalHostName());
            if (local) {
                inStream = closer.register(PacketInStream.createLocalPacketInstream(lockBlockResult.getBlockPath(), blockId, blockSize));
            } else {
                inStream = closer.register(PacketInStream.createNettyPacketInStream(context, blockWorkerClient.getDataServerAddress(), blockId, lockBlockResult.getLockId(), blockWorkerClient.getSessionId(), blockSize, false, Protocol.RequestType.ALLUXIO_BLOCK));
            }
            blockWorkerClient.accessBlock(blockId);
        } else {
            Preconditions.checkState(lockBlockResult.getLockBlockStatus().ufsTokenAcquired());
            inStream = closer.register(PacketInStream.createNettyPacketInStream(context, blockWorkerClient.getDataServerAddress(), blockId, lockBlockResult.getLockId(), blockWorkerClient.getSessionId(), blockSize, !options.getAlluxioStorageType().isStore(), Protocol.RequestType.UFS_BLOCK));
        }
        return new BlockInStream(inStream, blockWorkerClient, closer, options);
    } catch (AlluxioException | IOException e) {
        CommonUtils.closeQuitely(closer);
        throw CommonUtils.castToIOException(e);
    }
}
Also used : Closer(com.google.common.io.Closer) LockBlockOptions(alluxio.client.block.options.LockBlockOptions) LockBlockResult(alluxio.wire.LockBlockResult) BlockWorkerClient(alluxio.client.block.BlockWorkerClient) IOException(java.io.IOException) AlluxioException(alluxio.exception.AlluxioException)

Example 7 with BlockWorkerClient

use of alluxio.client.block.BlockWorkerClient in project alluxio by Alluxio.

the class BlockWorkerClientAuthenticationIntegrationTest method customAuthenticationDenyConnect.

@Test(timeout = 10000)
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_AUTHENTICATION_TYPE, "CUSTOM", PropertyKey.Name.SECURITY_AUTHENTICATION_CUSTOM_PROVIDER_CLASS, NameMatchAuthenticationProvider.FULL_CLASS_NAME, PropertyKey.Name.SECURITY_LOGIN_USERNAME, "alluxio", PropertyKey.Name.USER_RPC_RETRY_MAX_NUM_RETRY, "1" })
public void customAuthenticationDenyConnect() throws Exception {
    boolean failedToConnect = false;
    // Using no-alluxio as loginUser to connect to Worker, the IOException will be thrown
    LoginUserTestUtils.resetLoginUser("no-alluxio");
    try (BlockWorkerClient blockWorkerClient = FileSystemContext.INSTANCE.createBlockWorkerClient(mLocalAlluxioClusterResource.get().getWorkerAddress(), (long) 1)) {
        // Just to supress the "Empty try block" warning in CheckStyle.
        failedToConnect = false;
    } catch (IOException e) {
        if (e.getCause() instanceof TTransportException) {
            failedToConnect = true;
        }
    } finally {
        ClientTestUtils.resetClient();
    }
    Assert.assertTrue(failedToConnect);
}
Also used : TTransportException(org.apache.thrift.transport.TTransportException) BlockWorkerClient(alluxio.client.block.BlockWorkerClient) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

BlockWorkerClient (alluxio.client.block.BlockWorkerClient)7 IOException (java.io.IOException)5 Closer (com.google.common.io.Closer)4 AlluxioException (alluxio.exception.AlluxioException)2 LockBlockOptions (alluxio.client.block.options.LockBlockOptions)1 LockBlockResource (alluxio.client.resource.LockBlockResource)1 LockBlockResult (alluxio.wire.LockBlockResult)1 ArrayList (java.util.ArrayList)1 TTransportException (org.apache.thrift.transport.TTransportException)1 Test (org.junit.Test)1