Search in sources :

Example 1 with READER_GROUP_STREAM_PREFIX

use of io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX in project pravega by pravega.

the class StreamManagerImpl method deleteScope.

/**
 * A new API is created hence this is going to be deprecated.
 *
 * @deprecated As of Pravega release 0.11.0, replaced by {@link #deleteScopeRecursive(String)}.
 */
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) throws DeleteScopeFailedException {
    NameUtils.validateUserScopeName(scopeName);
    if (forceDelete) {
        log.info("Deleting scope recursively: {}", scopeName);
        List<String> readerGroupList = new ArrayList<>();
        Iterator<Stream> iterator = listStreams(scopeName);
        while (iterator.hasNext()) {
            Stream stream = iterator.next();
            if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
                readerGroupList.add(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
            }
            try {
                Futures.getThrowingException(Futures.exceptionallyExpecting(controller.sealStream(stream.getScope(), stream.getStreamName()), e -> {
                    Throwable unwrap = Exceptions.unwrap(e);
                    // ignore failures if the stream doesn't exist or we are unable to seal it.
                    return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
                }, false).thenCompose(sealed -> controller.deleteStream(stream.getScope(), stream.getStreamName())));
            } catch (Exception e) {
                String message = String.format("Failed to seal and delete stream %s", stream.getStreamName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
        while (kvtIterator.hasNext()) {
            KeyValueTableInfo kvt = kvtIterator.next();
            try {
                Futures.getThrowingException(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()));
            } catch (Exception e) {
                String message = String.format("Failed to delete key-value table %s", kvt.getKeyValueTableName());
                throw new DeleteScopeFailedException(message, e);
            }
        }
        for (String groupName : readerGroupList) {
            try {
                Futures.getThrowingException(controller.getReaderGroupConfig(scopeName, groupName).thenCompose(conf -> controller.deleteReaderGroup(scopeName, groupName, conf.getReaderGroupId())));
            } catch (Exception e) {
                if (Exceptions.unwrap(e) instanceof ReaderGroupNotFoundException) {
                    continue;
                }
                String message = String.format("Failed to delete reader group %s", groupName);
                throw new DeleteScopeFailedException(message, e);
            }
        }
    }
    return Futures.getThrowingException(controller.deleteScope(scopeName));
}
Also used : StreamCut(io.pravega.client.stream.StreamCut) Getter(lombok.Getter) StreamManager(io.pravega.client.admin.StreamManager) Exceptions(io.pravega.common.Exceptions) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) CompletableFuture(java.util.concurrent.CompletableFuture) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) AccessLevel(lombok.AccessLevel) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) NameUtils(io.pravega.shared.NameUtils) Callbacks(io.pravega.common.function.Callbacks) Iterator(java.util.Iterator) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) Collection(java.util.Collection) AsyncIterator(io.pravega.common.util.AsyncIterator) StreamInfo(io.pravega.client.admin.StreamInfo) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) ControllerImplConfig(io.pravega.client.control.impl.ControllerImplConfig) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ControllerImpl(io.pravega.client.control.impl.ControllerImpl) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) ClientConfig(io.pravega.client.ClientConfig) ArrayList(java.util.ArrayList) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) ReaderGroupNotFoundException(io.pravega.client.stream.ReaderGroupNotFoundException) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) DeleteScopeFailedException(io.pravega.client.stream.DeleteScopeFailedException)

Example 2 with READER_GROUP_STREAM_PREFIX

use of io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX in project pravega by pravega.

the class DeleteScopeTask method deleteScopeContent.

