Building and running Drools in a fat jar not working starting 7.45

53 views
Skip to first unread message

Liqun Du

unread,
Feb 1, 2021, 5:31:42 PM2/1/21
to drools...@googlegroups.com, drools-de...@googlegroups.com
Hi,
We are running into issues to upgrade drools to 7.48. According to the suggestion from https://docs.jboss.org/drools/release/7.48.0.Final/drools-docs/html_single/index.html, we added the following to the pom.xml for maven-shade-plugin
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/kie.conf</resource> </transformer>

At runtime, we see the error message "There already exists an implementation for service org.kie.api.KieServices with same priority 0"
Does anyone know how to resolve this? We have to build the fat jat because the rule engine is running in Spark cluster.

Thanks

Liqun

=====detail log=========

21/02/01 17:15:22 ERROR ServiceDiscoveryImpl: Loading failed because There already exists an implementation for service org.kie.api.KieServices with same priority 0

Exception in thread "main" java.lang.ExceptionInInitializerError

at org.drools.dynamic.DynamicServiceRegistrySupplier.get(DynamicServiceRegistrySupplier.java:32)

at org.drools.dynamic.DynamicServiceRegistrySupplier.get(DynamicServiceRegistrySupplier.java:23)

at org.kie.api.internal.utils.ServiceRegistry$Impl.getServiceRegistry(ServiceRegistry.java:90)

at org.kie.api.internal.utils.ServiceRegistry$ServiceRegistryHolder.<clinit>(ServiceRegistry.java:49)

at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:41)

at org.kie.api.internal.utils.ServiceRegistry.getService(ServiceRegistry.java:37)

at org.kie.api.KieServices$Factory$LazyHolder.<clinit>(KieServices.java:358)

at org.kie.api.KieServices$Factory.get(KieServices.java:365)

at org.cb.dm.dataprovenance.brms.engine.RuleManager.initByPackage(RuleManager.java:205)

at org.cb.dm.dataprovenance.brms.engine.RuleManager.initRules(RuleManager.java:129)

at org.cb.dm.dataprovenance.brms.GenericSparkDF.start(GenericSparkDF.java:277)

at org.cb.dm.dataprovenance.brms.GenericSparkDF.main(GenericSparkDF.java:100)

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:845)

at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:161)

at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:184)

at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:86)

at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:920)

at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:929)

at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

Caused by: java.lang.RuntimeException: Unable to build kie service url = jar:file:/Users/dev//target/nys_mvp_parquet-2.0.0.jar!/META-INF/kie.conf

at org.kie.api.internal.utils.ServiceDiscoveryImpl.registerConfs(ServiceDiscoveryImpl.java:105)

at org.kie.api.internal.utils.ServiceDiscoveryImpl.lambda$getServices$1(ServiceDiscoveryImpl.java:83)

at java.util.Optional.ifPresent(Optional.java:159)

at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:81)

at org.kie.api.internal.utils.ServiceRegistry$Impl.<init>(ServiceRegistry.java:62)

at org.drools.dynamic.DynamicServiceRegistrySupplier$LazyHolder.<clinit>(DynamicServiceRegistrySupplier.java:27)

... 24 more

Caused by: java.lang.RuntimeException: There already exists an implementation for service org.kie.api.KieServices with same priority 0

at org.kie.api.internal.utils.ServiceDiscoveryImpl$PriorityMap.put(ServiceDiscoveryImpl.java:222)

at org.kie.api.internal.utils.ServiceDiscoveryImpl.processKieService(ServiceDiscoveryImpl.java:124)

at org.kie.api.internal.utils.ServiceDiscoveryImpl.registerConfs(ServiceDiscoveryImpl.java:101)

... 29 more

                  

--
Liqun

Liqun Du

unread,
Feb 2, 2021, 1:15:18 PM2/2/21
to drools...@googlegroups.com, drools-de...@googlegroups.com
Hi Luca,
Thanks for your email. I can see the exception is thrown when I make the call "KieServices kieServices = KieServices.Factory.get();" in the application. I extracted the context from kie.conf per your request. Here it is:
I have no idea why some lines begin with a question mark '?'

C02VR25QHTD8:target ldu$ cat ./META-INF/kie.conf

org.kie.api.KieServices = org.drools.compiler.kie.builder.impl.KieServicesImpl

?org.kie.internal.builder.KnowledgeBuilderFactoryService = org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl

?org.kie.internal.builder.JaxbConfigurationFactoryService = org.drools.compiler.builder.impl.JaxbConfigurationFactoryServiceImpl

org.drools.compiler.kie.builder.impl.KieBaseUpdaters = org.drools.compiler.kie.builder.impl.KieBaseUpdatersImpl

org.kie.api.KieServices = org.drools.compiler.kie.builder.impl.KieServicesImpl

?org.kie.internal.builder.KnowledgeBuilderFactoryService = org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl

?org.kie.internal.builder.JaxbConfigurationFactoryService = org.drools.compiler.builder.impl.JaxbConfigurationFactoryServiceImpl

org.drools.compiler.kie.builder.impl.KieBaseUpdaters = org.drools.compiler.kie.builder.impl.KieBaseUpdatersImpl

org.kie.api.io.KieResources = org.drools.core.io.impl.ResourceFactoryServiceImpl

org.kie.api.concurrent.KieExecutors = org.drools.core.concurrent.ExecutorProviderImpl



