Читать книгу SAS Viya - Kevin D. Smith - Страница 18

Running CAS Actions

Оглавление

In the previous section, we made a connection to CAS, but didn’t explicitly perform any actions. However, after the connection was made, many actions were performed to obtain information about the server and what resources are available to the CAS installation. One of the things queried for is information about the currently loaded action sets. An action set is a collection of actions that can be executed. Actions can do various things such as return information about the server setup, load data, and perform advanced analytics. To see what action sets and actions are already loaded, you can call the help action on the CAS object that we previously created.

In [4]: out = conn.help()

NOTE: Available Action Sets and Actions:

NOTE: accessControl

NOTE: assumeRole - Assumes a role

NOTE: dropRole - Relinquishes a role

NOTE: showRolesIn - Shows the currently active role

NOTE: showRolesAllowed - Shows the roles that a user is

a member of

NOTE: isInRole - Shows whether a role is assumed

NOTE: isAuthorized - Shows whether access is authorized

NOTE: isAuthorizedActions - Shows whether access is

authorized to actions

NOTE: isAuthorizedTables - Shows whether access is authorized

to tables

NOTE: isAuthorizedColumns - Shows whether access is authorized

to columns

NOTE: listAllPrincipals - Lists all principals that have

explicit access controls

NOTE: whatIsEffective - Lists effective access and

explanations (Origins)

NOTE: listAcsData - Lists access controls for caslibs, tables,

and columns

NOTE: listAcsActionSet - Lists access controls for an action

or action set

NOTE: repAllAcsCaslib - Replaces all access controls for

a caslib

NOTE: repAllAcsTable - Replaces all access controls for a table

NOTE: repAllAcsColumn - Replaces all access controls for

a column

NOTE: repAllAcsActionSet - Replaces all access controls for

an action set

NOTE: repAllAcsAction - Replaces all access controls for

an action

NOTE: updSomeAcsCaslib - Adds, deletes, and modifies some

access controls for a caslib

NOTE: updSomeAcsTable - Adds, deletes, and modifies some

access controls for a table

NOTE: updSomeAcsColumn - Adds, deletes, and modifies some

access controls for a column

NOTE: updSomeAcsActionSet - Adds, deletes, and modifies some

access controls for an action set

NOTE: updSomeAcsAction - Adds, deletes, and modifies some

access controls for an action

NOTE: remAllAcsData - Removes all access controls for a

caslib, table, or column

... truncated ...

This prints out a listing of all of the loaded action sets and the actions within them. It also returns a CASResults structure that contains the action set information in tabular form. The results of CAS actions are discussed later in this chapter.

The help action takes arguments that specify which action sets and actions you want information about. To display help for an action set, use the actionset keyword parameter. The following code displays the help content for the builtins action set.

In [5]: out = conn.help(actionset='builtins')

NOTE: Information for action set 'builtins':

NOTE: builtins

NOTE: addNode - Adds a machine to the server

NOTE: removeNode - Remove one or more machines from the server

NOTE: help - Shows the parameters for an action or lists all

available actions

NOTE: listNodes - Shows the host names used by the server

NOTE: loadActionSet - Loads an action set for use in this

session

NOTE: installActionSet - Loads an action set in new sessions

automatically

NOTE: log - Shows and modifies logging levels

NOTE: queryActionSet - Shows whether an action set is loaded

NOTE: queryName - Checks whether a name is an action or

action set name

NOTE: reflect - Shows detailed parameter information for an

action or all actions in an action set

NOTE: serverStatus - Shows the status of the server

NOTE: about - Shows the status of the server

NOTE: shutdown - Shuts down the server

NOTE: userInfo - Shows the user information for your connection

NOTE: actionSetInfo - Shows the build information from loaded

action sets

NOTE: history - Shows the actions that were run in this session

NOTE: casCommon - Provides parameters that are common to many

actions

NOTE: ping - Sends a single request to the server to confirm

that the connection is working

NOTE: echo - Prints the supplied parameters to the client log

NOTE: modifyQueue - Modifies the action response queue settings

NOTE: getLicenseInfo - Shows the license information for a

SAS product

NOTE: refreshLicense - Refresh SAS license information from

a file

NOTE: httpAddress - Shows the HTTP address for the server

monitor

Notice that help is one of the actions in the builtins action set. To display the Help for an action, use the action keyword argument. You can display the Help for the help action as follows:

In [6]: out = conn.help(action='help')

NOTE: Information for action 'builtins.help':

NOTE: The following parameters are accepted.

Default values are shown.

NOTE: string action=NULL,

NOTE: specifies the name of the action for which you want help.

The name can be in the form 'actionSetName.actionName' or

just 'actionName'.

NOTE: string actionSet=NULL,

NOTE: specifies the name of the action set for which you

want help. This parameter is ignored if the action

parameter is specified.

NOTE: boolean verbose=true

NOTE: when set to True, provides more detail for each parameter.

Looking at the printed notes, you can see that the help action takes the parameters actionset, action, and verbose. We have previously seen the actionset and action parameters. The verbose parameter is enabled, which means that you will get a full description of all of the parameters of the action. You can suppress the parameter descriptions by specifying verbose=False as follows:

In [7]: out = conn.help(action='help', verbose=False)

NOTE: Information for action 'builtins.help':

NOTE: The following parameters are accepted.

Default values are shown.

NOTE: string action=NULL,

