sasjs context¶
The sasjs context command allows users to list all and export individual Compute Contexts. Administrators may also create, edit and delete contexts.
A compute context is used when firing up a new SAS session (it itself inherits from a Launcher Context). Example use cases for this tool:
- Creating a new compute context as part of a CI/CD deploy
- Deleting a compute context as part of a tidy up
- Discovering which compute contexts can actually be used
- Modifying a compute context, eg to update the autoexec or system account used
Prerequisites¶
Before using this command, you will need to install the SASJS CLI and add a deployment target.
Syntax¶
Additional arguments include:
| Option | Alias | Sub commands | Description |
|---|---|---|---|
--source |
-s |
create, edit |
The JSON file holding the context definition. Required for both. |
--target |
-t |
all | The target whose server holds the contexts. SAS Viya only. Defaults to defaultTarget in sasjsconfig.json, then the global .sasjsrc. |
Compute Context Structure¶
The create and edit actions use the same JSON structure for adding / modifying contexts. This also matches the context made by the export action, which can be used to provide a template for adding / modifying new contexts. The JSON is defined as follows:
{
"name": "myNewComputeContext",
"attributes": {
"reuseServerProcesses": true,
"runServerAs": "mycasaccount"
},
"environment": {
"autoExecLines": [
"%put autoexec line 1;",
"%put autoexect line 2;"
],
"options": [
"-BUFNO 10",
"-MEMSIZE 4G"
]
},
"launchContext": {
"contextName": "SAS Job Execution launcher context"
},
"launchType": "service",
}
To explain the sections:
name- name of the compute context you will createreuseServerProcesses- since Viya 3.5 you can re-use sessions, this improves performance significantly but requires the sessions to run under a system account (defined below)runServerAs- the system account to use when re-using server processesautoExecLines- an array of SAS program lines. These will execute ONCE when the server process is started, so expensive libname assignments could be placed here, speeding up web service response times.options- an array of SAS option settingscontextName- the name of the launcher context used to spawn the compute contextlaunchtype- a mandatory parameter, described in SAS Global Forum 2018 paper 2083
sasjs context create¶
Used to create a new compute context.
Syntax¶
sasjs context create -s source.json -t target
Usage¶
# create minimal context config
cat > ./myContext.json <<'EOL'
{
"name": "myNewComputeContext",
"launchContext": {
"contextName": "SAS Job Execution launcher context"
},
"launchType": "service"
}
EOL
# create the context using the target defined in sasjs add
sasjs context create -s ./myContext.json -t myTarget
sasjs context delete¶
Used to delete an existing context. No source JSON needed, contextName is used instead.
Syntax¶
sasjs context delete <contextName> -t target
Usage¶
sasjs context edit¶
Used to edit an existing context
Syntax¶
sasjs context edit <contextName> -s source.json -t target
Usage¶
# create JSON file with the changes to apply
cat > ./myContext.json <<'EOL'
{
"name": "myRenamedComputeContext",
"launchContext": {
"contextName": "Some Other launcher context"
},
"launchType": "service"
}
EOL
# update the context named myComputeContext
sasjs context edit myComputeContext -s ./myContext.json -t myTarget
sasjs context export¶
Exports specified compute context to contextName.json in the current folder. No source JSON is needed, just provide the contextName.
Syntax¶
sasjs context export <contextName> -t target
Usage¶
sasjs context list¶
Outputs a list of all accessible and inaccessible contexts. Accessible contexts are discovered by attempting to run %put &=sysuserid; on each context.
Syntax¶
sasjs context list -t target