Search in sources :

Example 26 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class HistoryCleanupAuthorizationTest method clearDatabase.

protected void clearDatabase() {
    // reset configuration changes
    String defaultStartTime = processEngineConfiguration.getHistoryCleanupBatchWindowStartTime();
    String defaultEndTime = processEngineConfiguration.getHistoryCleanupBatchWindowEndTime();
    int defaultBatchSize = processEngineConfiguration.getHistoryCleanupBatchSize();
    processEngineConfiguration.setHistoryCleanupBatchWindowStartTime(defaultStartTime);
    processEngineConfiguration.setHistoryCleanupBatchWindowEndTime(defaultEndTime);
    processEngineConfiguration.setHistoryCleanupBatchSize(defaultBatchSize);
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            List<Job> jobs = managementService.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);
            }
            List<HistoricIncident> historicIncidents = historyService.createHistoricIncidentQuery().list();
            for (HistoricIncident historicIncident : historicIncidents) {
                commandContext.getDbEntityManager().delete((HistoricIncidentEntity) historicIncident);
            }
            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());
    }
    List<HistoricCaseInstance> historicCaseInstances = historyService.createHistoricCaseInstanceQuery().list();
    for (HistoricCaseInstance historicCaseInstance : historicCaseInstances) {
        historyService.deleteHistoricCaseInstance(historicCaseInstance.getId());
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricProcessInstance(org.camunda.bpm.engine.history.HistoricProcessInstance) HistoricDecisionInstance(org.camunda.bpm.engine.history.HistoricDecisionInstance) JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) HistoricCaseInstance(org.camunda.bpm.engine.history.HistoricCaseInstance) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method deleteJobAndIncidents.

protected void deleteJobAndIncidents(final Job job) {
    final List<HistoricIncident> incidents = historyService.createHistoricIncidentQuery().incidentType(Incident.FAILED_JOB_HANDLER_TYPE).list();
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            ((JobEntity) job).delete();
            HistoricIncidentManager historicIncidentManager = commandContext.getHistoricIncidentManager();
            for (HistoricIncident incident : incidents) {
                HistoricIncidentEntity incidentEntity = (HistoricIncidentEntity) incident;
                historicIncidentManager.delete(incidentEntity);
            }
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(job.getId());
            return null;
        }
    });
}
Also used : HistoricIncident(org.camunda.bpm.engine.history.HistoricIncident) HistoricIncidentEntity(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HistoricIncidentManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentManager) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor)

Example 28 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class ManagementServiceTest method createJob.

protected void createJob(final int retries, final String owner, final Date lockExpirationTime) {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        @Override
        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            MessageEntity job = new MessageEntity();
            job.setJobHandlerType("any");
            job.setLockOwner(owner);
            job.setLockExpirationTime(lockExpirationTime);
            job.setRetries(retries);
            jobManager.send(job);
            return null;
        }
    });
}
Also used : 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)

Example 29 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class IncidentTest method testDoNotSetNegativeRetries.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/mgmt/IncidentTest.testShouldCreateOneIncident.bpmn" })
public void testDoNotSetNegativeRetries() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("failingProcess");
    executeAvailableJobs();
    // it exists a job with 0 retries and an incident
    Job job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
    assertEquals(1, runtimeService.createIncidentQuery().count());
    // it should not be possible to set negative retries
    final JobEntity jobEntity = (JobEntity) job;
    processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            jobEntity.setRetries(-100);
            return null;
        }
    });
    assertEquals(0, job.getRetries());
    // retries should still be 0 after execution this job again
    try {
        managementService.executeJob(job.getId());
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
    job = managementService.createJobQuery().singleResult();
    assertEquals(0, job.getRetries());
    // also no new incident was created
    assertEquals(1, runtimeService.createIncidentQuery().count());
    // it should not be possible to set the retries to a negative number with the management service
    try {
        managementService.setJobRetries(job.getId(), -200);
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
    try {
        managementService.setJobRetriesByJobDefinitionId(job.getJobDefinitionId(), -300);
        fail("Exception expected");
    } catch (ProcessEngineException e) {
    // expected
    }
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) Job(org.camunda.bpm.engine.runtime.Job) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 30 with CommandContext

use of org.camunda.bpm.engine.impl.interceptor.CommandContext in project camunda-bpm-platform by camunda.

the class JobQueryTest method createJobWithoutExceptionMsg.

private void createJobWithoutExceptionMsg() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            JobManager jobManager = commandContext.getJobManager();
            timerEntity = new TimerEntity();
            timerEntity.setLockOwner(UUID.randomUUID().toString());
            timerEntity.setDuedate(new Date());
            timerEntity.setRetries(0);
            StringWriter stringWriter = new StringWriter();
            NullPointerException exception = new NullPointerException();
            exception.printStackTrace(new PrintWriter(stringWriter));
            timerEntity.setExceptionStacktrace(stringWriter.toString());
            jobManager.insert(timerEntity);
            assertNotNull(timerEntity.getId());
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) StringWriter(java.io.StringWriter) TimerEntity(org.camunda.bpm.engine.impl.persistence.entity.TimerEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Aggregations

CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)120 CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)31 List (java.util.List)17 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)17 JobEntity (org.camunda.bpm.engine.impl.persistence.entity.JobEntity)11 Deployment (org.camunda.bpm.engine.test.Deployment)11 ArrayList (java.util.ArrayList)10 ProcessDefinitionEntity (org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionEntity)10 Date (java.util.Date)9 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)8 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)8 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)8 Command (org.camunda.bpm.engine.impl.interceptor.Command)6 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)6 After (org.junit.After)6 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)5 RepositoryService (org.camunda.bpm.engine.RepositoryService)5 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)5 ExecutionEntity (org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity)5 HistoricDecisionInstance (org.camunda.bpm.engine.history.HistoricDecisionInstance)4