SAS Viya compute contexts provide a place to customize the programming run-time, with SAS options, autoexec code, environment variables, and compute context attributes. Compute context attributes, and our newest pyviyatool to add, update and remove attributes from compute contexts, are the focus of this post.
For several GEL workshops we need to update compute context attributes as the workshop collection starts, or during a hands-on exercise. We would much prefer to script those updates, and none of the existing ways of doing it (discussed below) seemed very straightforward to me. So I wrote a couple of new pyviyatools to do the job:
I hope they will one day become redundant, as the sas-viya CLI would be a better place to provide this functionality. But in the mean time, these do a nice job. Read on to see what they do and why they are so useful.
Examples of compute context attributes include:
There are many more documented in the Compute Context Attributes section of the SAS Viya Administration > Servers and Services > SAS Programming Run-Time Environment > Server Contexts documentation, in the Reference section.
Until now the only ways to add or remove attributes from a compute context has been to either:
Well, now our two new pyviyatools provide another way to set them, and - especially if you already use the pyviyatools - I think they are rather easier to use.
The getcomputecontextattributes.py pyviyatool lists the attributes of a compute context. Like all the examples in this post, I have cloned a current version of pyviyatools, cd'd into the project directory and authenticated with the sas-viya CLI using ./loginviyauthinfo.py. Then:
./getcomputecontextattributes.py -n "Data Mining compute context"
Example output:
Attribute: reuseServerProcesses : true Attribute: runServerAs : sastest1 Attribute: serverInactiveTimeout : 900 Attribute: serverMinAvailable : 24
...or, if the compute context doesn't have any attributes:
Compute context 'SAS Model Manager compute context' has no attributes
Unsurprisingly, the setcomputecontextattributes.py pyviyatool is used to add, update or remove attributes from compute contexts. Here are some examples, starting with adding a new attribute:
./setcomputecontextattributes.py -n "Data Mining compute context" -a runAsUser -v sastest1
Example output:
Attribute: runAsUser to be added, with value sastest1
The tool will tell you if you are setting an attribute to a value that it already has. Let's run the exact same command we ran a moment ago:
./setcomputecontextattributes.py -n "Data Mining compute context" -a runAsUser -v sastest1
Example output:
Attribute: runAsUser already has value: sastest1, it will not be updated
But if you set the attribute to a different value, you can update an existing attribute's value:
./setcomputecontextattributes.py -n "Data Mining compute context" -a runAsUser -v dmuser
Example output:
Attribute: runAsUser : sastest1 to be updated to dmuser
The tool will also remove a named attribute, if it exists:
./setcomputecontextattributes.py -n "Data Mining compute context" -r runAsUser
Example output:
Attribute: runAsUser : sastest1 to be removed
But if the compute context does not have (or no longer has) the attribute, you will instead see:
Attribute: runAsUser was not found and cannot be removed
On some of our larger shared collections, where we have a .authinfo file as described here, and where pyviyatools is cloned from GitHub to /opt/pyviyatools, we set up one of the compute contexts for use in analytics workshops like this:
cd /opt/pyviyatools/ ./loginviauthinfo.py -f ~/.authinfo_sasadm ./getcomputecontextattributes.py -n "Data Mining compute context" ./setcomputecontextattributes.py -n "Data Mining compute context" -a reuseServerProcesses -v true ./setcomputecontextattributes.py -n "Data Mining compute context" -a runServerAs -v sastest1 ./setcomputecontextattributes.py -n "Data Mining compute context" -a serverInactiveTimeout -v 900 ./setcomputecontextattributes.py -n "Data Mining compute context" -a serverMinAvailable -v 24 ./getcomputecontextattributes.py -n "Data Mining compute context" ./getcomputecontextattributes.py -n "SAS Studio compute context" ./setcomputecontextattributes.py -n "SAS Studio compute context" -a reuseServerProcesses -v true ./setcomputecontextattributes.py -n "SAS Studio compute context" -a runServerAs -v sastest1 ./setcomputecontextattributes.py -n "SAS Studio compute context" -a serverInactiveTimeout -v 900 ./setcomputecontextattributes.py -n "SAS Studio compute context" -a serverMinAvailable -v 6 ./getcomputecontextattributes.py -n "SAS Studio compute context" cd -
This saves a few minutes of manual intervention when we refresh the workshop deployment.
My thanks to Jason Spruill for his help in reviewing my (very amateur) calls to the compute server REST APIs, and to Gerry Nelson for help testing I didn't break our callrestapi shared function by extending it to support eTags. Any mistakes or poor code are entirely my responsibility.
See you next time!
Find more articles from SAS Global Enablement and Learning here.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.