Search in sources :

Example 1 with AdminSegmentHelper

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

use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.

the class ControllerMetadataListKeysCommand method execute.

@Override
public void execute() {
    ensureArgCount(3);
    final String tableName = getArg(0);
    final int keyCount = getIntArg(1);
    final String segmentStoreHost = getArg(2);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    HashTableIteratorItem<TableSegmentKey> keys = completeSafely(adminSegmentHelper.readTableKeys(tableName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), keyCount, HashTableIteratorItem.State.EMPTY, super.authHelper.retrieveMasterToken(), 0L), tableName, null);
    if (keys == null) {
        return;
    }
    List<String> stringKeys = keys.getItems().stream().map(tableSegmentKey -> KEY_SERIALIZER.deserialize(getByteBuffer(tableSegmentKey.getKey()))).collect(Collectors.toList());
    output("List of at most %s keys in %s: ", keyCount, tableName);
    stringKeys.forEach(k -> output("- %s", k));
}
Also used : TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Cleanup(lombok.Cleanup) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) CommandArgs(io.pravega.cli.admin.CommandArgs) Collectors(java.util.stream.Collectors) CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 3 with AdminSegmentHelper

use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.

the class ListTableSegmentKeysCommand method execute.

@Override
public void execute() {
    ensureArgCount(3);
    ensureSerializersExist();
    final String fullyQualifiedTableSegmentName = getArg(0);
    final int keyCount = getIntArg(1);
    final String segmentStoreHost = getArg(2);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    CompletableFuture<HashTableIteratorItem<TableSegmentKey>> reply = adminSegmentHelper.readTableKeys(fullyQualifiedTableSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), keyCount, HashTableIteratorItem.State.EMPTY, super.authHelper.retrieveMasterToken(), 0L);
    List<String> keys = reply.join().getItems().stream().map(tableSegmentKey -> getCommandArgs().getState().getKeySerializer().deserialize(getByteBuffer(tableSegmentKey.getKey()))).collect(Collectors.toList());
    output("List of at most %s keys in %s: ", keyCount, fullyQualifiedTableSegmentName);
    keys.forEach(k -> output("- %s", k));
}
Also used : TableSegmentKey(io.pravega.client.tables.impl.TableSegmentKey) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) Cleanup(lombok.Cleanup) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem) CompletableFuture(java.util.concurrent.CompletableFuture) CommandArgs(io.pravega.cli.admin.CommandArgs) Collectors(java.util.stream.Collectors) CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup) HashTableIteratorItem(io.pravega.client.tables.impl.HashTableIteratorItem)

Example 4 with AdminSegmentHelper

use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.

the class PutTableSegmentEntryCommand method execute.

@Override
public void execute() {
    ensureArgCount(4);
    ensureSerializersExist();
    final String fullyQualifiedTableSegmentName = getArg(0);
    final String segmentStoreHost = getArg(1);
    final String key = getArg(2);
    final String value = getArg(3);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    long version = updateTableEntry(fullyQualifiedTableSegmentName, key, value, segmentStoreHost, adminSegmentHelper);
    output("Successfully updated the key %s in table %s with version %s", key, fullyQualifiedTableSegmentName, version);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 5 with AdminSegmentHelper

use of io.pravega.cli.admin.utils.AdminSegmentHelper in project pravega by pravega.

the class GetTableSegmentInfoCommand method execute.

@Override
public void execute() {
    ensureArgCount(2);
    final String fullyQualifiedTableSegmentName = getArg(0);
    final String segmentStoreHost = getArg(1);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    CompletableFuture<WireCommands.TableSegmentInfo> reply = adminSegmentHelper.getTableSegmentInfo(fullyQualifiedTableSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), super.authHelper.retrieveMasterToken());
    WireCommands.TableSegmentInfo tableSegmentInfo = reply.join();
    output("TableSegmentInfo for %s: ", fullyQualifiedTableSegmentName);
    SEGMENT_INFO_FIELD_MAP.forEach((name, f) -> output("%s = %s", name, f.apply(tableSegmentInfo)));
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) WireCommands(io.pravega.shared.protocol.netty.WireCommands) Cleanup(lombok.Cleanup)

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