Search in sources :

Example 26 with DelegationToken

use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken 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 27 with DelegationToken

use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken 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 28 with DelegationToken

use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken 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 29 with DelegationToken

use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken 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 30 with DelegationToken

use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.

the class SegmentHelper method createTransaction.

public CompletableFuture<Void> createTransaction(final String scope, final String stream, final long segmentId, final UUID txId, final String delegationToken, final long clientRequestId, final long rolloverSizeBytes) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final String transactionName = getTransactionName(scope, stream, segmentId, txId);
    final WireCommandType type = WireCommandType.CREATE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.CreateSegment request = new WireCommands.CreateSegment(requestId, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, delegationToken, rolloverSizeBytes);
    return sendRequest(connection, clientRequestId, request).thenAccept(r -> handleReply(clientRequestId, r, connection, transactionName, WireCommands.CreateSegment.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)

Aggregations

Controller (io.pravega.controller.stream.api.grpc.v1.Controller)37 CompletableFuture (java.util.concurrent.CompletableFuture)29 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)23 UUID (java.util.UUID)22 VisibleForTesting (com.google.common.annotations.VisibleForTesting)21 ImmutableMap (com.google.common.collect.ImmutableMap)21 ModelHelper (io.pravega.client.control.impl.ModelHelper)21 Exceptions (io.pravega.common.Exceptions)21 TagLogger (io.pravega.common.tracing.TagLogger)21 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)21 List (java.util.List)21 CompletionException (java.util.concurrent.CompletionException)21 TimeoutException (java.util.concurrent.TimeoutException)21 Collectors (java.util.stream.Collectors)21 LoggerFactory (org.slf4j.LoggerFactory)21 WireCommands (io.pravega.shared.protocol.netty.WireCommands)20 AuthenticationException (io.pravega.auth.AuthenticationException)19 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)19 Pair (org.apache.commons.lang3.tuple.Pair)19 RequestTag (io.pravega.common.tracing.RequestTag)16