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());
}
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;
}
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;
}
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);
}
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);
}
Aggregations