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/
21 * BatchManager_PBS.cxx :
23 * Auteur : Ivan DUTKA-MALEN - EDF R&D
24 * Mail : mailto:ivan.dutka-malen@der.edf.fr
25 * Date : Thu Nov 6 10:17:22 2003
31 #include <pbs_error.h>
37 //#include "MEDMEM_STRING.hxx"
38 #include "Batch_BatchManager_PBS.hxx"
43 // Recupere le nom du serveur par defaut
44 // string BatchManager_PBS::getDefaultServer() {
45 // string server_name = "localhost";
47 // const char * server_name_path = "@openpbsspooldir@/server_name";
48 // ifstream server_name_file(server_name_path);
49 // if (server_name_file) {
50 // server_name_file >> server_name;
51 // server_name_file.close();
54 // return server_name;
58 // BatchManager_PBS::BatchManager_PBS() throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(BatchManager_PBS::getDefaultServer())
60 // // On se connecte au serveur PBS
61 // _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
62 // if (_connect < 0) { // si erreur
63 // char * errmsg = pbs_geterrmsg(_connect);
64 // string msg = "PBS Server on host \"";
67 // msg += errmsg ? errmsg : "Reason unknown";
68 // throw ConnexionFailureException(msg.c_str());
73 // BatchManager_PBS::BatchManager_PBS(string host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(host)
75 // // On se connecte au serveur PBS
76 // _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
77 // if (_connect < 0) { // si erreur
78 // char * errmsg = pbs_geterrmsg(_connect);
79 // string msg = "PBS Server on host \"";
82 // msg += errmsg ? errmsg : "Reason unknown";
83 // throw ConnexionFailureException(msg.c_str());
86 BatchManager_PBS::BatchManager_PBS(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
88 // On se connecte au serveur PBS
89 _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
90 if (_connect < 0) { // si erreur
91 char * errmsg = pbs_geterrmsg(_connect);
92 string msg = "PBS Server on host \"";
95 msg += errmsg ? errmsg : "Reason unknown";
96 throw ConnexionFailureException(msg.c_str());
101 BatchManager_PBS::~BatchManager_PBS()
103 // On se deconnecte du serveur PBS
104 int rc = pbs_disconnect(_connect);
105 if (rc < 0) { // si erreur
106 string msg = "PBS Server on host \"";
109 msg += pbs_geterrmsg(_connect);
110 throw ConnexionFailureException(msg.c_str());
114 // Methode pour le controle des jobs : soumet un job au gestionnaire
115 const JobId BatchManager_PBS::submitJob(const Job & job)
117 Job_PBS jobpbs = job;
118 char * ref = pbs_submit(_connect,
119 jobpbs.getAttributesOP(),
121 jobpbs.getDestination(),
123 if (!ref) { // si erreur
124 char * msg = pbs_geterrmsg(_connect);
125 if (!msg) msg = "unknown";
126 throw APIInternalFailureException(string("PBS submit error. Reason : ") + msg);
129 JobId id(this, string(ref));
134 // Methode pour le controle des jobs : retire un job du gestionnaire
135 void BatchManager_PBS::deleteJob(const JobId & jobid)
137 char * ref = const_cast< char * >(jobid.getReference().c_str());
138 int rc = pbs_deljob(_connect, ref, 0);
139 if (rc) { // si erreur
140 char * msg = pbs_geterrmsg(_connect);
141 if (!msg) msg = "unknown";
142 throw APIInternalFailureException(string("PBS deljob error. Reason : ") + msg);
146 // Methode pour le controle des jobs : suspend un job en file d'attente
147 void BatchManager_PBS::holdJob(const JobId & jobid)
149 char * ref = const_cast< char * >(jobid.getReference().c_str());
150 int rc = pbs_holdjob(_connect, ref, USER_HOLD, 0);
151 if (rc) { // si erreur
152 char * msg = pbs_geterrmsg(_connect);
153 if (!msg) msg = "unknown";
154 throw APIInternalFailureException(string("PBS holdjob error. Reason : ") + msg);
158 // Methode pour le controle des jobs : relache un job suspendu
159 void BatchManager_PBS::releaseJob(const JobId & jobid)
161 char * ref = const_cast< char * >(jobid.getReference().c_str());
162 int rc = pbs_rlsjob(_connect, ref, USER_HOLD, 0);
163 if (rc) { // si erreur
164 char * msg = pbs_geterrmsg(_connect);
165 if (!msg) msg = "unknown";
166 throw APIInternalFailureException(string("PBS rlsjob error. Reason : ") + msg);
171 // Methode pour le controle des jobs : modifie un job en file d'attente
172 void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
177 char * ref = const_cast< char * >(jobid.getReference().c_str());
178 int rc = pbs_alterjob(_connect,
180 jobpbs.getAttributes(),
182 if (rc) { // si erreur
183 char * msg = pbs_geterrmsg(_connect);
184 if (!msg) msg = "unknown";
185 throw APIInternalFailureException(string("PBS alterjob error. Reason : ") + msg);
190 // Methode pour le controle des jobs : modifie un job en file d'attente
191 void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param)
193 alterJob(jobid, param, Environnement());
196 // Methode pour le controle des jobs : modifie un job en file d'attente
197 void BatchManager_PBS::alterJob(const JobId & jobid, const Environnement & env)
199 alterJob(jobid, Parametre(), env);
204 // Methode pour le controle des jobs : renvoie l'etat du job
205 JobInfo BatchManager_PBS::queryJob(const JobId & jobid)
207 char * id = const_cast< char * >(jobid.getReference().c_str());
208 JobInfo_PBS ji = JobInfo_PBS(pbs_statjob(_connect, id, 0, 0), true);