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