use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method listScopes.
@Override
public void listScopes(Controller.ScopesRequest request, StreamObserver<Controller.ScopesResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), LIST_SCOPES);
log.info(requestTag.getRequestId(), "listScope called.");
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScopes(), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<Controller.ScopesResponse>> scopesFn = delegationToken -> listWithFilter(request.getContinuationToken().getToken(), pageLimit, (x, y) -> controllerService.listScopes(x, y, requestTag.getRequestId()), x -> grpcAuthHelper.isAuthorized(authorizationResource.ofScope(x), AuthHandler.Permissions.READ, ctx), x -> x, requestTag.getRequestId()).thenApply(response -> Controller.ScopesResponse.newBuilder().addAllScopes(response.getKey()).setContinuationToken(Controller.ContinuationToken.newBuilder().setToken(response.getValue()).build()).build());
authenticateExecuteAndProcessResults(stringSupplier, scopesFn, responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method isStreamCutValid.
@Override
public void isStreamCutValid(Controller.StreamCut request, StreamObserver<Controller.StreamCutValidityResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), IS_STREAMCUT_VALID, request.getStreamInfo().getScope(), request.getStreamInfo().getStream());
log.info(requestTag.getRequestId(), "isStreamCutValid called for stream {}/{} streamcut {}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getCutMap());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorizationAndCreateToken(authorizationResource.ofStreamInScope(request.getStreamInfo().getScope(), request.getStreamInfo().getStream()), AuthHandler.Permissions.READ), delegationToken -> controllerService.isStreamCutValid(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getCutMap(), requestTag.getRequestId()).thenApply(bRes -> Controller.StreamCutValidityResponse.newBuilder().setResponse(bRes).build()), responseObserver);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method isSegmentValid.
@Override
public void isSegmentValid(SegmentId request, StreamObserver<SegmentValidityResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), IS_SEGMENT_OPEN, request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), Long.toString(request.getSegmentId()));
log.info(requestTag.getRequestId(), "isSegmentValid called for segment {}/{}/{}.", request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getSegmentId());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(request.getStreamInfo().getScope(), request.getStreamInfo().getStream()), AuthHandler.Permissions.READ), delegationToken -> controllerService.isSegmentValid(request.getStreamInfo().getScope(), request.getStreamInfo().getStream(), request.getSegmentId(), requestTag.getRequestId()).thenApply(bRes -> SegmentValidityResponse.newBuilder().setResponse(bRes).build()), responseObserver);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method sealSegment.
/**
* This method sends segment sealed message for the specified segment.
* It owns up the responsibility of retrying the operation on failures until success.
*
* @param scope stream scope
* @param stream stream name
* @param segmentNumber number of segment to be sealed
* @param hostControllerStore host controller store
* @param clientCF connection factory
* @param delegationToken the token to be presented to segmentstore.
* @return void
*/
public CompletableFuture<Boolean> sealSegment(final String scope, final String stream, final int segmentNumber, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final CompletableFuture<Boolean> result = new CompletableFuture<>();
final WireCommandType type = WireCommandType.SEAL_SEGMENT;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("sealSegment {}/{}/{} connectionDropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("sealSegment {}/{}/{} wrongHost", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void segmentSealed(WireCommands.SegmentSealed segmentSealed) {
log.info("sealSegment {}/{}/{} segmentSealed", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void segmentIsSealed(WireCommands.SegmentIsSealed segmentIsSealed) {
log.info("sealSegment {}/{}/{} SegmentIsSealed", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void processingFailure(Exception error) {
log.error("sealSegment {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
WireCommands.SealSegment request = new WireCommands.SealSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method deleteSegment.
public CompletableFuture<Boolean> deleteSegment(final String scope, final String stream, final int segmentNumber, final HostControllerStore hostControllerStore, final ConnectionFactory clientCF, String delegationToken) {
final CompletableFuture<Boolean> result = new CompletableFuture<>();
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final WireCommandType type = WireCommandType.DELETE_SEGMENT;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("deleteSegment {}/{}/{} Connection dropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("deleteSegment {}/{}/{} wrong host", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void noSuchSegment(WireCommands.NoSuchSegment noSuchSegment) {
log.info("deleteSegment {}/{}/{} NoSuchSegment", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void segmentDeleted(WireCommands.SegmentDeleted segmentDeleted) {
log.info("deleteSegment {}/{}/{} SegmentDeleted", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void processingFailure(Exception error) {
log.error("deleteSegment {}/{}/{} failed", scope, stream, segmentNumber, error);
result.completeExceptionally(error);
}
@Override
public void authTokenCheckFailed(WireCommands.AuthTokenCheckFailed authTokenCheckFailed) {
result.completeExceptionally(new WireCommandFailedException(new AuthenticationException(authTokenCheckFailed.toString()), type, WireCommandFailedException.Reason.AuthFailed));
}
};
WireCommands.DeleteSegment request = new WireCommands.DeleteSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), delegationToken);
sendRequestAsync(request, replyProcessor, result, clientCF, ModelHelper.encode(uri));
return result;
}
Aggregations