use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class StreamMetadataTasks method generateStreamCut.
/**
* Generate a new stream cut.
*
* @param scope scope.
* @param stream stream name.
* @param contextOpt optional context
* @param delegationToken token to be sent to segmentstore.
* @param previous previous stream cut record
* @return streamCut.
*/
public CompletableFuture<StreamCutRecord> generateStreamCut(final String scope, final String stream, final StreamCutRecord previous, final OperationContext contextOpt, String delegationToken) {
final OperationContext context = contextOpt != null ? contextOpt : streamMetadataStore.createStreamContext(scope, stream, ControllerService.nextRequestId());
return streamMetadataStore.getActiveSegments(scope, stream, context, executor).thenCompose(activeSegments -> Futures.allOfWithResults(activeSegments.stream().parallel().collect(Collectors.toMap(x -> x, x -> getSegmentOffset(scope, stream, x.segmentId(), delegationToken, context.getRequestId()))))).thenCompose(map -> {
final long generationTime = retentionClock.get().get();
ImmutableMap.Builder<Long, Long> builder = ImmutableMap.builder();
map.forEach((key, value) -> builder.put(key.segmentId(), value));
ImmutableMap<Long, Long> streamCutMap = builder.build();
return streamMetadataStore.getSizeTillStreamCut(scope, stream, streamCutMap, Optional.ofNullable(previous), context, executor).thenApply(sizeTill -> new StreamCutRecord(generationTime, sizeTill, streamCutMap));
});
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class StreamMetadataTasks method retention.
/**
* Method to check retention policy and generate new periodic cuts and/or truncate stream at an existing stream cut.
*
* @param scope scope
* @param stream stream
* @param policy retention policy
* @param recordingTime time of recording
* @param contextOpt operation context
* @param delegationToken token to be sent to segmentstore to authorize this operation.
* @return future.
*/
public CompletableFuture<Void> retention(final String scope, final String stream, final RetentionPolicy policy, final long recordingTime, final OperationContext contextOpt, final String delegationToken) {
Preconditions.checkNotNull(policy);
final OperationContext context = contextOpt != null ? contextOpt : streamMetadataStore.createStreamContext(scope, stream, ControllerService.nextRequestId());
return streamMetadataStore.getRetentionSet(scope, stream, context, executor).thenCompose(retentionSet -> {
StreamCutReferenceRecord latestCut = retentionSet.getLatest();
return generateStreamCutIfRequired(scope, stream, latestCut, recordingTime, context, delegationToken).thenCompose(newRecord -> truncate(scope, stream, policy, context, retentionSet, newRecord));
}).thenAccept(x -> StreamMetrics.reportRetentionEvent(scope, stream));
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method removeWriter.
@Override
public void removeWriter(Controller.RemoveWriterRequest request, StreamObserver<Controller.RemoveWriterResponse> responseObserver) {
StreamInfo streamInfo = request.getStream();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), REMOVE_WRITER, streamInfo.getScope(), streamInfo.getStream(), request.getWriter());
log.info(requestTag.getRequestId(), "writerShutdown called for stream {}/{}, writer={}", streamInfo.getScope(), streamInfo.getStream(), request.getWriter());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(streamInfo.getScope(), streamInfo.getStream()), AuthHandler.Permissions.READ_UPDATE), delegationToken -> controllerService.removeWriter(streamInfo.getScope(), streamInfo.getStream(), request.getWriter(), requestTag.getRequestId()), responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method checkStreamExists.
@Override
public void checkStreamExists(StreamInfo request, StreamObserver<Controller.ExistsResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), CHECK_STREAM_EXISTS);
String scope = request.getScope();
String stream = request.getStream();
log.info(requestTag.getRequestId(), "checkStream exists called for {}/{}.", scope, stream);
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(scope, stream), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<Controller.ExistsResponse>> streamFn = delegationToken -> controllerService.getStream(scope, stream, requestTag.getRequestId()).handle((response, e) -> {
boolean exists;
if (e != null) {
if (Exceptions.unwrap(e) instanceof StoreException.DataNotFoundException) {
exists = false;
} else {
throw new CompletionException(e);
}
} else {
exists = true;
}
return Controller.ExistsResponse.newBuilder().setExists(exists).build();
});
authenticateExecuteAndProcessResults(stringSupplier, streamFn, responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method listStreamsInScope.
@Override
public void listStreamsInScope(Controller.StreamsInScopeRequest request, StreamObserver<Controller.StreamsInScopeResponse> responseObserver) {
String scopeName = request.getScope().getScope();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_STREAMS_IN_SCOPE, scopeName);
log.info(requestTag.getRequestId(), "listStream called for scope {}.", scopeName);
final AuthContext ctx = this.grpcAuthHelper.isAuthEnabled() ? AuthContext.current() : null;
Function<String, CompletableFuture<Controller.StreamsInScopeResponse>> streamsFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listStreams(scopeName, x, y, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofStreamInScope(scopeName, x), AuthHandler.Permissions.READ, ctx), x -> StreamInfo.newBuilder().setScope(scopeName).setStream(x).build(), requestTag.getRequestId()).handle((response, ex) -> {
if (ex != null) {
if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
return Controller.StreamsInScopeResponse.newBuilder().setStatus(Controller.StreamsInScopeResponse.Status.SCOPE_NOT_FOUND).build();
} else {
throw new CompletionException(ex);
}
} else {
return Controller.StreamsInScopeResponse.newBuilder().addAllStreams(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).setStatus(Controller.StreamsInScopeResponse.Status.SUCCESS).build();
}
});
authenticateExecuteAndProcessResults(() -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScope(scopeName), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScope(scopeName), result);
return result;
}, streamsFn, responseObserver, requestTag);
}
Aggregations