use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AcquireJobsCmd method execute.
public AcquiredJobs execute(CommandContext commandContext) {
acquiredJobs = new AcquiredJobs(numJobsToAcquire);
List<JobEntity> jobs = commandContext.getJobManager().findNextJobsToExecute(new Page(0, numJobsToAcquire));
Map<String, List<String>> exclusiveJobsByProcessInstance = new HashMap<String, List<String>>();
for (JobEntity job : jobs) {
lockJob(job);
if (job.isExclusive()) {
List<String> list = exclusiveJobsByProcessInstance.get(job.getProcessInstanceId());
if (list == null) {
list = new ArrayList<String>();
exclusiveJobsByProcessInstance.put(job.getProcessInstanceId(), list);
}
list.add(job.getId());
} else {
acquiredJobs.addJobIdBatch(job.getId());
}
}
for (List<String> jobIds : exclusiveJobsByProcessInstance.values()) {
acquiredJobs.addJobIdBatch(jobIds);
}
// register an OptimisticLockingListener which is notified about jobs which cannot be acquired.
// the listener removes them from the list of acquired jobs.
commandContext.getDbEntityManager().registerOptimisticLockingListener(this);
return acquiredJobs;
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class AbstractSetJobStateCmd method checkAuthorization.
@Override
protected void checkAuthorization(CommandContext commandContext) {
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
if (jobId != null) {
JobManager jobManager = commandContext.getJobManager();
JobEntity job = jobManager.findJobById(jobId);
if (job != null) {
String processInstanceId = job.getProcessInstanceId();
if (processInstanceId != null) {
checker.checkUpdateProcessInstanceById(processInstanceId);
} else {
// start timer job is not assigned to a specific process
// instance, that's why we have to check whether there
// exists a UPDATE_INSTANCES permission on process definition or
// a UPDATE permission on any process instance
String processDefinitionKey = job.getProcessDefinitionKey();
if (processDefinitionKey != null) {
checker.checkUpdateProcessInstanceByProcessDefinitionKey(processDefinitionKey);
}
}
// if (processInstanceId == null && processDefinitionKey == null):
// job is not assigned to any process instance nor process definition
// then it is always possible to activate/suspend the corresponding job
// -> no authorization check necessary
}
} else if (jobDefinitionId != null) {
JobDefinitionManager jobDefinitionManager = commandContext.getJobDefinitionManager();
JobDefinitionEntity jobDefinition = jobDefinitionManager.findById(jobDefinitionId);
if (jobDefinition != null) {
String processDefinitionKey = jobDefinition.getProcessDefinitionKey();
checker.checkUpdateProcessInstanceByProcessDefinitionKey(processDefinitionKey);
}
} else if (processInstanceId != null) {
checker.checkUpdateProcessInstanceById(processInstanceId);
} else if (processDefinitionId != null) {
checker.checkUpdateProcessInstanceByProcessDefinitionId(processDefinitionId);
} else if (processDefinitionKey != null) {
checker.checkUpdateProcessInstanceByProcessDefinitionKey(processDefinitionKey);
}
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class ExecuteJobsCmd method execute.
public Void execute(CommandContext commandContext) {
ensureNotNull("jobId", jobId);
final JobEntity job = commandContext.getDbEntityManager().selectById(JobEntity.class, jobId);
final ProcessEngineConfigurationImpl processEngineConfiguration = Context.getProcessEngineConfiguration();
final IdentityService identityService = processEngineConfiguration.getIdentityService();
final JobExecutorContext jobExecutorContext = Context.getJobExecutorContext();
if (job == null) {
if (jobExecutorContext != null) {
// CAM-1842
// Job was acquired but does not exist anymore. This is not a problem.
// It usually means that the job has been deleted after it was acquired which can happen if the
// the activity instance corresponding to the job is cancelled.
LOG.debugAcquiredJobNotFound(jobId);
return null;
} else {
throw LOG.jobNotFoundException(jobId);
}
}
jobFailureCollector.setJob(job);
if (jobExecutorContext == null) {
// if null, then we are not called by the job executor
for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
checker.checkUpdateJob(job);
}
} else {
jobExecutorContext.setCurrentJob(job);
// if the job is called by the job executor then set the tenant id of the job
// as authenticated tenant to enable tenant checks
String tenantId = job.getTenantId();
if (tenantId != null) {
identityService.setAuthentication(null, null, Collections.singletonList(tenantId));
}
}
try {
// register as command context close lister to intercept exceptions on flush
commandContext.registerCommandContextListener(jobFailureCollector);
commandContext.setCurrentJob(job);
job.execute(commandContext);
} finally {
if (jobExecutorContext != null) {
jobExecutorContext.setCurrentJob(null);
identityService.clearAuthentication();
}
}
return null;
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class DefaultJobRetryCmd method executeStandardStrategy.
protected void executeStandardStrategy(CommandContext commandContext) {
JobEntity job = getJob();
if (job != null) {
job.unlock();
logException(job);
decrementRetries(job);
notifyAcquisition(commandContext);
} else {
LOG.debugFailedJobNotFound(jobId);
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobEntity in project camunda-bpm-platform by camunda.
the class BulkHistoryDeleteCmmnDisabledTest method clearDatabase.
@After
public void clearDatabase() {
engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired().execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
List<Job> jobs = engineRule.getManagementService().createJobQuery().list();
if (jobs.size() > 0) {
assertEquals(1, jobs.size());
String jobId = jobs.get(0).getId();
commandContext.getJobManager().deleteJob((JobEntity) jobs.get(0));
commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
}
commandContext.getMeterLogManager().deleteAll();
return null;
}
});
List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().list();
for (HistoricProcessInstance historicProcessInstance : historicProcessInstances) {
historyService.deleteHistoricProcessInstance(historicProcessInstance.getId());
}
List<HistoricDecisionInstance> historicDecisionInstances = historyService.createHistoricDecisionInstanceQuery().list();
for (HistoricDecisionInstance historicDecisionInstance : historicDecisionInstances) {
historyService.deleteHistoricDecisionInstanceByInstanceId(historicDecisionInstance.getId());
}
}
Aggregations