1 // Copyright (C) 2009-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "BL_CreateJobWizard.hxx"
21 #include "BL_JobsManager_QT.hxx"
23 #include <QFileDialog>
24 #include <QMessageBox>
32 #include <sys/types.h>
36 #include <ui_ResourceRequirementsWizardPage.h>
37 #include <ui_FilesWizardPage.h>
38 #include <ui_AdvancedParametersWizardPage.h>
47 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
49 DEBTRACE("Creating BL::CreateJobWizard");
50 BL_ASSERT(jobs_manager);
51 BL_ASSERT(salome_services);
52 _jobs_manager = jobs_manager;
53 _salome_services = salome_services;
59 python_salome_file = "";
65 coorm_batch_directory = "";
67 maximum_duration = "";
69 mem_req_type = BL::Job::MEM_PER_NODE;
73 // Parameters for COORM
77 result_directory = "";
79 resource_choosed = "";
85 yacs_driver_options = "";
88 setOptions(QWizard::NoBackButtonOnStartPage);
91 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
92 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
94 setPage(Page_JobName, _job_name_page);
95 setPage(Page_BatchParameters, _batch_parameters_page);
98 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
100 setPage(Page_Files, new BL::FilesPage(this, salome_services));
101 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
102 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
103 setPage(Page_Conclusion, new BL::ConclusionPage(this));
106 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
107 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
108 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
110 setWindowTitle("Create Job Wizard");
111 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
114 BL::CreateJobWizard::~CreateJobWizard()
116 DEBTRACE("Destroying BL::CreateJobWizard");
120 BL::CreateJobWizard::clone(const std::string & name)
122 if (_jobs_manager->job_already_exist(name) == true)
124 BL::Job * job = _jobs_manager->getJob(name);
126 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
127 if (job->getState() == BL::Job::CREATED ||
128 job->getState() == BL::Job::ERROR ||
129 job->getState() == BL::Job::FAILED ||
130 job->getState() == BL::Job::NOT_CREATED)
132 setField("job_name", QString(name.c_str()));
133 _job_name_page->_check_name = false;
136 if (job->getType() == BL::Job::YACS_SCHEMA)
138 setField("yacs_file", QString(job->getJobFile().c_str()));
139 setField("job_type_yacs", true);
140 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
141 setField("pre_yacs_file", QString(job->getPreCommand().c_str()));
142 if (job->getDumpYACSState() != -1)
145 value.setNum(job->getDumpYACSState());
146 setField("dump_yacs_state", value);
148 if (!job->getYacsDriverOptions().empty())
150 setField("yacs_driver_options", job->getYacsDriverOptions().c_str());
153 else if (job->getType() == BL::Job::COMMAND)
155 setField("command", QString(job->getJobFile().c_str()));
156 setField("job_type_command", true);
157 setField("env_command_file", QString(job->getEnvFile().c_str()));
158 setField("pre_command_file", QString(job->getPreCommand().c_str()));
160 else if (job->getType() == BL::Job::COMMAND_SALOME)
162 setField("command", QString(job->getJobFile().c_str()));
163 setField("job_type_command_salome", true);
164 setField("env_command_file", QString(job->getEnvFile().c_str()));
165 setField("pre_command_file", QString(job->getPreCommand().c_str()));
167 else if (job->getType() == BL::Job::PYTHON_SALOME)
169 setField("PythonSalome", QString(job->getJobFile().c_str()));
170 setField("job_type_python_salome", true);
171 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
172 setField("pre_PythonSalome_file", QString(job->getPreCommand().c_str()));
177 BL::Job::BatchParam batch_params = job->getBatchParameters();
178 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
179 std::string batch = resource_descr.batch.c_str();
180 if (batch == "coorm")
182 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
183 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
184 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
188 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
192 proc_value.setNum(batch_params.nb_proc);
193 setField("proc_value", proc_value);
196 node_value.setNum(batch_params.nb_node);
197 setField("node_value", node_value);
199 setField("exclusive", batch_params.exclusive);
201 if (batch_params.maximum_duration == "")
203 setField("default_time", true);
204 setField("duration_hour", 0);
205 setField("duration_min", 0);
209 setField("user_time", true);
210 std::size_t pos = batch_params.maximum_duration.find(":");
211 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
213 std::istringstream iss_hour(hour_str);
215 setField("duration_hour", hour);
217 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
219 std::istringstream iss_min(min_str);
221 setField("duration_min", min);
224 long long mem_mb = batch_params.mem_limit;
227 setField("default_mem", true);
231 setField("user_mem", true);
232 if (mem_mb % 1024 == 0)
234 setField("mem_value", mem_mb / 1024);
235 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
239 setField("mem_value", mem_mb);
240 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
242 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
245 BL::Job::FilesParam files_params = job->getFilesParameters();
247 std::list<std::string>::iterator it = files_params.input_files_list.begin();
248 for (; it != files_params.input_files_list.end(); it++)
249 _input_files_list->addItem(QString((*it).c_str()));
250 it = files_params.output_files_list.begin();
251 for (; it != files_params.output_files_list.end(); it++)
252 _output_files_list->addItem(QString((*it).c_str()));
254 setField("result_directory", QString(files_params.result_directory.c_str()));
255 setField("resource_choosed", QString(job->getResource().c_str()));
256 setField("batch_queue", QString(job->getBatchQueue().c_str()));
257 setField("batch_partition", QString(job->getBatchPartition().c_str()));
258 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
259 setField("wckey", QString(job->getWCKey().c_str()));
260 setField("extra_params", QString(job->getExtraParams().c_str()));
265 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
267 _input_files_list = input_files_list;
268 _output_files_list = output_files_list;
272 BL::CreateJobWizard::end(int result)
274 DEBTRACE("End of BL::CreateJobWizard");
278 QString f_job_name = field("job_name").toString();
279 job_name = f_job_name.trimmed().toUtf8().constData();
280 if (field("job_type_yacs").toBool())
282 else if (field("job_type_command").toBool())
284 else if (field("job_type_command_salome").toBool())
285 job_type = COMMAND_SALOME;
287 job_type = PYTHON_SALOME;
290 QString f_yacs_file = field("yacs_file").toString();
291 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
292 dump_yacs_state = field("dump_yacs_state").toInt();
293 yacs_driver_options = field("yacs_driver_options").toString().trimmed().toUtf8().constData();
296 QString f_command = field("command").toString();
297 command = f_command.trimmed().toUtf8().constData();
300 QString f_python_salome_file = field("PythonSalome").toString();
301 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
304 if (job_type == YACS)
305 f_env_file = field("env_yacs_file").toString();
306 else if (job_type == COMMAND || job_type == COMMAND_SALOME)
307 f_env_file = field("env_command_file").toString();
308 else if (job_type == PYTHON_SALOME)
309 f_env_file = field("env_PythonSalome_file").toString();
310 env_file = f_env_file.trimmed().toUtf8().constData();
312 QString f_pre_command_file;
313 if (job_type == YACS)
314 f_pre_command_file = field("pre_yacs_file").toString();
315 else if (job_type == COMMAND || job_type == COMMAND_SALOME)
316 f_pre_command_file = field("pre_command_file").toString();
317 else if (job_type == PYTHON_SALOME)
318 f_pre_command_file = field("pre_PythonSalome_file").toString();
319 pre_command = f_pre_command_file.trimmed().toUtf8().constData();
322 QString f_batch_directory = field("batch_directory").toString();
323 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
326 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
327 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
330 QString f_launcher_file = field("launcher_file").toString();
331 launcher_file = f_launcher_file.toUtf8().constData();
332 QString f_launcher_args = field("launcher_args").toString();
333 launcher_args = f_launcher_args.toUtf8().constData();
337 if (field("default_time").toBool() ||
338 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
340 maximum_duration = "";
344 if (field("duration_hour").toInt() < 10)
345 time_hour = "0" + field("duration_hour").toString().trimmed();
347 time_hour = field("duration_hour").toString().trimmed();
348 if (field("duration_min").toInt() < 10)
349 time_min = "0" + field("duration_min").toString().trimmed();
351 time_min = field("duration_min").toString().trimmed();
352 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
355 if(field("default_mem").toBool())
361 unsigned long mem = field("mem_value").toULongLong();
362 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
365 case BatchParametersPage::MB:
368 case BatchParametersPage::GB:
369 mem_limit = mem * 1024;
372 throw Exception("Invalid memory unit");
374 mem_req_type = _batch_parameters_page->getMemReqType();
377 nb_proc = field("proc_value").toInt();
378 nb_node = field("node_value").toInt();
379 exclusive = field("exclusive").toBool();
382 QString f_result_directory = field("result_directory").toString();
383 result_directory = f_result_directory.trimmed().toUtf8().constData();
384 for (int i = 0; i < _input_files_list->count(); ++i)
386 QListWidgetItem * item = _input_files_list->item(i);
387 QString item_text = item->text();
388 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
390 for (int i = 0; i < _output_files_list->count(); ++i)
392 QListWidgetItem * item = _output_files_list->item(i);
393 QString item_text = item->text();
394 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
398 QString f_resource_choosed = field("resource_choosed").toString();
399 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
402 QString f_batch_queue = field("batch_queue").toString();
403 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
406 QString f_batch_partition = field("batch_partition").toString();
407 batch_partition = f_batch_partition.trimmed().toUtf8().constData();
409 // LoadLeveler JobType
410 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
411 std::string batch = resource_descr.batch.c_str();
414 QString f_ll_jobtype = field("ll_jobtype").toString();
415 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
423 QString f_wckey = field("wckey").toString();
424 wckey = f_wckey.trimmed().toUtf8().constData();
427 QString f_extra_params = field("extra_params").toString();
428 extra_params = f_extra_params.trimmed().toUtf8().constData();
430 start_job = field("start_job").toBool();
435 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
436 : QWizardPage(parent)
438 _jobs_manager = jobs_manager;
440 setTitle("Create a new job");
442 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
443 label->setWordWrap(true);
444 QLabel * nameLabel = new QLabel("Job Name:");
445 QLineEdit * _nameLineEdit = new QLineEdit(this);
446 registerField("job_name", _nameLineEdit);
448 QLabel * label_type = new QLabel("Choose type of batch job:");
449 QGroupBox *groupBox = new QGroupBox("Type of job");
450 QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
451 _yacs_schema_button->setChecked(true);
452 QRadioButton * _command_button = new QRadioButton(tr("Command"));
453 QRadioButton * _command_salome_button = new QRadioButton(tr("Command in salome shell"));
454 QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
455 QVBoxLayout *vbox = new QVBoxLayout;
456 vbox->addWidget(_yacs_schema_button);
457 vbox->addWidget(_command_button);
458 vbox->addWidget(_command_salome_button);
459 vbox->addWidget(_python_salome_button);
461 groupBox->setLayout(vbox);
462 registerField("job_type_yacs", _yacs_schema_button);
463 registerField("job_type_command", _command_button);
464 registerField("job_type_command_salome", _command_salome_button);
465 registerField("job_type_python_salome", _python_salome_button);
467 QGroupBox * explanationBox = new QGroupBox("Explanation");
468 QVBoxLayout *explanationvbox = new QVBoxLayout;
469 _explanation = new QLabel();
470 _explanation->setWordWrap(true);
471 explanationvbox->addWidget(_explanation);
472 explanationvbox->addStretch(1);
473 explanationBox->setLayout(explanationvbox);
476 QVBoxLayout * main_layout = new QVBoxLayout;
477 main_layout->addWidget(label);
478 QGridLayout *layout = new QGridLayout;
479 layout->addWidget(nameLabel, 0, 0);
480 layout->addWidget(_nameLineEdit, 0, 1);
481 main_layout->insertLayout(-1, layout);
482 layout->addWidget(label_type, 2, 0);
483 layout->addWidget(groupBox, 3, 0, 1, -1);
484 layout->addWidget(explanationBox, 4, 0, 1, -1);
485 setLayout(main_layout);
487 connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
488 connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
489 connect(_command_salome_button, SIGNAL(toggled(bool)), this, SLOT(command_salome_button(bool)));
490 connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
493 yacs_schema_button(true);
496 BL::JobNamePage::~JobNamePage()
500 BL::JobNamePage::yacs_schema_button(bool checked)
504 _explanation->setText("Launch a YACS schema.");
505 setField("exclusive", true);
510 BL::JobNamePage::command_button(bool checked)
514 _explanation->setText("Launch a script on a remote resource without using "
515 "SALOME environment.");
516 setField("exclusive", false);
521 BL::JobNamePage::command_salome_button(bool checked)
525 _explanation->setText("Launch a script on a remote resource within SALOME "
526 "environment but whitout the SALOME application.");
527 setField("exclusive", false);
532 BL::JobNamePage::python_salome_button(bool checked)
536 _explanation->setText("Launch a python script into a SALOME application.");
537 setField("exclusive", true);
542 BL::JobNamePage::validatePage()
544 DEBTRACE("Calling validatePage of BL::JobNamePage");
546 QString job_name = field("job_name").toString();
548 // Check if job name is empty
551 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
552 return_value = false;
555 // Check if job name already exists
557 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
563 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
565 setField("job_name", value);
566 return_value = false;
574 BL::JobNamePage::nextId() const
576 if (field("job_type_yacs").toBool())
578 return BL::CreateJobWizard::Page_YACSSchema;
580 else if (field("job_type_command").toBool() ||
581 field("job_type_command_salome").toBool())
583 return BL::CreateJobWizard::Page_Command_Main_Definitions;
587 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
591 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
592 : QWizardPage(parent)
594 setTitle("Configure YACS Execution");
596 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
597 label->setWordWrap(true);
599 QGroupBox * files_param_box = new QGroupBox("YACS job files");
600 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
601 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
602 _yacs_file_text = new QLineEdit(this);
603 _yacs_file_text->setText("");
604 registerField("yacs_file", _yacs_file_text);
605 _yacs_file_text->setReadOnly(true);
606 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
607 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
608 _line_env_file = new QLineEdit(this);
609 registerField("env_yacs_file", _line_env_file);
610 _line_env_file->setReadOnly(true);
611 QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
612 connect(command_pre_command_button, SIGNAL(clicked()),
613 this, SLOT(choose_pre_command_file()));
614 _line_pre_command = new QLineEdit(this);
615 registerField("pre_yacs_file", _line_pre_command);
616 _line_pre_command->setReadOnly(true);
617 QGridLayout * files_layout = new QGridLayout;
618 files_layout->addWidget(yacs_file_button, 0, 0);
619 files_layout->addWidget(_yacs_file_text, 0, 1);
620 files_layout->addWidget(command_env_file_button, 1, 0);
621 files_layout->addWidget(_line_env_file, 1, 1);
622 files_layout->addWidget(command_pre_command_button, 2, 0);
623 files_layout->addWidget(_line_pre_command, 2, 1);
624 files_param_box->setLayout(files_layout);
626 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
627 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
628 QLabel * label_driver_options = new QLabel("YACS driver options - see YACS driver documentation.");
629 QSpinBox * spin_dump = new QSpinBox(this);
630 spin_dump->setMinimum(0);
631 spin_dump->setMaximum(1000000);
632 registerField("dump_yacs_state", spin_dump);
633 QLineEdit* edit_yacs_driver_options = new QLineEdit(this);
634 registerField("yacs_driver_options", edit_yacs_driver_options);
635 QGridLayout * specific_layout = new QGridLayout;
636 specific_layout->addWidget(label_dump, 0, 0);
637 specific_layout->addWidget(spin_dump, 0, 1);
638 specific_layout->addWidget(label_driver_options, 1, 0);
639 specific_layout->addWidget(edit_yacs_driver_options, 1, 1);
640 spec_param_box->setLayout(specific_layout);
642 QVBoxLayout * main_layout = new QVBoxLayout;
643 main_layout->addWidget(label);
644 main_layout->addWidget(files_param_box);
645 main_layout->addWidget(spec_param_box);
647 setLayout(main_layout);
650 BL::YACSSchemaPage::~YACSSchemaPage()
654 BL::YACSSchemaPage::validatePage()
657 QString yacs_file = field("yacs_file").toString();
664 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
665 return_value = false;
671 BL::YACSSchemaPage::choose_file()
673 QString yacs_file = QFileDialog::getOpenFileName(this,
674 tr("Open YACS files"), "",
675 tr("XML (*.xml);;All Files (*)"));
676 _yacs_file_text->setReadOnly(false);
677 _yacs_file_text->setText(yacs_file);
678 _yacs_file_text->setReadOnly(true);
682 BL::YACSSchemaPage::choose_env_file()
684 QString env_file = QFileDialog::getOpenFileName(this,
685 tr("Open environnement file"), "",
686 tr("sh (*.sh);;All Files (*)"));
687 _line_env_file->setReadOnly(false);
688 _line_env_file->setText(env_file);
689 _line_env_file->setReadOnly(true);
693 BL::YACSSchemaPage::choose_pre_command_file()
695 QString pre_command_file = QFileDialog::getOpenFileName(this,
696 tr("Open script file"), "",
697 tr("All Files (*)"));
698 _line_pre_command->setReadOnly(false);
699 _line_pre_command->setText(pre_command_file);
700 _line_pre_command->setReadOnly(true);
704 BL::YACSSchemaPage::nextId() const
706 return BL::CreateJobWizard::Page_Resource;
709 BL::CommandMainPage::CommandMainPage(QWidget * parent)
710 : QWizardPage(parent)
712 setTitle("Define command job");
713 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
714 label->setWordWrap(true);
717 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
718 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
719 _line_command = new QLineEdit(this);
720 registerField("command", _line_command);
721 _line_command->setReadOnly(true);
723 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
724 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
725 _line_env_file = new QLineEdit(this);
726 registerField("env_command_file", _line_env_file);
727 _line_env_file->setReadOnly(true);
729 QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
730 connect(command_pre_command_button, SIGNAL(clicked()),
731 this, SLOT(choose_pre_command_file()));
732 _line_pre_command = new QLineEdit(this);
733 registerField("pre_command_file", _line_pre_command);
734 _line_pre_command->setReadOnly(true);
736 QGridLayout *layout = new QGridLayout;
737 layout->addWidget(command_file_button, 0, 0);
738 layout->addWidget(_line_command, 0, 1);
739 layout->addWidget(command_env_file_button, 1, 0);
740 layout->addWidget(_line_env_file, 1, 1);
741 layout->addWidget(command_pre_command_button, 2, 0);
742 layout->addWidget(_line_pre_command, 2, 1);
744 QVBoxLayout * main_layout = new QVBoxLayout;
745 main_layout->addWidget(label);
746 main_layout->insertLayout(-1, layout);
747 setLayout(main_layout);
750 BL::CommandMainPage::~CommandMainPage()
754 BL::CommandMainPage::choose_command_file()
756 QString command_file = QFileDialog::getOpenFileName(this,
757 tr("Open command file"), "",
758 tr("sh (*.sh);;All Files (*)"));
759 _line_command->setReadOnly(false);
760 _line_command->setText(command_file);
761 _line_command->setReadOnly(true);
765 BL::CommandMainPage::choose_env_file()
767 QString env_file = QFileDialog::getOpenFileName(this,
768 tr("Open environnement file"), "",
769 tr("sh (*.sh);;All Files (*)"));
770 _line_env_file->setReadOnly(false);
771 _line_env_file->setText(env_file);
772 _line_env_file->setReadOnly(true);
776 BL::CommandMainPage::choose_pre_command_file()
778 QString pre_command_file = QFileDialog::getOpenFileName(this,
779 tr("Open script file"), "",
780 tr("All Files (*)"));
781 _line_pre_command->setReadOnly(false);
782 _line_pre_command->setText(pre_command_file);
783 _line_pre_command->setReadOnly(true);
787 BL::CommandMainPage::validatePage()
789 QString command = field("command").toString();
792 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
800 BL::CommandMainPage::nextId() const
802 return BL::CreateJobWizard::Page_Resource;
805 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
806 : QWizardPage(parent),
807 ui(new Ui::ResourceRequirementsWizardPage),
808 _salome_services(salome_services),
813 registerField("duration_hour", ui->spin_duration_hour);
814 registerField("duration_min", ui->spin_duration_min);
815 registerField("mem_value", ui->spin_memory);
816 registerField("proc_value", ui->spin_proc);
817 registerField("node_value", ui->spin_node);
818 registerField("exclusive", ui->check_exclusive);
819 registerField("default_time", ui->rb_default_time);
820 registerField("user_time", ui->rb_user_time);
821 registerField("default_mem", ui->rb_default_mem);
822 registerField("user_mem", ui->rb_user_mem);
824 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
825 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
828 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
829 "per node", Job::MEM_PER_NODE);
830 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
831 "per core", Job::MEM_PER_CPU);
833 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
834 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
835 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
836 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
837 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
840 BatchParametersPage::~BatchParametersPage()
846 BatchParametersPage::initializePage()
848 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
849 if (f_resource_choosed != resource_choosed)
851 resource_choosed = f_resource_choosed;
852 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
853 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
854 if (resource_descr.batch == "slurm")
856 ui->combo_memory_req_type->setEnabled(true);
860 ui->combo_memory_req_type->setEnabled(false);
861 setMemReqType(Job::MEM_PER_NODE);
866 BatchParametersPage::MemUnit
867 BatchParametersPage::getMemUnit() const
869 int idx = ui->combo_memory_unit->currentIndex();
870 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
874 BatchParametersPage::setMemUnit(MemUnit mem_unit)
876 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
880 BatchParametersPage::getMemReqType() const
882 int idx = ui->combo_memory_req_type->currentIndex();
883 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
887 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
889 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
893 BatchParametersPage::timeChanged()
895 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
896 ui->rb_default_time->setChecked(true);
898 ui->rb_user_time->setChecked(true);
902 BatchParametersPage::memChanged()
904 ui->rb_user_mem->setChecked(true);
908 BatchParametersPage::cleanupPage()
913 BatchParametersPage::nextId() const
915 return CreateJobWizard::Page_Files;
918 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
919 : QWizardPage(parent)
921 setTitle("Enter COORM Parameters");
922 resource_choosed = "";
924 _salome_services = salome_services;
926 QLabel *label = new QLabel("In this step you define the parameters for COORM");
927 label->setWordWrap(true);
928 QVBoxLayout * main_layout = new QVBoxLayout;
929 main_layout->addWidget(label);
931 // coorm_batch_directory
932 QLabel * label_directory = new QLabel("Remote work directory: ");
933 QLineEdit * line_directory = new QLineEdit(this);
934 registerField("coorm_batch_directory", line_directory);
937 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
938 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
939 _launcher_file_text = new QLineEdit(this);
940 _launcher_file_text->setText("");
941 registerField("launcher_file", _launcher_file_text);
942 _launcher_file_text->setReadOnly(true);
945 QLabel * launcher_args_label = new QLabel("Launcher args:");
946 QLineEdit * launcher_args_text = new QLineEdit(this);
947 registerField("launcher_args", launcher_args_text);
949 QGridLayout * layout = new QGridLayout;
950 layout->addWidget(label_directory, 0, 0);
951 layout->addWidget(line_directory, 0, 1);
952 layout->addWidget(launcher_file_button, 1, 0);
953 layout->addWidget(_launcher_file_text, 1, 1);
954 layout->addWidget(launcher_args_label, 2, 0);
955 layout->addWidget(launcher_args_text, 2, 1);
957 main_layout->insertLayout(-1, layout);
959 setLayout(main_layout);
962 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
966 BL::COORM_BatchParametersPage::validatePage()
968 QString coorm_batch_directory = field("coorm_batch_directory").toString();
969 if (coorm_batch_directory == "")
971 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
975 QString launcher_file = field("launcher_file").toString();
976 if (launcher_file == "")
978 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
986 BL::COORM_BatchParametersPage::nextId() const
988 return BL::CreateJobWizard::Page_Files;
992 BL::COORM_BatchParametersPage::choose_launcher_file()
994 QString launcher_file = QFileDialog::getOpenFileName(this,
995 tr("Open launcher files"), "",
996 tr("Py (*.py);;All Files (*)"));
997 _launcher_file_text->setReadOnly(false);
998 _launcher_file_text->setText(launcher_file);
999 _launcher_file_text->setReadOnly(true);
1002 void BL::COORM_BatchParametersPage::cleanupPage()
1006 BL::COORM_BatchParametersPage::initializePage()
1008 QString f_resource_choosed = field("resource_choosed").toString();
1009 if (f_resource_choosed != resource_choosed)
1011 resource_choosed = f_resource_choosed;
1012 // If choosed resource has a working_directory set
1013 // Generates a default remote working directory
1014 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1015 QString res_work_dir = resource_descr.working_directory.c_str();
1016 if (res_work_dir != "")
1020 std::string launch_date = ctime(&rawtime);
1021 for (int i = 0; i < launch_date.size(); i++)
1022 if (launch_date[i] == '/' ||
1023 launch_date[i] == '-' ||
1024 launch_date[i] == ':' ||
1025 launch_date[i] == ' ')
1026 launch_date[i] = '_';
1027 launch_date.erase(--launch_date.end()); // Last caracter is a \n
1028 QString date = launch_date.c_str();
1029 setField("coorm_batch_directory", res_work_dir + "/" + date);
1034 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
1035 : QWizardPage(parent),
1036 ui(new Ui::FilesWizardPage)
1040 resource_choosed = "";
1041 _salome_services = salome_services;
1043 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
1044 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
1045 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
1046 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
1047 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
1048 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
1049 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
1051 registerField("batch_directory", ui->line_remote_working_dir);
1052 registerField("result_directory", ui->line_result_dir);
1054 // Default result directory is home directory (if we found it)
1055 ui->line_result_dir->setText(QDir::homePath());
1057 parent->setFilesList(ui->input_files_list, ui->output_files_list);
1059 // Check for warning messages
1060 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
1061 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1062 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
1065 FilesPage::~FilesPage()
1071 FilesPage::initializePage()
1073 QString f_resource_choosed = field("resource_choosed").toString();
1074 if (f_resource_choosed != resource_choosed)
1076 resource_choosed = f_resource_choosed;
1077 // If choosed resource has a working_directory set
1078 // Generates a default remote working directory
1079 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1080 QString res_work_dir = resource_descr.working_directory.c_str();
1081 if (res_work_dir != "")
1085 std::string launch_date = ctime(&rawtime);
1086 for (int i = 0; i < launch_date.size(); i++)
1087 if (launch_date[i] == '/' ||
1088 launch_date[i] == '-' ||
1089 launch_date[i] == ':' ||
1090 launch_date[i] == ' ')
1091 launch_date[i] = '_';
1092 launch_date.erase(--launch_date.end()); // Last caracter is a \n
1093 QString date = launch_date.c_str();
1094 setField("batch_directory", res_work_dir + "/" + date);
1100 FilesPage::isComplete() const
1103 if (field("batch_directory").toString().isEmpty())
1104 warn_msg = "Remote working directory is mandatory.";
1105 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1107 if (!warn_msg.isEmpty()) warn_msg += "\n";
1108 warn_msg += "Result directory is mandatory if there are output files.";
1111 ui->label_warning_text->setText(warn_msg);
1112 if (warn_msg.isEmpty())
1114 ui->label_warning_icon->hide();
1119 ui->label_warning_icon->show();
1125 FilesPage::choose_input_files()
1127 // We need to be able to select both files and folders.
1128 // Standard QFileDialog cannot do it.
1129 QFileDialog w(this, tr("Select input files"),
1130 "", tr("All files and folders(*)")) ;
1131 w.setOption(QFileDialog::DontUseNativeDialog,true);
1132 QListView *l = w.findChild<QListView*>("listView");
1135 l->setSelectionMode(QAbstractItemView::MultiSelection);
1137 QTreeView *t = w.findChild<QTreeView*>();
1140 t->setSelectionMode(QAbstractItemView::MultiSelection);
1144 QStringList files = w.selectedFiles();
1145 for (int i = 0; i < files.size(); ++i)
1147 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1148 ui->input_files_list->addItem(files.at(i));
1154 FilesPage::choose_local_directory()
1156 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1158 QFileDialog::ShowDirsOnly
1159 | QFileDialog::DontResolveSymlinks);
1162 ui->line_result_dir->setText(dir);
1166 FilesPage::remove_input_files()
1168 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1169 for (int i = 0; i < list.size(); ++i)
1171 int row = ui->input_files_list->row( list.at(i) );
1172 delete ui->input_files_list->takeItem(row);
1177 FilesPage::input_itemSelectionChanged()
1179 if (ui->input_files_list->selectedItems().size() > 0)
1180 ui->remove_input_files_button->setEnabled(true);
1182 ui->remove_input_files_button->setEnabled(false);
1186 FilesPage::add_output_file()
1188 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1189 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1190 ui->output_files_list->addItem(new_item);
1191 emit completeChanged();
1195 FilesPage::remove_output_files()
1197 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1198 for (int i = 0; i < list.size(); ++i)
1200 int row = ui->output_files_list->row( list.at(i) );
1201 delete ui->output_files_list->takeItem(row);
1203 emit completeChanged();
1207 FilesPage::output_itemSelectionChanged()
1209 if (ui->output_files_list->selectedItems().size() > 0)
1210 ui->remove_output_files_button->setEnabled(true);
1212 ui->remove_output_files_button->setEnabled(false);
1216 FilesPage::nextId() const
1218 return BL::CreateJobWizard::Page_Advanced;
1221 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1222 : QWizardPage(parent)
1224 setTitle("Job definition is finished");
1225 QCheckBox * check_box = new QCheckBox("Start job after creation");
1226 registerField("start_job", check_box);
1227 QVBoxLayout * main_layout = new QVBoxLayout;
1228 main_layout->addWidget(check_box);
1229 setLayout(main_layout);
1232 BL::ConclusionPage::~ConclusionPage()
1236 BL::ConclusionPage::validatePage()
1242 BL::ConclusionPage::nextId() const
1247 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1248 : QWizardPage(parent)
1250 _salome_services = salome_services;
1251 setTitle("Select a Resource");
1253 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1254 main_label->setWordWrap(true);
1257 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1258 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1259 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1261 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1262 resource_list_layout->addWidget(_resource_list);
1263 resource_group_box->setLayout(resource_list_layout);
1265 QLabel * resource_label = new QLabel("Resource selected: ");
1266 _resource_choosed = new QLineEdit();
1267 _resource_choosed->setText("");
1268 _resource_choosed->setReadOnly(true);
1269 registerField("resource_choosed", _resource_choosed);
1271 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1272 QLineEdit * _bqLineEdit = new QLineEdit(this);
1273 registerField("batch_queue", _bqLineEdit);
1275 QLabel * bpLabel = new QLabel("Batch Partition (could be optional):");
1276 QLineEdit * _bpLineEdit = new QLineEdit(this);
1277 registerField("batch_partition", _bpLineEdit);
1279 _ll_label = new QLabel("LoadLeveler JobType:", this);
1280 _ll_value = new QLineEdit(this);
1281 registerField("ll_jobtype", _ll_value);
1285 _main_layout = new QGridLayout;
1286 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1287 _main_layout->addWidget(resource_label, 1, 0);
1288 _main_layout->addWidget(_resource_choosed, 1, 1);
1289 _main_layout->addWidget(bqLabel, 2, 0);
1290 _main_layout->addWidget(_bqLineEdit, 2, 1);
1291 _main_layout->addWidget(bpLabel, 3, 0);
1292 _main_layout->addWidget(_bpLineEdit, 3, 1);
1293 setLayout(_main_layout);
1297 BL::ResourcePage::~ResourcePage()
1301 BL::ResourcePage::initializePage()
1303 if (field("ll_jobtype").toString() != "")
1305 _main_layout->addWidget(_ll_label, 3, 0);
1306 _main_layout->addWidget(_ll_value, 3, 1);
1311 // Initialize resource_choosed with first resource in resource list
1312 if (field("resource_choosed").toString() == "")
1314 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1315 std::list<std::string>::iterator it = resource_list.begin();
1316 if (it != resource_list.end())
1318 QString first_resource((*it).c_str());
1319 setField("resource_choosed", first_resource);
1325 BL::ResourcePage::validatePage()
1327 QString resource_choosed = field("resource_choosed").toString();
1328 if (resource_choosed == "")
1330 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1334 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1335 std::string batch = resource_descr.batch.c_str();
1338 QString ll_jobtype = field("ll_jobtype").toString();
1339 if (ll_jobtype == "")
1341 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1349 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1351 _resource_choosed->setReadOnly(false);
1352 _resource_choosed->setText(item->text());
1353 _resource_choosed->setReadOnly(true);
1355 //Specific parameters for LoadLeveler
1356 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1357 std::string batch = resource_descr.batch.c_str();
1360 _main_layout->addWidget(_ll_label, 3, 0);
1361 _main_layout->addWidget(_ll_value, 3, 1);
1367 _main_layout->removeWidget(_ll_value);
1368 _main_layout->removeWidget(_ll_label);
1375 BL::ResourcePage::nextId() const
1377 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1378 std::string batch = resource_descr.batch.c_str();
1379 if (batch == "coorm")
1381 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1385 return BL::CreateJobWizard::Page_BatchParameters;
1389 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1390 : QWizardPage(parent)
1392 setTitle("Define a Python script in SALOME job");
1393 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1394 label->setWordWrap(true);
1397 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1398 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1399 _line_PythonSalome = new QLineEdit(this);
1400 registerField("PythonSalome", _line_PythonSalome);
1401 _line_PythonSalome->setReadOnly(true);
1403 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1404 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1405 _line_env_file = new QLineEdit(this);
1406 registerField("env_PythonSalome_file", _line_env_file);
1407 _line_env_file->setReadOnly(true);
1409 QPushButton * command_pre_command_button = new QPushButton(tr("Choose a pre processing script"));
1410 connect(command_pre_command_button, SIGNAL(clicked()),
1411 this, SLOT(choose_pre_command_file()));
1412 _line_pre_command = new QLineEdit(this);
1413 registerField("pre_PythonSalome_file", _line_pre_command);
1414 _line_pre_command->setReadOnly(true);
1416 QGridLayout *layout = new QGridLayout;
1417 layout->addWidget(PythonSalome_file_button, 0, 0);
1418 layout->addWidget(_line_PythonSalome, 0, 1);
1419 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1420 layout->addWidget(_line_env_file, 1, 1);
1421 layout->addWidget(command_pre_command_button, 2, 0);
1422 layout->addWidget(_line_pre_command, 2, 1);
1424 QVBoxLayout * main_layout = new QVBoxLayout;
1425 main_layout->addWidget(label);
1426 main_layout->insertLayout(-1, layout);
1427 setLayout(main_layout);
1430 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1434 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1436 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1437 tr("Open Python script file"), "",
1438 tr("py (*.py);;All Files (*)"));
1439 _line_PythonSalome->setReadOnly(false);
1440 _line_PythonSalome->setText(PythonSalome_file);
1441 _line_PythonSalome->setReadOnly(true);
1445 BL::PythonSalomeMainPage::choose_env_file()
1447 QString env_file = QFileDialog::getOpenFileName(this,
1448 tr("Open environnement file"), "",
1449 tr("sh (*.sh);;All Files (*)"));
1450 _line_env_file->setReadOnly(false);
1451 _line_env_file->setText(env_file);
1452 _line_env_file->setReadOnly(true);
1456 BL::PythonSalomeMainPage::choose_pre_command_file()
1458 QString pre_command_file = QFileDialog::getOpenFileName(this,
1459 tr("Open script file"), "",
1460 tr("All Files (*)"));
1461 _line_pre_command->setReadOnly(false);
1462 _line_pre_command->setText(pre_command_file);
1463 _line_pre_command->setReadOnly(true);
1467 BL::PythonSalomeMainPage::validatePage()
1469 QString PythonSalome = field("PythonSalome").toString();
1470 if (PythonSalome == "")
1472 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1480 BL::PythonSalomeMainPage::nextId() const
1482 return BL::CreateJobWizard::Page_Resource;
1487 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1488 : QWizardPage(parent),
1489 ui(new Ui::AdvancedParametersWizardPage)
1492 registerField("wckey", ui->line_wckey);
1493 registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1496 AdvancedParametersPage::~AdvancedParametersPage()
1502 AdvancedParametersPage::nextId() const
1504 return BL::CreateJobWizard::Page_Conclusion;