Search in sources :

Example 6 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)

Example 7 with AdminSegmentHelper

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

the class ModifyTableSegmentEntry method execute.

@Override
public void execute() {
    ensureArgCount(4);
    ensureSerializersExist();
    final String fullyQualifiedTableSegmentName = getArg(0);
    final String segmentStoreHost = getArg(1);
    final String key = getArg(2);
    Map<String, String> newFieldMap = parseStringData(getArg(3));
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    String currentValue = getTableEntry(fullyQualifiedTableSegmentName, key, segmentStoreHost, adminSegmentHelper);
    List<String> changedFields = new ArrayList<>();
    Map<String, String> currentValueFieldMap = parseStringData(currentValue);
    // Make changes to the fields in the entry that exists currently.
    // If the field name does not exist then the user is notified of the same.
    newFieldMap.forEach((f, v) -> {
        if (currentValueFieldMap.containsKey(f)) {
            currentValueFieldMap.put(f, v);
            changedFields.add(f);
        } else {
            output("%s field does not exist.", f);
        }
    });
    // If no change is made to fields of the current entry then return.
    if (changedFields.isEmpty()) {
        output("No fields provided to modify.");
        return;
    }
    StringBuilder updatedValueBuilder = new StringBuilder();
    currentValueFieldMap.forEach((f, v) -> appendField(updatedValueBuilder, f, v));
    String updatedValue = updatedValueBuilder.toString();
    long version = updateTableEntry(fullyQualifiedTableSegmentName, key, updatedValue, segmentStoreHost, adminSegmentHelper);
    output("Successfully modified the following fields in the value for key %s in table %s with version %s: %s", key, fullyQualifiedTableSegmentName, version, String.join(",", changedFields));
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ArrayList(java.util.ArrayList) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 8 with AdminSegmentHelper

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

the class FlushToStorageCommand method execute.

@Override
public void execute() throws Exception {
    ensureArgCount(2);
    final String containerId = getArg(0);
    final String segmentStoreHost = getArg(1);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    if (containerId.equalsIgnoreCase(ALL_CONTAINERS)) {
        int containerCount = getServiceConfig().getContainerCount();
        for (int id = 0; id < containerCount; id++) {
            flushContainerToStorage(adminSegmentHelper, id, segmentStoreHost);
        }
    } else {
        flushContainerToStorage(adminSegmentHelper, parseInt(containerId), segmentStoreHost);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 9 with AdminSegmentHelper

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

the class ListChunksCommand method execute.

@Override
public void execute() {
    ensureArgCount(2);
    final String fullyQualifiedSegmentName = getArg(0);
    final String segmentStoreHost = getArg(1);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    CompletableFuture<WireCommands.StorageChunksListed> reply = adminSegmentHelper.listStorageChunks(fullyQualifiedSegmentName, new PravegaNodeUri(segmentStoreHost, getServiceConfig().getAdminGatewayPort()), super.authHelper.retrieveMasterToken());
    List<WireCommands.ChunkInfo> chunks = reply.join().getChunks();
    output("List of chunks for %s: ", fullyQualifiedSegmentName);
    chunks.forEach(chunk -> {
        output("- Chunk name = %s", chunk.getChunkName());
        CHUNK_INFO_FIELD_MAP.forEach((name, f) -> output("  %s = %s", name, f.apply(chunk)));
        output("");
    });
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) PravegaNodeUri(io.pravega.shared.protocol.netty.PravegaNodeUri) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) Cleanup(lombok.Cleanup)

Example 10 with AdminSegmentHelper

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

the class GetTableSegmentEntryCommand method execute.

@Override
public void execute() {
    ensureArgCount(3);
    ensureSerializersExist();
    final String fullyQualifiedTableSegmentName = getArg(0);
    final String key = getArg(1);
    final String segmentStoreHost = getArg(2);
    @Cleanup CuratorFramework zkClient = createZKClient();
    @Cleanup AdminSegmentHelper adminSegmentHelper = instantiateAdminSegmentHelper(zkClient);
    String value = getTableEntry(fullyQualifiedTableSegmentName, key, segmentStoreHost, adminSegmentHelper);
    output("For the given key: %s", key);
    userFriendlyOutput(value);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) AdminSegmentHelper(io.pravega.cli.admin.utils.AdminSegmentHelper) 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