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

Compare commits

..

12 Commits

Author SHA1 Message Date
Allan Bowe
2bb1df86ec Merge pull request #379 from sasjs/378-ms_triggerstpsas
378 ms triggerstpsas
2024-10-31 18:07:33 +00:00
github-actions
b1bff1b0a4 chore: updating all.sas 2024-10-31 16:58:16 +00:00
Trevor Moody
5c3ac8a123 chore: reverted position of the '&boundary' put statement. 2024-10-31 16:57:52 +00:00
github-actions
2765d8c2ec chore: updating all.sas 2024-10-31 12:49:45 +00:00
Trevor Moody
bd4610f0b8 chore: updates to address comments 2024-10-31 12:49:16 +00:00
github-actions
ae92e14660 chore: updating all.sas 2024-10-31 11:27:47 +00:00
Trevor Moody
424ae548d0 chore: replaced obs test with mp_assertdsobs 2024-10-31 11:27:18 +00:00
github-actions
69fe9ebaed chore: updating all.sas 2024-10-31 11:10:40 +00:00
Trevor Moody
1b16383fd8 chore: Added test of ms_triggerstp.sas 2024-10-31 11:10:10 +00:00
github-actions
f88b219da1 chore: updating all.sas 2024-10-30 19:25:24 +00:00
Trevor Moody
900120df1b feat: Triggering of stored processes. Closes #378 2024-10-30 19:24:45 +00:00
github-actions
2a13ba72f6 chore: updating all.sas 2024-10-30 19:21:00 +00:00
3 changed files with 434 additions and 313 deletions

77
all.sas
View File

