1 // Copyright (C) 2009-2014 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"
26 #include <sys/types.h>
30 #include <ui_ResourceRequirementsWizardPage.h>
31 #include <ui_FilesWizardPage.h>
32 #include <ui_AdvancedParametersWizardPage.h>
41 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
43 DEBTRACE("Creating BL::CreateJobWizard");
44 BL_ASSERT(jobs_manager);
45 BL_ASSERT(salome_services);
46 _jobs_manager = jobs_manager;
47 _salome_services = salome_services;
52 python_salome_file = "";
57 coorm_batch_directory = "";
59 maximum_duration = "";
61 mem_req_type = BL::Job::MEM_PER_NODE;
64 // Parameters for COORM
68 result_directory = "";
70 resource_choosed = "";
77 setOptions(QWizard::NoBackButtonOnStartPage);
80 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
81 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
83 setPage(Page_JobName, _job_name_page);
84 setPage(Page_BatchParameters, _batch_parameters_page);
87 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
89 setPage(Page_Files, new BL::FilesPage(this, salome_services));
90 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
91 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
92 setPage(Page_Conclusion, new BL::ConclusionPage(this));
95 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
96 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
97 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
99 setWindowTitle("Create Job Wizard");
100 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
103 BL::CreateJobWizard::~CreateJobWizard()
105 DEBTRACE("Destroying BL::CreateJobWizard");
109 BL::CreateJobWizard::clone(const std::string & name)
111 if (_jobs_manager->job_already_exist(name) == true)
113 BL::Job * job = _jobs_manager->getJob(name);
115 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
116 if (job->getState() == BL::Job::CREATED ||
117 job->getState() == BL::Job::ERROR ||
118 job->getState() == BL::Job::FAILED ||
119 job->getState() == BL::Job::NOT_CREATED)
121 setField("job_name", QString(name.c_str()));
122 _job_name_page->_check_name = false;
125 if (job->getType() == BL::Job::YACS_SCHEMA)
127 setField("yacs_file", QString(job->getJobFile().c_str()));
128 _job_name_page->_yacs_schema_button->click();
129 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
130 if (job->getDumpYACSState() != -1)
133 value.setNum(job->getDumpYACSState());
134 setField("dump_yacs_state", value);
137 else if (job->getType() == BL::Job::COMMAND)
139 setField("command", QString(job->getJobFile().c_str()));
140 _job_name_page->_command_button->click();
141 setField("env_command_file", QString(job->getEnvFile().c_str()));
143 else if (job->getType() == BL::Job::PYTHON_SALOME)
145 setField("PythonSalome", QString(job->getJobFile().c_str()));
146 _job_name_page->_python_salome_button->click();
147 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
152 BL::Job::BatchParam batch_params = job->getBatchParameters();
153 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
154 std::string batch = resource_descr.batch.c_str();
155 if (batch == "coorm")
157 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
158 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
159 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
163 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
167 proc_value.setNum(batch_params.nb_proc);
168 setField("proc_value", proc_value);
170 setField("exclusive", batch_params.exclusive);
172 if (batch_params.maximum_duration == "")
174 setField("duration_hour", 0);
175 setField("duration_min", 0);
179 std::size_t pos = batch_params.maximum_duration.find(":");
180 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
182 std::istringstream iss_hour(hour_str);
184 setField("duration_hour", hour);
186 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
188 std::istringstream iss_min(min_str);
190 setField("duration_min", min);
193 unsigned long long mem_mb = batch_params.mem_limit;
194 if (mem_mb % 1024 == 0)
196 setField("mem_value", mem_mb / 1024);
197 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
201 setField("mem_value", mem_mb);
202 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
204 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
206 BL::Job::FilesParam files_params = job->getFilesParameters();
208 std::list<std::string>::iterator it = files_params.input_files_list.begin();
209 for (; it != files_params.input_files_list.end(); it++)
210 _input_files_list->addItem(QString((*it).c_str()));
211 it = files_params.output_files_list.begin();
212 for (; it != files_params.output_files_list.end(); it++)
213 _output_files_list->addItem(QString((*it).c_str()));
215 setField("result_directory", QString(files_params.result_directory.c_str()));
216 setField("resource_choosed", QString(job->getResource().c_str()));
217 setField("batch_queue", QString(job->getBatchQueue().c_str()));
218 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
219 setField("wckey", QString(job->getWCKey().c_str()));
224 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
226 _input_files_list = input_files_list;
227 _output_files_list = output_files_list;
231 BL::CreateJobWizard::end(int result)
233 DEBTRACE("End of BL::CreateJobWizard");
237 QString f_job_name = field("job_name").toString();
238 job_name = f_job_name.trimmed().toUtf8().constData();
241 QString f_yacs_file = field("yacs_file").toString();
242 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
243 dump_yacs_state = field("dump_yacs_state").toInt();
246 QString f_command = field("command").toString();
247 command = f_command.trimmed().toUtf8().constData();
250 QString f_python_salome_file = field("PythonSalome").toString();
251 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
255 f_env_file = field("env_yacs_file").toString();
256 else if (command != "")
257 f_env_file = field("env_command_file").toString();
258 else if (python_salome_file != "")
259 f_env_file = field("env_PythonSalome_file").toString();
260 env_file = f_env_file.trimmed().toUtf8().constData();
263 QString f_batch_directory = field("batch_directory").toString();
264 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
267 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
268 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
271 QString f_launcher_file = field("launcher_file").toString();
272 launcher_file = f_launcher_file.toUtf8().constData();
273 QString f_launcher_args = field("launcher_args").toString();
274 launcher_args = f_launcher_args.toUtf8().constData();
278 if(field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0)
280 maximum_duration = "";
284 if (field("duration_hour").toInt() < 10)
285 time_hour = "0" + field("duration_hour").toString().trimmed();
287 time_hour = field("duration_hour").toString().trimmed();
288 if (field("duration_min").toInt() < 10)
289 time_min = "0" + field("duration_min").toString().trimmed();
291 time_min = field("duration_min").toString().trimmed();
292 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
295 unsigned long mem = field("mem_value").toULongLong();
296 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
299 case BatchParametersPage::MB:
302 case BatchParametersPage::GB:
303 mem_limit = mem * 1024;
306 throw Exception("Invalid memory unit");
308 mem_req_type = _batch_parameters_page->getMemReqType();
310 nb_proc = field("proc_value").toInt();
311 exclusive = field("exclusive").toBool();
314 QString f_result_directory = field("result_directory").toString();
315 result_directory = f_result_directory.trimmed().toUtf8().constData();
316 for (int i = 0; i < _input_files_list->count(); ++i)
318 QListWidgetItem * item = _input_files_list->item(i);
319 QString item_text = item->text();
320 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
322 for (int i = 0; i < _output_files_list->count(); ++i)
324 QListWidgetItem * item = _output_files_list->item(i);
325 QString item_text = item->text();
326 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
330 QString f_resource_choosed = field("resource_choosed").toString();
331 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
334 QString f_batch_queue = field("batch_queue").toString();
335 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
337 // LoadLeveler JobType
338 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
339 std::string batch = resource_descr.batch.c_str();
342 QString f_ll_jobtype = field("ll_jobtype").toString();
343 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
351 QString f_wckey = field("wckey").toString();
352 wckey = f_wckey.trimmed().toUtf8().constData();
354 start_job = field("start_job").toBool();
359 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
360 : QWizardPage(parent)
362 _jobs_manager = jobs_manager;
364 setTitle("Create a new job");
366 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
367 label->setWordWrap(true);
368 QLabel * nameLabel = new QLabel("Job Name:");
369 QLineEdit * _nameLineEdit = new QLineEdit(this);
370 registerField("job_name", _nameLineEdit);
372 QLabel * label_type = new QLabel("Choose type of batch job:");
373 QGroupBox *groupBox = new QGroupBox("Type of job");
374 _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
375 _yacs_schema_button->setChecked(true);
376 _command_button = new QRadioButton(tr("Command"));
377 _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
378 QVBoxLayout *vbox = new QVBoxLayout;
379 vbox->addWidget(_yacs_schema_button);
380 vbox->addWidget(_command_button);
381 vbox->addWidget(_python_salome_button);
383 groupBox->setLayout(vbox);
385 QGroupBox * explanationBox = new QGroupBox("Explanation");
386 QVBoxLayout *explanationvbox = new QVBoxLayout;
387 _explanation = new QLabel();
388 _explanation->setWordWrap(true);
389 explanationvbox->addWidget(_explanation);
390 explanationvbox->addStretch(1);
391 explanationBox->setLayout(explanationvbox);
394 QVBoxLayout * main_layout = new QVBoxLayout;
395 main_layout->addWidget(label);
396 QGridLayout *layout = new QGridLayout;
397 layout->addWidget(nameLabel, 0, 0);
398 layout->addWidget(_nameLineEdit, 0, 1);
399 main_layout->insertLayout(-1, layout);
400 layout->addWidget(label_type, 2, 0);
401 layout->addWidget(groupBox, 3, 0, 1, -1);
402 layout->addWidget(explanationBox, 4, 0, 1, -1);
403 setLayout(main_layout);
405 connect(_yacs_schema_button, SIGNAL(clicked(bool)), this, SLOT(yacs_schema_button(bool)));
406 connect(_command_button, SIGNAL(clicked(bool)), this, SLOT(command_button(bool)));
407 connect(_python_salome_button, SIGNAL(clicked(bool)), this, SLOT(python_salome_button(bool)));
410 yacs_schema_button(true);
413 BL::JobNamePage::~JobNamePage()
417 BL::JobNamePage::yacs_schema_button(bool checked)
421 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
422 setField("exclusive", true);
427 BL::JobNamePage::command_button(bool checked)
431 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
432 setField("exclusive", false);
437 BL::JobNamePage::python_salome_button(bool checked)
441 _explanation->setText("This job permits to launch a python script into a SALOME application");
442 setField("exclusive", true);
447 BL::JobNamePage::validatePage()
449 DEBTRACE("Calling validatePage of BL::JobNamePage");
451 QString job_name = field("job_name").toString();
453 // Check if job name is empty
456 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
457 return_value = false;
460 // Check if job name already exists
462 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
468 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
470 setField("job_name", value);
471 return_value = false;
479 BL::JobNamePage::nextId() const
481 if (_yacs_schema_button->isChecked())
483 return BL::CreateJobWizard::Page_YACSSchema;
485 else if (_command_button->isChecked())
487 return BL::CreateJobWizard::Page_Command_Main_Definitions;
491 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
495 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
496 : QWizardPage(parent)
498 setTitle("Configure YACS Execution");
500 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
501 label->setWordWrap(true);
503 QGroupBox * files_param_box = new QGroupBox("YACS job files");
504 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
505 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
506 _yacs_file_text = new QLineEdit(this);
507 _yacs_file_text->setText("");
508 registerField("yacs_file", _yacs_file_text);
509 _yacs_file_text->setReadOnly(true);
510 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
511 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
512 _line_env_file = new QLineEdit(this);
513 registerField("env_yacs_file", _line_env_file);
514 _line_env_file->setReadOnly(true);
515 QGridLayout * files_layout = new QGridLayout;
516 files_layout->addWidget(yacs_file_button, 0, 0);
517 files_layout->addWidget(_yacs_file_text, 0, 1);
518 files_layout->addWidget(command_env_file_button, 1, 0);
519 files_layout->addWidget(_line_env_file, 1, 1);
520 files_param_box->setLayout(files_layout);
522 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
523 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
524 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
525 QSpinBox * spin_dump = new QSpinBox(this);
526 spin_dump->setMinimum(0);
527 spin_dump->setMaximum(1000000);
528 registerField("dump_yacs_state", spin_dump);
529 QGridLayout * specific_layout = new QGridLayout;
530 specific_layout->addWidget(label_dump, 0, 0);
531 specific_layout->addWidget(spin_dump, 0, 1);
532 specific_layout->addWidget(label_dump_warning, 1, 0);
533 spec_param_box->setLayout(specific_layout);
535 QVBoxLayout * main_layout = new QVBoxLayout;
536 main_layout->addWidget(label);
537 main_layout->addWidget(files_param_box);
538 main_layout->addWidget(spec_param_box);
540 setLayout(main_layout);
543 BL::YACSSchemaPage::~YACSSchemaPage()
547 BL::YACSSchemaPage::validatePage()
550 QString yacs_file = field("yacs_file").toString();
557 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
558 return_value = false;
564 BL::YACSSchemaPage::choose_file()
566 QString yacs_file = QFileDialog::getOpenFileName(this,
567 tr("Open YACS files"), "",
568 tr("XML (*.xml);;All Files (*)"));
569 _yacs_file_text->setReadOnly(false);
570 _yacs_file_text->setText(yacs_file);
571 _yacs_file_text->setReadOnly(true);
575 BL::YACSSchemaPage::choose_env_file()
577 QString env_file = QFileDialog::getOpenFileName(this,
578 tr("Open environnement file"), "",
579 tr("sh (*.sh);;All Files (*)"));
580 _line_env_file->setReadOnly(false);
581 _line_env_file->setText(env_file);
582 _line_env_file->setReadOnly(true);
587 BL::YACSSchemaPage::nextId() const
589 return BL::CreateJobWizard::Page_Resource;
592 BL::CommandMainPage::CommandMainPage(QWidget * parent)
593 : QWizardPage(parent)
595 setTitle("Define command job");
596 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
597 label->setWordWrap(true);
600 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
601 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
602 _line_command = new QLineEdit(this);
603 registerField("command", _line_command);
604 _line_command->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_command_file", _line_env_file);
610 _line_env_file->setReadOnly(true);
612 QGridLayout *layout = new QGridLayout;
613 layout->addWidget(command_file_button, 0, 0);
614 layout->addWidget(_line_command, 0, 1);
615 layout->addWidget(command_env_file_button, 1, 0);
616 layout->addWidget(_line_env_file, 1, 1);
618 QVBoxLayout * main_layout = new QVBoxLayout;
619 main_layout->addWidget(label);
620 main_layout->insertLayout(-1, layout);
621 setLayout(main_layout);
624 BL::CommandMainPage::~CommandMainPage()
628 BL::CommandMainPage::choose_command_file()
630 QString command_file = QFileDialog::getOpenFileName(this,
631 tr("Open command file"), "",
632 tr("sh (*.sh);;All Files (*)"));
633 _line_command->setReadOnly(false);
634 _line_command->setText(command_file);
635 _line_command->setReadOnly(true);
639 BL::CommandMainPage::choose_env_file()
641 QString env_file = QFileDialog::getOpenFileName(this,
642 tr("Open environnement file"), "",
643 tr("sh (*.sh);;All Files (*)"));
644 _line_env_file->setReadOnly(false);
645 _line_env_file->setText(env_file);
646 _line_env_file->setReadOnly(true);
650 BL::CommandMainPage::validatePage()
652 QString command = field("command").toString();
655 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
663 BL::CommandMainPage::nextId() const
665 return BL::CreateJobWizard::Page_Resource;
668 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
669 : QWizardPage(parent),
670 ui(new Ui::ResourceRequirementsWizardPage),
671 _salome_services(salome_services),
676 registerField("duration_hour", ui->spin_duration_hour);
677 registerField("duration_min", ui->spin_duration_min);
678 registerField("mem_value", ui->spin_memory);
679 registerField("proc_value", ui->spin_proc);
680 registerField("exclusive", ui->check_exclusive);
682 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
683 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
686 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
687 "per node", Job::MEM_PER_NODE);
688 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
689 "per core", Job::MEM_PER_CPU);
692 BatchParametersPage::~BatchParametersPage()
698 BatchParametersPage::initializePage()
700 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
701 if (f_resource_choosed != resource_choosed)
703 resource_choosed = f_resource_choosed;
704 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
705 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
706 if (resource_descr.batch == "slurm")
708 ui->combo_memory_req_type->setEnabled(true);
712 ui->combo_memory_req_type->setEnabled(false);
713 setMemReqType(Job::MEM_PER_NODE);
718 BatchParametersPage::MemUnit
719 BatchParametersPage::getMemUnit() const
721 int idx = ui->combo_memory_unit->currentIndex();
722 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
726 BatchParametersPage::setMemUnit(MemUnit mem_unit)
728 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
732 BatchParametersPage::getMemReqType() const
734 int idx = ui->combo_memory_req_type->currentIndex();
735 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
739 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
741 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
745 BatchParametersPage::cleanupPage()
750 BatchParametersPage::nextId() const
752 return CreateJobWizard::Page_Files;
755 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
756 : QWizardPage(parent)
758 setTitle("Enter COORM Parameters");
759 resource_choosed = "";
761 _salome_services = salome_services;
763 QLabel *label = new QLabel("In this step you define the parameters for COORM");
764 label->setWordWrap(true);
765 QVBoxLayout * main_layout = new QVBoxLayout;
766 main_layout->addWidget(label);
768 // coorm_batch_directory
769 QLabel * label_directory = new QLabel("Remote work directory: ");
770 QLineEdit * line_directory = new QLineEdit(this);
771 registerField("coorm_batch_directory", line_directory);
774 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
775 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
776 _launcher_file_text = new QLineEdit(this);
777 _launcher_file_text->setText("");
778 registerField("launcher_file", _launcher_file_text);
779 _launcher_file_text->setReadOnly(true);
782 QLabel * launcher_args_label = new QLabel("Launcher args:");
783 QLineEdit * launcher_args_text = new QLineEdit(this);
784 registerField("launcher_args", launcher_args_text);
786 QGridLayout * layout = new QGridLayout;
787 layout->addWidget(label_directory, 0, 0);
788 layout->addWidget(line_directory, 0, 1);
789 layout->addWidget(launcher_file_button, 1, 0);
790 layout->addWidget(_launcher_file_text, 1, 1);
791 layout->addWidget(launcher_args_label, 2, 0);
792 layout->addWidget(launcher_args_text, 2, 1);
794 main_layout->insertLayout(-1, layout);
796 setLayout(main_layout);
799 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
803 BL::COORM_BatchParametersPage::validatePage()
805 QString coorm_batch_directory = field("coorm_batch_directory").toString();
806 if (coorm_batch_directory == "")
808 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
812 QString launcher_file = field("launcher_file").toString();
813 if (launcher_file == "")
815 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
823 BL::COORM_BatchParametersPage::nextId() const
825 return BL::CreateJobWizard::Page_Files;
829 BL::COORM_BatchParametersPage::choose_launcher_file()
831 QString launcher_file = QFileDialog::getOpenFileName(this,
832 tr("Open launcher files"), "",
833 tr("Py (*.py);;All Files (*)"));
834 _launcher_file_text->setReadOnly(false);
835 _launcher_file_text->setText(launcher_file);
836 _launcher_file_text->setReadOnly(true);
839 void BL::COORM_BatchParametersPage::cleanupPage()
843 BL::COORM_BatchParametersPage::initializePage()
845 QString f_resource_choosed = field("resource_choosed").toString();
846 if (f_resource_choosed != resource_choosed)
848 resource_choosed = f_resource_choosed;
849 // If choosed resource has a working_directory set
850 // Generates a default remote working directory
851 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
852 QString res_work_dir = resource_descr.working_directory.c_str();
853 if (res_work_dir != "")
857 std::string launch_date = ctime(&rawtime);
858 for (int i = 0; i < launch_date.size(); i++)
859 if (launch_date[i] == '/' ||
860 launch_date[i] == '-' ||
861 launch_date[i] == ':' ||
862 launch_date[i] == ' ')
863 launch_date[i] = '_';
864 launch_date.erase(--launch_date.end()); // Last caracter is a \n
865 QString date = launch_date.c_str();
866 setField("coorm_batch_directory", res_work_dir + "/" + date);
871 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
872 : QWizardPage(parent),
873 ui(new Ui::FilesWizardPage)
877 resource_choosed = "";
878 _salome_services = salome_services;
880 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
881 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
882 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
883 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
884 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
885 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
886 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
888 registerField("batch_directory", ui->line_remote_working_dir);
889 registerField("result_directory", ui->line_result_dir);
891 // Default result directory is home directory (if we found it)
894 ui->line_result_dir->setText(getenv("HOME"));
897 ui->line_result_dir->setText(getenv("HOME"));
899 // Second try -> getpwuid
900 struct passwd * pass_struct = getpwuid(getuid());
902 ui->line_result_dir->setText(pass_struct->pw_dir);
906 parent->setFilesList(ui->input_files_list, ui->output_files_list);
908 // Check for warning messages
909 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
910 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
911 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
914 FilesPage::~FilesPage()
920 FilesPage::initializePage()
922 QString f_resource_choosed = field("resource_choosed").toString();
923 if (f_resource_choosed != resource_choosed)
925 resource_choosed = f_resource_choosed;
926 // If choosed resource has a working_directory set
927 // Generates a default remote working directory
928 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
929 QString res_work_dir = resource_descr.working_directory.c_str();
930 if (res_work_dir != "")
934 std::string launch_date = ctime(&rawtime);
935 for (int i = 0; i < launch_date.size(); i++)
936 if (launch_date[i] == '/' ||
937 launch_date[i] == '-' ||
938 launch_date[i] == ':' ||
939 launch_date[i] == ' ')
940 launch_date[i] = '_';
941 launch_date.erase(--launch_date.end()); // Last caracter is a \n
942 QString date = launch_date.c_str();
943 setField("batch_directory", res_work_dir + "/" + date);
949 FilesPage::isComplete() const
952 if (field("batch_directory").toString().isEmpty())
953 warn_msg = "Remote working directory is mandatory.";
954 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
956 if (!warn_msg.isEmpty()) warn_msg += "\n";
957 warn_msg += "Result directory is mandatory if there are output files.";
960 ui->label_warning_text->setText(warn_msg);
961 if (warn_msg.isEmpty())
963 ui->label_warning_icon->hide();
968 ui->label_warning_icon->show();
974 FilesPage::choose_input_files()
976 QStringList files = QFileDialog::getOpenFileNames(this,
977 tr("Add input files"), "",
978 tr("All Files (*)"));
979 for (int i = 0; i < files.size(); ++i)
981 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
982 ui->input_files_list->addItem(files.at(i));
987 FilesPage::choose_local_directory()
989 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
991 QFileDialog::ShowDirsOnly
992 | QFileDialog::DontResolveSymlinks);
995 ui->line_result_dir->setText(dir);
999 FilesPage::remove_input_files()
1001 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1002 for (int i = 0; i < list.size(); ++i)
1004 int row = ui->input_files_list->row( list.at(i) );
1005 delete ui->input_files_list->takeItem(row);
1010 FilesPage::input_itemSelectionChanged()
1012 if (ui->input_files_list->selectedItems().size() > 0)
1013 ui->remove_input_files_button->setEnabled(true);
1015 ui->remove_input_files_button->setEnabled(false);
1019 FilesPage::add_output_file()
1021 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1022 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1023 ui->output_files_list->addItem(new_item);
1024 emit completeChanged();
1028 FilesPage::remove_output_files()
1030 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1031 for (int i = 0; i < list.size(); ++i)
1033 int row = ui->output_files_list->row( list.at(i) );
1034 delete ui->output_files_list->takeItem(row);
1036 emit completeChanged();
1040 FilesPage::output_itemSelectionChanged()
1042 if (ui->output_files_list->selectedItems().size() > 0)
1043 ui->remove_output_files_button->setEnabled(true);
1045 ui->remove_output_files_button->setEnabled(false);
1049 FilesPage::nextId() const
1051 return BL::CreateJobWizard::Page_Advanced;
1054 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1055 : QWizardPage(parent)
1057 setTitle("Job definition is finished");
1058 QCheckBox * check_box = new QCheckBox("Start job after creation");
1059 registerField("start_job", check_box);
1060 QVBoxLayout * main_layout = new QVBoxLayout;
1061 main_layout->addWidget(check_box);
1062 setLayout(main_layout);
1065 BL::ConclusionPage::~ConclusionPage()
1069 BL::ConclusionPage::validatePage()
1075 BL::ConclusionPage::nextId() const
1080 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1081 : QWizardPage(parent)
1083 _salome_services = salome_services;
1084 setTitle("Select a Resource");
1086 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1087 main_label->setWordWrap(true);
1090 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1091 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1092 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1094 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1095 resource_list_layout->addWidget(_resource_list);
1096 resource_group_box->setLayout(resource_list_layout);
1098 QLabel * resource_label = new QLabel("Resource selected: ");
1099 _resource_choosed = new QLineEdit();
1100 _resource_choosed->setText("");
1101 _resource_choosed->setReadOnly(true);
1102 registerField("resource_choosed", _resource_choosed);
1104 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1105 QLineEdit * _bqLineEdit = new QLineEdit(this);
1106 registerField("batch_queue", _bqLineEdit);
1108 _ll_label = new QLabel("LoadLeveler JobType:", this);
1109 _ll_value = new QLineEdit(this);
1110 registerField("ll_jobtype", _ll_value);
1114 _main_layout = new QGridLayout;
1115 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1116 _main_layout->addWidget(resource_label, 1, 0);
1117 _main_layout->addWidget(_resource_choosed, 1, 1);
1118 _main_layout->addWidget(bqLabel, 2, 0);
1119 _main_layout->addWidget(_bqLineEdit, 2, 1);
1120 setLayout(_main_layout);
1124 BL::ResourcePage::~ResourcePage()
1128 BL::ResourcePage::initializePage()
1130 if (field("ll_jobtype").toString() != "")
1132 _main_layout->addWidget(_ll_label, 3, 0);
1133 _main_layout->addWidget(_ll_value, 3, 1);
1138 // Initialize resource_choosed with first resource in resource list
1139 if (field("resource_choosed").toString() == "")
1141 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1142 std::list<std::string>::iterator it = resource_list.begin();
1143 if (it != resource_list.end())
1145 QString first_resource((*it).c_str());
1146 setField("resource_choosed", first_resource);
1152 BL::ResourcePage::validatePage()
1154 QString resource_choosed = field("resource_choosed").toString();
1155 if (resource_choosed == "")
1157 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1161 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1162 std::string batch = resource_descr.batch.c_str();
1165 QString ll_jobtype = field("ll_jobtype").toString();
1166 if (ll_jobtype == "")
1168 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1176 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1178 _resource_choosed->setReadOnly(false);
1179 _resource_choosed->setText(item->text());
1180 _resource_choosed->setReadOnly(true);
1182 //Specific parameters for LoadLeveler
1183 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1184 std::string batch = resource_descr.batch.c_str();
1187 _main_layout->addWidget(_ll_label, 3, 0);
1188 _main_layout->addWidget(_ll_value, 3, 1);
1194 _main_layout->removeWidget(_ll_value);
1195 _main_layout->removeWidget(_ll_label);
1202 BL::ResourcePage::nextId() const
1204 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1205 std::string batch = resource_descr.batch.c_str();
1206 if (batch == "coorm")
1208 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1212 return BL::CreateJobWizard::Page_BatchParameters;
1216 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1217 : QWizardPage(parent)
1219 setTitle("Define a Python script in SALOME job");
1220 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1221 label->setWordWrap(true);
1224 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1225 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1226 _line_PythonSalome = new QLineEdit(this);
1227 registerField("PythonSalome", _line_PythonSalome);
1228 _line_PythonSalome->setReadOnly(true);
1230 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1231 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1232 _line_env_file = new QLineEdit(this);
1233 registerField("env_PythonSalome_file", _line_env_file);
1234 _line_env_file->setReadOnly(true);
1236 QGridLayout *layout = new QGridLayout;
1237 layout->addWidget(PythonSalome_file_button, 0, 0);
1238 layout->addWidget(_line_PythonSalome, 0, 1);
1239 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1240 layout->addWidget(_line_env_file, 1, 1);
1242 QVBoxLayout * main_layout = new QVBoxLayout;
1243 main_layout->addWidget(label);
1244 main_layout->insertLayout(-1, layout);
1245 setLayout(main_layout);
1248 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1252 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1254 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1255 tr("Open Python script file"), "",
1256 tr("py (*.py);;All Files (*)"));
1257 _line_PythonSalome->setReadOnly(false);
1258 _line_PythonSalome->setText(PythonSalome_file);
1259 _line_PythonSalome->setReadOnly(true);
1263 BL::PythonSalomeMainPage::choose_env_file()
1265 QString env_file = QFileDialog::getOpenFileName(this,
1266 tr("Open environnement file"), "",
1267 tr("sh (*.sh);;All Files (*)"));
1268 _line_env_file->setReadOnly(false);
1269 _line_env_file->setText(env_file);
1270 _line_env_file->setReadOnly(true);
1274 BL::PythonSalomeMainPage::validatePage()
1276 QString PythonSalome = field("PythonSalome").toString();
1277 if (PythonSalome == "")
1279 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1287 BL::PythonSalomeMainPage::nextId() const
1289 return BL::CreateJobWizard::Page_Resource;
1294 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1295 : QWizardPage(parent),
1296 ui(new Ui::AdvancedParametersWizardPage)
1299 registerField("wckey", ui->line_wckey);
1302 AdvancedParametersPage::~AdvancedParametersPage()
1308 AdvancedParametersPage::nextId() const
1310 return BL::CreateJobWizard::Page_Conclusion;