org.kie.api.internal.assembler.KieAssemblers = org.kie.internal.services.KieAssemblersImpl

org.kie.api.internal.runtime.KieRuntimes = org.kie.internal.services.KieRuntimesImpl

org.kie.api.internal.weaver.KieWeavers = org.kie.internal.services.KieWeaversImpl

org.kie.api.internal.runtime.beliefs.KieBeliefs = org.kie.internal.services.KieBeliefsImpl


org.drools.compiler.rule.builder.ConstraintBuilder = org.drools.mvel.MVELConstraintBuilder

org.drools.core.base.CoreComponentsBuilder = org.drools.mvel.MVELCoreComponentsBuilder

org.drools.core.base.FieldAccessorFactory = org.drools.mvel.asm.ClassFieldAccessorFactory

org.drools.core.factmodel.ClassBuilderFactory = org.drools.mvel.asm.DefaultClassBuilderFactory


On Tue, Feb 2, 2021 at 3:57 AM Luca Molteni <lmol...@redhat.com> wrote:


> On 1 Feb 2021, at 23:31, Liqun Du <liq...@gmail.com> wrote:
>
> Hi,
> We are running into issues to upgrade drools to 7.48. According to the suggestion from https://docs.jboss.org/drools/release/7.48.0.Final/drools-docs/html_single/index.html, we added the following to the pom.xml for maven-shade-plugin
> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
>     <resource>META-INF/kie.conf</resource>
> </transformer>
>
>
> At runtime, we see the error message "There already exists an implementation for service org.kie.api.KieServices with same priority 0"
> Does anyone know how to resolve this? We have to build the fat jat because the rule engine is running in Spark cluster.
>
> Thanks
>
> Liqun

Hello  Liqun

The error message you’re getting is due to a recent change in the Service Discovery.
Before when we had different implementation, a random one were chosen, now an error message is thrown.

You can provide a higher priority implementation in the kie.conf file using this syntax

org.kie.api.internal.assembler.KieAssemblers = org.kie.api.internal.utils.AnotherMockAssemblersImpl;4

as shown in this test.

https://github.com/kiegroup/droolsjbpm-knowledge/blob/0891ee943bdd023ac7fb5e4bffd1589c4e30b16a/kie-api/src/test/java/org/kie/api/internal/utils/ServiceDiscoveryImplTest.java#L57-L56

You can find some more details on the feature in ths Jira.

https://issues.redhat.com/browse/DROOLS-4070

Having said that, this doesn’t seem to be related to the uberjar you’re creating.
Maybe what happens is that by creating a uberjar some unwanted kie.conf files are merged altogether?
Please check (or post here) the generated kie.conf file in the uberjar.

Hope this helps

Luca


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/699FFF46-8FFC-4741-8EC5-51FA861DD73F%40redhat.com.


--
Liqun

Liqun Du

unread,
Feb 4, 2021, 4:49:42 PM2/4/21
to drools...@googlegroups.com, drools-de...@googlegroups.com
Hi Luca,
Thanks again for your help. >>>"I’m especially interested in the first few lines of the mvn execution, which in my reproducer are" this gave me the clue. Apparently I have another drools app (in fat jar) as the dependency for this project. So now when I check for drools jars, I do see duplicates from maven execution. The issue has been resolved.

Thanks,

Liqun

On Wed, Feb 3, 2021 at 12:17 PM Luca Molteni <lmol...@redhat.com> wrote:


> On 3 Feb 2021, at 18:15, Luca Molteni <lmol...@redhat.com> wrote:
>
> I tried to create a reproducer, but unfortunately I couldn’t see the same behaviour


One more thing

I’m especially interested in the first few lines of the mvn execution, which in my reproducer are

[INFO] --- maven-shade-plugin:3.1.0:shade (default) @ uberjar-kieconf ---
[INFO] Including org.drools:drools-engine-classic:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie:kie-api:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie.soup:kie-soup-maven-support:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.slf4j:slf4j-api:jar:1.7.26 in the shaded jar.
[INFO] Including org.kie:kie-internal:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.drools:drools-core:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie.soup:kie-soup-xstream:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.drools:drools-core-reflective:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.drools:drools-core-dynamic:jar:7.48.0.Final in the shaded jar.
[INFO] Including commons-codec:commons-codec:jar:1.11 in the shaded jar.
[INFO] Including org.drools:drools-compiler:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie:kie-memory-compiler:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.antlr:antlr-runtime:jar:3.5.2 in the shaded jar.
[INFO] Including com.thoughtworks.xstream:xstream:jar:1.4.14 in the shaded jar.
[INFO] Including xmlpull:xmlpull:jar:1.1.3.1 in the shaded jar.
[INFO] Including xpp3:xpp3_min:jar:1.1.4c in the shaded jar.
[INFO] Including org.drools:drools-mvel:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.mvel:mvel2:jar:2.4.11.Final in the shaded jar.
[INFO] Including org.kie.soup:kie-soup-project-datamodel-commons:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie.soup:kie-soup-commons:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.kie.soup:kie-soup-project-datamodel-api:jar:7.48.0.Final in the shaded jar.
[INFO] Including org.drools:drools-ecj:jar:7.48.0.Final in the shaded jar.


As you can see drools-compiler is listed only once.

Thanks!


Luca

--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.


--
Liqun
Reply all
Reply to author
Forward
0 new messages