ElasticSearch 2.2.0 - ESIntegTestCase - 在搜索中执行groovy脚本时出现ClassNotFoundException

[英]ElasticSearch 2.2.0 - ESIntegTestCase - ClassNotFoundException when executing groovy script in search


I've been using Elastic 1.4.4, but we're now upgrading to 2.2.0. I am having trouble getting my integration tests to run. My integration test extends org.elasticsearch.test.ESIntegTestCase:

我一直在使用Elastic 1.4.4,但我们现在升级到2.2.0。我无法运行集成测试。我的集成测试扩展了org.elasticsearch.test.ESIntegTestCase:

@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE, numDataNodes = 1)
public abstract class AbstractApplicationTest extends ESIntegTestCase {
  ...
}

I can index documents without problems, but when I try searching with a script field, I get an error. I'm running my tests using sbt (I'm using the Play framework).

我可以没有问题索引文档,但是当我尝试使用脚本字段进行搜索时,我收到错误。我正在使用sbt运行我的测试(我正在使用Play框架)。

The error I'm getting is following:

我得到的错误如下:

{
    "error": {
        "root_cause": [{
            "type": "script_exception",
            "reason": "failed to compile groovy script"
        }],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [{
            "shard": 0,
            "index": "bokun",
            "node": "BNyjts9hTOicRgCAWGdKgQ",
            "reason": {
                "type": "script_exception",
                "reason": "Failed to compile inline script [if(_source.accumulated_availability != null){  for(item in _source.accumulated_availability){    if(start.compareTo(item.day) < 0 && (end == null || end.compareTo(item.day) >= 0)){      return item.day    }  }} else return null;] using lang [groovy]",
                "caused_by": {
                    "type": "script_exception",
                    "reason": "failed to compile groovy script",
                    "caused_by": {
                        "type": "multiple_compilation_errors_exception",
                        "reason": "startup failed:\nCould not instantiate global transform class groovy.grape.GrabAnnotationTransformation specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  because of exception java.lang.ClassNotFoundException: groovy.grape.GrabAnnotationTransformation\n\nCould not instantiate global transform class org.codehaus.groovy.ast.builder.AstBuilderTransformation specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  because of exception java.lang.ClassNotFoundException: org.codehaus.groovy.ast.builder.AstBuilderTransformation\n\n2 errors\n"
                    }
                }
            }
        }]
    },
    "status": 500
}

I'll reformat the "reason" message for readability:

为了便于阅读,我将重新格式化“原因”消息:

startup failed:

Could not instantiate global transform class 
groovy.grape.GrabAnnotationTransformation 
specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  

because of exception 
java.lang.ClassNotFoundException: groovy.grape.GrabAnnotationTransformation

Could not instantiate global transform class 
org.codehaus.groovy.ast.builder.AstBuilderTransformation 
specified at jar:file:/Users/ogg/.ivy2/cache/org.codehaus.groovy/groovy-all/jars/groovy-all-2.4.4-indy.jar!/META-INF/services/org.codehaus.groovy.transform.ASTTransformation  

because of exception java.lang.ClassNotFoundException: org.codehaus.groovy.ast.builder.AstBuilderTransformation

What can cause this? As far as I can tell, I have this class in my classpath: org.codehaus.groovy.ast.builder.AstBuilderTransformation. I have the following dependencies in my build.sbt:

是什么导致这种情况?据我所知,我的类路径中有这个类:org.codehaus.groovy.ast.builder.AstBuilderTransformation。我的build.sbt中有以下依赖项:

  "org.codehaus.groovy" % "groovy-all" % "2.4.4",
  "com.carrotsearch.randomizedtesting" % "randomizedtesting-runner" % "2.3.0" % "test",
  "org.apache.lucene" % "lucene-test-framework" % "5.4.1",
  "org.elasticsearch" % "elasticsearch" % "2.2.0" % "test" classifier "tests" withSources(),
  "org.elasticsearch" % "elasticsearch" % "2.2.0" withSources(),
  "org.elasticsearch.plugin" % "analysis-icu" % "2.2.0" % "test",
  "org.elasticsearch.module" % "lang-groovy" % "2.2.0" % "test"

...and I have the following in my EsIntegTestCase extension class:

...我在EsIntegTestCase扩展类中有以下内容:

@Override
protected Settings nodeSettings(int nodeOrdinal) {
    return Settings.settingsBuilder()
            .put(super.nodeSettings(nodeOrdinal))
            .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
            .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
            .put(Node.HTTP_ENABLED, true)
            .put("script.groovy.sandbox.enabled", true)
            .put("script.engine.groovy.inline.search", true)
            .put("script.engine.groovy.inline.update", "true")
            .put("script.inline", true)
            .put("script.update", true)
            .put("script.indexed", true)
            .put("script.default_lang", "groovy")
            .build();
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
    return pluginList(GroovyPlugin.class, AnalysisICUPlugin.class);
}

I'm completely stuck, and Google is unwilling to help! :slightly_smiling:

我完全陷入困境,谷歌不愿意提供帮助! :slightly_smiling:

Any help or pointers would be greatly appreciated.

任何帮助或指示将不胜感激。

Many thanks, OGG

非常感谢,OGG

1 个解决方案

#1


3  

This is now solved.

现在已经解决了。

The problem was actually that this was a SecurityException rethrown as ClassNotFoundException.

问题实际上是这是一个SecurityException重新抛出为ClassNotFoundException。

Using the instructions at https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-security.html I created a security policy file and added permission for the following classes:

使用https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting-security.html上的说明创建了一个安全策略文件,并为以下类添加了权限:

grant {
    permission org.elasticsearch.script.ClassPermission "java.lang.Class";
    permission org.elasticsearch.script.ClassPermission "org.codehaus.groovy.*";
    permission org.elasticsearch.script.ClassPermission "groovy.*";
    permission org.elasticsearch.script.ClassPermission "java.lang.*";
    permission org.elasticsearch.script.ClassPermission "java.util.*";
    permission org.elasticsearch.script.ClassPermission "java.math.BigDecimal";
    permission org.elasticsearch.script.ClassPermission "org.joda.time.*";
};

And then I start the tests passing my security policy file on the command line:

然后我开始在命令行上传递我的安全策略文件的测试:

-Djava.security.policy=security.policy

-Djava.security.policy = security.policy

You can see the thread on the Elastic discussion forum which helped me reach this solution: https://discuss.elastic.co/t/2-2-0-esintegtestcase-classnotfoundexception-when-executing-groovy-script-in-search/43579

你可以看到在弹性论坛这让我达到这个解决方案的主题:https://discuss.elastic.co/t/2-2-0-esintegtestcase-classnotfoundexception-when-executing-groovy-script-in-search / 43579

关注微信公众号

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/03/06/979adfdc74622bab4da7a3e1162e4f9.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com