Merge pull request #15200 from rjernst/old_plugin_error

Add nicer error message when a plugin descriptor is missing
This commit is contained in:
Ryan Ernst 2015-12-04 14:24:52 -08:00
commit 06f7d693bf
2 changed files with 26 additions and 5 deletions

View File

@ -46,6 +46,7 @@ import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
@ -282,7 +283,7 @@ public class PluginsService extends AbstractComponent {
public PluginsAndModules info() {
return info;
}
// a "bundle" is a group of plugins in a single classloader
// really should be 1-1, but we are not so fortunate
static class Bundle {
@ -331,7 +332,7 @@ public class PluginsService extends AbstractComponent {
if (!isAccessibleDirectory(pluginsDirectory, logger)) {
return Collections.emptyList();
}
List<Bundle> bundles = new ArrayList<>();
// a special purgatory for plugins that directly depend on each other
bundles.add(new Bundle());
@ -343,7 +344,14 @@ public class PluginsService extends AbstractComponent {
continue;
}
logger.trace("--- adding plugin [{}]", plugin.toAbsolutePath());
PluginInfo info = PluginInfo.readFromProperties(plugin);
final PluginInfo info;
try {
info = PluginInfo.readFromProperties(plugin);
} catch (NoSuchFileException e) {
throw new IllegalStateException("Existing plugin [" + plugin.getFileName() + "] missing plugin descriptor. " +
"Was the plugin built before 2.0?", e);
}
List<URL> urls = new ArrayList<>();
if (info.isJvm()) {
// a jvm plugin: gather urls for jar files
@ -364,7 +372,7 @@ public class PluginsService extends AbstractComponent {
bundle.urls.addAll(urls);
}
}
return bundles;
}
@ -382,7 +390,7 @@ public class PluginsService extends AbstractComponent {
} catch (Exception 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
ClassLoader loader = URLClassLoader.newInstance(bundle.urls.toArray(new URL[0]), getClass().getClassLoader());
for (PluginInfo pluginInfo : bundle.plugins) {

View File

@ -26,6 +26,8 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.test.ESTestCase;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
public class PluginsServiceTests extends ESTestCase {
@ -123,4 +125,15 @@ public class PluginsServiceTests extends ESTestCase {
assertEquals("boom", ex.getCause().getCause().getMessage());
}
}
public void testExistingPluginMissingDescriptor() throws Exception {
Path pluginsDir = createTempDir();
Files.createDirectory(pluginsDir.resolve("plugin-missing-descriptor"));
try {
PluginsService.getPluginBundles(pluginsDir);
fail();
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("[plugin-missing-descriptor] missing plugin descriptor"));
}
}
}