BookmarkSubscribeRSS Feed

Add, update and remove compute context attributes with new pyviyatools

Started ‎04-01-2022 by
Modified ‎04-01-2022 by
Views 3,930

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.

 

What are compute context attributes?

 

 Examples of compute context attributes include:

 

  • runServerAs: run as a specific account, instead of the logged-on user (not supported when user identities are provided by SCIM)
  • reuseServerProcesses: for contexts which runServerAs a specific user, keep compute sessions around for a while after they have finished being used, to see if another client requests a compute session under the same context. If so, the same server process can be reused, and the startup overhead is avoided.
  • serverInactiveTimeout: define how long the server should remain running while it is inactive.

 

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:

 

  • create or update a compute context interactively in SAS Environment Manager's contexts page, in the Compute Contexts view, or
  • programmatically create a compute context with the desired attributes using the sas-viya CLI, e.g. sas-viya compute contexts create -d /path/to/json_file, or
  • use the SASjs CLI, an open-source project with which I have no experience, but it looks like it provides a way to update compute contexts: see Managing SAS Viya Compute Contexts with SASjs - SAS Dev Ops with SASjs CLI.

 

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.  

 

getcomputecontextattributes.py

 

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

 

setcomputecontextattributes.py

 

Add an attribute

 

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

 

Update an attribute

 

 

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

 

Remove an attribute

 

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

 

Conclusion

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.

Version history
Last update:
‎04-01-2022 11:38 AM
Updated by:
Contributors

SAS Innovate 2025: Register Now

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!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags