1 // Copyright (C) 2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_ResourcesCatalog_Parser.hxx"
24 #include "Launcher_Job.hxx"
25 #include "Launcher_Job_SALOME.hxx"
26 #include "Launcher_Job_YACSFile.hxx"
27 #include "Launcher.hxx"
28 #include "ResourcesManager.hxx"
30 static PyObject *convertJob(Launcher::Job *job, int owner)
32 PyObject *ret(nullptr);
38 if(dynamic_cast<Launcher::Job_YACSFile *>(job))
39 return SWIG_NewPointerObj((void*)dynamic_cast<Launcher::Job_YACSFile *>(job),SWIGTYPE_p_Launcher__Job_YACSFile,owner);
40 throw LauncherException("Not recognized type of job on downcast !");
47 %typemap(out) const std::list<std::string>&
50 std::list<std::string>::const_iterator iL;
51 $result = PyList_New($1->size());
52 for (i=0, iL=$1->cbegin(); iL!=$1->cend(); i++, iL++)
53 PyList_SetItem($result,i,PyUnicode_FromString((*iL).c_str()));
56 %typemap(out) const std::map<std::string, std::string> &
58 $result = PyDict_New();
59 for(std::map<std::string, std::string>::const_iterator iL=$1->cbegin();iL!=$1->cend();iL++)
61 PyObject *a(PyUnicode_FromString((*iL).first.c_str()));
62 PyObject *b(PyUnicode_FromString((*iL).second.c_str()));
63 PyDict_SetItem($result,a,b);
64 Py_DECREF(a); Py_DECREF(b);
68 %typemap(out) std::vector<std::string> *
71 std::vector<std::string>::const_iterator iL;
72 $result = PyList_New($1->size());
73 for (i=0, iL=$1->cbegin(); iL!=$1->cend(); i++, iL++)
74 PyList_SetItem($result,i,PyUnicode_FromString((*iL).c_str()));
77 %typemap(out) Launcher::Job *
79 $result=convertJob($1,$owner);
87 catch(LauncherException& e)
89 SWIG_exception_fail(SWIG_RuntimeError,e.msg.c_str());
93 SWIG_exception_fail(SWIG_UnknownError, "Unknown");
102 std::string hostname;
103 bool can_launch_batch_jobs;
104 bool can_run_containers;
108 long nb_proc_per_node;
111 std::vector<std::string> componentList;
112 std::vector<std::string> resourceList;
115 class ResourcesManager_cpp
118 ResourcesManager_cpp(const char *xmlFilePath);
121 class ParserResourcesType
124 ParserResourcesType();
125 ~ParserResourcesType();
126 std::string getAccessProtocolTypeStr() const;
127 std::string getResourceTypeStr() const;
128 std::string getBatchTypeStr() const;
129 std::string getMpiImplTypeStr() const;
130 std::string getClusterInternalProtocolStr() const;
131 std::string getCanLaunchBatchJobsStr() const;
132 std::string getCanRunContainersStr() const;
134 void setAccessProtocolTypeStr(const std::string & protocolTypeStr);
135 void setResourceTypeStr(const std::string & resourceTypeStr);
136 void setBatchTypeStr(const std::string & batchTypeStr);
137 void setMpiImplTypeStr(const std::string & mpiImplTypeStr);
138 void setClusterInternalProtocolStr(const std::string & internalProtocolTypeStr);
139 void setCanLaunchBatchJobsStr(const std::string & canLaunchBatchJobsStr);
140 void setCanRunContainersStr(const std::string & canRunContainersStr);
143 %feature("unref") Launcher::Job "$this->decrRef();"
144 %feature("unref") Launcher::Job_SALOME "$this->decrRef();"
145 %feature("unref") Launcher::Job_YACSFile "$this->decrRef();"
154 void setState(const std::string & state);
155 std::string getState() const;
156 std::string getAssignedHostnames();
157 void setNumber(const int & number);
159 virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
160 ParserResourcesType getResourceDefinition() const;
162 void setJobName(const std::string & job_name);
163 virtual void setJobFile(const std::string & job_file);
164 void setPreCommand(const std::string & preCommand);
165 void setWorkDirectory(const std::string & work_directory);
166 void setLocalDirectory(const std::string & local_directory);
167 void setResultDirectory(const std::string & result_directory);
168 void add_in_file(const std::string & file);
169 void add_out_file(const std::string & file);
170 void setMaximumDuration(const std::string & maximum_duration);
171 void setResourceRequiredParams(const resourceParams & resource_required_params);
172 void setQueue(const std::string & queue);
173 void setPartition(const std::string & partition);
174 void setEnvFile(const std::string & env_file);
175 void setExclusive(bool exclusive);
176 void setExclusiveStr(const std::string & exclusiveStr);
177 void setMemPerCpu(unsigned long mem_per_cpu);
178 void setWCKey(const std::string & wckey);
179 void setExtraParams(const std::string & extra_params);
180 void setReference(const std::string & reference);
182 void setLauncherFile(const std::string & launcher_file);
183 void setLauncherArgs(const std::string & launcher_args);
185 std::string getJobName() const;
186 std::string getJobFile() const;
187 std::string getPreCommand() const;
188 std::string getWorkDirectory() const;
189 std::string getLocalDirectory() const;
190 std::string getResultDirectory() const;
191 const std::list<std::string> & get_in_files() const;
192 const std::list<std::string> & get_out_files() const;
193 std::string getMaximumDuration() const;
194 resourceParams getResourceRequiredParams() const;
195 std::string getQueue() const;
196 std::string getPartition() const;
197 std::string getEnvFile() const;
198 std::string getJobType() const;
199 bool getExclusive() const;
200 std::string getExclusiveStr() const;
201 unsigned long getMemPerCpu() const;
202 std::string getWCKey() const;
203 std::string getExtraParams() const;
204 std::string getReference() const;
205 std::string getLauncherFile() const;
206 std::string getLauncherArgs() const;
207 std::string updateJobState();
209 void addSpecificParameter(const std::string & name, const std::string & value);
210 const std::map<std::string, std::string> & getSpecificParameters() const;
211 virtual void checkSpecificParameters();
214 void checkMaximumDuration(const std::string & maximum_duration);
215 void checkResourceRequiredParams(const resourceParams & resource_required_params);
218 long convertMaximumDuration(const std::string & maximum_duration);
219 std::string getLaunchDate() const;
223 virtual void update_job() = 0;
226 class Job_SALOME : public Job
231 virtual ~Job_SALOME();
232 virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
233 virtual void update_job();
236 std::string buildSalomeScript(Batch::Parametre params);
240 class Job_YACSFile : public Job_SALOME
244 virtual ~Job_YACSFile();
245 virtual void setJobFile(const std::string & job_file);
246 virtual void checkSpecificParameters();
254 virtual ~Launcher_cpp();
255 void createJob(Launcher::Job * new_job);
256 void launchJob(int job_id);
257 const char * getJobState(int job_id);
258 const char * getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
259 void getJobResults(int job_id, std::string directory);
260 void clearJobWorkingDir(int job_id);
261 bool getJobDumpState(int job_id, std::string directory);
262 bool getJobWorkFile(int job_id, std::string work_file, std::string directory);
263 void stopJob(int job_id);
264 void removeJob(int job_id);
265 std::string dumpJob(int job_id);
266 int restoreJob(const std::string& dumpedJob);
267 std::list<int> loadJobs(const char* jobs_file);
268 void saveJobs(const char* jobs_file);
269 long createJobWithFile(std::string xmlExecuteFile, std::string clusterName);
270 std::map<int, Launcher::Job *> getJobs();
271 void addJobDirectlyToMap(Launcher::Job * new_job);
272 void SetResourcesManager( ResourcesManager_cpp *rm );
273 Launcher::Job * findJob(int job_id);
277 def sendJobToSession(self, job_id, sessionId=None):
278 """Send job specified by its job_id in self to a remote SALOME session.
279 Doing so, it's possible to follow the job created locally into the JobManager module of the target SALOME session.
280 SALOME session is specified by the file pointed by the content of OMNIORB_CONFIG environement var. The content of this var is called sessionId.
281 If sessionId is let untouched, the current OMNIORB_CONFIG environement var is used.
282 If this method fails to connect to the target SALOME session a RuntimeError exception will be thrown.
284 def job_type_traducer(jyf):
285 dico = {'Job_YACSFile' : 'yacs_file'}
286 st = type(jyf).__name__
288 raise RuntimeError("Not recognized type %s !"%st)
291 def resource_required_func(jyf):
293 rp =jyf.getResourceRequiredParams()
294 l12 = [('name', None), ('hostname', None), ('can_launch_batch_jobs', None), ('can_run_containers', None), ('OS', None), ('componentList', None), ('nb_proc', None), ('mem_mb', None), ('cpu_clock', None), ('nb_node', None), ('nb_proc_per_node', None), ('policy', lambda x: 'cycl'), ('resList', lambda x: x.resourceList)]
302 return Engines.ResourceParameters(**kw2)
304 filest = self.dumpJob(job_id);
305 # Connect to SALOME session a retrieve its SalomeLauncher object
307 if sessionId is not None:
308 os.environ["OMNIORB_CONFIG"]=sessionId
312 clt=orbmodule.client()
313 sl = clt.Resolve("SalomeLauncher")
315 raise RuntimeError("Fail to connect to the remote SALOME session.")
316 # swig to CORBA translation
317 # Job_YACSFile -> Engines.JobParameters and resourceParams -> Engines.ResourceParameters()
318 l21= [('job_name', None), ('job_type', job_type_traducer), ('job_file', None), ('pre_command', None), ('env_file', None), ('in_files', lambda x: x.get_in_files()), ('out_files', lambda x: x.get_out_files()), ('work_directory', None), ('local_directory', None), ('result_directory', None), ('maximum_duration', None), ('resource_required',resource_required_func) , ('queue', None), ('partition', None), ('exclusive', None), ('mem_per_cpu', None), ('wckey', lambda x: x.getWCKey() ), ('extra_params', None), ('specific_parameters', lambda x: list(x.getSpecificParameters().items())), ('launcher_file', None), ('launcher_args', None)]
320 jyf = self.findJob(job_id)
323 kw[a]=eval("jyf.get%s()"%"".join(["%s%s"%(elt2[0].upper(),elt2[1:]) for elt2 in a.split("_")]),{"jyf" : jyf})
327 jyc = Engines.JobParameters(**kw)
328 ########################
329 bpc = sl.createJob(jyc)
330 sl.restoreJob(filest)
332 Launcher_cpp.sendJobToSession = sendJobToSession