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