Try using JobScheduler's REST-API
We have summarized the knowledge gained so far about JobScheduler of SOS, which was used for the first time at work from the middle of last month. The appeal of JobScheduler is that it is programmable and multifunctional, and there is plenty of room for Mashup. There are many good points unique to OSS, and when you touch it, it will sprout. It is also wonderful that Chairman Funai of the User Group and everyone are kind and enthusiastic about popularization. I also wanted to disseminate information so that this charming job management tool would become a little more popular in Japan.
Here is a sample RestClient for REST-API (JASON based) functions added from the latest version. I made a template of RestClient that performs the following processing.
・ Authentication (Make a basic authentication request and get an AccesToken) -Issue a request to REST-API (Issuing a request to acquire order information from RescClient using AccessToken) ・ Parsing the returned value (Parse return value with JSON format hierarchy)
Compared to a script language such as Python, which has a good undercarriage, implementing it in Java seems to be troublesome. By introducing a convenient library, it can be implemented in a fairly short man-hour. I wrote a simple code that can be easily tried by basic engineers who do not usually have much opportunity to program Java.
【REST-API】 Please refer to the following for the REST-API specifications used this time.
This is a list of REST-API reception URLs that can get a View of all system information of JobScheduler. http://test.sos-berlin.com/JOC/raml-doc/JOC-API/
Click here for detailed I / F information of REST-API to acquire order information. http://test.sos-berlin.com/JOC.1.11.0/raml-doc/JOC-API/resource/orders.html
Regarding the REST-API I / F for authentication, this article was very easy to understand. https://qiita.com/ike_dai/items/8eb4a542aa59937a5f64
Built on VirtualBox (CentOS-7-x86_64-Minimal-1708.iso)
・ JobScheduler: (1.11.4) ・ OS: RHEL Ver7.3 -DB: PostgreSQL 9.6.X -Java: JDK1.8.0_152-b16
Introduced "jersey" for RestClient implementation Introduced "json" for parsing JSON format data
・ Jersey-bundle-1.18.jar ・ Jackson-core-2.1.4.jar -Jackson-databind-2.2.0-rc1.jar ・ Jackson-annotations-2.0.0-rc1.jar
Package information and location of the created program.
tmp
└─kaeru
├─ RestClient.java
├─ RestClient.class
├─ RestTest.java
└─ RestTest.class
For the detailed procedure for building the verification environment, refer to the article by Mr. Funai, the chairman of the user group. https://qiita.com/satoruf/items/fd78523c68a7c2a0593e
After building, start JOC (Jetty) and manager.
The source of the main body of RestClient is here.
/tmp/kaeru/RestClient.java https://qiita.com/yatabekaeru/items/b8f03cccfb8b904efe99
When generating a Client for Basic authentication, HTTPBasicAuthFilter is applied. No data settings are required for the request body.
The Client that issues the request after issuing the AccessToken sets the AccessToken in the header field. Data is set in the request body as appropriate according to the various REST-API interface specifications.
When issuing a request to "Orders", the following JASON format character string is set in the request body. 『 { jobschedulerId:"scheduler" } 』
The test class is here.
/tmp/kaeru/RestTest.java https://qiita.com/yatabekaeru/items/06e7d40a12935f107458
Two times, when an Access Token is issued by Basic authentication and a request to REST-API "Orders" Make a POST request to the given URL. The data returned as the latter response is parsed by the JASON parser.
Follow the procedure below to compile. It is a super easy execution environment. You can create a batch process with a simple procedure without a deployment tool.
** ★ Below, connect to the verification environment with a terminal and execute as a scheduler user. ** **
Create a package placement directory.
mkdir /tmp/kaeru
Place the source file.
/tmp/kaeru/RestClient.java
/tmp/kaeru/RestTest.java
Place the additional jar file in any directory. (Example: Under /usr/java/jdk1.8.0_152/ap_lib/, etc.)
Set the CLASSPATH variable to an environment variable.
CLASSPATH=/usr/java/jdk1.8.0_152/ap_lib/jersey-bundle-1.18.jar:/usr/java/jdk1.8.0_152/ap_lib/jackson-core-2.1.4.jar:/usr/java/jdk1.8.0_152/ap_lib/jackson-databind-2.2.0-rc1.jar:/usr/java/jdk1.8.0_152/ap_lib/jackson-annotations-2.0.0-rc1.jar:/usr/java/jdk1.8.0_152/jre/lib:/tmp/
export CLASSPATH
Change to the directory one level above the package directory. (If / tmp / kaeru is a package directory)
cd /tmp
Compile with the javac command
javac kaeru/RestClient.java kaeru/RestTest.java
Grant execute permission.
chmod +x /tmp/kaeru/*.class
The command execution procedure is described below.
** ★ Execute as the scheduler user in the same terminal as the compiled terminal below. ** ** (If you boot from another terminal, reset your CLASSPATH)
Change to the directory one level above the package directory. (If / tmp / kaeru is a package directory)
cd /tmp
Execute the sample program with the following command.
java kaeru.RestTest
[scheduler@localhost tmp]$ java kaeru.RestTest
<Issued Access Token>
*****1cf7ffa4-ab60-4604-a0e8-36d93b7abe95
<JSON format data>
[orderId]: createDailyPlan [job]: /sos/dailyplan/CreateDailyPlan [path]: /sos/dailyplan/CreateDailyPlan,createDailyPlan [status]: PENDING [nextStart]: 2018-01-08T15:01:00Z
[orderId]: MonitorSystem [job]: /sos/notification/SystemNotifier [path]: /sos/notification/SystemNotifier,MonitorSystem [status]: PENDING [nextStart]:
[orderId]: AcknowledgeMonitorSystem [job]: /sos/notification/ResetNotifications [path]: /sos/notification/ResetNotifications,AcknowledgeMonitorSystem [status]: PENDING [nextStart]:
[orderId]: Reporting [job]: /sos/reporting/ReportingAggregation [path]: /sos/reporting/Reporting,Reporting [status]: PENDING [nextStart]:
[orderId]: Cleanup [job]: /sos/notification/CleanupNotifications [path]: /sos/notification/CleanupNotifications,Cleanup [status]: PENDING [nextStart]:
[orderId]: Unskip [job]: /sos/operations/criticalpath/UncriticalJobNodes [path]: /sos/operations/criticalpath/UncriticalJobNodes,Unskip [status]: PENDING [nextStart]:
[orderId]: Skip [job]: /sos/operations/criticalpath/UncriticalJobNodes [path]: /sos/operations/criticalpath/UncriticalJobNodes,Skip [status]: PENDING [nextStart]:
If you want to make it a little more Java-like, prepare a data storage class and mapper and implement object mapping. Creating a set of REST-APIs required for operation and monitoring makes it a nice operation tool.
The JOC also uses Jersey to start the RESTful API service. Placing additional libraries on the PATH referenced by Jetty may not work properly! --This is because version conflicts occur depending on the environment.
** Be sure to place the additional jar files individually so that unrelated services do not refer to them. ** **
So far, I have introduced the REST-API sample program in a hurry. (Please forgive me for the quality of the New Year.)
In addition, I would like to revise the manuscript and upload an article tailored as an actual operation tool.
Recommended Posts