在 Spark 作业中使用 drools

Using drools in a Spark job

我正在尝试在提交到集群的 spark 作业中使用 drools。该工作将从 drools 服务器获取 drools jar 开始,然后初始化基础和会话。 我的代码在 Spark 中执行时有效,但在提交到 spark 集群时发生 NPE。

我就是这样做的

String url = "{my server address}/drools-wb/maven2/com/myspace/Project1/1.0.0/Project1-1.0.0.jar";
KieServices ks = KieServices.Factory.get();

//ERROR is in the below line 
ReleaseId releaseId = ks.newReleaseId("com.myspace", "Project1", "1.0.0"); 

KieRepository kr = ks.getRepository();
UrlResource urlResource = (UrlResource) ks.getResources().newUrlResource(url);

提交代码后显示的错误:

Exception in thread "main" java.lang.NullPointerException
    at org.opencell.spark.jobs.TestWithDrools.main(TestWithDrools.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:879)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain(SparkSubmit.scala:197)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:227)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:136)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
2018-08-29 10:08:09 INFO  ShutdownHookManager:54 - Shutdown hook called

你有解决这个问题的想法吗?

问题是因为ks为空。

所以要解决这个问题,请参考这个post:

Drools 7.4.1 kieservices.factory.get() returns null