Search in sources :

Example 91 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class SpawnerNoBootstrapTests method testNoControllerSpawn.

/**
     * Simplest case: a plugin with no controller daemon.
     */
public void testNoControllerSpawn() throws IOException, InterruptedException {
    Path esHome = createTempDir().resolve("esHome");
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(Environment.PATH_HOME_SETTING.getKey(), esHome.toString());
    Settings settings = settingsBuilder.build();
    Environment environment = new Environment(settings);
    // This plugin will NOT have a controller daemon
    Path plugin = environment.pluginsFile().resolve("a_plugin");
    Files.createDirectories(plugin);
    try (Spawner spawner = new Spawner()) {
        spawner.spawnNativePluginControllers(environment);
        assertTrue(spawner.getProcesses().isEmpty());
    }
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 92 with Environment

use of org.elasticsearch.env.Environment 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)

Example 93 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class InstallPluginCommandTests method testBin.

public void testBin() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path binDir = pluginDir.resolve("bin");
    Files.createDirectory(binDir);
    Files.createFile(binDir.resolve("somescript"));
    String pluginZip = createPlugin("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 94 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class ListPluginsCommandTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    home = createTempDir();
    Files.createDirectories(home.resolve("plugins"));
    Settings settings = Settings.builder().put("path.home", home).build();
    env = new Environment(settings);
}
Also used : Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 95 with Environment

use of org.elasticsearch.env.Environment in project elasticsearch by elastic.

the class EvilLoggerConfigurationTests method testResolveMultipleConfigs.

public void testResolveMultipleConfigs() throws Exception {
    final Level level = ESLoggerFactory.getLogger("test").getLevel();
    try {
        final Path configDir = getDataPath("config");
        final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
        final Environment environment = new Environment(settings);
        LogConfigurator.configure(environment);
        {
            final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            final Configuration config = ctx.getConfiguration();
            final LoggerConfig loggerConfig = config.getLoggerConfig("test");
            final Appender appender = loggerConfig.getAppenders().get("console");
            assertThat(appender, notNullValue());
        }
        {
            final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            final Configuration config = ctx.getConfiguration();
            final LoggerConfig loggerConfig = config.getLoggerConfig("second");
            final Appender appender = loggerConfig.getAppenders().get("console2");
            assertThat(appender, notNullValue());
        }
        {
            final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
            final Configuration config = ctx.getConfiguration();
            final LoggerConfig loggerConfig = config.getLoggerConfig("third");
            final Appender appender = loggerConfig.getAppenders().get("console3");
            assertThat(appender, notNullValue());
        }
    } finally {
        Configurator.setLevel("test", level);
    }
}
Also used : Path(java.nio.file.Path) Appender(org.apache.logging.log4j.core.Appender) Configuration(org.apache.logging.log4j.core.config.Configuration) Environment(org.elasticsearch.env.Environment) Level(org.apache.logging.log4j.Level) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Settings(org.elasticsearch.common.settings.Settings) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

Environment (org.elasticsearch.env.Environment)130 Settings (org.elasticsearch.common.settings.Settings)84 Path (java.nio.file.Path)66 Matchers.containsString (org.hamcrest.Matchers.containsString)42 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)26 TestEnvironment (org.elasticsearch.env.TestEnvironment)22 IndexSettings (org.elasticsearch.index.IndexSettings)21 UserException (org.elasticsearch.cli.UserException)17 IOException (java.io.IOException)15 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)9 MockTerminal (org.elasticsearch.cli.MockTerminal)8 ClusterState (org.elasticsearch.cluster.ClusterState)8 ScriptService (org.elasticsearch.script.ScriptService)8 HashMap (java.util.HashMap)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 ArrayList (java.util.ArrayList)6 ElasticsearchException (org.elasticsearch.ElasticsearchException)6 Before (org.junit.Before)6