Search in sources :

Example 16 with CommandArgs

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

the class ControllerCommandsTest method executeCommand.

static String executeCommand(String inputCommand, AdminCommandState state) throws Exception {
    Parser.Command pc = Parser.parse(inputCommand);
    Assert.assertNotNull(pc.toString());
    CommandArgs args = new CommandArgs(pc.getArgs(), state);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    TestingDescribeStreamCommand cmd = new TestingDescribeStreamCommand(args);
    try (PrintStream ps = new PrintStream(baos, true, StandardCharsets.UTF_8)) {
        cmd.setOut(ps);
        cmd.execute();
    }
    return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Parser(io.pravega.cli.admin.Parser)

Example 17 with CommandArgs

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

the class ControllerCommandsTest method testDescribeStreamCommand.

@Test
@SneakyThrows
public void testDescribeStreamCommand() {
    String scope = "testScope";
    String testStream = "testStream";
    String commandResult = executeCommand("controller describe-stream " + scope + " " + testStream, cliConfig());
    Assert.assertTrue(commandResult.contains("stream_config"));
    Assert.assertTrue(commandResult.contains("stream_state"));
    Assert.assertTrue(commandResult.contains("segment_count"));
    Assert.assertTrue(commandResult.contains("is_sealed"));
    Assert.assertTrue(commandResult.contains("active_epoch"));
    Assert.assertTrue(commandResult.contains("truncation_record"));
    Assert.assertTrue(commandResult.contains("scaling_info"));
    // Exercise actual instantiateSegmentHelper
    CommandArgs commandArgs = new CommandArgs(Arrays.asList(scope, testStream), cliConfig());
    ControllerDescribeStreamCommand command = new ControllerDescribeStreamCommand(commandArgs);
    @Cleanup CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(CLUSTER.zookeeperConnectString(), new RetryOneTime(5000));
    curatorFramework.start();
    @Cleanup ConnectionPool pool = new ConnectionPoolImpl(CLIENT_CONFIG, new SocketConnectionFactoryImpl(CLIENT_CONFIG));
    @Cleanup SegmentHelper sh = command.instantiateSegmentHelper(curatorFramework, pool);
    Assert.assertNotNull(sh);
    // Try the Zookeeper backend, which is expected to fail and be handled by the command.
    Properties properties = new Properties();
    properties.setProperty("cli.store.metadata.backend", CLIConfig.MetadataBackends.ZOOKEEPER.name());
    cliConfig().getConfigBuilder().include(properties);
    commandArgs = new CommandArgs(Arrays.asList(scope, testStream), cliConfig());
    new ControllerDescribeStreamCommand(commandArgs).execute();
    properties.setProperty("cli.store.metadata.backend", CLIConfig.MetadataBackends.SEGMENTSTORE.name());
    cliConfig().getConfigBuilder().include(properties);
}
Also used : CommandArgs(io.pravega.cli.admin.CommandArgs) ConnectionPool(io.pravega.client.connection.impl.ConnectionPool) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) ConnectionPoolImpl(io.pravega.client.connection.impl.ConnectionPoolImpl) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) SegmentHelper(io.pravega.controller.server.SegmentHelper) Properties(java.util.Properties) Cleanup(lombok.Cleanup) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Example 18 with CommandArgs

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

the class SecureControllerCommandsTest method testAuthConfig.

@Test
@SneakyThrows
public void testAuthConfig() {
    String scope = "testScope";
    Properties pravegaProperties = new Properties();
    pravegaProperties.setProperty("cli.security.auth.enable", "true");
    pravegaProperties.setProperty("cli.security.auth.credentials.username", "admin");
    pravegaProperties.setProperty("cli.security.auth.credentials.password", "1111_aaaa");
    cliConfig().getConfigBuilder().include(pravegaProperties);
    String commandResult = TestUtils.executeCommand("controller list-scopes", cliConfig());
    // Check that both the new scope and the system one exist.
    Assert.assertTrue(commandResult.contains("_system"));
    Assert.assertTrue(commandResult.contains(scope));
    Assert.assertNotNull(ControllerListScopesCommand.descriptor());
    // Restore config
    pravegaProperties.setProperty("cli.security.auth.enable", "false");
    cliConfig().getConfigBuilder().include(pravegaProperties);
    // Exercise response codes for REST requests.
    @Cleanup val c1 = new AdminCommandState();
    CommandArgs commandArgs = new CommandArgs(Collections.emptyList(), c1);
    ControllerListScopesCommand command = new ControllerListScopesCommand(commandArgs);
    command.printResponseInfo(Response.status(Response.Status.UNAUTHORIZED).build());
    command.printResponseInfo(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build());
}
Also used : lombok.val(lombok.val) CommandArgs(io.pravega.cli.admin.CommandArgs) Properties(java.util.Properties) Cleanup(lombok.Cleanup) AdminCommandState(io.pravega.cli.admin.AdminCommandState) Test(org.junit.Test) SneakyThrows(lombok.SneakyThrows)

Aggregations

CommandArgs (io.pravega.cli.admin.CommandArgs)18 Test (org.junit.Test)16 Properties (java.util.Properties)12 AdminCommandState (io.pravega.cli.admin.AdminCommandState)11 SegmentProperties (io.pravega.segmentstore.contracts.SegmentProperties)10 Cleanup (lombok.Cleanup)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 lombok.val (lombok.val)4 TestUtils (io.pravega.cli.admin.utils.TestUtils)3 AttributeUpdateCollection (io.pravega.segmentstore.contracts.AttributeUpdateCollection)3 DeleteSegmentOperation (io.pravega.segmentstore.server.logs.operations.DeleteSegmentOperation)3 BookKeeperLogFactory (io.pravega.segmentstore.storage.impl.bookkeeper.BookKeeperLogFactory)3 UUID (java.util.UUID)3 Parser (io.pravega.cli.admin.Parser)2 CompositeByteArraySegment (io.pravega.common.util.CompositeByteArraySegment)2 ImmutableDate (io.pravega.common.util.ImmutableDate)2 AttributeId (io.pravega.segmentstore.contracts.AttributeId)2 AttributeUpdate (io.pravega.segmentstore.contracts.AttributeUpdate)2 DataCorruptionException (io.pravega.segmentstore.server.DataCorruptionException)2