use of io.pravega.shared.controller.event.SealStreamEvent in project pravega by pravega.
the class SealStreamTask method execute.
@Override
public CompletableFuture<Void> execute(final SealStreamEvent request) {
String scope = request.getScope();
String stream = request.getStream();
final OperationContext context = streamMetadataStore.createContext(scope, stream);
// when seal stream task is picked, if the state is sealing/sealed, process sealing, else postpone.
return streamMetadataStore.getState(scope, stream, true, context, executor).thenAccept(state -> {
if (!state.equals(State.SEALING) && !state.equals(State.SEALED)) {
throw new TaskExceptions.StartException("Seal stream task not started yet.");
}
}).thenCompose(x -> streamMetadataStore.getActiveSegments(scope, stream, context, executor)).thenCompose(activeSegments -> {
if (activeSegments.isEmpty()) {
// Do not update the state if the stream is already sealed.
return CompletableFuture.completedFuture(null);
} else {
return notifySealed(scope, stream, context, activeSegments);
}
});
}
use of io.pravega.shared.controller.event.SealStreamEvent in project pravega by pravega.
the class StreamMetadataTasks method sealStream.
/**
* Seal a stream.
*
* @param scope scope.
* @param stream stream name.
* @param contextOpt optional context
* @return update status.
*/
public CompletableFuture<UpdateStreamStatus.Status> sealStream(String scope, String stream, OperationContext contextOpt) {
final OperationContext context = contextOpt == null ? streamMetadataStore.createContext(scope, stream) : contextOpt;
// 1. post event for seal.
SealStreamEvent event = new SealStreamEvent(scope, stream);
return writeEvent(event).thenCompose(x -> streamMetadataStore.getState(scope, stream, false, context, executor)).thenCompose(state -> {
if (state.equals(State.SEALED)) {
return CompletableFuture.completedFuture(true);
} else {
return streamMetadataStore.setState(scope, stream, State.SEALING, context, executor);
}
}).thenCompose(result -> {
if (result) {
return checkDone(() -> isSealed(scope, stream, context)).thenApply(x -> UpdateStreamStatus.Status.SUCCESS);
} else {
return CompletableFuture.completedFuture(UpdateStreamStatus.Status.FAILURE);
}
}).exceptionally(ex -> {
log.warn("Exception thrown in trying to notify sealed segments {}", ex.getMessage());
return handleUpdateStreamError(ex);
});
}
Aggregations