L'extraction programmatique des chemins sources des Jobs SAS Data Integration est une tâche critique pour tout administrateur souhaitant cartographier son patrimoine applicatif ou préparer une migration. Ce script illustre parfaitement la puissance des fonctions d'interface de métadonnées pour "recoller" les morceaux entre le monde logique (le Job en métadonnées) et le monde physique (le fichier .sas sur le serveur).
Type : EXTERNE
Les données proviennent du SAS Metadata Server (SAS 9). Le script utilise les fonctions d'interface de métadonnées (`metadata_resolve`, `metadata_getnobj`, `metadata_getattr`, `metadata_getnasn`) pour extraire les informations.
| 1 | options metaserver="my.sas.server" |
| 2 | metaport=8561 |
| 3 | metauser="sasadm @saspw" |
| 4 | metapass="password" |
| 5 | metarepository=Foundation |
| 6 | metaprotocol=bridge; |
| 1 | DATA SOURCE; |
| 2 | |
| 3 | keep job_name SOURCE; /* Retain only the job name and it's source code full path. */ |
| 4 | |
| 5 | /* Initialize variables. */ |
| 6 | |
| 7 | LENGTH type id job_uri job_name file_uri file_name dir_uri path $ 50; |
| 8 | call missing (of _character_); |
| 9 | |
| 10 | obj="omsobj:Job? @code_sas_json/_render_idcolumn.json contains '.'"; /* Search critera for Jobs. */ |
| 11 | |
| 12 | job_count=metadata_resolve(obj,type,id); /* Count all jobs. Only run loop if jobs exist. */ |
| 13 | |
| 14 | IF job_count > 0 THEN DO i=1 to job_count; /* Loop: For each job found, get attributes and associations. */ |
| 15 | rc=metadata_getnobj(obj,i,job_uri); |
| 16 | rc=metadata_getattr(job_uri,"Name",job_name); /* Get job name. */ |
| 17 | rc=metadata_getnasn(job_uri,"SourceCode",1,file_uri); /* Get file Metadata object id. */ |
| 18 | rc=metadata_getattr(file_uri,"Name",file_name); /* Get file name. */ |
| 19 | rc=metadata_getnasn(file_uri,"Directories",1,dir_uri); /* Get directory Metadata object id. */ |
| 20 | rc=metadata_getattr(dir_uri,"DirectoryName",path); /* Get path to directory. */ |
| 21 | SOURCE=catx('/',path,file_name); /* combine directory path and file name to create full path to file.*/ |
| 22 | OUTPUT; |
| 23 | END; /* End loop. */ |
| 24 | ELSE put "WARN: No jobs found in Metadata."; /* If no jobs are found, write a message to the log. */ |
| 25 | RUN; |