Search in sources :

Example 1 with DryRunNotSupportedException

use of eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException in project CzechIdMng by bcvsolutions.

the class DefaultSchedulerManager method createTrigger.

@Override
public AbstractTaskTrigger createTrigger(String taskId, AbstractTaskTrigger trigger, boolean dryRun) {
    Assert.notNull(taskId);
    Assert.notNull(trigger);
    // 
    // task has to support dry run mode
    Task task = getTask(taskId);
    Assert.notNull(task);
    if (dryRun && !task.isSupportsDryRun()) {
        throw new DryRunNotSupportedException(task.getTaskType().getCanonicalName());
    }
    // 
    String triggerId = Key.createUniqueName(taskId);
    trigger.setId(triggerId);
    trigger.setTaskId(taskId);
    // TODO use of visitor pattern may be good
    if (trigger instanceof CronTaskTrigger) {
        createTriggerInternal(taskId, (CronTaskTrigger) trigger, dryRun);
    } else if (trigger instanceof SimpleTaskTrigger) {
        createTriggerInternal(taskId, (SimpleTaskTrigger) trigger, dryRun);
    } else if (trigger instanceof DependentTaskTrigger) {
        createTriggerInternal(taskId, (DependentTaskTrigger) trigger);
    } else {
        throw new SchedulerException(CoreResultCode.SCHEDULER_UNSUPPORTED_TASK_TRIGGER, ImmutableMap.of("trigger", trigger.getClass()));
    }
    return trigger;
}
Also used : Task(eu.bcvsolutions.idm.core.scheduler.api.dto.Task) SchedulerException(eu.bcvsolutions.idm.core.scheduler.exception.SchedulerException) DependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) DryRunNotSupportedException(eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException) CronTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger) SimpleTaskTrigger(eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger)

Example 2 with DryRunNotSupportedException

use of eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException in project CzechIdMng by bcvsolutions.

the class AbstractSchedulableStatefulExecutor method processCandidate.

private void processCandidate(DTO candidate, boolean dryRun) {
    if (isInProcessedQueue(candidate)) {
        // item was processed earlier - just drop the count by one
        --count;
        return;
    }
    Optional<OperationResult> result;
    if (dryRun) {
        if (!supportsDryRun()) {
            throw new DryRunNotSupportedException(getName());
        }
        // dry run mode - operation is not executed with dry run code (no content)
        result = Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.DRY_RUN)).build());
    } else {
        result = this.processItem(candidate);
    }
    // 
    if (result.isPresent()) {
        OperationResult opResult = result.get();
        this.logItemProcessed(candidate, opResult);
        if (OperationState.isSuccessful(opResult.getState())) {
            ++counter;
            this.addToProcessedQueue(candidate, opResult);
        }
        LOG.debug("Statefull process [{}] intermediate result: [{}], count: [{}/{}]", getClass().getSimpleName(), opResult, count, counter);
    } else {
        ++counter;
        LOG.debug("Statefull process [{}] processed item [{}] without result.", getClass().getSimpleName(), candidate);
    }
}
Also used : DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) DryRunNotSupportedException(eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Aggregations

DryRunNotSupportedException (eu.bcvsolutions.idm.core.scheduler.api.exception.DryRunNotSupportedException)2 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)1 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 CronTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.CronTaskTrigger)1 DependentTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.DependentTaskTrigger)1 SimpleTaskTrigger (eu.bcvsolutions.idm.core.scheduler.api.dto.SimpleTaskTrigger)1 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)1 IdmDependentTaskTrigger (eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger)1 SchedulerException (eu.bcvsolutions.idm.core.scheduler.exception.SchedulerException)1