Search in sources :

Example 1 with KieRuntimeFactory

use of org.kie.api.runtime.KieRuntimeFactory in project drools by kiegroup.

the class DMNKiePMMLTrustyInvocationEvaluator method getPMMLRuntime.

/**
 * @param eventManager
 * @return
 */
private PMMLRuntime getPMMLRuntime(DMNRuntimeEventManager eventManager) {
    DMNRuntimeImpl dmnRuntime = (DMNRuntimeImpl) eventManager.getRuntime();
    final DMNRuntimeKB runtimeKB = dmnRuntime.getRuntimeKB();
    if (runtimeKB instanceof DMNRuntimeKBWrappingIKB) {
        // We are in drools
        return getPMMLRuntimeFromDMNRuntimeKBWrappingIKB((DMNRuntimeKBWrappingIKB) runtimeKB);
    } else {
        // we are in kogito
        KieRuntimeFactory kieFactory = dmnRuntime.getKieRuntimeFactory(model);
        return kieFactory.get(PMMLRuntime.class);
    }
}
Also used : KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) DMNRuntimeKB(org.kie.dmn.core.impl.DMNRuntimeKB) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNRuntimeKBWrappingIKB(org.kie.dmn.core.impl.DMNRuntimeKBWrappingIKB)

Example 2 with KieRuntimeFactory

use of org.kie.api.runtime.KieRuntimeFactory in project drools by kiegroup.

the class DMNRuntimeBuilderTest method setKieRuntimeFactoryFunction.

@Test
public void setKieRuntimeFactoryFunction() {
    KieRuntimeFactory toReturn = KieRuntimeFactory.of(KIE_BASE);
    Function<String, KieRuntimeFactory> kieRuntimeFactoryFunction = s -> toReturn;
    final DMNRuntimeImpl retrieved = (DMNRuntimeImpl) dmnRuntimeBuilder.setKieRuntimeFactoryFunction(kieRuntimeFactoryFunction).buildConfiguration().fromResources(Collections.emptyList()).getOrElseThrow(RuntimeException::new);
    assertNotNull(retrieved);
    KieRuntimeFactory kieRuntimeFactory = retrieved.getKieRuntimeFactory("TEST");
    assertEquals(toReturn, kieRuntimeFactory);
}
Also used : KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) KieBase(org.kie.api.KieBase) Collections(java.util.Collections) Function(java.util.function.Function) KnowledgeBaseFactory(org.drools.kiesession.rulebase.KnowledgeBaseFactory) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) Test(org.junit.Test)

Example 3 with KieRuntimeFactory

use of org.kie.api.runtime.KieRuntimeFactory in project drools by kiegroup.

the class PMMLMiningModelEvaluator method getPMMLRuntime.

/**
 * Retrieve the <code>PMMLRuntime</code> to be used for the given <b>segment</b>
 * It creates new <code>InternalKnowledgeBase</code>s and store them in a <code>Map</code>,
 * to reuse them.
 * @param kModulePackageName
 * @param knowledgeBase
 * @param containerModelName
 * @return
 */
PMMLRuntime getPMMLRuntime(final String kModulePackageName, final KieBase knowledgeBase, final String containerModelName) {
    final String key = containerModelName + "_" + kModulePackageName;
    InternalKnowledgeBase kieBase = MAPPED_KIEBASES.computeIfAbsent(key, s -> {
        final KiePackage kiePackage = knowledgeBase.getKiePackage(kModulePackageName);
        final List<KiePackage> packages = kiePackage != null ? Collections.singletonList(knowledgeBase.getKiePackage(kModulePackageName)) : Collections.emptyList();
        RuleBaseConfiguration conf = new RuleBaseConfiguration();
        conf.setClassLoader(((RuleBase) knowledgeBase).getRootClassLoader());
        InternalKnowledgeBase toReturn = KnowledgeBaseFactory.newKnowledgeBase(kModulePackageName, conf);
        toReturn.addPackages(packages);
        return toReturn;
    });
    KieRuntimeFactory kieRuntimeFactory = KieRuntimeFactory.of(kieBase);
    return kieRuntimeFactory.get(PMMLRuntime.class);
}
Also used : RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) KiePackage(org.kie.api.definition.KiePackage) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase)

Aggregations

KieRuntimeFactory (org.kie.api.runtime.KieRuntimeFactory)3 DMNRuntimeImpl (org.kie.dmn.core.impl.DMNRuntimeImpl)2 Collections (java.util.Collections)1 Function (java.util.function.Function)1 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)1 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)1 KnowledgeBaseFactory (org.drools.kiesession.rulebase.KnowledgeBaseFactory)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Before (org.junit.Before)1 Test (org.junit.Test)1 KieBase (org.kie.api.KieBase)1 KiePackage (org.kie.api.definition.KiePackage)1 DMNRuntimeKB (org.kie.dmn.core.impl.DMNRuntimeKB)1 DMNRuntimeKBWrappingIKB (org.kie.dmn.core.impl.DMNRuntimeKBWrappingIKB)1