use of org.jbpm.runtime.manager.impl.AbstractRuntimeManager in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImpl method onDeploy.
/*
* Deploy and undeploy handling
*/
@Override
public void onDeploy(DeploymentEvent event) {
AbstractRuntimeManager runtimeManager = (AbstractRuntimeManager) event.getDeployedUnit().getRuntimeManager();
KieBase kieBase = runtimeManager.getEnvironment().getKieBase();
Collection<Process> processes = kieBase.getProcesses();
Map<String, DeployedAsset> mapProcessById = event.getDeployedUnit().getDeployedAssets().stream().collect(toMap(DeployedAsset::getId, asset -> asset));
for (Process process : processes) {
if (((WorkflowProcess) process).isDynamic()) {
String caseIdPrefix = collectCaseIdPrefix(process);
Collection<CaseMilestone> caseMilestones = collectMilestoness(process);
Collection<CaseStage> caseStages = collectCaseStages(event.getDeploymentId(), process.getId(), ((WorkflowProcess) process));
Collection<CaseRole> caseRoles = collectCaseRoles(process);
Collection<AdHocFragment> adHocFragments = collectAdHocFragments((WorkflowProcess) process);
Map<String, List<String>> dataAccessRestrictions = collectDataAccessRestrictions(process);
CaseDefinitionImpl caseDef = new CaseDefinitionImpl((ProcessAssetDesc) mapProcessById.get(process.getId()), caseIdPrefix, caseStages, caseMilestones, caseRoles, adHocFragments, dataAccessRestrictions);
availableCases.add(caseDef);
caseIdGenerator.register(caseIdPrefix);
}
}
// collect role information
Collection<DeployedAsset> assets = event.getDeployedUnit().getDeployedAssets();
List<String> roles = null;
for (DeployedAsset asset : assets) {
if (asset instanceof ProcessAssetDesc) {
// if it's not dynamic it's considered as not case definition
if (!((ProcessAssetDesc) asset).isDynamic()) {
availableProcesses.add((ProcessAssetDesc) asset);
}
if (roles == null) {
roles = ((ProcessAssetDesc) asset).getRoles();
}
}
}
if (roles == null) {
roles = Collections.emptyList();
}
deploymentRolesManager.addRolesForDeployment(event.getDeploymentId(), roles);
}
use of org.jbpm.runtime.manager.impl.AbstractRuntimeManager in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testScriptFailureAfterUserTask.
@Test
public void testScriptFailureAfterUserTask() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ProcessInstance pi = ksession1.startProcess("UserTaskWithRollback");
manager.disposeRuntimeEngine(runtime1);
runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi.getId()));
ksession1 = runtime1.getKieSession();
TaskService taskService = runtime1.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
Map<String, Object> results = new HashMap<>();
results.put("output1", "rollback");
try {
taskService.complete(taskId, "john", results);
fail("Complete task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime1);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(1, errors.size());
assertExecutionError(errors.get(0), "Process", "UserTaskWithRollback", "Script Task 1");
}
use of org.jbpm.runtime.manager.impl.AbstractRuntimeManager in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testDataBaseFailureInMemoryStorage.
@Test
public void testDataBaseFailureInMemoryStorage() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.addEventListener(new DefaultProcessEventListener() {
@Override
public void afterProcessStarted(ProcessStartedEvent event) {
pds.close();
}
});
try {
ksession1.startProcess("UserTaskWithRollback");
fail("Start process should fail due to data base error");
} catch (Throwable e) {
// expected
}
int expectedErrors = 1;
try {
manager.disposeRuntimeEngine(runtime1);
} catch (Exception e) {
// expected to fail for some strategies due to data source being down
expectedErrors++;
}
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(expectedErrors, errors.size());
assertExecutionError(errors.get(0), "DB", "UserTaskWithRollback", "Hello");
}
use of org.jbpm.runtime.manager.impl.AbstractRuntimeManager in project jbpm by kiegroup.
the class ExecutionErrorHandlingRuntimeManagerTest method testUserTaskFailure.
@SuppressWarnings("unchecked")
@Test
public void testUserTaskFailure() {
RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession1 = runtime1.getKieSession();
assertNotNull(ksession1);
ksession1.startProcess("UserTaskWithRollback");
TaskService taskService = runtime1.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
try {
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskStartedEvent(TaskEvent event) {
throw new TaskExecutionException("On purpose");
}
});
taskService.start(taskId, "john");
fail("Start task should fail due to broken script");
} catch (Throwable e) {
// expected
}
manager.disposeRuntimeEngine(runtime1);
ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
ExecutionErrorStorage storage = errorManager.getStorage();
List<ExecutionError> errors = storage.list(0, 10);
assertNotNull(errors);
assertEquals(1, errors.size());
assertExecutionError(errors.get(0), "Task", "UserTaskWithRollback", "Hello");
}
use of org.jbpm.runtime.manager.impl.AbstractRuntimeManager in project jbpm by kiegroup.
the class GlobalTimerServiceBaseTest method testTimerFailureAndRetrigger.
@Test(timeout = 20000)
public void testTimerFailureAndRetrigger() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Timer_1m", 3);
final List<Long> timerExporations = new ArrayList<Long>();
ProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
if (event.getNodeInstance().getNodeName().equals("Timer_1m")) {
timerExporations.add(event.getNodeInstance().getId());
}
}
};
environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("org/jbpm/test/functional/timer/helloretrigger.bpmn2"), ResourceType.BPMN2).schedulerService(globalScheduler).registerableItemsFactory(new TestRegisterableItemsFactory(listener, countDownListener)).get();
manager = getManager(environment, false);
RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
KieSession ksession = runtime.getKieSession();
Map<String, Object> params = new HashMap<>();
ProcessInstance pi = ksession.startProcess("rescheduletimer.helloretrigger", params);
assertEquals("Process instance should be active", ProcessInstance.STATE_ACTIVE, pi.getState());
manager.disposeRuntimeEngine(runtime);
final long processInstanceId = pi.getId();
// let the timer (every 2 sec) fire three times as third will fail on gateway
countDownListener.waitTillCompleted(8000);
assertEquals("There should be only 3 nodes as there third is failing", 3, timerExporations.size());
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
ksession = runtime.getKieSession();
ksession.execute(new ExecutableCommand<Void>() {
@Override
public Void execute(Context context) {
KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
ProcessInstance pi = (ProcessInstance) ksession.getProcessInstance(processInstanceId);
((WorkflowProcessInstance) pi).setVariable("fixed", true);
return null;
}
});
manager.disposeRuntimeEngine(runtime);
countDownListener.reset(1);
countDownListener.waitTillCompleted(5000);
assertEquals("There should be 3 expirations as the failing one should finally proceed", 3, timerExporations.size());
try {
runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
ksession = runtime.getKieSession();
pi = ksession.getProcessInstance(processInstanceId);
assertNull(pi);
} catch (SessionNotFoundException e) {
// expected for PerProcessInstanceManagers since process instance is completed
}
((AbstractRuntimeManager) manager).close(true);
}
Aggregations