Search in sources :

Example 6 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class DataRecoveryTest method testRepairLogEditOperationCreateAttributeUpdateCollection.

@Test
public void testRepairLogEditOperationCreateAttributeUpdateCollection() throws IOException {
    // Setup command object.
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega0");
    STATE.get().getConfigBuilder().include(pravegaProperties);
    CommandArgs args = new CommandArgs(List.of("0"), STATE.get());
    DurableDataLogRepairCommand command = Mockito.spy(new DurableDataLogRepairCommand(args));
    // Create an AttributeUpdateCollection via the command logic and check the expected output.
    AttributeUpdateCollection attributeUpdates = new AttributeUpdateCollection();
    UUID uuid = UUID.randomUUID();
    attributeUpdates.add(new AttributeUpdate(AttributeId.fromUUID(uuid), AttributeUpdateType.Replace, 1, 2));
    Mockito.doReturn(true).doReturn(false).when(command).confirmContinue();
    Mockito.doReturn(uuid.toString()).when(command).getStringUserInput(Mockito.any());
    Mockito.doReturn(1L).doReturn(2L).doReturn(1L).when(command).getLongUserInput(Mockito.any());
    Mockito.doReturn((int) AttributeUpdateType.Replace.getTypeId()).when(command).getIntUserInput(Mockito.any());
    Assert.assertArrayEquals(attributeUpdates.getUUIDAttributeUpdates().toArray(), command.createAttributeUpdateCollection().getUUIDAttributeUpdates().toArray());
    // Induce exceptions during the process to check error handling.
    Mockito.doReturn(true).doReturn(true).doReturn(false).when(command).confirmContinue();
    Mockito.doThrow(NumberFormatException.class).doThrow(NullPointerException.class).when(command).getStringUserInput(Mockito.any());
    Assert.assertArrayEquals(new Object[0], command.createAttributeUpdateCollection().getUUIDAttributeUpdates().toArray());
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) AttributeUpdateCollection(io.pravega.segmentstore.contracts.AttributeUpdateCollection) AttributeUpdate(io.pravega.segmentstore.contracts.AttributeUpdate) SegmentProperties(io.pravega.segmentstore.contracts.SegmentProperties) Properties(java.util.Properties) UUID(java.util.UUID) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test)

Example 7 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class ParseReaderGroupStreamCommandTest method setup.

public void setup(boolean enableAuth, boolean enableTls) throws Exception {
    ClientConfig.ClientConfigBuilder clientConfigBuilder = ClientConfig.builder().controllerURI(SETUP_UTILS.getControllerUri());
    STATE.set(new AdminCommandState());
    SETUP_UTILS.startAllServices(enableAuth, enableTls);
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("cli.controller.grpc.uri", SETUP_UTILS.getControllerUri().toString());
    pravegaProperties.setProperty("cli.controller.connect.grpc.uri", SETUP_UTILS.getControllerUri().getHost() + ":" + SETUP_UTILS.getControllerUri().getPort());
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", SETUP_UTILS.getZkTestServer().getConnectString());
    pravegaProperties.setProperty("pravegaservice.container.count", String.valueOf(CONTAINER_COUNT));
    pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(SETUP_UTILS.getAdminPort()));
    if (enableAuth) {
        clientConfigBuilder = clientConfigBuilder.credentials(new DefaultCredentials(SecurityConfigDefaults.AUTH_ADMIN_PASSWORD, SecurityConfigDefaults.AUTH_ADMIN_USERNAME));
        pravegaProperties.setProperty("cli.channel.auth", Boolean.toString(true));
        pravegaProperties.setProperty("cli.credentials.username", SecurityConfigDefaults.AUTH_ADMIN_USERNAME);
        pravegaProperties.setProperty("cli.credentials.pwd", SecurityConfigDefaults.AUTH_ADMIN_PASSWORD);
    }
    if (enableTls) {
        clientConfigBuilder = clientConfigBuilder.trustStore(pathToConfig() + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME).validateHostName(false);
        pravegaProperties.setProperty("cli.channel.tls", Boolean.toString(true));
        pravegaProperties.setProperty("cli.trustStore.location", "../../config/" + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME);
        pravegaProperties.setProperty("cli.trustStore.access.token.ttl.seconds", Integer.toString(300));
    }
    STATE.get().getConfigBuilder().include(pravegaProperties);
    clientConfig = clientConfigBuilder.build();
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClientConfig(io.pravega.client.ClientConfig) Properties(java.util.Properties) AdminCommandState(io.pravega.cli.admin.AdminCommandState)

Example 8 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class StorageCommandsTest method testListChunksCommand.

