1 // Copyright (C) 2007-2012 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 // Ce manager permet de faire de la reprise
87 BatchManager_LSF::addJob(const Batch::Job & job, const std::string reference)
89 return JobId(this, reference);
92 // Methode pour le controle des jobs : retire un job du gestionnaire
93 void BatchManager_LSF::deleteJob(const JobId & jobid)
96 istringstream iss(jobid.getReference());
98 int rc = lsb_deletejob(ref, 0, 0);
99 if (rc < 0) { // si erreur
100 char * msg = lsb_sysmsg();
101 if (!msg) msg = "unknown";
102 throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg);
106 // Methode pour le controle des jobs : suspend un job en file d'attente
107 void BatchManager_LSF::holdJob(const JobId & jobid)
110 istringstream iss(jobid.getReference());
112 int rc = lsb_signaljob(ref, SIGSTOP);
113 if (rc < 0) { // si erreur
114 char * msg = lsb_sysmsg();
115 if (!msg) msg = "unknown";
116 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
120 // Methode pour le controle des jobs : relache un job suspendu
121 void BatchManager_LSF::releaseJob(const JobId & jobid)
124 istringstream iss(jobid.getReference());
126 int rc = lsb_signaljob(ref, SIGCONT);
127 if (rc < 0) { // si erreur
128 char * msg = lsb_sysmsg();
129 if (!msg) msg = "unknown";
130 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
135 // Methode pour le controle des jobs : modifie un job en file d'attente
136 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
139 istringstream iss(jobid.getReference());
142 Job_LSF joblsf = Job(param, env);
143 struct submitReply reply;
144 ref = lsb_modify(joblsf.getSubmitStruct(),
147 if (ref < 0) { // si erreur
148 ostringstream msg_sst;
149 char * msg = lsb_sysmsg();
150 if (!msg) msg = "unknown";
151 msg_sst << msg << endl;
152 // msg_sst << "BadJobId = " << (long) reply.badJobId << endl
153 // << "BadJobName = " << reply.badJobName << endl
154 // << "BadReqIndx = " << reply.badReqIndx << endl;
155 throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str());
159 // Methode pour le controle des jobs : modifie un job en file d'attente
160 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param)
162 alterJob(jobid, param, Environnement());
165 // Methode pour le controle des jobs : modifie un job en file d'attente
166 void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env)
168 alterJob(jobid, Parametre(), env);
173 // Methode pour le controle des jobs : renvoie l'etat du job
174 JobInfo BatchManager_LSF::queryJob(const JobId & jobid)
177 istringstream iss(jobid.getReference());
180 JobInfo_LSF ji = JobInfo_LSF(id);
187 // Methode pour le controle des jobs : teste si un job est present en machine
188 bool BatchManager_LSF::isRunning(const JobId & jobid)
191 istringstream iss(jobid.getReference());
194 JobInfo_LSF ji = JobInfo_LSF(id);
196 return ji.isRunning();