Search in sources :

Example 21 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method readTableEntries.

public CompletableFuture<HashTableIteratorItem<TableSegmentEntry>> readTableEntries(final String tableName, final PravegaNodeUri uri, final int suggestedEntryCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.READ_TABLE_ENTRIES;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
    WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
    WireCommands.ReadTableEntries request = new WireCommands.ReadTableEntries(requestId, tableName, delegationToken, suggestedEntryCount, args);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableEntries.class, type);
        WireCommands.TableEntriesRead tableEntriesRead = (WireCommands.TableEntriesRead) rpl;
        final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableEntriesRead.getContinuationToken());
        final List<TableSegmentEntry> entries = tableEntriesRead.getEntries().getEntries().stream().map(e -> {
            WireCommands.TableKey k = e.getKey();
            return TableSegmentEntry.versioned(k.getData(), e.getValue().getData(), k.getKeyVersion());
        }).collect(Collectors.toList());
        return new HashTableIteratorItem<>(newState, entries);
    });
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Unpooled(io.netty.buffer.Unpooled) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Request(io.pravega.shared.protocol.netty.Request) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Config(io.pravega.controller.util.Config) Futures(io.pravega.common.concurrent.Futures) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) ModelHelper(io.pravega.client.control.impl.ModelHelper) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) RawClient(io.pravega.client.connection.impl.RawClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) NameUtils.getQualifiedStreamSegmentName(io.pravega.shared.NameUtils.getQualifiedStreamSegmentName) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) Host(io.pravega.common.cluster.Host) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) NameUtils.getTransactionNameFromId(io.pravega.shared.NameUtils.getTransactionNameFromId) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) WireCommands(io.pravega.shared.protocol.netty.WireCommands) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem)

Example 22 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method readTableKeys.

public CompletableFuture<HashTableIteratorItem<TableSegmentKey>> readTableKeys(final String tableName, final PravegaNodeUri uri, final int suggestedKeyCount, final HashTableIteratorItem.State state, final String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.READ_TABLE_KEYS;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    final HashTableIteratorItem.State token = (state == null) ? HashTableIteratorItem.State.EMPTY : state;
    WireCommands.TableIteratorArgs args = new WireCommands.TableIteratorArgs(token.getToken(), Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
    WireCommands.ReadTableKeys request = new WireCommands.ReadTableKeys(requestId, tableName, delegationToken, suggestedKeyCount, args);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTableKeys.class, type);
        WireCommands.TableKeysRead tableKeysRead = (WireCommands.TableKeysRead) rpl;
        final HashTableIteratorItem.State newState = HashTableIteratorItem.State.fromBytes(tableKeysRead.getContinuationToken());
        final List<TableSegmentKey> keys = tableKeysRead.getKeys().stream().map(k -> TableSegmentKey.versioned(k.getData(), k.getKeyVersion())).collect(Collectors.toList());
        return new HashTableIteratorItem<>(newState, keys);
    });
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Unpooled(io.netty.buffer.Unpooled) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Request(io.pravega.shared.protocol.netty.Request) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Config(io.pravega.controller.util.Config) Futures(io.pravega.common.concurrent.Futures) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) ModelHelper(io.pravega.client.control.impl.ModelHelper) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) RawClient(io.pravega.client.connection.impl.RawClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) NameUtils.getQualifiedStreamSegmentName(io.pravega.shared.NameUtils.getQualifiedStreamSegmentName) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) Host(io.pravega.common.cluster.Host) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) NameUtils.getTransactionNameFromId(io.pravega.shared.NameUtils.getTransactionNameFromId) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) WireCommands(io.pravega.shared.protocol.netty.WireCommands) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem)

Example 23 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method readTable.

