95%macro mv_getjoblog(uri=0,outref=0
96 ,access_token_var=ACCESS_TOKEN
97 ,grant_type=sas_services
100%local dbg libref1 libref2 loglocation fname1 fname2 jobstate err_httpcode
102%
if &mdebug=1 %then %
do;
103 %put &sysmacroname entry vars:;
109%
if &grant_type=detect %then %
do;
110 %
if %symexist(&access_token_var) %then %let grant_type=authorization_code;
111 %
else %let grant_type=sas_services;
113%
if &grant_type=sas_services %then %
do;
114 %let oauth_bearer=oauth_bearer=sas_services;
115 %let &access_token_var=;
118%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
119 and &grant_type ne sas_services
122 ,msg=%str(Invalid value
for grant_type: &grant_type)
129 if length(uri)<12 then
do;
130 call symputx(
'errflg',1);
131 call symputx(
'errmsg',
"URI is too short - "!!uri,
'l');
133 if scan(uri,-1)=
'state' or scan(uri,1) ne 'jobExecution' then do;
134 call symputx('errflg',1);
135 call symputx('errmsg',
136 "URI should be in format /jobExecution/jobs/$$$$UUID$$$$"
137 !!" but is actually like:"!!uri,'l');
141%mp_abort(iftrue=(&errflg=1)
146%mp_abort(iftrue=(&outref=0)
148 ,msg=%str(Output fileref should be provided)
151%if %mf_existfileref(&outref) ne 1 %then %do;
152 filename &outref temp;
155options noquotelenmax;
157%let base_uri=%mf_getplatform(VIYARESTAPI);
160%let fname1=%mf_getuniquefileref();
161%let fname2=%mf_getuniquefileref();
162proc http method='GET' out=&fname1 &oauth_bearer
165 %if &grant_type=authorization_code %then %do;
166 "Authorization"="Bearer &&&access_token_var"
170%if &mdebug=1 %then %do;
171 %put &sysmacroname: fetching log loc from &uri;
172 data _null_;infile &fname1;input;putlog _infile_;run;
174%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201 %then
176 data _null_;infile &fname1;input;putlog _infile_;run;
177 %mp_abort(mac=&sysmacroname
178 ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
182%let libref1=%mf_getuniquelibref();
183libname &libref1 JSON fileref=&fname1;
186 call symputx('loglocation',loglocation,'l');
187 %if %mf_existvar(&libref1..root,state) %then %do;
188 call symputx('jobstate',state,'l');
191 call symputx('jobstate','unknown','l');
196%if %str(&jobstate)= %then %let jobstate=unknown;
204%if &mdebug=1 %then %do;
205 %put &sysmacroname: jobstate=[&jobstate] loglocation=[&loglocation];
207%if %length(&loglocation)<2 %then %do;
210 %if %sysfunc(exist(&libref1..error)) %then %do;
213 call symputx('err_httpcode',httpStatusCode,'l');
214 call symputx('err_msg',message,'l');
215 putlog "&sysmacroname: Job &jobstate - error " httpStatusCode ": " message;
223 %let abortmsg=Job &jobstate, no log available. GET &uri;
224 %if %length(&err_msg)>0 %then %let abortmsg=Job &jobstate, no log available. Error &err_httpcode: &err_msg. GET &uri;
230 %if &jobstate=canceled %then %do;
231 %put &sysmacroname: &abortmsg;
234 put "&sysmacroname: &abortmsg";
238 %mp_abort(iftrue=(1=1)
246%let errmsg=No loglocation entry in &fname1 fileref;
248 uri=symget('loglocation');
249 if length(uri)<12 then do;
250 call symputx('errflg',1);
251 call symputx('errmsg',"URI is too
short - "!!uri,'l');
253 else if (scan(uri,1,'/') ne 'compute' or scan(uri,2,'/') ne 'sessions')
254 and (scan(uri,1,'/') ne 'files' or scan(uri,2,'/') ne 'files')
256 call symputx('errflg',1);
257 call symputx('errmsg',
258 "URI should be in format /compute/sessions/$$$$UUID$$$$/jobs/$$$$UUID$$$$"
259 !!" or /files/files/$$$$UUID$$$$"
260 !!" but is actually like:"!!uri,'l');
263 call symputx('errflg',0,'l');
264 call symputx('logloc',uri,'l');
268%mp_abort(iftrue=(%str(&errflg)=1)
274%&dbg.put &sysmacroname: querying &base_uri&logloc/content;
275proc http method='GET' out=&fname2 &oauth_bearer
276 url="&base_uri&logloc/content?limit=10000";
278 %if &grant_type=authorization_code %then %do;
279 "Authorization"="Bearer &&&access_token_var"
284%if &mdebug=1 %then %do;
285 %put &sysmacroname: fetching log content from &base_uri&logloc/content;
286 data _null_;infile &fname2;input;putlog _infile_;run;
289%if &SYS_PROCHTTP_STATUS_CODE=400 %then %do;
291 %let logloc=%substr(&logloc,1,%index(&logloc,%str(/jobs/))-1);
292 %&dbg.put &sysmacroname: Now querying &base_uri&logloc/log/content;
293 proc http method='GET' out=&fname2 &oauth_bearer
294 url="&base_uri&logloc/log/content?limit=10000";
296 %if &grant_type=authorization_code %then %do;
297 "Authorization"="Bearer &&&access_token_var"
301 %if &mdebug=1 %then %do;
302 %put &sysmacroname: fetching log content from &base_uri&logloc/log/content;
303 data _null_;infile &fname2;input;putlog _infile_;run;
307%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
309 %if &mdebug ne 1 %then %do;
310 data _null_;infile &fname2;input;putlog _infile_;run;
312 %mp_abort(mac=&sysmacroname
313 ,msg=%str(logfetch: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
317%let libref2=%mf_getuniquelibref();
318libname &libref2 JSON fileref=&fname2;
324 set &libref2..items end=last;
325 %if &mdebug=1 %then %do;
334%if &mdebug=0 %then %do;
335 filename &fname1 clear;
336 filename &fname2 clear;
337 libname &libref1 clear;
338 libname &libref2 clear;
341 %put &sysmacroname exit vars:;