Search in sources :

Example 21 with CommandExecutor

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

the class JobMigrationScenario method triggerEntryCriterion.

@DescribesScenario("createJob")
public static ScenarioSetup triggerEntryCriterion() {
    return new ScenarioSetup() {

        public void execute(ProcessEngine engine, final String scenarioName) {
            final ProcessEngineConfigurationImpl engineConfiguration = (ProcessEngineConfigurationImpl) engine.getProcessEngineConfiguration();
            CommandExecutor commandExecutor = engineConfiguration.getCommandExecutorTxRequired();
            // create a job with the scenario name as id and a null suspension state
            commandExecutor.execute(new Command<Void>() {

                public Void execute(CommandContext commandContext) {
                    Connection connection = null;
                    Statement statement = null;
                    ResultSet rs = null;
                    try {
                        SqlSession sqlSession = commandContext.getDbSqlSession().getSqlSession();
                        connection = sqlSession.getConnection();
                        statement = connection.createStatement();
                        statement.executeUpdate("INSERT INTO ACT_RU_JOB(ID_, REV_, RETRIES_, TYPE_, EXCLUSIVE_, HANDLER_TYPE_) " + "VALUES (" + "'" + scenarioName + "'," + "1," + "3," + "'timer'," + DbSqlSessionFactory.databaseSpecificTrueConstant.get(engineConfiguration.getDatabaseType()) + "," + "'" + TimerStartEventJobHandler.TYPE + "'" + ")");
                        connection.commit();
                        statement.close();
                    } catch (SQLException e) {
                        throw new RuntimeException(e);
                    } finally {
                        try {
                            if (statement != null) {
                                statement.close();
                            }
                            if (rs != null) {
                                rs.close();
                            }
                            if (connection != null) {
                                connection.close();
                            }
                        } catch (SQLException e) {
                            throw new RuntimeException(e);
                        }
                    }
                    return null;
                }
            });
        }
    };
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) SqlSession(org.apache.ibatis.session.SqlSession) SQLException(java.sql.SQLException) Statement(java.sql.Statement) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) Connection(java.sql.Connection) ScenarioSetup(org.camunda.bpm.qa.upgrade.ScenarioSetup) ResultSet(java.sql.ResultSet) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) DescribesScenario(org.camunda.bpm.qa.upgrade.DescribesScenario)

Example 22 with CommandExecutor

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

the class StartTimerEventTest method cleanDB.

private void cleanDB() {
    String jobId = managementService.createJobQuery().singleResult().getId();
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new DeleteJobsCmd(jobId, true));
}
Also used : CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) DeleteJobsCmd(org.camunda.bpm.engine.impl.cmd.DeleteJobsCmd)

Example 23 with CommandExecutor

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

the class ExecutionTree method forExecution.

public static ExecutionTree forExecution(final String executionId, ProcessEngine processEngine) {
    ProcessEngineConfigurationImpl configuration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    CommandExecutor commandExecutor = configuration.getCommandExecutorTxRequired();
    ExecutionTree executionTree = commandExecutor.execute(new Command<ExecutionTree>() {

        public ExecutionTree execute(CommandContext commandContext) {
            ExecutionEntity execution = commandContext.getExecutionManager().findExecutionById(executionId);
            return ExecutionTree.forExecution(execution);
        }
    });
    return executionTree;
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ExecutionEntity(org.camunda.bpm.engine.impl.persistence.entity.ExecutionEntity) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)

Example 24 with CommandExecutor

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

the class UserOperationLogQueryTest method testQueryJobDefinitionOperationWithDelayedJobDefinition.

