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