use of io.pravega.controller.store.Scope in project pravega by pravega.
the class AbstractKVTableMetadataStore method getScope.
public Scope getScope(final String scopeName, final OperationContext context) {
if (context instanceof KVTOperationContext) {
return ((KVTOperationContext) context).getScope();
}
Scope scope = scopeCache.getUnchecked(scopeName);
scope.refresh();
return scope;
}
use of io.pravega.controller.store.Scope in project pravega by pravega.
the class AbstractStreamMetadataStore method getScope.
public Scope getScope(final String scopeName, final OperationContext context) {
if (context != null) {
if (context instanceof StreamOperationContext) {
return ((StreamOperationContext) context).getScope();
} else if (context instanceof RGOperationContext) {
return ((RGOperationContext) context).getScope();
}
}
Scope scope = scopeCache.getUnchecked(scopeName);
scope.refresh();
return scope;
}
use of io.pravega.controller.store.Scope 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));
}
}
use of io.pravega.controller.store.Scope in project pravega by pravega.
the class AbstractStreamMetadataStore method createStreamContext.
@Override
public OperationContext createStreamContext(String scopeName, String streamName, long requestId) {
Scope scope = getScope(scopeName, null);
Stream stream = getStream(scopeName, streamName, null);
return new StreamOperationContext(scope, stream, requestId);
}
use of io.pravega.controller.store.Scope in project pravega by pravega.
the class AbstractStreamMetadataStore method createScope.
/**
* Create a scope with given name.
*
* @param scopeName Name of scope to created.
* @return CreateScopeStatus future.
*/
@Override
public CompletableFuture<CreateScopeStatus> createScope(final String scopeName, final OperationContext ctx, Executor executor) {
OperationContext context = getOperationContext(ctx);
Scope scope = getScope(scopeName, context);
return Futures.completeOn(scope.isScopeSealed(scopeName, context).thenCompose(isScopeSealed -> {
if (isScopeSealed) {
return CompletableFuture.completedFuture(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build());
}
return scope.createScope(context).handle((result, ex) -> {
if (ex == null) {
return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SUCCESS).build();
}
if (Exceptions.unwrap(ex) instanceof StoreException.DataExistsException) {
return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.SCOPE_EXISTS).build();
} else {
log.error(context.getRequestId(), "Create scope failed for scope {} due to ", scopeName, ex);
return CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.FAILURE).build();
}
});
}), executor);
}
Aggregations