if (task == null) {
throw new NotFoundException("Task " + taskId);
}
TaskUtil taskUtil = getTaskUtil(task);
TaskExecTO result = null;
LOG.debug("Execution started for {}", task);
switch (taskUtil) {
case PROPAGATION:
final TaskExec propExec = propagationManager.execute((PropagationTask) task);
result = binder.getTaskExecTO(propExec);
break;
case NOTIFICATION:
final TaskExec notExec = notificationManager.execute((NotificationTask) task);
result = binder.getTaskExecTO(notExec);
break;
case SCHED:
case SYNC:
try {
jobInstanceLoader.registerJob(task, ((SchedTask) task).getJobClassName(), ((SchedTask) task).
getCronExpression());
JobDataMap map = new JobDataMap();
map.put(AbstractTaskJob.DRY_RUN_JOBDETAIL_KEY, dryRun);
scheduler.getScheduler().triggerJob(JobInstanceLoader.getJobName(task), Scheduler.DEFAULT_GROUP,
map);
} catch (Exception e) {
LOG.error("While executing task {}", task, e);
auditManager.audit(Category.task, TaskSubCategory.execute, Result.failure,
"Could not start execution for task: " + task.getId() + "/" + taskUtil, e);
SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(
HttpStatus.BAD_REQUEST);
SyncopeClientException sce = new SyncopeClientException(SyncopeClientExceptionType.Scheduling);
sce.addElement(e.getMessage());
scce.addException(sce);
throw scce;
}
result = new TaskExecTO();
result.setTask(taskId);
result.setStartDate(new Date());
result.setStatus("JOB_FIRED");
result.setMessage("Job fired; waiting for results...");
break;
default:
}
LOG.debug("Execution finished for {}, {}", task, result);