use of io.pravega.shared.controller.tracing.RPCTracingTags.CHECK_STREAM_EXISTS 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);
}
Aggregations