mirror of
https://github.com/sasjs/core.git
synced 2026-01-14 20:10:05 +00:00
fix: removing lua dependency from mv_getjoblog to enable viya 4
This commit is contained in:
@@ -49,8 +49,12 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
%* Finally, fetch the log;
|
%* Finally, fetch the log;
|
||||||
%mv_getjoblog(uri=%str(&uri),outref=mylog)
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
%mv_getjoblog(uri=%str(&uri),outref=mylog,mdebug=1)
|
||||||
|
/* ignore auto proc json vars */
|
||||||
|
%mp_assertscope(COMPARE
|
||||||
|
,ignorelist=MCLIB2_JADP2LEN MCLIB2_JADPNUM MCLIB2_JADVLEN
|
||||||
|
)
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
infile mylog end=eof;
|
infile mylog end=eof;
|
||||||
|
|||||||
@@ -86,7 +86,8 @@
|
|||||||
@li mp_abort.sas
|
@li mp_abort.sas
|
||||||
@li mf_getplatform.sas
|
@li mf_getplatform.sas
|
||||||
@li mf_existfileref.sas
|
@li mf_existfileref.sas
|
||||||
@li ml_json.sas
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@
|
|||||||
,grant_type=sas_services
|
,grant_type=sas_services
|
||||||
,mdebug=0
|
,mdebug=0
|
||||||
);
|
);
|
||||||
%local dbg;
|
%local dbg libref1 libref2 loglocation fname1 fname2;
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
%put &sysmacroname entry vars:;
|
%put &sysmacroname entry vars:;
|
||||||
%put _local_;
|
%put _local_;
|
||||||
@@ -154,8 +155,8 @@ options noquotelenmax;
|
|||||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||||
|
|
||||||
/* prepare request*/
|
/* prepare request*/
|
||||||
%local fname1;
|
|
||||||
%let fname1=%mf_getuniquefileref();
|
%let fname1=%mf_getuniquefileref();
|
||||||
|
%let fname2=%mf_getuniquefileref();
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname1 &oauth_bearer
|
||||||
url="&base_uri&uri";
|
url="&base_uri&uri";
|
||||||
headers
|
headers
|
||||||
@@ -175,37 +176,19 @@ run;
|
|||||||
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
||||||
)
|
)
|
||||||
%end;
|
%end;
|
||||||
%local fname2 fname3 fpath1 fpath2 fpath3;
|
|
||||||
%let fname2=%mf_getuniquefileref();
|
|
||||||
%let fname3=%mf_getuniquefileref();
|
|
||||||
%let fpath1=%sysfunc(pathname(&fname1));
|
|
||||||
%let fpath2=%sysfunc(pathname(&fname2));
|
|
||||||
%let fpath3=%sysfunc(pathname(&fname3));
|
|
||||||
|
|
||||||
/* compile the lua JSON module */
|
%let libref1=%mf_getuniquelibref();
|
||||||
%ml_json()
|
libname &libref1 JSON fileref=&fname1;
|
||||||
/* read using LUA - this allows the code to be of any length */
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file "&fpath3..lua";
|
set &libref1..root;
|
||||||
put '
|
call symputx('loglocation',loglocation,'l');
|
||||||
infile = io.open (sas.symget("fpath1"), "r")
|
|
||||||
outfile = io.open (sas.symget("fpath2"), "w")
|
|
||||||
io.input(infile)
|
|
||||||
local resp=json.decode(io.read())
|
|
||||||
local logloc=resp["logLocation"]
|
|
||||||
outfile:write(logloc)
|
|
||||||
io.close(infile)
|
|
||||||
io.close(outfile)
|
|
||||||
';
|
|
||||||
run;
|
run;
|
||||||
%inc "&fpath3..lua";
|
|
||||||
/* get log path*/
|
/* validate log path*/
|
||||||
%let errflg=1;
|
%let errflg=1;
|
||||||
%let errmsg=No entry in &fname2 fileref;
|
%let errmsg=No loglocation entry in &fname1 fileref;
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &fname2;
|
uri=symget('loglocation');
|
||||||
input;
|
|
||||||
uri=cats(_infile_);
|
|
||||||
if length(uri)<12 then do;
|
if length(uri)<12 then do;
|
||||||
call symputx('errflg',1);
|
call symputx('errflg',1);
|
||||||
call symputx('errmsg',"URI is invalid (too short) - '&uri'",'l');
|
call symputx('errmsg',"URI is invalid (too short) - '&uri'",'l');
|
||||||
@@ -232,7 +215,7 @@ run;
|
|||||||
|
|
||||||
/* we have a log uri - now fetch the log */
|
/* we have a log uri - now fetch the log */
|
||||||
%&dbg.put &sysmacroname: querying &base_uri&logloc/content;
|
%&dbg.put &sysmacroname: querying &base_uri&logloc/content;
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname2 &oauth_bearer
|
||||||
url="&base_uri&logloc/content?limit=10000";
|
url="&base_uri&logloc/content?limit=10000";
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
@@ -243,14 +226,14 @@ run;
|
|||||||
|
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
%put &sysmacroname: fetching log content from &base_uri&logloc/content;
|
%put &sysmacroname: fetching log content from &base_uri&logloc/content;
|
||||||
data _null_;infile &fname1;input;putlog _infile_;run;
|
data _null_;infile &fname2;input;putlog _infile_;run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &SYS_PROCHTTP_STATUS_CODE=400 %then %do;
|
%if &SYS_PROCHTTP_STATUS_CODE=400 %then %do;
|
||||||
/* fetch log from parent session */
|
/* fetch log from parent session */
|
||||||
%let logloc=%substr(&logloc,1,%index(&logloc,%str(/jobs/))-1);
|
%let logloc=%substr(&logloc,1,%index(&logloc,%str(/jobs/))-1);
|
||||||
%&dbg.put &sysmacroname: Now querying &base_uri&logloc/log/content;
|
%&dbg.put &sysmacroname: Now querying &base_uri&logloc/log/content;
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname2 &oauth_bearer
|
||||||
url="&base_uri&logloc/log/content?limit=10000";
|
url="&base_uri&logloc/log/content?limit=10000";
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
@@ -260,47 +243,32 @@ run;
|
|||||||
run;
|
run;
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
%put &sysmacroname: fetching log content from &base_uri&logloc/log/content;
|
%put &sysmacroname: fetching log content from &base_uri&logloc/log/content;
|
||||||
data _null_;infile &fname1;input;putlog _infile_;run;
|
data _null_;infile &fname2;input;putlog _infile_;run;
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
|
%if &SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201
|
||||||
%then %do;
|
%then %do;
|
||||||
%if &mdebug ne 1 %then %do; /* have already output above */
|
%if &mdebug ne 1 %then %do; /* have already output above */
|
||||||
data _null_;infile &fname1;input;putlog _infile_;run;
|
data _null_;infile &fname2;input;putlog _infile_;run;
|
||||||
%end;
|
%end;
|
||||||
%mp_abort(mac=&sysmacroname
|
%mp_abort(mac=&sysmacroname
|
||||||
,msg=%str(logfetch: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
,msg=%str(logfetch: &SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
||||||
)
|
)
|
||||||
%end;
|
%end;
|
||||||
data _null_;
|
|
||||||
file "&fpath3..lua";
|
|
||||||
put '
|
|
||||||
infile = io.open (sas.symget("fpath1"), "r")
|
|
||||||
outfile = io.open (sas.symget("fpath2"), "w")
|
|
||||||
io.input(infile)
|
|
||||||
local resp=json.decode(io.read())
|
|
||||||
for i, v in pairs(resp["items"]) do
|
|
||||||
outfile:write(v.line,"\n")
|
|
||||||
end
|
|
||||||
io.close(infile)
|
|
||||||
io.close(outfile)
|
|
||||||
';
|
|
||||||
run;
|
|
||||||
%inc "&fpath3..lua";
|
|
||||||
|
|
||||||
/* write log out to the specified fileref */
|
%let libref2=%mf_getuniquelibref();
|
||||||
|
libname &libref2 JSON fileref=&fname2;
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &fname2 end=last;
|
|
||||||
file &outref mod;
|
file &outref mod;
|
||||||
if _n_=1 then do;
|
if _n_=1 then do;
|
||||||
put "/** SASJS Viya Job Log Extract start: &uri **/";
|
put "/** SASJS Viya Job Log Extract start: &uri **/";
|
||||||
end;
|
end;
|
||||||
input;
|
set &libref2..items end=last;
|
||||||
put _infile_;
|
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
putlog _infile_;
|
putlog line;
|
||||||
%end;
|
%end;
|
||||||
|
put line;
|
||||||
if last then do;
|
if last then do;
|
||||||
put "/** SASJS Viya Job Log Extract end: &uri **/";
|
put "/** SASJS Viya Job Log Extract end: &uri **/";
|
||||||
end;
|
end;
|
||||||
@@ -309,7 +277,8 @@ run;
|
|||||||
%if &mdebug=0 %then %do;
|
%if &mdebug=0 %then %do;
|
||||||
filename &fname1 clear;
|
filename &fname1 clear;
|
||||||
filename &fname2 clear;
|
filename &fname2 clear;
|
||||||
filename &fname3 clear;
|
libname &libref1 clear;
|
||||||
|
libname &libref2 clear;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
%put &sysmacroname exit vars:;
|
%put &sysmacroname exit vars:;
|
||||||
|
|||||||
Reference in New Issue
Block a user