Search in sources :

Example 11 with AdminSegmentHelper

use of io.pravega.cli.admin.utils.AdminSegmentHelper 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 12 with AdminSegmentHelper

use of io.pravega.cli.admin.utils.AdminSegmentHelper 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

AdminSegmentHelper (io.pravega.cli.admin.utils.AdminSegmentHelper)12 Cleanup (lombok.Cleanup)11 CuratorFramework (org.apache.curator.framework.CuratorFramework)11 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)5 CommandArgs (io.pravega.cli.admin.CommandArgs)3 ControllerMetadataSerializer (io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer)3 HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)3 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ControllerMetadataJsonSerializer (io.pravega.cli.admin.json.ControllerMetadataJsonSerializer)2 TableSegmentKey (io.pravega.client.tables.impl.TableSegmentKey)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 ControllerMetadataSerializer.isStreamMetadataTableName (io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer.isStreamMetadataTableName)1 ConnectionPool (io.pravega.client.connection.impl.ConnectionPool)1 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)1 HostControllerStore (io.pravega.controller.store.host.HostControllerStore)1 WireCommands (io.pravega.shared.protocol.netty.WireCommands)1 FileWriter (java.io.FileWriter)1