Skip to content

Commit

Permalink
fix: adding outds and parameters to mv_jobexecute
Browse files Browse the repository at this point in the history
  • Loading branch information
allanbowe committed Nov 29, 2020
1 parent 3a90295 commit def0cc8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 26 deletions.
53 changes: 40 additions & 13 deletions all.sas
Original file line number Diff line number Diff line change
Expand Up @@ -12299,6 +12299,12 @@ libname &libref1 clear;
,name=somejob
)
Example with parameters:
%mv_jobexecute(path=/Public/folder
,name=somejob
,paramstring=%str("macvarname":"macvarvalue","answer":42)
)
@param access_token_var= The global macro variable to contain the access token
@param grant_type= valid values:
Expand All @@ -12310,10 +12316,14 @@ libname &libref1 clear;
@param path= The SAS Drive path to the job being executed
@param name= The name of the job to execute
@param params= A macro quoted string to append to the URL
@param paramstring= A JSON fragment with name:value pairs, eg: `"name":"value"`
or "name":"value","name2":42`. This will need to be wrapped in `%str()`.
@param contextName= Context name with which to run the job.
Default = `SAS Job Execution compute context`
@param outds= The output dataset containing links (Default=work.mv_jobexecute)
@version VIYA V.03.04
@author Allan Bowe, source: https://github.com/sasjs/core
Expand All @@ -12322,6 +12332,7 @@ libname &libref1 clear;
@li mp_abort.sas
@li mf_getplatform.sas
@li mf_getuniquefileref.sas
@li mf_getuniquelibref.sas
@li mv_getfoldermembers.sas
**/
Expand All @@ -12331,6 +12342,8 @@ libname &libref1 clear;
,contextName=SAS Job Execution compute context
,access_token_var=ACCESS_TOKEN
,grant_type=sas_services
,paramstring=0
,outds=work.mv_jobexecute
);
%local oauth_bearer;
%if &grant_type=detect %then %do;
Expand Down Expand Up @@ -12392,11 +12405,16 @@ run;

data _null_;
file &fname0;
put '{"jobDefinitionUri": "'@@;
put "&joburi"@@;
put '","arguments":{"_contextName":"'@@;
put "&contextName"@@;
put '"}}';
length joburi contextname $128 paramstring $32765;
joburi=quote(trim(symget('joburi')));
contextname=quote(trim(symget('contextname')));
paramstring=symget('paramstring');
put '{"jobDefinitionUri":' joburi ;
put ' ,"arguments":{"_contextName":' contextname;
if paramstring ne "0" then do;
put ' ,' paramstring;
end;
put '}}';
run;

proc http method='POST' in=&fname0 out=&fname1 &oauth_bearer
Expand All @@ -12408,18 +12426,27 @@ proc http method='POST' in=&fname0 out=&fname1 &oauth_bearer
%end;
;
run;
/*data _null_;infile &fname1;input;putlog _infile_;run;*/

%mp_abort(iftrue=(
&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;
data _null_;infile &fname0;input;putlog _infile_;run;
data _null_;infile &fname1;input;putlog _infile_;run;
%mp_abort(mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
)
,mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
)
%end;

%local libref;
%let libref=%mf_getuniquelibref();
libname &libref JSON fileref=&fname1;

data &outds;
set &libref..links;
run;

/* clear refs */
filename &fname0 clear;
filename &fname1 clear;
libname &libref;

%mend;/**
@file mv_registerclient.sas
Expand Down
53 changes: 40 additions & 13 deletions viya/mv_jobexecute.sas
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
,name=somejob
)
Example with parameters:
%mv_jobexecute(path=/Public/folder
,name=somejob
,paramstring=%str("macvarname":"macvarvalue","answer":42)
)
@param access_token_var= The global macro variable to contain the access token
@param grant_type= valid values:
Expand All @@ -27,10 +33,14 @@
@param path= The SAS Drive path to the job being executed
@param name= The name of the job to execute
@param params= A macro quoted string to append to the URL
@param paramstring= A JSON fragment with name:value pairs, eg: `"name":"value"`
or "name":"value","name2":42`. This will need to be wrapped in `%str()`.
@param contextName= Context name with which to run the job.
Default = `SAS Job Execution compute context`
@param outds= The output dataset containing links (Default=work.mv_jobexecute)
@version VIYA V.03.04
@author Allan Bowe, source: https://github.com/sasjs/core
Expand All @@ -39,6 +49,7 @@
@li mp_abort.sas
@li mf_getplatform.sas
@li mf_getuniquefileref.sas
@li mf_getuniquelibref.sas
@li mv_getfoldermembers.sas
**/
Expand All @@ -48,6 +59,8 @@
,contextName=SAS Job Execution compute context
,access_token_var=ACCESS_TOKEN
,grant_type=sas_services
,paramstring=0
,outds=work.mv_jobexecute
);
%local oauth_bearer;
%if &grant_type=detect %then %do;
Expand Down Expand Up @@ -109,11 +122,16 @@ run;

data _null_;
file &fname0;
put '{"jobDefinitionUri": "'@@;
put "&joburi"@@;
put '","arguments":{"_contextName":"'@@;
put "&contextName"@@;
put '"}}';
length joburi contextname $128 paramstring $32765;
joburi=quote(trim(symget('joburi')));
contextname=quote(trim(symget('contextname')));
paramstring=symget('paramstring');
put '{"jobDefinitionUri":' joburi ;
put ' ,"arguments":{"_contextName":' contextname;
if paramstring ne "0" then do;
put ' ,' paramstring;
end;
put '}}';
run;

proc http method='POST' in=&fname0 out=&fname1 &oauth_bearer
Expand All @@ -125,17 +143,26 @@ proc http method='POST' in=&fname0 out=&fname1 &oauth_bearer
%end;
;
run;
/*data _null_;infile &fname1;input;putlog _infile_;run;*/

%mp_abort(iftrue=(
&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;
data _null_;infile &fname0;input;putlog _infile_;run;
data _null_;infile &fname1;input;putlog _infile_;run;
%mp_abort(mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
)
,mac=&sysmacroname
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
)
%end;

%local libref;
%let libref=%mf_getuniquelibref();
libname &libref JSON fileref=&fname1;

data &outds;
set &libref..links;
run;

/* clear refs */
filename &fname0 clear;
filename &fname1 clear;
libname &libref;

%mend;

0 comments on commit def0cc8

Please sign in to comment.