1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-08 10:00:04 +00:00

fix: removing lua from mv_getjobcode to enable Viya 4 compatibility

This commit is contained in:
munja
2022-03-06 21:01:02 +00:00
parent a8b5107b1a
commit 17ed2240d3
5 changed files with 98 additions and 68 deletions

View File

@@ -48,6 +48,11 @@
outfile=0 outfile=0
)/*/STORE SOURCE*/; )/*/STORE SOURCE*/;
%if "%substr(&sysver,1,4)"="V.04" %then %do;
%put %str(ERR)OR: Viya 4 does not support the IO library in lua;
%return;
%end;
%ml_gsubfile() %ml_gsubfile()
%mend mp_gsubfile; %mend mp_gsubfile;

View File

@@ -100,49 +100,14 @@
"name": "viya4", "name": "viya4",
"serverUrl": "https://azureuse011059.my-trials.sas.com", "serverUrl": "https://azureuse011059.my-trials.sas.com",
"serverType": "SASVIYA", "serverType": "SASVIYA",
"appLoc": "/Public/sasjscore", "appLoc": "/Public/temp/macrocore",
"macroFolders": [], "macroFolders": [
"programFolders": [], "tests/viyaonly"
"binaryFolders": [], ],
"buildConfig": {
"initProgram": "",
"termProgram": "",
"buildOutputFileName": "viya4.sas",
"buildOutputFolder": "sasjsbuild",
"buildResultsFolder": "sasjsresults",
"macroVars": {}
},
"jobConfig": {
"jobFolders": [],
"initProgram": "",
"termProgram": "",
"macroVars": {}
},
"serviceConfig": {
"serviceFolders": [],
"initProgram": "",
"termProgram": "",
"macroVars": {}
},
"streamConfig": {
"streamWebFolder": "",
"streamWeb": false,
"webSourcePath": "",
"streamServiceName": "",
"assetPaths": []
},
"deployConfig": { "deployConfig": {
"deployServicePack": true, "deployServicePack": true
"deployScripts": []
},
"testConfig": {
"initProgram": "",
"termProgram": "",
"macroVars": {},
"testSetUp": "",
"testTearDown": ""
}, },
"contextName": "SAS Job Execution compute context" "contextName": "SAS Job Execution compute context"
} }
] ]
} }

View File

@@ -8,6 +8,13 @@
**/ **/
%macro gsubtest();
%if "%substr(&sysver,1,4)"="V.04" %then %do;
%put %str(ERR)OR: Viya 4 does not support the IO library in lua;
%return;
%end;
/** /**
* test 1 - simple replace * test 1 - simple replace
*/ */
@@ -63,4 +70,8 @@ run;
iftrue=("&strcheck2b"="&str2"), iftrue=("&strcheck2b"="&str2"),
desc=Check that multi line replacement was successful (line3), desc=Check that multi line replacement was successful (line3),
outds=work.test_results outds=work.test_results
) )
%mend gsubtest;
%gsubtest()

View File

@@ -4,6 +4,7 @@
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mp_assert.sas @li mp_assert.sas
@li mp_assertscope.sas
@li mv_createjob.sas @li mv_createjob.sas
@li mv_getjobcode.sas @li mv_getjobcode.sas
@@ -27,11 +28,17 @@ run;
) )
/* now get the code back */ /* now get the code back */
%mp_assertscope(SNAPSHOT)
%mv_getjobcode( %mv_getjobcode(
path=&mcTestAppLoc/services/temp, path=&mcTestAppLoc/services/temp,
name=some_job, name=some_job,
outref=mycode outref=mycode
) )
/* exclude automatic proc json macro variables from scope check */
%mp_assertscope(COMPARE,
ignorelist=MCLIB2_JADP1LEN MCLIB2_JADP2LEN MCLIB2_JADPNUM MCLIB2_JADVLEN
MCLIB2_JADP3LEN
)
%let diditexist=NO; %let diditexist=NO;
data work.test1; data work.test1;
@@ -46,4 +53,4 @@ run;
%mp_assert( %mp_assert(
iftrue=(&diditexist=NO), iftrue=(&diditexist=NO),
desc=Check if the code that was sent was successfully retrieved desc=Check if the code that was sent was successfully retrieved
) )

