use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method updateTableEntries.
public CompletableFuture<List<TableSegmentKeyVersion>> updateTableEntries(final String tableName, final PravegaNodeUri uri, final List<TableSegmentEntry> entries, String delegationToken, final long clientRequestId) {
final WireCommandType type = WireCommandType.UPDATE_TABLE_ENTRIES;
List<Map.Entry<WireCommands.TableKey, WireCommands.TableValue>> wireCommandEntries = entries.stream().map(te -> {
final WireCommands.TableKey key = convertToWireCommand(te.getKey());
final WireCommands.TableValue value = new WireCommands.TableValue(te.getValue());
return new AbstractMap.SimpleImmutableEntry<>(key, value);
}).collect(Collectors.toList());
RawClient connection = new RawClient(uri, connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.UpdateTableEntries request = new WireCommands.UpdateTableEntries(requestId, tableName, delegationToken, new WireCommands.TableEntries(wireCommandEntries), WireCommands.NULL_TABLE_SEGMENT_OFFSET);
return sendRequest(connection, clientRequestId, request).thenApply(rpl -> {
handleReply(clientRequestId, rpl, connection, tableName, WireCommands.UpdateTableEntries.class, type);
return ((WireCommands.TableEntriesUpdated) rpl).getUpdatedVersions().stream().map(TableSegmentKeyVersion::from).collect(Collectors.toList());
});
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method truncateSegment.
public CompletableFuture<Void> truncateSegment(final String scope, final String stream, final long segmentId, final long offset, final String delegationToken, final long clientRequestId) {
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
final String qualifiedStreamSegmentName = getQualifiedStreamSegmentName(scope, stream, segmentId);
final WireCommandType type = WireCommandType.TRUNCATE_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
return sendRequest(connection, clientRequestId, new WireCommands.TruncateSegment(requestId, qualifiedStreamSegmentName, offset, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedStreamSegmentName, WireCommands.TruncateSegment.class, type));
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method noteTimestampFromWriter.
// region watermarking apis
@Override
public void noteTimestampFromWriter(Controller.TimestampFromWriter request, StreamObserver<Controller.TimestampResponse> responseObserver) {
StreamInfo streamInfo = request.getPosition().getStreamInfo();
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), NOTE_TIMESTAMP_FROM_WRITER, streamInfo.getScope(), streamInfo.getStream(), request.getWriter());
log.info(requestTag.getRequestId(), "noteWriterMark called for stream {}/{}, writer={} time={}", streamInfo.getScope(), streamInfo.getStream(), request.getWriter(), request.getTimestamp());
authenticateExecuteAndProcessResults(() -> this.grpcAuthHelper.checkAuthorization(authorizationResource.ofStreamInScope(streamInfo.getScope(), streamInfo.getStream()), AuthHandler.Permissions.READ_UPDATE), delegationToken -> controllerService.noteTimestampFromWriter(streamInfo.getScope(), streamInfo.getStream(), request.getWriter(), request.getTimestamp(), request.getPosition().getCutMap(), requestTag.getRequestId()), responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class ControllerServiceImpl method checkScopeExists.
@Override
public void checkScopeExists(ScopeInfo request, StreamObserver<Controller.ExistsResponse> responseObserver) {
RequestTag requestTag = requestTracker.initializeAndTrackRequestTag(controllerService.nextRequestId(), CHECK_SCOPE_EXISTS, request.getScope());
String scope = request.getScope();
log.info(requestTag.getRequestId(), "checkScopeExists called for scope {}.", request);
final AuthContext ctx;
if (this.grpcAuthHelper.isAuthEnabled()) {
ctx = AuthContext.current();
} else {
ctx = null;
}
Supplier<String> stringSupplier = () -> {
String result = this.grpcAuthHelper.checkAuthorization(authorizationResource.ofScope(scope), AuthHandler.Permissions.READ, ctx);
log.debug("Result of authorization for [{}] and READ permission is: [{}]", authorizationResource.ofScopes(), result);
return result;
};
Function<String, CompletableFuture<Controller.ExistsResponse>> scopeFn = delegationToken -> controllerService.getScope(scope, 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, scopeFn, responseObserver, requestTag);
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method removeTableKeys.
/**
* This method sends a WireCommand to remove table keys.
*
* @param tableName Qualified table name.
* @param keys List of {@link TableSegmentKey}s to be removed. Only if all the elements in the list has version
* as {@link TableSegmentKeyVersion#NO_VERSION} then an unconditional update/removal is performed.
* Else an atomic conditional update (removal) is performed.
* @param delegationToken The token to be presented to the Segment Store.
* @param clientRequestId Request id.
* @return A CompletableFuture that will complete normally when the provided keys are deleted.
* If the operation failed, the future will be failed with the causing exception. If the exception can be
* retried then the future will be failed with {@link WireCommandFailedException}.
*/
public CompletableFuture<Void> removeTableKeys(final String tableName, final List<TableSegmentKey> keys, String delegationToken, final long clientRequestId) {
final Controller.NodeUri uri = getTableUri(tableName);
final WireCommandType type = WireCommandType.REMOVE_TABLE_KEYS;
List<WireCommands.TableKey> keyList = keys.stream().map(x -> {
WireCommands.TableKey key = convertToWireCommand(x);
return key;
}).collect(Collectors.toList());
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
WireCommands.RemoveTableKeys request = new WireCommands.RemoveTableKeys(requestId, tableName, delegationToken, keyList, WireCommands.NULL_TABLE_SEGMENT_OFFSET);
return sendRequest(connection, clientRequestId, request).thenAccept(rpl -> handleReply(clientRequestId, rpl, connection, tableName, WireCommands.RemoveTableKeys.class, type));
}
Aggregations