org.camunda.bpm.engine.impl.interceptor.CommandExecutor Java Examples

The following examples show how to use org.camunda.bpm.engine.impl.interceptor.CommandExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SetProcessDefinitionVersionCmdTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = TEST_PROCESS_ATTACHED_TIMER)
public void testSetProcessDefinitionVersionAttachedTimer() {
  // given a process instance
  ProcessInstance instance =
      runtimeService.startProcessInstanceByKey("attachedTimer");

  // and a second deployment of the process
  org.camunda.bpm.engine.repository.Deployment deployment = repositoryService
    .createDeployment()
    .addClasspathResource(TEST_PROCESS_ATTACHED_TIMER)
    .deploy();

  ProcessDefinition newDefinition =
      repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
  assertNotNull(newDefinition);

  // when the process instance is migrated
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2));

  Job job = managementService.createJobQuery().singleResult();
  assertNotNull(job);
  assertEquals(newDefinition.getId(), job.getProcessDefinitionId());

  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #2
Source File: JobQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void deleteJobInDatabase() {
    CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
    commandExecutor.execute(new Command<Void>() {
      public Void execute(CommandContext commandContext) {

        timerEntity.delete();

        commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(timerEntity.getId());

        List<HistoricIncident> historicIncidents = Context
            .getProcessEngineConfiguration()
            .getHistoryService()
            .createHistoricIncidentQuery()
            .list();

        for (HistoricIncident historicIncident : historicIncidents) {
          commandContext
            .getDbEntityManager()
            .delete((DbEntity) historicIncident);
        }

        return null;
      }
    });
}
 
Example #3
Source File: CommandContextInterceptorTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
public void testCommandContextNestedTryCatch() {
  final ExceptionThrowingCmd innerCommand = new ExceptionThrowingCmd(new IdentifiableRuntimeException(1));

  processEngineConfiguration.getCommandExecutorTxRequired().execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      CommandExecutor commandExecutor = Context.getProcessEngineConfiguration().getCommandExecutorTxRequired();

      try {
        commandExecutor.execute(innerCommand);
        fail("exception expected to pop up during execution of inner command");
      } catch (IdentifiableRuntimeException e) {
        // happy path
        assertNull("the exception should not have been propagated to this command's context",
            Context.getCommandInvocationContext().getThrowable());
      }

      return null;
    }
  });
}
 
Example #4
Source File: IndependentJobExecutionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@OperateOnDeployment("pa1")
@Test
public void testDeploymentUnawareJobAcquisition() {
  JobExecutor defaultJobExecutor = processEngineConfiguration.getJobExecutor();

  ProcessInstance instance1 = engine1.getRuntimeService().startProcessInstanceByKey("archive1Process");
  ProcessInstance instance2 = processEngine.getRuntimeService().startProcessInstanceByKey("archive2Process");

  Job job1 = managementService.createJobQuery().processInstanceId(instance1.getId()).singleResult();
  Job job2 = managementService.createJobQuery().processInstanceId(instance2.getId()).singleResult();

  // the deployment unaware configuration should return both jobs
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  processEngineConfiguration.setJobExecutorDeploymentAware(false);
  try {
    AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(defaultJobExecutor));

    Assert.assertEquals(2, acquiredJobs.size());
    Assert.assertTrue(acquiredJobs.contains(job1.getId()));
    Assert.assertTrue(acquiredJobs.contains(job2.getId()));
  } finally {
    processEngineConfiguration.setJobExecutorDeploymentAware(true);
  }
}
 
Example #5
Source File: ExecuteJobHelper.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
protected static void invokeJobListener(CommandExecutor commandExecutor, JobFailureCollector jobFailureCollector) {
  if(jobFailureCollector.getJobId() != null) {
    if (jobFailureCollector.getFailure() != null) {
      // the failed job listener is responsible for decrementing the retries and logging the exception to the DB.

      FailedJobListener failedJobListener = createFailedJobListener(commandExecutor, jobFailureCollector);

      OptimisticLockingException exception = callFailedJobListenerWithRetries(commandExecutor, failedJobListener);
      if (exception != null) {
        throw exception;
      }

    } else {
      SuccessfulJobListener successListener = createSuccessfulJobListener(commandExecutor);
      commandExecutor.execute(successListener);
    }
  }
}
 
