use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method getStreamConfiguration.
@Override
public void getStreamConfiguration(StreamInfo request, StreamObserver<StreamConfig> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_STREAM_CONFIGURATION);
String scope = request.getScope();
String stream = request.getStream();
log.info(requestTag.getRequestId(), "{} called for {}/{}.", GET_STREAM_CONFIGURATION, 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<StreamConfig>> streamFn = delegationToken -> controllerService.getStream(scope, stream, requestTag.getRequestId()).handle((response, e) -> {
if (e != null) {
throw new CompletionException(e);
} else {
return decode(scope, stream, response);
}
});
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 createTransaction.
@Override
public void createTransaction(CreateTxnRequest request, StreamObserver<Controller.CreateTxnResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), CREATE_TRANSACTION, request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), Long.toString(request.getLease()));
log.info(requestTag.getRequestId(), "createTransaction called for stream {}/{}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorizationAndCreateToken(authorizationResource.ofStreamInScope(request.getStreamInfo().getScope(), request.getStreamInfo().getStream()), AuthHandler.Permissions.READ_UPDATE), delegationToken -> controllerService.createTransaction(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getLease(), requestTag.getRequestId()).thenApply(pair -> Controller.CreateTxnResponse.newBuilder().setDelegationToken(delegationToken).setTxnId(decode(pair.getKey())).addAllActiveSegments(pair.getValue()).build()), responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method getSegmentsBetween.
@Override
public void getSegmentsBetween(Controller.StreamCutRange request, StreamObserver<Controller.StreamCutRangeResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_SEGMENTS_BETWEEN_STREAM_CUTS, request.getStreamInfo().getScope(), request.getStreamInfo().getStream());
log.info(requestTag.getRequestId(), "getSegmentsBetweenStreamCuts called for stream {} for cuts from {} to {}", request.getStreamInfo(), request.getFromMap(), request.getToMap());
String scope = request.getStreamInfo().getScope();
String stream = request.getStreamInfo().getStream();
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorizationAndCreateToken(authorizationResource.ofStreamInScope(scope, stream), AuthHandler.Permissions.READ), delegationToken -> {
logIfEmpty(delegationToken, "getSegmentsBetween", request.getStreamInfo().getScope(), request.getStreamInfo().getStream());
return controllerService.getSegmentsBetweenStreamCuts(request, requestTag.getRequestId()).thenApply(segments -> ModelHelper.createStreamCutRangeResponse(scope, stream, segments.stream().map(x -> ModelHelper.createSegmentId(scope, stream, x.segmentId())).collect(Collectors.toList()), delegationToken));
}, responseObserver);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method listKeyValueTablesInScope.
@Override
public void listKeyValueTablesInScope(Controller.KVTablesInScopeRequest request, StreamObserver<Controller.KVTablesInScopeResponse> responseObserver) {
String scopeName = request.getScope().getScope();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_KEY_VALUE_TABLES, scopeName);
log.info(requestTag.getRequestId(), "listKeyValueTables called for scope {}.", scopeName);
final AuthContext ctx = this.grpcAuthHelper.isAuthEnabled() ? AuthContext.current() : null;
Function<String, CompletableFuture<Controller.KVTablesInScopeResponse>> streamsFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listKeyValueTables(scopeName, x, y, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofKeyValueTableInScope(scopeName, x), AuthHandler.Permissions.READ, ctx), x -> KeyValueTableInfo.newBuilder().setScope(scopeName).setKvtName(x).build(), requestTag.getRequestId()).handle((response, ex) -> {
if (ex != null) {
if (Exceptions.unwrap(ex) instanceof StoreException.DataNotFoundException) {
return Controller.KVTablesInScopeResponse.newBuilder().setStatus(Controller.KVTablesInScopeResponse.Status.SCOPE_NOT_FOUND).build();
} else {
throw new CompletionException(ex);
}
} else {
return Controller.KVTablesInScopeResponse.newBuilder().addAllKvtables(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).setStatus(Controller.KVTablesInScopeResponse.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);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method getSegmentsImmediatelyFollowing.
@Override
public void getSegmentsImmediatelyFollowing(SegmentId segmentId, StreamObserver<SuccessorResponse> responseObserver) {
String segment = NameUtils.getQualifiedStreamSegmentName(segmentId.getStreamInfo().getScope(), segmentId.getStreamInfo().getStream(), segmentId.getSegmentId());
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_SEGMENTS_IMMEDIATELY_FOLLOWING, segment);
log.info(requestTag.getRequestId(), "getSegmentsImmediatelyFollowing called for segment {} ", segment);
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(segmentId.getStreamInfo().getScope(), segmentId.getStreamInfo().getStream()), AuthHandler.Permissions.READ), delegationToken -> controllerService.getSegmentsImmediatelyFollowing(segmentId, requestTag.getRequestId()).thenApply(ModelHelper::createSuccessorResponse).thenApply(response -> {
response.setDelegationToken(delegationToken);
return response.build();
}), responseObserver);
}
Aggregations