Search in sources :

Example 1 with IdmLongRunningTaskDto

use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.

the class LongRunningTaskExecuteDependentProcessor method process.

@Override
public EventResult<IdmLongRunningTaskDto> process(EntityEvent<IdmLongRunningTaskDto> event) {
    IdmLongRunningTaskDto longRunningTask = event.getContent();
    IdmScheduledTaskDto scheduledTask = service.findByLongRunningTaskId(longRunningTask.getId());
    if (scheduledTask == null) {
        LOG.debug("Ecexute dependent tasks is supported for scheduled tasks. LRT [{}] does not have scheduled task.", longRunningTask.getId());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    List<IdmDependentTaskTrigger> dependentTasks = dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName());
    if (dependentTasks.isEmpty()) {
        LOG.trace("Task [{}] has not dependent tasks.", longRunningTask.getId());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    // 
    if (longRunningTask.getResultState() != OperationState.EXECUTED) {
        LOG.debug("Task [{}] was not successfully executed. Dependent tasks [{}] will not be executed.", longRunningTask.getId(), dependentTasks.size());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    // find all triggers by quartz task name = job detail name. Default group is supported now only
    dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName()).forEach(dependentTaskTrigger -> {
        LOG.info("Scheduled task [{}] ended. Dependent task [{}] will be executed in dryRun [{}].", dependentTaskTrigger.getInitiatorTaskId(), dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
        schedulerManager.runTask(dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
    });
    return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.EXECUTED)).build();
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 2 with IdmLongRunningTaskDto

use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmLongRunningTaskService method create.

@Override
@Transactional()
public IdmLongRunningTaskDto create(IdmScheduledTaskDto scheduledTask, SchedulableTaskExecutor<?> taskExecutor, String instanceId) {
    IdmLongRunningTaskDto task = new IdmLongRunningTaskDto();
    task.setTaskType(taskExecutor.getName());
    task.setTaskDescription(taskExecutor.getDescription());
    task.setInstanceId(instanceId);
    task.setResult(new OperationResult.Builder(OperationState.CREATED).build());
    task.setScheduledTask(scheduledTask.getId());
    return this.save(task);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IdmLongRunningTaskDto

use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmScheduledTaskService method findByLongRunningTaskId.

@Override
@Transactional(readOnly = true)
public IdmScheduledTaskDto findByLongRunningTaskId(UUID lrtId) {
    Assert.notNull(lrtId);
    // 
    IdmLongRunningTaskDto lrt = lrtService.get(lrtId);
    // 
    return lrt.getScheduledTask() == null ? null : this.get(lrt.getScheduledTask());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmLongRunningTaskDto

use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.

the class DefaultLongRunningTaskManager method getValidTask.

/**
 * Returns executor's LRT task, when task is valid. Throws exception otherwise.
 *
 * @param taskExecutor
 * @return
 */
private IdmLongRunningTaskDto getValidTask(LongRunningTaskExecutor<?> taskExecutor) {
    IdmLongRunningTaskDto task = service.get(taskExecutor.getLongRunningTaskId());
    Assert.notNull(task);
    // 
    if (!task.getInstanceId().equals(configurationService.getInstanceId())) {
        throw new ResultCodeException(CoreResultCode.LONG_RUNNING_TASK_DIFFERENT_INSTANCE, ImmutableMap.of("taskId", task.getId(), "taskInstanceId", task.getInstanceId(), "currentInstanceId", configurationService.getInstanceId()));
    }
    taskExecutor.validate(task);
    return task;
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 5 with IdmLongRunningTaskDto

use of eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto in project CzechIdMng by bcvsolutions.

the class RemoveAutomaticRoleTaskExecutor method saveResult.

private void saveResult(ResultModel resultModel, OperationState state, Exception ex) {
    IdmLongRunningTaskDto task = longRunningTaskService.get(getLongRunningTaskId());
    task.setResult(new OperationResult.Builder(state).setModel(resultModel).setCause(ex).build());
    // 
    // TODO: skips event about task ends with exception
    getLongRunningTaskService().save(task);
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)

Aggregations

IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)56 Test (org.junit.Test)32 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)29 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)14 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)13 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)13 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)7 LocalDate (org.joda.time.LocalDate)6 LongRunningFutureTask (eu.bcvsolutions.idm.core.scheduler.api.dto.LongRunningFutureTask)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)4 Task (eu.bcvsolutions.idm.core.scheduler.api.dto.Task)4 UUID (java.util.UUID)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)3