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