Search in sources :

Example 6 with JobDefinitionEntity

use of org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity 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 7 with JobDefinitionEntity

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

the class IncidentInstanceHandler method handleFailedJobIncident.

protected void handleFailedJobIncident(MigratingInstanceParseContext parseContext, IncidentEntity incident) {
    MigratingJobInstance owningInstance = parseContext.getMigratingJobInstanceById(incident.getConfiguration());
    if (owningInstance != null) {
        parseContext.consume(incident);
        if (owningInstance.migrates()) {
            MigratingIncident migratingIncident = new MigratingIncident(incident, owningInstance.getTargetScope());
            JobDefinitionEntity targetJobDefinitionEntity = owningInstance.getTargetJobDefinitionEntity();
            if (targetJobDefinitionEntity != null) {
                migratingIncident.setTargetJobDefinitionId(targetJobDefinitionEntity.getId());
            }
            owningInstance.addMigratingDependentInstance(migratingIncident);
        }
    }
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) MigratingIncident(org.camunda.bpm.engine.impl.migration.instance.MigratingIncident) MigratingJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingJobInstance)

Example 8 with JobDefinitionEntity

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

the class ActivityInstanceJobHandler method handle.

@Override
public void handle(MigratingInstanceParseContext parseContext, MigratingActivityInstance activityInstance, List<JobEntity> elements) {
    Map<String, TimerDeclarationImpl> timerDeclarationsInEventScope = getTimerDeclarationsByTriggeringActivity(activityInstance.getTargetScope());
    for (JobEntity job : elements) {
        if (!isTimerJob(job)) {
            // skip non timer jobs
            continue;
        }
        MigrationInstruction migrationInstruction = parseContext.findSingleMigrationInstruction(job.getActivityId());
        ActivityImpl targetActivity = parseContext.getTargetActivity(migrationInstruction);
        if (targetActivity != null && activityInstance.migratesTo(targetActivity.getEventScope())) {
            // the timer job is migrated
            JobDefinitionEntity targetJobDefinitionEntity = parseContext.getTargetJobDefinition(targetActivity.getActivityId(), job.getJobHandlerType());
            TimerDeclarationImpl targetTimerDeclaration = timerDeclarationsInEventScope.remove(targetActivity.getId());
            MigratingJobInstance migratingTimerJobInstance = new MigratingTimerJobInstance(job, targetJobDefinitionEntity, targetActivity, migrationInstruction.isUpdateEventTrigger(), targetTimerDeclaration);
            activityInstance.addMigratingDependentInstance(migratingTimerJobInstance);
            parseContext.submit(migratingTimerJobInstance);
        } else {
            // the timer job is removed
            MigratingJobInstance removingJobInstance = new MigratingTimerJobInstance(job);
            activityInstance.addRemovingDependentInstance(removingJobInstance);
            parseContext.submit(removingJobInstance);
        }
        parseContext.consume(job);
    }
    if (activityInstance.migrates()) {
        addEmergingTimerJobs(activityInstance, timerDeclarationsInEventScope.values());
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) TimerDeclarationImpl(org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl) MigrationInstruction(org.camunda.bpm.engine.migration.MigrationInstruction) MigratingJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingJobInstance) MigratingTimerJobInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingTimerJobInstance)

Example 9 with JobDefinitionEntity

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

the class MigratingInstanceParser method parse.