Example #6
Source File: JobQueryTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
private void createJobWithoutExceptionStacktrace() {
  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);
      timerEntity.setExceptionMessage("I'm supposed to fail");

      jobManager.insert(timerEntity);

      assertNotNull(timerEntity.getId());

      return null;

    }
  });

}
 
Example #7
Source File: ManagementServiceTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
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;
    }
  });
}
 
Example #8
Source File: IndependentJobExecutionTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@OperateOnDeployment("pa1")
@Test
public void testDeploymentAwareJobAcquisition() {
  JobExecutor jobExecutor1 = engine1Configuration.getJobExecutor();

  ProcessInstance instance1 = engine1.getRuntimeService().startProcessInstanceByKey("archive1Process");
  ProcessInstance instance2 = processEngine.getRuntimeService().startProcessInstanceByKey("archive2Process");

  Job job1 = managementService.createJobQuery().processInstanceId(instance1.getId()).singleResult();
  Job job2 = managementService.createJobQuery().processInstanceId(instance2.getId()).singleResult();


  // the deployment aware configuration should only return the jobs of the registered deployments
  CommandExecutor commandExecutor = engine1Configuration.getCommandExecutorTxRequired();
  AcquiredJobs acquiredJobs = commandExecutor.execute(new AcquireJobsCmd(jobExecutor1));

  Assert.assertEquals(1, acquiredJobs.size());
  Assert.assertTrue(acquiredJobs.contains(job1.getId()));
  Assert.assertFalse(acquiredJobs.contains(job2.getId()));
}
 
Example #9
Source File: AbstractRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void clearCommentByProcessInstanceId(final String processInstanceId) {
  CommandExecutor commandExecutor = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getCommentManager().deleteCommentsByProcessInstanceIds(Collections.singletonList(processInstanceId));
      return null;
    }
  });
}
 
Example #10
Source File: AbstractRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void clearHistoricIncident(final HistoricIncident historicIncident) {
  CommandExecutor commandExecutor = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getHistoricIncidentManager().delete((HistoricIncidentEntity) historicIncident);
      return null;
    }
  });
}
 
Example #11
Source File: HistoricIncidentAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void clearDatabase() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendProcessDefinitionHandler.TYPE);
      List<HistoricIncident> incidents = Context.getProcessEngineConfiguration().getHistoryService().createHistoricIncidentQuery().list();
      for (HistoricIncident incident : incidents) {
        commandContext.getHistoricIncidentManager().delete((HistoricIncidentEntity) incident);
      }
      return null;
    }
  });
}
 
Example #12
Source File: SuspendJobDefinitionTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendJobDefinitionHandler.TYPE);
      return null;
    }
  });

}
 
Example #13
Source File: SequentialJobAcquisitionRunnable.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected AcquiredJobs acquireJobs(
    JobAcquisitionContext context,
    JobAcquisitionStrategy acquisitionStrategy,
    ProcessEngineImpl currentProcessEngine) {
  CommandExecutor commandExecutor = currentProcessEngine.getProcessEngineConfiguration()
      .getCommandExecutorTxRequired();

  int numJobsToAcquire = acquisitionStrategy.getNumJobsToAcquire(currentProcessEngine.getName());

  AcquiredJobs acquiredJobs = null;

  if (numJobsToAcquire > 0) {
    jobExecutor.logAcquisitionAttempt(currentProcessEngine);
    acquiredJobs = commandExecutor.execute(jobExecutor.getAcquireJobsCmd(numJobsToAcquire));
  }
  else {
    acquiredJobs = new AcquiredJobs(numJobsToAcquire);
  }

  context.submitAcquiredJobs(currentProcessEngine.getName(), acquiredJobs);

  jobExecutor.logAcquiredJobs(currentProcessEngine, acquiredJobs.size());
  jobExecutor.logAcquisitionFailureJobs(currentProcessEngine, acquiredJobs.getNumberOfJobsFailedToLock());

  LOG.acquiredJobs(currentProcessEngine.getName(), acquiredJobs);

  return acquiredJobs;
}
 
