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