use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class StreamMetadataResourceImpl method listStreams.
/**
* Implementation of listStreams REST API.
*
* @param scopeName The scope name of stream.
* @param securityContext The security for API access.
* @param asyncResponse AsyncResponse provides means for asynchronous server side response processing.
*/
@Override
public void listStreams(final String scopeName, final String showInternalStreams, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "listStreams");
try {
authenticate(scopeName, READ);
} catch (AuthenticationException e) {
log.warn("List streams for {} failed due to authentication failure.", scopeName);
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "listStreams", traceId);
return;
}
boolean showOnlyInternalStreams = showInternalStreams != null && showInternalStreams.equals("true");
controllerService.listStreamsInScope(scopeName).thenApply(streamsList -> {
StreamsList streams = new StreamsList();
streamsList.forEach(stream -> {
// otherwise display the regular user created streams.
if (!showOnlyInternalStreams ^ stream.getStreamName().startsWith(INTERNAL_NAME_PREFIX)) {
streams.addStreamsItem(ModelHelper.encodeStreamResponse(stream));
}
});
log.info("Successfully fetched streams for scope: {}", scopeName);
return Response.status(Status.OK).entity(streams).build();
}).exceptionally(exception -> {
if (exception.getCause() instanceof StoreException.DataNotFoundException || exception instanceof StoreException.DataNotFoundException) {
log.warn("Scope name: {} not found", scopeName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn("listStreams for {} failed with exception: {}", scopeName, exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "listStreams", traceId));
}
use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class StreamMetadataResourceImpl method getReaderGroup.
@Override
public void getReaderGroup(final String scopeName, final String readerGroupName, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "getReaderGroup");
try {
authenticate(scopeName + "/" + readerGroupName, READ);
} catch (AuthenticationException e) {
log.warn("Get reader group for {} failed due to authentication failure.", scopeName + "/" + readerGroupName);
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
return;
}
ReaderGroupManager readerGroupManager = new ReaderGroupManagerImpl(scopeName, this.localController, new ClientFactoryImpl(scopeName, this.localController), this.connectionFactory);
ReaderGroupProperty readerGroupProperty = new ReaderGroupProperty();
readerGroupProperty.setScopeName(scopeName);
readerGroupProperty.setReaderGroupName(readerGroupName);
CompletableFuture.supplyAsync(() -> {
ReaderGroup readerGroup = readerGroupManager.getReaderGroup(readerGroupName);
readerGroupProperty.setOnlineReaderIds(new ArrayList<>(readerGroup.getOnlineReaders()));
readerGroupProperty.setStreamList(new ArrayList<>(readerGroup.getStreamNames()));
return Response.status(Status.OK).entity(readerGroupProperty).build();
}, controllerService.getExecutor()).exceptionally(exception -> {
log.warn("getReaderGroup for {} failed with exception: ", readerGroupName, exception);
if (exception.getCause() instanceof InvalidStreamException) {
return Response.status(Status.NOT_FOUND).build();
} else {
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenAccept(response -> {
asyncResponse.resume(response);
readerGroupManager.close();
LoggerHelpers.traceLeave(log, "getReaderGroup", traceId);
});
}
use of io.pravega.common.auth.AuthenticationException in project pravega by pravega.
the class StreamMetadataResourceImpl method listReaderGroups.
@Override
public void listReaderGroups(final String scopeName, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "listReaderGroups");
try {
authenticate(scopeName, READ);
} catch (AuthenticationException e) {
log.warn("Get reader groups for {} failed due to authentication failure.", scopeName);
asyncResponse.resume(Response.status(Status.UNAUTHORIZED).build());
LoggerHelpers.traceLeave(log, "listReaderGroups", traceId);
return;
}
// Each reader group is represented by a stream within the mentioned scope.
controllerService.listStreamsInScope(scopeName).thenApply(streamsList -> {
ReaderGroupsList readerGroups = new ReaderGroupsList();
streamsList.forEach(stream -> {
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
ReaderGroupsListReaderGroups readerGroup = new ReaderGroupsListReaderGroups();
readerGroup.setReaderGroupName(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
readerGroups.addReaderGroupsItem(readerGroup);
}
});
log.info("Successfully fetched readerGroups for scope: {}", scopeName);
return Response.status(Status.OK).entity(readerGroups).build();
}).exceptionally(exception -> {
if (exception.getCause() instanceof StoreException.DataNotFoundException || exception instanceof StoreException.DataNotFoundException) {
log.warn("Scope name: {} not found", scopeName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn("listReaderGroups for {} failed with exception: ", scopeName, exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "listReaderGroups", traceId));
}
use of io.pravega.common.auth.AuthenticationException 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;
}
Aggregations