public virtual void Execute(IJobHandlerConfiguration configuration, ExecutionEntity execution,
                                    CommandContext commandContext, string tenantId)
        {
            var         config  = (BatchSeedJobConfiguration)configuration;
            var         batchId = config.BatchId;
            BatchEntity batch   = commandContext.BatchManager.FindBatchById(batchId);

            EnsureUtil.EnsureNotNull("Batch with id '" + batchId + "' cannot be found", "batch", batch);

            IBatchJobHandler batchJobHandler =
                commandContext.ProcessEngineConfiguration.BatchHandlers[batch.Type];

            var done = batchJobHandler.CreateJobs(batch);

            if (!done)
            {
                batch.CreateSeedJob();
            }
            else
            {
                // create monitor job initially without due date to
                // enable rapid completion of simple batches
                batch.CreateMonitorJob(false);
            }
        }
Exemple #2
0
 protected internal virtual void CheckAccess(CommandContext commandContext, BatchEntity batch)
 {
     foreach (var checker in commandContext.ProcessEngineConfiguration.CommandCheckers)
     {
         checker.CheckDeleteBatch(batch);
     }
 }
Exemple #3
0
        public override IBatch Execute(CommandContext commandContext)
        {
            IList <AbstractProcessInstanceModificationCommand> instructions = builder.Instructions;
            ICollection <string> processInstanceIds = CollectProcessInstanceIds();

            EnsureUtil.EnsureNotEmpty(typeof(BadUserRequestException), "Restart instructions cannot be empty", "instructions", instructions);
            EnsureUtil.EnsureNotEmpty(typeof(BadUserRequestException), "Process instance ids cannot be empty", "processInstanceIds", processInstanceIds);
            EnsureUtil.EnsureNotContainsNull(typeof(BadUserRequestException), "Process instance ids cannot be null", "processInstanceIds", processInstanceIds);

            commandContext.AuthorizationManager.CheckAuthorization(Permissions.Create, Resources.Batch);
            ProcessDefinitionEntity processDefinition = GetProcessDefinition(commandContext, builder.ProcessDefinitionId);

            EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "Process definition cannot be null", processDefinition);
            EnsureTenantAuthorized(commandContext, processDefinition);

            WriteUserOperationLog(commandContext, processDefinition, processInstanceIds.Count, true);

            List <string> ids = new List <string>();

            ids.AddRange(processInstanceIds);
            BatchEntity batch = CreateBatch(commandContext, instructions, ids, processDefinition);

            batch.CreateSeedJobDefinition();
            batch.CreateMonitorJobDefinition();
            batch.CreateBatchJobDefinition();

            batch.FireHistoricStartEvent();

            batch.CreateSeedJob();
            return(batch);
        }
        public virtual void DeleteJobs(BatchEntity batch)
        {
            //IList<JobEntity> jobs = Context.CommandContext.JobManager.findJobsByJobDefinitionId(batch.BatchJobDefinitionId);

            //foreach (JobEntity job in jobs)
            //{
            //  //job.delete();
            //}
        }
Exemple #5
0
        public virtual object Execute(CommandContext commandContext)
        {
            EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "Batch id must not be null", "batch id", batchId);

            BatchEntity batchEntity = commandContext.BatchManager.FindBatchById(batchId);

            EnsureUtil.EnsureNotNull(typeof(BadUserRequestException), "Batch for id '" + batchId + "' cannot be found",
                                     "batch", batchEntity);

            CheckAccess(commandContext, batchEntity);

            batchEntity.Delete(cascadeToHistory);
            return(null);
        }
        //public abstract JobDeclaration<BatchJobContext, MessageEntity> JobDeclaration {get;}

        public virtual bool CreateJobs(BatchEntity batch)
        {
            throw new NotImplementedException();
            var commandContext = Context.CommandContext;
            //ByteArrayManager byteArrayManager = commandContext.ByteArrayManager;
            //JobManager jobManager = commandContext.JobManager;

            //var configuration = readConfiguration(batch.ConfigurationBytes);

            var batchJobsPerSeed       = batch.BatchJobsPerSeed;
            var invocationsPerBatchJob = batch.InvocationsPerBatchJob;

            //var ids = configuration.Ids;
            //var numberOfItemsToProcess = Math.Min(invocationsPerBatchJob*batchJobsPerSeed, ids.Count);
            // view of process instances to process
            //IList<string> processIds = ids.subList(0, numberOfItemsToProcess);

            var createdJobs = 0;

            //while (processIds.Count > 0)
            //{
            //  int lastIdIndex = Math.Min(invocationsPerBatchJob, processIds.Count);
            //  // view of process instances for this job
            //  IList<string> idsForJob = processIds.subList(0, lastIdIndex);

            //  T jobConfiguration = createJobConfiguration(configuration, idsForJob);
            //  ResourceEntity configurationEntity = saveConfiguration(byteArrayManager, jobConfiguration);

            //  JobEntity job = createBatchJob(batch, configurationEntity);
            //  postProcessJob(configuration, job);
            //  jobManager.insertAndHintJobExecutor(job);

            //  idsForJob.Clear();
            //  createdJobs++;
            //}

            // update created jobs for batch
            batch.JobsCreated = batch.JobsCreated + createdJobs;

            // update batch configuration
            //batch.ConfigurationBytes = writeConfiguration(configuration);

            //return ids.Count == 0;
            return(true);
        }
