Search in sources :

Example 21 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.

the class WBCommonServicesBackendTest method testAsKieWbCommonServicesBackendBuilder.

@Test
public void testAsKieWbCommonServicesBackendBuilder() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
    final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("wbcommonservicesbackend_app.dmn", this.getClass()), ks.getResources().newClassPathResource("wbcommonservicesbackend_route.dmn", this.getClass()));
    final KieContainer kieContainer = ks.newKieContainer(v100);
    final KieSession kieSession = kieContainer.newKieSession();
    final DMNRuntime runtime = kieSession.getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(2));
    checkApp(runtime);
    // the below is performed by the WB at: https://github.com/kiegroup/kie-wb-common/blob/9e6b6da145e61ac8f5a9f7c0259d44aa9d090a2b/kie-wb-common-services/kie-wb-common-services-backend/src/main/java/org/kie/workbench/common/services/backend/builder/core/Builder.java#L592-L620
    final KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieModule, null);
    final KieContainer kieContainer2 = new KieContainerImpl(kieProject, ks.getRepository(), v100);
    // exhibit the issue.
    final KieSession kieSession2 = kieContainer2.newKieSession();
    final DMNRuntime runtime2 = kieSession2.getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime2);
    assertThat(runtime2.getModels(), hasSize(2));
    checkApp(runtime2);
}
Also used : KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieProject(org.drools.compiler.kie.builder.impl.KieProject) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 22 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.

the class PMMLRuntimeFactoryInternal method getPMMLFileFromKieContainerByDefaultKieBase.

/**
 * Load a <code>File</code> with the given <b>pmmlFileName</b> from the <code>kjar</code> contained in the
 * <code>KieContainer</code> with the given <code>ReleaseId</code>
 * It will use the <b>default</b> Kiebase defined inside the <b>kmodule.xml</b> of the loaded <b>kjar</b>
 * @param pmmlFileName
 * @param releaseId
 * @return
 */
private static File getPMMLFileFromKieContainerByDefaultKieBase(final String pmmlFileName, final ReleaseId releaseId) {
    KieContainerImpl kieContainer = (KieContainerImpl) KIE_SERVICES.newKieContainer(releaseId);
    String defaultKieBase = kieContainer.getKieProject().getDefaultKieBaseModel().getName();
    return getPMMLFileFromKieContainerByKieBase(pmmlFileName, defaultKieBase, releaseId);
}
Also used : KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl)

Example 23 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project drools by kiegroup.

the class PMMLRuntimeFactoryInternal method getPMMLFileFromKieContainerByKieBase.

/**
 * Load a <code>File</code> with the given <b>pmmlFileName</b> from the <code>kjar</code> contained in the
 * <code>KieContainer</code> with the given <code>ReleaseId</code>
 * @param pmmlFileName
 * @param kieBase the name of the Kiebase configured inside the <b>kmodule.xml</b> of the loaded <b>kjar</b>
 * @param releaseId
 * @return
 */
private static File getPMMLFileFromKieContainerByKieBase(final String pmmlFileName, final String kieBase, final ReleaseId releaseId) {
    KieContainerImpl kieContainer = (KieContainerImpl) KIE_SERVICES.newKieContainer(releaseId);
    InternalResource internalResource = ((InternalKieModule) (kieContainer).getKieModuleForKBase(kieBase)).getResource(pmmlFileName);
    try (InputStream inputStream = internalResource.getInputStream()) {
        return getPMMLFile(pmmlFileName, inputStream);
    } catch (Exception e) {
        throw new ExternalException(e);
    }
}
Also used : InternalResource(org.drools.core.io.internal.InternalResource) InputStream(java.io.InputStream) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ExternalException(org.kie.pmml.api.exceptions.ExternalException) ExternalException(org.kie.pmml.api.exceptions.ExternalException) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 24 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project kie-wb-common by kiegroup.

the class Builder method getKieContainer.

