Search in sources :

Example 46 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class FoxJobRetryCmdTest method assertJobRetriesForActivity.

protected void assertJobRetriesForActivity(ProcessInstance pi, String activityId) {
    assertNotNull(pi);
    waitForExecutedJobWithRetriesLeft(4);
    stillOneJobWithExceptionAndRetriesLeft();
    Job job = fetchJob(pi.getProcessInstanceId());
    assertNotNull(job);
    assertEquals(pi.getProcessInstanceId(), job.getProcessInstanceId());
    assertEquals(4, job.getRetries());
    ExecutionEntity execution = fetchExecutionEntity(pi.getProcessInstanceId(), activityId);
    assertNotNull(execution);
    waitForExecutedJobWithRetriesLeft(3);
    job = refreshJob(job.getId());
    assertEquals(3, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(2);
    job = refreshJob(job.getId());
    assertEquals(2, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(1);
    job = refreshJob(job.getId());
    assertEquals(1, job.getRetries());
    stillOneJobWithExceptionAndRetriesLeft();
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
    waitForExecutedJobWithRetriesLeft(0);
    job = refreshJob(job.getId());
    assertEquals(0, job.getRetries());
    assertEquals(1, managementService.createJobQuery().withException().count());
    assertEquals(0, managementService.createJobQuery().withRetriesLeft().count());
    assertEquals(1, managementService.createJobQuery().noRetriesLeft().count());
    execution = refreshExecutionEntity(execution.getId());
    assertEquals(activityId, execution.getActivityId());
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) Job(org.camunda.bpm.engine.runtime.Job)

Example 47 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class JobDeclaration method createJobInstance.

// Job instance factory //////////////////////////////////////////
/**
 * @return the created Job instances
 */
public T createJobInstance(S context) {
    T job = newJobInstance(context);
    // set job definition id
    String jobDefinitionId = resolveJobDefinitionId(context);
    job.setJobDefinitionId(jobDefinitionId);
    if (jobDefinitionId != null) {
        JobDefinitionEntity jobDefinition = Context.getCommandContext().getJobDefinitionManager().findById(jobDefinitionId);
        if (jobDefinition != null) {
            // if job definition is suspended while creating a job instance,
            // suspend the job instance right away:
            job.setSuspensionState(jobDefinition.getSuspensionState());
            job.setProcessDefinitionKey(jobDefinition.getProcessDefinitionKey());
            job.setProcessDefinitionId(jobDefinition.getProcessDefinitionId());
            job.setTenantId(jobDefinition.getTenantId());
        }
    }
    job.setJobHandlerConfiguration(resolveJobHandlerConfiguration(context));
    job.setJobHandlerType(resolveJobHandlerType(context));
    job.setExclusive(resolveExclusive(context));
    job.setRetries(resolveRetries(context));
    job.setDuedate(resolveDueDate(context));
    // contentExecution can be null in case of a timer start event or
    // and batch jobs unrelated to executions
    ExecutionEntity contextExecution = resolveExecution(context);
    if (Context.getProcessEngineConfiguration().isProducePrioritizedJobs()) {
        long priority = Context.getProcessEngineConfiguration().getJobPriorityProvider().determinePriority(contextExecution, this, jobDefinitionId);
        job.setPriority(priority);
    }
    if (contextExecution != null) {
        // in case of shared process definitions, the job definitions have no tenant id.
        // To distinguish jobs between tenants and enable the tenant check for the job executor,
        // use the tenant id from the execution.
        job.setTenantId(contextExecution.getTenantId());
    }
    postInitialize(context, job);
    return job;
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)

Example 48 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class MigratingTransitionInstance method detachState.

@Override
public void detachState() {
    jobInstance.detachState();
    for (MigratingInstance dependentInstance : migratingDependentInstances) {
        dependentInstance.detachState();
    }
    ExecutionEntity execution = resolveRepresentativeExecution();
    execution.setActive(false);
    getParent().destroyAttachableExecution(execution);
    setParent(null);
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)

Example 49 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class ActivityInstanceHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, ActivityInstance element) {
    MigratingActivityInstance migratingInstance = null;
    MigrationInstruction applyingInstruction = parseContext.getInstructionFor(element.getActivityId());
    ScopeImpl sourceScope = null;
    ScopeImpl targetScope = null;
    ExecutionEntity representativeExecution = parseContext.getMapping().getExecution(element);
    if (element.getId().equals(element.getProcessInstanceId())) {
        sourceScope = parseContext.getSourceProcessDefinition();
        targetScope = parseContext.getTargetProcessDefinition();
    } else {
        sourceScope = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
        if (applyingInstruction != null) {
            String activityId = applyingInstruction.getTargetActivityId();
            targetScope = parseContext.getTargetProcessDefinition().findActivity(activityId);
        }
    }
    migratingInstance = parseContext.getMigratingProcessInstance().addActivityInstance(applyingInstruction, element, sourceScope, targetScope, representativeExecution);
    MigratingActivityInstance parentInstance = parseContext.getMigratingActivityInstanceById(element.getParentActivityInstanceId());
    if (parentInstance != null) {
        migratingInstance.setParent(parentInstance);
    }
    CoreActivityBehavior<?> sourceActivityBehavior = sourceScope.getActivityBehavior();
    if (sourceActivityBehavior instanceof MigrationObserverBehavior) {
        ((MigrationObserverBehavior) sourceActivityBehavior).onParseMigratingInstance(parseContext, migratingInstance);
    }
    parseContext.submit(migratingInstance);
    parseTransitionInstances(parseContext, migratingInstance);
    parseDependentInstances(parseContext, migratingInstance);
}
Also used : ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigrationObserverBehavior(org.camunda.bpm.engine.impl.pvm.delegate.MigrationObserverBehavior) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ScopeImpl(org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)

Example 50 with ExecutionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity in project camunda-bpm-platform by camunda.

the class CompensationInstanceHandler method createMigratingEventScopeInstance.

protected MigratingProcessElementInstance createMigratingEventScopeInstance(MigratingInstanceParseContext parseContext, EventSubscriptionEntity element) {
    ActivityImpl compensatingActivity = parseContext.getSourceProcessDefinition().findActivity(element.getActivityId());
    MigrationInstruction migrationInstruction = getMigrationInstruction(parseContext, compensatingActivity);
    ActivityImpl eventSubscriptionTargetScope = null;
    if (migrationInstruction != null) {
        if (compensatingActivity.isCompensationHandler()) {
            ActivityImpl targetEventScope = (ActivityImpl) parseContext.getTargetActivity(migrationInstruction).getEventScope();
            eventSubscriptionTargetScope = targetEventScope.findCompensationHandler();
        } else {
            eventSubscriptionTargetScope = parseContext.getTargetActivity(migrationInstruction);
        }
    }
    ExecutionEntity eventScopeExecution = CompensationUtil.getCompensatingExecution(element);
    MigrationInstruction eventScopeInstruction = parseContext.findSingleMigrationInstruction(eventScopeExecution.getActivityId());
    ActivityImpl targetScope = parseContext.getTargetActivity(eventScopeInstruction);
    MigratingEventScopeInstance migratingCompensationInstance = parseContext.getMigratingProcessInstance().addEventScopeInstance(eventScopeInstruction, eventScopeExecution, eventScopeExecution.getActivity(), targetScope, migrationInstruction, element, compensatingActivity, eventSubscriptionTargetScope);
    parseContext.consume(element);
    parseContext.submit(migratingCompensationInstance);
    parseDependentEntities(parseContext, migratingCompensationInstance);
    return migratingCompensationInstance;
}
Also used : ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigratingEventScopeInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingEventScopeInstance)

Aggregations

ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)170 Deployment (org.camunda.bpm.engine.test.Deployment)42 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)18 TaskEntity (org.camunda.bpm.engine.impl.persistence.entity.TaskEntity)17 CaseExecutionEntity (org.camunda.bpm.engine.impl.cmmn.entity.runtime.CaseExecutionEntity)16 Execution (org.camunda.bpm.engine.runtime.Execution)14 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)13 ActivityImpl (org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)12 Task (org.camunda.bpm.engine.task.Task)12 ScopeImpl (org.camunda.bpm.engine.impl.pvm.process.ScopeImpl)10 ArrayList (java.util.ArrayList)9 VariableInstanceEntity (org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity)9 Test (org.junit.Test)9 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)7 EventSubscriptionEntity (org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity)7 PvmExecutionImpl (org.camunda.bpm.engine.impl.pvm.runtime.PvmExecutionImpl)7 ProcessDefinitionImpl (org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl)6 ActivityInstance (org.camunda.bpm.engine.runtime.ActivityInstance)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5