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();
}
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);
}
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());
}
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;
}
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);
}
Aggregations