use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class MockController method deleteSegment.
private boolean deleteSegment(String name, PravegaNodeUri uri) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
result.completeExceptionally(new ConnectionClosedException());
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
result.completeExceptionally(new UnsupportedOperationException());
}
@Override
public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
result.complete(true);
}
@Override
public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
result.complete(false);
}
@Override
public void processingFailure(Exception error) {
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
}
};
DeleteSegment command = new WireCommands.DeleteSegment(idGenerator.get(), name, "");
sendRequestOverNewConnection(command, replyProcessor, result);
return getAndHandleExceptions(result, RuntimeException::new);
}
use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class MockController method createSegment.
private boolean createSegment(String name, PravegaNodeUri uri) {
CompletableFuture<Boolean> result = new CompletableFuture<>();
FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
result.completeExceptionally(new ConnectionClosedException());
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
result.completeExceptionally(new UnsupportedOperationException());
}
@Override
public void segmentAlreadyExists(WireCommands.SegmentAlreadyExists segmentAlreadyExists) {
result.complete(false);
}
@Override
public void segmentCreated(WireCommands.SegmentCreated segmentCreated) {
result.complete(true);
}
@Override
public void processingFailure(Exception error) {
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new AuthenticationException(authTokenCheckFailed.toString()));
}
};
CreateSegment command = new WireCommands.CreateSegment(idGenerator.get(), name, WireCommands.CreateSegment.NO_SCALE, 0, "");
sendRequestOverNewConnection(command, replyProcessor, result);
return getAndHandleExceptions(result, RuntimeException::new);
}
use of io.pravega.common.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<>();
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.complete(null);
}
@Override
public void transactionAborted(TransactionAborted transactionAborted) {
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 CommitTransaction(idGenerator.get(), segment.getScopedName(), txId, ""), replyProcessor, result);
return result;
}
use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class AppendProcessor method setupAppend.
/**
* Setup an append so that subsequent append calls can occur.
* This requires validating that the segment exists.
* The reply: AppendSetup indicates that appends may proceed and contains the eventNumber which they should proceed
* from (in the event that this is a reconnect from a producer we have seen before)
*/
@Override
public void setupAppend(SetupAppend setupAppend) {
String newSegment = setupAppend.getSegment();
UUID writer = setupAppend.getWriterId();
log.info("Setting up appends for writer: {} on segment: {}", writer, newSegment);
if (this.tokenVerifier != null && !tokenVerifier.verifyToken(newSegment, setupAppend.getDelegationToken(), AuthHandler.Permissions.READ_UPDATE)) {
log.warn("Delegation token verification failed");
handleException(setupAppend.getWriterId(), setupAppend.getRequestId(), newSegment, "Update Segment Attribute", new AuthenticationException("Token verification failed"));
return;
}
store.getStreamSegmentInfo(newSegment, true, TIMEOUT).whenComplete((info, u) -> {
try {
if (u != null) {
handleException(writer, setupAppend.getRequestId(), newSegment, "setting up append", u);
} else {
long eventNumber = info.getAttributes().getOrDefault(writer, SegmentMetadata.NULL_ATTRIBUTE_VALUE);
synchronized (lock) {
latestEventNumbers.putIfAbsent(Pair.of(newSegment, writer), eventNumber);
}
connection.send(new AppendSetup(setupAppend.getRequestId(), newSegment, writer, eventNumber));
}
} catch (Throwable e) {
handleException(writer, setupAppend.getRequestId(), newSegment, "handling setupAppend result", e);
}
});
}
use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class PravegaRequestProcessor method handleException.
private Void handleException(long requestId, String segment, String operation, Throwable u) {
if (u == null) {
IllegalStateException exception = new IllegalStateException("No exception to handle.");
log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, exception);
throw exception;
}
u = Exceptions.unwrap(u);
if (u instanceof StreamSegmentExistsException) {
log.info("Segment '{}' already exists and cannot perform operation '{}'.", segment, operation);
connection.send(new SegmentAlreadyExists(requestId, segment));
} else if (u instanceof StreamSegmentNotExistsException) {
log.warn("Segment '{}' does not exist and cannot perform operation '{}'.", segment, operation);
connection.send(new NoSuchSegment(requestId, segment));
} else if (u instanceof StreamSegmentSealedException) {
log.info("Segment '{}' is sealed and cannot perform operation '{}'.", segment, operation);
connection.send(new SegmentIsSealed(requestId, segment));
} else if (u instanceof ContainerNotFoundException) {
int containerId = ((ContainerNotFoundException) u).getContainerId();
log.warn("Wrong host. Segment = '{}' (Container {}) is not owned. Operation = '{}').", segment, containerId, operation);
connection.send(new WrongHost(requestId, segment, ""));
} else if (u instanceof CancellationException) {
log.info("Closing connection {} while performing {} due to {}.", connection, operation, u.getMessage());
connection.close();
} else if (u instanceof AuthenticationException) {
log.warn("Authentication error during '{}'.", operation);
connection.send(new WireCommands.AuthTokenCheckFailed(requestId));
connection.close();
} else if (u instanceof UnsupportedOperationException) {
log.warn("Unsupported Operation '{}'.", operation, u);
connection.send(new OperationUnsupported(requestId, operation));
} else if (u instanceof BadOffsetException) {
BadOffsetException badOffset = (BadOffsetException) u;
connection.send(new SegmentIsTruncated(requestId, segment, badOffset.getExpectedOffset()));
} else {
log.error("Error (Segment = '{}', Operation = '{}')", segment, operation, u);
// Closing connection should reinitialize things, and hopefully fix the problem
connection.close();
throw new IllegalStateException("Unknown exception.", u);
}
return null;
}
Aggregations