@@ -23115,7 +23115,7 @@ run;
%mend ms_testservice; %mend ms_testservice;
/** /**
@file @file
@brief Triggers a SASjs Server STP using the /SASjsApi/code/trigger endpoint @brief Triggers a SASjs Server STP using the /SASjsApi/stp/trigger endpoint
@details Triggers the STP and returns the sessionId @details Triggers the STP and returns the sessionId
Example: Example:
@@ -23141,6 +23141,8 @@ run;
|---|---|--| |---|---|--|
|someref|some_name|some_filename.xls| |someref|some_name|some_filename.xls|
|fref2|another_file|zyx_v2.csv| |fref2|another_file|zyx_v2.csv|
@param [in] expiresaftermins= (15) The number of minutes to retain the session
folder after the session ends.
@param [out] outds= (work.ms_triggerstp) Set to the name of a dataset to @param [out] outds= (work.ms_triggerstp) Set to the name of a dataset to
contain the sessionId. If this dataset already exists, and contains the contain the sessionId. If this dataset already exists, and contains the
@@ -23152,8 +23154,11 @@ run;
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_getuniquefileref.sas @li mf_getuniquefileref.sas
@li mf_getuniquelibref.sas
@li mf_getuniquename.sas @li mf_getuniquename.sas
@li mp_abort.sas @li mp_abort.sas
@li mp_dropmembers.sas
@li mf_nobs.sas
**/ **/
@@ -23161,12 +23166,14 @@ run;
,debug=131 ,debug=131
,inputparams=_null_ ,inputparams=_null_
,inputfiles=_null_ ,inputfiles=_null_
,expiresAfterMins=15
,outds=work.ms_triggerstp ,outds=work.ms_triggerstp
,mdebug=0 ,mdebug=0
); );
%local dbg mainref authref; %local dbg mainref authref boundary libref triggered_sid;
%let mainref=%mf_getuniquefileref(); %let mainref=%mf_getuniquefileref();
%let authref=%mf_getuniquefileref(); %let authref=%mf_getuniquefileref();
%let boundary=%mf_getuniquename();
%if &inputparams=0 %then %let inputparams=_null_; %if &inputparams=0 %then %let inputparams=_null_;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
@@ -23180,13 +23187,17 @@ run;
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(Program not provided) ,msg=%str(Program not provided)
) )
%mp_abort(iftrue=("&outds"="")
,mac=&sysmacroname
,msg=%str(Output dataset not provided)
)
/* avoid sending bom marker to API */ /* avoid sending bom marker to API */
%local optval; %local optval;
%let optval=%sysfunc(getoption(bomfile)); %let optval=%sysfunc(getoption(bomfile));
options nobomfile; options nobomfile;
/* add params */ /* Add params to the content */
data _null_; data _null_;
file &mainref termstr=crlf lrecl=32767 mod; file &mainref termstr=crlf lrecl=32767 mod;
length line $1000 name $32 value $32767; length line $1000 name $32 value $32767;
@@ -23214,7 +23225,7 @@ data _null_;
end; end;
run; run;
/* write out the input files */ /* write out the input files to the content */
%local i; %local i;
%do i=1 %to &webcount; %do i=1 %to &webcount;
data _null_; data _null_;
@@ -23239,9 +23250,10 @@ run;
run; run;
%end; %end;
/* Add footer to the content */
data _null_; data _null_;
file &mainref termstr=crlf mod; file &mainref termstr=crlf mod;
put "--&boundary--"; put / "--&boundary--";
run; run;
data _null_; data _null_;
@@ -23254,24 +23266,27 @@ run;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
data _null_; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** authref=&authref content *****";
infile &authref; infile &authref;
input; input;
put _infile_; put _infile_;
data _null_; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** mainref=&mainref content *****";
infile &mainref; infile &mainref;
input; input;
put _infile_; put _infile_;
run; run;
%end; %end;
%local resp_path; %local resp_path outref;
%let resp_path=%sysfunc(pathname(work))/%mf_getuniquename(); %let resp_path=%sysfunc(pathname(work))/%mf_getuniquename();
%let outref=%mf_getuniquefileref();
filename &outref "&resp_path" lrecl=32767; filename &outref "&resp_path" lrecl=32767;
/* prepare request*/ /* prepare request*/
proc http method='POST' headerin=&authref in=&mainref out=&outref proc http method='POST' headerin=&authref in=&mainref out=&outref
url="&_sasjs_apiserverurl/SASjsApi/stp/trigger?%trim( url="&_sasjs_apiserverurl/SASjsApi/stp/trigger?%trim(
)_program=&pgm%str(&)_debug=131"; )_program=&pgm%str(&)_debug=131%str(&)expiresAfterMins=&expiresaftermins";
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
debug level=2; debug level=2;
%end; %end;
@@ -23280,10 +23295,16 @@ run;
%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)
or &mdebug=1 or &mdebug=1
%then %do; %then %do;
data _null_;infile &outref;input;putlog _infile_;run; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** outref=&outref content *****";
infile &outref;
input;
putlog _infile_;
run;
%end; %end;
%mp_abort( %mp_abort(
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201) iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200
and &SYS_PROCHTTP_STATUS_CODE ne 201)
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE) ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
) )
@@ -23291,31 +23312,21 @@ or &mdebug=1
/* reset options */ /* reset options */
options &optval; options &optval;
data work.%mf_getuniquename(); %let libref=%mf_getuniquelibref();
infile "&resp_path"; libname &libref JSON fileref=&outref;
input %let triggered_sid=%mf_getuniquename(prefix=triggered_sid_);
%if &outlogds ne _null_ or &mdebug=1 %then %do; data work.&triggered_sid (keep=sessionid);
%local matchstr chopout; set &libref..root;
%let matchstr=SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784;
%let chopout=%sysfunc(pathname(work))/%mf_getuniquename(prefix=chop);
%mp_chop("&resp_path"
,matchvar=matchstr
,keep=LAST
,matchpoint=END
,outfile="&chopout"
,mdebug=&mdebug
)
data &outlogds;
infile "&chopout" lrecl=2000;
length line $2000;
line=_infile_;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
putlog line=; putlog (_all_)(=);
%end; %end;
run; run;
%if %mf_nobs(work.&triggered_sid)>0 %then %do;
proc append base=&outds data=work.&triggered_sid;
run;
%end; %end;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
@@ -23326,9 +23337,13 @@ data work.%mf_getuniquename();
/* clear refs */ /* clear refs */
filename &authref; filename &authref;
filename &mainref; filename &mainref;
filename &outref;
libname &libref clear;
/* and remove temp dataset */
%mp_dropmembers(&triggered_sid,libref=work);
%end; %end;
%mend ms_triggerstp;
/** %mend ms_triggerstp;/**
@file @file
@brief Send data to/from sasjs/server @brief Send data to/from sasjs/server
@details This macro should be added to the start of each web service, @details This macro should be added to the start of each web service,

View File

@@ -1,6 +1,6 @@
/** /**
@file @file
@brief Triggers a SASjs Server STP using the /SASjsApi/code/trigger endpoint @brief Triggers a SASjs Server STP using the /SASjsApi/stp/trigger endpoint
@details Triggers the STP and returns the sessionId @details Triggers the STP and returns the sessionId
Example: Example:
@@ -26,6 +26,8 @@
|---|---|--| |---|---|--|
|someref|some_name|some_filename.xls| |someref|some_name|some_filename.xls|
|fref2|another_file|zyx_v2.csv| |fref2|another_file|zyx_v2.csv|
@param [in] expiresaftermins= (15) The number of minutes to retain the session
folder after the session ends.
@param [out] outds= (work.ms_triggerstp) Set to the name of a dataset to @param [out] outds= (work.ms_triggerstp) Set to the name of a dataset to
contain the sessionId. If this dataset already exists, and contains the contain the sessionId. If this dataset already exists, and contains the
@@ -37,8 +39,11 @@
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_getuniquefileref.sas @li mf_getuniquefileref.sas
@li mf_getuniquelibref.sas
@li mf_getuniquename.sas @li mf_getuniquename.sas
@li mp_abort.sas @li mp_abort.sas
@li mp_dropmembers.sas
@li mf_nobs.sas
**/ **/
@@ -46,12 +51,14 @@
,debug=131 ,debug=131
,inputparams=_null_ ,inputparams=_null_
,inputfiles=_null_ ,inputfiles=_null_
,expiresAfterMins=15
,outds=work.ms_triggerstp ,outds=work.ms_triggerstp
,mdebug=0 ,mdebug=0
); );
%local dbg mainref authref; %local dbg mainref authref boundary libref triggered_sid;
%let mainref=%mf_getuniquefileref(); %let mainref=%mf_getuniquefileref();
%let authref=%mf_getuniquefileref(); %let authref=%mf_getuniquefileref();
%let boundary=%mf_getuniquename();
%if &inputparams=0 %then %let inputparams=_null_; %if &inputparams=0 %then %let inputparams=_null_;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
@@ -65,13 +72,17 @@
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(Program not provided) ,msg=%str(Program not provided)
) )
%mp_abort(iftrue=("&outds"="")
,mac=&sysmacroname
,msg=%str(Output dataset not provided)
)
/* avoid sending bom marker to API */ /* avoid sending bom marker to API */
%local optval; %local optval;
%let optval=%sysfunc(getoption(bomfile)); %let optval=%sysfunc(getoption(bomfile));
options nobomfile; options nobomfile;
/* add params */ /* Add params to the content */
data _null_; data _null_;
file &mainref termstr=crlf lrecl=32767 mod; file &mainref termstr=crlf lrecl=32767 mod;
length line $1000 name $32 value $32767; length line $1000 name $32 value $32767;
@@ -99,7 +110,7 @@ data _null_;
end; end;
run; run;
/* write out the input files */ /* write out the input files to the content */
%local i; %local i;
%do i=1 %to &webcount; %do i=1 %to &webcount;
data _null_; data _null_;
@@ -124,9 +135,10 @@ run;
run; run;
%end; %end;
/* Add footer to the content */
data _null_; data _null_;
file &mainref termstr=crlf mod; file &mainref termstr=crlf mod;
put "--&boundary--"; put / "--&boundary--";
run; run;
data _null_; data _null_;
@@ -139,24 +151,27 @@ run;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
data _null_; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** authref=&authref content *****";
infile &authref; infile &authref;
input; input;
put _infile_; put _infile_;
data _null_; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** mainref=&mainref content *****";
infile &mainref; infile &mainref;
input; input;
put _infile_; put _infile_;
run; run;
%end; %end;
%local resp_path; %local resp_path outref;
%let resp_path=%sysfunc(pathname(work))/%mf_getuniquename(); %let resp_path=%sysfunc(pathname(work))/%mf_getuniquename();
%let outref=%mf_getuniquefileref();
filename &outref "&resp_path" lrecl=32767; filename &outref "&resp_path" lrecl=32767;
/* prepare request*/ /* prepare request*/
proc http method='POST' headerin=&authref in=&mainref out=&outref proc http method='POST' headerin=&authref in=&mainref out=&outref
url="&_sasjs_apiserverurl/SASjsApi/stp/trigger?%trim( url="&_sasjs_apiserverurl/SASjsApi/stp/trigger?%trim(
)_program=&pgm%str(&)_debug=131"; )_program=&pgm%str(&)_debug=131%str(&)expiresAfterMins=&expiresaftermins";
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
debug level=2; debug level=2;
%end; %end;
@@ -165,10 +180,16 @@ run;
%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)
or &mdebug=1 or &mdebug=1
%then %do; %then %do;
data _null_;infile &outref;input;putlog _infile_;run; data _null_;
if _n_ eq 1 then putlog "NOTE: ***** outref=&outref content *****";
infile &outref;
input;
putlog _infile_;
run;
%end; %end;
%mp_abort( %mp_abort(
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200 and &SYS_PROCHTTP_STATUS_CODE ne 201) iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200
and &SYS_PROCHTTP_STATUS_CODE ne 201)
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE) ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
) )
@@ -176,31 +197,21 @@ or &mdebug=1
/* reset options */ /* reset options */
options &optval; options &optval;
data work.%mf_getuniquename(); %let libref=%mf_getuniquelibref();
infile "&resp_path"; libname &libref JSON fileref=&outref;
input %let triggered_sid=%mf_getuniquename(prefix=triggered_sid_);
%if &outlogds ne _null_ or &mdebug=1 %then %do; data work.&triggered_sid (keep=sessionid);
%local matchstr chopout; set &libref..root;
%let matchstr=SASJS_LOGS_SEPARATOR_163ee17b6ff24f028928972d80a26784;
%let chopout=%sysfunc(pathname(work))/%mf_getuniquename(prefix=chop);
%mp_chop("&resp_path"
,matchvar=matchstr
,keep=LAST
,matchpoint=END
,outfile="&chopout"
,mdebug=&mdebug
)
data &outlogds;
infile "&chopout" lrecl=2000;
length line $2000;
line=_infile_;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
putlog line=; putlog (_all_)(=);
%end; %end;
run; run;
%if %mf_nobs(work.&triggered_sid)>0 %then %do;
proc append base=&outds data=work.&triggered_sid;
run;
%end; %end;
%if &mdebug=1 %then %do; %if &mdebug=1 %then %do;
@@ -211,5 +222,10 @@ data work.%mf_getuniquename();
/* clear refs */ /* clear refs */
filename &authref; filename &authref;
filename &mainref; filename &mainref;
filename &outref;
libname &libref clear;
/* and remove temp dataset */
%mp_dropmembers(&triggered_sid,libref=work);
%end; %end;
%mend ms_triggerstp; %mend ms_triggerstp;

