Search in sources :

Example 1 with KieContainerImpl

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

the class KieServicesTest method testDisposeClearTheIDReference.

@Test
public void testDisposeClearTheIDReference() {
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
    createAndDeployJar(ks, releaseId, createDRL("ruleA"));
    KieContainer c1 = ks.newKieContainer("id1", releaseId);
    try {
        ks.newKieClasspathContainer("id1");
        fail("should not allow repeated container IDs.");
    } catch (IllegalStateException is) {
    // ok.
    }
    ((KieContainerImpl) c1).dispose();
    // now OK.
    ks.newKieClasspathContainer("id1");
}
Also used : KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 2 with KieContainerImpl

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

the class InjectableRegisterableItemsFactory method getWorkItemHandlers.

@Override
public Map<String, WorkItemHandler> getWorkItemHandlers(RuntimeEngine runtime) {
    Map<String, WorkItemHandler> handler = new HashMap<String, WorkItemHandler>();
    handler.put("Human Task", getHTWorkItemHandler(runtime));
    RuntimeManager manager = ((RuntimeEngineImpl) runtime).getManager();
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("ksession", runtime.getKieSession());
    parameters.put("taskService", runtime.getTaskService());
    parameters.put("runtimeManager", manager);
    parameters.put("kieContainer", getRuntimeManager().getKieContainer());
    try {
        parameters.put("executorService", executorService.get());
    } catch (Exception e) {
        logger.debug("Executor service not available due to {}", e.getMessage());
    }
    if (kieContainer != null) {
        // add classloader as one of the parameters so it can be easily referenced
        parameters.put("classLoader", kieContainer.getClassLoader());
        KieSessionModel ksessionModel = null;
        if (StringUtils.isEmpty(ksessionName)) {
            ksessionModel = ((KieContainerImpl) kieContainer).getKieProject().getDefaultKieSession();
            if (ksessionModel == null) {
                ksessionModel = ((KieContainerImpl) kieContainer).getKieSessionModel(DEFAULT_KIE_SESSION);
            }
        } 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");
        }
        try {
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession(), parameters);
        } catch (Throwable e) {
            // use fallback mechanism
            InjectionHelper.wireSessionComponents(ksessionModel, runtime.getKieSession());
        }
    }
    try {
        for (WorkItemHandlerProducer producer : workItemHandlerProducer) {
            handler.putAll(producer.getWorkItemHandlers(manager.getIdentifier(), parameters));
        }
    } catch (Exception e) {
        // do nothing as work item handler is considered optional
        logger.warn("Exception while evalutating work item handler prodcuers {}", e.getMessage());
    }
    // add handlers from descriptor
    handler.putAll(getWorkItemHandlersFromDescriptor(runtime));
    return handler;
}
Also used : HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) RuntimeEngineImpl(org.jbpm.runtime.manager.impl.RuntimeEngineImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) IOException(java.io.IOException) KieSessionModel(org.kie.api.builder.model.KieSessionModel) WorkItemHandler(org.kie.api.runtime.process.WorkItemHandler) WorkItemHandlerProducer(org.kie.internal.runtime.manager.WorkItemHandlerProducer)

Example 3 with KieContainerImpl

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

the class DMNRuntimeKBWrappingIKB method getListeners.

@Override
public List<DMNRuntimeEventListener> getListeners() {
    if (knowledgeBase != null && knowledgeBase.getKieContainer() instanceof KieContainerImpl) {
        KieBaseModelImpl kieBaseModel = (KieBaseModelImpl) ((KieContainerImpl) knowledgeBase.getKieContainer()).getKieProject().getKieBaseModel(knowledgeBase.getId());
        ChainedProperties cp = ChainedProperties.getChainedProperties(getRootClassLoader());
        Properties kmoduleProperties = new Properties();
        kmoduleProperties.putAll(kieBaseModel.getKModule().getConfigurationProperties());
        cp.addProperties(kmoduleProperties);
        Map<String, String> listenersMap = new HashMap<>();
        cp.mapStartsWith(listenersMap, DMNAssemblerService.DMN_RUNTIME_LISTENER_PREFIX, true);
        logger.debug("{}", listenersMap);
        return listenersMap.values().stream().map(this::loadEventListener).flatMap(o -> o.map(Stream::of).orElseGet(Stream::empty)).collect(Collectors.toList());
    } else {
        logger.warn("No DMNRuntime Listener can be provided, as created without a reference to KnowledgeBase");
    }
    return Collections.emptyList();
}
Also used : MsgUtil(org.kie.dmn.core.util.MsgUtil) DMNPackage(org.kie.dmn.api.core.DMNPackage) LoggerFactory(org.slf4j.LoggerFactory) ClassLoaderUtil(org.kie.dmn.feel.util.ClassLoaderUtil) HashMap(java.util.HashMap) ResourceType(org.kie.api.io.ResourceType) ArrayList(java.util.ArrayList) KieRuntimeFactory(org.kie.api.runtime.KieRuntimeFactory) DMNModel(org.kie.dmn.api.core.DMNModel) Map(java.util.Map) ResourceTypePackageRegistry(org.drools.core.definitions.ResourceTypePackageRegistry) KieBase(org.kie.api.KieBase) DMNAssemblerService(org.kie.dmn.core.assembler.DMNAssemblerService) DMNProfile(org.kie.dmn.core.compiler.DMNProfile) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) Properties(java.util.Properties) Logger(org.slf4j.Logger) KieBaseModelImpl(org.drools.compiler.kproject.models.KieBaseModelImpl) KieContainer(org.kie.api.runtime.KieContainer) ChainedProperties(org.kie.internal.utils.ChainedProperties) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) Msg(org.kie.dmn.core.util.Msg) Collections(java.util.Collections) HashMap(java.util.HashMap) KieContainerImpl(org.drools.compiler.kie.builder.impl.KieContainerImpl) ChainedProperties(org.kie.internal.utils.ChainedProperties) Stream(java.util.stream.Stream) KieBaseModelImpl(org.drools.compiler.kproject.models.KieBaseModelImpl) Properties(java.util.Properties) ChainedProperties(org.kie.internal.utils.ChainedProperties)

Example 4 with KieContainerImpl

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

the class DMNUpdateTest method test_as_kie_wb_common_services_backend_Builder2.

@Test
public void test_as_kie_wb_common_services_backend_Builder2() 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("v1_2/dmn-hotcold.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(1));
    checkDMNHotColdDMN12WithNSScattered(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(1));
    checkDMNHotColdDMN12WithNSScattered(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 5 with KieContainerImpl

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

the class WBCommonServicesBackendTest method testProfileWithKieWbCommonServicesBackendBuilder.

@Test
public void testProfileWithKieWbCommonServicesBackendBuilder() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0.0");
    final KieModule kieModule = KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("nowGT1970.dmn", this.getClass()));
    final KieContainer kieContainer = ks.newKieContainer(v100);
    final DMNRuntime runtime = KieRuntimeFactory.of(kieContainer.getKieBase()).get(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    check_nowGT1970(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);
    final DMNRuntime runtime2 = KieRuntimeFactory.of(kieContainer2.getKieBase()).get(DMNRuntime.class);
    Assert.assertNotNull(runtime2);
    assertThat(runtime2.getModels(), hasSize(1));
    check_nowGT1970(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) 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)

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