Exemple #7
0
        protected internal virtual BatchEntity CreateBatch(CommandContext commandContext, IList <AbstractProcessInstanceModificationCommand> instructions, IList <string> processInstanceIds, ProcessDefinitionEntity processDefinition)
        {
            ProcessEngineConfigurationImpl processEngineConfiguration = commandContext.ProcessEngineConfiguration;
            IBatchJobHandler batchJobHandler = GetBatchJobHandler(processEngineConfiguration);

            RestartProcessInstancesBatchConfiguration configuration = new RestartProcessInstancesBatchConfiguration(processInstanceIds, instructions, builder.ProcessDefinitionId, builder.InitialVariables, builder.SkipCustomListeners, builder.SkipIoMappings, builder.WithoutBusinessKey);

            BatchEntity batch = new BatchEntity();

            batch.Type                   = batchJobHandler.Type;
            batch.TotalJobs              = CalculateSize(processEngineConfiguration, configuration);
            batch.BatchJobsPerSeed       = processEngineConfiguration.BatchJobsPerSeed;
            batch.InvocationsPerBatchJob = processEngineConfiguration.InvocationsPerBatchJob;
            batch.ConfigurationBytes     = batchJobHandler.WriteConfiguration(configuration);
            batch.TenantId               = processDefinition.TenantId;
            commandContext.BatchManager.Add(batch);

            return(batch);
        }
        public virtual void Execute(IJobHandlerConfiguration configuration, ExecutionEntity execution,
                                    CommandContext commandContext, string tenantId)
        {
            var         conf    = (BatchMonitorJobConfiguration)configuration;
            var         batchId = conf.BatchId;
            BatchEntity batch   = commandContext.BatchManager.FindBatchById(conf.BatchId);

            EnsureUtil.EnsureNotNull("Batch with id '" + batchId + "' cannot be found", "batch", batch);

            bool completed = batch.Completed;

            if (!completed)
            {
                //batch.CreateMonitorJob(true);
            }
            else
            {
                batch.Delete(false);
            }
        }
        protected internal virtual BatchEntity CreateBatch(CommandContext commandContext, IMigrationPlan migrationPlan,
                                                           ICollection <string> processInstanceIds, ProcessDefinitionEntity sourceProcessDefinition)
        {
            var processEngineConfiguration = commandContext.ProcessEngineConfiguration;
            var batchJobHandler            = getBatchJobHandler(processEngineConfiguration);

            var configuration = new MigrationBatchConfiguration(new List <string>(processInstanceIds), migrationPlan,
                                                                ExecutionBuilder.SkipCustomListenersRenamed, ExecutionBuilder.SkipIoMappingsRenamed);

            var batch = new BatchEntity();

            batch.Type                   = batchJobHandler.Type;
            batch.TotalJobs              = CalculateSize(processEngineConfiguration, configuration);
            batch.BatchJobsPerSeed       = processEngineConfiguration.BatchJobsPerSeed;
            batch.InvocationsPerBatchJob = processEngineConfiguration.InvocationsPerBatchJob;
            batch.ConfigurationBytes     = batchJobHandler.WriteConfiguration(configuration);
            batch.TenantId               = sourceProcessDefinition.TenantId;
            (commandContext.BatchManager).Add(batch);

            return(batch);
        }
Exemple #10
0
 public BatchJobContext(BatchEntity batchEntity, ResourceEntity configuration)
 {
     Batch = batchEntity;
     this.Configuration = configuration;
 }
 protected internal virtual JobEntity CreateBatchJob(BatchEntity batch, ResourceEntity configuration)
 {
     //BatchJobContext creationContext = new BatchJobContext(batch, configuration);
     //return JobDeclaration.createJobInstance(creationContext);
     return(null);
 }