@sasjs/core 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -81,7 +81,7 @@
81
81
  %mp_init()
82
82
 
83
83
  %local ds test_result test_comments del add mod ilist;
84
- %let ilist=%upcase(&_SASJS_FUNCTIONS SYS_PROCHTTP_STATUS_CODE
84
+ %let ilist=%upcase(_SASJS_FUNCTIONS SYS_PROCHTTP_STATUS_CODE
85
85
  SYS_PROCHTTP_STATUS_CODE SYS_PROCHTTP_STATUS_PHRASE &ignorelist);
86
86
 
87
87
  /* get current variables */
package/base/mp_init.sas CHANGED
@@ -22,7 +22,7 @@
22
22
  All the system variables this macro creates use the hard-coded `_SASJS_`
23
23
  prefix - the same namespace sasjs/server uses in the pre-program it
24
24
  generates for each session (`_SASJS_WEBOUT_HEADERS`, `_SASJS_TOKENFILE`,
25
- `_SASJS_USERNAME` ...). There is no configurable prefix.
25
+ `_SASJS_USERNAME` ...).
26
26
 
27
27
  Setting `_SASJS_INIT` before this macro runs skips it, which is how an
28
28
  autoexec opts out - a second pass would re-apply the options below.
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "devDependencies": {
44
44
  "@nogoo9/gitleaks": "8.30.1-post.2"
45
45
  },
46
- "version": "6.0.0"
46
+ "version": "6.1.0"
47
47
  }
@@ -196,6 +196,7 @@ options &optval;
196
196
  data &outlogds;
197
197
  infile "&chopout" lrecl=2000;
198
198
  length line $2000;
199
+ input;
199
200
  line=_infile_;
200
201
  %if &mdebug=1 %then %do;
201
202
  putlog line=;
@@ -21,7 +21,7 @@
21
21
  |stpmacname|some value|
22
22
  |mustbevalidname|can be anything, oops, %abort!!|
23
23
 
24
- @param [in] debug= (log) Provide the _debug value
24
+ @param [in] debug= (131) Provide the _debug value.
25
25
  @param [in] mdebug= (0) Set to 1 to provide macro debugging
26
26
  @param [in] viyaresult= (WEBOUT_JSON) The Viya result type to return. For
27
27
  more info, see mv_getjobresult.sas
@@ -31,6 +31,17 @@
31
31
  0 if the service output is not in JSON format.
32
32
  @param [out] outref= (0) Output fileref to create, to contain the full _webout
33
33
  response.
34
+ @param [out] outlogds= (_null_) Name of a dataset to receive the child's log
35
+ (one column, line). Populated on Viya, from the job log mv_jobflow
36
+ collects, and on SASjs Server, from the log the server appends to the
37
+ response - ms_testservice discards that log unless this is set. Not
38
+ populated on SAS 9, where proc stp returns no child log. On SASjs Server
39
+ it is only populated when debug is 131 or above: the server appends the log
40
+ to the response in debug mode, so a lower value returns an empty dataset.
41
+ @param [out] outstatus= (0) Name of a dataset to receive the outcome of each
42
+ child run - one row per program, with columns STATE, URI, ERRMSG and
43
+ PLATFORM. ERRMSG is only populated on SASjs Server, from the abort block;
44
+ the Viya job flow carries a state but no message, and SAS 9 gives neither.
34
45
 
35
46
  <h4> SAS Macros </h4>
36
47
  @li mf_getplatform.sas
@@ -56,14 +67,16 @@
56
67
  inputfiles=0,
57
68
  inputdatasets=0,
58
69
  inputparams=0,
59
- debug=log,
70
+ debug=131,
60
71
  mdebug=0,
61
72
  outlib=0,
62
73
  outref=0,
74
+ outlogds=_null_,
75
+ outstatus=0,
63
76
  viyaresult=WEBOUT_JSON,
64
77
  viyacontext=SAS Job Execution compute context
65
78
  );
66
- %local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform;
79
+ %local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform jobds respref clearmeref;
67
80
  %if &mdebug=1 %then %do;
68
81
  %put &sysmacroname entry vars:;
69
82
  %put _local_;
@@ -183,6 +196,27 @@ filename &webref "&webrefpath";
183
196
  %mp_binarycopy(inref=&webref,outref=&outref)
184
197
  %end;
185
198
 
199
+ %if "&outlogds" ne "_null_" %then %do;
200
+ /* SAS 9 returns no child log. Create the dataset all the same, so a caller
201
+ * that reads it gets no rows rather than a missing table. */
202
+ data &outlogds;
203
+ length line $32767;
204
+ stop;
205
+ run;
206
+ %end;
207
+
208
+ /* proc stp gives no job status - say so rather than imply success */
209
+ %if "&outstatus" ne "0" %then %do;
210
+ data &outstatus;
211
+ length state $20 uri $256 errmsg $256 platform $10;
212
+ state='unknown';
213
+ uri='';
214
+ errmsg='proc stp returns no job status';
215
+ platform='SASMETA';
216
+ output;
217
+ run;
218
+ %end;
219
+
186
220
  %end;
