Salome HOME
bd44f39546a3bb5e59dd908406f4b0fccdbbeafb
[modules/jobmanager.git] / src / genericgui / BL_JobTab.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_JobTab.hxx"
21 #include "BL_Traces.hxx"
22
23 #ifdef WNT
24 #undef ERROR
25 #endif
26
27 using namespace std;
28
29 BL::JobTab::JobTab(QWidget *parent, BL::JobsManager_QT * jobs_manager) : QTabWidget(parent)
30 {
31   DEBTRACE("Creating BL::JobTab");
32   BL_ASSERT(parent);
33   BL_ASSERT(jobs_manager);
34   _parent = parent;
35   _jobs_manager = jobs_manager;
36   _model = NULL;
37
38   createJobSummaryTab();
39   createJobFilesTab();
40 }
41
42 BL::JobTab::~JobTab()
43 {
44   DEBTRACE("Destroying BL::JobTab");
45 }
46
47 void
48 BL::JobTab::setModel(QStandardItemModel * model)
49 {
50   DEBTRACE("Call setModel BL::JobTab");
51   BL_ASSERT(model);
52
53   _model = model;
54 }
55
56 void
57 BL::JobTab::createJobSummaryTab()
58 {
59   _summary_tab = new QWidget(this);
60
61   QLabel * job_name_label = new QLabel("Name:");
62   _job_name_label_value = new QLabel("");
63   QLabel * job_type_label = new QLabel("Type:");
64   _job_type_label_value = new QLabel("");
65   QLabel * job_state_label = new QLabel("State:");
66   _job_state_label_value = new QLabel("");
67   QLabel * job_launcher_label = new QLabel("Launcher Id:");
68   _job_launcher_label_value = new QLabel("");
69   QLabel * job_resource_label = new QLabel("Resource:");
70   _job_resource_label_value = new QLabel("");
71   QLabel * job_jobfile_label = new QLabel("Job File:");
72   _job_jobfile_label_value = new QLabel("");
73   QLabel * job_envfile_label = new QLabel("Env File:");
74   _job_envfile_label_value = new QLabel("");
75
76
77   // Specific values
78   _yacs_dump_state_label = new QLabel("YACS dump state:");
79   _yacs_dump_state_value = new QLabel("");
80
81   QGroupBox * main_values_box = new QGroupBox("Main values");
82   _main_values_form = new QFormLayout;
83   _main_values_form->insertRow(0, job_name_label, _job_name_label_value);
84   _main_values_form->insertRow(1, job_type_label, _job_type_label_value);
85   _main_values_form->insertRow(2, job_state_label, _job_state_label_value);
86   _main_values_form->insertRow(3, job_launcher_label, _job_launcher_label_value);
87   _main_values_form->insertRow(4, job_resource_label, _job_resource_label_value);
88   _main_values_form->insertRow(5, job_jobfile_label, _job_jobfile_label_value);
89   _main_values_form->insertRow(6, job_envfile_label, _job_envfile_label_value);
90   main_values_box->setLayout(_main_values_form);
91
92   QLabel * job_nif_label = new QLabel("Number of Input Files:");
93   _job_nif_label_value = new QLabel("");
94   QLabel * job_nof_label = new QLabel("Number of Output Files:");
95   _job_nof_label_value = new QLabel("");
96   QLabel * job_bd_label = new QLabel("Execution directory:");
97   _job_bd_label_value = new QLabel("");
98   QLabel * job_rd_label = new QLabel("Result directory:");
99   _job_rd_label_value = new QLabel("");
100
101   QLabel * job_mdt_label = new QLabel("Maximum duration:");
102   _job_mdt_label_value = new QLabel("");
103   QLabel * job_em_label = new QLabel("Expected memory:");
104   _job_em_label_value = new QLabel("");
105   QLabel * job_nop_label = new QLabel("Number of processors:");
106   _job_nop_label_value = new QLabel("");
107   QLabel * job_excl_label = new QLabel("Exclusive:");
108   _job_excl_label_value = new QLabel("");
109
110   // Parameters for COORM
111   QLabel * job_lf_label = new QLabel("Launcher file:");
112   _job_lf_label_value = new QLabel("");
113   QLabel * job_la_label = new QLabel("Launcher args:");
114   _job_la_label_value = new QLabel("");
115
116   // Specific values
117   _batch_queue_label = new QLabel("Batch queue:");
118   _batch_queue_value = new QLabel("");
119   _ll_jobtype_label = new QLabel("LoadLeveler JobType:");
120   _ll_jobtype_value = new QLabel("");
121
122   QGroupBox * run_values_box = new QGroupBox("Run values");
123   _run_values_form = new QFormLayout;
124   _run_values_form->insertRow(0, job_nif_label, _job_nif_label_value);
125   _run_values_form->insertRow(1, job_nof_label, _job_nof_label_value);
126   _run_values_form->insertRow(2, job_bd_label, _job_bd_label_value);
127   _run_values_form->insertRow(3, job_rd_label, _job_rd_label_value);
128
129   // Parameters for COORM
130   _run_values_form->insertRow(4, job_lf_label, _job_lf_label_value);
131
132   _other_run_values_form = new QFormLayout;
133   _other_run_values_form->insertRow(0, job_mdt_label, _job_mdt_label_value);
134   _other_run_values_form->insertRow(1, job_em_label, _job_em_label_value);
135   _other_run_values_form->insertRow(2, job_nop_label, _job_nop_label_value);
136   _other_run_values_form->insertRow(3, job_excl_label, _job_excl_label_value);
137
138   // Parameters for COORM
139   _other_run_values_form->insertRow(4, job_la_label, _job_la_label_value);
140
141   QHBoxLayout * box_layout = new QHBoxLayout();
142   box_layout->addLayout(_run_values_form);
143   box_layout->addLayout(_other_run_values_form);
144   run_values_box->setLayout(box_layout);
145
146   QVBoxLayout * mainLayout = new QVBoxLayout();
147   mainLayout->addWidget(main_values_box);
148   mainLayout->addWidget(run_values_box);
149   _summary_tab->setLayout(mainLayout);
150
151   removeTab(0);
152   insertTab(0, _summary_tab, "Job Summary");
153   setCurrentIndex(0);
154 }
155
156 void
157 BL::JobTab::createJobFilesTab()
158 {
159   _files_tab = new QWidget(this);
160
161   _input_files_list = new QListWidget(this);
162   _input_files_list->setSelectionMode(QAbstractItemView::NoSelection);
163   QGroupBox * input_files_box = new QGroupBox("Input Files");
164   QVBoxLayout * input_layout = new QVBoxLayout();
165   input_layout->addWidget(_input_files_list);
166   input_files_box->setLayout(input_layout);
167
168   _output_files_list = new QListWidget(this);
169   _output_files_list->setSelectionMode(QAbstractItemView::NoSelection);
170   QGroupBox * output_files_box = new QGroupBox("Output Files");
171   QVBoxLayout * output_layout = new QVBoxLayout();
172   output_layout->addWidget(_output_files_list);
173   output_files_box->setLayout(output_layout);
174
175   QVBoxLayout * mainLayout = new QVBoxLayout();
176   mainLayout->addWidget(input_files_box);
177   mainLayout->addWidget(output_files_box);
178   _files_tab->setLayout(mainLayout);
179
180   insertTab(1, _files_tab, "Job Files");
181 }
182
183 void
184 BL::JobTab::job_selected(const QModelIndex & index)
185 {
186   DEBTRACE("BL::JobTab::job_selected slot");
187   QStandardItem * item = _model->itemFromIndex(index);
188   QStandardItem * item_name = _model->item(item->row());
189   if (item)
190   {
191     BL::Job * job = _jobs_manager->getJob(item_name->text().toUtf8().constData());
192
193     reset("");
194
195     _job_name_label_value->setText(QString::fromUtf8(job->getName().c_str()));
196
197     if (job->getState() == BL::Job::CREATED)
198       _job_state_label_value->setText("Created");
199     else if (job->getState() == BL::Job::IN_PROCESS)
200       _job_state_label_value->setText("In Process");
201     else if (job->getState() == BL::Job::QUEUED)
202       _job_state_label_value->setText("Queued");
203     else if (job->getState() == BL::Job::RUNNING)
204       _job_state_label_value->setText("Running");
205     else if (job->getState() == BL::Job::PAUSED)
206       _job_state_label_value->setText("Paused");
207     else if (job->getState() == BL::Job::ERROR)
208       _job_state_label_value->setText("Error");
209     else if (job->getState() == BL::Job::FAILED)
210       _job_state_label_value->setText("Failed");
211     else if (job->getState() == BL::Job::NOT_CREATED)
212       _job_state_label_value->setText("Not Created");
213     else 
214       _job_state_label_value->setText("Finished");
215
216     _job_launcher_label_value->setText(QVariant(job->getSalomeLauncherId()).toString());
217     _job_jobfile_label_value->setText(QString::fromUtf8(job->getJobFile().c_str()));
218     _job_envfile_label_value->setText(QString::fromUtf8(job->getEnvFile().c_str()));
219     if (job->getType() == BL::Job::YACS_SCHEMA)
220       _job_type_label_value->setText("YACS_Schema");
221     else if (job->getType() == BL::Job::COMMAND)
222       _job_type_label_value->setText("Command");
223     else if (job->getType() == BL::Job::PYTHON_SALOME)
224       _job_type_label_value->setText("Python_Salome");
225
226     _job_resource_label_value->setText(QString::fromUtf8(job->getResource().c_str()));
227
228     BL::Job::BatchParam batch_params = job->getBatchParameters();
229
230     BL::Job::FilesParam files_params = job->getFilesParameters();
231     int nif = files_params.input_files_list.size();
232     _job_nif_label_value->setText(QVariant(nif).toString());
233     int nof = files_params.output_files_list.size();
234     _job_nof_label_value->setText(QVariant(nof).toString());
235     _job_bd_label_value->setText(QString::fromUtf8(batch_params.batch_directory.c_str()));
236     _job_rd_label_value->setText(QString::fromUtf8(files_params.result_directory.c_str()));
237
238     _job_mdt_label_value->setText(QString(batch_params.maximum_duration.c_str()));
239     _job_nop_label_value->setText(QVariant(batch_params.nb_proc).toString());
240     QString exclText = (batch_params.exclusive)? "yes" : "no";
241     _job_excl_label_value->setText(exclText);
242
243     // Memory requirement
244     unsigned long long mem_mb = batch_params.mem_limit;
245     ostringstream mem_ss;
246     if (mem_mb % 1024 == 0)
247       mem_ss << mem_mb / 1024 << "GB";
248     else
249       mem_ss << mem_mb << "MB";
250     switch (batch_params.mem_req_type)
251     {
252     case BL::Job::MEM_PER_NODE:
253       mem_ss << " per node";
254       break;
255     case BL::Job::MEM_PER_CPU:
256       mem_ss << " per core";
257       break;
258     default:
259       throw Exception("Unknown memory requirement, unable to show selected job");
260     }
261     _job_em_label_value->setText(QString(mem_ss.str().c_str()));
262
263     // Parameters for COORM
264     _job_lf_label_value->setText(QString::fromUtf8(batch_params.launcher_file.c_str()));
265     _job_la_label_value->setText(QString::fromUtf8(batch_params.launcher_args.c_str()));
266
267     _input_files_list->clear();
268     _output_files_list->clear();
269     std::list<std::string>::iterator it;
270     for (it = files_params.input_files_list.begin(); it != files_params.input_files_list.end(); it++)
271     {
272       std::string file = *it;
273       _input_files_list->addItem(QString::fromUtf8(file.c_str()));
274     }
275     for (it = files_params.output_files_list.begin(); it != files_params.output_files_list.end(); it++)
276     {
277       std::string file = *it;
278       _output_files_list->addItem(QString::fromUtf8(file.c_str()));
279     }
280
281     // Specific parameters management
282     if (job->getDumpYACSState() > 0)
283     {
284       // Add widget in the layout
285       _yacs_dump_state_value->setText(QVariant(job->getDumpYACSState()).toString());
286       _main_values_form->insertRow(7, _yacs_dump_state_label, _yacs_dump_state_value);
287     }
288     if (job->getBatchQueue() != "")
289     {
290       _batch_queue_value->setText(QVariant(job->getBatchQueue().c_str()).toString());
291       _other_run_values_form->insertRow(_other_run_values_form->rowCount(), _batch_queue_label, _batch_queue_value);
292     }
293     if (job->getLoadLevelerJobType() != "")
294     {
295       _ll_jobtype_value->setText(QVariant(job->getLoadLevelerJobType().c_str()).toString());
296       _other_run_values_form->insertRow(_other_run_values_form->rowCount(), _ll_jobtype_label, _ll_jobtype_value);
297     }
298   }
299   else
300     DEBTRACE ("itemFromIndex returns 0 !");
301 }
302
303 void 
304 BL::JobTab::itemChanged(QStandardItem * item)
305 {
306   DEBTRACE("BL::JobTab::itemChanged slot");
307
308   QStandardItem * item_name = _model->item(item->row());
309   BL::Job * job = _jobs_manager->getJob(item_name->text().toUtf8().constData());
310
311   if (_job_name_label_value->text() == QString::fromUtf8(job->getName().c_str()))
312   {
313     if (job->getState() == BL::Job::CREATED)
314       _job_state_label_value->setText("Created");
315     else if (job->getState() == BL::Job::IN_PROCESS)
316       _job_state_label_value->setText("In Process");
317     else if (job->getState() == BL::Job::QUEUED)
318       _job_state_label_value->setText("Queued");
319     else if (job->getState() == BL::Job::RUNNING)
320       _job_state_label_value->setText("Running");
321     else if (job->getState() == BL::Job::PAUSED)
322       _job_state_label_value->setText("Paused");
323     else if (job->getState() == BL::Job::ERROR)
324       _job_state_label_value->setText("Error");
325     else if (job->getState() == BL::Job::FAILED)
326       _job_state_label_value->setText("Failed");
327     else if (job->getState() == BL::Job::NOT_CREATED)
328       _job_state_label_value->setText("Not Created");
329     else 
330       _job_state_label_value->setText("Finished");
331   }
332 }
333
334 void
335 BL::JobTab::reset(QString job_name)
336 {
337   if (job_name == _job_name_label_value->text() || job_name == "")
338   {
339     _job_name_label_value->setText("");
340     _job_type_label_value->setText("");
341     _job_state_label_value->setText("");
342     _job_launcher_label_value->setText("");
343     _job_resource_label_value->setText("");
344     _job_nif_label_value->setText("");
345     _job_nof_label_value->setText("");
346     _job_bd_label_value->setText("");
347     _job_rd_label_value->setText("");
348     _job_mdt_label_value->setText("");
349     _job_em_label_value->setText("");
350     _job_nop_label_value->setText("");
351     _job_excl_label_value->setText("");
352     _job_jobfile_label_value->setText("");
353     _job_envfile_label_value->setText("");
354
355     _input_files_list->clear();
356     _output_files_list->clear();
357
358     _yacs_dump_state_value->setText("");
359     _batch_queue_value->setText("");
360     _ll_jobtype_value->setText("");
361
362         // Parameters for COORM
363     _job_lf_label_value->setText("");
364     _job_la_label_value->setText("");
365   }
366 }