View File

@@ -0,0 +1,90 @@
/**
@file
@brief Testing ms_triggerstp.sas macro
<h4> SAS Macros </h4>
@li mf_getuniquename.sas
@li mp_assert.sas
@li mp_assertscope.sas
@li ms_createfile.sas
@li ms_triggerstp.sas
@li mf_existds.sas
@li mp_assertdsobs.sas
@li mp_assertcols.sas
@li mf_getvartype.sas
@li ms_deletefile.sas
**/
/* first, create multiple STPs to run */
filename stpcode1 temp;
data _null_;
file stpcode1;
put '%put hello world;';
put '%put _all_;';
put 'data _null_; file _webout1; put "triggerstp test 1";run;';
run;
filename stpcode2 temp;
data _null_;
file stpcode2;
put '%put Lorem Ipsum;';
put '%put _all_;';
put 'data _null_; file _webout2; put "triggerstp test 2";run;';
run;
options mprint;
%let fname1=%mf_getuniquename();
%let fname2=%mf_getuniquename();
%ms_createfile(/sasjs/tests/&fname1..sas
,inref=stpcode1
,mdebug=1
)
%ms_createfile(/sasjs/tests/&fname2..sas
,inref=stpcode2
)
%mp_assertscope(SNAPSHOT)
%ms_triggerstp(/sasjs/tests/&fname1
,debug=131
,outds=work.mySessions
)
%ms_triggerstp(/sasjs/tests/&fname2
,outds=work.mySessions
)
%mp_assertscope(COMPARE
,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN)
%mp_assert(iftrue=%str(%mf_existds(work.mySessions)=1)
,desc=Testing output exists
,outds=work.test_results
)
%mp_assertdsobs(work.mySessions,
test=EQUALS 2,
desc=Testing observations,
outds=work.test_results
)
%mp_assertcols(work.mySessions,
cols=sessionid,
test=ALL,
desc=Testing column exists,
outds=work.test_results
)
data _null_;
retain contentCheck 1;
set work.mySessions end=last;
if missing(sessionID) then contentCheck = 0;
if last then do;
call symputx("contentCheck",contentCheck,"l");
end;
run;
%let typeCheck = %mf_getvartype(work.mySessions,sessionid);
%mp_assert(iftrue=%str(&typeCheck = C and &contentCheck = 1)
,desc=Testing type and content of output
,outds=work.test_results
)
%ms_deletefile(/sasjs/tests/&fname1..sas)
%ms_deletefile(/sasjs/tests/&fname2..sas)