Search in sources :

Example 1 with JobEntity

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

the class DefaultJobRetryCmd method execute.

public Object execute(CommandContext commandContext) {
    JobEntity job = getJob();
    ActivityImpl activity = getCurrentActivity(commandContext, job);
    if (activity == null) {
        LOG.debugFallbackToDefaultRetryStrategy();
        executeStandardStrategy(commandContext);
    } else {
        try {
            executeCustomStrategy(commandContext, job, activity);
        } catch (Exception e) {
            LOG.debugFallbackToDefaultRetryStrategy();
            executeStandardStrategy(commandContext);
        }
    }
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) ActivityImpl(org.camunda.bpm.engine.impl.pvm.process.ActivityImpl)

Example 2 with JobEntity

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

the class DeleteJobCmd method execute.

public Object execute(CommandContext commandContext) {
    ensureNotNull("jobId", jobId);
    JobEntity job = commandContext.getJobManager().findJobById(jobId);
    ensureNotNull("No job found with id '" + jobId + "'", "job", job);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkUpdateJob(job);
    }
    // In that case, we can't allow to delete the job.
    if (job.getLockOwner() != null || job.getLockExpirationTime() != null) {
        throw new ProcessEngineException("Cannot delete job when the job is being executed. Try again later.");
    }
    job.delete();
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 3 with JobEntity

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

the class AbstractSetJobRetriesCmd method setJobRetriesByJobId.

protected void setJobRetriesByJobId(String jobId, int retries, CommandContext commandContext) {
    JobEntity job = commandContext.getJobManager().findJobById(jobId);
    if (job != null) {
        for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
            checker.checkUpdateJob(job);
        }
        if (job.isInInconsistentLockState()) {
            job.resetLock();
        }
        int oldRetries = job.getRetries();
        job.setRetries(retries);
        PropertyChange propertyChange = new PropertyChange(RETRIES, oldRetries, job.getRetries());
        commandContext.getOperationLogManager().logJobOperation(getLogEntryOperation(), job.getId(), job.getJobDefinitionId(), job.getProcessInstanceId(), job.getProcessDefinitionId(), job.getProcessDefinitionKey(), propertyChange);
    } else {
        throw new ProcessEngineException("No job found with id '" + jobId + "'.");
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 4 with JobEntity

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

the class SetProcessDefinitionVersionCmd method execute.

public Void execute(CommandContext commandContext) {
    ProcessEngineConfigurationImpl configuration = commandContext.getProcessEngineConfiguration();
    // check that the new process definition is just another version of the same
    // process definition that the process instance is using
    ExecutionManager executionManager = commandContext.getExecutionManager();
    final ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
    if (processInstance == null) {
        throw new ProcessEngineException("No process instance found for id = '" + processInstanceId + "'.");
    } else if (!processInstance.isProcessInstanceExecution()) {
        throw new ProcessEngineException("A process instance id is required, but the provided id " + "'" + processInstanceId + "' " + "points to a child execution of process instance " + "'" + processInstance.getProcessInstanceId() + "'. " + "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
    }
    ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();
    DeploymentCache deploymentCache = configuration.getDeploymentCache();
    ProcessDefinitionEntity currentProcessDefinition;
    if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
        currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
    } else {
        currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());
    }
    ProcessDefinitionEntity newProcessDefinition = deploymentCache.findDeployedProcessDefinitionByKeyVersionAndTenantId(currentProcessDefinition.getKey(), processDefinitionVersion, currentProcessDefinition.getTenantId());
    validateAndSwitchVersionOfExecution(commandContext, processInstance, newProcessDefinition);
    HistoryLevel historyLevel = configuration.getHistoryLevel();
    if (historyLevel.isHistoryEventProduced(HistoryEventTypes.PROCESS_INSTANCE_UPDATE, processInstance)) {
        HistoryEventProcessor.processHistoryEvents(new HistoryEventProcessor.HistoryEventCreator() {

            @Override
            public HistoryEvent createHistoryEvent(HistoryEventProducer producer) {
                return producer.createProcessInstanceUpdateEvt(processInstance);
            }
        });
    }
    // switch all sub-executions of the process instance to the new process definition version
    List<ExecutionEntity> childExecutions = executionManager.findExecutionsByProcessInstanceId(processInstanceId);
    for (ExecutionEntity executionEntity : childExecutions) {
        validateAndSwitchVersionOfExecution(commandContext, executionEntity, newProcessDefinition);
    }
    // switch all jobs to the new process definition version
    List<JobEntity> jobs = commandContext.getJobManager().findJobsByProcessInstanceId(processInstanceId);
    List<JobDefinitionEntity> currentJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(currentProcessDefinition.getId());
    List<JobDefinitionEntity> newVersionJobDefinitions = commandContext.getJobDefinitionManager().findByProcessDefinitionId(newProcessDefinition.getId());
    Map<String, String> jobDefinitionMapping = getJobDefinitionMapping(currentJobDefinitions, newVersionJobDefinitions);
    for (JobEntity jobEntity : jobs) {
        switchVersionOfJob(jobEntity, newProcessDefinition, jobDefinitionMapping);
    }
    // switch all incidents to the new process definition version
    List<IncidentEntity> incidents = commandContext.getIncidentManager().findIncidentsByProcessInstance(processInstanceId);
    for (IncidentEntity incidentEntity : incidents) {
        switchVersionOfIncident(commandContext, incidentEntity, newProcessDefinition);
    }
    // add an entry to the op log
    PropertyChange change = new PropertyChange("processDefinitionVersion", currentProcessDefinition.getVersion(), processDefinitionVersion);
    commandContext.getOperationLogManager().logProcessInstanceOperation(UserOperationLogEntry.OPERATION_TYPE_MODIFY_PROCESS_INSTANCE, processInstanceId, null, null, Collections.singletonList(change));
    return null;
}
Also used : ExecutionManager(org.camunda.bpm.engine.impl.persistence.entity.ExecutionManager) PropertyChange(org.camunda.bpm.engine.impl.persistence.entity.PropertyChange) ProcessDefinitionImpl(org.camunda.bpm.engine.impl.pvm.process.ProcessDefinitionImpl) IncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.IncidentEntity) HistoryEventProducer(org.camunda.bpm.engine.impl.history.producer.HistoryEventProducer) HistoryEvent(org.camunda.bpm.engine.impl.history.event.HistoryEvent) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) HistoryEventProcessor(org.camunda.bpm.engine.impl.history.event.HistoryEventProcessor) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) ProcessDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 5 with JobEntity

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

the class GetJobExceptionStacktraceCmd method execute.

public String execute(CommandContext commandContext) {
    ensureNotNull("jobId", jobId);
    JobEntity job = commandContext.getJobManager().findJobById(jobId);
    ensureNotNull("No job found with id " + jobId, "job", job);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkReadJob(job);
    }
    return job.getExceptionStacktrace();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Aggregations

JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)68 Test (org.junit.Test)26 Date (java.util.Date)18 Job (org.camunda.bpm.engine.runtime.Job)13 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)11 HistoryCleanupJobHandlerConfiguration (org.camunda.bpm.engine.impl.jobexecutor.historycleanup.HistoryCleanupJobHandlerConfiguration)9 Deployment (org.camunda.bpm.engine.test.Deployment)9 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)7 SimpleDateFormat (java.text.SimpleDateFormat)6 List (java.util.List)6 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)6 Page (org.camunda.bpm.engine.impl.Page)5 JobDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity)5 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)4 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)4 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)4 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)4 ArrayList (java.util.ArrayList)3 HistoricCaseInstance (org.camunda.bpm.engine.history.HistoricCaseInstance)3