use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.
the class ControllerService method createScope.
/**
* Controller Service API to create scope.
*
* @param scope Name of scope to be created.
* @param requestId request id
* @return Status of create scope.
*/
public CompletableFuture<CreateScopeStatus> createScope(final String scope, final long requestId) {
Exceptions.checkNotNullOrEmpty(scope, "scope");
Timer timer = new Timer();
try {
NameUtils.validateScopeName(scope);
} catch (IllegalArgumentException | NullPointerException e) {
log.error(requestId, "Create scope failed due to invalid scope name {}", scope);
return CompletableFuture.completedFuture(CreateScopeStatus.newBuilder().setStatus(CreateScopeStatus.Status.INVALID_SCOPE_NAME).build());
}
OperationContext context = streamStore.createScopeContext(scope, requestId);
return streamStore.createScope(scope, context, executor).thenApply(r -> reportCreateScopeMetrics(scope, r, timer.getElapsed()));
}
use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.
the class ControllerService method getKeyValueTableConfiguration.
public CompletableFuture<KeyValueTableConfigResponse> getKeyValueTableConfiguration(final String scope, final String kvtName, final long requestId) {
Exceptions.checkNotNullOrEmpty(scope, "Scope name");
Exceptions.checkNotNullOrEmpty(kvtName, "KeyValueTable name.");
OperationContext context = kvtMetadataStore.createContext(scope, kvtName, requestId);
return kvtMetadataStore.getConfiguration(scope, kvtName, context, executor).handleAsync((r, ex) -> {
if (ex == null) {
return KeyValueTableConfigResponse.newBuilder().setConfig(ModelHelper.decode(scope, kvtName, r)).setStatus(KeyValueTableConfigResponse.Status.SUCCESS).build();
} else if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
return KeyValueTableConfigResponse.newBuilder().setStatus(KeyValueTableConfigResponse.Status.TABLE_NOT_FOUND).build();
}
return KeyValueTableConfigResponse.newBuilder().setStatus(KeyValueTableConfigResponse.Status.FAILURE).build();
});
}
use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.
the class ControllerService method isStreamCutValid.
/**
* Checks if its a well formed streamcut. Well formed stream cuts are those that can unambiguously split the stream into two parts,
* before and after. Any event position can be compared against a streamcut to determine unambiguously if it lies
* before, On, or after the streamcut.
*
* @param scope scope
* @param stream stream name
* @param streamCut stream cut to validate
* @param requestId request id
* @return future that when completed will indicate if the stream cut is well formed or not.
*/
public CompletableFuture<Boolean> isStreamCutValid(final String scope, final String stream, final Map<Long, Long> streamCut, final long requestId) {
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(stream, "stream");
OperationContext context = streamStore.createStreamContext(scope, stream, requestId);
return streamStore.isStreamCutValid(scope, stream, streamCut, context, executor);
}
use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.
the class ControllerService method getCurrentSegments.
public CompletableFuture<List<SegmentRange>> getCurrentSegments(final String scope, final String stream, long requestId) {
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(stream, "stream");
// Fetch active segments from segment store.
OperationContext context = streamStore.createStreamContext(scope, stream, requestId);
return streamStore.getActiveSegments(scope, stream, context, executor).thenApplyAsync(activeSegments -> getSegmentRanges(activeSegments, scope, stream), executor);
}
use of io.pravega.controller.store.stream.OperationContext in project pravega by pravega.
the class DeleteTableTask method execute.
@Override
public CompletableFuture<Void> execute(final DeleteTableEvent request) {
String scope = request.getScope();
String kvt = request.getKvtName();
long requestId = request.getRequestId();
String kvTableId = request.getTableId().toString();
final OperationContext context = kvtMetadataStore.createContext(scope, kvt, requestId);
return RetryHelper.withRetriesAsync(() -> getKeyValueTable(scope, kvt).thenCompose(table -> table.getId(context)).thenCompose(id -> {
if (!id.equals(kvTableId)) {
log.debug(requestId, "Skipped processing delete event for KeyValueTable {}/{} with Id:{} as UUIDs did not match.", scope, kvt, id);
return CompletableFuture.completedFuture(null);
} else {
return Futures.exceptionallyExpecting(kvtMetadataStore.getAllSegmentIds(scope, kvt, context, executor).thenComposeAsync(allSegments -> kvtMetadataTasks.deleteSegments(scope, kvt, allSegments, kvtMetadataTasks.retrieveDelegationToken(), requestId), executor), e -> Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException, null).thenCompose(v -> this.kvtMetadataStore.deleteKeyValueTable(scope, kvt, context, executor));
}
}), e -> Exceptions.unwrap(e) instanceof RetryableException, Integer.MAX_VALUE, executor);
}
Aggregations