Published on :
Administration CREATION_INTERNE

DMS Tasks and Logs Cleanup

This code is also available in: Deutsch Español Français
Awaiting validation
Attention : This code requires administrator privileges.
The DMSRVADM procedure is used to administer the DataFlux Data Management Server. This example illustrates how to obtain a report of ongoing or completed tasks, and then how to use the information from this report (specifically the task identifier 'jobid') to invoke the DMSrvKillJob and DMSrvDeleteLog functions. These functions are essential for releasing resources and maintaining server order by stopping unwanted processes and erasing execution traces.
Data Analysis

Type : CREATION_INTERNE


Examples generate simulated data ('work.joblist') to demonstrate function calls without relying on pre-existing external data, or use simulated CAS sessions for Viya examples.

1 Code Block
PROC DMSRVADM / DATA _NULL_ Data
Explanation :
This basic example shows how to use PROC DMSRVADM to generate a task report. Then, a Data Step iterates through this report and simulates calling the DMSrvKillJob and DMSrvDeleteLog functions for each task. Actual calls are commented out; a simple PUT statement is used for illustration.
Copied!
1DATA work.joblist;
2 LENGTH jobid $16. STATUS $10.;
3 INPUT jobid $ STATUS $;
4 DATALINES;
5JOB001 RUNNING
6JOB002 COMPLETED
7JOB003 FAILED
8JOB004 RUNNING
9;
10RUN;
11 
12PROC DMSRVADM
13 out=work.jobReport
14 host='http://myhost.unx.com' port=50001;
15RUN;
16 
17DATA _null_;
18 SET work.joblist;
19 put 'Simulating kill and delete for JobID: ' jobid;
20 /* Dans un environnement réel, ces fonctions seraient appelées. Ici, nous les simulons. */
21 /* kjrc=dmsrvkilljob (jobid, 'http://myhost.unx.com' , 50001); */
22 /* dlrc=dmsrvdeletelog (jobid, 'http://myhost.unx.com' , 50001); */
23 IF STATUS = 'RUNNING' THEN put ' ACTION: Tentative d''arrêt de la tâche ' jobid;
24 put ' ACTION: Tentative de suppression du journal pour la tâche ' jobid;
25RUN;
2 Code Block
PROC DMSRVADM / DATA _NULL_ Data
Explanation :
This example extends the first by adding selection logic. After generating the task report, the Data Step uses an 'if status = 'RUNNING'' condition to target only active tasks. This allows for more controlled cleanup, avoiding action on tasks that are already completed or pending.
Copied!
1DATA work.joblist;
2 LENGTH jobid $16. STATUS $10. description $30.;
3 INPUT jobid $ STATUS $ description $;
4 DATALINES;
5JOB001 RUNNING 'Analyse quotidienne'
6JOB002 COMPLETED 'Rapport mensuel'
7JOB003 FAILED 'Importation de données'
8JOB004 RUNNING 'Traitement de nuit'
9JOB005 PENDING 'Mise à jour'
10;
11RUN;
12 
13PROC DMSRVADM
14 out=work.jobReport
15 host='http://myhost.unx.com' port=50001;
16RUN;
17 
18DATA _null_;
19 SET work.jobReport;
20 IF STATUS = 'RUNNING' THEN DO;
21 put 'Arrêt et suppression des logs pour la tâche ' jobid ' (Status: ' STATUS ', Description: ' description ')';
22 /* Ici, dmsrvkilljob et dmsrvdeletelog seraient appelés pour les tâches 'RUNNING' */
23 /* kjrc=dmsrvkilljob (jobid, 'http://myhost.unx.com' , 50001); */
24 /* dlrc=dmsrvdeletelog (jobid, 'http://myhost.unx.com' , 50001); */
25 END;
26 ELSE DO;
27 put 'Ignoré la tâche ' jobid ' (Status: ' STATUS ')';
28 END;
29RUN;
3 Code Block
PROC DMSRVADM / DATA _NULL_ Data
Explanation :
This example introduces the use of macro variables (%let) to define the Data Management Server host and port. This makes the code more flexible and easier to maintain, as connection information can be changed in a single place. Cleanup is extended to 'RUNNING' and 'FAILED' tasks.
Copied!
1/* Définition des macro-variables pour l'hôte et le port */
2%let DMS_HOST = http://myhost.unx.com;
3%let DMS_PORT = 50001;
4 
5DATA work.joblist;
6 LENGTH jobid $16. STATUS $10. description $30.;
7 INPUT jobid $ STATUS $ description $;
8 DATALINES;
9JOB001 RUNNING 'Analyse quotidienne'
10JOB002 COMPLETED 'Rapport mensuel'
11JOB003 FAILED 'Importation de données'
12JOB004 RUNNING 'Traitement de nuit'
13JOB005 PENDING 'Mise à jour'
14;
15RUN;
16 
17PROC DMSRVADM
18 out=work.jobReport
19 host="&DMS_HOST."
20 port=&DMS_PORT.;
21RUN;
22 
23DATA _null_;
24 SET work.jobReport;
25 IF STATUS in ('RUNNING', 'FAILED') THEN DO;
26 put 'Traitement de la tâche ' jobid ' (Status: ' STATUS ') sur &DMS_HOST.:&DMS_PORT.';
27 /* Utilisation des macro-variables dans les fonctions simulées */
28 /* kjrc=dmsrvkilljob (jobid, "&DMS_HOST." , &DMS_PORT.); */
29 /* dlrc=dmsrvdeletelog (jobid, "&DMS_HOST." , &DMS_PORT.); */
30 END;
31RUN;
32 
33%mend;
4 Code Block
PROC CAS / DATA _NULL_ Data
Explanation :
This example proposes a scenario where one might want to clean logs not from the DataFlux Data Management Server, but from CAS sessions or services. Since DMSRVADM is not a CAS procedure, the example is conceptual and simulates the creation of CAS log data, then the hypothetical call of a CAS action ('logmanagement.cleanupLogs') that would be responsible for cleaning inactive logs. This demonstrates the approach and logic of resource management in a Viya/CAS environment even if the specific cleanup tools may vary.
Copied!
1/* Cet exemple est conceptuel et simule une approche de gestion des journaux */
2/* dans un environnement SAS Viya/CAS, bien que DMSrvAdmin soit spécifique à DataFlux. */
3/* Il illustre l'idée de nettoyer des ressources via des actions CAS si un service */
4/* de nettoyage des journaux CAS était disponible ou pouvait être orchestré. */
5 
6/* Connexion à une session CAS (si non déjà connectée) */
7/* options casopts=(cascertpath="/opt/sas/viya/config/etc/certs/trustedcerts.pem"); */
8/* cas casauto; */
9 
10/* Création d'une table simulée de journaux CAS */
11DATA casuser.caslogs;
12 LENGTH logname $50. logsize num STATUS $10.;
13 INPUT logname $ logsize STATUS $;
14 DATALINES;
15/cas/logs/session1.log 1024 ACTIVE
16/cas/logs/session2.log 2048 INACTIVE
17/cas/logs/old/session3.log 512 INACTIVE
18/cas/logs/corrupted.log 0 ERROR
19;
20RUN;
21 
22/* Utilisation de PROC CAS pour appeler une action simulant le nettoyage */
23/* Imaginez une action CAS 'logmanagement.cleanupLogs' */
24PROC CASUTIL;
25 load DATA=casuser.caslogs outcaslib="casuser" replace;
26RUN;
27 
28PROC CAS;
29 /* Simulation d'une action CAS pour nettoyer les journaux inactifs */
30 /* work.logmanagement.cleanupLogs / details=casuser.caslogs filter='status="INACTIVE"' */
31 /* output table=casuser.cleanedlogs; */
32 
33 PRINT 'Simulating CAS log cleanup for INACTIVE logs from casuser.caslogs...';
34 ACTION TABLE.fetch / TABLE={name='caslogs', caslib='casuser'} sortBy={'logname'};
35 RUN;
36 
37DATA _null_;
38 SET casuser.caslogs;
39 IF STATUS = 'INACTIVE' THEN
40 put 'ACTION CAS (simulé): Suppression du journal inactif ' logname;
41RUN;
42 
43/* Terminer la session CAS si elle a été démarrée ici */
44/* cas term; */
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 © SAS Institute Inc. All Rights Reserved