public KieContainer getKieContainer() {
    BuildResults results = null;
    // Kie classes are only available once built
    if (!isBuilt()) {
        results = build();
    } else {
        results = new BuildResults();
        results.addAllBuildMessages(convertMessages(kieBuilder.getResults().getMessages(), handles));
    }
    // It's impossible to retrieve a KieContainer if the KieModule contains errors
    if (results.getErrorMessages().isEmpty()) {
        // Do not retrieve the KieContainer with KieServices.newKieContainer(releaseId) since this looks-up the KieModule to
        // create the KieContainer from KieRepository. This holds the most recent KieModule (for the ReleaseId) that was built with
        // kieBuilder.buildAll() which *may* be a KieModule created during asset validation and hence will lack many assets.
        // See https://bugzilla.redhat.com/show_bug.cgi?id=1202551
        final org.kie.api.builder.KieModule kieModule = kieBuilder.getKieModule();
        final ReleaseId releaseId = kieModule.getReleaseId();
        final org.drools.compiler.kie.builder.impl.KieProject kieProject = new KieModuleKieProject((InternalKieModule) kieBuilder.getKieModule(), null);
        final KieContainer kieContainer = new KieContainerImpl(kieProject, KieServices.Factory.get().getRepository(), releaseId);
        return kieContainer;
    } else {
        return null;
    }
}
Also used : BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) IncrementalBuildResults(org.guvnor.common.services.project.builder.model.IncrementalBuildResults) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ReleaseId(org.kie.api.builder.ReleaseId) KieModuleKieProject(org.drools.compiler.kie.builder.impl.KieModuleKieProject) KieContainer(org.kie.api.runtime.KieContainer)

Example 25 with KieContainerImpl

use of org.drools.compiler.kie.builder.impl.KieContainerImpl in project jbpm by kiegroup.

the class KModuleRegisterableItemsFactory method getWorkItemHandlers.

@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
    KieSessionModel ksessionModel = null;
    if (StringUtils.isEmpty(ksessionName)) {
        ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
        if (ksessionModel == null) {
            ksessionName = DEFAULT_KIE_SESSION;
            ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
        }
    } else {
        ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(ksessionName);
    }
    if (ksessionModel == null) {
        throw new IllegalStateException("Cannot find ksession, either it does not exist or there are multiple default ksession in kmodule.xml");
    }
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ksession", runtime.getKieSession());
    parameters.put("taskService", runtime.getTaskService());
    parameters.put("runtimeManager", ((RuntimeEngineImpl) runtime).getManager());
    if (getRuntimeManager().getKieContainer() != null) {
        parameters.put("kieContainer", getRuntimeManager().getKieContainer());
    }
    parameters.put("classLoader", getRuntimeManager().getEnvironment().getClassLoader());
    try {
        InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
    } catch (Exception e) {
        e.printStackTrace();
        // use fallback mechanism
        InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
    }
    return super.getWorkItemHandlers(runtime);
}
Also used : HashMap(java.util.HashMap) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Aggregations

KieContainerImpl (org.drools.compiler.kie.builder.impl.KieContainerImpl)25 ReleaseId (org.kie.api.builder.ReleaseId)17 KieContainer (org.kie.api.runtime.KieContainer)15 Test (org.junit.Test)14 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)11 KieServices (org.kie.api.KieServices)10 KieProject (org.drools.compiler.kie.builder.impl.KieProject)9 KieModule (org.kie.api.builder.KieModule)9 KieModuleKieProject (org.drools.compiler.kie.builder.impl.KieModuleKieProject)8 KieSession (org.kie.api.runtime.KieSession)7 KieBase (org.kie.api.KieBase)4 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)4 HashMap (java.util.HashMap)3 MemoryKieModule (org.drools.compiler.kie.builder.impl.MemoryKieModule)3 Person (org.drools.modelcompiler.domain.Person)3 KieFileSystem (org.kie.api.builder.KieFileSystem)3 KieBaseModel (org.kie.api.builder.model.KieBaseModel)3 KieModuleModel (org.kie.api.builder.model.KieModuleModel)3 KReleaseId (org.kie.api.cdi.KReleaseId)3 FileKieModule (org.drools.compiler.kie.builder.impl.FileKieModule)2