Search in sources :

Example 21 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testCustomConstantRequestRetry.

@Test(timeout = 10000)
public void testCustomConstantRequestRetry() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("retryDelay", "2s");
    ctxCMD.setData("retries", 2);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    RequestInfo failedJob = inErrorRequests.get(0);
    assertEquals(3, failedJob.getExecutions());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    // Three retries means 4 executions in total 1(regular) + 2(retries)
    assertEquals(3, errors.size());
    long firstError = errors.get(0).getTime().getTime();
    long secondError = errors.get(1).getTime().getTime();
    long thirdError = errors.get(2).getTime().getTime();
    // time difference between first and second should be at least 3 seconds
    long diff = secondError - firstError;
    assertTrue(diff > 2000);
    // time difference between second and third should be at least 6 seconds
    diff = thirdError - secondError;
    assertTrue(diff > 2000);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) ErrorInfo(org.kie.api.executor.ErrorInfo) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 22 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class BasicExecutorBaseTest method testCustomIncrementingRequestRetry.

@Test(timeout = 10000)
public void testCustomIncrementingRequestRetry() throws InterruptedException {
    CountDownAsyncJobListener countDownListener = configureListener(3);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("retryDelay", "3s, 6s");
    ctxCMD.setData("retries", 2);
    executorService.scheduleRequest("org.jbpm.executor.ThrowExceptionCommand", ctxCMD);
    countDownListener.waitTillCompleted();
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(1, inErrorRequests.size());
    List<ErrorInfo> errors = executorService.getAllErrors(new QueryContext());
    // Three retries means 4 executions in total 1(regular) + 3(retries)
    assertEquals(3, errors.size());
    long firstError = errors.get(0).getTime().getTime();
    long secondError = errors.get(1).getTime().getTime();
    long thirdError = errors.get(2).getTime().getTime();
    // time difference between first and second should be at least 3 seconds
    long diff = secondError - firstError;
    assertTrue(diff > 3000);
    // time difference between second and third should be at least 6 seconds
    diff = thirdError - secondError;
    assertTrue(diff > 6000);
}
Also used : CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) ErrorInfo(org.kie.api.executor.ErrorInfo) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 23 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class JmsAvaiableJobExecutorTest method testAsyncAuditProducerNotExistingDeployment.

@Test
public void testAsyncAuditProducerNotExistingDeployment() throws Exception {
    CountDownAsyncJobListener countDownListener = configureListener(1);
    CommandContext ctxCMD = new CommandContext();
    ctxCMD.setData("businessKey", UUID.randomUUID().toString());
    ctxCMD.setData("deploymentId", "not-existing");
    UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
    ut.begin();
    executorService.scheduleRequest("org.jbpm.executor.commands.PrintOutCommand", ctxCMD);
    ut.commit();
    MessageReceiver receiver = new MessageReceiver();
    receiver.receiveAndProcess(queue, countDownListener, 3000);
    List<RequestInfo> inErrorRequests = executorService.getInErrorRequests(new QueryContext());
    assertEquals(0, inErrorRequests.size());
    List<RequestInfo> queuedRequests = executorService.getQueuedRequests(new QueryContext());
    assertEquals(1, queuedRequests.size());
    List<RequestInfo> executedRequests = executorService.getCompletedRequests(new QueryContext());
    assertEquals(0, executedRequests.size());
}
Also used : UserTransaction(javax.transaction.UserTransaction) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) CommandContext(org.kie.api.executor.CommandContext) QueryContext(org.kie.api.runtime.query.QueryContext) RequestInfo(org.kie.api.executor.RequestInfo) Test(org.junit.Test)

Example 24 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method getAdHocFragmentsForCase.

@Override
public Collection<AdHocFragment> getAdHocFragmentsForCase(String caseId) {
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceByCorrelationKey(correlationKeyFactory.newCorrelationKey(caseId));
    if (pi == null || !pi.getState().equals(ProcessInstance.STATE_ACTIVE)) {
        throw new CaseNotFoundException("No case instance found with id " + caseId + " or it's not active anymore");
    }
    CaseDefinition caseDef = getCase(pi.getDeploymentId(), pi.getProcessId());
    List<AdHocFragment> adHocFragments = new ArrayList<>();
    adHocFragments.addAll(caseDef.getAdHocFragments());
    Collection<CaseStageInstance> activeStages = internalGetCaseStages(caseDef, caseId, true, new QueryContext(0, 100));
    activeStages.forEach(stage -> adHocFragments.addAll(stage.getAdHocFragments()));
    return adHocFragments;
}
Also used : CaseDefinition(org.jbpm.casemgmt.api.model.CaseDefinition) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) CaseNotFoundException(org.jbpm.casemgmt.api.CaseNotFoundException) AdHocFragment(org.jbpm.casemgmt.api.model.AdHocFragment)