Example #14
Source File: SetProcessDefinitionVersionCmdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public void testSetProcessDefinitionVersionNonExistingPI() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  try {
    commandExecutor.execute(new SetProcessDefinitionVersionCmd("42", 23));
    fail("ProcessEngineException expected");
  } catch (ProcessEngineException ae) {
    assertTextPresent("No process instance found for id = '42'.", ae.getMessage());
  }
}
 
Example #15
Source File: TelemetryReporter.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
public TelemetryReporter(CommandExecutor commandExecutor,
                         String telemetryEndpoint,
                         Data data,
                         HttpClient httpClient) {
  this.commandExecutor = commandExecutor;
  this.telemetryEndpoint = telemetryEndpoint;
  this.data = data;
  this.httpClient = httpClient;
  initTelemetrySendingTask();
}
 
Example #16
Source File: JobAuthorizationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Override
public void tearDown() {
  super.tearDown();
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogsByHandlerType(TimerSuspendJobDefinitionHandler.TYPE);
      return null;
    }
  });
  deleteDeployment(deploymentId);
}
 
Example #17
Source File: SetProcessDefinitionVersionCmdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * See https://app.camunda.com/jira/browse/CAM-9505
 */
@Deployment(resources = TEST_PROCESS_ONE_JOB)
public void testPreserveTimestampOnUpdatedIncident() {
  // given
  ProcessInstance instance =
      runtimeService.startProcessInstanceByKey("oneJobProcess", Variables.createVariables().putValue("shouldFail", true));

  executeAvailableJobs();

  Incident incident = runtimeService.createIncidentQuery().singleResult();
  assertNotNull(incident);

  Date timestamp = incident.getIncidentTimestamp();

  org.camunda.bpm.engine.repository.Deployment deployment = repositoryService
    .createDeployment()
    .addClasspathResource(TEST_PROCESS_ONE_JOB)
    .deploy();

  ProcessDefinition newDefinition =
      repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
  assertNotNull(newDefinition);

  // when
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new SetProcessDefinitionVersionCmd(instance.getId(), 2));

  Incident migratedIncident = runtimeService.createIncidentQuery().singleResult();

  // then
  assertEquals(timestamp, migratedIncident.getIncidentTimestamp());

  // cleanup
  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #18
Source File: BpmnParseTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment
@Test
public void testParseNamespaceInConditionExpressionType() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  ProcessDefinitionEntity processDefinitionEntity = commandExecutor.execute(new Command<ProcessDefinitionEntity>() {
    @Override
    public ProcessDefinitionEntity execute(CommandContext commandContext) {
      return Context.getProcessEngineConfiguration().getDeploymentCache().findDeployedLatestProcessDefinitionByKey("resolvableNamespacesProcess");
    }
  });

  // Test that the process definition has been deployed
  assertNotNull(processDefinitionEntity);
  PvmActivity activity = processDefinitionEntity.findActivity("ExclusiveGateway_1");
  assertNotNull(activity);

  // Test that the conditions has been resolved
  for (PvmTransition transition : activity.getOutgoingTransitions()) {
    if (transition.getDestination().getId().equals("Task_2")) {
      assertTrue(transition.getProperty("conditionText").equals("#{approved}"));
    } else if (transition.getDestination().getId().equals("Task_3")) {
      assertTrue(transition.getProperty("conditionText").equals("#{!approved}"));
    } else {
      fail("Something went wrong");
    }

  }
}
 
