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'"));
}
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());
}
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);
}
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));
}
}
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"));
}
Aggregations