Search in sources :

Example 1 with AuthenticationException

use of io.pravega.common.auth.AuthenticationException 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 AuthenticationException

use of io.pravega.common.auth.AuthenticationException 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 AuthenticationException

use of io.pravega.common.auth.AuthenticationException 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 AuthenticationException

use of io.pravega.common.auth.AuthenticationException 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 AuthenticationException

use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.

the class SegmentHelper method createSegment.

public CompletableFuture<Boolean> createSegment(final String scope, final String stream, final int segmentNumber, final ScalingPolicy policy, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String controllerToken) {
    final CompletableFuture<Boolean> result = new CompletableFuture<>();
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
    final WireCommandType type = WireCommandType.CREATE_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
            log.info("CreateSegment {}/{}/{} segmentAlreadyExists", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentCreated(WireCommands.SegmentCreated segmentCreated) {
            log.info("CreateSegment {}/{}/{} SegmentCreated", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("CreateSegment {}/{}/{} threw exception", 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.CreateSegment request = new WireCommands.CreateSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), extracted.getLeft(), extracted.getRight(), controllerToken);
    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)

Aggregations

AuthenticationException (io.pravega.common.auth.AuthenticationException)24 CompletableFuture (java.util.concurrent.CompletableFuture)19 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)14 WireCommands (io.pravega.shared.protocol.netty.WireCommands)10 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)9 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)9 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)9 AuthHandler (io.pravega.auth.AuthHandler)6 READ (io.pravega.auth.AuthHandler.Permissions.READ)5 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)5 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)5 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)5 ConnectionFactory (io.pravega.client.netty.impl.ConnectionFactory)5 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)5 ReaderGroup (io.pravega.client.stream.ReaderGroup)5 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)5 ClientFactoryImpl (io.pravega.client.stream.impl.ClientFactoryImpl)5 LoggerHelpers (io.pravega.common.LoggerHelpers)5 ControllerService (io.pravega.controller.server.ControllerService)5 LocalController (io.pravega.controller.server.eventProcessor.LocalController)5