Search in sources :

Example 11 with FailingReplyProcessor

use of io.pravega.shared.protocol.netty.FailingReplyProcessor in project pravega by pravega.

the class SegmentHelper method deleteSegment.

public CompletableFuture<Boolean> deleteSegment(final String scope, final String stream, final int segmentNumber, 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.DELETE_SEGMENT;
    final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

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

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

        @Override
        public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
            log.info("deleteSegment {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
            log.info("deleteSegment {}/{}/{} SegmentDeleted", scope, stream, segmentNumber);
            result.complete(true);
        }

        @Override
        public void processingFailure(Exception error) {
            log.error("deleteSegment {}/{}/{} 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.DeleteSegment request = new WireCommands.DeleteSegment(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 12 with FailingReplyProcessor

use of io.pravega.shared.protocol.netty.FailingReplyProcessor 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 13 with FailingReplyProcessor

use of io.pravega.shared.protocol.netty.FailingReplyProcessor 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 14 with FailingReplyProcessor

use of io.pravega.shared.protocol.netty.FailingReplyProcessor in project pravega by pravega.

the class MockController method abortTxSegment.

private CompletableFuture<Void> abortTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {

        @Override
        public void connectionDropped() {
            result.completeExceptionally(new ConnectionClosedException());
        }

        @Override
        public void wrongHost(WrongHost wrongHost) {
            result.completeExceptionally(new UnsupportedOperationException());
        }

        @Override
        public void transactionCommitted(TransactionCommitted transactionCommitted) {
            result.completeExceptionally(new RuntimeException("Transaction already committed."));
        }

        @Override
        public void transactionAborted(TransactionAborted transactionAborted) {
            result.complete(null);
        }

        @Override
        public void processingFailure(Exception error) {
            result.completeExceptionally(error);
        }

        @Override
        public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
            result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
        }
    };
    sendRequestOverNewConnection(new AbortTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.common.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) TransactionAborted(io.pravega.shared.protocol.netty.WireCommands.TransactionAborted) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) AuthenticationException(io.pravega.common.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) TransactionCommitted(io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted) CompletableFuture(java.util.concurrent.CompletableFuture) AbortTransaction(io.pravega.shared.protocol.netty.WireCommands.AbortTransaction)

Aggregations

AuthenticationException (io.pravega.common.auth.AuthenticationException)14 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)14 CompletableFuture (java.util.concurrent.CompletableFuture)14 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 WireCommands (io.pravega.shared.protocol.netty.WireCommands)9 TxnFailedException (io.pravega.client.stream.TxnFailedException)5 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)5 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)5 TxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.TxnStatus)2 TransactionAborted (io.pravega.shared.protocol.netty.WireCommands.TransactionAborted)2 TransactionCommitted (io.pravega.shared.protocol.netty.WireCommands.TransactionCommitted)2 AbortTransaction (io.pravega.shared.protocol.netty.WireCommands.AbortTransaction)1 CommitTransaction (io.pravega.shared.protocol.netty.WireCommands.CommitTransaction)1 CreateSegment (io.pravega.shared.protocol.netty.WireCommands.CreateSegment)1 CreateTransaction (io.pravega.shared.protocol.netty.WireCommands.CreateTransaction)1 DeleteSegment (io.pravega.shared.protocol.netty.WireCommands.DeleteSegment)1 TransactionCreated (io.pravega.shared.protocol.netty.WireCommands.TransactionCreated)1 UUID (java.util.UUID)1