Search in sources :

Example 1 with ControllerMetadataSerializer

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("");
    });
}
Also used : ControllerMetadataSerializer(io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer) Cleanup(lombok.Cleanup) Collectors(java.util.stream.Collectors) ControllerMetadataSerializer.isStreamMetadataTableName(io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer.isStreamMetadataTableName) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) Map(java.util.Map) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Preconditions(com.google.common.base.Preconditions) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) CommandArgs(io.pravega.cli.admin.CommandArgs) TableSegmentEntry(io.pravega.client.tables.impl.TableSegmentEntry) CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) ControllerMetadataSerializer(io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer) List(java.util.List) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 2 with ControllerMetadataSerializer

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());
    }
}
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 3 with ControllerMetadataSerializer

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());
}
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

ControllerMetadataSerializer (io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer)3 AdminSegmentHelper (io.pravega.cli.admin.utils.AdminSegmentHelper)3 TableSegmentEntry (io.pravega.client.tables.impl.TableSegmentEntry)3 Cleanup (lombok.Cleanup)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 ControllerMetadataJsonSerializer (io.pravega.cli.admin.json.ControllerMetadataJsonSerializer)2 Preconditions (com.google.common.base.Preconditions)1 CommandArgs (io.pravega.cli.admin.CommandArgs)1 ControllerMetadataSerializer.isStreamMetadataTableName (io.pravega.cli.admin.serializers.controller.ControllerMetadataSerializer.isStreamMetadataTableName)1 HashTableIteratorItem (io.pravega.client.tables.impl.HashTableIteratorItem)1 TableSegmentKeyVersion (io.pravega.client.tables.impl.TableSegmentKeyVersion)1 PravegaNodeUri (io.pravega.shared.protocol.netty.PravegaNodeUri)1 FileWriter (java.io.FileWriter)1 ByteBuffer (java.nio.ByteBuffer)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 lombok.val (lombok.val)1