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