Search in sources :

Example 26 with RawClient

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

the class SegmentHelper method createTransaction.

public CompletableFuture<Void> createTransaction(final String scope, final String stream, final long segmentId, final UUID txId, final String delegationToken, final long clientRequestId, final long rolloverSizeBytes) {
    final Controller.NodeUri uri = getSegmentUri(scope, stream, segmentId);
    final String transactionName = getTransactionName(scope, stream, segmentId, txId);
    final WireCommandType type = WireCommandType.CREATE_SEGMENT;
    RawClient connection = new RawClient(ModelHelper.encode(uri), connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.CreateSegment request = new WireCommands.CreateSegment(requestId, transactionName, WireCommands.CreateSegment.NO_SCALE, 0, delegationToken, rolloverSizeBytes);
    return sendRequest(connection, clientRequestId, request).thenAccept(r -> handleReply(clientRequestId, r, connection, transactionName, 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) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 27 with RawClient

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

the class AdminSegmentHelper method listStorageChunks.

/**
 * This methods sends a WireCommand to get the list of storage chunks under the given segment name.
 *
 * @param qualifiedName   StreamSegmentName
 * @param uri             The uri of the Segment Store instance.
 * @param delegationToken The token to be presented to the Segment Store.
 * @return A CompletableFuture that return the list of storage chunks as a WireCommand.
 */
public CompletableFuture<WireCommands.StorageChunksListed> listStorageChunks(String qualifiedName, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.LIST_STORAGE_CHUNKS;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.ListStorageChunks request = new WireCommands.ListStorageChunks(qualifiedName, delegationToken, requestId);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, qualifiedName, WireCommands.ListStorageChunks.class, type);
        assert r instanceof WireCommands.StorageChunksListed;
        return (WireCommands.StorageChunksListed) 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 28 with RawClient

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

the class AdminSegmentHelper method flushToStorage.

/**
 * This method sends a WireCommand to flush the container corresponding to the given containerId to storage.
 *
 * @param containerId     The Id of the container that needs to be persisted to storage.
 * @param uri             The uri of the Segment Store instance.
 * @param delegationToken The token to be presented to the Segment Store.
 * @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.
 */
public CompletableFuture<WireCommands.StorageFlushed> flushToStorage(int containerId, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.FLUSH_TO_STORAGE;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.FlushToStorage request = new WireCommands.FlushToStorage(containerId, delegationToken, requestId);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, null, WireCommands.FlushToStorage.class, type);
        assert r instanceof WireCommands.StorageFlushed;
        return (WireCommands.StorageFlushed) 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 29 with RawClient

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

the class SegmentMetadataClientImpl method truncateSegmentAsync.

private CompletableFuture<SegmentTruncated> truncateSegmentAsync(Segment segment, long offset, DelegationTokenProvider tokenProvider) {
    log.debug("Truncating segment: {} at offset {}", segment, offset);
    RawClient connection = getConnection();
    long requestId = connection.getFlow().getNextSequenceNumber();
    return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new TruncateSegment(requestId, segment.getScopedName(), offset, token))).thenApply(r -> transformReply(r, SegmentTruncated.class));
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) Retry(io.pravega.common.util.Retry) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) RawClient(io.pravega.client.connection.impl.RawClient) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) AccessOperation(io.pravega.shared.security.auth.AccessOperation) TokenException(io.pravega.auth.TokenException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment) RetryWithBackoff(io.pravega.common.util.Retry.RetryWithBackoff) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) GuardedBy(javax.annotation.concurrent.GuardedBy) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) Slf4j(lombok.extern.slf4j.Slf4j) InvalidTokenException(io.pravega.auth.InvalidTokenException) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) RawClient(io.pravega.client.connection.impl.RawClient) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment)

Example 30 with RawClient

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

the class SegmentMetadataClientImpl method getPropertyAsync.

private CompletableFuture<WireCommands.SegmentAttribute> getPropertyAsync(UUID attributeId) {
    log.debug("Getting segment attribute: {}", attributeId);
    RawClient connection = getConnection();
    long requestId = connection.getFlow().getNextSequenceNumber();
    return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new GetSegmentAttribute(requestId, segmentId.getScopedName(), attributeId, token))).thenApply(r -> transformReply(r, WireCommands.SegmentAttribute.class));
}
Also used : SneakyThrows(lombok.SneakyThrows) TokenExpiredException(io.pravega.auth.TokenExpiredException) Retry(io.pravega.common.util.Retry) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) GetStreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.GetStreamSegmentInfo) RawClient(io.pravega.client.connection.impl.RawClient) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) AccessOperation(io.pravega.shared.security.auth.AccessOperation) TokenException(io.pravega.auth.TokenException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamSegmentInfo(io.pravega.shared.protocol.netty.WireCommands.StreamSegmentInfo) TruncateSegment(io.pravega.shared.protocol.netty.WireCommands.TruncateSegment) RetryWithBackoff(io.pravega.common.util.Retry.RetryWithBackoff) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) lombok.val(lombok.val) CompletionException(java.util.concurrent.CompletionException) DelegationTokenProviderFactory(io.pravega.client.security.auth.DelegationTokenProviderFactory) UUID(java.util.UUID) WireCommands(io.pravega.shared.protocol.netty.WireCommands) GuardedBy(javax.annotation.concurrent.GuardedBy) WrongHost(io.pravega.shared.protocol.netty.WireCommands.WrongHost) DelegationTokenProvider(io.pravega.client.security.auth.DelegationTokenProvider) SegmentAttributeUpdated(io.pravega.shared.protocol.netty.WireCommands.SegmentAttributeUpdated) Slf4j(lombok.extern.slf4j.Slf4j) InvalidTokenException(io.pravega.auth.InvalidTokenException) SegmentTruncated(io.pravega.shared.protocol.netty.WireCommands.SegmentTruncated) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException) Controller(io.pravega.client.control.impl.Controller) Futures(io.pravega.common.concurrent.Futures) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute) UpdateSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.UpdateSegmentAttribute) RawClient(io.pravega.client.connection.impl.RawClient) GetSegmentAttribute(io.pravega.shared.protocol.netty.WireCommands.GetSegmentAttribute)

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