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