Search in sources :

Example 6 with RawClient

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

the class SegmentHelper method sealSegment.

/**
 * This method sends segment sealed message for the specified segment.
 *
 * @param scope               stream scope
 * @param stream              stream name
 * @param segmentId           number of segment to be sealed
 * @param delegationToken     the token to be presented to segmentstore.
 * @param clientRequestId     client-generated id for end-to-end tracing
 * @return void
 */
public CompletableFuture<Void> sealSegment(final String scope, final String stream, final long segmentId, final String delegationToken, final long clientRequestId) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final String qualifiedName = getQualifiedStreamSegmentName(scope, stream, segmentId);
    final WireCommandType type = WireCommandType.SEAL_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    return sendRequest(connection, clientRequestId, new WireCommands.SealSegment(requestId, qualifiedName, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedName, WireCommands.SealSegment.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)

Example 7 with RawClient

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

the class SegmentHelper method updateSegmentAttribute.

public CompletableFuture<WireCommands.SegmentAttributeUpdated> updateSegmentAttribute(String qualifiedName, UUID attributeId, long newValue, long existingValue, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.UPDATE_SEGMENT_ATTRIBUTE;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.UpdateSegmentAttribute request = new WireCommands.UpdateSegmentAttribute(requestId, qualifiedName, attributeId, newValue, existingValue, delegationToken);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, qualifiedName, WireCommands.UpdateSegmentAttribute.class, type);
        assert r instanceof WireCommands.SegmentAttributeUpdated;
        return (WireCommands.SegmentAttributeUpdated) r;
    });
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 8 with RawClient

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

the class SegmentHelper method updateTableEntries.

public CompletableFuture<List<TableSegmentKeyVersion>> updateTableEntries(final String tableName, final PravegaNodeUri uri, final List<TableSegmentEntry> entries, String delegationToken, final long clientRequestId) {
    final WireCommandType type = WireCommandType.UPDATE_TABLE_ENTRIES;
    List<Map.Entry<WireCommands.TableKey, WireCommands.TableValue>> wireCommandEntries = entries.stream().map(te -> {
        final WireCommands.TableKey key = convertToWireCommand(te.getKey());
        final WireCommands.TableValue value = new WireCommands.TableValue(te.getValue());
        return new AbstractMap.SimpleImmutableEntry<>(key, value);
    }).collect(Collectors.toList());
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.UpdateTableEntries request = new WireCommands.UpdateTableEntries(requestId, tableName, delegationToken, new WireCommands.TableEntries(wireCommandEntries), WireCommands.NULL_TABLE_SEGMENT_OFFSET);
    return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
        handleReply(clientRequestId, rpl, connection, tableName, WireCommands.UpdateTableEntries.class, type);
        return ((WireCommands.TableEntriesUpdated) rpl).getUpdatedVersions().stream().map(TableSegmentKeyVersion::from).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) AbstractMap(java.util.AbstractMap) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 9 with RawClient

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

the class SegmentHelper method truncateSegment.

public CompletableFuture<Void> truncateSegment(final String scope, final String stream, final long segmentId, final long offset, final String delegationToken, final long clientRequestId) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final String qualifiedStreamSegmentName = getQualifiedStreamSegmentName(scope, stream, segmentId);
    final WireCommandType type = WireCommandType.TRUNCATE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    return sendRequest(connection, clientRequestId, new WireCommands.TruncateSegment(requestId, qualifiedStreamSegmentName, offset, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedStreamSegmentName, WireCommands.TruncateSegment.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)

Example 10 with RawClient

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

the class SegmentHelper method removeTableKeys.

/**
 * This method sends a WireCommand to remove table keys.
 *
 * @param tableName       Qualified table name.
 * @param keys            List of {@link TableSegmentKey}s to be removed. Only if all the elements in the list has version
 *                        as {@link TableSegmentKeyVersion#NO_VERSION} then an unconditional update/removal is performed.
 *                        Else an atomic conditional update (removal) is performed.
 * @param delegationToken The token to be presented to the Segment Store.
 * @param clientRequestId Request id.
 * @return A CompletableFuture that will complete normally when the provided keys are deleted.
 * If the operation failed, the future will be failed with the causing exception. If the exception can be
 * retried then the future will be failed with {@link WireCommandFailedException}.
 */
public CompletableFuture<Void> removeTableKeys(final String tableName, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
    final Controller.NodeUri uri = getTableUri(tableName);
    final WireCommandType type = WireCommandType.REMOVE_TABLE_KEYS;
    List<WireCommands.TableKey> keyList = keys.stream().map(x -> {
        WireCommands.TableKey key = convertToWireCommand(x);
        return key;
    }).collect(Collectors.toList());
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.RemoveTableKeys request = new WireCommands.RemoveTableKeys(requestId, tableName, delegationToken, keyList, WireCommands.NULL_TABLE_SEGMENT_OFFSET);
    return sendRequest(connection, clientRequestId, request).thenAccept(rpl -> handleReply(clientRequestId, rpl, connection, tableName, WireCommands.RemoveTableKeys.class, type));
}
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) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) 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