use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method getSegmentInfo.
public CompletableFuture<WireCommands.StreamSegmentInfo> getSegmentInfo(String scope, String stream, int segmentNumber, HostControllerStore hostControllerStore, ConnectionFactory clientCF, String delegationToken) {
final CompletableFuture<WireCommands.StreamSegmentInfo> result = new CompletableFuture<>();
final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentNumber, hostControllerStore);
final WireCommandType type = WireCommandType.GET_STREAM_SEGMENT_INFO;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("getSegmentInfo {}/{}/{} connectionDropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("getSegmentInfo {}/{}/{} WrongHost", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void streamSegmentInfo(WireCommands.StreamSegmentInfo streamInfo) {
log.info("getSegmentInfo {}/{}/{} got response", scope, stream, segmentNumber);
result.complete(streamInfo);
}
@Override
public void processingFailure(Exception error) {
log.error("getSegmentInfo {}/{}/{} 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.GetStreamSegmentInfo request = new WireCommands.GetStreamSegmentInfo(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 truncateSegment.
public CompletableFuture<Boolean> truncateSegment(final String scope, final String stream, final int segmentNumber, final long offset, 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.TRUNCATE_SEGMENT;
final FailingReplyProcessor replyProcessor = new FailingReplyProcessor() {
@Override
public void connectionDropped() {
log.warn("truncateSegment {}/{}/{} Connection dropped", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.ConnectionDropped));
}
@Override
public void wrongHost(WireCommands.WrongHost wrongHost) {
log.warn("truncateSegment {}/{}/{} Wrong host", scope, stream, segmentNumber);
result.completeExceptionally(new WireCommandFailedException(type, WireCommandFailedException.Reason.UnknownHost));
}
@Override
public void segmentTruncated(WireCommands.SegmentTruncated segmentTruncated) {
log.info("truncateSegment {}/{}/{} SegmentTruncated", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void segmentIsTruncated(WireCommands.SegmentIsTruncated segmentIsTruncated) {
log.info("truncateSegment {}/{}/{} SegmentIsTruncated", scope, stream, segmentNumber);
result.complete(true);
}
@Override
public void processingFailure(Exception error) {
log.error("truncateSegment {}/{}/{} error", 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.TruncateSegment request = new WireCommands.TruncateSegment(idGenerator.get(), Segment.getScopedName(scope, stream, segmentNumber), offset, 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 getTableSegmentInfo.
/**
* This method sends a WireCommand to get information about a Table Segment.
*
* @param tableName Qualified table name.
* @param delegationToken The token to be presented to the segmentstore.
* @param clientRequestId Request id.
* @return A CompletableFuture that, when completed successfully, will return information about the Table Segment.
* 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<WireCommands.TableSegmentInfo> getTableSegmentInfo(final String tableName, String delegationToken, final long clientRequestId) {
final Controller.NodeUri uri = getTableUri(tableName);
final WireCommandType type = WireCommandType.GET_TABLE_SEGMENT_INFO;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
// All Controller Metadata Segments are non-sorted.
return sendRequest(connection, clientRequestId, new WireCommands.GetTableSegmentInfo(requestId, tableName, delegationToken)).thenApply(r -> {
handleReply(clientRequestId, r, connection, tableName, WireCommands.GetTableSegmentInfo.class, type);
assert r instanceof WireCommands.TableSegmentInfo;
return (WireCommands.TableSegmentInfo) r;
});
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method deleteSegment.
public CompletableFuture<Void> deleteSegment(final String scope, final String stream, final long segmentId, 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.DELETE_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
return sendRequest(connection, clientRequestId, new WireCommands.DeleteSegment(requestId, qualifiedStreamSegmentName, delegationToken)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedStreamSegmentName, WireCommands.DeleteSegment.class, type));
}
use of io.pravega.controller.stream.api.grpc.v1.Controller.DelegationToken in project pravega by pravega.
the class SegmentHelper method deleteTableSegment.
/**
* This method sends a WireCommand to delete a table segment.
*
* @param tableName Qualified table name.
* @param mustBeEmpty Flag to check if the table segment should be empty before deletion.
* @param delegationToken The token to be presented to the segmentstore.
* @param clientRequestId Request id.
* @return A CompletableFuture that, when completed normally, will indicate the table segment deletion completed
* successfully. 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> deleteTableSegment(final String tableName, final boolean mustBeEmpty, String delegationToken, final long clientRequestId) {
final Controller.NodeUri uri = getTableUri(tableName);
final WireCommandType type = WireCommandType.DELETE_TABLE_SEGMENT;
RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
final long requestId = connection.getFlow().asLong();
return sendRequest(connection, clientRequestId, new WireCommands.DeleteTableSegment(requestId, tableName, mustBeEmpty, delegationToken)).thenAccept(rpl -> handleReply(clientRequestId, rpl, connection, tableName, WireCommands.DeleteTableSegment.class, type));
}
Aggregations