Search in sources :

Example 1 with RawClient

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

the class AdminSegmentHelper method getTableSegmentInfo.

/**
 * This method sends a WireCommand to get table segment info for the given table 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 will return the table segment info as a WireCommand.
 */
public CompletableFuture<WireCommands.TableSegmentInfo> getTableSegmentInfo(String qualifiedName, PravegaNodeUri uri, String delegationToken) {
    final WireCommandType type = WireCommandType.GET_TABLE_SEGMENT_INFO;
    RawClient connection = new RawClient(uri, connectionPool);
    final long requestId = connection.getFlow().asLong();
    WireCommands.GetTableSegmentInfo request = new WireCommands.GetTableSegmentInfo(requestId, qualifiedName, delegationToken);
    return sendRequest(connection, requestId, request).thenApply(r -> {
        handleReply(requestId, r, connection, qualifiedName, 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) WireCommands(io.pravega.shared.protocol.netty.WireCommands)

Example 2 with RawClient

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

the class SegmentMetadataClientImpl method closeConnection.

private void closeConnection(Reply badReply) {
    log.info("Closing connection as a result of receiving: {}", badReply);
    RawClient c;
    synchronized (lock) {
        c = client;
        client = null;
    }
    if (c != null) {
        try {
            c.close();
        } catch (Exception e) {
            log.warn("Exception tearing down connection: ", e);
        }
    }
}
Also used : RawClient(io.pravega.client.connection.impl.RawClient) TokenExpiredException(io.pravega.auth.TokenExpiredException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) TokenException(io.pravega.auth.TokenException) CompletionException(java.util.concurrent.CompletionException) InvalidTokenException(io.pravega.auth.InvalidTokenException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException)

Example 3 with RawClient

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

the class SegmentMetadataClientImpl method closeConnection.

private void closeConnection(Throwable exceptionToInflightRequests) {
    log.debug("Closing connection with exception: {}", exceptionToInflightRequests.getMessage());
    RawClient c;
    synchronized (lock) {
        c = client;
        client = null;
    }
    if (c != null) {
        try {
            c.close();
        } catch (Exception e) {
            log.warn("Exception tearing down connection: ", e);
        }
    }
}
Also used : RawClient(io.pravega.client.connection.impl.RawClient) TokenExpiredException(io.pravega.auth.TokenExpiredException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) TokenException(io.pravega.auth.TokenException) CompletionException(java.util.concurrent.CompletionException) InvalidTokenException(io.pravega.auth.InvalidTokenException) ConnectionClosedException(io.pravega.client.stream.impl.ConnectionClosedException)

Example 4 with RawClient

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

the class SegmentMetadataClientImpl method sealSegmentAsync.

private CompletableFuture<SegmentSealed> sealSegmentAsync(Segment segment, DelegationTokenProvider tokenProvider) {
    log.trace("Sealing segment: {}", segment);
    RawClient connection = getConnection();
    long requestId = connection.getFlow().getNextSequenceNumber();
    return tokenProvider.retrieveToken().thenCompose(token -> connection.sendRequest(requestId, new SealSegment(requestId, segment.getScopedName(), token))).thenApply(r -> transformReply(r, SegmentSealed.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) SegmentSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentSealed) RawClient(io.pravega.client.connection.impl.RawClient) SealSegment(io.pravega.shared.protocol.netty.WireCommands.SealSegment)

Example 5 with RawClient

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

the class ConditionalOutputStreamImpl method write.

@Override
public boolean write(ByteBuffer data, long expectedOffset) throws SegmentSealedException {
    Exceptions.checkNotClosed(closed.get(), this);
    synchronized (lock) {
        // Used to preserver order.
        long appendSequence = requestIdGenerator.get();
        return retrySchedule.retryWhen(e -> {
            Throwable cause = Exceptions.unwrap(e);
            boolean hasTokenExpired = cause instanceof TokenExpiredException;
            if (hasTokenExpired) {
                this.tokenProvider.signalTokenExpired();
            }
            return cause instanceof Exception && (hasTokenExpired || cause instanceof ConnectionFailedException);
        }).run(() -> {
            if (client == null || client.isClosed()) {
                client = new RawClient(controller, connectionPool, segmentId);
                long requestId = client.getFlow().getNextSequenceNumber();
                log.debug("Setting up appends on segment {} for ConditionalOutputStream with writer id {}", segmentId, writerId);
                CompletableFuture<Reply> reply = tokenProvider.retrieveToken().thenCompose(token -> {
                    SetupAppend setup = new SetupAppend(requestId, writerId, segmentId.getScopedName(), token);
                    return client.sendRequest(requestId, setup);
                });
                AppendSetup appendSetup = transformAppendSetup(reply.join());
                if (appendSetup.getLastEventNumber() >= appendSequence) {
                    return true;
                }
            }
            long requestId = client.getFlow().getNextSequenceNumber();
            val request = new ConditionalAppend(writerId, appendSequence, expectedOffset, new Event(Unpooled.wrappedBuffer(data)), requestId);
            val reply = client.sendRequest(requestId, request);
            return transformDataAppended(reply.join());
        });
    }
}
Also used : Event(io.pravega.shared.protocol.netty.WireCommands.Event) TokenExpiredException(io.pravega.auth.TokenExpiredException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) Reply(io.pravega.shared.protocol.netty.Reply) Exceptions(io.pravega.common.Exceptions) ConditionalCheckFailed(io.pravega.shared.protocol.netty.WireCommands.ConditionalCheckFailed) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) RawClient(io.pravega.client.connection.impl.RawClient) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) AuthTokenCheckFailed(io.pravega.shared.protocol.netty.WireCommands.AuthTokenCheckFailed) ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) RetryWithBackoff(io.pravega.common.util.Retry.RetryWithBackoff) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) lombok.val(lombok.val) AuthenticationException(io.pravega.auth.AuthenticationException) 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) AtomicLong(java.util.concurrent.atomic.AtomicLong) InvalidEventNumber(io.pravega.shared.protocol.netty.WireCommands.InvalidEventNumber) Slf4j(lombok.extern.slf4j.Slf4j) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DataAppended(io.pravega.shared.protocol.netty.WireCommands.DataAppended) SegmentIsSealed(io.pravega.shared.protocol.netty.WireCommands.SegmentIsSealed) Controller(io.pravega.client.control.impl.Controller) lombok.val(lombok.val) ConditionalAppend(io.pravega.shared.protocol.netty.WireCommands.ConditionalAppend) RawClient(io.pravega.client.connection.impl.RawClient) TokenExpiredException(io.pravega.auth.TokenExpiredException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) AuthenticationException(io.pravega.auth.AuthenticationException) AppendSetup(io.pravega.shared.protocol.netty.WireCommands.AppendSetup) TokenExpiredException(io.pravega.auth.TokenExpiredException) SetupAppend(io.pravega.shared.protocol.netty.WireCommands.SetupAppend) Reply(io.pravega.shared.protocol.netty.Reply) Event(io.pravega.shared.protocol.netty.WireCommands.Event) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException)

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