Salome HOME
updated copyright message
[modules/kernel.git] / src / Launcher / Launcher.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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 #ifndef __LAUNCHER_HXX__
24 #define __LAUNCHER_HXX__
25
26 #include "Launcher_Utils.hxx"
27 #include "Launcher_Job.hxx"
28
29 #include "ResourcesManager.hxx"
30 #include <SALOME_ResourcesCatalog_Parser.hxx>
31
32 #include "SALOME_Launcher_Parser.hxx"
33
34 #include <string>
35 #include <vector>
36 #include <list>
37 #include <memory>
38
39 class MpiImpl;
40
41 namespace Batch{
42   class BatchManager;
43   class Job;
44 }
45
46 struct LAUNCHER_EXPORT JobParameters_cpp
47 {
48   std::string job_name;
49   std::string job_type;
50   std::string job_file;
51   std::string pre_command;
52   std::string env_file;
53   std::list<std::string> in_files;
54   std::list<std::string> out_files;
55   std::string work_directory;
56   std::string local_directory;
57   std::string result_directory;
58   std::string maximum_duration;
59   resourceParams resource_required;
60   std::string queue;
61   std::string partition;
62   bool exclusive;
63   unsigned int mem_per_cpu;
64   std::string wckey;
65   std::string extra_params;
66   std::map<std::string, std::string> specific_parameters;
67   std::string launcher_file;
68   std::string launcher_args;
69 };
70
71 class LAUNCHER_EXPORT Launcher_cpp
72 {
73 public:
74   Launcher_cpp();
75   virtual ~Launcher_cpp();
76
77   // Main interface
78   void         createJob(Launcher::Job * new_job);
79   int          createJob(const JobParameters_cpp& job_parameters);
80   void         launchJob(int job_id);
81   std::string  getJobState(int job_id);
82   std::string  getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
83   void         exportInputFiles(int job_id);
84   void         getJobResults(int job_id, std::string directory);
85   void         clearJobWorkingDir(int job_id);
86   bool         getJobDumpState(int job_id, std::string directory);
87   bool         getJobWorkFile(int job_id, std::string work_file, std::string directory);
88   void         stopJob(int job_id);
89   void         removeJob(int job_id);
90   std::string  dumpJob(int job_id);
91   int restoreJob(const std::string& dumpedJob);
92   JobParameters_cpp getJobParameters(int job_id);
93
94   /*! Load the jobs from the file "jobs_file" and add them to the Launcher.
95    *  Return a list with the IDs of the jobs that were successfully loaded.
96    */
97   std::list<int> loadJobs(const char* jobs_file);
98
99   //! Save the jobs of the Launcher to the file "jobs_file".
100   void saveJobs(const char* jobs_file);
101
102   // Useful methods
103   long createJobWithFile(std::string xmlExecuteFile, std::string clusterName);
104   std::map<int, Launcher::Job *> getJobs();
105   void addJobDirectlyToMap(Launcher::Job * new_job);
106   Launcher::Job * findJob(int job_id);
107
108   // Lib methods
109   void SetResourcesManager( std::shared_ptr<ResourcesManager_cpp>& rm ) {_ResManager = rm;}
110
111 protected:
112
113   // Used by SALOME_Launcher
114   std::shared_ptr<ResourcesManager_cpp> _ResManager;
115
116   virtual void notifyObservers(const std::string & /*event_name*/, const std::string & /*event_data*/) {}
117   int addJob(Launcher::Job * new_job);
118
119   // Methods used by user interface methods
120 #ifdef WITH_LIBBATCH
121   Batch::BatchManager *FactoryBatchManager(ParserResourcesType& params);
122   std::map <int, Batch::BatchManager*> _batchmap;
123   Batch::BatchManager* getBatchManager(Launcher::Job * job);
124 #endif
125   ParserLauncherType ParseXmlFile(std::string xmlExecuteFile);
126
127   std::map <int, Launcher::Job *> _launcher_job_map;  
128   int _job_cpt; // job number counter
129 };
130
131 #endif