Search in sources :

Example 21 with Environment

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

the class EvilLoggerTests method setupLogging.

private void setupLogging(final String config, final Settings settings) throws IOException, UserException {
    assert !Environment.PATH_CONF_SETTING.exists(settings);
    assert !Environment.PATH_HOME_SETTING.exists(settings);
    final Path configDir = getDataPath(config);
    // need to set custom path.conf so we can use a custom log4j2.properties file for the test
    final Settings mergedSettings = Settings.builder().put(settings).put(Environment.PATH_CONF_SETTING.getKey(), configDir.toAbsolutePath()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build();
    final Environment environment = new Environment(mergedSettings);
    LogConfigurator.configure(environment);
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Settings(org.elasticsearch.common.settings.Settings)

Example 22 with Environment

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

the class InstallPluginCommandTests method testSpaceInUrl.

public void testSpaceInUrl() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPlugin("fake", pluginDir);
    Path pluginZipWithSpaces = createTempFile("foo bar", ".zip");
    try (InputStream in = FileSystemUtils.openFileURLStream(new URL(pluginZip))) {
        Files.copy(in, pluginZipWithSpaces, StandardCopyOption.REPLACE_EXISTING);
    }
    installPlugin(pluginZipWithSpaces.toUri().toURL().toString(), env.v1());
    assertPlugin("fake", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) URL(java.net.URL)

Example 23 with Environment

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

the class InstallPluginCommandTests method testMalformedUrlNotMaven.

public void testMalformedUrlNotMaven() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    // has two colons, so it appears similar to maven coordinates
    MalformedURLException e = expectThrows(MalformedURLException.class, () -> installPlugin("://host:1234", env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) Environment(org.elasticsearch.env.Environment)

Example 24 with Environment

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

the class InstallPluginCommandTests method testBinNotDir.

public void testBinNotDir() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path binDir = pluginDir.resolve("bin");
    Files.createFile(binDir);
    String pluginZip = createPlugin("fake", pluginDir);
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("not a directory"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.elasticsearch.cli.UserException)

Example 25 with Environment

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

the class InstallPluginCommandTests method testBinPermissions.

public void testBinPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    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);
    try (PosixPermissionsResetter binAttrs = new PosixPermissionsResetter(env.v2().binFile())) {
        Set<PosixFilePermission> perms = binAttrs.getCopyPermissions();
        // make sure at least one execute perm is missing, so we know we forced it during installation
        perms.remove(PosixFilePermission.GROUP_EXECUTE);
        binAttrs.setPermissions(perms);
        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) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) PosixPermissionsResetter(org.elasticsearch.test.PosixPermissionsResetter)

Aggregations

Environment (org.elasticsearch.env.Environment)103 Settings (org.elasticsearch.common.settings.Settings)63 Path (java.nio.file.Path)60 Matchers.containsString (org.hamcrest.Matchers.containsString)28 IndexSettings (org.elasticsearch.index.IndexSettings)20 UserException (org.elasticsearch.cli.UserException)14 IOException (java.io.IOException)11 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)8 ScriptService (org.elasticsearch.script.ScriptService)8 AnalysisModule (org.elasticsearch.indices.analysis.AnalysisModule)7 ScriptContextRegistry (org.elasticsearch.script.ScriptContextRegistry)7 ScriptEngineRegistry (org.elasticsearch.script.ScriptEngineRegistry)7 ScriptSettings (org.elasticsearch.script.ScriptSettings)7 Collections (java.util.Collections)5 Before (org.junit.Before)5 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Logger (org.apache.logging.log4j.Logger)4 MockScriptEngine (org.elasticsearch.script.MockScriptEngine)4