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