NOTE: string actionSet=NULL,

NOTE: boolean verbose=true

In addition to the Help system that is provided by CAS, the SWAT module also enables you to access the action set and action information using mechanisms supplied by Python and IPython. Python supplies the help function to display information about Python objects. This same function can be used to display information about CAS action sets and actions. We have been using the help action on our CAS object. Let’s see what the Python help function displays.

In [8]: help(conn.help)

Help on builtins.Help in module swat.cas.actions object:

class builtins.Help(CASAction)

| Shows the parameters for an action or lists all available actions

|

| Parameters

| ----------

| action : string, optional

| specifies the name of the action for which you want help.

| The name can be in the form 'actionSetName.actionName' or

| just 'actionName'.

|

| actionset : string, optional

| specifies the name of the action set for which you want help.

| This parameter is ignored if the action parameter is

| specified.

|

| verbose : boolean, optional

| when set to True, provides more detail for each parameter.

| Default: True

|

| Returns

| -------

| Help object

... truncated ...

It gets a little confusing in that code snippet because both the name of the function in Python and the name of the action are the same, but you see that the information displayed by Python’s Help system is essentially the same as what CAS displayed. You can also use the IPython/Jupyter Help system (our preferred method) by following the action name with a question mark.

In [9]: conn.help?

Type: builtins.Help

String form: ?.builtins.Help()

File: swat/cas/actions.py

Definition: ?.help(_self_, action=None,

actionset=None,

verbose=True, **kwargs)

Docstring:

Shows the parameters for an action or lists all available actions

Parameters

----------

action : string, optional

specifies the name of the action for which you want help. The name

can be in the form 'actionSetName.actionName' or just 'actionName.

actionset : string, optional

specifies the name of the action set for which you want help. This

parameter is ignored if the action parameter is specified.

verbose : boolean, optional

when set to True, provides more detail for each parameter.

Default: True

Returns

-------

Help object

... truncated ...

These methods of getting help work both on actions and action sets. For example, we know that there is a builtins action set that the help action belongs to. The CAS object has an attribute that maps to the builtins action set just like the help action. We can display the help for the builtins action set as follows:

In [10]: conn.builtins?

Type: Builtins

String form: <swat.cas.actions.Builtins object at 0x7f7ad35b9048>

File: swat/cas/actions.py

Docstring:

System

Actions

-------

builtins.about : Shows the status of the server

builtins.actionsetinfo : Shows the build information from loaded

action sets

builtins.addnode : Adds a machine to the server

builtins.cascommon : Provides parameters that are common to

many actions

builtins.echo : Prints the supplied parameters to the

client log

builtins.getgroups : Shows the groups from the authentication

provider

builtins.getlicenseinfo : Shows the license information for a SAS

product

builtins.getusers : Shows the users from the authentication

provider

builtins.help : Shows the parameters for an action or

lists all available actions

builtins.history : Shows the actions that were run in this

session

builtins.httpaddress : Shows the HTTP address for the server

monitor

builtins.installactionset : Loads an action set in new sessions

automatically

builtins.listactions : Shows the parameters for an action or

lists all available actions

builtins.listnodes : Shows the host names used by the server

builtins.loadactionset : Loads an action set for use in this

session

builtins.log : Shows and modifies logging levels

builtins.modifyqueue : Modifies the action response queue

settings

builtins.ping : Sends a single request to the server to

confirm that the connection is working

builtins.queryactionset : Shows whether an action set is loaded

builtins.queryname : Checks whether a name is an action or

action set name

builtins.reflect : Shows detailed parameter information for

an action or all actions in an action set

builtins.refreshlicense : Refresh SAS license information from a

file

builtins.refreshtoken : Refreshes an authentication token for this

session

builtins.removenode : Remove one or more machines from the

server

builtins.serverstatus : Shows the status of the server

builtins.setlicenseinfo : Sets the license information for a SAS

product

builtins.shutdown : Shuts down the server

builtins.userinfo : Shows the user information for your

connection

Each time that an action set is loaded into the server, the information about the action set and its actions are reflected back to SWAT. SWAT then creates attributes on the CAS object that map to the new action sets and actions, including all of the documentation and Help system hooks. The advantage is that the documentation about actions can never get out of date in the Python client.

In addition to the documentation, since the action sets and actions appear as attributes on the CAS object, you can also use tab completion to display what is in an action set.

In [11]: conn.builtins.<tab>

conn.builtins.about conn.builtins.loadactionset

conn.builtins.actionsetinfo conn.builtins.log

conn.builtins.addnode conn.builtins.modifyqueue

conn.builtins.cascommon conn.builtins.ping

conn.builtins.echo conn.builtins.queryactionset

conn.builtins.getgroups conn.builtins.queryname

conn.builtins.getlicenseinfo conn.builtins.reflect

conn.builtins.getusers conn.builtins.refreshlicense

conn.builtins.help conn.builtins.refreshtoken

conn.builtins.history conn.builtins.removenode

conn.builtins.httpaddress conn.builtins.serverstatus

conn.builtins.installactionset conn.builtins.setlicenseinfo

conn.builtins.listactions conn.builtins.shutdown

conn.builtins.listnodes conn.builtins.userinfo

Now that we have seen how to query the server for available action sets and actions, and we know how to get help for the actions, we can move on to some more advanced action calls.

SAS Viya

Подняться наверх