Data is dynamically retrieved via a call to the SAS Workload Orchestrator REST API. The script does not depend on pre-existing data files or SASHELP tables.
1 Code Block
PROC HTTP
Explanation : This block defines connection parameters (username, password, base URL) and initializes temporary files. It then performs a first PROC HTTP call with the POST method to authenticate to the SAS Grid interface and retrieve an authentication cookie in the temporary 'headout' file.
Copied!
/* Provide connection information. */
%let username = sas;
%let pw = password;
%let baseURL = http://sgmg-master.demo.sas.com:8901;
/* Initialize temporary files to capture HTTP response body and headers. */
filename body temp;
filename headout temp;
/* Authenticate and get an auth cookie. */
proc http URL="&baseURL/sasgrid/index.html" method="post"
out=body headerout=headout headerout_overwrite
in="username=&username%nrstr(&password)=&pw";
headers "ContentType"="application/x-www-form-urlencoded";
run;
Explanation : This second PROC HTTP call uses the previously obtained authentication to query the jobs API. It sends a GET request to obtain all non-archived jobs ('state=ALL'). The API response, which is in JSON format, is written to the temporary 'body' file.
Copied!
/* Submit an authenticated query against the jobs API */
/* requesting jobs with a state of "ALL" e.g. any non-archived jobs. */
proc http URL="&baseURL/sasgrid/api/jobs?state=ALL"
out=body headerout=headout headerout_overwrite;
headers "Accept"="application/vnd.sas.sasgrid.jobs;version=1;charset=utf-8";
run;
1
/* Submit an authenticated query against the jobs API */
2
/* requesting jobs with a state of "ALL" e.g. any non-archived jobs. */
Explanation : This block uses the LIBNAME JSON engine to interpret the content of the 'body' file. It creates a virtual SAS library named 'jobinfo' whose tables correspond to the objects found in the JSON file structure.
Copied!
/* Deassign the jobinfo libname. */
libname jobinfo;
/* Read in the job info. */
libname jobinfo json fileref=body;
1
/* Deassign the jobinfo libname. */
2
LIBNAME jobinfo;
3
4
/* Read in the job info. */
5
LIBNAME jobinfo json fileref=body;
4 Code Block
PROC SQL Data
Explanation : This SQL procedure creates a SAS table named 'jobs' in the WORK library. It performs a join on the tables generated from the JSON ('jobinfo.jobs', 'jobinfo.jobs_processinginfo', 'jobinfo.jobs_request') to consolidate relevant information about each job into a single flat table.
Copied!
/* Create a single table with items of interest. */
proc sql;
create table jobs as
select
a.id,
b.state, b.queue, b.submitTime, b.startTime,
b.endTime, b.processId, b.executionHost, b.exitCode,
c.name, c.user, c.cmd
from
jobinfo.jobs a,
jobinfo.jobs_processinginfo b,
jobinfo.jobs_request c
where
a.ordinal_jobs = b.ordinal_jobs and
b.ordinal_jobs = c.ordinal_jobs
order by a.id;
quit;
1
/* Create a single table with items of interest. */
Explanation : Displays the content of the 'work.jobs' table created in the previous step, thus presenting the final job report.
Copied!
/* Print it. */
proc print data=work.jobs; run;
1
/* Print it. */
2
PROC PRINTDATA=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: 30AUG2019
« Using PROC HTTP to interface directly with the SAS Workload Orchestrator (SWO) microservices is a modern, scalable approach to grid administration. This method transforms your SAS session into a powerful monitoring console, allowing you to bypass the GUI to extract real-time data on queue states, node utilization, and job lifecycles. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.