use of io.pravega.cli.admin.json.ControllerMetadataJsonSerializer 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.json.ControllerMetadataJsonSerializer 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