Salome HOME
Create LICENSE
[modules/jobmanager.git] / src / engine / BL_Job.cxx
1 // Copyright (C) 2009-2024  CEA, EDF
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 #include "BL_Job.hxx"
21
22 BL::Job::Job()
23 {
24   DEBTRACE("Creating BL::Job");
25   _name = "";
26   _type = COMMAND;
27   _job_file = "";
28   _env_file = "";
29   _pre_command = "";
30   _batch_params.batch_directory = "";
31   _batch_params.maximum_duration = "";
32   _batch_params.mem_limit = 0;
33   _batch_params.mem_req_type = MEM_PER_NODE;
34   _batch_params.nb_proc = 0;
35   _batch_params.nb_node = 0;
36   _batch_params.exclusive = false;
37   _files_params.result_directory = "";
38   _resource_choosed = "";
39   _batch_queue = "";
40   _batch_partition = "";
41   _state = BL::Job::CREATED;
42   _thread_state = BL::Job::NOTHING;
43   _salome_launcher_id = -1;
44   _dump_yacs_state = 0;
45   _yacs_driver_options = "";
46   _ll_jobtype = "";
47
48   // Parameters for COORM
49   _batch_params.launcher_file = "";
50   _batch_params.launcher_args = "";
51 }
52
53 BL::Job::Job(const std::string & name)
54 {
55   DEBTRACE("Creating BL::Job with name : " << name);
56   _name = name;
57   _type = COMMAND;
58   _job_file = "";
59   _env_file = "";
60   _pre_command = "";
61   _batch_params.batch_directory = "";
62   _batch_params.maximum_duration = "";
63   _batch_params.mem_limit = 0;
64   _batch_params.mem_req_type = MEM_PER_NODE;
65   _batch_params.nb_proc = 0;
66   _batch_params.nb_node = 0;
67   _batch_params.exclusive = false;
68   _files_params.result_directory = "";
69   _resource_choosed = "";
70   _batch_queue = "";
71   _batch_partition = "";
72   _state = BL::Job::CREATED;
73   _thread_state = BL::Job::NOTHING;
74   _salome_launcher_id = -1;
75   _dump_yacs_state = 0;
76   _yacs_driver_options = "";
77   _ll_jobtype = "";
78
79   // Parameters for COORM
80   _batch_params.launcher_file = "";
81   _batch_params.launcher_args = "";
82 }
83
84 BL::Job::~Job()
85 {}
86
87 void
88 BL::Job::setName(const std::string & name)
89 {
90   _name = name;
91 }
92
93 std::string
94 BL::Job::getName()
95 {
96   return _name;
97 }
98
99 void
100 BL::Job::setType(BL::Job::JobType type)
101 {
102   _type = type;
103 }
104
105 void
106 BL::Job::setType(const std::string & type)
107 {
108   if (type == "command")
109   {
110     setType(BL::Job::COMMAND);
111   }
112   else if (type == "yacs_file")
113   {
114     setType(BL::Job::YACS_SCHEMA);
115   }
116   else if (type == "python_salome")
117   {
118     setType(BL::Job::PYTHON_SALOME);
119   }
120   else if (type == "command_salome")
121   {
122     setType(BL::Job::COMMAND_SALOME);
123   }
124 }
125
126 BL::Job::JobType
127 BL::Job::getType()
128 {
129   return _type;
130 }
131
132 void
133 BL::Job::setDumpYACSState(const int & dump_yacs_state)
134 {
135   _dump_yacs_state = dump_yacs_state;
136 }
137
138 int
139 BL::Job::getDumpYACSState()
140 {
141   return _dump_yacs_state;
142 }
143
144 void
145 BL::Job::setYacsDriverOptions(const std::string& options)
146 {
147   _yacs_driver_options = options;
148 }
149
150 const std::string&
151 BL::Job::getYacsDriverOptions()const
152 {
153   return _yacs_driver_options;
154 }
155
156 void 
157 BL::Job::setJobFile(const std::string & job_file)
158 {
159   _job_file = job_file;
160 }
161
162 std::string & 
163 BL::Job::getJobFile()
164 {
165   return _job_file;
166 }
167
168 void 
169 BL::Job::setEnvFile(const std::string & env_file)
170 {
171   _env_file = env_file;
172 }
173
174 std::string & 
175 BL::Job::getEnvFile()
176 {
177   return _env_file;
178 }
179
180 void 
181 BL::Job::setPreCommand(const std::string & pre_command)
182 {
183   _pre_command = pre_command;
184 }
185
186 std::string & 
187 BL::Job::getPreCommand()
188 {
189   return _pre_command;
190 }
191
192 void 
193 BL::Job::setBatchParameters(const BL::Job::BatchParam & param)
194 {
195   _batch_params = param;
196 }
197
198 const BL::Job::BatchParam &
199 BL::Job::getBatchParameters()
200 {
201   return _batch_params;
202 }
203
204 void 
205 BL::Job::setFilesParameters(BL::Job::FilesParam & param)
206 {
207   _files_params.result_directory = param.result_directory;
208   _files_params.input_files_list = param.input_files_list;
209   _files_params.output_files_list = param.output_files_list;
210 }
211
212 BL::Job::FilesParam & 
213 BL::Job::getFilesParameters()
214 {
215   return _files_params;
216 }
217
218 void
219 BL::Job::setResource(const std::string & resource)
220 {
221   _resource_choosed = resource;
222 }
223
224 std::string &
225 BL::Job::getResource()
226 {
227   return _resource_choosed;
228 }
229
230 void
231 BL::Job::setBatchQueue(const std::string & queue)
232 {
233   _batch_queue = queue;
234 }
235
236 std::string &
237 BL::Job::getBatchQueue()
238 {
239   return _batch_queue;
240 }
241
242 void
243 BL::Job::setBatchPartition(const std::string & partition)
244 {
245   _batch_partition = partition;
246 }
247
248 std::string &
249 BL::Job::getBatchPartition()
250 {
251   return _batch_partition;
252 }
253
254 void
255 BL::Job::setWCKey(const std::string & wckey)
256 {
257   _wckey = wckey;
258 }
259
260 const std::string &
261 BL::Job::getWCKey()
262 {
263   return _wckey;
264 }
265
266 void
267 BL::Job::setExtraParams(const std::string & extra_params)
268 {
269   _extra_params = extra_params;
270 }
271
272 const std::string &
273 BL::Job::getExtraParams()
274 {
275   return _extra_params;
276 }
277
278 void
279 BL::Job::setLoadLevelerJobType(const std::string & jobtype)
280 {
281   _ll_jobtype = jobtype;
282 }
283
284 std::string &
285 BL::Job::getLoadLevelerJobType()
286 {
287   return _ll_jobtype;
288 }
289
290 void 
291 BL::Job::setState(BL::Job::State state)
292 {
293   _state = state;
294 }
295
296 BL::Job::State 
297 BL::Job::getState()
298 {
299   return _state;
300 }
301
302 std::string
303 BL::Job::setStringState(const std::string & state)
304 {
305   std::string result("");
306
307   // Check if state is an error
308   if (state != "CREATED"     &&
309       state != "IN_PROCESS"  &&
310       state != "QUEUED"      &&
311       state != "RUNNING"     &&
312       state != "PAUSED"      &&
313       state != "FINISHED"    &&
314       state != "FAILED"      &&
315       state != "NOT_CREATED" &&
316       state != "ERROR"
317      )
318   {
319     DEBTRACE("Error state in setStringState");
320     result = "RefreshError";
321   }
322
323   if (result == "")
324   {
325     if (state == "CREATED")
326     {
327       if (_state != BL::Job::CREATED)
328       {
329         setState(BL::Job::CREATED);
330         result = state;
331       }
332     }
333     else if (state == "NOT_CREATED")
334     {
335       if (_state != BL::Job::NOT_CREATED)
336       {
337         setState(BL::Job::NOT_CREATED);
338         result = state;
339       }
340     }
341     else if (state == "QUEUED")
342     {
343       if (_state != BL::Job::QUEUED)
344       {
345         setState(BL::Job::QUEUED);
346         result = state;
347       }
348     }
349     else if (state == "IN_PROCESS")
350     {
351       if (_state != BL::Job::IN_PROCESS)
352       {
353         setState(BL::Job::IN_PROCESS);
354         result = state;
355       }
356     }
357     else if (state == "RUNNING")
358     {
359       if (_state != BL::Job::RUNNING)
360       {
361         setState(BL::Job::RUNNING);
362         result = state;
363       }
364     }
365     else if (state == "PAUSED")
366     {
367       if (_state != BL::Job::PAUSED)
368       {
369         setState(BL::Job::PAUSED);
370         result = state;
371       }
372     }
373     else if (state == "FINISHED")
374     {
375       if (_state != BL::Job::FINISHED)
376       {
377         setState(BL::Job::FINISHED);
378         result = state;
379       }
380     }
381     else if (state == "ERROR")
382     {
383       if (_state != BL::Job::ERROR)
384       {
385         setState(BL::Job::ERROR);
386         result = state;
387       }
388     }
389     else if (state == "FAILED")
390     {
391       if (_state != BL::Job::FAILED)
392       {
393         setState(BL::Job::FAILED);
394         result = state;
395       }
396     }
397   }
398   return result;
399 }
400
401 void 
402 BL::Job::setThreadState(BL::Job::ThreadState state)
403 {
404   _thread_state = state;
405 }
406
407 BL::Job::ThreadState 
408 BL::Job::getThreadState()
409 {
410   return _thread_state;
411 }
412
413 void 
414 BL::Job::setSalomeLauncherId(int id)
415 {
416   _salome_launcher_id = id;
417 }
418
419 int 
420 BL::Job::getSalomeLauncherId()
421 {
422   return _salome_launcher_id;
423 }