Search in sources :

Example 1 with InMemoryScope

use of io.pravega.controller.store.InMemoryScope in project pravega by pravega.

the class InMemoryStreamMetadataStore method createScope.

// endregion
@Override
@Synchronized
public CompletableFuture<CreateScopeStatus> createScope(final String scopeName, OperationContext ctx, Executor executor) {
    OperationContext context = getOperationContext(ctx);
    if (!scopes.containsKey(scopeName)) {
        InMemoryScope scope = (InMemoryScope) getScope(scopeName, context);
        return scope.createScope(context).thenApply(x -> {
            scopes.put(scopeName, scope);
            orderedScopes.put(scopeName, position.incrementAndGet());
            return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SUCCESS).build();
        });
    } else {
        return CompletableFuture.completedFuture(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build());
    }
}
Also used : InMemoryScope(io.pravega.controller.store.InMemoryScope) Synchronized(lombok.Synchronized)

Example 2 with InMemoryScope

use of io.pravega.controller.store.InMemoryScope in project pravega by pravega.

the class InMemoryStreamMetadataStore method listStreamsInScope.

/**
 * List the streams in scope.
 *
 * @param scopeName Name of scope
 * @return List of streams in scope
 */
@Override
@Synchronized
public CompletableFuture<Map<String, StreamConfiguration>> listStreamsInScope(final String scopeName, final OperationContext ctx, final Executor executor) {
    OperationContext context = getOperationContext(ctx);
    InMemoryScope inMemoryScope = scopes.get(scopeName);
    if (inMemoryScope != null) {
        return inMemoryScope.listStreamsInScope(context).thenApply(streams -> {
            HashMap<String, StreamConfiguration> result = new HashMap<>();
            for (String stream : streams) {
                State state = getState(scopeName, stream, true, null, executor).join();
                StreamConfiguration configuration = Futures.exceptionallyExpecting(getConfiguration(scopeName, stream, null, executor), e -> e instanceof StoreException.DataNotFoundException, null).join();
                if (configuration != null && !state.equals(State.CREATING) && !state.equals(State.UNKNOWN)) {
                    result.put(stream, configuration);
                }
            }
            return result;
        });
    } else {
        return Futures.failedFuture(StoreException.create(StoreException.Type.DATA_NOT_FOUND, scopeName));
    }
}
Also used : CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) SneakyThrows(lombok.SneakyThrows) RetentionPolicy(io.pravega.client.stream.RetentionPolicy) Scope(io.pravega.controller.store.Scope) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) Pair(org.apache.commons.lang3.tuple.Pair) InMemoryScope(io.pravega.controller.store.InMemoryScope) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) DeleteScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus) Synchronized(lombok.Synchronized) Executor(java.util.concurrent.Executor) Set(java.util.Set) IOException(java.io.IOException) UUID(java.util.UUID) GuardedBy(javax.annotation.concurrent.GuardedBy) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) AtomicInt96(io.pravega.common.lang.AtomicInt96) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Version(io.pravega.controller.store.Version) InMemoryHostIndex(io.pravega.controller.store.index.InMemoryHostIndex) Int96(io.pravega.common.lang.Int96) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) LinkedTreeMap(com.google.gson.internal.LinkedTreeMap) Futures(io.pravega.common.concurrent.Futures) InMemoryScope(io.pravega.controller.store.InMemoryScope) HashMap(java.util.HashMap) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Synchronized(lombok.Synchronized)

Aggregations

InMemoryScope (io.pravega.controller.store.InMemoryScope)2 Synchronized (lombok.Synchronized)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)1 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)1 Futures (io.pravega.common.concurrent.Futures)1 AtomicInt96 (io.pravega.common.lang.AtomicInt96)1 Int96 (io.pravega.common.lang.Int96)1 Scope (io.pravega.controller.store.Scope)1 Version (io.pravega.controller.store.Version)1 InMemoryHostIndex (io.pravega.controller.store.index.InMemoryHostIndex)1 CreateScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus)1 DeleteScopeStatus (io.pravega.controller.stream.api.grpc.v1.Controller.DeleteScopeStatus)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1