Salome HOME
SWIG-python API for Launcher_cpp
[modules/kernel.git] / src / Launcher_SWIG / Launcher.i
1 // Copyright (C) 2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 %module pylauncher
21
22 %{
23 #include "Launcher.hxx"
24 #include "ResourcesManager.hxx"
25
26 struct ResourceDefinition_cpp
27 {
28 public:
29   std::string name;
30   std::string hostname;
31   std::string type;
32   std::string protocol;
33   std::string username;
34   std::string applipath;
35   std::string OS;
36   int  mem_mb;
37   int  cpu_clock;
38   int  nb_node;
39   int  nb_proc_per_node;
40   std::string batch;
41   std::string mpiImpl;
42   std::string iprotocol;
43   bool can_launch_batch_jobs;
44   bool can_run_containers;
45   std::string working_directory;
46 };
47 %}
48
49 %include "std_string.i"
50 %include "std_vector.i"
51 %include "std_list.i"
52 %include "std_map.i"
53
54 namespace std {
55   %template(list_int) list<int>;
56   %template(list_str) list<string>;
57   %template(vector_str) vector<string>;
58   %template(map_ss) map<string,string>;
59 };
60
61 // see ResourceParameters from SALOME_ResourcesManager.idl
62 // see resourceParams from ResourcesManager.hxx
63 %naturalvar JobParameters_cpp::componentList;
64 %naturalvar JobParameters_cpp::resourceList;
65 struct resourceParams
66 {
67   resourceParams();
68
69   std::string name;
70   std::string hostname;
71   bool can_launch_batch_jobs;
72   bool can_run_containers;
73   std::string OS;
74   long nb_proc;
75   long nb_node;
76   long nb_proc_per_node;
77   long cpu_clock;
78   long mem_mb;
79   std::vector<std::string> componentList;
80   std::vector<std::string> resourceList;
81 };
82
83 // see JobParameters from SALOME_Launcher.idl
84 // see JobParameters_cpp from Launcher.hxx
85 %naturalvar JobParameters_cpp::in_files;
86 %naturalvar JobParameters_cpp::out_files;
87 %naturalvar JobParameters_cpp::specific_parameters;
88 struct JobParameters_cpp
89 {
90 public:
91   std::string job_name;
92   std::string job_type;
93   std::string job_file;
94   std::string pre_command;
95   std::string env_file;
96   std::list<std::string> in_files;
97   std::list<std::string> out_files;
98   std::string work_directory;
99   std::string local_directory;
100   std::string result_directory;
101   std::string maximum_duration;
102   resourceParams resource_required;
103   std::string queue;
104   std::string partition;
105   bool exclusive;
106   unsigned int mem_per_cpu;
107   std::string wckey;
108   std::string extra_params;
109   std::map<std::string, std::string> specific_parameters;
110   std::string launcher_file;
111   std::string launcher_args;
112 };
113
114 // see ResourceDefinition from SALOME_ResourcesManager.idl
115 // no other c++ equivalent. Convertion from ParserResourcesType
116 struct ResourceDefinition_cpp
117 {
118 public:
119   std::string name;
120   std::string hostname;
121   std::string type;
122   std::string protocol;
123   std::string username;
124   std::string applipath;
125   std::string OS;
126   int  mem_mb;
127   int  cpu_clock;
128   int  nb_node;
129   int  nb_proc_per_node;
130   std::string batch;
131   std::string mpiImpl;
132   std::string iprotocol;
133   bool can_launch_batch_jobs;
134   bool can_run_containers;
135   std::string working_directory;
136 };
137
138 %exception
139 {
140   try
141   {
142     $function
143   }
144   catch (ResourcesException& e)
145   {
146     SWIG_exception_fail(SWIG_RuntimeError, e.msg.c_str());
147   }
148   catch(...)
149   {
150     SWIG_exception_fail(SWIG_RuntimeError,"Unknown exception");
151   }
152 }
153
154 %include <std_shared_ptr.i>
155 %shared_ptr(ResourcesManager_cpp)
156
157 class ResourcesManager_cpp
158 {
159 public:
160   ResourcesManager_cpp(const char *xmlFilePath);
161   std::vector<std::string> GetFittingResources(const resourceParams& params);
162 %extend
163 {
164   ResourceDefinition_cpp GetResourceDefinition(const std::string& name)
165   {
166     ResourceDefinition_cpp swig_result;
167     ParserResourcesType cpp_result = $self->GetResourcesDescr(name);
168
169     swig_result.name = cpp_result.Name;
170     swig_result.hostname = cpp_result.HostName;
171     swig_result.type = cpp_result.getResourceTypeStr();
172     swig_result.protocol = cpp_result.getAccessProtocolTypeStr();
173     swig_result.username = cpp_result.UserName;
174     swig_result.applipath = cpp_result.AppliPath;
175     swig_result.OS = cpp_result.OS;
176     swig_result.mem_mb = cpp_result.DataForSort._memInMB;
177     swig_result.cpu_clock = cpp_result.DataForSort._CPUFreqMHz;
178     swig_result.nb_node = cpp_result.DataForSort._nbOfNodes;
179     swig_result.nb_proc_per_node = cpp_result.DataForSort._nbOfProcPerNode;
180     swig_result.batch = cpp_result.getBatchTypeStr();
181     swig_result.mpiImpl = cpp_result.getMpiImplTypeStr();
182     swig_result.iprotocol = cpp_result.getClusterInternalProtocolStr();
183     swig_result.can_launch_batch_jobs = cpp_result.can_launch_batch_jobs;
184     swig_result.can_run_containers = cpp_result.can_run_containers;
185     swig_result.working_directory = cpp_result.working_directory;
186
187     return swig_result;
188   }
189 }
190 };
191
192 %exception
193 {
194   try
195   {
196     $function
197   }
198   catch (LauncherException& e)
199   {
200     SWIG_exception_fail(SWIG_RuntimeError, e.msg.c_str());
201   }
202   catch(...)
203   {
204     SWIG_exception_fail(SWIG_RuntimeError,"Unknown exception");
205   }
206 }
207
208 class Launcher_cpp
209 {
210 public:
211   Launcher_cpp();
212   virtual ~Launcher_cpp();
213   int          createJob(const JobParameters_cpp& job_parameters);
214   void         launchJob(int job_id);
215   std::string  getJobState(int job_id);
216   std::string  getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
217   void         getJobResults(int job_id, std::string directory);
218   void         clearJobWorkingDir(int job_id);
219   bool         getJobDumpState(int job_id, std::string directory);
220   bool         getJobWorkFile(int job_id, std::string work_file, std::string directory);
221   void         stopJob(int job_id);
222   void         removeJob(int job_id);
223   std::string  dumpJob(int job_id);
224   int restoreJob(const std::string& dumpedJob);
225   JobParameters_cpp getJobParameters(int job_id);
226   std::list<int> loadJobs(const char* jobs_file);
227   void saveJobs(const char* jobs_file);
228   long createJobWithFile(std::string xmlExecuteFile, std::string clusterName);
229   void SetResourcesManager(std::shared_ptr<ResourcesManager_cpp>& rm );
230 };