Search in sources :

Example 1 with Terminal

use of org.elasticsearch.cli.Terminal in project elasticsearch by elastic.

the class Bootstrap method createEnvironment.

private static Environment createEnvironment(boolean foreground, Path pidFile, SecureSettings secureSettings, Settings initialSettings) {
    Terminal terminal = foreground ? Terminal.DEFAULT : null;
    Settings.Builder builder = Settings.builder();
    if (pidFile != null) {
        builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile);
    }
    builder.put(initialSettings);
    if (secureSettings != null) {
        builder.setSecureSettings(secureSettings);
    }
    return InternalSettingsPreparer.prepareEnvironment(builder.build(), terminal, Collections.emptyMap());
}
Also used : Terminal(org.elasticsearch.cli.Terminal) Settings(org.elasticsearch.common.settings.Settings) SecureSettings(org.elasticsearch.common.settings.SecureSettings)

Example 2 with Terminal

use of org.elasticsearch.cli.Terminal in project elasticsearch by elastic.

the class ESElasticsearchCliTestCase method runTest.

void runTest(final int expectedStatus, final boolean expectedInit, final Consumer<String> outputConsumer, final InitConsumer initConsumer, String... args) throws Exception {
    final MockTerminal terminal = new MockTerminal();
    Path home = createTempDir();
    try {
        final AtomicBoolean init = new AtomicBoolean();
        final int status = Elasticsearch.main(args, new Elasticsearch() {

            @Override
            protected Environment createEnv(Terminal terminal, Map<String, String> settings) {
                Settings realSettings = Settings.builder().put("path.home", home).put(settings).build();
                return new Environment(realSettings);
            }

            @Override
            void init(final boolean daemonize, final Path pidFile, final boolean quiet, Environment initialEnv) {
                init.set(true);
                initConsumer.accept(!daemonize, pidFile, quiet, initialEnv);
            }

            @Override
            protected boolean addShutdownHook() {
                return false;
            }
        }, terminal);
        assertThat(status, equalTo(expectedStatus));
        assertThat(init.get(), equalTo(expectedInit));
        outputConsumer.accept(terminal.getOutput());
    } catch (Exception e) {
        // if an unexpected exception is thrown, we log
        // terminal output to aid debugging
        logger.info(terminal.getOutput());
        // rethrow so the test fails
        throw e;
    }
}
Also used : Path(java.nio.file.Path) MockTerminal(org.elasticsearch.cli.MockTerminal) MockTerminal(org.elasticsearch.cli.MockTerminal) Terminal(org.elasticsearch.cli.Terminal) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

Terminal (org.elasticsearch.cli.Terminal)2 Settings (org.elasticsearch.common.settings.Settings)2 Path (java.nio.file.Path)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 MockTerminal (org.elasticsearch.cli.MockTerminal)1 SecureSettings (org.elasticsearch.common.settings.SecureSettings)1 Environment (org.elasticsearch.env.Environment)1