use of io.pravega.controller.server.rest.generated.model.StreamsList 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");
long requestId = requestIdGenerator.nextLong();
try {
restAuthHelper.authenticateAuthorize(getAuthorizationHeader(), authorizationResource.ofReaderGroupsInScope(scopeName), READ);
} catch (AuthException e) {
log.warn(requestId, "Get reader groups for {} failed due to authentication failure.", scopeName);
asyncResponse.resume(Response.status(Status.fromStatusCode(e.getResponseCode())).build());
LoggerHelpers.traceLeave(log, "listReaderGroups", traceId);
return;
}
// Each reader group is represented by a stream within the mentioned scope.
controllerService.listStreamsInScope(scopeName, requestId).thenApply(streamsList -> {
ReaderGroupsList readerGroups = new ReaderGroupsList();
streamsList.forEach((stream, config) -> {
if (stream.startsWith(READER_GROUP_STREAM_PREFIX)) {
ReaderGroupsListReaderGroups readerGroup = new ReaderGroupsListReaderGroups();
readerGroup.setReaderGroupName(stream.substring(READER_GROUP_STREAM_PREFIX.length()));
readerGroups.addReaderGroupsItem(readerGroup);
}
});
log.info(requestId, "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(requestId, "Scope name: {} not found", scopeName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn(requestId, "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));
}
Aggregations