Search in sources :

Example 1 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<UUID> createTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final CompletableFuture<UUID> result = new CompletableFuture<>();
    final WireCommandType type = WireCommandType.CREATE_TRANSACTION;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void transactionCreated(WireCommands.TransactionCreated transactionCreated) {
            log.debug("createTransaction {}/{}/{} TransactionCreated", scope, stream, segmentNumber);
            result.complete(txId);
        }

        @Override
        public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
            log.debug("createTransaction {}/{}/{} TransactionCreated", scope, stream, segmentNumber);
            result.complete(txId);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("createTransaction {}/{}/{} 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.CreateTransaction request = new WireCommands.CreateTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, 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) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 2 with DelegationToken

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

the class SegmentHelper method abortTransaction.

public CompletableFuture<TxnStatus> abortTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final CompletableFuture<TxnStatus> result = new CompletableFuture<>();
    final WireCommandType type = WireCommandType.ABORT_TRANSACTION;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void transactionCommitted(WireCommands.TransactionCommitted transactionCommitted) {
            log.warn("abortTransaction {}/{}/{} TransactionCommitted", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.PreconditionFailed));
        }

        @Override
        public void transactionAborted(WireCommands.TransactionAborted transactionDropped) {
            log.debug("abortTransaction {}/{}/{} transactionAborted", scope, stream, segmentNumber);
            result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
        }

        @Override
        public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
            log.info("abortTransaction {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
            result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
        }

        @Override
        public void processingFailure(Exception error) {
            log.info("abortTransaction {}/{}/{} 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.AbortTransaction request = new WireCommands.AbortTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, 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) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)

Example 3 with DelegationToken

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

the class SegmentHelper method commitTransaction.

public CompletableFuture<TxnStatus> commitTransaction(final String scope, final String stream, final int segmentNumber, final UUID txId, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final CompletableFuture<TxnStatus> result = new CompletableFuture<>();
    final WireCommandType type = WireCommandType.COMMIT_TRANSACTION;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void transactionCommitted(WireCommands.TransactionCommitted transactionCommitted) {
            log.debug("commitTransaction {}/{}/{} TransactionCommitted", scope, stream, segmentNumber);
            result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
        }

        @Override
        public void transactionAborted(WireCommands.TransactionAborted transactionAborted) {
            log.warn("commitTransaction {}/{}/{} Transaction aborted", scope, stream, segmentNumber);
            result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.PreconditionFailed));
        }

        @Override
        public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
            log.info("commitTransaction {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
            result.complete(TxnStatus.newBuilder().setStatus(TxnStatus.Status.SUCCESS).build());
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("commitTransaction {}/{}/{} 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.CommitTransaction request = new WireCommands.CommitTransaction(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), txId, 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) TxnStatus(io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)

Example 4 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, int segmentNumber, HostControllerStore hostControllerStore, ConnectionFactory clientCF, String delegationToken) {
    final CompletableFuture<Void> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.UPDATE_SEGMENT_POLICY;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void segmentPolicyUpdated(WireCommands.SegmentPolicyUpdated policyUpdated) {
            log.info("updatePolicy {}/{}/{} SegmentPolicyUpdated", scope, stream, segmentNumber);
            result.complete(null);
        }

        @Override
        public void processingFailure(Exception error) {
            log.info("updatePolicy {}/{}/{} 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));
        }
    };
    Pair<Byte, Integer> extracted = extractFromPolicy(policy);
    WireCommands.UpdateSegmentPolicy request = new WireCommands.UpdateSegmentPolicy(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), extracted.getLeft(), extracted.getRight(), 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 5 with DelegationToken

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

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