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>
38 #include "Batch_BatchManager_LSF.hxx"
44 BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
46 // On se connecte au serveur LSF
47 _connect = lsb_init("Salome2 Batch library");
48 if (_connect < 0) { // si erreur
49 char * errmsg = lsb_sysmsg();
50 string msg = "LSF Server on host \"";
53 msg += errmsg ? errmsg : "Reason unknown";
54 throw ConnexionFailureException(msg.c_str());
59 BatchManager_LSF::~BatchManager_LSF()
64 // Methode pour le controle des jobs : soumet un job au gestionnaire
65 const JobId BatchManager_LSF::submitJob(const Job & job)
68 struct submitReply reply;
69 int ref = lsb_submit(joblsf.getSubmitStruct(),
71 if (ref < 0) { // si erreur
72 char * msg = lsb_sysmsg();
73 if (!msg) msg = "unknown";
74 throw APIInternalFailureException(string("LSF submit error. Reason : ") + msg);
79 JobId id(this, oss.str());
83 // Methode pour le controle des jobs : retire un job du gestionnaire
84 void BatchManager_LSF::deleteJob(const JobId & jobid)
87 istringstream iss(jobid.getReference());
89 int rc = lsb_deletejob(ref, 0, 0);
90 if (rc < 0) { // si erreur
91 char * msg = lsb_sysmsg();
92 if (!msg) msg = "unknown";
93 throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg);
97 // Methode pour le controle des jobs : suspend un job en file d'attente
98 void BatchManager_LSF::holdJob(const JobId & jobid)
101 istringstream iss(jobid.getReference());
103 int rc = lsb_signaljob(ref, SIGSTOP);
104 if (rc < 0) { // si erreur
105 char * msg = lsb_sysmsg();
106 if (!msg) msg = "unknown";
107 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
111 // Methode pour le controle des jobs : relache un job suspendu
112 void BatchManager_LSF::releaseJob(const JobId & jobid)
115 istringstream iss(jobid.getReference());
117 int rc = lsb_signaljob(ref, SIGCONT);
118 if (rc < 0) { // si erreur
119 char * msg = lsb_sysmsg();
120 if (!msg) msg = "unknown";
121 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
126 // Methode pour le controle des jobs : modifie un job en file d'attente
127 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
130 istringstream iss(jobid.getReference());
133 Job_LSF joblsf = Job(param, env);
134 struct submitReply reply;
135 ref = lsb_modify(joblsf.getSubmitStruct(),
138 if (ref < 0) { // si erreur
139 ostringstream msg_sst;
140 char * msg = lsb_sysmsg();
141 if (!msg) msg = "unknown";
142 msg_sst << msg << endl;
143 // msg_sst << "BadJobId = " << (long) reply.badJobId << endl
144 // << "BadJobName = " << reply.badJobName << endl
145 // << "BadReqIndx = " << reply.badReqIndx << endl;
146 throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str());
150 // Methode pour le controle des jobs : modifie un job en file d'attente
151 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param)
153 alterJob(jobid, param, Environnement());
156 // Methode pour le controle des jobs : modifie un job en file d'attente
157 void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env)
159 alterJob(jobid, Parametre(), env);
164 // Methode pour le controle des jobs : renvoie l'etat du job
165 JobInfo BatchManager_LSF::queryJob(const JobId & jobid)
168 istringstream iss(jobid.getReference());
171 JobInfo_LSF ji = JobInfo_LSF(id);
178 // Methode pour le controle des jobs : teste si un job est present en machine
179 bool BatchManager_LSF::isRunning(const JobId & jobid)
182 istringstream iss(jobid.getReference());
185 JobInfo_LSF ji = JobInfo_LSF(id);
187 return ji.isRunning();