]> SALOME platform Git repositories - modules/yacs.git/blob - src/Batch/Batch_JobInfo_LSF.cxx
Salome HOME
merge from branch BR_V5_DEV
[modules/yacs.git] / src / Batch / Batch_JobInfo_LSF.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * JobInfo_LSF.cxx : 
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Mail   : mailto:ivan.dutka-malen@der.edf.fr
27  * Date   : Fri Nov 21 09:42:06 2003
28  * Projet : Salome 2
29  *
30  */
31
32 #include <cstdio>
33 #include <sstream>
34 #include <string>
35 #include "Batch_Parametre.hxx"
36 #include "Batch_Environnement.hxx"
37 #include "Batch_RunTimeException.hxx"
38 #include "Batch_APIInternalFailureException.hxx"
39 #include "Batch_JobInfo_LSF.hxx"
40
41 using namespace std;
42
43 namespace Batch {
44
45
46
47   // Constructeurs
48   JobInfo_LSF::JobInfo_LSF(int id) : JobInfo()
49   {
50     struct loadIndexLog * p_ld        = new struct loadIndexLog;
51     struct jobInfoHead  * p_jInfoHead = lsb_openjobinfo_a(id, NULL, NULL, NULL, NULL, ALL_JOB);
52
53     int more = p_jInfoHead->numJobs;
54     if (more != 1) {
55       char * msg = lsb_sysmsg();
56       if (!msg) msg = "unknown";
57       throw APIInternalFailureException(string("LSF lsb_openjobinfo error. Reason : ") + msg);     
58     }
59
60     // on remplit une structure contenant <more> elements
61     struct jobInfoEnt & jobInfo = * lsb_readjobinfo(&more);
62
63
64     // On remplit les membres _param et _env
65     _param[ACCOUNT]          = jobInfo.submit.projectName;
66     _param[CHECKPOINT]       = jobInfo.submit.chkpntPeriod != 0;
67     _param[CKPTINTERVAL]     = jobInfo.submit.chkpntPeriod;
68     _param[CREATIONTIME]     = jobInfo.submitTime;
69     // _param[EGROUP]           = jobInfo.;
70     _param[ELIGIBLETIME]     = jobInfo.reserveTime;
71     _param[ENDTIME]          = jobInfo.endTime;
72     _param[EUSER]            = jobInfo.execUsername;
73     _param[EXECUTABLE]       = jobInfo.submit.command;
74     _param[EXITCODE]         = jobInfo.exitStatus;
75     _param[HOLD]             = jobInfo.status & (JOB_STAT_PSUSP | JOB_STAT_SSUSP | JOB_STAT_USUSP);
76     _param[MAIL]             = jobInfo.submit.mailUser;
77     _param[MAXCPUTIME]       = jobInfo.submit.rLimits[LSF_RLIMIT_CPU];
78     _param[MAXDISKSIZE]      = jobInfo.submit.rLimits[LSF_RLIMIT_FSIZE];
79     _param[MAXRAMSIZE]       = jobInfo.submit.rLimits[LSF_RLIMIT_SWAP];
80     _param[MAXWALLTIME]      = jobInfo.submit.rLimits[LSF_RLIMIT_RUN];
81     _param[MODIFICATIONTIME] = jobInfo.lastEvent;
82     _param[NAME]             = jobInfo.jName;
83     _param[NBPROC]           = jobInfo.submit.numProcessors;
84     _param[PID]              = jobInfo.jobPid;
85     _param[QUEUE]            = jobInfo.submit.queue;
86     _param[QUEUEDTIME]       = jobInfo.submitTime;
87     // _param[SERVER]           = jobInfo.;
88     _param[STARTTIME]        = jobInfo.startTime;
89     _param[TEXT]             = jobInfo.numReasons ? lsb_pendreason(jobInfo.numReasons,
90                                                                    jobInfo.reasonTb, 
91                                                                    p_jInfoHead,
92                                                                    p_ld,0) : "";
93     // _param[TMPDIR]           = jobInfo.;
94     _param[USEDCPUTIME]      = static_cast<long>(jobInfo.cpuTime);
95     // _param[USEDDISKSIZE]     = jobInfo.;
96     _param[USEDRAMSIZE]      = jobInfo.runRusage.mem;
97     _param[USEDWALLTIME]     = jobInfo.duration * 60L;
98     _param[USER]             = jobInfo.user;
99
100
101     ostringstream oss;
102     int jobid = jobInfo.jobId;
103     oss << jobid;
104     _param[ID] = oss.str();
105
106
107     string hosts, sep;
108     for(int i=0; i < jobInfo.numExHosts; i++, sep="+") {
109       hosts += jobInfo.exHosts[i];
110       hosts += sep;
111     }
112     _param[EXECUTIONHOST]    = hosts;
113
114     ostringstream status;
115
116     if (IS_PEND(jobInfo.status))
117       status << " Job is pending;";
118     if (IS_START(jobInfo.status))
119       status << " Job is started;";
120     if (IS_FINISH(jobInfo.status))
121       status << " Job is finished;";
122     if (IS_SUSP(jobInfo.status))
123       status << " Job is suspended;";
124     if (IS_POST_DONE(jobInfo.status))
125       status << " Job is post-done;";
126     if (IS_POST_ERR(jobInfo.status))
127       status << " Job is post-error;";
128
129     _param[STATE] = status.str();
130     _running = IS_FINISH(jobInfo.status) ? false : true;
131
132
133     if (strlen(jobInfo.submit.inFile))
134       _param[INFILE]  += Couple(jobInfo.submit.inFile, "stdin");
135     if (strlen(jobInfo.submit.outFile))
136       _param[OUTFILE]  += Couple(jobInfo.submit.outFile, "stdout");
137     if (strlen(jobInfo.submit.errFile))
138       _param[OUTFILE]  += Couple(jobInfo.submit.errFile, "stderr");
139
140     for(int i=0; i < jobInfo.submit.nxf; i++) {
141       switch (jobInfo.submit.xf[i].options) {
142       case XF_OP_SUB2EXEC:
143         _param[INFILE]  += Couple(jobInfo.submit.xf[i].subFn, jobInfo.submit.xf[i].execFn);
144         break;
145
146       case XF_OP_EXEC2SUB:
147         _param[OUTFILE] += Couple(jobInfo.submit.xf[i].subFn, jobInfo.submit.xf[i].execFn);
148         break;
149
150       default:
151         break;
152       }
153     }
154
155
156     lsb_closejobinfo();
157     delete p_ld;
158   }
159
160
161
162     // Teste si un job est present en machine
163   bool JobInfo_LSF::isRunning() const
164   {
165     return _running;
166   }
167
168
169   // Destructeur
170   JobInfo_LSF::~JobInfo_LSF()
171   {
172     // Nothing to do
173   }
174
175
176   
177   // Convertit une date HH:MM:SS en secondes
178   long JobInfo_LSF::HMStoLong(const string & s)
179   {
180     long hour, min, sec;
181
182     sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec);
183     return ( ( ( hour * 60L ) + min ) * 60L ) + sec;
184   }
185
186   // Methode pour l'interfacage avec Python (SWIG) : affichage en Python
187   string JobInfo_LSF::__str__() const
188   {
189     ostringstream sst;
190     sst << "<JobInfo_LSF (" << this << ") :" << endl;
191     sst << " ID = " <<_param[ID] << endl;
192
193     sst << "  + Parametre :" << endl;
194     Parametre::const_iterator itp;
195     for(itp=_param.begin(); itp!=_param.end(); itp++) {
196       if ( (*itp).first != ID ) {
197         sst << "    * " << (*itp).first << " = " << (*itp).second << endl;
198       }
199     }
200     return sst.str();
201   }
202
203
204 }