Published on :
Administration CREATION_INTERNE

Adding Deployment Directories to SAS Metadata

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The program connects to the SAS© metadata server, then creates an internal dataset containing the names and paths of the directories to be added. It checks for the existence of the target application context. If the context is found, the script iterates through the dataset and, for each entry, creates a new metadata object of type 'Directory' associated with that context, specifying its physical path and other required attributes.
Data Analysis

Type : CREATION_INTERNE


Information about deployment directories (name and path) is created directly within the script via a DATA step and a 'datalines' statement.

1 Code Block
OPTIONS
Explanation :
This block configures system options to establish a connection to the SAS metadata server. It specifies the host, port, user credentials, repository (Foundation), and connection protocol (BRIDGE).
Copied!
1/* Define connection to Metadata. */
2options
3 metaserver="meta.demo.sas.com"
4 metaport=8561
5 metauser="sasadm @saspw"
6 metapass="password"
7 metarepository=Foundation
8 metaprotocol=BRIDGE;
2 Code Block
DATA STEP Data
Explanation :
Defines a macro variable 'appcontext' for the context name. Then, a DATA step creates the 'depdirs' table in memory. This table contains two columns, 'Name' and 'Path', which are populated via the 'datalines' statement with the list of deployment directories to be created.
Copied!
1/* Define the context to attach the deployment directories. */
2%let appcontext = SASApp;
3 
4/* Create a dataset with each deployment directory name and path. */
5DATA depdirs;
6 LENGTH Name Path $ 255;
7 INPUT Name Path;
8 DATALINES;
9 DeploymentDir1 /tmp/depdir1
10 DeploymentDir2 /tmp/depdir2
11 ;;
12RUN;
3 Code Block
DATA STEP
Explanation :
This DATA _null_ step (which does not produce an output table) manages the main logic. It starts by resolving the application context's URI via 'metadata_resolve'. If the context is found, it reads the 'depdirs' table line by line. For each line, it uses 'metadata_newobj' to create a new 'Directory' object and 'metadata_setattr' to define its attributes, notably the path ('DirectoryName').
Copied!
1DATA _null_;
2 
3/* Initialize variables. */
4LENGTH type id appuri diruri $ 255;
5call missing (of _character_);
6 
7/* Define query for context. */
8appobj = "omsobj:ServerContext? @Name='&appcontext'";
9 
10/* Check for the existence of the context. */
11rc=metadata_resolve(appobj,type,id);
12 
13/* If the context doesn't exist, throw an error and end the program. */
14IF rc ne 1 THEN DO;
15put "ERROR: A single context named &appcontext not found.";
16stop;
17END;
18 
19/* Read in the data set of deployment directories. */
20SET depdirs;
21 
22/* For each one, create the directory object as a child of the context */
23/* defined above. */
24rc=metadata_newobj("Directory",diruri,Name,"Foundation",appobj,"DataPackages");
25 
26/* Add the attribute defining the path. */
27rc=metadata_setattr(diruri,"DirectoryName",Path);
28 
29/* Add some required attributes. */
30rc=metadata_setattr(diruri,"UsageVersion","0");
31rc=metadata_setattr(diruri,"IsRelative","0");
32 
33RUN;
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 : Author: Greg Wootton Date: 14JUN2019


Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« Programmatically adding deployment directories is an advanced administration technique that ensures consistency across your server contexts (such as SASApp). By using metadata interface functions rather than the manual GUI, you eliminate human entry errors and enable the industrial deployment of technical folder structures across multi-tier environments. »