3

I am using optaplanner to solve a scheduling problem. I want to invoke the scheduling code from AWS Lambda (i know that Lambda's max execution time is 5 minutes and thats okay for this application)

To achieve this I have build a maven project with two modules: module-1: scheduling optimization code module-2: aws lambda handler ( calls scheduling code from module-1)

When i run my tests in IntelliJ Idea for module-1(that has optaplanner code), it runs fine.

When I invoke the lambda function, i get following exception:

java.lang.ExceptionInInitializerError:    
java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError
 at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
 ...
Caused by: java.lang.RuntimeException: Child services [org.kie.api.internal.assembler.KieAssemblers] have no parent
 at org.kie.api.internal.utils.ServiceDiscoveryImpl.buildMap(ServiceDiscoveryImpl.java:191)
 at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:97)
 ...

I have included following dependency in maven file: org.optaplanner optaplanner-core 7.7.0.Final

Also checked that jar file have drools-core, kie-api, kei-internal, drools-compiler. Does anyone know what might be the issue?

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
mluser
  • 53
  • 1
  • 6
  • For what's it's worth (not much), EasyScoreCalculator and IncrementalScoreCalculator won't have this problem. – Geoffrey De Smet Jul 10 '18 at 20:19
  • @GeoffreyDeSmet this error is happening when I initialize SolverFactory from XMLResource, much before score calculation stage. – mluser Jul 11 '18 at 14:27
  • Are you 100% sure? I would expect it to happen at `solverFactory.buildSolver()`, not at `SolverFactory.createFromXmlResource()`. In the former case, the other calculators aren't affected. – Geoffrey De Smet Jul 12 '18 at 07:01
  • 1
    @GeoffreyDeSmet yes you are right, its happening at `solverFactory.buildSolver()` – mluser Jul 12 '18 at 13:44

2 Answers2

1

Sounds like a bug in drools when running in a restricted environment such as AWS-lambda. Please create a JIRA and link it here.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • 1
    Thank you for your response @Geoffrey. I have created a jira (https://issues.jboss.org/browse/DROOLS-2726) ticket. Is this something that can be fixed sooner or do you suggest any workaround? – mluser Jul 11 '18 at 13:32
  • still not fixed apparently. – sansa Mar 18 '19 at 01:56
  • I've improved bug report so it goes to the drools core guys. **Workaround**: don't use Drools score calculation. – Geoffrey De Smet Mar 19 '19 at 06:40
1

I was getting the same error attempting to run a fat jar containing an example OptaPlanner project. A little debugging revealed that the problem was services was empty when ServiceDiscoveryImpl::buildMap was invoked; I was using the first META-INF/kie.conf in the build, and as a result services were missing from that file. Naturally your tests would work properly because the class path would contain all of the dependencies (that is, several distinct META-INF/kie.conf files), and not the assembly you were attempting to execute on the lambda.

Concatenating those files instead (using an appropriate merge strategy in assembly) fixes the problem and appears appropriate given how those are loaded by ServiceDiscoveryImpl. The updated JAR runs properly as an AWS lambda.

Note: I was using the default scoreDrl from the v7.12.0.Final Cloud Balancing example.

Luis Woods
  • 11
  • 3