@Test
public void testListChunksCommand() throws Exception {
    int instanceId = 0;
    int bookieCount = 3;
    int containerCount = 1;
    @Cleanup TestUtils.PravegaRunner pravegaRunner = new TestUtils.PravegaRunner(bookieCount, containerCount);
    pravegaRunner.startBookKeeperRunner(instanceId++);
    this.factory = new BookKeeperLogFactory(pravegaRunner.getBookKeeperRunner().getBkConfig().get(), pravegaRunner.getBookKeeperRunner().getZkClient().get(), executorService());
    pravegaRunner.startControllerAndSegmentStore(this.storageFactory, this.factory, true);
    String streamName = "testListChunksCommand";
    TestUtils.createScopeStream(pravegaRunner.getControllerRunner().getController(), SCOPE, streamName, config);
    try (val clientRunner = new TestUtils.ClientRunner(pravegaRunner.getControllerRunner(), SCOPE)) {
        // Write events to the streams.
        TestUtils.writeEvents(streamName, clientRunner.getClientFactory());
    }
    ServiceBuilder.ComponentSetup componentSetup = new ServiceBuilder.ComponentSetup(pravegaRunner.getSegmentStoreRunner().getServiceBuilder());
    for (int containerId = 0; containerId < containerCount; containerId++) {
        componentSetup.getContainerRegistry().getContainer(containerId).flushToStorage(TIMEOUT).join();
    }
    STATE.set(new AdminCommandState());
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(pravegaRunner.getSegmentStoreRunner().getAdminPort()));
    pravegaProperties.setProperty("pravegaservice.container.count", "1");
    pravegaProperties.setProperty("pravegaservice.storage.impl.name", "FILESYSTEM");
    pravegaProperties.setProperty("pravegaservice.storage.layout", "CHUNKED_STORAGE");
    pravegaProperties.setProperty("filesystem.root", this.baseDir.getAbsolutePath());
    STATE.get().getConfigBuilder().include(pravegaProperties);
    String commandResult = TestUtils.executeCommand("storage list-chunks _system/containers/metadata_0 localhost", STATE.get());
    Assert.assertTrue(commandResult.contains("List of chunks for _system/containers/metadata_0"));
}
Also used : lombok.val(lombok.val) Properties(java.util.Properties) Cleanup(lombok.Cleanup) ServiceBuilder(io.pravega.segmentstore.server.store.ServiceBuilder) TestUtils(io.pravega.cli.admin.utils.TestUtils) AdminCommandState(io.pravega.cli.admin.AdminCommandState) BookKeeperLogFactory(io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory) Test(org.junit.Test)

Example 9 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class AbstractControllerMetadataCommandsTest method setup.

public void setup(boolean enableAuth, boolean enableTls) throws Exception {
    ClientConfig.ClientConfigBuilder clientConfigBuilder = ClientConfig.builder().controllerURI(SETUP_UTILS.getControllerUri());
    STATE.set(new AdminCommandState());
    SETUP_UTILS.startAllServices(enableAuth, enableTls);
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("cli.controller.rest.uri", SETUP_UTILS.getControllerRestUri().toString());
    pravegaProperties.setProperty("cli.controller.grpc.uri", SETUP_UTILS.getControllerUri().toString());
    pravegaProperties.setProperty("pravegaservice.zk.connect.uri", SETUP_UTILS.getZkTestServer().getConnectString());
    pravegaProperties.setProperty("pravegaservice.container.count", String.valueOf(1));
    pravegaProperties.setProperty("pravegaservice.admin.gateway.port", String.valueOf(SETUP_UTILS.getAdminPort()));
    pravegaProperties.setProperty("pravegaservice.clusterName", "pravega-cluster");
    if (enableAuth) {
        clientConfigBuilder = clientConfigBuilder.credentials(new DefaultCredentials(SecurityConfigDefaults.AUTH_ADMIN_PASSWORD, SecurityConfigDefaults.AUTH_ADMIN_USERNAME));
        pravegaProperties.setProperty("cli.channel.auth", Boolean.toString(true));
        pravegaProperties.setProperty("cli.credentials.username", SecurityConfigDefaults.AUTH_ADMIN_USERNAME);
        pravegaProperties.setProperty("cli.credentials.pwd", SecurityConfigDefaults.AUTH_ADMIN_PASSWORD);
    }
    if (enableTls) {
        clientConfigBuilder = clientConfigBuilder.trustStore(pathToConfig() + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME).validateHostName(false);
        pravegaProperties.setProperty("cli.channel.tls", Boolean.toString(true));
        pravegaProperties.setProperty("cli.trustStore.location", "../../config/" + SecurityConfigDefaults.TLS_CA_CERT_FILE_NAME);
        pravegaProperties.setProperty("cli.trustStore.access.token.ttl.seconds", Integer.toString(300));
    }
    STATE.get().getConfigBuilder().include(pravegaProperties);
    clientConfig = clientConfigBuilder.build();
}
Also used : DefaultCredentials(io.pravega.shared.security.auth.DefaultCredentials) ClientConfig(io.pravega.client.ClientConfig) Properties(java.util.Properties) AdminCommandState(io.pravega.cli.admin.AdminCommandState)

Example 10 with AdminCommandState

use of io.pravega.cli.admin.AdminCommandState in project pravega by pravega.

the class ConfigCommandsTest method testSetAndListConfigCommands.

@Test
public void testSetAndListConfigCommands() throws Exception {
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("cli.controller.rest.uri", "test");
    @Cleanup AdminCommandState adminCommandState = new AdminCommandState();
    adminCommandState.getConfigBuilder().include(pravegaProperties);
    String commandResult = TestUtils.executeCommand("config list", adminCommandState);
    Assert.assertTrue(commandResult.contains("cli.controller.rest.uri"));
    TestUtils.executeCommand("config set hello=world", adminCommandState);
    commandResult = TestUtils.executeCommand("config list", adminCommandState);
    Assert.assertTrue(commandResult.contains("hello=world"));
}
Also used : Properties(java.util.Properties) Cleanup(lombok.Cleanup) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test)

Aggregations

AdminCommandState (io.pravega.cli.admin.AdminCommandState)27 Properties (java.util.Properties)23 Test (org.junit.Test)22 Cleanup (lombok.Cleanup)14 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)13 CommandArgs (io.pravega.cli.admin.CommandArgs)11 lombok.val (lombok.val)9 TestUtils (io.pravega.cli.admin.utils.TestUtils)6 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)5 DeleteSegmentOperation (io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation)4 ClientConfig (io.pravega.client.ClientConfig)3 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)3 ServiceBuilder (io.pravega.segmentstore.server.store.ServiceBuilder)3 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 CompositeByteArraySegment (io.pravega.common.util.CompositeByteArraySegment)2 ImmutableDate (io.pravega.common.util.ImmutableDate)2 AttributeId (io.pravega.segmentstore.contracts.AttributeId)2