Search in sources :

Example 1 with AuthenticationException

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

the class AsyncSegmentInputStreamImpl method read.

@Override
public CompletableFuture<SegmentRead> read(long offset, int length) {
    Exceptions.checkNotClosed(closed.get(), this);
    return backoffSchedule.retryWhen(t -> {
        Throwable ex = Exceptions.unwrap(t);
        if (closed.get()) {
            log.debug("Exception: {} while reading from Segment : {}", ex.toString(), segmentId);
        } else {
            log.warn("Exception while reading from Segment {} at offset {} :", segmentId, offset, ex);
        }
        return ex instanceof Exception && !(ex instanceof ConnectionClosedException) && !(ex instanceof SegmentTruncatedException) && !(ex instanceof AuthenticationException);
    }).runAsync(() -> this.tokenProvider.retrieveToken().thenComposeAsync(token -> {
        final WireCommands.ReadSegment request = new WireCommands.ReadSegment(segmentId.getScopedName(), offset, length, token, requestId);
        return getConnection().whenComplete((connection1, ex) -> {
            if (ex != null) {
                log.warn("Exception while establishing connection with Pravega node {}: ", connection1, ex);
                closeConnection(new ConnectionFailedException(ex));
            }
        }).thenCompose(c -> sendRequestOverConnection(request, c).whenComplete((reply, ex) -> {
            if (ex instanceof ConnectionFailedException) {
                log.debug("ConnectionFailedException observed when sending request {}", request, ex);
                closeConnection((ConnectionFailedException) ex);
            }
        }));
    }, connectionPool.getInternalExecutor()), connectionPool.getInternalExecutor());
}
Also used : Getter(lombok.Getter) TokenExpiredException(io.pravega.auth.TokenExpiredException) Retry(io.pravega.common.util.Retry) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) SegmentIsTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentIsTruncated) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) ClientConnection(io.pravega.client.connection.impl.ClientConnection) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) SegmentRead(io.pravega.shared.protocol.netty.WireCommands.SegmentRead) Map(java.util.Map) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Flow(io.pravega.client.connection.impl.Flow) RetryWithBackoff(io.pravega.common.util.Retry.RetryWithBackoff) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) Semaphore(java.util.concurrent.Semaphore) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) GuardedBy(javax.annotation.concurrent.GuardedBy) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) AuthenticationException(io.pravega.auth.AuthenticationException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) TokenExpiredException(io.pravega.auth.TokenExpiredException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) AuthenticationException(io.pravega.auth.AuthenticationException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException)

Example 2 with AuthenticationException

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

the class MockController method createSegmentTx.

private CompletableFuture<Void> createSegmentTx(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    if (!callServer) {
        result.complete(null);
        return result;
    }
    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 segmentCreated(WireCommands.SegmentCreated transactionCreated) {
            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()));
        }
    };
    String transactionName = NameUtils.getTransactionNameFromId(segment.getScopedName(), txId);
    sendRequestOverNewConnection(new CreateSegment(idGenerator.get(), transactionName, WireCommands.CreateSegment.NO_SCALE, 0, "", 0), replyProcessor, result);
    return result;
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) FailingReplyProcessor(io.pravega.shared.protocol.netty.FailingReplyProcessor) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) AuthenticationException(io.pravega.auth.AuthenticationException) TxnFailedException(io.pravega.client.stream.TxnFailedException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) CompletableFuture(java.util.concurrent.CompletableFuture) CreateSegment(io.pravega.shared.protocol.netty.WireCommands.CreateSegment)

Example 3 with AuthenticationException

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

the class MockController method commitTxSegment.

private CompletableFuture<Void> commitTxSegment(UUID txId, Segment segment) {
    CompletableFuture<Void> result = new CompletableFuture<>();
    if (!callServer) {
        result.complete(null);
        return result;
    }
    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 segmentsMerged(WireCommands.SegmentsMerged segmentsMerged) {
            result.complete(null);
        }

        @Override
        public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
            result.completeExceptionally(new TxnFailedException("Transaction already aborted."));
        }

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

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

Example 4 with AuthenticationException

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

the class SegmentHelperTest method abortTransaction.

