Search in sources :

Example 6 with AbstractRuntimeManager

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);
}
Also used : TaskSummary(org.kie.api.task.model.TaskSummary) Arrays(java.util.Arrays) CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) BoundaryEventNode(org.jbpm.workflow.core.node.BoundaryEventNode) DynamicNode(org.jbpm.workflow.core.node.DynamicNode) StartNode(org.jbpm.workflow.core.node.StartNode) CaseRuntimeDataService(org.jbpm.casemgmt.api.CaseRuntimeDataService) CaseDefinitionComparator(org.jbpm.casemgmt.impl.model.CaseDefinitionComparator) Collectors.toMap(java.util.stream.Collectors.toMap) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) Map(java.util.Map) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KieInternalServices(org.kie.internal.KieInternalServices) AuthorizationManager(org.jbpm.casemgmt.api.auth.AuthorizationManager) CaseMilestoneInstance(org.jbpm.casemgmt.api.model.instance.CaseMilestoneInstance) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Process(org.kie.api.definition.process.Process) FILTER(org.kie.internal.query.QueryParameterIdentifiers.FILTER) Set(java.util.Set) DeploymentRolesManager(org.jbpm.kie.services.impl.security.DeploymentRolesManager) QueryContext(org.kie.api.runtime.query.QueryContext) Collectors(java.util.stream.Collectors) CaseMilestoneInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseMilestoneInstanceImpl) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) CaseFileItem(org.jbpm.casemgmt.api.model.CaseFileItem) List(java.util.List) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) MilestoneNode(org.jbpm.workflow.core.node.MilestoneNode) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ServiceRegistry(org.jbpm.services.api.service.ServiceRegistry) CorrelationKeyFactory(org.kie.internal.process.CorrelationKeyFactory) Status(org.kie.api.task.model.Status) NodeContainer(org.kie.api.definition.process.NodeContainer) AdHocFragmentImpl(org.jbpm.casemgmt.impl.model.AdHocFragmentImpl) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) CaseRoleImpl(org.jbpm.casemgmt.impl.model.CaseRoleImpl) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) HashMap(java.util.HashMap) DeploymentEventListener(org.jbpm.services.api.DeploymentEventListener) TransactionalCommandService(org.jbpm.shared.services.impl.TransactionalCommandService) ArrayList(java.util.ArrayList) ProcessDefinitionComparator(org.jbpm.casemgmt.impl.model.ProcessDefinitionComparator) HashSet(java.util.HashSet) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) DeploymentEvent(org.jbpm.services.api.DeploymentEvent) CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) CaseStageImpl(org.jbpm.casemgmt.impl.model.CaseStageImpl) KieBase(org.kie.api.KieBase) IdentityProvider(org.kie.internal.identity.IdentityProvider) QueryManager(org.jbpm.shared.services.impl.QueryManager) CorrelationKey(org.kie.internal.process.CorrelationKey) QueryNameCommand(org.jbpm.shared.services.impl.commands.QueryNameCommand) CaseIdGenerator(org.jbpm.casemgmt.api.generator.CaseIdGenerator) Collectors.toList(java.util.stream.Collectors.toList) Node(org.kie.api.definition.process.Node) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus) CaseMilestoneImpl(org.jbpm.casemgmt.impl.model.CaseMilestoneImpl) CommonUtils.getAuthenticatedUserRoles(org.jbpm.kie.services.impl.CommonUtils.getAuthenticatedUserRoles) Collections(java.util.Collections) DeployedAsset(org.jbpm.services.api.model.DeployedAsset) CaseMilestone(org.jbpm.casemgmt.api.model.CaseMilestone) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) CaseDefinitionImpl(org.jbpm.casemgmt.impl.model.CaseDefinitionImpl) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) Process(org.kie.api.definition.process.Process) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment) ProcessAssetDesc(org.jbpm.kie.services.impl.model.ProcessAssetDesc) KieBase(org.kie.api.KieBase) CaseRole(org.jbpm.casemgmt.api.model.CaseRole) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess)

Example 7 with AbstractRuntimeManager

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 8 with AbstractRuntimeManager

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 9 with AbstractRuntimeManager

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");
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutionError(org.kie.internal.runtime.error.ExecutionError) TaskService(org.kie.api.task.TaskService) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) EventService(org.kie.internal.task.api.EventService) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 10 with AbstractRuntimeManager

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);
}
Also used : InitialContext(javax.naming.InitialContext) RegistryContext(org.drools.core.command.impl.RegistryContext) Context(org.kie.api.runtime.Context) ProcessInstanceIdContext(org.kie.internal.runtime.manager.context.ProcessInstanceIdContext) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) ArrayList(java.util.ArrayList) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) ProcessNodeTriggeredEvent(org.kie.api.event.process.ProcessNodeTriggeredEvent) KieSession(org.kie.api.runtime.KieSession) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException) Test(org.junit.Test)

Aggregations

AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)18 Test (org.junit.Test)12 KieSession (org.kie.api.runtime.KieSession)12 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)12 ExecutionError (org.kie.internal.runtime.error.ExecutionError)12 ExecutionErrorManager (org.kie.internal.runtime.error.ExecutionErrorManager)12 ExecutionErrorStorage (org.kie.internal.runtime.error.ExecutionErrorStorage)10 HashMap (java.util.HashMap)9 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)9 ArrayList (java.util.ArrayList)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 ExecutorServiceImpl (org.jbpm.executor.impl.ExecutorServiceImpl)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)5 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)5 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)5 QueryContext (org.kie.api.runtime.query.QueryContext)5 TaskService (org.kie.api.task.TaskService)5 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)4 List (java.util.List)3 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)3