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