Search in sources :

Example 21 with DelegationToken

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

the class SegmentHelper method getSegmentInfo.

public CompletableFuture<WireCommands.StreamSegmentInfo> getSegmentInfo(String scope, String stream, int segmentNumber, HostControllerStore hostControllerStore, ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<WireCommands.StreamSegmentInfo> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.GET_STREAM_SEGMENT_INFO;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("getSegmentInfo {}/{}/{} connectionDropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("getSegmentInfo {}/{}/{} WrongHost", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void streamSegmentInfo(WireCommands.StreamSegmentInfo streamInfo) {
            log.info("getSegmentInfo {}/{}/{} got response", scope, stream, segmentNumber);
            result.complete(streamInfo);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("getSegmentInfo {}/{}/{} failed", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.GetStreamSegmentInfo request = new WireCommands.GetStreamSegmentInfo(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 22 with DelegationToken

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

the class SegmentHelper method truncateSegment.

public CompletableFuture<Boolean> truncateSegment(final String scope, final String stream, final int segmentNumber, final long offset, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<Boolean> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.TRUNCATE_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            log.warn("truncateSegment {}/{}/{} Connection dropped", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
        }

        @Override
        public void wrongHost(WireCommands.WrongHost wrongHost) {
            log.warn("truncateSegment {}/{}/{} Wrong host", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
        }

        @Override
        public void segmentTruncated(WireCommands.SegmentTruncated segmentTruncated) {
            log.info("truncateSegment {}/{}/{} SegmentTruncated", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentIsTruncated(WireCommands.SegmentIsTruncated segmentIsTruncated) {
            log.info("truncateSegment {}/{}/{} SegmentIsTruncated", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("truncateSegment {}/{}/{} error", scope, stream, segmentNumber, error);
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
        }
    };
    WireCommands.TruncateSegment request = new WireCommands.TruncateSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), offset, delegationToken);
    sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) AuthenticationException(io.pravega.common.auth.AuthenticationException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 23 with DelegationToken

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

the class SegmentHelper method getTableSegmentInfo.

/**
 * This method sends a WireCommand to get information about a Table Segment.
 *
 * @param tableName           Qualified table name.
 * @param delegationToken     The token to be presented to the segmentstore.
 * @param clientRequestId     Request id.
 * @return A CompletableFuture that, when completed successfully, will return information about the Table Segment.
 * 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<WireCommands.TableSegmentInfo> getTableSegmentInfo(final String tableName, String delegationToken, final long clientRequestId) {
    final Controller.NodeUri uri = getTableUri(tableName);
    final WireCommandType type = WireCommandType.GET_TABLE_SEGMENT_INFO;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    // All Controller Metadata Segments are non-sorted.
    return sendRequest(connection, clientRequestId, new WireCommands.GetTableSegmentInfo(requestId, tableName, delegationToken)).thenApply(r -> {
        handleReply(clientRequestId, r, connection, tableName, WireCommands.GetTableSegmentInfo.class, type);
        assert r instanceof WireCommands.TableSegmentInfo;
        return (WireCommands.TableSegmentInfo) r;
    });
}
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 24 with DelegationToken

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

the class SegmentHelper method deleteSegment.

public CompletableFuture<Void> deleteSegment(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 qualifiedStreamSegmentName = getQualifiedStreamSegmentName(scope, stream, segmentId);
    final WireCommandType type = WireCommandType.DELETE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    return sendRequest(connection, clientRequestId, new WireCommands.DeleteSegment(requestId, qualifiedStreamSegmentName, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedStreamSegmentName, WireCommands.DeleteSegment.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 25 with DelegationToken

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

the class SegmentHelper method deleteTableSegment.

/**
 * This method sends a WireCommand to delete a table segment.
 *
 * @param tableName           Qualified table name.
 * @param mustBeEmpty         Flag to check if the table segment should be empty before deletion.
 * @param delegationToken     The token to be presented to the segmentstore.
 * @param clientRequestId     Request id.
 * @return A CompletableFuture that, when completed normally, will indicate the table segment deletion completed
 * successfully. 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> deleteTableSegment(final String tableName, final boolean mustBeEmpty, String delegationToken, final long clientRequestId) {
    final Controller.NodeUri uri = getTableUri(tableName);
    final WireCommandType type = WireCommandType.DELETE_TABLE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    return sendRequest(connection, clientRequestId, new WireCommands.DeleteTableSegment(requestId, tableName, mustBeEmpty, delegationToken)).thenAccept(rpl -> handleReply(clientRequestId, rpl, connection, tableName, WireCommands.DeleteTableSegment.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)

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