Getting Started With Quartz Scheduler Locality API
Terracotta Quartz Scheduler Where introduces an Enterprise feature that allows jobs and triggers to be run on specified Terracotta clients instead of randomly chosen ones. Quartz Scheduler Where is a locality API that can be used to direct jobs to nodes having enough resources or the relevant data for successfully executing those jobs. Also introduced with Quartz 2.0 is a more readable fluent-interface approach to creating and scheduling jobs and triggers.
This section shows you how to install, configure, and use the locality API.
Installation
To access the Quartz Scheduler Locality API in a standard installation, include quartz-terracotta-ee-2.0.0-SNAPSHOT.jar in your classpath. This jar is found under the ${TERRACOTTA_HOME}/quartz
directory.
For DSO installation, see this.
Configuration
-
Set the Enterprise Terracotta JobStore in
quartz.properties
:org.quartz.jobStore.class = org.terracotta.quartz.EnterpriseTerracottaJobStore
- Create or choose an implementation of
org.quartz.spi.InstanceIdGenerator
to generate node IDs to be used in the locality configuration. You can choose from one of the provided classes:- org.quartz.simpl.HostnameInstanceIdGenerator – Returns the hostname as the instanceId.
- org.quartz.simpl.SimpleInstanceIdGenerator – Returns a mix of hostname and timestamp (to be sure we have a unique name), default!
-
org.quartz.simpl.SystemPropertyInstanceIdGenerator – Returns the value of the
org.quartz.scheduler.instanceId
system property of the JVM. Available with Quartz 2.0 or higher.
The generator class must be specified inquartz.properties
:org.quartz.jobStore.class = org.terracotta.quartz.EnterpriseTerracottaJobStore
- Configure the trigger and nodes (Terracotta clients) in
quartzLocality.properties
. For example:
Any job with a trigger in the "slowTriggers" group will fire only on nodes in the group "slowJobs", while jobs with triggers in "fastTriggers" will fire only on nodes in the group "group1".
quartzLocality.properties
must be on the classpath, the same asquartz.properties
.
Use in Application Code
The following example is a code snippet that uses Quartz Scheduler Where to create a locality-aware trigger and a locality-aware job.
This example showed how memory and node-group constraints are used to route locality-aware triggers and jobs. trigger2, for example, is set to fire myJob2 on a node in a specific group (“allNodes”) with a specified minimum amount of free memory. A constraint based on operating system (Linux, Microsoft Windows, Apple OSX, and Oracle Solaris) is also available.
Locality With the Standard Quartz Scheduler API
It is also possible to add locality to jobs and triggers created with the standard Quartz Scheduler API by assigning the triggers to a trigger group specified in quartzLocality.properties
.
DSO Installation
DSO users must install tim-quartz-2.0-ee. First, add the TIM to your Terracotta configuration file (tc-config.xml
by default):
…
…
To install the TIMs declared in the Terracotta configuration file, use the following command (UNIX/Linux):
${TERRACOTTA_HOME}/bin/tim-get.sh install-for /path/to/tc-config.xml
Use tim-get.bat
with Microsoft Windows.