Search in sources :

Example 66 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class KModuleDeploymentServiceTest method testDeploymentOfProcessWithDescriptor.

@Test
public void testDeploymentOfProcessWithDescriptor() {
    assertNotNull(deploymentService);
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/customtask.bpmn");
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/general/import.bpmn");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_REQUEST).addWorkItemHandler(new NamedObjectModel("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler"));
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, pom);
    DeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployedGeneral);
    assertNotNull(deployedGeneral.getDeploymentUnit());
    assertNotNull(deployedGeneral.getRuntimeManager());
    DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor();
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_REQUEST, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(1, descriptor.getWorkItemHandlers().size());
    assertEquals(0, descriptor.getRequiredRoles().size());
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    manager.disposeRuntimeEngine(engine);
    checkFormsDeployment(deploymentUnit.getIdentifier());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) DeploymentUnit(org.jbpm.services.api.model.DeploymentUnit) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 67 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class KModuleDeploymentServiceTest method testDeploymentAvoidEmptyDescriptorOverride.

@Test
public void testDeploymentAvoidEmptyDescriptorOverride() {
    assertNotNull(deploymentService);
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId(GROUP_ID, "kjar-with-dd", VERSION);
    List<String> processes = new ArrayList<String>();
    processes.add("repo/processes/general/customtask.bpmn");
    processes.add("repo/processes/general/humanTask.bpmn");
    processes.add("repo/processes/general/import.bpmn");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_REQUEST).addWorkItemHandler(new NamedObjectModel("Log", "org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler"));
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, processes, resources);
    File pom = new File("target/kmodule", "pom.xml");
    pom.getParentFile().mkdir();
    try {
        FileOutputStream fs = new FileOutputStream(pom);
        fs.write(getPom(releaseId).getBytes());
        fs.close();
    } catch (Exception e) {
    }
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, pom);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, "kjar-with-dd", VERSION, "KBase-test", "ksession-test2");
    // let's simulate change of deployment descriptor on deploy time
    // set empty one...
    deploymentUnit.setDeploymentDescriptor(new DeploymentDescriptorImpl());
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployedGeneral = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployedGeneral);
    assertNotNull(deployedGeneral.getDeploymentUnit());
    assertNotNull(deployedGeneral.getRuntimeManager());
    DeploymentDescriptor descriptor = ((InternalRuntimeManager) deployedGeneral.getRuntimeManager()).getDeploymentDescriptor();
    assertNotNull(descriptor);
    assertEquals("org.jbpm.domain", descriptor.getPersistenceUnit());
    assertEquals("org.jbpm.domain", descriptor.getAuditPersistenceUnit());
    assertEquals(AuditMode.JPA, descriptor.getAuditMode());
    assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
    assertEquals(RuntimeStrategy.PER_REQUEST, descriptor.getRuntimeStrategy());
    assertEquals(0, descriptor.getMarshallingStrategies().size());
    assertEquals(0, descriptor.getConfiguration().size());
    assertEquals(0, descriptor.getEnvironmentEntries().size());
    assertEquals(0, descriptor.getEventListeners().size());
    assertEquals(0, descriptor.getGlobals().size());
    assertEquals(0, descriptor.getTaskEventListeners().size());
    assertEquals(1, descriptor.getWorkItemHandlers().size());
    assertEquals(0, descriptor.getRequiredRoles().size());
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance processInstance = engine.getKieSession().startProcess("customtask", params);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
    manager.disposeRuntimeEngine(engine);
    checkFormsDeployment(deploymentUnit.getIdentifier());
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ArrayList(java.util.ArrayList) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) FileOutputStream(java.io.FileOutputStream) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) File(java.io.File) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 68 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class KModuleWithDependenciesDeploymentServiceTest method testDeploymentOfProcesses.

