job.setTaskKey(task.getKey()); Implementation jobDelegate = task.getJobDelegate() == null ? task instanceof PullTask ? implementationDAO.find(ImplementationType.TASKJOB_DELEGATE).stream(). findFirst().orElse(null) : null : task.getJobDelegate(); if (jobDelegate == null) { throw new IllegalArgumentException("Task " + task JobNamer.getJobKey(task).getName(), job, task.getCronExpression(), startAt, jobMap);
@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); }
@Override public SchedTask createSchedTask(final SchedTaskTO taskTO, final TaskUtils taskUtils) { Class<? extends TaskTO> taskTOClass = taskUtils.taskTOClass(); if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) { throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass, taskTO.getClass())); } SchedTask task = taskUtils.newTask(); task.setStartAt(taskTO.getStartAt()); task.setCronExpression(taskTO.getCronExpression()); task.setName(taskTO.getName()); task.setDescription(taskTO.getDescription()); task.setActive(taskTO.isActive()); if (taskUtils.getType() == TaskType.SCHEDULED) { Implementation implementation = implementationDAO.find(taskTO.getJobDelegate()); if (implementation == null) { throw new NotFoundException("Implementation " + taskTO.getJobDelegate()); } task.setJobDelegate(implementation); } else if (taskTO instanceof ProvisioningTaskTO) { ProvisioningTaskTO provisioningTaskTO = (ProvisioningTaskTO) taskTO; ExternalResource resource = resourceDAO.find(provisioningTaskTO.getResource()); if (resource == null) { throw new NotFoundException("Resource " + provisioningTaskTO.getResource()); } ((ProvisioningTask) task).setResource(resource); fill((ProvisioningTask) task, provisioningTaskTO); } return task; }
@Override public void updateSchedTask(final SchedTask task, final SchedTaskTO taskTO, final TaskUtils taskUtils) { Class<? extends TaskTO> taskTOClass = taskUtils.taskTOClass(); if (taskTOClass == null || !taskTOClass.equals(taskTO.getClass())) { throw new IllegalArgumentException(String.format("Expected %s, found %s", taskTOClass, taskTO.getClass())); } if (StringUtils.isBlank(taskTO.getName())) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.RequiredValuesMissing); sce.getElements().add("name"); throw sce; } task.setName(taskTO.getName()); task.setDescription(taskTO.getDescription()); task.setCronExpression(taskTO.getCronExpression()); task.setActive(taskTO.isActive()); if (task instanceof ProvisioningTask) { fill((ProvisioningTask) task, (ProvisioningTaskTO) taskTO); } }
task.setName((action == ProvisionAction.DEPROVISION ? "de" : "") + "provision members of group " + group.getName()); task.setActive(true); task.setJobDelegate(jobDelegate); task = taskDAO.save(task); result.setRefKey(task.getKey()); result.setRefDesc(taskDataBinder.buildRefDesc(task)); result.setStart(new Date());
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()); } }
if (!task.isActive()) { LOG.info("Task {} not active, aborting...", taskKey);
@Override public boolean isValid(final SchedTask task, final ConstraintValidatorContext context) { boolean isValid = true; if (task.getCronExpression() != null) { try { new CronExpression(task.getCronExpression()); } catch (ParseException e) { LOG.error("Invalid cron expression '" + task.getCronExpression() + "'", e); isValid = false; context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate( getTemplate(EntityViolationType.InvalidSchedTask, "Invalid cron expression")). addPropertyNode("cronExpression").addConstraintViolation(); } } return isValid; } }
Class<T> clazz = getTaskClassReference(); if (!clazz.isAssignableFrom(task.getClass())) { throw new JobExecutionException("Task " + task.getKey() + " isn't a ProvisioningTask");
@Override public String buildRefDesc(final Task task) { return taskUtilsFactory.getInstance(task).getType().name() + " " + "Task " + task.getKey() + " " + (task instanceof SchedTask ? SchedTask.class.cast(task).getName() : task instanceof PropagationTask ? PropagationTask.class.cast(task).getConnObjectKey() : StringUtils.EMPTY); }
if (schedTask.getJobDelegate() != null) { schedTaskTO.setJobDelegate(schedTask.getJobDelegate().getKey());
case PULL: case PUSH: if (!((SchedTask) task).isActive()) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Scheduling); sce.getElements().add("Task " + key + " is not active");
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); loadException = true;
@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); }