Vesion:
Elasticsearch 8.6.2
(My plugin is working on Elasticsearch7.6.0 )
I am developing a plugin to let ES filter through Redis data.
So I import Jedis package in my code. But when ES starts, I get this error.
2023-03-09 14:52:22 {"@timestamp":"2023-03-09T06:52:22.853Z", "log.level":"ERROR", "message":"fatal exception while booting Elasticsearch", "ecs.version": "1.2.0","service.name":"ES_ECS","event.dataset":"elasticsearch.server","process.thread.name":"main","log.logger":"org.elasticsearch.bootstrap.Elasticsearch","elasticsearch.node.name":"5988c9637415","elasticsearch.cluster.name":"docker-cluster","error.type":"java.lang.IllegalStateException","error.message":"failed to load plugin class [com.jinnrry.Main]","error.stack_trace":"java.lang.IllegalStateException: failed to load plugin class [com.jinnrry.Main]\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:618)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.loadBundle(PluginsService.java:493)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.loadBundles(PluginsService.java:290)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:159)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.lambda$getPluginsServiceCtor$14(PluginsService.java:645)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.node.Node.<init>(Node.java:415)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.node.Node.<init>(Node.java:322)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.bootstrap.Elasticsearch$2.<init>(Elasticsearch.java:214)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.bootstrap.Elasticsearch.initPhase3(Elasticsearch.java:214)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:67)\nCaused by: java.lang.reflect.InvocationTargetException\n\tat java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:79)\n\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)\n\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:484)\n\tat org.elasticsearch.server@8.6.2/org.elasticsearch.plugins.PluginsService.loadPlugin(PluginsService.java:609)\n\t... 9 more\nCaused by: java.security.AccessControlException: access denied (\"javax.management.MBeanServerPermission\" \"createMBeanServer\")\n\tat java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:485)\n\tat java.base/java.security.AccessController.checkPermission(AccessController.java:1068)\n\tat java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:411)\n\tat java.management/java.lang.management.ManagementFactory.getPlatformMBeanServer(ManagementFactory.java:482)\n\tat org.apache.commons.pool2.impl.BaseGenericObjectPool.jmxRegister(BaseGenericObjectPool.java:1189)\n\tat org.apache.commons.pool2.impl.BaseGenericObjectPool.<init>(BaseGenericObjectPool.java:401)\n\tat org.apache.commons.pool2.impl.GenericObjectPool.<init>(GenericObjectPool.java:147)\n\tat redis.clients.jedis.util.Pool.<init>(Pool.java:16)\n\tat redis.clients.jedis.util.Pool.<init>(Pool.java:12)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:368)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:341)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:335)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:324)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:313)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:293)\n\tat redis.clients.jedis.JedisPool.<init>(JedisPool.java:34)\n\tat com.jinnrry.Main.lambda$connectRedis$0(Main.java:54)\n\tat java.base/java.security.AccessController.doPrivileged(AccessController.java:318)\n\tat com.jinnrry.Main.connectRedis(Main.java:54)\n\tat com.jinnrry.Main.<init>(Main.java:26)\n\tat java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:67)\n\t... 12 more\n"}
This is my plugin code :
public class Main extends Plugin implements ScriptPlugin, SearchPlugin {
private static final String RedisConfigKey = "esHotelPlugin.redis.url";
public Main(final Settings settings, final Path configPath) {
JedisPool jedisPool = connectRedis(settings.get(RedisConfigKey));
RedisScriptEngine.setPool(jedisPool);
}
/**
* @return the plugin's custom settings
*/
@Override
public List<Setting<?>> getSettings() {
List<Setting<?>> settings = new ArrayList<>();
settings.add(new Setting<>(RedisConfigKey, "redis://127.0.0.1:6379", Function.identity(),
Setting.Property.NodeScope));
return settings;
}
@Override
public ScriptEngine getScriptEngine(Settings settings, Collection<ScriptContext<?>> contexts) {
return new RedisScriptEngine();
}
private static JedisPool connectRedis(String redisUrl) {
SpecialPermission.check();
return java.security.AccessController.doPrivileged((java.security.PrivilegedAction<JedisPool>) () -> new JedisPool(redisUrl));
}
}
This is my plugin-security.policy
file content :
grant {
permission javax.management.MBeanServerPermission "createMBeanServer";
permission javax.management.MBeanServerPermission "findMBeanServer";
permission javax.management.MBeanServerPermission "newMBeanServer";
permission javax.management.MBeanTrustPermission "register";
permission javax.management.MBeanPermission "*" "*";
permission javax.management.MBeanServerPermission "releaseMBeanServer";
};