Search in sources :

Example 56 with CommandContext

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

the class DeleteProcessInstancesJobHandler method createJobEntities.

protected void createJobEntities(BatchEntity batch, DeleteProcessInstanceBatchConfiguration configuration, String deploymentId, List<String> processInstancesToHandle, int invocationsPerBatchJob) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    int createdJobs = 0;
    while (!processInstancesToHandle.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processInstancesToHandle.size());
        // view of process instances for this job
        List<String> idsForJob = processInstancesToHandle.subList(0, lastIdIndex);
        DeleteProcessInstanceBatchConfiguration jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        job.setDeploymentId(deploymentId);
        jobManager.insertAndHintJobExecutor(job);
        createdJobs++;
        idsForJob.clear();
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 57 with CommandContext

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

the class AbstractBatchJobHandler method createJobs.

@Override
public boolean createJobs(BatchEntity batch) {
    CommandContext commandContext = Context.getCommandContext();
    ByteArrayManager byteArrayManager = commandContext.getByteArrayManager();
    JobManager jobManager = commandContext.getJobManager();
    T configuration = readConfiguration(batch.getConfigurationBytes());
    int batchJobsPerSeed = batch.getBatchJobsPerSeed();
    int invocationsPerBatchJob = batch.getInvocationsPerBatchJob();
    List<String> ids = configuration.getIds();
    int numberOfItemsToProcess = Math.min(invocationsPerBatchJob * batchJobsPerSeed, ids.size());
    // view of process instances to process
    List<String> processIds = ids.subList(0, numberOfItemsToProcess);
    int createdJobs = 0;
    while (!processIds.isEmpty()) {
        int lastIdIndex = Math.min(invocationsPerBatchJob, processIds.size());
        // view of process instances for this job
        List<String> idsForJob = processIds.subList(0, lastIdIndex);
        T jobConfiguration = createJobConfiguration(configuration, idsForJob);
        ByteArrayEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);
        JobEntity job = createBatchJob(batch, configurationEntity);
        postProcessJob(configuration, job);
        jobManager.insertAndHintJobExecutor(job);
        idsForJob.clear();
        createdJobs++;
    }
    // update created jobs for batch
    batch.setJobsCreated(batch.getJobsCreated() + createdJobs);
    // update batch configuration
    batch.setConfigurationBytes(writeConfiguration(configuration));
    return ids.isEmpty();
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ByteArrayEntity(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayEntity) ByteArrayManager(org.camunda.bpm.engine.impl.persistence.entity.ByteArrayManager) JobManager(org.camunda.bpm.engine.impl.persistence.entity.JobManager)

Example 58 with CommandContext

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

the class BatchEntity method delete.

public void delete(boolean cascadeToHistory) {
    CommandContext commandContext = Context.getCommandContext();
    deleteSeedJob();
    deleteMonitorJob();
    getBatchJobHandler().deleteJobs(this);
    JobDefinitionManager jobDefinitionManager = commandContext.getJobDefinitionManager();
    jobDefinitionManager.delete(getSeedJobDefinition());
    jobDefinitionManager.delete(getMonitorJobDefinition());
    jobDefinitionManager.delete(getBatchJobDefinition());
    commandContext.getBatchManager().delete(this);
    configuration.deleteByteArrayValue();
    fireHistoricEndEvent();
    if (cascadeToHistory) {
        HistoricIncidentManager historicIncidentManager = commandContext.getHistoricIncidentManager();
        historicIncidentManager.deleteHistoricIncidentsByJobDefinitionId(seedJobDefinitionId);
        historicIncidentManager.deleteHistoricIncidentsByJobDefinitionId(monitorJobDefinitionId);
        historicIncidentManager.deleteHistoricIncidentsByJobDefinitionId(batchJobDefinitionId);
        HistoricJobLogManager historicJobLogManager = commandContext.getHistoricJobLogManager();
        historicJobLogManager.deleteHistoricJobLogsByJobDefinitionId(seedJobDefinitionId);
        historicJobLogManager.deleteHistoricJobLogsByJobDefinitionId(monitorJobDefinitionId);
        historicJobLogManager.deleteHistoricJobLogsByJobDefinitionId(batchJobDefinitionId);
        commandContext.getHistoricBatchManager().deleteHistoricBatchById(id);
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) JobDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.JobDefinitionManager) HistoricJobLogManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogManager) HistoricIncidentManager(org.camunda.bpm.engine.impl.persistence.entity.HistoricIncidentManager)

Example 59 with CommandContext

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

the class HistoricProcessInstanceReportImpl method duration.

// report execution /////////////////////////////////////////////
public List<DurationReportResult> duration(PeriodUnit periodUnit) {
    ensureNotNull(NotValidException.class, "periodUnit", periodUnit);
    this.durationPeriodUnit = periodUnit;
    CommandContext commandContext = Context.getCommandContext();
    if (commandContext == null) {
        return commandExecutor.execute(new Command<List<DurationReportResult>>() {

            @Override
            public List<DurationReportResult> execute(CommandContext commandContext) {
                return executeDurationReport(commandContext);
            }
        });
    } else {
        return executeDurationReport(commandContext);
    }
}
Also used : CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ArrayList(java.util.ArrayList) List(java.util.List)

Example 60 with CommandContext

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

the class ProcessApplicationManager method getDeployedProcessDefinitionArtifacts.

protected List<ProcessDefinition> getDeployedProcessDefinitionArtifacts(DeploymentEntity deployment) {
    CommandContext commandContext = Context.getCommandContext();
    // in case deployment was created by this command
    List<ProcessDefinition> entities = deployment.getDeployedProcessDefinitions();
    if (entities == null) {
        String deploymentId = deployment.getId();
        ProcessDefinitionManager manager = commandContext.getProcessDefinitionManager();
        return manager.findProcessDefinitionsByDeploymentId(deploymentId);
    }
    return entities;
}
Also used : ProcessDefinitionManager(org.camunda.bpm.engine.impl.persistence.entity.ProcessDefinitionManager) CommandContext(org.camunda.bpm.engine.impl.interceptor.CommandContext) ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition)

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