Search in sources :

Example 11 with Environment

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

the class InstallPluginCommandTests method testMissingDescriptor.

public void testMissingDescriptor() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Files.createFile(pluginDir.resolve("fake.yml"));
    String pluginZip = writeZip(pluginDir, "elasticsearch");
    NoSuchFileException e = expectThrows(NoSuchFileException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("plugin-descriptor.properties"));
    assertInstallCleaned(env.v2());
}
Also used : Path(java.nio.file.Path) NoSuchFileException(java.nio.file.NoSuchFileException) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 12 with Environment

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

the class InstallPluginCommandTests method testJarHell.

public void testJarHell() throws Exception {
    // jar hell test needs a real filesystem
    assumeTrue("real filesystem", isReal);
    Tuple<Path, Environment> environment = createEnv(fs, temp);
    Path pluginDirectory = createPluginDir(temp);
    writeJar(pluginDirectory.resolve("other.jar"), "FakePlugin");
    // adds plugin.jar with FakePlugin
    String pluginZip = createPlugin("fake", pluginDirectory);
    IllegalStateException e = expectThrows(IllegalStateException.class, () -> installPlugin(pluginZip, environment.v1(), true));
    assertTrue(e.getMessage(), e.getMessage().contains("jar hell"));
    assertInstallCleaned(environment.v2());
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 13 with Environment

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

the class InstallPluginCommandTests method testBinContainsDir.

public void testBinContainsDir() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path dirInBinDir = pluginDir.resolve("bin").resolve("foo");
    Files.createDirectories(dirInBinDir);
    Files.createFile(dirInBinDir.resolve("somescript"));
    String pluginZip = createPlugin("fake", pluginDir);
    UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("Directories not allowed in bin dir for plugin"));
    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 14 with Environment

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

the class InstallPluginCommandTests method testUnknownPlugin.

public void testUnknownPlugin() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    UserException e = expectThrows(UserException.class, () -> installPlugin("foo", env.v1()));
    assertTrue(e.getMessage(), e.getMessage().contains("Unknown plugin foo"));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) UserException(org.elasticsearch.cli.UserException)

Example 15 with Environment

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

the class InstallPluginCommandTests method testExistingConfig.

public void testExistingConfig() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path envConfigDir = env.v2().configFile().resolve("fake");
    Files.createDirectories(envConfigDir);
    Files.write(envConfigDir.resolve("custom.yaml"), "existing config".getBytes(StandardCharsets.UTF_8));
    Path pluginDir = createPluginDir(temp);
    Path configDir = pluginDir.resolve("config");
    Files.createDirectory(configDir);
    Files.write(configDir.resolve("custom.yaml"), "new config".getBytes(StandardCharsets.UTF_8));
    Files.createFile(configDir.resolve("other.yaml"));
    String pluginZip = createPlugin("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
    List<String> configLines = Files.readAllLines(envConfigDir.resolve("custom.yaml"), StandardCharsets.UTF_8);
    assertEquals(1, configLines.size());
    assertEquals("existing config", configLines.get(0));
    assertTrue(Files.exists(envConfigDir.resolve("other.yaml")));
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) Matchers.containsString(org.hamcrest.Matchers.containsString)

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