Search in sources :

Example 16 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testPluginAlreadyInstalled.

public void testPluginAlreadyInstalled() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    String pluginZip = createPluginUrl("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    final UserException e = expectThrows(UserException.class, () -> installPlugin(pluginZip, env.v1(), randomFrom(skipJarHellCommand, defaultCommand)));
    assertThat(e.getMessage(), equalTo("plugin directory [" + env.v2().pluginsFile().resolve("fake") + "] already exists; " + "if you need to update the plugin, uninstall it first using command 'remove fake'"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) UserException(org.opensearch.cli.UserException)

Example 17 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method testConfig.

public void testConfig() throws Exception {
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path configDir = pluginDir.resolve("config");
    Files.createDirectory(configDir);
    Files.createFile(configDir.resolve("custom.yml"));
    String pluginZip = createPluginUrl("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 18 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class InstallPluginCommandTests method installPlugins.

void installPlugins(final List<String> pluginUrls, final Path home, final InstallPluginCommand command) throws Exception {
    final Environment env = TestEnvironment.newEnvironment(Settings.builder().put("path.home", home).build());
    command.execute(terminal, pluginUrls, false, env);
}
Also used : TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment)

Example 19 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class SpawnerNoBootstrapTests method assertControllerSpawns.

private void assertControllerSpawns(final Function<Environment, Path> pluginsDirFinder, boolean expectSpawn) throws Exception {
    /*
         * On Windows you can not directly run a batch file - you have to run cmd.exe with the batch
         * file as an argument and that's out of the remit of the controller daemon process spawner.
         */
    assumeFalse("This test does not work on Windows", Constants.WINDOWS);
    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 = TestEnvironment.newEnvironment(settings);
    // this plugin will have a controller daemon
    Path plugin = pluginsDirFinder.apply(environment).resolve("test_plugin");
    Files.createDirectories(environment.modulesFile());
    Files.createDirectories(environment.pluginsFile());
    Files.createDirectories(plugin);
    PluginTestUtil.writePluginProperties(plugin, "description", "test_plugin", "version", Version.CURRENT.toString(), "opensearch.version", Version.CURRENT.toString(), "name", "test_plugin", "java.version", "1.8", "classname", "TestPlugin", "has.native.controller", "true");
    Path controllerProgram = Platforms.nativeControllerPath(plugin);
    createControllerProgram(controllerProgram);
    // this plugin will not have a controller daemon
    Path otherPlugin = pluginsDirFinder.apply(environment).resolve("other_plugin");
    Files.createDirectories(otherPlugin);
    PluginTestUtil.writePluginProperties(otherPlugin, "description", "other_plugin", "version", Version.CURRENT.toString(), "opensearch.version", Version.CURRENT.toString(), "name", "other_plugin", "java.version", "1.8", "classname", "OtherPlugin", "has.native.controller", "false");
    Spawner spawner = new Spawner();
    spawner.spawnNativeControllers(environment, false);
    List<Process> processes = spawner.getProcesses();
    if (expectSpawn) {
        // as there should only be a reference in the list for the module that had the controller daemon, we expect one here
        assertThat(processes, hasSize(1));
        Process process = processes.get(0);
        final InputStreamReader in = new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8);
        try (BufferedReader stdoutReader = new BufferedReader(in)) {
            String line = stdoutReader.readLine();
            assertEquals("I am alive", line);
            spawner.close();
            // fail if the process does not die within one second; usually it will be even quicker but it depends on OS scheduling
            assertTrue(process.waitFor(1, TimeUnit.SECONDS));
        }
    } else {
        assertThat(processes, hasSize(0));
    }
}
Also used : Path(java.nio.file.Path) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) Settings(org.opensearch.common.settings.Settings)

Example 20 with Environment

use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.

the class SpawnerNoBootstrapTests method testControllerSpawnWithIncorrectDescriptor.

public void testControllerSpawnWithIncorrectDescriptor() throws IOException {
    // this plugin will have a controller daemon
    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 = TestEnvironment.newEnvironment(settings);
    Path plugin = environment.modulesFile().resolve("test_plugin");
    Files.createDirectories(plugin);
    PluginTestUtil.writePluginProperties(plugin, "description", "test_plugin", "version", Version.CURRENT.toString(), "opensearch.version", Version.CURRENT.toString(), "name", "test_plugin", "java.version", "1.8", "classname", "TestPlugin", "has.native.controller", "false");
    Path controllerProgram = Platforms.nativeControllerPath(plugin);
    createControllerProgram(controllerProgram);
    Spawner spawner = new Spawner();
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> spawner.spawnNativeControllers(environment, false));
    assertThat(e.getMessage(), equalTo("module [test_plugin] does not have permission to fork native controller"));
}
Also used : Path(java.nio.file.Path) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) Settings(org.opensearch.common.settings.Settings)

Aggregations

Environment (org.opensearch.env.Environment)142 TestEnvironment (org.opensearch.env.TestEnvironment)98 Path (java.nio.file.Path)80 Settings (org.opensearch.common.settings.Settings)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 Matchers.hasToString (org.hamcrest.Matchers.hasToString)40 NodeEnvironment (org.opensearch.env.NodeEnvironment)32 IOException (java.io.IOException)27 UserException (org.opensearch.cli.UserException)23 ClusterState (org.opensearch.cluster.ClusterState)22 IndexSettings (org.opensearch.index.IndexSettings)22 MockTerminal (org.opensearch.cli.MockTerminal)19 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)19 OpenSearchException (org.opensearch.OpenSearchException)18 Map (java.util.Map)16 OptionSet (joptsimple.OptionSet)15 DiscoverySettings (org.opensearch.node.Node.DiscoverySettings)14 Version (org.opensearch.Version)13 Files (java.nio.file.Files)11 Arrays (java.util.Arrays)11