use of org.camunda.bpm.engine.impl.persistence.entity.JobManager in project camunda-bpm-platform by camunda.
the class ManagementServiceTest method testSetJobRetriesByDefinitionUnlocksInconsistentJobs.
@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/ManagementServiceTest.testGetJobExceptionStacktrace.bpmn20.xml" })
public void testSetJobRetriesByDefinitionUnlocksInconsistentJobs() {
// given a job definition
final JobDefinition jobDefinition = managementService.createJobDefinitionQuery().singleResult();
// and an inconsistent job that is never again picked up by a job executor
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
@Override
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
MessageEntity job = new MessageEntity();
job.setJobDefinitionId(jobDefinition.getId());
job.setJobHandlerType("any");
job.setLockOwner("owner");
job.setLockExpirationTime(ClockUtil.getCurrentTime());
job.setRetries(0);
jobManager.send(job);
return null;
}
});
// when the job retries are reset
managementService.setJobRetriesByJobDefinitionId(jobDefinition.getId(), 3);
// then the job can be picked up again
JobEntity job = (JobEntity) managementService.createJobQuery().singleResult();
assertNotNull(job);
assertNull(job.getLockOwner());
assertNull(job.getLockExpirationTime());
assertEquals(3, job.getRetries());
deleteJobAndIncidents(job);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobManager in project camunda-bpm-platform by camunda.
the class AbstractSetJobDefinitionStateCmd method updateSuspensionState.
@Override
protected void updateSuspensionState(CommandContext commandContext, SuspensionState suspensionState) {
JobDefinitionManager jobDefinitionManager = commandContext.getJobDefinitionManager();
JobManager jobManager = commandContext.getJobManager();
if (jobDefinitionId != null) {
jobDefinitionManager.updateJobDefinitionSuspensionStateById(jobDefinitionId, suspensionState);
} else if (processDefinitionId != null) {
jobDefinitionManager.updateJobDefinitionSuspensionStateByProcessDefinitionId(processDefinitionId, suspensionState);
jobManager.updateStartTimerJobSuspensionStateByProcessDefinitionId(processDefinitionId, suspensionState);
} else if (processDefinitionKey != null) {
if (!isProcessDefinitionTenantIdSet) {
jobDefinitionManager.updateJobDefinitionSuspensionStateByProcessDefinitionKey(processDefinitionKey, suspensionState);
jobManager.updateStartTimerJobSuspensionStateByProcessDefinitionKey(processDefinitionKey, suspensionState);
} else {
jobDefinitionManager.updateJobDefinitionSuspensionStateByProcessDefinitionKeyAndTenantId(processDefinitionKey, processDefinitionTenantId, suspensionState);
jobManager.updateStartTimerJobSuspensionStateByProcessDefinitionKeyAndTenantId(processDefinitionKey, processDefinitionTenantId, suspensionState);
}
}
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobManager 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.JobManager in project camunda-bpm-platform by camunda.
the class AcquireJobCmdUnitTest method initCommand.
@Before
public void initCommand() {
JobExecutor jobExecutor = mock(JobExecutor.class);
when(jobExecutor.getMaxJobsPerAcquisition()).thenReturn(3);
when(jobExecutor.getLockOwner()).thenReturn("test");
when(jobExecutor.getLockTimeInMillis()).thenReturn(5 * 60 * 1000);
acquireJobsCmd = new AcquireJobsCmd(jobExecutor);
commandContext = mock(CommandContext.class);
DbEntityManager dbEntityManager = mock(DbEntityManager.class);
when(commandContext.getDbEntityManager()).thenReturn(dbEntityManager);
jobManager = mock(JobManager.class);
when(commandContext.getJobManager()).thenReturn(jobManager);
}
use of org.camunda.bpm.engine.impl.persistence.entity.JobManager in project camunda-bpm-platform by camunda.
the class JobExecutorTest method testBasicJobExecutorOperation.
public void testBasicJobExecutorOperation() throws Exception {
CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
JobManager jobManager = commandContext.getJobManager();
jobManager.send(createTweetMessage("message-one"));
jobManager.send(createTweetMessage("message-two"));
jobManager.send(createTweetMessage("message-three"));
jobManager.send(createTweetMessage("message-four"));
jobManager.schedule(createTweetTimer("timer-one", new Date()));
jobManager.schedule(createTweetTimer("timer-two", new Date()));
return null;
}
});
executeAvailableJobs();
Set<String> messages = new HashSet<String>(tweetHandler.getMessages());
Set<String> expectedMessages = new HashSet<String>();
expectedMessages.add("message-one");
expectedMessages.add("message-two");
expectedMessages.add("message-three");
expectedMessages.add("message-four");
expectedMessages.add("timer-one");
expectedMessages.add("timer-two");
assertEquals(new TreeSet<String>(expectedMessages), new TreeSet<String>(messages));
commandExecutor.execute(new Command<Void>() {
public Void execute(CommandContext commandContext) {
List<HistoricJobLog> historicJobLogs = processEngineConfiguration.getHistoryService().createHistoricJobLogQuery().list();
for (HistoricJobLog historicJobLog : historicJobLogs) {
commandContext.getHistoricJobLogManager().deleteHistoricJobLogById(historicJobLog.getId());
}
return null;
}
});
}
Aggregations