@Test
public void abortTransaction() {
    MockConnectionFactory factory = new MockConnectionFactory();
    @Cleanup SegmentHelper helper = new SegmentHelper(factory, new MockHostControllerStore(), executorService());
    CompletableFuture<Controller.TxnStatus> retVal = helper.abortTransaction("", "", 0L, new UUID(0, 0L), "", System.nanoTime());
    long requestId = ((MockConnection) (factory.connection)).getRequestId();
    factory.rp.process(new WireCommands.AuthTokenCheckFailed(requestId, "SomeException"));
    AssertExtensions.assertThrows("", retVal::join, ex -> ex instanceof WireCommandFailedException && ex.getCause() instanceof AuthenticationException);
    CompletableFuture<Controller.TxnStatus> result = helper.abortTransaction("", "", 1L, new UUID(0L, 0L), "", System.nanoTime());
    requestId = ((MockConnection) (factory.connection)).getRequestId();
    factory.rp.process(new WireCommands.SegmentDeleted(requestId, getQualifiedStreamSegmentName("", "", System.nanoTime())));
    result.join();
    result = helper.abortTransaction("", "", 1L, new UUID(0L, 0L), "", System.nanoTime());
    requestId = ((MockConnection) (factory.connection)).getRequestId();
    factory.rp.process(new WireCommands.NoSuchSegment(requestId, getQualifiedStreamSegmentName("", "", 0L), "", System.nanoTime()));
    result.join();
    Supplier<CompletableFuture<?>> futureSupplier = () -> helper.abortTransaction("", "", 0L, new UUID(0, 0L), "", System.nanoTime());
    validateProcessingFailureCFE(factory, futureSupplier);
    testConnectionFailure(factory, futureSupplier);
}
Also used : AuthenticationException(io.pravega.auth.AuthenticationException) Cleanup(lombok.Cleanup) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Test(org.junit.Test)

Example 5 with AuthenticationException

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

the class SegmentHelperTest method testProcessAndRethrowExceptions.

@Test
public void testProcessAndRethrowExceptions() {
    // The wire-command itself we use for this test is immaterial, so we are using the simplest one here.
    WireCommands.Hello dummyRequest = new WireCommands.Hello(0, 0);
    @SuppressWarnings("resource") SegmentHelper objectUnderTest = new SegmentHelper(null, null, null);
    AssertExtensions.assertThrows("Unexpected exception thrown", () -> objectUnderTest.<WireCommands.Hello>processAndRethrowException(1, dummyRequest, new ExecutionException(new ConnectionFailedException())), e -> hasWireCommandFailedWithReason(e, WireCommandFailedException.Reason.ConnectionFailed));
    AssertExtensions.assertThrows("Unexpected exception thrown", () -> objectUnderTest.<WireCommands.Hello>processAndRethrowException(1, dummyRequest, new ExecutionException(new AuthenticationException("Authentication failed"))), e -> hasWireCommandFailedWithReason(e, WireCommandFailedException.Reason.AuthFailed));
    AssertExtensions.assertThrows("Unexpected exception thrown", () -> objectUnderTest.<WireCommands.Hello>processAndRethrowException(1, dummyRequest, new ExecutionException(new TokenExpiredException("Token expired"))), e -> hasWireCommandFailedWithReason(e, WireCommandFailedException.Reason.AuthFailed));
    AssertExtensions.assertThrows("Unexpected exception thrown", () -> objectUnderTest.<WireCommands.Hello>processAndRethrowException(1, dummyRequest, new ExecutionException(new TimeoutException("Authentication failed"))), e -> hasWireCommandFailedWithReason(e, WireCommandFailedException.Reason.ConnectionFailed));
    AssertExtensions.assertThrows("Unexpected exception thrown", () -> objectUnderTest.<WireCommands.Hello>processAndRethrowException(1, dummyRequest, new ExecutionException(new RuntimeException())), e -> e instanceof ExecutionException && e.getCause() instanceof RuntimeException);
}
Also used : TokenExpiredException(io.pravega.auth.TokenExpiredException) AuthenticationException(io.pravega.auth.AuthenticationException) WireCommands(io.pravega.shared.protocol.netty.WireCommands) ExecutionException(java.util.concurrent.ExecutionException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

AuthenticationException (io.pravega.auth.AuthenticationException)19 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)12 WireCommands (io.pravega.shared.protocol.netty.WireCommands)10 CompletableFuture (java.util.concurrent.CompletableFuture)9 Test (org.junit.Test)7 TokenExpiredException (io.pravega.auth.TokenExpiredException)6 Cleanup (lombok.Cleanup)6 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)5 Reply (io.pravega.shared.protocol.netty.Reply)5 WrongHost (io.pravega.shared.protocol.netty.WireCommands.WrongHost)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Segment (io.pravega.client.segment.impl.Segment)4 List (java.util.List)4 UUID (java.util.UUID)4 Unpooled (io.netty.buffer.Unpooled)3 TxnFailedException (io.pravega.client.stream.TxnFailedException)3 MockConnectionFactoryImpl (io.pravega.client.stream.mock.MockConnectionFactoryImpl)3 MockController (io.pravega.client.stream.mock.MockController)3 Exceptions (io.pravega.common.Exceptions)3 FailingReplyProcessor (io.pravega.shared.protocol.netty.FailingReplyProcessor)3