187
221
  %else %if &platform=SASVIYA %then %do;
188
222
 
@@ -240,9 +274,11 @@ filename &webref "&webrefpath";
240
274
  putlog (_all_)(=);
241
275
  run;
242
276
 
277
+ /* the flow table is an internal detail: unique name, thrown away below */
278
+ %let jobds=%mf_getuniquename(prefix=mx_execute_);
243
279
  %mv_jobflow(inds=&ds1
244
280
  ,maxconcurrency=1
245
- ,outds=work.results
281
+ ,outds=&jobds
246
282
  ,outref=&fref1
247
283
  ,mdebug=&mdebug
248
284
  )
@@ -252,12 +288,36 @@ filename &webref "&webrefpath";
252
288
  input;
253
289
  putlog _infile_;
254
290
  run;
291
+ /* and keep it, if the caller asked */
292
+ %if "&outlogds" ne "_null_" %then %do;
293
+ data &outlogds;
294
+ infile &fref1 lrecl=32767 end=eof;
295
+ length line $32767;
296
+ do while(not eof);
297
+ input;
298
+ output;
299
+ end;
300
+ run;
301
+ %end;
255
302
  /* get the uri to fetch results */
256
303
  data _null_;
257
- set work.results;
304
+ set &jobds;
258
305
  call symputx('uri',uri);
259
306
  putlog "&sysmacroname: fetching results for " uri;
260
307
  run;
308
+ /* the outcome, before the flow table goes away */
309
+ %if "&outstatus" ne "0" %then %do;
310
+ data &outstatus;
311
+ length state $20 uri $256 errmsg $256 platform $10;
312
+ platform='SASVIYA';
313
+ errmsg='';
314
+ set &jobds(keep=state uri);
315
+ run;
316
+ %end;
317
+ /* nothing else needs the flow table - do not leave it in the caller's WORK */
318
+ proc datasets lib=work nolist nowarn;
319
+ delete &jobds;
320
+ quit;
261
321
  /* fetch results from webout.json */
262
322
  %mv_getjobresult(uri=&uri,
263
323
  result=&viyaresult,
@@ -269,6 +329,13 @@ filename &webref "&webrefpath";
269
329
  %end;
270
330
  %else %if &platform=SASJS %then %do;
271
331
 
332
+ /* the response is needed to judge the outcome, even if not requested -
333
+ * and only a ref we create here may be cleared afterwards */
334
+ %let respref=&outref;
335
+ %if "&respref"="0" and "&outstatus" ne "0" %then %do;
336
+ %let respref=%mf_getuniquefileref();
337
+ %let clearmeref=1;
338
+ %end;
272
339
  %ms_testservice(&program
273
340
  ,inputfiles=&inputfiles
274
341
  ,inputdatasets=&inputdatasets
@@ -276,8 +343,37 @@ filename &webref "&webrefpath";
276
343
  ,debug=&debug
277
344
  ,mdebug=&mdebug
278
345
  ,outlib=&outlib
279
- ,outref=&outref
346
+ ,outref=&respref
347
+ ,outlogds=&outlogds
280
348
  )
349
+ %if "&outstatus" ne "0" %then %do;
350
+ data &outstatus;
351
+ length state $20 uri $256 errmsg $256 platform $10;
352
+ retain state 'completed' uri '' errmsg '' platform 'SASJS' abortseen 0;
353
+ infile &respref end=eof lrecl=32767;
354
+ /* scan the whole response - the abort block is not always on the first
355
+ * line - but only take a message from inside that block, so a service
356
+ * with its own MSG field does not look like an abort */
357
+ do while(not eof);
358
+ input;
359
+ if index(_infile_,'"sasjsAbort"')>0 then do;
360
+ state='canceled';
361
+ abortseen=1;
362
+ end;
363
+ if abortseen=1 and errmsg='' and index(_infile_,'"MSG"')>0 then do;
364
+ /* prxchange returns its input untouched when nothing matches, which
365
+ * would put the whole line in errmsg */
366
+ if prxmatch('/"MSG" *: *"([^"]*)"/',_infile_) then
367
+ errmsg=prxchange('s/.*"MSG" *: *"([^"]*)".*/$1/',-1,_infile_);
368
+ end;
369
+ end;
370
+ /* one row, whatever the response contained */
371
+ output;
372
+ run;
373
+ %end;
374
+ %if %length(&clearmeref)>0 %then %do;
375
+ filename &respref clear;
376
+ %end;
281
377
 
282
378
  %end;
283
379
  %else %do;