Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Core / BatchManager.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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, or (at your option) any later version.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * BatchManager.hxx : 
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Date   : Septembre 2003
27  * Projet : SALOME 2
28  *
29  */
30
31 #ifndef _BATCHMANAGER_H_
32 #define _BATCHMANAGER_H_
33
34 #include "Defines.hxx"
35
36 #include <string>
37 #include <map>
38 #include "Job.hxx"
39 #include "JobId.hxx"
40 #include "JobInfo.hxx"
41 #include "InvalidArgumentException.hxx"
42 #include "CommunicationProtocol.hxx"
43 #include "MpiImpl.hxx"
44
45 namespace Batch {
46
47   class Job;
48   class JobId;
49   class JobInfo;
50   class FactBatchManager;
51
52   class BATCH_EXPORT BatchManager
53   {
54   public:
55     // Constructeur et destructeur
56     BatchManager(const Batch::FactBatchManager * parent, const char * host = "localhost",
57                  const char * username = "",
58                  CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi");
59     virtual ~BatchManager();
60     virtual std::string __repr__() const;
61
62     // Recupere le l'identifiant d'un job deja soumis au BatchManager
63     //virtual const JobId getJobIdByReference(const std::string & ref);
64     virtual const Batch::JobId getJobIdByReference(const char * ref);
65
66     // Methodes pour le controle des jobs : doivent etre implementees dans les classes filles
67     virtual const Batch::JobId submitJob(const Batch::Job & job); // soumet un job au gestionnaire
68     virtual void deleteJob(const Batch::JobId & jobid); // retire un job du gestionnaire
69     virtual void holdJob(const Batch::JobId & jobid); // suspend un job en file d'attente
70     virtual void releaseJob(const Batch::JobId & jobid); // relache un job suspendu
71     virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param, const Batch::Environnement & env); // modifie un job en file d'attente
72     virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param); // modifie un job en file d'attente
73     virtual void alterJob(const Batch::JobId & jobid, const Batch::Environnement & env); // modifie un job en file d'attente
74     virtual Batch::JobInfo queryJob(const Batch::JobId & jobid); // renvoie l'etat du job
75     virtual const Batch::JobId addJob(const Batch::Job & job, const std::string & reference); // ajoute un nouveau job sans le soumettre
76     virtual std::string waitForJobEnd(const Batch::JobId & jobid, long timeout = -1,
77                                       long initSleepTime = 1, long maxSleepTime = 600);
78     virtual void importOutputFiles( const Job & job, const std::string directory );
79     bool importDumpStateFile( const Job & job, const std::string directory );
80     // copier le fichier work_file à partir du working_directory vers directory
81     virtual bool importWorkFile( const Job & job, const std::string& work_file, const std::string& directory );
82     virtual void clearWorkingDir( const Job & job );
83
84     // Get the underlying communication protocol
85     const CommunicationProtocol & getProtocol() const;
86     virtual void exportInputFiles(const Job & job);
87
88   protected:
89     std::string _hostname; // serveur ou tourne le BatchManager
90     // std::map< const std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis
91     std::map< std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis
92     const std::string & _type;
93     const CommunicationProtocol & _protocol; // protocol to access _hostname
94     const std::string _username; // username to access _hostname
95     MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script
96
97     MpiImpl* FactoryMpiImpl(std::string mpiImpl);
98     
99     // Preprocessing done on the frontal using "PREPROCESS" parameter as a script.
100     // May throw exceptions in case of failure.
101     virtual void preprocess(const Batch::Job & job);
102     
103     // Submit to batch manager, but we suppose input files are already copied
104     // and preprocess finished without error
105     virtual const Batch::JobId runJob(const Batch::Job & job);
106
107   private:
108
109   };
110
111 }
112
113 #endif