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());
}
}
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));
}
}
Aggregations