@Deployment(resources = { ONE_TASK_PROCESS })
public void testQueryJobDefinitionOperationWithDelayedJobDefinition() {
    // given
    // a running process instance
    ProcessInstance process = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    // with a process definition id
    String processDefinitionId = process.getProcessDefinitionId();
    // ...which will be suspended with the corresponding jobs
    managementService.suspendJobDefinitionByProcessDefinitionId(processDefinitionId, true);
    // one week from now
    ClockUtil.setCurrentTime(today);
    long oneWeekFromStartTime = today.getTime() + (7 * 24 * 60 * 60 * 1000);
    // when
    // activate the job definition
    managementService.activateJobDefinitionByProcessDefinitionId(processDefinitionId, false, new Date(oneWeekFromStartTime));
    // then
    // there is a user log entry for the activation
    Long jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
    assertEquals(1, jobDefinitionEntryCount.longValue());
    // there exists a job for the delayed activation execution
    JobQuery jobQuery = managementService.createJobQuery();
    Job delayedActivationJob = jobQuery.timers().active().singleResult();
    assertNotNull(delayedActivationJob);
    // execute job
    managementService.executeJob(delayedActivationJob.getId());
    jobDefinitionEntryCount = query().entityType(JOB_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_ACTIVATE_JOB_DEFINITION).processDefinitionId(processDefinitionId).count();
    assertEquals(1, jobDefinitionEntryCount.longValue());
    // Clean up db
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerActivateJobDefinitionHandler.TYPE);
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) JobQuery(org.camunda.bpm.engine.runtime.JobQuery) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 25 with CommandExecutor

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

the class UserOperationLogQueryTest method testQueryProcessDefinitionOperationWithDelayedProcessDefinition.

@Deployment(resources = { "org/camunda/bpm/engine/test/api/repository/ProcessDefinitionSuspensionTest.testWithOneAsyncServiceTask.bpmn" })
public void testQueryProcessDefinitionOperationWithDelayedProcessDefinition() {
    // given
    ClockUtil.setCurrentTime(today);
    final long hourInMs = 60 * 60 * 1000;
    String key = "oneFailingServiceTaskProcess";
    // a running process instance with a failed service task
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("fail", Boolean.TRUE);
    runtimeService.startProcessInstanceByKey(key, params);
    // when
    // the process definition will be suspended
    repositoryService.suspendProcessDefinitionByKey(key, false, new Date(today.getTime() + (2 * hourInMs)));
    // then
    // there exists a timer job to suspend the process definition delayed
    Job timerToSuspendProcessDefinition = managementService.createJobQuery().timers().singleResult();
    assertNotNull(timerToSuspendProcessDefinition);
    // there is a user log entry for the activation
    Long processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
    assertEquals(1, processDefinitionEntryCount.longValue());
    // when
    // execute job
    managementService.executeJob(timerToSuspendProcessDefinition.getId());
    // then
    // there is a user log entry for the activation
    processDefinitionEntryCount = query().entityType(PROCESS_DEFINITION).operationType(UserOperationLogEntry.OPERATION_TYPE_SUSPEND_PROCESS_DEFINITION).processDefinitionKey(key).count();
    assertEquals(1, processDefinitionEntryCount.longValue());
    // clean up op log
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Object>() {

        public Object execute(CommandContext commandContext) {
            commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
            return null;
        }
    });
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) HashMap(java.util.HashMap) CommandExecutor(org.camunda.bpm.engine.impl.interceptor.CommandExecutor) Job(org.camunda.bpm.engine.runtime.Job) Date(java.util.Date) Deployment(org.camunda.bpm.engine.test.Deployment)

Aggregations

CommandExecutor (org.camunda.bpm.engine.impl.interceptor.CommandExecutor)53 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)31 Deployment (org.camunda.bpm.engine.test.Deployment)17 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)15 SetProcessDefinitionVersionCmd (org.camunda.bpm.engine.impl.cmd.SetProcessDefinitionVersionCmd)13 HistoricProcessInstance (org.camunda.bpm.engine.history.HistoricProcessInstance)11 Job (org.camunda.bpm.engine.runtime.Job)9 Date (java.util.Date)8 List (java.util.List)7 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)7 Execution (org.camunda.bpm.engine.runtime.Execution)6 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)5 HistoricIncident (org.camunda.bpm.engine.history.HistoricIncident)5 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)5 AcquireJobsCmd (org.camunda.bpm.engine.impl.cmd.AcquireJobsCmd)5 AcquiredJobs (org.camunda.bpm.engine.impl.jobexecutor.AcquiredJobs)5 JobExecutor (org.camunda.bpm.engine.impl.jobexecutor.JobExecutor)5 JobManager (org.camunda.bpm.engine.impl.persistence.entity.JobManager)5 HistoricIncidentEntity (org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentEntity)4 MessageEntity (org.camunda.bpm.engine.impl.persistence.entity.MessageEntity)4