SchedTask task = it.next(); try { register(task, task.getStartAt(), conf.getRight()); } catch (Exception e) { LOG.error("While loading job instance for task " + task.getKey(), e);
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_CREATE + "')") public <T extends SchedTaskTO> T createSchedTask(final TaskType type, final T taskTO) { TaskUtils taskUtils = taskUtilsFactory.getInstance(taskTO); if (taskUtils.getType() != type) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest); sce.getElements().add("Found " + type + ", expected " + taskUtils.getType()); throw sce; } SchedTask task = binder.createSchedTask(taskTO, taskUtils); task = taskDAO.save(task); try { jobManager.register( task, task.getStartAt(), confDAO.find("tasks.interruptMaxRetries", 1L)); } catch (Exception e) { LOG.error("While registering quartz job for task " + task.getKey(), e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling); sce.getElements().add(e.getMessage()); throw sce; } return binder.getTaskTO(task, taskUtils, false); }
@PreAuthorize("hasRole('" + StandardEntitlement.TASK_UPDATE + "')") public <T extends SchedTaskTO> T updateSchedTask(final TaskType type, final SchedTaskTO taskTO) { SchedTask task = taskDAO.find(taskTO.getKey()); if (task == null) { throw new NotFoundException("Task " + taskTO.getKey()); } TaskUtils taskUtils = taskUtilsFactory.getInstance(task); if (taskUtils.getType() != type) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRequest); sce.getElements().add("Found " + type + ", expected " + taskUtils.getType()); throw sce; } binder.updateSchedTask(task, taskTO, taskUtils); task = taskDAO.save(task); try { jobManager.register( task, task.getStartAt(), confDAO.find("tasks.interruptMaxRetries", 1L)); } catch (Exception e) { LOG.error("While registering quartz job for task " + task.getKey(), e); SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling); sce.getElements().add(e.getMessage()); throw sce; } return binder.getTaskTO(task, taskUtils, false); }
private void fill(final SchedTaskTO schedTaskTO, final SchedTask schedTask) { schedTaskTO.setName(schedTask.getName()); schedTaskTO.setDescription(schedTask.getDescription()); schedTaskTO.setStart(schedTask.getStartAt()); schedTaskTO.setCronExpression(schedTask.getCronExpression()); schedTaskTO.setActive(schedTask.isActive()); schedTaskTO.setLastExec(schedTaskTO.getStart()); String triggerName = JobNamer.getTriggerName(JobNamer.getJobKey(schedTask).getName()); try { Trigger trigger = scheduler.getScheduler().getTrigger(new TriggerKey(triggerName, Scheduler.DEFAULT_GROUP)); if (trigger != null) { schedTaskTO.setLastExec(trigger.getPreviousFireTime()); schedTaskTO.setNextExec(trigger.getNextFireTime()); } } catch (SchedulerException e) { LOG.warn("While trying to get to " + triggerName, e); } if (schedTaskTO instanceof ProvisioningTaskTO && schedTask instanceof ProvisioningTask) { ProvisioningTaskTO provisioningTaskTO = (ProvisioningTaskTO) schedTaskTO; ProvisioningTask provisioningTask = (ProvisioningTask) schedTask; provisioningTaskTO.setResource(provisioningTask.getResource().getKey()); provisioningTaskTO.getActions().addAll( provisioningTask.getActions().stream().map(Entity::getKey).collect(Collectors.toList())); provisioningTaskTO.setPerformCreate(provisioningTask.isPerformCreate()); provisioningTaskTO.setPerformUpdate(provisioningTask.isPerformUpdate()); provisioningTaskTO.setPerformDelete(provisioningTask.isPerformDelete()); provisioningTaskTO.setSyncStatus(provisioningTask.isSyncStatus()); } }