Fail to start if plugin tries broken onModule

If a plugin declares `onModule(SomethingThatIsntAModule)` then refuse
to start. Before this commit we just logged a warning that flies by in
the console and is easy to miss. You can't miss refusing to start!
This commit is contained in:
Nik Everett 2016-06-22 12:03:11 -04:00
parent 6d04c1e78e
commit 6574243077
2 changed files with 13 additions and 2 deletions

View File

@ -44,6 +44,7 @@ import org.elasticsearch.index.IndexModule;
import org.elasticsearch.script.NativeScriptFactory; import org.elasticsearch.script.NativeScriptFactory;
import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.script.ScriptEngineService; import org.elasticsearch.script.ScriptEngineService;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.ExecutorBuilder;
import java.io.IOException; import java.io.IOException;
@ -206,9 +207,14 @@ public class PluginsService extends AbstractComponent {
} }
Class moduleClass = method.getParameterTypes()[0]; Class moduleClass = method.getParameterTypes()[0];
if (!Module.class.isAssignableFrom(moduleClass)) { if (!Module.class.isAssignableFrom(moduleClass)) {
logger.warn("Plugin: {} implementing onModule by the type is not of Module type {}", pluginEntry.v1().getName(), moduleClass); if (moduleClass == ScriptModule.class) {
// This is still part of the Plugin class to point the user to the new implementation
continue; continue;
} }
throw new RuntimeException(
"Plugin: [" + pluginEntry.v1().getName() + "] implements onModule taking a parameter that isn't a Module ["
+ moduleClass.getSimpleName() + "]");
}
list.add(new OnModuleReference(moduleClass, method)); list.add(new OnModuleReference(moduleClass, method));
} }
if (!list.isEmpty()) { if (!list.isEmpty()) {

View File

@ -117,3 +117,8 @@ via ES_JAVA_OPTS.
The ability to specify a custom plugins path via `path.plugins` has The ability to specify a custom plugins path via `path.plugins` has
been removed. been removed.
==== ScriptPlugin
Plugins that register custom scripts should implement `ScriptPlugin` and remove
their `onModule(ScriptModule)` implementation.