Example #19
Source File: HistoryCleanupRemovalTimeTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
protected void clearJobLog(final String jobId) {
  CommandExecutor commandExecutor = engineRule.getProcessEngineConfiguration().getCommandExecutorTxRequired();
  commandExecutor.execute(new Command<Object>() {
    public Object execute(CommandContext commandContext) {
      commandContext.getHistoricJobLogManager().deleteHistoricJobLogByJobId(jobId);
      return null;
    }
  });
}
 
Example #20
Source File: SetProcessDefinitionVersionCmdTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Deployment(resources = {TEST_PROCESS_CALL_ACTIVITY})
public void testSetProcessDefinitionVersionWithCallActivity() {
  // start process instance
  ProcessInstance pi = runtimeService.startProcessInstanceByKey("parentProcess");

  // check that receive task has been reached
  Execution execution = runtimeService.createExecutionQuery()
    .activityId("waitState1")
    .processDefinitionKey("childProcess")
    .singleResult();
  assertNotNull(execution);

  // deploy new version of the process definition
  org.camunda.bpm.engine.repository.Deployment deployment = repositoryService
    .createDeployment()
    .addClasspathResource(TEST_PROCESS_CALL_ACTIVITY)
    .deploy();
  assertEquals(2, repositoryService.createProcessDefinitionQuery().processDefinitionKey("parentProcess").count());

  // migrate process instance to new process definition version
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequired();
  commandExecutor.execute(new SetProcessDefinitionVersionCmd(pi.getId(), 2));

  // signal process instance
  runtimeService.signal(execution.getId());

  // should be finished now
  assertEquals(0, runtimeService.createProcessInstanceQuery().processInstanceId(pi.getId()).count());

  // undeploy "manually" deployed process definition
  repositoryService.deleteDeployment(deployment.getId(), true);
}
 
Example #21
Source File: NativeHistoricProcessInstanceQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public NativeHistoricProcessInstanceQueryImpl(CommandExecutor commandExecutor) {
  super(commandExecutor);
}
 
Example #22
Source File: HistoryCleanupHandler.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public HistoryCleanupHandler setCommandExecutor(CommandExecutor commandExecutor) {
  this.commandExecutor = commandExecutor;
  return this;
}
 
Example #23
Source File: CaseSentryPartEntityTest.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected CaseSentryPartEntity readCaseSentryPart() {
  CommandExecutor commandExecutor = processEngineConfiguration.getCommandExecutorTxRequiresNew();
  return new CaseSentryPartQueryImpl(commandExecutor).singleResult();
}
 
Example #24
Source File: ExecutionQueryImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public ExecutionQueryImpl(CommandExecutor commandExecutor) {
  super(commandExecutor);
}
 
Example #25
Source File: AbstractQuery.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public AbstractQuery<T, U> setCommandExecutor(CommandExecutor commandExecutor) {
  this.commandExecutor = commandExecutor;
  return this;
}
 
Example #26
Source File: UpdateProcessInstanceSuspensionStateBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public UpdateProcessInstanceSuspensionStateBuilderImpl(CommandExecutor commandExecutor) {
  this.commandExecutor = commandExecutor;
}
 
Example #27
Source File: ExecuteJobHelper.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
protected static SuccessfulJobListener createSuccessfulJobListener(CommandExecutor commandExecutor) {
  return new SuccessfulJobListener();
}
 
Example #28
Source File: DeleteDeploymentFailListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public DeleteDeploymentFailListener(String deploymentId, ProcessApplicationReference processApplicationReference, CommandExecutor commandExecutor) {
  this.deploymentId = deploymentId;
  this.processApplicationReference = processApplicationReference;
  this.commandExecutor = commandExecutor;
}
 
Example #29
Source File: FailedJobListener.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public FailedJobListener(CommandExecutor commandExecutor, JobFailureCollector jobFailureCollector) {
  this.commandExecutor = commandExecutor;
  this.jobFailureCollector = jobFailureCollector;
}
 
Example #30
Source File: ModificationBuilderImpl.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
public CommandExecutor getCommandExecutor() {
  return commandExecutor;
}