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