@Test
public void testDeploymentOfProcesses() throws Exception {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION, "defaultKieBase", "defaultKieSession");
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeployedUnit deployed = deploymentService.getDeployedUnit(deploymentUnit.getIdentifier());
    assertNotNull(deployed);
    assertNotNull(deployed.getDeploymentUnit());
    assertNotNull(deployed.getRuntimeManager());
    assertEquals("org.jbpm.test:jbpm-module:1.0.0:defaultKieBase:defaultKieSession", deployed.getDeploymentUnit().getIdentifier());
    assertTrue(deployed instanceof DeployedUnitImpl);
    assertEquals(2, ((DeployedUnitImpl) deployed).getDeployedClasses().size());
    List<String> classnames = new ArrayList<String>();
    for (Class<?> clazz : ((DeployedUnitImpl) deployed).getDeployedClasses()) {
        classnames.add(clazz.getName());
    }
    assertTrue(classnames.contains("org.jbpm.data.rest.CustomDataObject"));
    assertTrue(classnames.contains("org.jbpm.test.Person"));
    assertNotNull(runtimeDataService);
    Collection<ProcessDefinition> processes = runtimeDataService.getProcesses(new QueryContext());
    assertNotNull(processes);
    assertEquals(1, processes.size());
    RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnit.getIdentifier());
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(EmptyContext.get());
    assertNotNull(engine);
    Class<?> clazz = Class.forName("org.jbpm.test.Person", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    Object instance = clazz.newInstance();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("person", instance);
    ProcessInstance processInstance = engine.getKieSession().startProcess("testkjar.src.main.resources.process", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    List<TaskSummary> tasks = engine.getTaskService().getTasksOwned("salaboy", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    Map<String, Object> content = ((InternalTaskService) engine.getTaskService()).getTaskContent(taskId);
    assertTrue(content.containsKey("personIn"));
    Object person = content.get("personIn");
    assertEquals(clazz.getName(), person.getClass().getName());
    engine.getTaskService().start(taskId, "salaboy");
    Map<String, Object> data = new HashMap<String, Object>();
    data.put("personOut", instance);
    engine.getTaskService().complete(taskId, "salaboy", data);
    processInstance = engine.getKieSession().getProcessInstance(processInstance.getId());
    assertNull(processInstance);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) ArrayList(java.util.ArrayList) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) InternalTaskService(org.kie.internal.task.api.InternalTaskService) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeployedUnitImpl(org.jbpm.kie.services.impl.DeployedUnitImpl) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 69 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager in project jbpm by kiegroup.

the class InjectableRegisterableItemsFactory method getGlobals.

@Override
public Map<String, Object> getGlobals(RuntimeEngine runtime) {
    Map<String, Object> globals = new HashMap<String, Object>();
    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());
    }
    try {
        for (GlobalProducer producer : globalProducer) {
            globals.putAll(producer.getGlobals(manager.getIdentifier(), parameters));
        }
    } catch (Exception e) {
        // do nothing as work item handler is considered optional
        logger.warn("Exception while evalutating globals prodcuers {}", e.getMessage());
    }
    // add globals from descriptor
    globals.putAll(getGlobalsFromDescriptor(runtime));
    return globals;
}
Also used : GlobalProducer(org.kie.internal.runtime.manager.GlobalProducer) HashMap(java.util.HashMap) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) RuntimeEngineImpl(org.jbpm.runtime.manager.impl.RuntimeEngineImpl) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException) IOException(java.io.IOException)

Example 70 with RuntimeManager

use of org.kie.api.runtime.manager.RuntimeManager 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)

Aggregations

RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)150 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)116 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)79 KieSession (org.kie.api.runtime.KieSession)55 TaskService (org.kie.api.task.TaskService)53 Test (org.junit.Test)51 HashMap (java.util.HashMap)49 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)46 InternalTaskService (org.kie.internal.task.api.InternalTaskService)44 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)38 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)35 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)23 TaskSummary (org.kie.api.task.model.TaskSummary)21 ArrayList (java.util.ArrayList)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)19 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)18 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)15 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)15 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)15