Search in sources :

Example 96 with Environment

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

the class EvilLoggerConfigurationTests method testHierarchy.

public void testHierarchy() throws Exception {
    final Path configDir = getDataPath("hierarchy");
    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);
    assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(Level.TRACE));
    assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(Level.DEBUG));
    final Level level = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR);
    Loggers.setLevel(ESLoggerFactory.getLogger("x"), level);
    assertThat(ESLoggerFactory.getLogger("x").getLevel(), equalTo(level));
    assertThat(ESLoggerFactory.getLogger("x.y").getLevel(), equalTo(level));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Level(org.apache.logging.log4j.Level) Settings(org.elasticsearch.common.settings.Settings)

Example 97 with Environment

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

the class EvilLoggerConfigurationTests method testDefaults.

public void testDefaults() throws IOException, UserException {
    final Path configDir = getDataPath("config");
    final String level = randomFrom(Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR).toString();
    final Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put("logger.level", level).build();
    final Environment environment = new Environment(settings);
    LogConfigurator.configure(environment);
    final String loggerName = "test";
    final Logger logger = ESLoggerFactory.getLogger(loggerName);
    assertThat(logger.getLevel().toString(), equalTo(level));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Logger(org.apache.logging.log4j.Logger) Settings(org.elasticsearch.common.settings.Settings)

Example 98 with Environment

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

the class EvilLoggerConfigurationTests method testResolveOrder.

// tests that custom settings are not overwritten by settings in the config file
public void testResolveOrder() throws Exception {
    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()).put("logger.test_resolve_order", "TRACE").build();
    final Environment environment = new Environment(settings);
    LogConfigurator.configure(environment);
    // args should overwrite whatever is in the config
    final String loggerName = "test_resolve_order";
    final Logger logger = ESLoggerFactory.getLogger(loggerName);
    assertTrue(logger.isTraceEnabled());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Logger(org.apache.logging.log4j.Logger) Settings(org.elasticsearch.common.settings.Settings)

Example 99 with Environment

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

the class EvilLoggerConfigurationTests method testMissingConfigFile.

public void testMissingConfigFile() {
    final Path configDir = getDataPath("does_not_exist");
    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);
    UserException e = expectThrows(UserException.class, () -> LogConfigurator.configure(environment));
    assertThat(e, hasToString(containsString("no log4j2.properties found; tried")));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) UserException(org.elasticsearch.cli.UserException) Settings(org.elasticsearch.common.settings.Settings)

Example 100 with Environment

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

the class InstallPluginCommandTests method installPlugin.

private void installPlugin(MockTerminal terminal, boolean isBatch) throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    // if batch is enabled, we also want to add a security policy
    String pluginZip = createPlugin("fake", pluginDir, isBatch);
    new InstallPluginCommand() {

        @Override
        void jarHellCheck(Path candidate, Path pluginsDir) throws Exception {
        }
    }.execute(terminal, pluginZip, isBatch, env.v2());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) NoSuchFileException(java.nio.file.NoSuchFileException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) UserException(org.elasticsearch.cli.UserException)

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