Salome HOME
487a39b34b494323ef389e7676cd7e7e921ab482
[modules/jobmanager.git] / src / engine / BL_Job.cxx
1 // Copyright (C) 2009-2014  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::setLoadLevelerJobType(const std::string & jobtype)
208 {
209   _ll_jobtype = jobtype;
210 }
211
212 std::string &
213 BL::Job::getLoadLevelerJobType()
214 {
215   return _ll_jobtype;
216 }
217
218 void 
219 BL::Job::setState(BL::Job::State state)
220 {
221   _state = state;
222 }
223
224 BL::Job::State 
225 BL::Job::getState()
226 {
227   return _state;
228 }
229
230 std::string
231 BL::Job::setStringState(const std::string & state)
232 {
233   std::string result("");
234
235   // Check if state is an error
236   if (state != "CREATED"     &&
237       state != "IN_PROCESS"  &&
238       state != "QUEUED"      &&
239       state != "RUNNING"     &&
240       state != "PAUSED"      &&
241       state != "FINISHED"    &&
242       state != "FAILED"      &&
243       state != "NOT_CREATED" &&
244       state != "ERROR"
245      )
246   {
247     DEBTRACE("Error state in setStringState");
248     result = "RefreshError";
249   }
250
251   if (result == "")
252   {
253     if (state == "CREATED")
254     {
255       if (_state != BL::Job::CREATED)
256       {
257         setState(BL::Job::CREATED);
258         result = state;
259       }
260     }
261     else if (state == "NOT_CREATED")
262     {
263       if (_state != BL::Job::NOT_CREATED)
264       {
265         setState(BL::Job::NOT_CREATED);
266         result = state;
267       }
268     }
269     else if (state == "QUEUED")
270     {
271       if (_state != BL::Job::QUEUED)
272       {
273         setState(BL::Job::QUEUED);
274         result = state;
275       }
276     }
277     else if (state == "IN_PROCESS")
278     {
279       if (_state != BL::Job::IN_PROCESS)
280       {
281         setState(BL::Job::IN_PROCESS);
282         result = state;
283       }
284     }
285     else if (state == "RUNNING")
286     {
287       if (_state != BL::Job::RUNNING)
288       {
289         setState(BL::Job::RUNNING);
290         result = state;
291       }
292     }
293     else if (state == "PAUSED")
294     {
295       if (_state != BL::Job::PAUSED)
296       {
297         setState(BL::Job::PAUSED);
298         result = state;
299       }
300     }
301     else if (state == "FINISHED")
302     {
303       if (_state != BL::Job::FINISHED)
304       {
305         setState(BL::Job::FINISHED);
306         result = state;
307       }
308     }
309     else if (state == "ERROR")
310     {
311       if (_state != BL::Job::ERROR)
312       {
313         setState(BL::Job::ERROR);
314         result = state;
315       }
316     }
317     else if (state == "FAILED")
318     {
319       if (_state != BL::Job::FAILED)
320       {
321         setState(BL::Job::FAILED);
322         result = state;
323       }
324     }
325   }
326   return result;
327 }
328
329 void 
330 BL::Job::setThreadState(BL::Job::ThreadState state)
331 {
332   _thread_state = state;
333 }
334
335 BL::Job::ThreadState 
336 BL::Job::getThreadState()
337 {
338   return _thread_state;
339 }
340
341 void 
342 BL::Job::setSalomeLauncherId(int id)
343 {
344   _salome_launcher_id = id;
345 }
346
347 int 
348 BL::Job::getSalomeLauncherId()
349 {
350   return _salome_launcher_id;
351 }