Verbose plugin not found exception (#849)
* Add Plugin name for verbose Plugin not found exception * Make the plugin loading failure exception more verbose * Throw Opensearch in place of RuntimeException for plugin load failure * Nit fix, added ... to make logging standout Signed-off-by: Jayesh Hathila <sharma.jayesh52@gmail.com>
This commit is contained in:
parent
110cef7882
commit
3cd4e7ff54
|
@ -662,6 +662,7 @@ public class PluginsService implements ReportingService<PluginsAndModules> {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.debug("Loading plugin [" + name + "]...");
|
||||||
Class<? extends Plugin> pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader);
|
Class<? extends Plugin> pluginClass = loadPluginClass(bundle.plugin.getClassname(), loader);
|
||||||
if (loader != pluginClass.getClassLoader()) {
|
if (loader != pluginClass.getClassLoader()) {
|
||||||
throw new IllegalStateException("Plugin [" + name + "] must reference a class loader local Plugin class ["
|
throw new IllegalStateException("Plugin [" + name + "] must reference a class loader local Plugin class ["
|
||||||
|
@ -700,8 +701,8 @@ public class PluginsService implements ReportingService<PluginsAndModules> {
|
||||||
private Class<? extends Plugin> loadPluginClass(String className, ClassLoader loader) {
|
private Class<? extends Plugin> loadPluginClass(String className, ClassLoader loader) {
|
||||||
try {
|
try {
|
||||||
return Class.forName(className, false, loader).asSubclass(Plugin.class);
|
return Class.forName(className, false, loader).asSubclass(Plugin.class);
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (Throwable t) {
|
||||||
throw new OpenSearchException("Could not find plugin class [" + className + "]", e);
|
throw new OpenSearchException("Unable to load plugin class [" + className + "]", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -734,6 +734,30 @@ public class PluginsServiceTests extends OpenSearchTestCase {
|
||||||
TestPlugin.class.getName() + "] (class loader [" + PluginsServiceTests.class.getClassLoader() + "])")));
|
TestPlugin.class.getName() + "] (class loader [" + PluginsServiceTests.class.getClassLoader() + "])")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPluginLoadFailure() throws IOException {
|
||||||
|
final Path pathHome = createTempDir();
|
||||||
|
final Path plugins = pathHome.resolve("plugins");
|
||||||
|
final Path fake = plugins.resolve("fake");
|
||||||
|
|
||||||
|
PluginTestUtil.writePluginProperties(
|
||||||
|
fake,
|
||||||
|
"description", "description",
|
||||||
|
"name", "fake",
|
||||||
|
"version", "1.0.0",
|
||||||
|
"opensearch.version", Version.CURRENT.toString(),
|
||||||
|
"java.version", System.getProperty("java.specification.version"),
|
||||||
|
"classname", "DummyClass"); // This class is not present in Path, hence plugin loading will throw ClassNotFoundException
|
||||||
|
|
||||||
|
final Settings settings =
|
||||||
|
Settings.builder()
|
||||||
|
.put("path.home", pathHome)
|
||||||
|
.put("plugin.mandatory", "fake")
|
||||||
|
.build();
|
||||||
|
RuntimeException exception = expectThrows(RuntimeException.class, () -> newPluginsService(settings));
|
||||||
|
assertTrue(exception.getCause() instanceof ClassNotFoundException);
|
||||||
|
assertThat(exception, hasToString(containsString("Unable to load plugin class [DummyClass]")));
|
||||||
|
}
|
||||||
|
|
||||||
public void testExtensiblePlugin() {
|
public void testExtensiblePlugin() {
|
||||||
TestExtensiblePlugin extensiblePlugin = new TestExtensiblePlugin();
|
TestExtensiblePlugin extensiblePlugin = new TestExtensiblePlugin();
|
||||||
PluginsService.loadExtensions(Collections.singletonList(
|
PluginsService.loadExtensions(Collections.singletonList(
|
||||||
|
|
Loading…
Reference in New Issue