Search in sources :

Example 6 with JobManager

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);
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) MessageEntity(org.camunda.bpm.engine.impl.persistence.entity.MessageEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) JobDefinition(org.camunda.bpm.engine.management.JobDefinition) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 7 with JobManager

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);
        }
    }
}
Also used : JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 8 with JobManager

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);
        }
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) JobDefinitionEntity(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionEntity) JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker)

Example 9 with JobManager

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);
}
Also used : AcquireJobsCmd(org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) JobExecutor(org.camunda.bpm.engine.impl.jobexecutor.JobExecutor) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Before(org.junit.Before)

Example 10 with 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;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricJobLog(org.camunda.bpm.engine.history.HistoricJobLog) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ArrayList(java.util.ArrayList) List(java.util.List) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)10 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)8 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)5 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)4 Date (java.util.Date)3 ByteArrayEntity (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity)2 ByteArrayManager (org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager)2 JobDefinitionManager (org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager)2 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)2 TimerEntity (org.camunda.bpm.engine.impl.persistence.entity.TimerEntity)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 HistoricJobLog (org.camunda.bpm.engine.history.HistoricJobLog)1 CommandChecker (org.camunda.bpm.engine.impl.cfg.CommandChecker)1 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)1