use of io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer 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.serializers.controller.ControllerMetadataSerializer in project pravega by pravega.
the class ControllerMetadataGetEntryCommand method execute.
@Override
public void execute() throws Exception {
Preconditions.checkArgument(getArgCount() >= 3 && getArgCount() < 5, "Incorrect argument count.");
final String tableName = getArg(0);
final String key = getArg(1);
final String segmentStoreHost = getArg(2);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
ControllerMetadataSerializer serializer = new ControllerMetadataSerializer(tableName, key);
TableSegmentEntry entry = getTableEntry(tableName, key, segmentStoreHost, adminSegmentHelper);
if (entry == null) {
return;
}
val value = serializer.deserialize(getByteBuffer(entry.getValue()));
output("For the given key: %s", key);
if (getArgCount() == 4) {
final String jsonFile = getArg(3);
ControllerMetadataJsonSerializer jsonSerializer = new ControllerMetadataJsonSerializer();
@Cleanup FileWriter writer = new FileWriter(createFileAndDirectory(jsonFile));
writer.write(jsonSerializer.toJson(value));
writer.flush();
output("Successfully wrote the value to %s in JSON.", jsonFile);
} else {
userFriendlyOutput(value.toString(), serializer.getMetadataType());
}
}
use of io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer in project pravega by pravega.
the class ControllerMetadataUpdateEntryCommand method execute.
@Override
public void execute() throws Exception {
ensureArgCount(4);
final String tableName = getArg(0);
final String key = getArg(1);
final String newValueFile = getArg(3);
final String segmentStoreHost = getArg(2);
@Cleanup CuratorFramework zkClient = createZKClient();
@Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
ControllerMetadataSerializer serializer = new ControllerMetadataSerializer(tableName, key);
ControllerMetadataJsonSerializer jsonSerializer = new ControllerMetadataJsonSerializer();
String jsonValue;
try {
jsonValue = new String(Files.readAllBytes(Paths.get(newValueFile)));
} catch (NoSuchFileException e) {
output("File with new value does not exist: %s", newValueFile);
return;
}
ByteBuffer updatedValue = serializer.serialize(jsonSerializer.fromJson(jsonValue, serializer.getMetadataClass()));
TableSegmentEntry currentEntry = getTableEntry(tableName, key, segmentStoreHost, adminSegmentHelper);
if (currentEntry == null) {
return;
}
long currentVersion = currentEntry.getKey().getVersion().getSegmentVersion();
TableSegmentKeyVersion newVersion = updateTableEntry(tableName, key, updatedValue, currentVersion, segmentStoreHost, adminSegmentHelper);
if (newVersion == null) {
return;
}
output("Successfully updated the key %s in table %s with version %s", key, tableName, newVersion.getSegmentVersion());
}
Aggregations