Published on :
Administration INTERNAL_CREATION

Extracting Metadata Deployment Directories

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The program establishes a connection to the SAS© metadata server using the 'metaserver', 'metaport', 'metauser', 'metapass', 'metarepository', and 'metaprotocol' options. It then initializes a DATA step to query the metadata. The script uses the 'metadata_resolve', 'metadata_getnobj', 'metadata_getnasn', and 'metadata_getattr' functions to identify 'Directory' objects with an associated 'ServerContext' (designating deployment directories). For each directory found, it retrieves its name, path, associated applications, contained files, and, if transformations (jobs) are linked to the files, the job name and owner. The collected information is stored in the 'work.deployfiles' table. Finally, PROC PRINT is used to display the contents of this table.
Data Analysis

Type : INTERNAL_CREATION


Data is dynamically generated by querying the SAS metadata environment via SAS Metadata Interface functions. No external data sources (files, databases, etc.) are read directly by the script.

1 Code Block
OPTIONS
Explanation :
This block configures the connection to the SAS metadata server, specifying the address, port, credentials, repository, and protocol. These options are crucial to allow the script to interact with the metadata environment.
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 Data
Explanation :
This DATA step connects to SAS metadata to extract information about deployment directories. It uses SAS Metadata Interface functions to resolve directory objects, retrieve their attributes (name, path), as well as associated applications, files, and jobs. Variables are declared and kept to form a new 'work.deployfiles' dataset containing details of directories, files, and job owners.
Copied!
1DATA work.deployfiles;
2 
3 /* declare and initialize variables */
4 LENGTH app_name type dir_uri app_uri dir_name file_uri file_name owner
5 trans_uri resp_uri job_name $ 50 id $ 17 dir_path $ 255;
6 call missing(of _character_);
7 
8 /* variables to store to table */
9 keep app_name dir_name dir_path file_name owner job_name;
10 
11 /* Define a query to find deployment directories (directory objects with an */
12 /* associated server context). */
13 dir_obj="omsobj:Directory?Directory[ @code_sas_json/downside_frequency_test.json contains '.'][DeployedComponents/ServerContext]";
14 /* Count number of directories with an associated server context. */
15 dir_rc=metadata_resolve(dir_obj,type,id);
16 
17 /* if directories exist, pull data from them. */
18 IF dir_rc > 0 THEN DO n=1 to dir_rc;
19 
20 rc=metadata_getnobj(dir_obj,n,dir_uri);
21 rc=metadata_getnasn(dir_uri,"DeployedComponents",1,app_uri);
22 rc=metadata_getattr(app_uri,"Name",app_name);
23 rc=metadata_getattr(dir_uri,"Name",dir_name);
24 rc=metadata_getattr(dir_uri,"DirectoryName",dir_path);
25 
26 file_rc=metadata_getnasn(dir_uri,"Files",1,file_uri);
27 
28 /* if files are associated with the directory, pull data on them. */
29 IF file_rc > 0 THEN DO m=1 to file_rc;
30 
31 rc=metadata_getnasn(dir_uri,"Files",m,file_uri);
32 rc=metadata_getattr(file_uri,"FileName",file_name);
33 trans_rc=metadata_getnasn(file_uri,"AssociatedTransformation",1,trans_uri);
34 
35 /* if jobs are associated with the files, pull the responsible */
36 /* party of that job. */
37 IF trans_rc > 0 THEN DO o=1 to trans_rc;
38 
39 rc=metadata_getnasn(file_uri,"AssociatedTransformation",o,trans_uri);
40 rc=metadata_getattr(trans_uri,"Name",job_name);
41 rc=metadata_getnasn(trans_uri,"ResponsibleParties",1,resp_uri);
42 rc=metadata_getattr(resp_uri,"Name",owner);
43 OUTPUT;
44 END;
45 ELSE put "INFO: No Associations Found";
46 END;
47 ELSE put "INFO: No Associated Files Found";
48 
49 END;
50 ELSE put "INFO: No Deployment Directories Found";
51RUN;
3 Code Block
PROC PRINT
Explanation :
This procedure generates a readable report by displaying the content of the 'work.deployfiles' table created during the previous DATA step. It allows visualizing deployment directories and their information extracted from metadata.
Copied!
1PROC PRINT DATA=deployfiles; RUN;
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 : This program pulls a list of Deployment Directories to Metadata. Author: Greg Wootton Date: 09DEC2016


Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« Maintaining a healthy SAS environment requires full visibility into how physical resources relate to metadata objects. Using DATA step metadata functions is the most powerful method for auditing these links. This script doesn't just list directories; it reconstructs the lineage between physical paths, deployed code, and the responsible stakeholders. »