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