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_Local.hxx :
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
30 * Refactored by Renaud Barate (EDF R&D) in September 2009 to use
31 * CommunicationProtocol classes and merge Local_SH, Local_RSH and Local_SSH batch
36 #ifndef _BATCHMANAGER_LOCAL_H_
37 #define _BATCHMANAGER_LOCAL_H_
39 #include "Batch_Defines.hxx"
40 #include "Batch_CommunicationProtocol.hxx"
50 #include "Batch_Job.hxx"
51 #include "Batch_JobId.hxx"
52 #include "Batch_JobInfo.hxx"
53 #include "Batch_JobInfo_Local.hxx"
54 #include "Batch_Job_Local.hxx"
55 #include "Batch_BatchManager.hxx"
59 class FactBatchManager;
62 * This class defines a local pseudo batch manager that can launch jobs locally or on a remote
63 * machine with SSH or RSH. This class is NOT thread-safe.
65 class BATCH_EXPORT BatchManager_Local : virtual public BatchManager
70 typedef HANDLE Process;
72 typedef pid_t Process;
74 friend class ThreadAdapter;
77 ThreadAdapter(BatchManager_Local & bm, const Job_Local & job, Id id);
78 static void * run(void * arg);
79 BatchManager_Local & getBatchManager() const { return _bm; };
80 Id getId() const { return _id; };
83 BatchManager_Local & _bm;
88 void pere(Process child);
92 Process launchWin32ChildProcess();
108 std::queue<Commande, std::deque<Commande> > command_queue;
120 BatchManager_Local(const Batch::FactBatchManager * parent, const char * host = "localhost",
121 const char * username = "",
122 CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi",
123 int nb_proc_per_node = 1);
124 virtual ~BatchManager_Local();
126 // Recupere le nom du serveur par defaut
127 // static string BatchManager_Local::getDefaultServer();
129 // Methodes pour le controle des jobs
130 virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire
131 virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire
132 virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente
133 virtual void releaseJob(const JobId & jobid); // relache un job suspendu
134 virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente
135 virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente
136 virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente
137 virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job
138 virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine
140 virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente
141 virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente
143 virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre
146 int _connect; // Local connect id
147 pthread_mutex_t _threads_mutex;
148 std::map<Id, Child > _threads;
150 // Methode qui renvoie la commande a executer
151 std::vector<std::string> exec_command(const Parametre & param) const;
154 static void kill_child_on_exit(void * p_pid);
155 static void delete_on_exit(void * arg);
156 static void setFailedOnCancel(void * arg);
157 pthread_cond_t _threadSyncCondition;
162 // Recupere le l'identifiant d'un job deja soumis au BatchManager
163 //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); }
164 virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); }