Published on :

Updating Server Contexts for SAS Libraries

This code is also available in: Deutsch Español Français
Attention : This code requires administrator privileges.
This script connects to a SAS© 9 metadata server. It first identifies the URI of a specific application server context (here, 'SASSTP'). Then, it searches for all SAS© libraries matching a metadata query. For each library found, it adds the server context to its 'DeployedComponents' list. The script includes checks to ensure that the context and libraries exist before proceeding with the update. Important: this script uses SAS© 9 metadata functions and is not compatible with SAS© Viya 4. The query to find the libraries (`libobj`) seems to contain a syntax error (` @code_sas©_json/RFValid.json contains '.'`) and should probably target an attribute like ` @Name`.
Data Analysis

Type : MIXED


The script does not use data in the traditional sense (SAS tables). It reads and modifies objects (metadata) directly on the SAS metadata server. The 'source' data are the definitions of server contexts and SAS libraries stored in the metadata.

1 Code Block
OPTIONS
Explanation :
This block configures the connection parameters for the SAS 9 metadata server (host, port, credentials, repository). These options are necessary for metadata functions to interact with the server. This type of connection is deprecated in SAS Viya 4.
Copied!
1options
2 metaserver="meta.demo.sas.com"
3 metaport=8561
4 metauser="sasadm @saspw"
5 metapass="password"
6 metarepository=Foundation
7 metaprotocol=Bridge;
2 Code Block
DATA STEP
Explanation :
This _NULL_ DATA STEP (does not create a table) is the core of the program. It uses SAS 9 metadata functions. First, it uses `metadata_resolve` to find the URI of an application server context ('SASSTP'). If the context is found, it executes a second query to find SAS libraries. For each library found, it uses `metadata_setassn` to associate the server context with it. Error messages are issued and the program stops if the context or libraries are not found.
Copied!
1DATA _null_;
2 
3/* Initialize variables. */
4 
5 LENGTH type id app_uri lib_uri $ 50;
6 call missing(of _character_);
7 
8/* Define query for the Application Server Context */
9/* to add to the libraries and search for it. */
10 
11 appobj="omsobj:ServerContext? @Name='SASSTP'";
12 app_count=metadata_resolve(appobj,type,id);
13 
14/* If no context matches this query, stop the program with an error. */
15 
16 IF app_count <= 0 THEN DO;
17 put "ERROR: No application server context found matching query " appobj;
18 stop;
19 END;
20 ELSE DO;
21 
22/* Extract the URI of the context if it exists. */
23 
24 rc=metadata_getnobj(appobj,1,app_uri);
25 
26/* Define the query for the libraries to be updated and search for them. */
27 
28 libobj="omsobj:SASLibrary? @code_sas_json/RFValid.json contains '.'";
29 lib_count=metadata_resolve(libobj,type,id);
30 
31/* If no libraries match the query, stop the program with an error. */
32 IF lib_count <= 0 THEN DO;
33 put "ERROR: No libraries found matching query " libobj;
34 stop;
35 END;
36 
37/* If libraries are found, for each one append */
38/* the context to its list of associated contexts. */
39 
40 ELSE DO n=1 to lib_count;
41 rc=metadata_getnobj(libobj,1,lib_uri);
42 rc=metadata_setassn(lib_uri,"DeployedComponents","Append",app_uri);
43 END;
44 END;
45RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © 2023, SAS Institute Inc., Cary, NC, USA. All Rights Reserved. SPDX-License-Identifier: Apache-2.0


Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« In a SAS 9.4 environment, the relationship between a SAS Library and an Application Server (like SASApp or SASSTP) is defined through a metadata association called DeployedComponents. This script is an excellent administrative tool for bulk-assigning libraries to new server contexts, which is often required during server migrations or when horizontal scaling is implemented. »