public CompletableFuture<Void> deleteScopeContent(String scopeName, OperationContext context, long requestId) {
    Map<String, String> readerGroupMap = new HashMap<>();
    Iterator<Stream> iterator = listStreams(scopeName, context).asIterator();
    // Seal and delete streams and add entry to RGList
    while (iterator.hasNext()) {
        Stream stream = iterator.next();
        Timer timer = new Timer();
        if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
            readerGroupMap.put(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()), stream.getStreamName());
        }
        log.debug("Processing seal and delete stream for Stream {}", stream);
        Futures.getThrowingException(Futures.exceptionallyExpecting(streamMetadataTasks.sealStream(scopeName, stream.getStreamName(), requestId), e -> {
            Throwable unwrap = Exceptions.unwrap(e);
            // ignore failures if the stream doesn't exist or we are unable to seal it.
            return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
        }, Controller.UpdateStreamStatus.Status.STREAM_NOT_FOUND).thenCompose(sealed -> {
            ControllerService.reportSealStreamMetrics(scopeName, stream.getStreamName(), sealed, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        }).thenCompose(x -> streamMetadataTasks.deleteStream(stream.getScope(), stream.getStreamName(), requestId).thenCompose(status -> {
            ControllerService.reportDeleteStreamMetrics(scopeName, stream.getStreamName(), status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        })));
    }
    // Delete ReaderGroups
    for (Map.Entry<String, String> rgMapEntry : readerGroupMap.entrySet()) {
        log.debug("Processing delete ReaderGroup for {}", rgMapEntry.getKey());
        Timer timer = new Timer();
        Futures.getThrowingException(streamMetadataTasks.getReaderGroupConfig(scopeName, rgMapEntry.getKey(), requestId).thenCompose(conf -> streamMetadataTasks.deleteReaderGroup(scopeName, rgMapEntry.getKey(), conf.getConfig().getReaderGroupId(), requestId).thenCompose(status -> {
            ControllerService.reportDeleteReaderGroupMetrics(scopeName, rgMapEntry.getValue(), status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        })));
    }
    // Delete KVTs
    Iterator<KeyValueTableInfo> kvtIterator = listKVTs(scopeName, requestId, context).asIterator();
    while (kvtIterator.hasNext()) {
        String kvt = kvtIterator.next().getKeyValueTableName();
        Timer timer = new Timer();
        log.debug("Processing delete kvt for {}", kvt);
        Futures.getThrowingException(kvtMetadataTasks.deleteKeyValueTable(scopeName, kvt, context.getRequestId()).thenCompose(status -> {
            ControllerService.reportDeleteKVTableMetrics(scopeName, kvt, status, timer.getElapsed());
            return CompletableFuture.completedFuture(null);
        }));
    }
    return streamMetadataStore.deleteScopeRecursive(scopeName, context, executor).thenApply(status -> {
        log.debug("Recursive Delete Scope returned with a status {}", status);
        return null;
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TagLogger(io.pravega.common.tracing.TagLogger) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ControllerService(io.pravega.controller.server.ControllerService) Iterator(java.util.Iterator) Collection(java.util.Collection) DeleteScopeEvent(io.pravega.shared.controller.event.DeleteScopeEvent) AsyncIterator(io.pravega.common.util.AsyncIterator) UUID(java.util.UUID) Timer(io.pravega.common.Timer) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) Collectors(java.util.stream.Collectors) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) AbstractMap(java.util.AbstractMap) List(java.util.List) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) HashMap(java.util.HashMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Timer(io.pravega.common.Timer) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Example 3 with READER_GROUP_STREAM_PREFIX

use of io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX 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

Stream (io.pravega.client.stream.Stream)3 Futures (io.pravega.common.concurrent.Futures)3 READER_GROUP_STREAM_PREFIX (io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX)3 Iterator (java.util.Iterator)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Preconditions (com.google.common.base.Preconditions)2 ClientConfig (io.pravega.client.ClientConfig)2 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)2 ControllerFailureException (io.pravega.client.control.impl.ControllerFailureException)2 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)2 ReaderGroupNotFoundException (io.pravega.client.stream.ReaderGroupNotFoundException)2 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Exceptions (io.pravega.common.Exceptions)2 TagLogger (io.pravega.common.tracing.TagLogger)2 AsyncIterator (io.pravega.common.util.AsyncIterator)2 ControllerService (io.pravega.controller.server.ControllerService)2 Collectors (java.util.stream.Collectors)2 LoggerFactory (org.slf4j.LoggerFactory)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1