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
21 * BatchManager_LSF.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
32 #include <lsf/lsbatch.h>
37 #include "Batch_BatchManager_LSF.hxx"
41 BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
43 // On se connecte au serveur LSF
44 _connect = lsb_init("Salome2 Batch library");
45 if (_connect < 0) { // si erreur
46 char * errmsg = lsb_sysmsg();
47 string msg = "LSF Server on host \"";
50 msg += errmsg ? errmsg : "Reason unknown";
51 throw ConnexionFailureException(msg.c_str());
56 BatchManager_LSF::~BatchManager_LSF()
61 // Methode pour le controle des jobs : soumet un job au gestionnaire
62 const JobId BatchManager_LSF::submitJob(const Job & job)
65 struct submitReply reply;
66 int ref = lsb_submit(joblsf.getSubmitStruct(),
68 if (ref < 0) { // si erreur
69 char * msg = lsb_sysmsg();
70 if (!msg) msg = "unknown";
71 throw APIInternalFailureException(string("LSF submit error. Reason : ") + msg);
76 JobId id(this, oss.str());
80 // Methode pour le controle des jobs : retire un job du gestionnaire
81 void BatchManager_LSF::deleteJob(const JobId & jobid)
84 istringstream iss(jobid.getReference());
86 int rc = lsb_deletejob(ref, 0, 0);
87 if (rc < 0) { // si erreur
88 char * msg = lsb_sysmsg();
89 if (!msg) msg = "unknown";
90 throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg);
94 // Methode pour le controle des jobs : suspend un job en file d'attente
95 void BatchManager_LSF::holdJob(const JobId & jobid)
98 istringstream iss(jobid.getReference());
100 int rc = lsb_signaljob(ref, SIGSTOP);
101 if (rc < 0) { // si erreur
102 char * msg = lsb_sysmsg();
103 if (!msg) msg = "unknown";
104 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
108 // Methode pour le controle des jobs : relache un job suspendu
109 void BatchManager_LSF::releaseJob(const JobId & jobid)
112 istringstream iss(jobid.getReference());
114 int rc = lsb_signaljob(ref, SIGCONT);
115 if (rc < 0) { // si erreur
116 char * msg = lsb_sysmsg();
117 if (!msg) msg = "unknown";
118 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
123 // Methode pour le controle des jobs : modifie un job en file d'attente
124 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
127 istringstream iss(jobid.getReference());
130 Job_LSF joblsf = Job(param, env);
131 struct submitReply reply;
132 ref = lsb_modify(joblsf.getSubmitStruct(),
135 if (ref < 0) { // si erreur
136 ostringstream msg_sst;
137 char * msg = lsb_sysmsg();
138 if (!msg) msg = "unknown";
139 msg_sst << msg << endl;
140 // msg_sst << "BadJobId = " << (long) reply.badJobId << endl
141 // << "BadJobName = " << reply.badJobName << endl
142 // << "BadReqIndx = " << reply.badReqIndx << endl;
143 throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str());
147 // Methode pour le controle des jobs : modifie un job en file d'attente
148 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param)
150 alterJob(jobid, param, Environnement());
153 // Methode pour le controle des jobs : modifie un job en file d'attente
154 void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env)
156 alterJob(jobid, Parametre(), env);
161 // Methode pour le controle des jobs : renvoie l'etat du job
162 JobInfo BatchManager_LSF::queryJob(const JobId & jobid)
165 istringstream iss(jobid.getReference());
168 JobInfo_LSF ji = JobInfo_LSF(id);
175 // Methode pour le controle des jobs : teste si un job est present en machine
176 bool BatchManager_LSF::isRunning(const JobId & jobid)
179 istringstream iss(jobid.getReference());
182 JobInfo_LSF ji = JobInfo_LSF(id);
184 return ji.isRunning();