1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
32 //#include "MEDMEM_STRING.hxx"
33 #include "Batch_Parametre.hxx"
34 #include "Batch_Environnement.hxx"
35 #include "Batch_RunTimeException.hxx"
36 #include "Batch_JobInfo_PBS.hxx"
42 JobInfo_PBS::JobInfo_PBS(struct batch_status * list, bool tobedeleted) : JobInfo()
44 // On ne considere que le premier element de la liste
45 // Si tout est OK, la liste ne devrait contenir qu'un element
46 // Sinon on leve une exception.
47 struct batch_status * p_job = list;
49 for(i=0; p_job; p_job = p_job->next) i++;
50 if (i == 0) throw RunTimeException("Liste vide (le job est absent de la file)");
54 sst << "JobInfo_PBS::JobInfo_PBS(struct batch_status * list, bool tobedeleted) : la liste contient "
55 << i << " elements" << " (1 seul requis)" << endl;
56 throw RunTimeException(sst.str());
60 // On remplit les membres _param et _env
62 if (p_job->name && strlen(p_job->name)) _param[ID] = p_job->name;
63 if (p_job->text && strlen(p_job->text)) _param[TEXT] = p_job->text;
65 for(struct attrl * p_attr = p_job->attribs; p_attr; p_attr = p_attr->next) {
67 string name, res, value;
68 if (p_attr->name && strlen(p_attr->name)) name = p_attr->name;
69 if (p_attr->resource && strlen(p_attr->resource)) res = p_attr->resource;
70 if (p_attr->value && strlen(p_attr->value)) value = p_attr->value;
75 } else if (name == ATTR_owner) {
78 } else if (name == ATTR_state) {
79 _param[STATE] = value;
81 } else if (name == ATTR_queue) {
82 _param[QUEUE] = value;
84 } else if (name == ATTR_A) {
85 _param[ACCOUNT] = value;
87 } else if (name == ATTR_M) {
90 } else if (name == ATTR_c) {
91 if (!strcmp(value.c_str(), CHECKPOINT_UNSPECIFIED)) _param[CHECKPOINT] = 1L;
92 else _param[CHECKPOINT] = 0L;
94 } else if (name == ATTR_h) {
95 if (!strcmp(value.c_str(), NO_HOLD)) _param[HOLD] = 0L;
96 else _param[HOLD] = 1L;
98 } else if (name == ATTR_ctime) {
99 _param[CREATIONTIME] = atol(value.c_str());
101 } else if (name == ATTR_etime) {
102 _param[ELIGIBLETIME] = atol(value.c_str());
104 } else if (name == ATTR_mtime) {
105 _param[MODIFICATIONTIME] = atol(value.c_str());
107 } else if (name == ATTR_qtime) {
108 _param[QUEUEDTIME] = atol(value.c_str());
110 } else if (name == ATTR_exechost) {
111 _param[EXECUTIONHOST] = value;
113 } else if (name == ATTR_session) {
114 _param[PID] = atol(value.c_str());
116 } else if (name == ATTR_euser) {
117 _param[EUSER] = value;
119 } else if (name == ATTR_egroup) {
120 _param[EGROUP] = value;
122 } else if (name == ATTR_l) {
124 _param[MAXCPUTIME] = HMStoLong(value);
126 } else if (res == "walltime") {
127 _param[MAXWALLTIME] = HMStoLong(value);
131 } else if (name == ATTR_used) {
133 _param[USEDCPUTIME] = HMStoLong(value);
135 } else if (res == "walltime") {
136 _param[USEDWALLTIME] = HMStoLong(value);
140 } else if (name == ATTR_v) {
146 pos = value.find(",", deb);
147 string sub = value.substr(deb, pos-deb);
149 if (pos < 0) ok = false;
151 int eq = sub.find("=");
152 _env[sub.substr(0, eq)] = sub.substr(eq+1);
159 if (tobedeleted) pbs_statfree(list);
163 JobInfo_PBS::~JobInfo_PBS()
168 // Convertit une date HH:MM:SS en secondes
169 long JobInfo_PBS::HMStoLong(const string & s)
173 sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec);
174 return ( ( ( hour * 60L ) + min ) * 60L ) + sec;
177 // Methode pour l'interfacage avec Python (SWIG) : affichage en Python
178 string JobInfo_PBS::__str__() const
180 //MEDMEM::STRING sst;
182 sst << "<JobInfo_PBS (" << this << ") :" << endl;
183 sst << " ID = " <<_param[ID] << endl;
185 sst << " + Parametre :" << endl;
186 Parametre::const_iterator itp;
187 for(itp=_param.begin(); itp!=_param.end(); itp++) {
188 if ( (*itp).first != ID ) {
189 sst << " * " << (*itp).first << " = " << (*itp).second << endl;