94%macro mv_getjoblog(uri=0,outref=0
95 ,access_token_var=ACCESS_TOKEN
96 ,grant_type=sas_services
99%local dbg libref1 libref2 loglocation fname1 fname2;
100%
if &mdebug=1 %then %
do;
101 %put &sysmacroname entry vars:;
107%
if &grant_type=detect %then %
do;
108 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
109 %
else %let grant_type=sas_services;
111%
if &grant_type=sas_services %then %
do;
112 %let oauth_bearer=oauth_bearer=sas_services;
113 %let &access_token_var=;
116%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
117 and &grant_type ne sas_services
120 ,msg=%str(Invalid value
for grant_type: &grant_type)
127 if length(uri)<12 then
do;
128 call symputx(
'errflg',1);
129 call symputx(
'errmsg',
"URI is too short - "!!uri,
'l');
131 if scan(uri,-1)=
'state' or scan(uri,1) ne 'jobExecution' then do;
132 call symputx('errflg',1);
133 call symputx('errmsg',
134 "URI should be in format /jobExecution/jobs/$$$$UUID$$$$"
135 !!" but is actually like:"!!uri,'l');
139%mp_abort(iftrue=(&errflg=1)
144%mp_abort(iftrue=(&outref=0)
146 ,msg=%str(Output fileref should be provided)
149%if %mf_existfileref(&outref) ne 1 %then %do;
150 filename &outref temp;
153options noquotelenmax;
155%let base_uri=%mf_getplatform(VIYARESTAPI);
158%let fname1=%mf_getuniquefileref();
159%let fname2=%mf_getuniquefileref();
160proc http method='GET' out=&fname1 &oauth_bearer
163 %if &grant_type=authorization_code %then %do;
164 "Authorization"="Bearer &&&access_token_var"
168%if &mdebug=1 %then %do;
169 %put &sysmacroname: fetching log loc from &uri;
170 data _null_;infile &fname1;input;putlog _infile_;run;
172%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201 %then
174 data _null_;infile &fname1;input;putlog _infile_;run;
175 %mp_abort(mac=&sysmacroname
176 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
180%let libref1=%mf_getuniquelibref();
181libname &libref1 JSON fileref=&fname1;
184 call symputx('loglocation',loglocation,'l');
189%let errmsg=No loglocation entry in &fname1 fileref;
191 uri=symget('loglocation');
192 if length(uri)<12 then do;
193 call symputx('errflg',1);
194 call symputx('errmsg',"URI is too
short - "!!uri,'l');
196 else if (scan(uri,1,'/') ne 'compute' or scan(uri,2,'/') ne 'sessions')
197 and (scan(uri,1,'/') ne 'files' or scan(uri,2,'/') ne 'files')
199 call symputx('errflg',1);
200 call symputx('errmsg',
201 "URI should be in format /compute/sessions/$$$$UUID$$$$/jobs/$$$$UUID$$$$"
202 !!" or /files/files/$$$$UUID$$$$"
203 !!" but is actually like:"!!uri,'l');
206 call symputx('errflg',0,'l');
207 call symputx('logloc',uri,'l');
211%mp_abort(iftrue=(%str(&errflg)=1)
217%&dbg.put &sysmacroname: querying &base_uri&logloc/content;
218proc http method='GET' out=&fname2 &oauth_bearer
219 url="&base_uri&logloc/content?limit=10000";
221 %if &grant_type=authorization_code %then %do;
222 "Authorization"="Bearer &&&access_token_var"
227%if &mdebug=1 %then %do;
228 %put &sysmacroname: fetching log content from &base_uri&logloc/content;
229 data _null_;infile &fname2;input;putlog _infile_;run;
232%if &SYS_PROCHTTP_STATUS_CODE=400 %then %do;
234 %let logloc=%substr(&logloc,1,%index(&logloc,%str(/jobs/))-1);
235 %&dbg.put &sysmacroname: Now querying &base_uri&logloc/log/content;
236 proc http method='GET' out=&fname2 &oauth_bearer
237 url="&base_uri&logloc/log/content?limit=10000";
239 %if &grant_type=authorization_code %then %do;
240 "Authorization"="Bearer &&&access_token_var"
244 %if &mdebug=1 %then %do;
245 %put &sysmacroname: fetching log content from &base_uri&logloc/log/content;
246 data _null_;infile &fname2;input;putlog _infile_;run;
250%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
252 %if &mdebug ne 1 %then %do;
253 data _null_;infile &fname2;input;putlog _infile_;run;
255 %mp_abort(mac=&sysmacroname
256 ,msg=%str(logfetch: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
260%let libref2=%mf_getuniquelibref();
261libname &libref2 JSON fileref=&fname2;
267 set &libref2..items end=last;
268 %if &mdebug=1 %then %do;
277%if &mdebug=0 %then %do;
278 filename &fname1 clear;
279 filename &fname2 clear;
280 libname &libref1 clear;
281 libname &libref2 clear;
284 %put &sysmacroname exit vars:;