How to implement a job that uses Java API in JobScheduler

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.

Java class implementation

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

Compile & jar file creation

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 jar file in classpath

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.

Job definition implementation

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

How to implement a job that uses Java API in JobScheduler
How to implement date calculation in Java
How to implement Kalman filter in Java
How to implement coding conventions in Java
How to display a web page in Java
A bat file that uses Java in windows
How to implement a like feature in Rails
How to implement optimistic locking in REST API
How to test a private method in Java and partially mock that method
[Java] Implement a function that uses a class implemented in the Builder pattern
How to implement a like feature in Ajax in Rails
How to create a data URI (base64) in Java
How to store Rakuten API data in a table
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
Summary of how to implement default arguments in Java
[Java] How to implement multithreading
How to store a string from ArrayList to String in Java (Personal)
How to call and use API in Java (Spring Boot)
How to develop and register a Sota app in Java
How to simulate uploading a post-object form to OSS in Java
3 Implement a simple interpreter in Java
How to make a Java container
How to learn JAVA in 7 days
[Java] How to create a folder
How to use classes in Java?
How to name variables in Java
Try to implement Yubaba in Java
How to make a Java array
How to concatenate strings in java
How to batch initialize arrays in Java that I didn't know when I was a beginner
How to create a new Gradle + Java + Jar project in Intellij 2016.03
How to automatically operate a screen created in Java on Windows
How to run a job with docker login in AWS batch
How to make a Java calendar Summary
How to implement search functionality in Rails
Multilingual Locale in Java How to use Locale
Implement API Gateway Lambda Authorizer in Java Lambda
Try to implement n-ary addition in Java
How to insert a video in Rails
How to do base conversion in Java
[Introduction to Java] How to write a Java program
How to make a Discord bot (Java)
How to make a key pair of ecdsa in a format that can be read by Java
How to embed Janus Graph in Java
How to print a Java Word document
How to get the date in java
Implement something like a stack in Java
How to implement ranking functionality in Rails
How to implement asynchronous processing in Outsystems
How to publish a library in jCenter
How to implement a slideshow using slick in Rails (one by one & multiple by one)
[Personal memo] How to interact with a random number generator in Java
How to pass a proxy when throwing REST over SSL in Java
How to get the absolute path of a directory running in Java
[Java] [For beginners] How to insert elements directly in a 2D array
Try to create a bulletin board in Java
I tried to implement deep learning in Java
How to create a class that inherits class information
How to get Class from Element in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java