Example 25 with QueryContext

use of org.kie.api.runtime.query.QueryContext in project jbpm by kiegroup.

the class CaseRuntimeDataServiceImpl method internalGetCaseStages.

/*
     * Helper methods to parse process and extract case related information
     */
public List<CaseStageInstance> internalGetCaseStages(CaseDefinition caseDef, String caseId, boolean activeOnly, QueryContext queryContext) {
    CorrelationKey correlationKey = correlationKeyFactory.newCorrelationKey(caseId);
    Collection<org.jbpm.services.api.model.NodeInstanceDesc> nodes = runtimeDataService.getNodeInstancesByCorrelationKeyNodeType(correlationKey, Arrays.asList(ProcessInstance.STATE_ACTIVE), Arrays.asList("DynamicNode"), queryContext);
    Collection<Long> completedNodes = nodes.stream().filter(n -> ((NodeInstanceDesc) n).getType() == 1).map(n -> n.getId()).collect(toList());
    Map<String, CaseStage> stagesByName = caseDef.getCaseStages().stream().collect(toMap(CaseStage::getId, c -> c));
    Predicate<org.jbpm.services.api.model.NodeInstanceDesc> filterNodes = null;
    if (activeOnly) {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0 && !completedNodes.contains(((NodeInstanceDesc) n).getId());
    } else {
        filterNodes = n -> ((NodeInstanceDesc) n).getType() == 0;
    }
    List<String> triggeredStages = new ArrayList<>();
    List<CaseStageInstance> stages = new ArrayList<>();
    nodes.stream().filter(filterNodes).map(n -> {
        StageStatus status = StageStatus.Active;
        if (completedNodes.contains(((NodeInstanceDesc) n).getId())) {
            status = StageStatus.Completed;
        }
        Collection<org.jbpm.services.api.model.NodeInstanceDesc> activeNodes = getActiveNodesForCaseAndStage(caseId, n.getNodeId(), new QueryContext(0, 100));
        return new CaseStageInstanceImpl(n.getNodeId(), n.getName(), stagesByName.get(n.getNodeId()).getAdHocFragments(), activeNodes, status);
    }).forEach(csi -> {
        stages.add(csi);
        triggeredStages.add(csi.getName());
    });
    if (!activeOnly) {
        // add other stages that are present in the definition
        caseDef.getCaseStages().stream().filter(cs -> !triggeredStages.contains(cs.getName())).map(cs -> new CaseStageInstanceImpl(cs.getId(), cs.getName(), cs.getAdHocFragments(), Collections.emptyList(), StageStatus.Available)).forEach(csi -> stages.add(csi));
    }
    return stages;
}
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) CaseStage(org.jbpm.casemgmt.api.model.CaseStage) ArrayList(java.util.ArrayList) CaseStageInstance(org.jbpm.casemgmt.api.model.instance.CaseStageInstance) QueryContext(org.kie.api.runtime.query.QueryContext) StageStatus(org.jbpm.casemgmt.api.model.instance.StageStatus) CorrelationKey(org.kie.internal.process.CorrelationKey) Collection(java.util.Collection) NodeInstanceDesc(org.jbpm.kie.services.impl.model.NodeInstanceDesc) CaseStageInstanceImpl(org.jbpm.casemgmt.impl.model.instance.CaseStageInstanceImpl)

Aggregations

QueryContext (org.kie.api.runtime.query.QueryContext)315 Test (org.junit.Test)299 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)131 HashMap (java.util.HashMap)115 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)109 ArrayList (java.util.ArrayList)99 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)67 RequestInfo (org.kie.api.executor.RequestInfo)53 TaskSummary (org.kie.api.task.model.TaskSummary)53 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)51 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)49 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)45 CommandContext (org.kie.api.executor.CommandContext)39 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)37 UserImpl (org.jbpm.services.task.impl.model.UserImpl)37 OrganizationalEntity (org.kie.api.task.model.OrganizationalEntity)36 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)34 QueryFilter (org.kie.internal.query.QueryFilter)30 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)29 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)29