use of io.pravega.common.tracing.RequestTag in project pravega by pravega.
the class ControllerServiceImpl method checkScale.
@Override
public void checkScale(ScaleStatusRequest request, StreamObserver<ScaleStatusResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), CHECK_SCALE, request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), Integer.toString(request.getEpoch()));
log.debug(requestTag.getRequestId(), "check scale status called for stream {}/{}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(request.getStreamInfo().getScope(), request.getStreamInfo().getStream()), AuthHandler.Permissions.READ), delegationToken -> controllerService.checkScale(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getEpoch(), requestTag.getRequestId()), responseObserver);
}
use of io.pravega.common.tracing.RequestTag in project pravega by pravega.
the class ControllerServiceImpl method getCurrentSegments.
@Override
public void getCurrentSegments(StreamInfo request, StreamObserver<SegmentRanges> responseObserver) {
final String scope = request.getScope();
final String stream = request.getStream();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), GET_CURRENT_SEGMENTS, request.getScope(), request.getStream());
log.info(requestTag.getRequestId(), "getCurrentSegments called for stream {}/{}.", scope, stream);
String resource = StreamAuthParams.toResourceString(scope, stream);
final boolean isDelegationTokenRequested = !request.getAccessOperation().equals(StreamInfo.AccessOperation.NONE);
authenticateExecuteAndProcessResults(() -> {
if (isDelegationTokenRequested) {
// by this method for both reads and writes.
return this.grpcAuthHelper.checkAuthorizationAndCreateToken(resource, AuthHandler.Permissions.READ_UPDATE);
} else {
return this.grpcAuthHelper.checkAuthorization(resource, AuthHandler.Permissions.READ);
}
}, authorizationResult -> {
logIfEmpty(authorizationResult, "getCurrentSegments", scope, stream);
return controllerService.getCurrentSegments(scope, stream, requestTag.getRequestId()).thenApply(segmentRanges -> {
SegmentRanges.Builder builder = SegmentRanges.newBuilder().addAllSegmentRanges(segmentRanges);
if (isDelegationTokenRequested) {
builder.setDelegationToken(authorizationResult);
}
return builder.build();
});
}, responseObserver, requestTag);
}
use of io.pravega.common.tracing.RequestTag 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.common.tracing.RequestTag 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.common.tracing.RequestTag in project pravega by pravega.
the class ControllerServiceImpl method abortTransaction.
@Override
public void abortTransaction(TxnRequest request, StreamObserver<TxnStatus> responseObserver) {
final UUID txnId = ModelHelper.encode(request.getTxnId());
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), ABORT_TRANSACTION, request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), txnId.toString());
log.info(requestTag.getRequestId(), "abortTransaction called for stream {}/{}, txnId={}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), txnId);
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(request.getStreamInfo().getScope(), request.getStreamInfo().getStream()), AuthHandler.Permissions.READ_UPDATE), delegationToken -> controllerService.abortTransaction(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), txnId, requestTag.getRequestId()), responseObserver);
}
Aggregations