1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * BatchManager_PBS.cxx :
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Mail : mailto:ivan.dutka-malen@der.edf.fr
27 * Date : Thu Nov 6 10:17:22 2003
33 #include <pbs_error.h>
39 //#include "MEDMEM_STRING.hxx"
40 #include "Batch_BatchManager_PBS.hxx"
45 // Recupere le nom du serveur par defaut
46 // string BatchManager_PBS::getDefaultServer() {
47 // string server_name = "localhost";
49 // const char * server_name_path = "@openpbsspooldir@/server_name";
50 // ifstream server_name_file(server_name_path);
51 // if (server_name_file) {
52 // server_name_file >> server_name;
53 // server_name_file.close();
56 // return server_name;
60 // BatchManager_PBS::BatchManager_PBS() throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(BatchManager_PBS::getDefaultServer())
62 // // On se connecte au serveur PBS
63 // _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
64 // if (_connect < 0) { // si erreur
65 // char * errmsg = pbs_geterrmsg(_connect);
66 // string msg = "PBS Server on host \"";
69 // msg += errmsg ? errmsg : "Reason unknown";
70 // throw ConnexionFailureException(msg.c_str());
75 // BatchManager_PBS::BatchManager_PBS(string host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(host)
77 // // On se connecte au serveur PBS
78 // _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
79 // if (_connect < 0) { // si erreur
80 // char * errmsg = pbs_geterrmsg(_connect);
81 // string msg = "PBS Server on host \"";
84 // msg += errmsg ? errmsg : "Reason unknown";
85 // throw ConnexionFailureException(msg.c_str());
88 BatchManager_PBS::BatchManager_PBS(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
90 // On se connecte au serveur PBS
91 _connect = pbs_connect(const_cast< char * >(_hostname.c_str()));
92 if (_connect < 0) { // si erreur
93 throw ConnexionFailureException(getErrorMessage("connect").c_str());
98 BatchManager_PBS::~BatchManager_PBS()
100 // On se deconnecte du serveur PBS
101 int rc = pbs_disconnect(_connect);
102 if (rc < 0) { // si erreur
103 throw ConnexionFailureException(getErrorMessage("disconnect").c_str());
107 string BatchManager_PBS::getErrorMessage(const char * operation) const
109 char * msg = pbs_geterrmsg(_connect);
111 sstr << "PBS " << operation << " error (host \"" << _hostname << "\"): ";
115 sstr << "code = " << pbs_errno << " (" << pbse_to_txt(pbs_errno) << ")";
120 // Methode pour le controle des jobs : soumet un job au gestionnaire
121 const JobId BatchManager_PBS::submitJob(const Job & job)
123 Job_PBS jobpbs = job;
124 char * ref = pbs_submit(_connect,
125 jobpbs.getAttributesOP(),
127 jobpbs.getDestination(),
129 if (!ref) { // si erreur
130 throw APIInternalFailureException(getErrorMessage("submit").c_str());
133 JobId id(this, string(ref));
138 // Methode pour le controle des jobs : retire un job du gestionnaire
139 void BatchManager_PBS::deleteJob(const JobId & jobid)
141 char * ref = const_cast< char * >(jobid.getReference().c_str());
142 int rc = pbs_deljob(_connect, ref, 0);
143 if (rc) { // si erreur
144 throw APIInternalFailureException(getErrorMessage("deljob").c_str());
148 // Methode pour le controle des jobs : suspend un job en file d'attente
149 void BatchManager_PBS::holdJob(const JobId & jobid)
151 char * ref = const_cast< char * >(jobid.getReference().c_str());
152 int rc = pbs_holdjob(_connect, ref, USER_HOLD, 0);
153 if (rc) { // si erreur
154 throw APIInternalFailureException(getErrorMessage("holdjob").c_str());
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 throw APIInternalFailureException(getErrorMessage("rlsjob").c_str());
169 // Methode pour le controle des jobs : modifie un job en file d'attente
170 void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
175 char * ref = const_cast< char * >(jobid.getReference().c_str());
176 int rc = pbs_alterjob(_connect,
178 jobpbs.getAttributes(),
180 if (rc) { // si erreur
181 throw APIInternalFailureException(getErrorMessage("alterjob").c_str());
186 // Methode pour le controle des jobs : modifie un job en file d'attente
187 void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param)
189 alterJob(jobid, param, Environnement());
192 // Methode pour le controle des jobs : modifie un job en file d'attente
193 void BatchManager_PBS::alterJob(const JobId & jobid, const Environnement & env)
195 alterJob(jobid, Parametre(), env);
200 // Methode pour le controle des jobs : renvoie l'etat du job
201 JobInfo BatchManager_PBS::queryJob(const JobId & jobid)
203 char * id = const_cast< char * >(jobid.getReference().c_str());
204 JobInfo_PBS ji = JobInfo_PBS(pbs_statjob(_connect, id, 0, 0), true);