Search in sources :

Example 1 with ControllerMetadataJsonSerializer

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());
    }
}
Also used : lombok.val(lombok.val) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) CuratorFramework(org.apache.curator.framework.CuratorFramework) ControllerMetadataSerializer(io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer) FileWriter(java.io.FileWriter) ControllerMetadataJsonSerializer(io.pravega.cli.admin.json.ControllerMetadataJsonSerializer) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 2 with ControllerMetadataJsonSerializer

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());
}
Also used : TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) CuratorFramework(org.apache.curator.framework.CuratorFramework) ControllerMetadataSerializer(io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer) NoSuchFileException(java.nio.file.NoSuchFileException) TableSegmentKeyVersion(io.pravega.client.tables.impl.TableSegmentKeyVersion) ControllerMetadataJsonSerializer(io.pravega.cli.admin.json.ControllerMetadataJsonSerializer) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ControllerMetadataJsonSerializer (io.pravega.cli.admin.json.ControllerMetadataJsonSerializer)2 ControllerMetadataSerializer (io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer)2 AdminSegmentHelper (io.pravega.cli.admin.utils.AdminSegmentHelper)2 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)2 Cleanup (lombok.Cleanup)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)1 FileWriter (java.io.FileWriter)1 ByteBuffer (java.nio.ByteBuffer)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 lombok.val (lombok.val)1