Search in sources :

Example 1 with ConnectionPool

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

the class ControllerDescribeStreamCommand method execute.

@Override
public void execute() {
    ensureArgCount(2);
    final String scope = getArg(0);
    final String stream = getArg(1);
    try {
        @Cleanup CuratorFramework zkClient = createZKClient();
        ScheduledExecutorService executor = getCommandArgs().getState().getExecutor();
        @Cleanup ConnectionPool pool = createConnectionPool();
        // The Pravega Controller service may store metadata either at Zookeeper or the Segment Store service
        // (tables). We need to instantiate the correct type of metadata store object based on the cluster at hand.
        StreamMetadataStore store;
        @Cleanup SegmentHelper segmentHelper = null;
        if (getCLIControllerConfig().getMetadataBackend().equals(CLIConfig.MetadataBackends.ZOOKEEPER.name())) {
            store = StreamStoreFactory.createZKStore(zkClient, executor);
        } else {
            segmentHelper = instantiateSegmentHelper(zkClient, pool);
            GrpcAuthHelper authHelper;
            authHelper = GrpcAuthHelper.getDisabledAuthHelper();
            store = StreamStoreFactory.createPravegaTablesStore(segmentHelper, authHelper, zkClient, executor);
        }
        // Output the configuration of this Stream.
        CompletableFuture<StreamConfiguration> streamConfig = store.getConfiguration(scope, stream, null, executor);
        prettyJSONOutput("stream_config", streamConfig.join());
        // Output the state for this Stream.
        prettyJSONOutput("stream_state", store.getState(scope, stream, true, null, executor).join());
        // Output the total number of segments for this Stream.
        Set<Long> segments = store.getAllSegmentIds(scope, stream, null, executor).join();
        prettyJSONOutput("segment_count", segments.size());
        // Check if the Stream is sealed.
        prettyJSONOutput("is_sealed", store.isSealed(scope, stream, null, executor).join());
        // Output the active epoch for this Stream.
        prettyJSONOutput("active_epoch", store.getActiveEpoch(scope, stream, null, true, executor).join());
        // Output the number of active Transactions for ths Stream.
        Map<UUID, ActiveTxnRecord> activeTxn = store.getActiveTxns(scope, stream, null, getCommandArgs().getState().getExecutor()).join();
        if (!activeTxn.isEmpty()) {
            prettyJSONOutput("active_transactions", activeTxn);
        }
        // Output Truncation point.
        prettyJSONOutput("truncation_record", store.getTruncationRecord(scope, stream, null, executor).join().getObject());
        // Output the metadata that describes all the scaling information for this Stream.
        prettyJSONOutput("scaling_info", store.getScaleMetadata(scope, stream, segments.stream().min(Long::compareTo).get(), segments.stream().max(Long::compareTo).get(), null, executor).join());
        // Cleanup resources.
        if (segmentHelper != null) {
            segmentHelper.close();
            store.close();
        }
    } catch (Exception e) {
        System.err.println("Exception accessing the metadata store: " + e.getMessage());
    }
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) ActiveTxnRecord(io.pravega.controller.store.stream.records.ActiveTxnRecord) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup) CuratorFramework(org.apache.curator.framework.CuratorFramework) GrpcAuthHelper(io.pravega.controller.server.security.auth.GrpcAuthHelper) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) UUID(java.util.UUID)

Example 2 with ConnectionPool

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

the class ParseReaderGroupStreamCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(4);
    final String scope = getArg(0);
    final String readerGroup = getArg(1);
    final String segmentStoreHost = getArg(2);
    final String fileName = getArg(3);
    String stream = NameUtils.getStreamForReaderGroup(readerGroup);
    @Cleanup ConnectionPool pool = createConnectionPool();
    @Cleanup Controller controller = instantiateController(pool);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup SegmentHelper segmentHelper = instantiateSegmentHelper(zkClient, pool);
    readRGSegmentToFile(segmentHelper, segmentStoreHost, controller, scope, stream, fileName);
    output("The readerGroup stream has been successfully written into %s", fileName);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) CuratorFramework(org.apache.curator.framework.CuratorFramework) Controller(io.pravega.client.control.impl.Controller) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup)

Example 3 with ConnectionPool

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

the class ReadSegmentRangeCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(5);
    final String fullyQualifiedSegmentName = getArg(0);
    final long offset = getLongArg(1);
    final long length = getLongArg(2);
    final String segmentStoreHost = getArg(3);
    final String fileName = getArg(4);
    Preconditions.checkArgument(offset >= 0, "The provided offset cannot be negative.");
    Preconditions.checkArgument(length >= 0, "The provided length cannot be negative.");
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup ConnectionPool pool = createConnectionPool();
    @Cleanup SegmentHelper segmentHelper = instantiateSegmentHelper(zkClient, pool);
    output("Downloading %d bytes from offset %d into %s.", length, offset, fileName);
    readAndWriteSegmentToFile(segmentHelper, segmentStoreHost, fullyQualifiedSegmentName, offset, length, fileName, getServiceConfig().getAdminGatewayPort(), super.authHelper.retrieveMasterToken());
    output("\nThe segment data has been successfully written into %s", fileName);
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) CuratorFramework(org.apache.curator.framework.CuratorFramework) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup)

Example 4 with ConnectionPool

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

the class GetSegmentInfoCommand method execute.

@Override
public void execute() {
    ensureArgCount(2);
    final String fullyQualifiedSegmentName = getArg(0);
    final String segmentStoreHost = getArg(1);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup ConnectionPool pool = createConnectionPool();
    @Cleanup SegmentHelper segmentHelper = instantiateSegmentHelper(zkClient, pool);
    CompletableFuture<WireCommands.StreamSegmentInfo> reply = segmentHelper.getSegmentInfo(fullyQualifiedSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), super.authHelper.retrieveMasterToken(), 0L);
    output("StreamSegmentInfo: %s", reply.join().toString());
}
Also used : ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) SegmentHelper(io.pravega.controller.server.SegmentHelper) Cleanup(lombok.Cleanup)

Example 5 with ConnectionPool

use of io.pravega.client.connection.impl.ConnectionPool 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

ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)41 Cleanup (lombok.Cleanup)22 ConnectionPoolImpl (io.pravega.client.connection.impl.ConnectionPoolImpl)19 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)19 ClientConfig (io.pravega.client.ClientConfig)17 CompletableFuture (java.util.concurrent.CompletableFuture)17 Test (org.junit.Test)16 UUID (java.util.UUID)14 StreamManager (io.pravega.client.admin.StreamManager)13 StreamManagerImpl (io.pravega.client.admin.impl.StreamManagerImpl)13 List (java.util.List)13 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)12 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11 ScalingPolicy (io.pravega.client.stream.ScalingPolicy)11 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)11 ConnectionFactory (io.pravega.client.connection.impl.ConnectionFactory)10 Exceptions (io.pravega.common.Exceptions)10 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)10 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)10 WireCommands (io.pravega.shared.protocol.netty.WireCommands)10