Introduction
The JS7 - REST Web Service API allows to perform any sort of operation on the lifecycle of scheduling objects such as creating, deploying, running, stopping workflows and jobs.
The REST Web Service API is available from JOC Cockpit. When used by jobs then the jobs are required to implement a REST client implementing the functionality to login and to logout from JOC Cockpit.
In order to reduce the overhead of REST client implementation a JavaScript class is suggested that can be used by any number of JavaScript jobs.
JavaScript Class
A JavaScript class is suggested that
- connects to JOC Cockpit,
- performs login and logout to/from JOC Cockpit from the methods
signIn( user, password )
signOut()
- performs arbitrary calls to the REST Web Service API from the method
post( path, headers )
For re-usability users can add the JavaScript class to a JS7 - Script Include that can be included by any number of jobs. Changes to the Script Include will be reflected with the next deployment of workflows.
Download JavaScript class from Script Include (upload .json): JavaScript-JS7RestApi.includescript.json
Find the source code of the JavaScript class:
JavaScript Job
A JavaScript job can make use of the JavaScript class provided by the Script Include:
- The following syntax makes the Script Include available:
//!include JavaScript-JS7RestApi
- The JavaScript class can be instantiated from the job like this:
let api = new JS7RestApi(url, controllerId);
Download JavaScript job from Workflow (upload .json): pdJavaScriptJS7RestAPI.workflow.json
Find the source code of the job script:
//!include JavaScript-JS7RestApi class JS7Job extends js7.Job { processOrder(js7Step) { const url = 'http://localhost:4446'; const controllerId = 'controller'; const account = 'root'; const password = 'root'; let api = new JS7RestApi(url, controllerId); // call the signIn function with the provided user account and password api.signIn(account, password); // get curent account's permissions for JOC Cockpit operations api.getJocCockpitPermissions(); // call the signOut function to log out and to invalidate the access token api.signOut(); } }