forked from sakaiproject/sakai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SAK-40327 Better auto provisioning of jobs/triggers. (sakaiproject#5796)
* SAK-40327 Added auto provisioning of jobs support. This allows other services to automatically provision jobs and triggers into the scheduler at startup. This uses the standard XML that quartz supports. * SAK-40327 event log purge switch to auto provision Switch the trigger event log to use the newer auto provisioning rather than the spring XML.
- Loading branch information
Showing
10 changed files
with
275 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
jobscheduler/scheduler-component/src/resources/event-log-purge.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version='1.0' encoding='utf-8'?> | ||
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_2_0.xsd" | ||
version="2.0"> | ||
|
||
<processing-directives> | ||
<!-- The UI allows people to change the jobs and we don't want to overwrite those changes --> | ||
<overwrite-existing-data>false</overwrite-existing-data> | ||
<!-- We stop on the first error, this means if you don't like the trigger, just delete it and it won't | ||
make any changes because the job exists --> | ||
<ignore-duplicates>false</ignore-duplicates> | ||
</processing-directives> | ||
|
||
<schedule> | ||
<!-- Put all the jobs in the default group --> | ||
<job> | ||
<!-- This is an old style job that uses our wrapper to get the instance from spring --> | ||
<name>Event Log Purge</name> | ||
<description>Purge the trigger events</description> | ||
<job-class>org.sakaiproject.component.app.scheduler.jobs.SpringStatefulJobBeanWrapper</job-class> | ||
<!-- We make the job durable otherwise when the trigger is removed the job goes and it gets re-created --> | ||
<durability>true</durability> | ||
<recover>false</recover> | ||
<job-data-map> | ||
<entry> | ||
<key>org.sakaiproject.api.app.scheduler.JobBeanWrapper.bean</key> | ||
<value>eventPurgeJob</value> | ||
</entry> | ||
<entry> | ||
<key>org.sakaiproject.api.app.scheduler.JobBeanWrapper.jobType</key> | ||
<value>Event Log Purge</value> | ||
</entry> | ||
</job-data-map> | ||
</job> | ||
|
||
<trigger> | ||
<cron> | ||
<name>Nightly Log Purge Trigger</name> | ||
<job-name>Event Log Purge</job-name> | ||
<job-data-map> | ||
<entry> | ||
<key>number.days</key> | ||
<value>7</value> | ||
</entry> | ||
</job-data-map> | ||
<!-- Every 5 minutes --> | ||
<cron-expression>0 0 0 * * ? *</cron-expression> | ||
</cron> | ||
</trigger> | ||
</schedule> | ||
</job-scheduling-data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>scheduler</artifactId> | ||
<groupId>org.sakaiproject.scheduler</groupId> | ||
<version>19-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.sakaiproject.scheduler</groupId> | ||
<artifactId>scheduler-utils</artifactId> | ||
<name>Sakai Job Scheduler Utils </name> | ||
<description>This holds the code for the automatic provsioning of jobs and triggers at startup. It needs to be | ||
in the classloader that holds the XML for configuring the jobs.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.sakaiproject.kernel</groupId> | ||
<artifactId>sakai-kernel-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.sakaiproject.scheduler</groupId> | ||
<artifactId>scheduler-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.quartz-scheduler</groupId> | ||
<artifactId>quartz</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
67 changes: 67 additions & 0 deletions
67
jobscheduler/scheduler-utils/src/java/org/sakaiproject/scheduler/util/AutoProvisionJobs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.sakaiproject.scheduler.util; | ||
|
||
import lombok.Setter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.quartz.ObjectAlreadyExistsException; | ||
import org.quartz.Scheduler; | ||
import org.quartz.SchedulerException; | ||
import org.quartz.simpl.CascadingClassLoadHelper; | ||
import org.quartz.spi.ClassLoadHelper; | ||
import org.quartz.xml.ValidationException; | ||
import org.quartz.xml.XMLSchedulingDataProcessor; | ||
import org.sakaiproject.api.app.scheduler.SchedulerManager; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
import javax.xml.xpath.XPathException; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.text.ParseException; | ||
import java.util.List; | ||
|
||
/** | ||
* This allows quartz jobs to be automatically provisioned at startup. It has the advantage over the | ||
* builtin Spring Quartz support of optionally not overwriting any changes that are made. This is in a JAR as | ||
* there's no way to load resources from a component apart from having a class in there. | ||
* Although SchedulerManagerImpl can automatically provision jobs these have to be in the job scheduler and can't | ||
* be in other projects. So in the future this method is preferred. | ||
* | ||
* @see XMLSchedulingDataProcessor | ||
*/ | ||
@Slf4j | ||
public class AutoProvisionJobs { | ||
|
||
@Setter | ||
private SchedulerManager schedulerManager; | ||
|
||
@Setter | ||
private List<String> files; | ||
|
||
public void init() throws ParserConfigurationException, XPathException, ParseException, IOException, ValidationException, SchedulerException, SAXException, ClassNotFoundException { | ||
|
||
boolean noFiles = files == null || files.isEmpty(); | ||
if (noFiles || !schedulerManager.isAutoProvisioning()) { | ||
log.info("Not auto provisioning jobs: "+ ((noFiles)?"no files.":String.join(", ", files))); | ||
return; | ||
} | ||
|
||
Scheduler scheduler = schedulerManager.getScheduler(); | ||
ClassLoadHelper clh = new CascadingClassLoadHelper(); | ||
clh.initialize(); | ||
|
||
for (String file : files ) { | ||
XMLSchedulingDataProcessor proc = new XMLSchedulingDataProcessor(clh); | ||
InputStream in = getClass().getResourceAsStream(file); | ||
if (in == null) { | ||
throw new IllegalArgumentException("Couldn't find resource on classpath: "+ file); | ||
} | ||
try { | ||
proc.processStreamAndScheduleJobs(in, file, scheduler); | ||
log.info("Successfully provisioned jobs/triggers from :"+ file); | ||
} catch (ObjectAlreadyExistsException e) { | ||
log.info("Not fully processing: "+ file+ " because some parts already exist"); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.