public CompletableFuture<List<TableSegmentEntry>> readTable(final String tableName, final PravegaNodeUri uri, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.READ_TABLE;
    // the version is always NO_VERSION as read returns the latest version of value.
    List<WireCommands.TableKey> keyList = keys.stream().map(k -> new WireCommands.TableKey(k.getKey(), k.getVersion().getSegmentVersion())).collect(Collectors.toList());
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.ReadTable request = new WireCommands.ReadTable(requestId, tableName, delegationToken, keyList);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.ReadTable.class, type);
        return ((WireCommands.TableRead) rpl).getEntries().getEntries().stream().map(this::convertFromWireCommand).collect(Collectors.toList());
    });
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) Unpooled(io.netty.buffer.Unpooled) TagLogger(io.pravega.common.tracing.TagLogger) Pair(org.apache.commons.lang3.tuple.Pair) Duration(java.time.Duration) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) CompletionException(java.util.concurrent.CompletionException) Request(io.pravega.shared.protocol.netty.Request) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Config(io.pravega.controller.util.Config) Futures(io.pravega.common.concurrent.Futures) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) ModelHelper(io.pravega.client.control.impl.ModelHelper) Exceptions(io.pravega.common.Exceptions) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) NameUtils.getSegmentNumber(io.pravega.shared.NameUtils.getSegmentNumber) RawClient(io.pravega.client.connection.impl.RawClient) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) NameUtils.getQualifiedStreamSegmentName(io.pravega.shared.NameUtils.getQualifiedStreamSegmentName) RecordHelper(io.pravega.controller.store.stream.records.RecordHelper) Host(io.pravega.common.cluster.Host) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) WireCommand(io.pravega.shared.protocol.netty.WireCommand) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) HostControllerStore(io.pravega.controller.store.host.HostControllerStore) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) ScalingPolicy(io.pravega.client.stream.ScalingPolicy) NameUtils.getTransactionNameFromId(io.pravega.shared.NameUtils.getTransactionNameFromId) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 24 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method updatePolicy.

public CompletableFuture<Void> updatePolicy(String scope, String stream, ScalingPolicy policy, long segmentId, String delegationToken, long clientRequestId) {
    final String qualifiedName = getQualifiedStreamSegmentName(scope, stream, segmentId);
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final WireCommandType type = WireCommandType.UPDATE_SEGMENT_POLICY;
    Pair<Byte, Integer> extracted = extractFromPolicy(policy);
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.UpdateSegmentPolicy request = new WireCommands.UpdateSegmentPolicy(requestId, qualifiedName, extracted.getLeft(), extracted.getRight(), delegationToken);
    return sendRequest(connection, clientRequestId, request).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedName, WireCommands.UpdateSegmentPolicy.class, type));
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 25 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method readSegment.

public CompletableFuture<WireCommands.SegmentRead> readSegment(String qualifiedName, long offset, int length, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.READ_SEGMENT;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.ReadSegment request = new WireCommands.ReadSegment(qualifiedName, offset, length, delegationToken, requestId);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, qualifiedName, WireCommands.ReadSegment.class, type);
        assert r instanceof WireCommands.SegmentRead;
        return (WireCommands.SegmentRead) r;
    });
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Aggregations

RawClient (io.pravega.client.connection.impl.RawClient)34 WireCommands (io.pravega.shared.protocol.netty.WireCommands)25 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)24 TokenExpiredException (io.pravega.auth.TokenExpiredException)17 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)17 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)16 Reply (io.pravega.shared.protocol.netty.Reply)15 VisibleForTesting (com.google.common.annotations.VisibleForTesting)14 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)14 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)14 Exceptions (io.pravega.common.Exceptions)14 UUID (java.util.UUID)14 CompletableFuture (java.util.concurrent.CompletableFuture)14 CompletionException (java.util.concurrent.CompletionException)14 Futures (io.pravega.common.concurrent.Futures)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 SneakyThrows (lombok.SneakyThrows)12 AuthenticationException (io.pravega.auth.AuthenticationException)10 Unpooled (io.netty.buffer.Unpooled)9 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)8