Search in sources :

Example 1 with NotificationJob

use of org.apache.syncope.core.provisioning.java.job.notification.NotificationJob in project syncope by apache.

the class JobManagerImpl method load.

@Transactional
@Override
public void load() {
    if (disableQuartzInstance) {
        String instanceId = "AUTO";
        try {
            instanceId = scheduler.getScheduler().getSchedulerInstanceId();
            scheduler.getScheduler().standby();
            LOG.info("Successfully put Quartz instance {} in standby", instanceId);
        } catch (SchedulerException e) {
            LOG.error("Could not put Quartz instance {} in standby", instanceId, e);
        }
        return;
    }
    final Pair<String, Long> conf = AuthContextUtils.execWithAuthContext(SyncopeConstants.MASTER_DOMAIN, () -> {
        String notificationJobCronExpression = StringUtils.EMPTY;
        Optional<? extends CPlainAttr> notificationJobCronExp = confDAO.find("notificationjob.cronExpression");
        if (!notificationJobCronExp.isPresent()) {
            notificationJobCronExpression = NotificationJob.DEFAULT_CRON_EXP;
        } else if (!notificationJobCronExp.get().getValuesAsStrings().isEmpty()) {
            notificationJobCronExpression = notificationJobCronExp.get().getValuesAsStrings().get(0);
        }
        long interruptMaxRetries = confDAO.find("tasks.interruptMaxRetries", 1L);
        return Pair.of(notificationJobCronExpression, interruptMaxRetries);
    });
    for (String domain : domainsHolder.getDomains().keySet()) {
        AuthContextUtils.execWithAuthContext(domain, () -> {
            // 1. jobs for SchedTasks
            Set<SchedTask> tasks = new HashSet<>(taskDAO.<SchedTask>findAll(TaskType.SCHEDULED));
            tasks.addAll(taskDAO.<PullTask>findAll(TaskType.PULL));
            tasks.addAll(taskDAO.<PushTask>findAll(TaskType.PUSH));
            boolean loadException = false;
            for (Iterator<SchedTask> it = tasks.iterator(); it.hasNext() && !loadException; ) {
                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;
                }
            }
            if (loadException) {
                LOG.debug("Errors while loading job instances for tasks, aborting");
            } else {
                // 2. jobs for Reports
                for (Iterator<Report> it = reportDAO.findAll().iterator(); it.hasNext() && !loadException; ) {
                    Report report = it.next();
                    try {
                        register(report, null, conf.getRight());
                    } catch (Exception e) {
                        LOG.error("While loading job instance for report " + report.getName(), e);
                        loadException = true;
                    }
                }
                if (loadException) {
                    LOG.debug("Errors while loading job instances for reports, aborting");
                }
            }
            return null;
        });
    }
    Map<String, Object> jobMap = new HashMap<>();
    jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());
    // 3. NotificationJob
    if (StringUtils.isBlank(conf.getLeft())) {
        LOG.debug("Empty value provided for {}'s cron, not registering anything on Quartz", NotificationJob.class.getSimpleName());
    } else {
        LOG.debug("{}'s cron expression: {} - registering Quartz job and trigger", NotificationJob.class.getSimpleName(), conf.getLeft());
        try {
            NotificationJob job = createSpringBean(NotificationJob.class);
            registerJob(NOTIFICATION_JOB.getName(), job, conf.getLeft(), null, jobMap);
        } catch (Exception e) {
            LOG.error("While loading {} instance", NotificationJob.class.getSimpleName(), e);
        }
    }
    // 4. SystemLoadReporterJob (fixed schedule, every minute)
    LOG.debug("Registering {}", SystemLoadReporterJob.class);
    try {
        SystemLoadReporterJob job = createSpringBean(SystemLoadReporterJob.class);
        registerJob("systemLoadReporterJob", job, "0 * * * * ?", null, jobMap);
    } catch (Exception e) {
        LOG.error("While loading {} instance", SystemLoadReporterJob.class.getSimpleName(), e);
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) Report(org.apache.syncope.core.persistence.api.entity.Report) HashMap(java.util.HashMap) NotificationJob(org.apache.syncope.core.provisioning.java.job.notification.NotificationJob) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SQLException(java.sql.SQLException) SchedulerException(org.quartz.SchedulerException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) SchedTask(org.apache.syncope.core.persistence.api.entity.task.SchedTask) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)1 Report (org.apache.syncope.core.persistence.api.entity.Report)1 SchedTask (org.apache.syncope.core.persistence.api.entity.task.SchedTask)1 NotificationJob (org.apache.syncope.core.provisioning.java.job.notification.NotificationJob)1 SchedulerException (org.quartz.SchedulerException)1 BeanCreationException (org.springframework.beans.factory.BeanCreationException)1 Transactional (org.springframework.transaction.annotation.Transactional)1