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());
}
}
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);
}
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);
}
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());
}
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());
});
}
}
Aggregations