Search in sources :

Example 11 with Terminal

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

the class ValidateInputTask method accept.

@Override
public void accept(final Tuple<TaskInput, Terminal> input) {
    final TaskInput taskInput = input.v1();
    final Terminal terminal = input.v2();
    terminal.println("Verifying the details ...");
    // check if the elasticsearch version is supported
    if (taskInput.getVersion().isPresent()) {
        final Version version = taskInput.getVersion().get();
        if (version.equals(LegacyESVersion.V_7_10_2) == false) {
            throw new RuntimeException(String.format(Locale.getDefault(), "The installed version %s of elasticsearch is not supported.", version));
        }
    } else {
        terminal.println("Unable to detect installed elasticsearch version.");
        confirmToProceed(terminal);
    }
    // check if the OpenSearch config is set to an external location
    if (taskInput.getOpenSearchConfig().getParent().equals(taskInput.getOpenSearchBin().getParent())) {
        terminal.println("OpenSearch config directory is set inside the installation directory. " + "It is recommended to use an external config directory and set the environment variable " + "OPENSEARCH_PATH_CONF to it.");
        confirmToProceed(terminal);
    }
    // print summary and confirm with user if everything looks correct.
    final Map<String, String> fieldsMap = getSummaryFieldsMap(taskInput);
    final String format = " %-25s | %s";
    terminal.println("+----------------------- SUMMARY -----------------------+");
    for (Map.Entry<String, String> entry : fieldsMap.entrySet()) {
        terminal.println(String.format(Locale.getDefault(), format, entry.getKey(), entry.getValue()));
    }
    terminal.println("+-------------------------------------------------------+");
    terminal.println("Please verify if everything above looks good.");
    confirmToProceed(terminal);
}
Also used : LegacyESVersion(org.opensearch.LegacyESVersion) Version(org.opensearch.Version) Terminal(org.opensearch.cli.Terminal) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Terminal (org.opensearch.cli.Terminal)11 Path (java.nio.file.Path)6 IOException (java.io.IOException)5 Tuple (org.opensearch.common.collect.Tuple)3 Settings (org.opensearch.common.settings.Settings)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Version (org.opensearch.Version)2 MockTerminal (org.opensearch.cli.MockTerminal)2 UserException (org.opensearch.cli.UserException)2 SuppressForbidden (org.opensearch.common.SuppressForbidden)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 EnumSet (java.util.EnumSet)1 LinkedHashMap (java.util.LinkedHashMap)1