JobScheduler can implement job processing in various languages. Most of them are described in shell and implemented easily, but in shell, it is inconvenient to do a little elaborate things such as not being able to call JobScheduler's internal API. In this article, I will introduce how to implement it in Java.
As below It inherits the Job_impl class in the sos.spooler package and implements the Java class.
SimpleJobApiExample.java
package sample.test;
import sos.spooler.*;
public class SimpleJobApiExample extends Job_impl {
@Override
public boolean spooler_process() throws Exception {
spooler_log.info("Hello world!");
return false;
}
}
See documentation for available package classes. http://www.sos-berlin.com/doc/doxygen-docs/SOSJobSchedulerModel/html/index.html
After creating it, compile it as follows.
sample/test/SimpleJobApiExample.java Against
$ cd sample/test
$ javac -classpath .:/opt/sos-berlin.com/jobscheduler/scheduler/lib/sos/com.sos-berlin.jobscheduler.engine-1.11.3.jar SimpleJobApiExample.java
Create Manifest.txt
$ cd ../../
$ vim Manifest.txt
Manifest-Vwersion: 1.0
Main-Class: sample.test.SimpleJobApiExample
Class-Path: /opt/sos-berlin.com/jobscheduler/scheduler/lib/sos/*
jar file creation
$ jar cvfm SimpleJobApiExample.jar Manifest.txt sample/test/*.class
Place the jar file created above in a classpath that JobScheduler can recognize.
The classpath that JobScheduler Master recognizes as the read destination is in the [java] category described in factory.ini. The following settings.
[java]
class_path = ${SCHEDULER_HOME}/lib/pgsql/*.jar:${SCHEDULER_HOME}/lib/patches/*.jar:${SCHEDULER_HOME}/lib/user_lib/*.jar:${SCHEDULER_HOME}/lib/sos/*.jar:${SCHEDULER_HOME}/lib/3rd-party/*.jar:${SCHEDULER_HOME}/lib/jdbc/*.jar:${SCHEDULER_DATA}/config:${SCHEDULER_HOME}/lib/log/log4j/*.jar
If you want to place it in a place different from the above default, you need to change the above setting. If you do not need to change it, it is appropriate to place it below.
Under /opt/sos-berlin.com/jobscheduler/scheduler/lib/user_lib/
$ cp SimpleJobApiExample.jar /opt/sos-berlin.com/jobscheduler/scheduler/lib/user_lib
If multiple JobScheduler Masters are clustered, place them in the classpath folder on all Master servers.
Implement the job as follows with the jar file placed as described above.
<job title="Simple Java API Job" order="no">
<script language="Java" java_class_path="/opt/sos-berlin.com/jobscheduler/scheduler/lib/user_lib" java_class="sample.test.SimpleJobApiExample"/>
<run_time/>
</job>
With the above settings, the sample.test.SimpleJobApiExample class will be called. Processes such as spooler_process () implemented in the class are automatically executed. If you want to place it in a place different from the default classpath of JobScheduler Master, add java_class_path setting as follows.
<job title="Simple Java API Job" order="no">
<script language="Java" java_class_path="/hoge/lib/*.jar" java_class="sample.test.SimpleJobApiExample"/>
<run_time/>
</job>
However, the above java_class_path will be added to the class_path setting of the existing JobScheduler Master to specify the folder to be searched, so If the one with the same name is placed in the class_path of JobScheduler Master, that will be read with priority, so be careful.
Recommended Posts