Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -77,6 +78,7 @@ public void testNoControllerSpawn() throws IOException, InterruptedException {

// This plugin will NOT have a controller daemon
Path plugin = environment.pluginsFile().resolve("a_plugin");
Files.createDirectories(environment.modulesFile());
Files.createDirectories(plugin);
PluginTestUtil.writePluginProperties(
plugin,
Expand All @@ -97,7 +99,12 @@ public void testNoControllerSpawn() throws IOException, InterruptedException {
/**
* Two plugins - one with a controller daemon and one without.
*/
public void testControllerSpawn() throws IOException, InterruptedException {
public void testControllerSpawn() throws Exception {
assertControllerSpawns(Environment::pluginsFile);
assertControllerSpawns(Environment::modulesFile);
}

private void assertControllerSpawns(Function<Environment, Path> pluginsDirFinder) 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.
Expand All @@ -112,32 +119,34 @@ public void testControllerSpawn() throws IOException, InterruptedException {
Environment environment = TestEnvironment.newEnvironment(settings);

// this plugin will have a controller daemon
Path plugin = environment.pluginsFile().resolve("test_plugin");
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(),
"elasticsearch.version", Version.CURRENT.toString(),
"name", "test_plugin",
"java.version", "1.8",
"classname", "TestPlugin",
"has.native.controller", "true");
plugin,
"description", "test_plugin",
"version", Version.CURRENT.toString(),
"elasticsearch.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 = environment.pluginsFile().resolve("other_plugin");
Path otherPlugin = pluginsDirFinder.apply(environment).resolve("other_plugin");
Files.createDirectories(otherPlugin);
PluginTestUtil.writePluginProperties(
otherPlugin,
"description", "other_plugin",
"version", Version.CURRENT.toString(),
"elasticsearch.version", Version.CURRENT.toString(),
"name", "other_plugin",
"java.version", "1.8",
"classname", "OtherPlugin",
"has.native.controller", "false");
otherPlugin,
"description", "other_plugin",
"version", Version.CURRENT.toString(),
"elasticsearch.version", Version.CURRENT.toString(),
"name", "other_plugin",
"java.version", "1.8",
"classname", "OtherPlugin",
"has.native.controller", "false");

Spawner spawner = new Spawner();
spawner.spawnNativePluginControllers(environment);
Expand All @@ -150,7 +159,7 @@ public void testControllerSpawn() throws IOException, InterruptedException {
assertThat(processes, hasSize(1));
Process process = processes.get(0);
final InputStreamReader in =
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8);
new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8);
try (BufferedReader stdoutReader = new BufferedReader(in)) {
String line = stdoutReader.readLine();
assertEquals("I am alive", line);
Expand Down Expand Up @@ -181,6 +190,7 @@ public void testControllerSpawnMetaPlugin() throws IOException, InterruptedExcep
Environment environment = TestEnvironment.newEnvironment(settings);

Path metaPlugin = environment.pluginsFile().resolve("meta_plugin");
Files.createDirectories(environment.modulesFile());
Files.createDirectories(metaPlugin);
PluginTestUtil.writeMetaPluginProperties(
metaPlugin,
Expand Down Expand Up @@ -279,6 +289,7 @@ public void testSpawnerHandlingOfDesktopServicesStoreFiles() throws IOException

final Environment environment = TestEnvironment.newEnvironment(settings);

Files.createDirectories(environment.modulesFile());
Files.createDirectories(environment.pluginsFile());

final Path desktopServicesStore = environment.pluginsFile().resolve(".DS_Store");
Expand Down
10 changes: 1 addition & 9 deletions server/src/main/java/org/elasticsearch/bootstrap/Security.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,8 @@ static Map<String,Policy> getPluginPermissions(Environment environment) throws I
Map<String,Policy> map = new HashMap<>();
// collect up set of plugins and modules by listing directories.
Set<Path> pluginsAndModules = new LinkedHashSet<>(PluginsService.findPluginDirs(environment.pluginsFile()));
pluginsAndModules.addAll(PluginsService.findPluginDirs(environment.modulesFile()));

if (Files.exists(environment.modulesFile())) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(environment.modulesFile())) {
for (Path module : stream) {
if (pluginsAndModules.add(module) == false) {
throw new IllegalStateException("duplicate module: " + module);
}
}
}
}
// now process each one
for (Path plugin : pluginsAndModules) {
Path policyFile = plugin.resolve(PluginInfo.ES_PLUGIN_POLICY);
Expand Down
16 changes: 10 additions & 6 deletions server/src/main/java/org/elasticsearch/bootstrap/Spawner.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,20 @@ void spawnNativePluginControllers(final Environment environment) throws IOExcept
if (!spawned.compareAndSet(false, true)) {
throw new IllegalStateException("native controllers already spawned");
}
final Path pluginsFile = environment.pluginsFile();
if (!Files.exists(pluginsFile)) {
throw new IllegalStateException("plugins directory [" + pluginsFile + "] not found");
spawnControllers(environment.pluginsFile(), "plugins", environment.tmpFile());
spawnControllers(environment.modulesFile(), "modules", environment.tmpFile());
}

/** Spawn controllers in plugins found within the given directory. */
private void spawnControllers(Path pluginsDir, String type, Path tmpDir) throws IOException {
if (!Files.exists(pluginsDir)) {
throw new IllegalStateException(type + " directory [" + pluginsDir + "] not found");
}
/*
* For each plugin, attempt to spawn the controller daemon. Silently ignore any plugin that
* don't include a controller for the correct platform.
*/
List<Path> paths = PluginsService.findPluginDirs(pluginsFile);
List<Path> paths = PluginsService.findPluginDirs(pluginsDir);
for (Path plugin : paths) {
final PluginInfo info = PluginInfo.readFromProperties(plugin);
final Path spawnPath = Platforms.nativeControllerPath(plugin);
Expand All @@ -85,8 +90,7 @@ void spawnNativePluginControllers(final Environment environment) throws IOExcept
plugin.getFileName());
throw new IllegalArgumentException(message);
}
final Process process =
spawnNativePluginController(spawnPath, environment.tmpFile());
final Process process = spawnNativePluginController(spawnPath, tmpDir);
processes.add(process);
}
}
Expand Down