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