From 8d5b5ad862de589667211456f1e96c156412c90f Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Fri, 31 Jul 2015 12:59:44 -0400 Subject: [PATCH] restore my lost code changes and add measures to detect/prevent this in the future --- .../elasticsearch/plugins/PluginsService.java | 67 +++++++++---------- .../SitePluginRelativePathConfigTests.java | 2 +- .../plugins/SitePluginTests.java | 2 +- .../anotherplugin/_site/index.html | 0 .../plugin-descriptor.properties | 3 + .../dummy/_site/dir1/.empty | 0 .../dummy/_site/index.html | 0 .../dummy/plugin-descriptor.properties | 3 + .../subdir/_site/dir/index.html | 0 .../subdir/_site/dir_without_index/page.html | 0 .../subdir/plugin-descriptor.properties | 3 + dev-tools/smoke_test_plugins.py | 7 +- .../main/resources/ant/integration-tests.xml | 18 ++--- .../main/resources/bin/elasticsearch.in.bat | 7 +- .../main/resources/bin/elasticsearch.in.sh | 8 ++- 15 files changed, 68 insertions(+), 52 deletions(-) rename core/src/test/resources/org/elasticsearch/{plugins => test_plugins}/anotherplugin/_site/index.html (100%) create mode 100644 core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties rename core/src/test/resources/org/elasticsearch/{plugins => test_plugins}/dummy/_site/dir1/.empty (100%) rename core/src/test/resources/org/elasticsearch/{plugins => test_plugins}/dummy/_site/index.html (100%) create mode 100644 core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties rename core/src/test/resources/org/elasticsearch/{plugins => test_plugins}/subdir/_site/dir/index.html (100%) rename core/src/test/resources/org/elasticsearch/{plugins => test_plugins}/subdir/_site/dir_without_index/page.html (100%) create mode 100644 core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java index 61303bd070a..64e3bc39662 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginsService.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginsService.java @@ -47,6 +47,7 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -107,7 +108,7 @@ public class PluginsService extends AbstractComponent { List bundles = getPluginBundles(environment); tupleBuilder.addAll(loadBundles(bundles)); } catch (IOException ex) { - throw new IllegalStateException("Can't load plugins into classloader", ex); + throw new IllegalStateException(ex); } plugins = tupleBuilder.build(); @@ -309,34 +310,30 @@ public class PluginsService extends AbstractComponent { try (DirectoryStream stream = Files.newDirectoryStream(pluginsDirectory)) { for (Path plugin : stream) { - try { - if (FileSystemUtils.isHidden(plugin)) { - logger.trace("--- skip hidden plugin file[{}]", plugin.toAbsolutePath()); - continue; - } - logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath()); - PluginInfo info = PluginInfo.readFromProperties(plugin); - List urls = new ArrayList<>(); - if (info.isJvm()) { - // a jvm plugin: gather urls for jar files - try (DirectoryStream jarStream = Files.newDirectoryStream(plugin, "*.jar")) { - for (Path jar : jarStream) { - urls.add(jar.toUri().toURL()); - } + if (FileSystemUtils.isHidden(plugin)) { + logger.trace("--- skip hidden plugin file[{}]", plugin.toAbsolutePath()); + continue; + } + logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath()); + PluginInfo info = PluginInfo.readFromProperties(plugin); + List urls = new ArrayList<>(); + if (info.isJvm()) { + // a jvm plugin: gather urls for jar files + try (DirectoryStream jarStream = Files.newDirectoryStream(plugin, "*.jar")) { + for (Path jar : jarStream) { + urls.add(jar.toUri().toURL()); } } - final Bundle bundle; - if (info.isJvm() && info.isIsolated() == false) { - bundle = bundles.get(0); // purgatory - } else { - bundle = new Bundle(); - bundles.add(bundle); - } - bundle.plugins.add(info); - bundle.urls.addAll(urls); - } catch (Throwable e) { - logger.warn("failed to add plugin [" + plugin + "]", e); } + final Bundle bundle; + if (info.isJvm() && info.isIsolated() == false) { + bundle = bundles.get(0); // purgatory + } else { + bundle = new Bundle(); + bundles.add(bundle); + } + bundle.plugins.add(info); + bundle.urls.addAll(urls); } } @@ -360,7 +357,7 @@ public class PluginsService extends AbstractComponent { jars.addAll(bundle.urls); JarHell.checkJarHell(jars.toArray(new URL[0])); } catch (Exception e) { - logger.warn("failed to load bundle {} due to jar hell", bundle.urls, e); + throw new IllegalStateException("failed to load bundle " + bundle.urls + " due to jar hell", e); } // create a child to load the plugins in this bundle @@ -371,17 +368,13 @@ public class PluginsService extends AbstractComponent { .build(); for (PluginInfo pluginInfo : bundle.plugins) { - try { - final Plugin plugin; - if (pluginInfo.isJvm()) { - plugin = loadPlugin(pluginInfo.getClassname(), settings); - } else { - plugin = new SitePlugin(pluginInfo.getName(), pluginInfo.getDescription()); - } - plugins.add(new Tuple<>(pluginInfo, plugin)); - } catch (Throwable e) { - logger.warn("failed to load plugin from [" + bundle.urls + "]", e); + final Plugin plugin; + if (pluginInfo.isJvm()) { + plugin = loadPlugin(pluginInfo.getClassname(), settings); + } else { + plugin = new SitePlugin(pluginInfo.getName(), pluginInfo.getDescription()); } + plugins.add(new Tuple<>(pluginInfo, plugin)); } } diff --git a/core/src/test/java/org/elasticsearch/plugins/SitePluginRelativePathConfigTests.java b/core/src/test/java/org/elasticsearch/plugins/SitePluginRelativePathConfigTests.java index d350e43c0f4..78dd6809033 100644 --- a/core/src/test/java/org/elasticsearch/plugins/SitePluginRelativePathConfigTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/SitePluginRelativePathConfigTests.java @@ -45,7 +45,7 @@ public class SitePluginRelativePathConfigTests extends ElasticsearchIntegrationT @Override protected Settings nodeSettings(int nodeOrdinal) { String cwdToRoot = getRelativePath(PathUtils.get(".").toAbsolutePath()); - Path pluginDir = PathUtils.get(cwdToRoot, relativizeToRootIfNecessary(getDataPath("/org/elasticsearch/plugins")).toString()); + Path pluginDir = PathUtils.get(cwdToRoot, relativizeToRootIfNecessary(getDataPath("/org/elasticsearch/test_plugins")).toString()); Path tempDir = createTempDir(); boolean useRelativeInMiddleOfPath = randomBoolean(); diff --git a/core/src/test/java/org/elasticsearch/plugins/SitePluginTests.java b/core/src/test/java/org/elasticsearch/plugins/SitePluginTests.java index 35ae9844fc1..254d35253cb 100644 --- a/core/src/test/java/org/elasticsearch/plugins/SitePluginTests.java +++ b/core/src/test/java/org/elasticsearch/plugins/SitePluginTests.java @@ -49,7 +49,7 @@ public class SitePluginTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { - Path pluginDir = getDataPath("/org/elasticsearch/plugins"); + Path pluginDir = getDataPath("/org/elasticsearch/test_plugins"); return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put("path.plugins", pluginDir.toAbsolutePath()) diff --git a/core/src/test/resources/org/elasticsearch/plugins/anotherplugin/_site/index.html b/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/_site/index.html similarity index 100% rename from core/src/test/resources/org/elasticsearch/plugins/anotherplugin/_site/index.html rename to core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/_site/index.html diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties new file mode 100644 index 00000000000..8a08b726b50 --- /dev/null +++ b/core/src/test/resources/org/elasticsearch/test_plugins/anotherplugin/plugin-descriptor.properties @@ -0,0 +1,3 @@ +site=true +description=anotherplugin +version=1.0 diff --git a/core/src/test/resources/org/elasticsearch/plugins/dummy/_site/dir1/.empty b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/_site/dir1/.empty similarity index 100% rename from core/src/test/resources/org/elasticsearch/plugins/dummy/_site/dir1/.empty rename to core/src/test/resources/org/elasticsearch/test_plugins/dummy/_site/dir1/.empty diff --git a/core/src/test/resources/org/elasticsearch/plugins/dummy/_site/index.html b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/_site/index.html similarity index 100% rename from core/src/test/resources/org/elasticsearch/plugins/dummy/_site/index.html rename to core/src/test/resources/org/elasticsearch/test_plugins/dummy/_site/index.html diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties new file mode 100644 index 00000000000..71f5a590274 --- /dev/null +++ b/core/src/test/resources/org/elasticsearch/test_plugins/dummy/plugin-descriptor.properties @@ -0,0 +1,3 @@ +site=true +description=dummy +version=1.0 diff --git a/core/src/test/resources/org/elasticsearch/plugins/subdir/_site/dir/index.html b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/_site/dir/index.html similarity index 100% rename from core/src/test/resources/org/elasticsearch/plugins/subdir/_site/dir/index.html rename to core/src/test/resources/org/elasticsearch/test_plugins/subdir/_site/dir/index.html diff --git a/core/src/test/resources/org/elasticsearch/plugins/subdir/_site/dir_without_index/page.html b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/_site/dir_without_index/page.html similarity index 100% rename from core/src/test/resources/org/elasticsearch/plugins/subdir/_site/dir_without_index/page.html rename to core/src/test/resources/org/elasticsearch/test_plugins/subdir/_site/dir_without_index/page.html diff --git a/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties new file mode 100644 index 00000000000..f6a05a4f499 --- /dev/null +++ b/core/src/test/resources/org/elasticsearch/test_plugins/subdir/plugin-descriptor.properties @@ -0,0 +1,3 @@ +site=true +description=subdir +version=1.0 diff --git a/dev-tools/smoke_test_plugins.py b/dev-tools/smoke_test_plugins.py index 693edf414af..da6c2c95209 100644 --- a/dev-tools/smoke_test_plugins.py +++ b/dev-tools/smoke_test_plugins.py @@ -95,18 +95,18 @@ if __name__ == '__main__': run('%s; %s clean package -DskipTests' % (JAVA_ENV, MVN)) - for f in os.listdir('core/target/releases/'): + for f in os.listdir('distribution/tar/target/releases/'): if f.endswith('.tar.gz'): artifact = f break else: - raise RuntimeError('could not find elasticsearch release under core/target/releases/') + raise RuntimeError('could not find elasticsearch release under distribution/tar/target/releases/') tmp_dir = tempfile.mkdtemp() p = None try: # Extract artifact: - run('tar -xzf core/target/releases/%s -C %s' % (artifact, tmp_dir)) + run('tar -xzf distribution/tar/target/releases/%s -C %s' % (artifact, tmp_dir)) es_install_dir = os.path.join(tmp_dir, artifact[:-7]) es_plugin_path = os.path.join(es_install_dir, 'bin/plugin') installed_plugin_names = set() @@ -131,6 +131,7 @@ if __name__ == '__main__': '-Des.node.name=smoke_tester', '-Des.cluster.name=smoke_tester_cluster' '-Des.discovery.zen.ping.multicast.enabled=false', + '-Des.logger.level=debug', '-Des.script.inline=on', '-Des.script.indexed=on'), stdout = subprocess.PIPE, diff --git a/dev-tools/src/main/resources/ant/integration-tests.xml b/dev-tools/src/main/resources/ant/integration-tests.xml index 92f346fed1d..a8cb9912dd3 100644 --- a/dev-tools/src/main/resources/ant/integration-tests.xml +++ b/dev-tools/src/main/resources/ant/integration-tests.xml @@ -21,7 +21,6 @@ - @@ -31,15 +30,18 @@ - + + + + - + - - + + @@ -86,7 +88,7 @@ Installing plugin @{name}... - + @@ -116,7 +118,7 @@ Starting up external cluster... - @@ -144,7 +146,7 @@ - diff --git a/distribution/src/main/resources/bin/elasticsearch.in.bat b/distribution/src/main/resources/bin/elasticsearch.in.bat index fdc5d82a649..6cdd131776d 100644 --- a/distribution/src/main/resources/bin/elasticsearch.in.bat +++ b/distribution/src/main/resources/bin/elasticsearch.in.bat @@ -89,5 +89,10 @@ set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8 REM Use our provided JNA always versus the system one set JAVA_OPTS=%JAVA_OPTS% -Djna.nosys=true -set ES_CLASSPATH=%ES_CLASSPATH%;%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/* +set CORE_CLASSPATH=%ES_HOME%/lib/${project.build.finalName}.jar;%ES_HOME%/lib/* +if "%ES_CLASSPATH%" == "" ( +set ES_CLASSPATH=%CORE_CLASSPATH% +) else ( +set ES_CLASSPATH=%ES_CLASSPATH%;%CORE_CLASSPATH% +) set ES_PARAMS=-Delasticsearch -Des-foreground=yes -Des.path.home="%ES_HOME%" diff --git a/distribution/src/main/resources/bin/elasticsearch.in.sh b/distribution/src/main/resources/bin/elasticsearch.in.sh index 86af7224604..46ab4b6db75 100644 --- a/distribution/src/main/resources/bin/elasticsearch.in.sh +++ b/distribution/src/main/resources/bin/elasticsearch.in.sh @@ -1,6 +1,12 @@ #!/bin/sh -ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*" +CORE_CLASSPATH="$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*" + +if [ "x$ES_CLASSPATH" = "x" ]; then + ES_CLASSPATH="$CORE_CLASSPATH" +else + ES_CLASSPATH="$ES_CLASSPATH:$CORE_CLASSPATH" +fi if [ "x$ES_MIN_MEM" = "x" ]; then ES_MIN_MEM=${packaging.elasticsearch.heap.min}