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