apache / incubator-kie-kogito-examples

Kogito examples - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
256 stars 381 forks source link

Decision Tables - Using Variables - Unable to resolve class '<X>' for global 'e' #52

Closed mmonti closed 5 years ago

mmonti commented 5 years ago

I have been playing around with https://github.com/kiegroup/kogito-examples/tree/master/drools-quarkus-example because we have a service that uses drools and we want to migrate to Kogito.

I found an issue when using Variables that seems to be happening only when I run a native build (mvn clean package -Pnative). The project compiles and I can run the executable just fine but when I call the endpoint I get the following error:

Caused by: java.lang.RuntimeException: Unable to resolve class 'com.group.artifact.ActionExecutor' for global 'e'
        at org.drools.core.impl.KnowledgeBaseImpl.mergePackage(KnowledgeBaseImpl.java:1252)
        at org.drools.core.impl.KnowledgeBaseImpl.internalAddPackages(KnowledgeBaseImpl.java:895)
        at org.drools.core.impl.KnowledgeBaseImpl.lambda$addPackages$2(KnowledgeBaseImpl.java:714)
        at org.drools.core.impl.KnowledgeBaseImpl.enqueueModification(KnowledgeBaseImpl.java:731)
        at org.drools.core.impl.KnowledgeBaseImpl.addPackages(KnowledgeBaseImpl.java:714)
        at org.drools.modelcompiler.builder.KieBaseBuilder.createKieBase(KieBaseBuilder.java:56)
        at org.drools.modelcompiler.builder.KieBaseBuilder.createKieBaseFromModel(KieBaseBuilder.java:90)
        at org.drools.project.model.ProjectRuntime.<init>(ProjectRuntime.java:16)
        at org.kie.kogito.examples.Application$RuleUnits.<init>(Application.java:30)
        at org.kie.kogito.examples.Application.<init>(Application.java:22)
        at org.kie.kogito.examples.Application_Bean.create(Application_Bean.zig:150)
        at org.kie.kogito.examples.Application_Bean.create(Application_Bean.zig:179)
        at io.quarkus.arc.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:70)
        at io.quarkus.arc.AbstractSharedContext.lambda$new$0(AbstractSharedContext.java:17)
        at io.quarkus.arc.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:99)
        at io.quarkus.arc.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.ComputingCache.getValue(ComputingCache.java:41)
        at io.quarkus.arc.AbstractSharedContext.get(AbstractSharedContext.java:23)
        at org.kie.kogito.examples.Application_Bean.get(Application_Bean.zig:76)
        at org.kie.kogito.examples.Application_Bean.get(Application_Bean.zig:46)
        at org.kie.kogito.quickstart.CanDrinkResource_Bean.create(CanDrinkResource_Bean.zig:222)
        at org.kie.kogito.quickstart.CanDrinkResource_Bean.create(CanDrinkResource_Bean.zig:171)
        at io.quarkus.arc.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:70)
        at io.quarkus.arc.AbstractSharedContext.lambda$new$0(AbstractSharedContext.java:17)
        at io.quarkus.arc.ComputingCache$CacheFunction.lambda$apply$0(ComputingCache.java:99)
        at io.quarkus.arc.LazyValue.get(LazyValue.java:26)
        at io.quarkus.arc.ComputingCache.getValue(ComputingCache.java:41)
        at io.quarkus.arc.AbstractSharedContext.get(AbstractSharedContext.java:23)
        at org.kie.kogito.quickstart.CanDrinkResource_Bean.get(CanDrinkResource_Bean.zig:46)
        at org.kie.kogito.quickstart.CanDrinkResource_Bean.get(CanDrinkResource_Bean.zig:261)
        at io.quarkus.arc.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:317)
        at io.quarkus.arc.ArcContainerImpl.beanInstanceHandle(ArcContainerImpl.java:329)
        at io.quarkus.arc.ArcContainerImpl$1.get(ArcContainerImpl.java:194)
        at io.quarkus.arc.ArcContainerImpl$1.get(ArcContainerImpl.java:191)
        at io.quarkus.arc.runtime.ArcDeploymentTemplate$2$1.create(ArcDeploymentTemplate.java:70)
        at io.quarkus.resteasy.server.common.runtime.QuarkusConstructorInjector.construct(QuarkusConstructorInjector.java:56)
        at org.jboss.resteasy.plugins.server.resourcefactory.POJOResourceFactory.createResource(POJOResourceFactory.java:69)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:340)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:477)
        ... 51 more

The exact same code runs just fine when running on debug mode: mvn clean package quarkus:dev

The way I am setting up the Variable is as follow:

@Path("/candrink/{name}/{age}")
public class CanDrinkResource {

    @Inject @Named("canDrinkKS")
    RuleUnit<SessionMemory> ruleUnit;

    @Inject
    Application application;

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String canDrink( @PathParam("name") String name, @PathParam("age") int age ) {
        Result result = new Result();
        Person person = new Person( name, age );

        ActionExecutor e = new ActionExecutor();
        RuleUnits ruleUnits = application.ruleUnits();
        KieRuntimeBuilder kieRuntimeBuilder = ruleUnits.ruleRuntimeBuilder();
        KieSession session = kieRuntimeBuilder.newKieSession();
        session.setGlobal("e", e);
        session.insert(result);
        session.insert(person);
        session.fireAllRules();

        return result.toString();
    }
}

This is how my decision table looks like:

Screen Shot 2019-07-22 at 10 48 30 AM

I have an example to reproduce this issue here:

I am wondering if this is an issue with the current implementation or If I am missing something in my code.

Thanks. M.-

mmonti commented 5 years ago

@mswiderski I just realized that the Kogito site mentions to report issues in the Jira platform. Should I move these two issues there for tracking?

mswiderski commented 5 years ago

@mmonti yes, please move it to jira so we can track it and include in upcoming release, thanks

mswiderski commented 5 years ago

moved to jira https://issues.jboss.org/browse/KOGITO-78