Published on :

Querying SAS Workload Orchestrator Job Information

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The program uses `PROC HTTP` to connect to the SAS© Workload Orchestrator API with basic authentication. It retrieves JSON data on jobs (all non-archived states), then uses a `LIBNAME JSON` to read this data. Finally, `PROC SQL` is used to join different parts of the JSON information (jobs, processinginfo, request) and create a single table. The results are then displayed via `PROC PRINT`.
Data Analysis

Type : EXTERNAL


Data is retrieved via an authenticated HTTP request to the SAS Workload Orchestrator REST API. The body of the response, in JSON format, is then read and processed as a SAS data source.

1 Code Block
Macro Variables & FILENAME Statements
Explanation :
This block initializes macro variables for authentication (`username`, `pw`) and the base URL (`baseURL`) of the SAS Workload Orchestrator API. It also defines two temporary filerefs, `body` and `headout`, to store the HTTP response body and headers respectively.
Copied!
1%let username = sas;
2%let pw = password;
3%let baseURL = http://wlo-master.demo.sas.com:8901;
4 
5filename body temp;
6filename headout temp;
2 Code Block
PROC HTTP Data
Explanation :
`PROC HTTP` is used to send a GET request to the SAS Workload Orchestrator jobs API. The URL is dynamically constructed with the `baseURL` macro variable and a `state=ALL` parameter to retrieve all non-archived jobs. Basic authentication is handled via `webusername` and `webpassword`. The response body is saved to the `body` fileref and headers to `headout`. An `Accept` header is specified for a specific API JSON format.
Copied!
1PROC HTTP URL="&baseURL/sasgrid/api/jobs?state=ALL" out=body
2headerout=headout headerout_overwrite webusername="&username" webpassword="&pw";
3headers "Accept"="application/vnd.sas.sasgrid.jobs;version=1;charset=utf-8";
4RUN;
3 Code Block
LIBNAME Statement Data
Explanation :
The first `libname jobinfo;` deallocates any existing libname with this name, ensuring a clean reset. The second `libname jobinfo json fileref=body;` creates a SAS library `jobinfo` by interpreting the JSON content of the `body` fileref (which contains the API response) as SAS tables. This makes the JSON data accessible via SAS tables.
Copied!
1LIBNAME jobinfo;
2LIBNAME jobinfo json fileref=body;
3 
4 Code Block
PROC SQL Data
Explanation :
This `PROC SQL` procedure creates a new `jobs` table in the `WORK` library. It performs a complex join between several virtual tables generated by the `LIBNAME JSON` (`jobinfo.jobs`, `jobinfo.jobs_processinginfo`, `jobinfo.jobs_request`) using the `ordinal_jobs` columns. The objective is to consolidate relevant job information (ID, state, queue, times, host, exit code, job name, user, command) into a single view ordered by job ID.
Copied!
1PROC SQL;
2create TABLE jobs as
3 select
4 a.id,
5 b.state, b.queue, b.submitTime, b.startTime, b.endTime,
6 b.processId, b.executionHost, b.exitCode,
7 c.name, c.user, c.cmd from
8 jobinfo.jobs a,
9 jobinfo.jobs_processinginfo b,
10 jobinfo.jobs_request c
11 where a.ordinal_jobs = b.ordinal_jobs and
12 b.ordinal_jobs = c.ordinal_jobs
13 order BY a.id;
14QUIT;
5 Code Block
PROC PRINT
Explanation :
The `PROC PRINT` procedure displays the content of the `work.jobs` table that was previously created, thus presenting the consolidated information on SAS Workload Orchestrator jobs.
Copied!
1PROC PRINT DATA=work.jobs; RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Author: Greg Wootton Date: 02JAN2019


Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« Programmatic access to SAS Workload Orchestrator (SWO) data is essential for administrators who need to automate grid monitoring or create custom performance reports. This script demonstrates a robust method for transforming complex system metrics into actionable datasets within your SAS session. »