Search in sources :

Example 6 with StreamsList

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));
}
Also used : ApiV1(io.pravega.controller.server.rest.v1.ApiV1) READ(io.pravega.auth.AuthHandler.Permissions.READ) StreamsList(io.pravega.controller.server.rest.generated.model.StreamsList) SecurityContext(javax.ws.rs.core.SecurityContext) LoggerFactory(org.slf4j.LoggerFactory) ReaderGroupManagerImpl(io.pravega.client.admin.impl.ReaderGroupManagerImpl) Random(java.util.Random) ReaderGroup(io.pravega.client.stream.ReaderGroup) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) TagLogger(io.pravega.common.tracing.TagLogger) RESTAuthHelper(io.pravega.shared.rest.security.RESTAuthHelper) LocalController(io.pravega.controller.server.eventProcessor.LocalController) StoreException(io.pravega.controller.store.stream.StoreException) ClientFactoryImpl(io.pravega.client.stream.impl.ClientFactoryImpl) ReaderGroupManager(io.pravega.client.admin.ReaderGroupManager) Stream(io.pravega.client.stream.Stream) ReaderGroupProperty(io.pravega.controller.server.rest.generated.model.ReaderGroupProperty) INTERNAL_NAME_PREFIX(io.pravega.shared.NameUtils.INTERNAL_NAME_PREFIX) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) CreateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateStreamStatus) AuthorizationResource(io.pravega.shared.security.auth.AuthorizationResource) Context(javax.ws.rs.core.Context) AsyncResponse(javax.ws.rs.container.AsyncResponse) CreateScopeRequest(io.pravega.controller.server.rest.generated.model.CreateScopeRequest) Collectors(java.util.stream.Collectors) CreateStreamRequest(io.pravega.controller.server.rest.generated.model.CreateStreamRequest) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) List(java.util.List) Principal(java.security.Principal) HttpHeaders(javax.ws.rs.core.HttpHeaders) StreamState(io.pravega.controller.server.rest.generated.model.StreamState) Response(javax.ws.rs.core.Response) ScopesList(io.pravega.controller.server.rest.generated.model.ScopesList) Futures(io.pravega.common.concurrent.Futures) AuthException(io.pravega.auth.AuthException) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) ConnectionFactory(io.pravega.client.connection.impl.ConnectionFactory) CompletableFuture(java.util.concurrent.CompletableFuture) UpdateStreamRequest(io.pravega.controller.server.rest.generated.model.UpdateStreamRequest) ArrayList(java.util.ArrayList) READ_UPDATE(io.pravega.auth.AuthHandler.Permissions.READ_UPDATE) ScaleMetadata(io.pravega.controller.store.stream.ScaleMetadata) DeleteStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteStreamStatus) Status(javax.ws.rs.core.Response.Status) AuthorizationResourceImpl(io.pravega.shared.security.auth.AuthorizationResourceImpl) LoggerHelpers(io.pravega.common.LoggerHelpers) ControllerService(io.pravega.controller.server.ControllerService) NameUtils(io.pravega.shared.NameUtils) Iterator(java.util.Iterator) ScopeProperty(io.pravega.controller.server.rest.generated.model.ScopeProperty) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ModelHelper(io.pravega.controller.server.rest.ModelHelper) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) AuthHandlerManager(io.pravega.shared.rest.security.AuthHandlerManager) ReaderGroupsListReaderGroups(io.pravega.controller.server.rest.generated.model.ReaderGroupsListReaderGroups) UpdateStreamStatus(io.pravega.controller.stream.api.grpc.v1.Controller.UpdateStreamStatus) ClientConfig(io.pravega.client.ClientConfig) ReaderGroupsListReaderGroups(io.pravega.controller.server.rest.generated.model.ReaderGroupsListReaderGroups) AuthException(io.pravega.auth.AuthException) ReaderGroupsList(io.pravega.controller.server.rest.generated.model.ReaderGroupsList) StoreException(io.pravega.controller.store.stream.StoreException)

Aggregations

StreamConfiguration (io.pravega.client.stream.StreamConfiguration)6 StreamsList (io.pravega.controller.server.rest.generated.model.StreamsList)6 Response (javax.ws.rs.core.Response)6 ReaderGroupsList (io.pravega.controller.server.rest.generated.model.ReaderGroupsList)3 ScopesList (io.pravega.controller.server.rest.generated.model.ScopesList)3 StoreException (io.pravega.controller.store.stream.StoreException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 AuthException (io.pravega.auth.AuthException)2 AuthFileUtils.credentialsAndAclAsString (io.pravega.auth.AuthFileUtils.credentialsAndAclAsString)2 READ (io.pravega.auth.AuthHandler.Permissions.READ)2 READ_UPDATE (io.pravega.auth.AuthHandler.Permissions.READ_UPDATE)2 ClientConfig (io.pravega.client.ClientConfig)2 ReaderGroupManager (io.pravega.client.admin.ReaderGroupManager)2 ReaderGroupManagerImpl (io.pravega.client.admin.impl.ReaderGroupManagerImpl)2 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)2 ReaderGroup (io.pravega.client.stream.ReaderGroup)2 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)2