Search in sources :

Example 26 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class ProcessServiceImpl method setProcessVariables.

@Override
public void setProcessVariables(String deploymentId, Long processInstanceId, Map<String, Object> variables) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    variables = process(variables, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        ProcessInstance pi = ksession.getProcessInstance(processInstanceId);
        if (pi == null) {
            throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found");
        }
        ksession.execute(new SetProcessInstanceVariablesCommand(processInstanceId, variables));
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) SetProcessInstanceVariablesCommand(org.drools.core.command.runtime.process.SetProcessInstanceVariablesCommand) KieSession(org.kie.api.runtime.KieSession) RuleFlowProcessInstance(org.jbpm.ruleflow.instance.RuleFlowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 27 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class MultipleDeploymentsProcessServiceEJBIntegrationTest method testStartProcessFromDifferentDeployments.

@Test
public void testStartProcessFromDifferentDeployments() {
    assertNotNull(deploymentService);
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentUnit.setDeploymentDescriptor(customDescriptor);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    DeploymentDescriptor customDescriptor2 = new DeploymentDescriptorImpl("org.jbpm.domain");
    customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE);
    KModuleDeploymentUnit deploymentUnit2 = new KModuleDeploymentUnit(GROUP_ID2, ARTIFACT_ID2, VERSION2);
    deploymentUnit2.setDeploymentDescriptor(customDescriptor2);
    deploymentService.deploy(deploymentUnit2);
    units.add(deploymentUnit2);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    isDeployed = deploymentService.isDeployed(deploymentUnit2.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    // first process from deployment 1
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "Import");
    assertNotNull(processInstanceId);
    try {
        ProcessInstance pi = processService.getProcessInstance(processInstanceId);
        assertNull(pi);
    } catch (EJBException e) {
        if (e.getCause() instanceof SessionNotFoundException) {
        // ignore as this is expected when per process instance is used
        } else {
            throw e;
        }
    }
    // second process from deployment 2
    long processInstanceId2 = processService.startProcess(deploymentUnit2.getIdentifier(), "customtask");
    assertNotNull(processInstanceId2);
    try {
        ProcessInstance pi2 = processService.getProcessInstance(processInstanceId2);
        assertNull(pi2);
    } catch (EJBException e) {
        if (e.getCause() instanceof SessionNotFoundException) {
        // ignore as this is expected when per process instance is used
        } else {
            throw e;
        }
    }
}
Also used : DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) EJBException(javax.ejb.EJBException) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Example 28 with SessionNotFoundException

use of org.kie.internal.runtime.manager.SessionNotFoundException in project jbpm by kiegroup.

the class TimerInitFailureRuntimeManagerTest method testPerProcessInstanceRuntimeManager.

@Test(timeout = 15000)
@BMScript(value = "byteman-scripts/failOnRuntimeManagerInitRules.btm")
public void testPerProcessInstanceRuntimeManager() throws Exception {
    final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Intermediate Catch Event 1", 1);
    RuntimeEnvironment environment = createEnvironment(countDownListener);
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment, "first");
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<>();
    ProcessInstance pi = ksession.startProcess("TimerInitFailure", params);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
    manager.disposeRuntimeEngine(runtime);
    countDownListener.waitTillCompleted();
    // User access
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi.getId()));
    runtime.getKieSession();
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, list.size());
    long taskId = list.get(0).getId();
    taskService.start(taskId, "john");
    taskService.complete(taskId, "john", null);
    manager.disposeRuntimeEngine(runtime);
    try {
        runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi.getId()));
        runtime.getKieSession();
        fail("ProcessInstance should already be completed");
    } catch (SessionNotFoundException e) {
    // expected
    }
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)28 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)27 KieSession (org.kie.api.runtime.KieSession)25 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)15 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)14 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)13 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)13 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)8 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)7 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)6 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)6 HashMap (java.util.HashMap)5 ProcessNodeLeftEvent (org.kie.api.event.process.ProcessNodeLeftEvent)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 WorkItem (org.kie.api.runtime.process.WorkItem)4 Properties (java.util.Properties)3