Search in sources :

Example 16 with RawClient

use of io.pravega.client.connection.impl.RawClient 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;
    });
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 17 with RawClient

use of io.pravega.client.connection.impl.RawClient 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));
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) Controller(io.pravega.controller.stream.api.grpc.v1.Controller)

Example 18 with RawClient

use of io.pravega.client.connection.impl.RawClient 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));
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) Controller(io.pravega.controller.stream.api.grpc.v1.Controller)

Example 19 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method getSegmentAttribute.

public CompletableFuture<WireCommands.SegmentAttribute> getSegmentAttribute(String qualifiedName, UUID attributeId, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.GET_SEGMENT_ATTRIBUTE;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.GetSegmentAttribute request = new WireCommands.GetSegmentAttribute(requestId, qualifiedName, attributeId, delegationToken);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, qualifiedName, WireCommands.GetSegmentAttribute.class, type);
        assert r instanceof WireCommands.SegmentAttribute;
        return (WireCommands.SegmentAttribute) r;
    });
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 20 with RawClient

use of io.pravega.client.connection.impl.RawClient in project pravega by pravega.

the class SegmentHelper method createSegment.

public CompletableFuture<Void> createSegment(final String scope, final String stream, final long segmentId, final ScalingPolicy policy, final String controllerToken, final long clientRequestId, final long rolloverSizeBytes) {
    final String qualifiedStreamSegmentName = getQualifiedStreamSegmentName(scope, stream, segmentId);
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final WireCommandType type = WireCommandType.CREATE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    Pair<Byte, Integer> extracted = extractFromPolicy(policy);
    return sendRequest(connection, clientRequestId, new WireCommands.CreateSegment(requestId, qualifiedStreamSegmentName, extracted.getLeft(), extracted.getRight(), controllerToken, rolloverSizeBytes)).thenAccept(r -> handleReply(clientRequestId, r, connection, qualifiedStreamSegmentName, WireCommands.CreateSegment.class, type));
}
Also used : WireCommandType(io.pravega.shared.protocol.netty.WireCommandType) RawClient(io.pravega.client.connection.impl.RawClient) Controller(io.pravega.controller.stream.api.grpc.v1.Controller)

Aggregations

RawClient (io.pravega.client.connection.impl.RawClient)34 WireCommands (io.pravega.shared.protocol.netty.WireCommands)25 WireCommandType (io.pravega.shared.protocol.netty.WireCommandType)24 TokenExpiredException (io.pravega.auth.TokenExpiredException)17 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)17 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)16 Reply (io.pravega.shared.protocol.netty.Reply)15 VisibleForTesting (com.google.common.annotations.VisibleForTesting)14 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)14 ConnectionClosedException (io.pravega.client.stream.impl.ConnectionClosedException)14 Exceptions (io.pravega.common.Exceptions)14 UUID (java.util.UUID)14 CompletableFuture (java.util.concurrent.CompletableFuture)14 CompletionException (java.util.concurrent.CompletionException)14 Futures (io.pravega.common.concurrent.Futures)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 SneakyThrows (lombok.SneakyThrows)12 AuthenticationException (io.pravega.auth.AuthenticationException)10 Unpooled (io.netty.buffer.Unpooled)9 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)8