2 * BatchManager_LSF.cxx :
4 * Auteur : Ivan DUTKA-MALEN - EDF R&D
5 * Mail : mailto:ivan.dutka-malen@der.edf.fr
6 * Date : Thu Nov 6 10:17:22 2003
13 #include <lsf/lsbatch.h>
18 #include "Batch_BatchManager_LSF.hxx"
22 BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host)
24 // On se connecte au serveur LSF
25 _connect = lsb_init("Salome2 Batch library");
26 if (_connect < 0) { // si erreur
27 char * errmsg = lsb_sysmsg();
28 string msg = "LSF Server on host \"";
31 msg += errmsg ? errmsg : "Reason unknown";
32 throw ConnexionFailureException(msg.c_str());
37 BatchManager_LSF::~BatchManager_LSF()
42 // Methode pour le controle des jobs : soumet un job au gestionnaire
43 const JobId BatchManager_LSF::submitJob(const Job & job)
46 struct submitReply reply;
47 int ref = lsb_submit(joblsf.getSubmitStruct(),
49 if (ref < 0) { // si erreur
50 char * msg = lsb_sysmsg();
51 if (!msg) msg = "unknown";
52 throw APIInternalFailureException(string("LSF submit error. Reason : ") + msg);
57 JobId id(this, oss.str());
61 // Methode pour le controle des jobs : retire un job du gestionnaire
62 void BatchManager_LSF::deleteJob(const JobId & jobid)
65 istringstream iss(jobid.getReference());
67 int rc = lsb_deletejob(ref, 0, 0);
68 if (rc < 0) { // si erreur
69 char * msg = lsb_sysmsg();
70 if (!msg) msg = "unknown";
71 throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg);
75 // Methode pour le controle des jobs : suspend un job en file d'attente
76 void BatchManager_LSF::holdJob(const JobId & jobid)
79 istringstream iss(jobid.getReference());
81 int rc = lsb_signaljob(ref, SIGSTOP);
82 if (rc < 0) { // si erreur
83 char * msg = lsb_sysmsg();
84 if (!msg) msg = "unknown";
85 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
89 // Methode pour le controle des jobs : relache un job suspendu
90 void BatchManager_LSF::releaseJob(const JobId & jobid)
93 istringstream iss(jobid.getReference());
95 int rc = lsb_signaljob(ref, SIGCONT);
96 if (rc < 0) { // si erreur
97 char * msg = lsb_sysmsg();
98 if (!msg) msg = "unknown";
99 throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg);
104 // Methode pour le controle des jobs : modifie un job en file d'attente
105 void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
108 istringstream iss(jobid.getReference());
111 Job_LSF joblsf = Job(param, env);
112 struct submitReply reply;
113 ref = lsb_modify(joblsf.getSubmitStruct(),
116 if (ref < 0) { // si erreur
117 ostringstream msg_sst;
118 char * msg = lsb_sysmsg();
119 if (!msg) msg = "unknown";
120 msg_sst << msg << endl;
121 // msg_sst << "BadJobId = " << (long) reply.badJobId << endl
122 // << "BadJobName = " << reply.badJobName << endl
123 // << "BadReqIndx = " << reply.badReqIndx << endl;
124 throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str());
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)
131 alterJob(jobid, param, Environnement());
134 // Methode pour le controle des jobs : modifie un job en file d'attente
135 void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env)
137 alterJob(jobid, Parametre(), env);
142 // Methode pour le controle des jobs : renvoie l'etat du job
143 JobInfo BatchManager_LSF::queryJob(const JobId & jobid)
146 istringstream iss(jobid.getReference());
149 JobInfo_LSF ji = JobInfo_LSF(id);
156 // Methode pour le controle des jobs : teste si un job est present en machine
157 bool BatchManager_LSF::isRunning(const JobId & jobid)
160 istringstream iss(jobid.getReference());
163 JobInfo_LSF ji = JobInfo_LSF(id);
165 return ji.isRunning();