View File

@@ -33,7 +33,6 @@
@li mf_getplatform.sas @li mf_getplatform.sas
@li mf_getuniquefileref.sas @li mf_getuniquefileref.sas
@li mv_getfoldermembers.sas @li mv_getfoldermembers.sas
@li ml_json.sas
**/ **/
@@ -44,7 +43,7 @@
,grant_type=sas_services ,grant_type=sas_services
,mdebug=0 ,mdebug=0
); );
%local dbg; %local dbg bufsize varcnt fname1 fname2 errmsg;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
%put &sysmacroname entry vars:; %put &sysmacroname entry vars:;
%put _local_; %put _local_;
@@ -104,7 +103,6 @@ run;
) )
/* prepare request*/ /* prepare request*/
%local fname1;
%let fname1=%mf_getuniquefileref(); %let fname1=%mf_getuniquefileref();
proc http method='GET' out=&fname1 &oauth_bearer proc http method='GET' out=&fname1 &oauth_bearer
url="&base_uri&joburi"; url="&base_uri&joburi";
@@ -121,30 +119,75 @@ 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 fname2=%mf_getuniquefileref();
%ml_json() filename &fname2 temp ;
/* read using LUA - this allows the code to be of any length */
/* cannot use lua IO package as not available in Viya 4 */
/* so use data step to read the JSON until the string `"code":"` is found */
data _null_; data _null_;
file "&fpath3..lua"; file &fname2 recfm=n;
put ' infile &fname1 lrecl=1 recfm=n;
infile = io.open (sas.symget("fpath1"), "r") input sourcechar $ 1. @@;
outfile = io.open (sas.symget("fpath2"), "w") format sourcechar hex2.;
io.input(infile) retain startwrite 0;
local resp=json.decode(io.read()) if startwrite=0 and sourcechar='"' then do;
local job=resp["code"] reentry:
outfile:write(job) input sourcechar $ 1. @@;
io.close(infile) if sourcechar='c' then do;
io.close(outfile) reentry2:
'; input sourcechar $ 1. @@;
if sourcechar='o' then do;
input sourcechar $ 1. @@;
if sourcechar='d' then do;
input sourcechar $ 1. @@;
if sourcechar='e' then do;
input sourcechar $ 1. @@;
if sourcechar='"' then do;
input sourcechar $ 1. @@;
if sourcechar=':' then do;
input sourcechar $ 1. @@;
if sourcechar='"' then do;
putlog 'code found';
startwrite=1;
input sourcechar $ 1. @@;
end;
end;
else if sourcechar='c' then goto reentry2;
end;
end;
else if sourcechar='"' then goto reentry;
end;
else if sourcechar='"' then goto reentry;
end;
else if sourcechar='"' then goto reentry;
end;
else if sourcechar='"' then goto reentry;
end;
/* once the `"code":"` string is found, write until unescaped `"` is found */
if startwrite=1 then do;
if sourcechar='\' then do;
input sourcechar $ 1. @@;
if sourcechar in ('"','\') then put sourcechar char1.;
else if sourcechar='n' then put '0A'x;
else if sourcechar='r' then put '0D'x;
else if sourcechar='t' then put '09'x;
else do;
call symputx('errmsg',"Uncaught escape char: "!!sourcechar,'l');
call symputx('syscc',99);
stop;
end;
end;
else if sourcechar='"' then stop;
else put sourcechar char1.;
end;
run; run;
%inc "&fpath3..lua";
%mp_abort(iftrue=("&syscc"="99")
,mac=mv_getjobcode
,msg=%str(&errmsg)
)
/* export to desired destination */ /* export to desired destination */
%if "&outref"="0" %then %do; %if "&outref"="0" %then %do;
data _null_; data _null_;
@@ -169,7 +212,6 @@ run;
/* clear refs */ /* clear refs */
filename &fname1 clear; filename &fname1 clear;
filename &fname2 clear; filename &fname2 clear;
filename &fname3 clear;
%end; %end;
%mend mv_getjobcode; %mend mv_getjobcode;