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;
}
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);
}
}
}
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());
}
}
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();
}
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;
}
Aggregations