Search in sources :

Example 16 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class UpgradeCli method execute.

/**
 * Executes the upgrade task. This retrieves an instance of {@link UpgradeTask} which is composed
 * of smaller individual tasks that perform specific operations as part of the overall process.
 *
 * @param terminal current terminal the command is running
 * @param options  options supplied to the command
 * @param env      current environment in which this cli tool is running.
 * @throws UserException if any exception is thrown from the tasks
 */
@Override
protected void execute(final Terminal terminal, final OptionSet options, final Environment env) throws UserException {
    try {
        final Tuple<TaskInput, Terminal> input = new Tuple<>(new TaskInput(env), terminal);
        UpgradeTask.getTask().accept(input);
        terminal.println("Done!");
        terminal.println("Next Steps: ");
        terminal.println(" Stop the running elasticsearch on this node.");
        terminal.println(" Start OpenSearch on this node.");
    } catch (RuntimeException ex) {
        throw new UserException(ExitCodes.DATA_ERROR, ex.getMessage());
    }
}
Also used : UserException(org.opensearch.cli.UserException) Terminal(org.opensearch.cli.Terminal) Tuple(org.opensearch.common.collect.Tuple)

Example 17 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class RemovePluginCommandTests method testBinNotDir.

public void testBinNotDir() throws Exception {
    createPlugin("fake");
    Files.createFile(env.binDir().resolve("fake"));
    UserException e = expectThrows(UserException.class, () -> removePlugin("fake", home, randomBoolean()));
    assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
    // did not remove
    assertTrue(Files.exists(env.pluginsDir().resolve("fake")));
    assertTrue(Files.exists(env.binDir().resolve("fake")));
    assertRemoveCleaned(env);
}
Also used : UserException(org.opensearch.cli.UserException)

Example 18 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class RemovePluginCommandTests method testPurgeNothingExists.

public void testPurgeNothingExists() throws Exception {
    final UserException e = expectThrows(UserException.class, () -> removePlugin("fake", home, true));
    assertThat(e, hasToString(containsString("plugin [fake] not found")));
}
Also used : UserException(org.opensearch.cli.UserException)

Example 19 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class AddStringKeyStoreCommandTests method testMissingSettingName.

public void testMissingSettingName() throws Exception {
    String password = "keystorepassword";
    createKeystore(password);
    terminal.addSecretInput(password);
    terminal.addSecretInput(password);
    terminal.addTextInput("");
    UserException e = expectThrows(UserException.class, this::execute);
    assertEquals(ExitCodes.USAGE, e.exitCode);
    assertThat(e.getMessage(), containsString("the setting names can not be empty"));
}
Also used : Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 20 with UserException

use of org.opensearch.cli.UserException in project OpenSearch by opensearch-project.

the class ChangeKeyStorePasswordCommandTests method testChangeKeyStorePasswordWrongExistingPassword.

public void testChangeKeyStorePasswordWrongExistingPassword() throws Exception {
    createKeystore("theoldpassword");
    loadKeystore("theoldpassword");
    terminal.addSecretInput("theoldmisspelledpassword");
    // We'll only be prompted once (for the old password)
    UserException e = expectThrows(UserException.class, this::execute);
    assertEquals(e.getMessage(), ExitCodes.DATA_ERROR, e.exitCode);
    if (inFipsJvm()) {
        assertThat(e.getMessage(), anyOf(containsString("Provided keystore password was incorrect"), containsString("Keystore has been corrupted or tampered with")));
    } else {
        assertThat(e.getMessage(), containsString("Provided keystore password was incorrect"));
    }
}
Also used : UserException(org.opensearch.cli.UserException)

Aggregations

UserException (org.opensearch.cli.UserException)76 Path (java.nio.file.Path)44 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Environment (org.opensearch.env.Environment)29 Matchers.hasToString (org.hamcrest.Matchers.hasToString)25 TestEnvironment (org.opensearch.env.TestEnvironment)25 IOException (java.io.IOException)16 Settings (org.opensearch.common.settings.Settings)16 ArrayList (java.util.ArrayList)12 BufferedReader (java.io.BufferedReader)11 Files (java.nio.file.Files)11 MockTerminal (org.opensearch.cli.MockTerminal)11 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)11 InputStream (java.io.InputStream)10 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 Terminal (org.opensearch.cli.Terminal)10 Tuple (org.opensearch.common.collect.Tuple)10 StringReader (java.io.StringReader)9 URL (java.net.URL)9