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_LSF.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
34 #include <lsf/lsbatch.h>
40 #include "Batch_BatchManager_LSF.hxx"
46 BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
48 // On se connecte au serveur LSF
49 _connect = lsb_init("Salome2 Batch library");
50 if (_connect < 0) { // si erreur
51 char * errmsg = lsb_sysmsg();
52 string msg = "LSF Server on host \"";
55 msg += errmsg ? errmsg : "Reason unknown";
56 throw ConnexionFailureException(msg.c_str());
61 BatchManager_LSF::~BatchManager_LSF()
66 // Methode pour le controle des jobs : soumet un job au gestionnaire
67 const JobId BatchManager_LSF::submitJob(const Job & job)
70 struct submitReply reply;
71 int ref = lsb_submit(joblsf.getSubmitStruct(),
73 if (ref < 0) { // si erreur
74 char * msg = lsb_sysmsg();
75 if (!msg) msg = "unknown";
76 throw APIInternalFailureException(string("LSF submit error. Reason : ") + msg);
81 JobId id(this, oss.str());
85 // Methode pour le controle des jobs : retire un job du gestionnaire
86 void BatchManager_LSF::deleteJob(const JobId & jobid)
89 istringstream iss(jobid.getReference());
91 int rc = lsb_deletejob(ref, 0, 0);
92 if (rc < 0) { // si erreur
93 char * msg = lsb_sysmsg();
94 if (!msg) msg = "unknown";
95 throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg);
99 // Methode pour le controle des jobs : suspend un job en file d'attente
100 void BatchManager_LSF::holdJob(const JobId & jobid)
103 istringstream iss(jobid.getReference());
105 int rc = lsb_signaljob(ref, SIGSTOP);
106 if (rc < 0) { // si erreur
107 char * msg = lsb_sysmsg();
108 if (!msg) msg = "unknown";
109 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
113 // Methode pour le controle des jobs : relache un job suspendu
114 void BatchManager_LSF::releaseJob(const JobId & jobid)
117 istringstream iss(jobid.getReference());
119 int rc = lsb_signaljob(ref, SIGCONT);
120 if (rc < 0) { // si erreur
121 char * msg = lsb_sysmsg();
122 if (!msg) msg = "unknown";
123 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
128 // Methode pour le controle des jobs : modifie un job en file d'attente
129 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
132 istringstream iss(jobid.getReference());
135 Job_LSF joblsf = Job(param, env);
136 struct submitReply reply;
137 ref = lsb_modify(joblsf.getSubmitStruct(),
140 if (ref < 0) { // si erreur
141 ostringstream msg_sst;
142 char * msg = lsb_sysmsg();
143 if (!msg) msg = "unknown";
144 msg_sst << msg << endl;
145 // msg_sst << "BadJobId = " << (long) reply.badJobId << endl
146 // << "BadJobName = " << reply.badJobName << endl
147 // << "BadReqIndx = " << reply.badReqIndx << endl;
148 throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str());
152 // Methode pour le controle des jobs : modifie un job en file d'attente
153 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param)
155 alterJob(jobid, param, Environnement());
158 // Methode pour le controle des jobs : modifie un job en file d'attente
159 void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env)
161 alterJob(jobid, Parametre(), env);
166 // Methode pour le controle des jobs : renvoie l'etat du job
167 JobInfo BatchManager_LSF::queryJob(const JobId & jobid)
170 istringstream iss(jobid.getReference());
173 JobInfo_LSF ji = JobInfo_LSF(id);
180 // Methode pour le controle des jobs : teste si un job est present en machine
181 bool BatchManager_LSF::isRunning(const JobId & jobid)
184 istringstream iss(jobid.getReference());
187 JobInfo_LSF ji = JobInfo_LSF(id);
189 return ji.isRunning();