public MigratingProcessInstance parse(String processInstanceId, MigrationPlan migrationPlan, MigratingProcessInstanceValidationReportImpl processInstanceReport) {
    CommandContext commandContext = Context.getCommandContext();
    List<EventSubscriptionEntity> eventSubscriptions = fetchEventSubscriptions(commandContext, processInstanceId);
    List<ExecutionEntity> executions = fetchExecutions(commandContext, processInstanceId);
    List<ExternalTaskEntity> externalTasks = fetchExternalTasks(commandContext, processInstanceId);
    List<IncidentEntity> incidents = fetchIncidents(commandContext, processInstanceId);
    List<JobEntity> jobs = fetchJobs(commandContext, processInstanceId);
    List<TaskEntity> tasks = fetchTasks(commandContext, processInstanceId);
    List<VariableInstanceEntity> variables = fetchVariables(commandContext, processInstanceId);
    ExecutionEntity processInstance = commandContext.getExecutionManager().findExecutionById(processInstanceId);
    processInstance.restoreProcessInstance(executions, eventSubscriptions, variables, tasks, jobs, incidents, externalTasks);
    ProcessDefinitionEntity targetProcessDefinition = Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedProcessDefinitionById(migrationPlan.getTargetProcessDefinitionId());
    List<JobDefinitionEntity> targetJobDefinitions = fetchJobDefinitions(commandContext, targetProcessDefinition.getId());
    final MigratingInstanceParseContext parseContext = new MigratingInstanceParseContext(this, migrationPlan, processInstance, targetProcessDefinition).eventSubscriptions(eventSubscriptions).externalTasks(externalTasks).incidents(incidents).jobs(jobs).tasks(tasks).targetJobDefinitions(targetJobDefinitions).variables(variables);
    ActivityInstance activityInstance = engine.getRuntimeService().getActivityInstance(processInstanceId);
    ActivityInstanceWalker activityInstanceWalker = new ActivityInstanceWalker(activityInstance);
    activityInstanceWalker.addPreVisitor(new TreeVisitor<ActivityInstance>() {

        @Override
        public void visit(ActivityInstance obj) {
            activityInstanceHandler.handle(parseContext, obj);
        }
    });
    activityInstanceWalker.walkWhile();
    CompensationEventSubscriptionWalker compensateSubscriptionsWalker = new CompensationEventSubscriptionWalker(parseContext.getMigratingActivityInstances());
    compensateSubscriptionsWalker.addPreVisitor(new TreeVisitor<EventSubscriptionEntity>() {

        @Override
        public void visit(EventSubscriptionEntity obj) {
            compensationInstanceHandler.handle(parseContext, obj);
        }
    });
    compensateSubscriptionsWalker.walkWhile();
    for (IncidentEntity incidentEntity : incidents) {
        incidentHandler.handle(parseContext, incidentEntity);
    }
    parseContext.validateNoEntitiesLeft(processInstanceReport);
    return parseContext.getMigratingProcessInstance();
}
Also used : ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) TaskEntity(org.camunda.bpm.engine.impl.persistence.entity.TaskEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) MigratingActivityInstance(org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance) ActivityInstance(org.camunda.bpm.engine.runtime.ActivityInstance) VariableInstanceEntity(org.camunda.bpm.engine.impl.persistence.entity.VariableInstanceEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) EventSubscriptionEntity(org.camunda.bpm.engine.impl.persistence.entity.EventSubscriptionEntity) IncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity) ExternalTaskEntity(org.camunda.bpm.engine.impl.persistence.entity.ExternalTaskEntity) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)

Example 10 with JobDefinitionEntity

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

the class BatchEntity method createMonitorJobDefinition.

public JobDefinitionEntity createMonitorJobDefinition() {
    monitorJobDefinition = new JobDefinitionEntity(BATCH_MONITOR_JOB_DECLARATION);
    monitorJobDefinition.setJobConfiguration(id);
    monitorJobDefinition.setTenantId(tenantId);
    Context.getCommandContext().getJobDefinitionManager().insert(monitorJobDefinition);
    monitorJobDefinitionId = monitorJobDefinition.getId();
    return monitorJobDefinition;
}
Also used : JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)

Aggregations

JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)16 JobDefinitionManager (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)5 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)5 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)3 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)3 MigratingJobInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingJobInstance)2 IncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity)2 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)2 PropertyChange (org.camunda.bpm.engine.impl.persistence.entity.PropertyChange)2 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 ParameterValueProvider (org.camunda.bpm.engine.impl.core.variable.mapping.value.ParameterValueProvider)1 HistoryLevel (org.camunda.bpm.engine.impl.history.HistoryLevel)1 HistoryEvent (org.camunda.bpm.engine.impl.history.event.HistoryEvent)1 HistoryEventProcessor (org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor)1 HistoryEventProducer (org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer)1 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)1 TimerDeclarationImpl (org.camunda.bpm.engine.impl.jobexecutor.TimerDeclarationImpl)1 MigratingActivityInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingActivityInstance)1 MigratingAsyncJobInstance (org.camunda.bpm.engine.impl.migration.instance.MigratingAsyncJobInstance)1