use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.
the class ControllerMetadataListEntriesCommand method execute.
@Override
public void execute() {
ensureArgCount(3);
final String tableName = getArg(0);
final int entryCount = getIntArg(1);
final String segmentStoreHost = getArg(2);
Preconditions.checkArgument(!isStreamMetadataTableName(tableName), "The given table %s is a stream metadata table. " + "Stream metadata tables are unsupported by this command.", tableName);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
HashTableIteratorItem<TableSegmentEntry> entries = completeSafely(adminSegmentHelper.readTableEntries(tableName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), entryCount, HashTableIteratorItem.State.EMPTY, super.authHelper.retrieveMasterToken(), 0L), tableName, null);
if (entries == null) {
return;
}
Map<String, List<String>> stringEntriesMap = entries.getItems().stream().collect(Collectors.toMap(entry -> KEY_SERIALIZER.deserialize(getByteBuffer(entry.getKey().getKey())), entry -> {
ControllerMetadataSerializer serializer = new ControllerMetadataSerializer(tableName, KEY_SERIALIZER.deserialize(getByteBuffer(entry.getKey().getKey())));
return List.of(serializer.deserialize(getByteBuffer(entry.getValue())).toString(), serializer.getMetadataType());
}));
output("List of at most %s entries in %s: ", entryCount, tableName);
stringEntriesMap.forEach((key, value) -> {
output("- %s", key);
userFriendlyOutput(value.get(0), value.get(1));
output("");
});
}
use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.
the class ControllerMetadataListKeysCommand method execute.
@Override
public void execute() {
ensureArgCount(3);
final String tableName = getArg(0);
final int keyCount = getIntArg(1);
final String segmentStoreHost = getArg(2);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
HashTableIteratorItem<TableSegmentKey> keys = completeSafely(adminSegmentHelper.readTableKeys(tableName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), keyCount, HashTableIteratorItem.State.EMPTY, super.authHelper.retrieveMasterToken(), 0L), tableName, null);
if (keys == null) {
return;
}
List<String> stringKeys = keys.getItems().stream().map(tableSegmentKey -> KEY_SERIALIZER.deserialize(getByteBuffer(tableSegmentKey.getKey()))).collect(Collectors.toList());
output("List of at most %s keys in %s: ", keyCount, tableName);
stringKeys.forEach(k -> output("- %s", k));
}
use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.
the class ListTableSegmentKeysCommand method execute.
@Override
public void execute() {
ensureArgCount(3);
ensureSerializersExist();
final String fullyQualifiedTableSegmentName = getArg(0);
final int keyCount = getIntArg(1);
final String segmentStoreHost = getArg(2);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
CompletableFuture<HashTableIteratorItem<TableSegmentKey>> reply = adminSegmentHelper.readTableKeys(fullyQualifiedTableSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), keyCount, HashTableIteratorItem.State.EMPTY, super.authHelper.retrieveMasterToken(), 0L);
List<String> keys = reply.join().getItems().stream().map(tableSegmentKey -> getCommandArgs().getState().getKeySerializer().deserialize(getByteBuffer(tableSegmentKey.getKey()))).collect(Collectors.toList());
output("List of at most %s keys in %s: ", keyCount, fullyQualifiedTableSegmentName);
keys.forEach(k -> output("- %s", k));
}
use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.
the class PutTableSegmentEntryCommand method execute.
@Override
public void execute() {
ensureArgCount(4);
ensureSerializersExist();
final String fullyQualifiedTableSegmentName = getArg(0);
final String segmentStoreHost = getArg(1);
final String key = getArg(2);
final String value = getArg(3);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
long version = updateTableEntry(fullyQualifiedTableSegmentName, key, value, segmentStoreHost, adminSegmentHelper);
output("Successfully updated the key %s in table %s with version %s", key, fullyQualifiedTableSegmentName, version);
}
use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.
the class GetTableSegmentInfoCommand method execute.
@Override
public void execute() {
ensureArgCount(2);
final String fullyQualifiedTableSegmentName = getArg(0);
final String segmentStoreHost = getArg(1);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
CompletableFuture<WireCommands.TableSegmentInfo> reply = adminSegmentHelper.getTableSegmentInfo(fullyQualifiedTableSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), super.authHelper.retrieveMasterToken());
WireCommands.TableSegmentInfo tableSegmentInfo = reply.join();
output("TableSegmentInfo for %s: ", fullyQualifiedTableSegmentName);
SEGMENT_INFO_FIELD_MAP.forEach((name, f) -> output("%s = %s", name, f.apply(tableSegmentInfo)));
}
Aggregations