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("default_time", true);
175 setField("duration_hour", 0);
176 setField("duration_min", 0);
180 setField("user_time", true);
181 std::size_t pos = batch_params.maximum_duration.find(":");
182 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
184 std::istringstream iss_hour(hour_str);
186 setField("duration_hour", hour);
188 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
190 std::istringstream iss_min(min_str);
192 setField("duration_min", min);
195 long long mem_mb = batch_params.mem_limit;
198 setField("default_mem", true);
202 setField("user_mem", true);
203 if (mem_mb % 1024 == 0)
205 setField("mem_value", mem_mb / 1024);
206 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
210 setField("mem_value", mem_mb);
211 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
213 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
216 BL::Job::FilesParam files_params = job->getFilesParameters();
218 std::list<std::string>::iterator it = files_params.input_files_list.begin();
219 for (; it != files_params.input_files_list.end(); it++)
220 _input_files_list->addItem(QString((*it).c_str()));
221 it = files_params.output_files_list.begin();
222 for (; it != files_params.output_files_list.end(); it++)
223 _output_files_list->addItem(QString((*it).c_str()));
225 setField("result_directory", QString(files_params.result_directory.c_str()));
226 setField("resource_choosed", QString(job->getResource().c_str()));
227 setField("batch_queue", QString(job->getBatchQueue().c_str()));
228 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
229 setField("wckey", QString(job->getWCKey().c_str()));
234 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
236 _input_files_list = input_files_list;
237 _output_files_list = output_files_list;
241 BL::CreateJobWizard::end(int result)
243 DEBTRACE("End of BL::CreateJobWizard");
247 QString f_job_name = field("job_name").toString();
248 job_name = f_job_name.trimmed().toUtf8().constData();
251 QString f_yacs_file = field("yacs_file").toString();
252 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
253 dump_yacs_state = field("dump_yacs_state").toInt();
256 QString f_command = field("command").toString();
257 command = f_command.trimmed().toUtf8().constData();
260 QString f_python_salome_file = field("PythonSalome").toString();
261 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
265 f_env_file = field("env_yacs_file").toString();
266 else if (command != "")
267 f_env_file = field("env_command_file").toString();
268 else if (python_salome_file != "")
269 f_env_file = field("env_PythonSalome_file").toString();
270 env_file = f_env_file.trimmed().toUtf8().constData();
273 QString f_batch_directory = field("batch_directory").toString();
274 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
277 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
278 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
281 QString f_launcher_file = field("launcher_file").toString();
282 launcher_file = f_launcher_file.toUtf8().constData();
283 QString f_launcher_args = field("launcher_args").toString();
284 launcher_args = f_launcher_args.toUtf8().constData();
288 if (field("default_time").toBool() ||
289 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
291 maximum_duration = "";
295 if (field("duration_hour").toInt() < 10)
296 time_hour = "0" + field("duration_hour").toString().trimmed();
298 time_hour = field("duration_hour").toString().trimmed();
299 if (field("duration_min").toInt() < 10)
300 time_min = "0" + field("duration_min").toString().trimmed();
302 time_min = field("duration_min").toString().trimmed();
303 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
306 if(field("default_mem").toBool())
312 unsigned long mem = field("mem_value").toULongLong();
313 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
316 case BatchParametersPage::MB:
319 case BatchParametersPage::GB:
320 mem_limit = mem * 1024;
323 throw Exception("Invalid memory unit");
325 mem_req_type = _batch_parameters_page->getMemReqType();
328 nb_proc = field("proc_value").toInt();
329 exclusive = field("exclusive").toBool();
332 QString f_result_directory = field("result_directory").toString();
333 result_directory = f_result_directory.trimmed().toUtf8().constData();
334 for (int i = 0; i < _input_files_list->count(); ++i)
336 QListWidgetItem * item = _input_files_list->item(i);
337 QString item_text = item->text();
338 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
340 for (int i = 0; i < _output_files_list->count(); ++i)
342 QListWidgetItem * item = _output_files_list->item(i);
343 QString item_text = item->text();
344 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
348 QString f_resource_choosed = field("resource_choosed").toString();
349 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
352 QString f_batch_queue = field("batch_queue").toString();
353 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
355 // LoadLeveler JobType
356 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
357 std::string batch = resource_descr.batch.c_str();
360 QString f_ll_jobtype = field("ll_jobtype").toString();
361 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
369 QString f_wckey = field("wckey").toString();
370 wckey = f_wckey.trimmed().toUtf8().constData();
372 start_job = field("start_job").toBool();
377 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
378 : QWizardPage(parent)
380 _jobs_manager = jobs_manager;
382 setTitle("Create a new job");
384 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
385 label->setWordWrap(true);
386 QLabel * nameLabel = new QLabel("Job Name:");
387 QLineEdit * _nameLineEdit = new QLineEdit(this);
388 registerField("job_name", _nameLineEdit);
390 QLabel * label_type = new QLabel("Choose type of batch job:");
391 QGroupBox *groupBox = new QGroupBox("Type of job");
392 _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
393 _yacs_schema_button->setChecked(true);
394 _command_button = new QRadioButton(tr("Command"));
395 _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
396 QVBoxLayout *vbox = new QVBoxLayout;
397 vbox->addWidget(_yacs_schema_button);
398 vbox->addWidget(_command_button);
399 vbox->addWidget(_python_salome_button);
401 groupBox->setLayout(vbox);
403 QGroupBox * explanationBox = new QGroupBox("Explanation");
404 QVBoxLayout *explanationvbox = new QVBoxLayout;
405 _explanation = new QLabel();
406 _explanation->setWordWrap(true);
407 explanationvbox->addWidget(_explanation);
408 explanationvbox->addStretch(1);
409 explanationBox->setLayout(explanationvbox);
412 QVBoxLayout * main_layout = new QVBoxLayout;
413 main_layout->addWidget(label);
414 QGridLayout *layout = new QGridLayout;
415 layout->addWidget(nameLabel, 0, 0);
416 layout->addWidget(_nameLineEdit, 0, 1);
417 main_layout->insertLayout(-1, layout);
418 layout->addWidget(label_type, 2, 0);
419 layout->addWidget(groupBox, 3, 0, 1, -1);
420 layout->addWidget(explanationBox, 4, 0, 1, -1);
421 setLayout(main_layout);
423 connect(_yacs_schema_button, SIGNAL(clicked(bool)), this, SLOT(yacs_schema_button(bool)));
424 connect(_command_button, SIGNAL(clicked(bool)), this, SLOT(command_button(bool)));
425 connect(_python_salome_button, SIGNAL(clicked(bool)), this, SLOT(python_salome_button(bool)));
428 yacs_schema_button(true);
431 BL::JobNamePage::~JobNamePage()
435 BL::JobNamePage::yacs_schema_button(bool checked)
439 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
440 setField("exclusive", true);
445 BL::JobNamePage::command_button(bool checked)
449 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
450 setField("exclusive", false);
455 BL::JobNamePage::python_salome_button(bool checked)
459 _explanation->setText("This job permits to launch a python script into a SALOME application");
460 setField("exclusive", true);
465 BL::JobNamePage::validatePage()
467 DEBTRACE("Calling validatePage of BL::JobNamePage");
469 QString job_name = field("job_name").toString();
471 // Check if job name is empty
474 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
475 return_value = false;
478 // Check if job name already exists
480 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
486 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
488 setField("job_name", value);
489 return_value = false;
497 BL::JobNamePage::nextId() const
499 if (_yacs_schema_button->isChecked())
501 return BL::CreateJobWizard::Page_YACSSchema;
503 else if (_command_button->isChecked())
505 return BL::CreateJobWizard::Page_Command_Main_Definitions;
509 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
513 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
514 : QWizardPage(parent)
516 setTitle("Configure YACS Execution");
518 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
519 label->setWordWrap(true);
521 QGroupBox * files_param_box = new QGroupBox("YACS job files");
522 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
523 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
524 _yacs_file_text = new QLineEdit(this);
525 _yacs_file_text->setText("");
526 registerField("yacs_file", _yacs_file_text);
527 _yacs_file_text->setReadOnly(true);
528 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
529 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
530 _line_env_file = new QLineEdit(this);
531 registerField("env_yacs_file", _line_env_file);
532 _line_env_file->setReadOnly(true);
533 QGridLayout * files_layout = new QGridLayout;
534 files_layout->addWidget(yacs_file_button, 0, 0);
535 files_layout->addWidget(_yacs_file_text, 0, 1);
536 files_layout->addWidget(command_env_file_button, 1, 0);
537 files_layout->addWidget(_line_env_file, 1, 1);
538 files_param_box->setLayout(files_layout);
540 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
541 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
542 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
543 QSpinBox * spin_dump = new QSpinBox(this);
544 spin_dump->setMinimum(0);
545 spin_dump->setMaximum(1000000);
546 registerField("dump_yacs_state", spin_dump);
547 QGridLayout * specific_layout = new QGridLayout;
548 specific_layout->addWidget(label_dump, 0, 0);
549 specific_layout->addWidget(spin_dump, 0, 1);
550 specific_layout->addWidget(label_dump_warning, 1, 0);
551 spec_param_box->setLayout(specific_layout);
553 QVBoxLayout * main_layout = new QVBoxLayout;
554 main_layout->addWidget(label);
555 main_layout->addWidget(files_param_box);
556 main_layout->addWidget(spec_param_box);
558 setLayout(main_layout);
561 BL::YACSSchemaPage::~YACSSchemaPage()
565 BL::YACSSchemaPage::validatePage()
568 QString yacs_file = field("yacs_file").toString();
575 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
576 return_value = false;
582 BL::YACSSchemaPage::choose_file()
584 QString yacs_file = QFileDialog::getOpenFileName(this,
585 tr("Open YACS files"), "",
586 tr("XML (*.xml);;All Files (*)"));
587 _yacs_file_text->setReadOnly(false);
588 _yacs_file_text->setText(yacs_file);
589 _yacs_file_text->setReadOnly(true);
593 BL::YACSSchemaPage::choose_env_file()
595 QString env_file = QFileDialog::getOpenFileName(this,
596 tr("Open environnement file"), "",
597 tr("sh (*.sh);;All Files (*)"));
598 _line_env_file->setReadOnly(false);
599 _line_env_file->setText(env_file);
600 _line_env_file->setReadOnly(true);
605 BL::YACSSchemaPage::nextId() const
607 return BL::CreateJobWizard::Page_Resource;
610 BL::CommandMainPage::CommandMainPage(QWidget * parent)
611 : QWizardPage(parent)
613 setTitle("Define command job");
614 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
615 label->setWordWrap(true);
618 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
619 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
620 _line_command = new QLineEdit(this);
621 registerField("command", _line_command);
622 _line_command->setReadOnly(true);
624 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
625 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
626 _line_env_file = new QLineEdit(this);
627 registerField("env_command_file", _line_env_file);
628 _line_env_file->setReadOnly(true);
630 QGridLayout *layout = new QGridLayout;
631 layout->addWidget(command_file_button, 0, 0);
632 layout->addWidget(_line_command, 0, 1);
633 layout->addWidget(command_env_file_button, 1, 0);
634 layout->addWidget(_line_env_file, 1, 1);
636 QVBoxLayout * main_layout = new QVBoxLayout;
637 main_layout->addWidget(label);
638 main_layout->insertLayout(-1, layout);
639 setLayout(main_layout);
642 BL::CommandMainPage::~CommandMainPage()
646 BL::CommandMainPage::choose_command_file()
648 QString command_file = QFileDialog::getOpenFileName(this,
649 tr("Open command file"), "",
650 tr("sh (*.sh);;All Files (*)"));
651 _line_command->setReadOnly(false);
652 _line_command->setText(command_file);
653 _line_command->setReadOnly(true);
657 BL::CommandMainPage::choose_env_file()
659 QString env_file = QFileDialog::getOpenFileName(this,
660 tr("Open environnement file"), "",
661 tr("sh (*.sh);;All Files (*)"));
662 _line_env_file->setReadOnly(false);
663 _line_env_file->setText(env_file);
664 _line_env_file->setReadOnly(true);
668 BL::CommandMainPage::validatePage()
670 QString command = field("command").toString();
673 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
681 BL::CommandMainPage::nextId() const
683 return BL::CreateJobWizard::Page_Resource;
686 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
687 : QWizardPage(parent),
688 ui(new Ui::ResourceRequirementsWizardPage),
689 _salome_services(salome_services),
694 registerField("duration_hour", ui->spin_duration_hour);
695 registerField("duration_min", ui->spin_duration_min);
696 registerField("mem_value", ui->spin_memory);
697 registerField("proc_value", ui->spin_proc);
698 registerField("exclusive", ui->check_exclusive);
699 registerField("default_time", ui->rb_default_time);
700 registerField("user_time", ui->rb_user_time);
701 registerField("default_mem", ui->rb_default_mem);
702 registerField("user_mem", ui->rb_user_mem);
704 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
705 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
708 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
709 "per node", Job::MEM_PER_NODE);
710 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
711 "per core", Job::MEM_PER_CPU);
713 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
714 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
715 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
716 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
717 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
720 BatchParametersPage::~BatchParametersPage()
726 BatchParametersPage::initializePage()
728 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
729 if (f_resource_choosed != resource_choosed)
731 resource_choosed = f_resource_choosed;
732 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
733 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
734 if (resource_descr.batch == "slurm")
736 ui->combo_memory_req_type->setEnabled(true);
740 ui->combo_memory_req_type->setEnabled(false);
741 setMemReqType(Job::MEM_PER_NODE);
746 BatchParametersPage::MemUnit
747 BatchParametersPage::getMemUnit() const
749 int idx = ui->combo_memory_unit->currentIndex();
750 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
754 BatchParametersPage::setMemUnit(MemUnit mem_unit)
756 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
760 BatchParametersPage::getMemReqType() const
762 int idx = ui->combo_memory_req_type->currentIndex();
763 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
767 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
769 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
773 BatchParametersPage::timeChanged()
775 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
776 ui->rb_default_time->setChecked(true);
778 ui->rb_user_time->setChecked(true);
782 BatchParametersPage::memChanged()
784 ui->rb_user_mem->setChecked(true);
788 BatchParametersPage::cleanupPage()
793 BatchParametersPage::nextId() const
795 return CreateJobWizard::Page_Files;
798 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
799 : QWizardPage(parent)
801 setTitle("Enter COORM Parameters");
802 resource_choosed = "";
804 _salome_services = salome_services;
806 QLabel *label = new QLabel("In this step you define the parameters for COORM");
807 label->setWordWrap(true);
808 QVBoxLayout * main_layout = new QVBoxLayout;
809 main_layout->addWidget(label);
811 // coorm_batch_directory
812 QLabel * label_directory = new QLabel("Remote work directory: ");
813 QLineEdit * line_directory = new QLineEdit(this);
814 registerField("coorm_batch_directory", line_directory);
817 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
818 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
819 _launcher_file_text = new QLineEdit(this);
820 _launcher_file_text->setText("");
821 registerField("launcher_file", _launcher_file_text);
822 _launcher_file_text->setReadOnly(true);
825 QLabel * launcher_args_label = new QLabel("Launcher args:");
826 QLineEdit * launcher_args_text = new QLineEdit(this);
827 registerField("launcher_args", launcher_args_text);
829 QGridLayout * layout = new QGridLayout;
830 layout->addWidget(label_directory, 0, 0);
831 layout->addWidget(line_directory, 0, 1);
832 layout->addWidget(launcher_file_button, 1, 0);
833 layout->addWidget(_launcher_file_text, 1, 1);
834 layout->addWidget(launcher_args_label, 2, 0);
835 layout->addWidget(launcher_args_text, 2, 1);
837 main_layout->insertLayout(-1, layout);
839 setLayout(main_layout);
842 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
846 BL::COORM_BatchParametersPage::validatePage()
848 QString coorm_batch_directory = field("coorm_batch_directory").toString();
849 if (coorm_batch_directory == "")
851 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
855 QString launcher_file = field("launcher_file").toString();
856 if (launcher_file == "")
858 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
866 BL::COORM_BatchParametersPage::nextId() const
868 return BL::CreateJobWizard::Page_Files;
872 BL::COORM_BatchParametersPage::choose_launcher_file()
874 QString launcher_file = QFileDialog::getOpenFileName(this,
875 tr("Open launcher files"), "",
876 tr("Py (*.py);;All Files (*)"));
877 _launcher_file_text->setReadOnly(false);
878 _launcher_file_text->setText(launcher_file);
879 _launcher_file_text->setReadOnly(true);
882 void BL::COORM_BatchParametersPage::cleanupPage()
886 BL::COORM_BatchParametersPage::initializePage()
888 QString f_resource_choosed = field("resource_choosed").toString();
889 if (f_resource_choosed != resource_choosed)
891 resource_choosed = f_resource_choosed;
892 // If choosed resource has a working_directory set
893 // Generates a default remote working directory
894 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
895 QString res_work_dir = resource_descr.working_directory.c_str();
896 if (res_work_dir != "")
900 std::string launch_date = ctime(&rawtime);
901 for (int i = 0; i < launch_date.size(); i++)
902 if (launch_date[i] == '/' ||
903 launch_date[i] == '-' ||
904 launch_date[i] == ':' ||
905 launch_date[i] == ' ')
906 launch_date[i] = '_';
907 launch_date.erase(--launch_date.end()); // Last caracter is a \n
908 QString date = launch_date.c_str();
909 setField("coorm_batch_directory", res_work_dir + "/" + date);
914 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
915 : QWizardPage(parent),
916 ui(new Ui::FilesWizardPage)
920 resource_choosed = "";
921 _salome_services = salome_services;
923 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
924 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
925 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
926 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
927 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
928 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
929 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
931 registerField("batch_directory", ui->line_remote_working_dir);
932 registerField("result_directory", ui->line_result_dir);
934 // Default result directory is home directory (if we found it)
937 ui->line_result_dir->setText(getenv("HOME"));
940 ui->line_result_dir->setText(getenv("HOME"));
942 // Second try -> getpwuid
943 struct passwd * pass_struct = getpwuid(getuid());
945 ui->line_result_dir->setText(pass_struct->pw_dir);
949 parent->setFilesList(ui->input_files_list, ui->output_files_list);
951 // Check for warning messages
952 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
953 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
954 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
957 FilesPage::~FilesPage()
963 FilesPage::initializePage()
965 QString f_resource_choosed = field("resource_choosed").toString();
966 if (f_resource_choosed != resource_choosed)
968 resource_choosed = f_resource_choosed;
969 // If choosed resource has a working_directory set
970 // Generates a default remote working directory
971 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
972 QString res_work_dir = resource_descr.working_directory.c_str();
973 if (res_work_dir != "")
977 std::string launch_date = ctime(&rawtime);
978 for (int i = 0; i < launch_date.size(); i++)
979 if (launch_date[i] == '/' ||
980 launch_date[i] == '-' ||
981 launch_date[i] == ':' ||
982 launch_date[i] == ' ')
983 launch_date[i] = '_';
984 launch_date.erase(--launch_date.end()); // Last caracter is a \n
985 QString date = launch_date.c_str();
986 setField("batch_directory", res_work_dir + "/" + date);
992 FilesPage::isComplete() const
995 if (field("batch_directory").toString().isEmpty())
996 warn_msg = "Remote working directory is mandatory.";
997 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
999 if (!warn_msg.isEmpty()) warn_msg += "\n";
1000 warn_msg += "Result directory is mandatory if there are output files.";
1003 ui->label_warning_text->setText(warn_msg);
1004 if (warn_msg.isEmpty())
1006 ui->label_warning_icon->hide();
1011 ui->label_warning_icon->show();
1017 FilesPage::choose_input_files()
1019 QStringList files = QFileDialog::getOpenFileNames(this,
1020 tr("Add input files"), "",
1021 tr("All Files (*)"));
1022 for (int i = 0; i < files.size(); ++i)
1024 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1025 ui->input_files_list->addItem(files.at(i));
1030 FilesPage::choose_local_directory()
1032 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1034 QFileDialog::ShowDirsOnly
1035 | QFileDialog::DontResolveSymlinks);
1038 ui->line_result_dir->setText(dir);
1042 FilesPage::remove_input_files()
1044 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1045 for (int i = 0; i < list.size(); ++i)
1047 int row = ui->input_files_list->row( list.at(i) );
1048 delete ui->input_files_list->takeItem(row);
1053 FilesPage::input_itemSelectionChanged()
1055 if (ui->input_files_list->selectedItems().size() > 0)
1056 ui->remove_input_files_button->setEnabled(true);
1058 ui->remove_input_files_button->setEnabled(false);
1062 FilesPage::add_output_file()
1064 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1065 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1066 ui->output_files_list->addItem(new_item);
1067 emit completeChanged();
1071 FilesPage::remove_output_files()
1073 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1074 for (int i = 0; i < list.size(); ++i)
1076 int row = ui->output_files_list->row( list.at(i) );
1077 delete ui->output_files_list->takeItem(row);
1079 emit completeChanged();
1083 FilesPage::output_itemSelectionChanged()
1085 if (ui->output_files_list->selectedItems().size() > 0)
1086 ui->remove_output_files_button->setEnabled(true);
1088 ui->remove_output_files_button->setEnabled(false);
1092 FilesPage::nextId() const
1094 return BL::CreateJobWizard::Page_Advanced;
1097 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1098 : QWizardPage(parent)
1100 setTitle("Job definition is finished");
1101 QCheckBox * check_box = new QCheckBox("Start job after creation");
1102 registerField("start_job", check_box);
1103 QVBoxLayout * main_layout = new QVBoxLayout;
1104 main_layout->addWidget(check_box);
1105 setLayout(main_layout);
1108 BL::ConclusionPage::~ConclusionPage()
1112 BL::ConclusionPage::validatePage()
1118 BL::ConclusionPage::nextId() const
1123 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1124 : QWizardPage(parent)
1126 _salome_services = salome_services;
1127 setTitle("Select a Resource");
1129 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1130 main_label->setWordWrap(true);
1133 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1134 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1135 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1137 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1138 resource_list_layout->addWidget(_resource_list);
1139 resource_group_box->setLayout(resource_list_layout);
1141 QLabel * resource_label = new QLabel("Resource selected: ");
1142 _resource_choosed = new QLineEdit();
1143 _resource_choosed->setText("");
1144 _resource_choosed->setReadOnly(true);
1145 registerField("resource_choosed", _resource_choosed);
1147 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1148 QLineEdit * _bqLineEdit = new QLineEdit(this);
1149 registerField("batch_queue", _bqLineEdit);
1151 _ll_label = new QLabel("LoadLeveler JobType:", this);
1152 _ll_value = new QLineEdit(this);
1153 registerField("ll_jobtype", _ll_value);
1157 _main_layout = new QGridLayout;
1158 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1159 _main_layout->addWidget(resource_label, 1, 0);
1160 _main_layout->addWidget(_resource_choosed, 1, 1);
1161 _main_layout->addWidget(bqLabel, 2, 0);
1162 _main_layout->addWidget(_bqLineEdit, 2, 1);
1163 setLayout(_main_layout);
1167 BL::ResourcePage::~ResourcePage()
1171 BL::ResourcePage::initializePage()
1173 if (field("ll_jobtype").toString() != "")
1175 _main_layout->addWidget(_ll_label, 3, 0);
1176 _main_layout->addWidget(_ll_value, 3, 1);
1181 // Initialize resource_choosed with first resource in resource list
1182 if (field("resource_choosed").toString() == "")
1184 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1185 std::list<std::string>::iterator it = resource_list.begin();
1186 if (it != resource_list.end())
1188 QString first_resource((*it).c_str());
1189 setField("resource_choosed", first_resource);
1195 BL::ResourcePage::validatePage()
1197 QString resource_choosed = field("resource_choosed").toString();
1198 if (resource_choosed == "")
1200 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1204 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1205 std::string batch = resource_descr.batch.c_str();
1208 QString ll_jobtype = field("ll_jobtype").toString();
1209 if (ll_jobtype == "")
1211 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1219 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1221 _resource_choosed->setReadOnly(false);
1222 _resource_choosed->setText(item->text());
1223 _resource_choosed->setReadOnly(true);
1225 //Specific parameters for LoadLeveler
1226 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1227 std::string batch = resource_descr.batch.c_str();
1230 _main_layout->addWidget(_ll_label, 3, 0);
1231 _main_layout->addWidget(_ll_value, 3, 1);
1237 _main_layout->removeWidget(_ll_value);
1238 _main_layout->removeWidget(_ll_label);
1245 BL::ResourcePage::nextId() const
1247 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1248 std::string batch = resource_descr.batch.c_str();
1249 if (batch == "coorm")
1251 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1255 return BL::CreateJobWizard::Page_BatchParameters;
1259 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1260 : QWizardPage(parent)
1262 setTitle("Define a Python script in SALOME job");
1263 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1264 label->setWordWrap(true);
1267 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1268 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1269 _line_PythonSalome = new QLineEdit(this);
1270 registerField("PythonSalome", _line_PythonSalome);
1271 _line_PythonSalome->setReadOnly(true);
1273 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1274 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1275 _line_env_file = new QLineEdit(this);
1276 registerField("env_PythonSalome_file", _line_env_file);
1277 _line_env_file->setReadOnly(true);
1279 QGridLayout *layout = new QGridLayout;
1280 layout->addWidget(PythonSalome_file_button, 0, 0);
1281 layout->addWidget(_line_PythonSalome, 0, 1);
1282 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1283 layout->addWidget(_line_env_file, 1, 1);
1285 QVBoxLayout * main_layout = new QVBoxLayout;
1286 main_layout->addWidget(label);
1287 main_layout->insertLayout(-1, layout);
1288 setLayout(main_layout);
1291 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1295 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1297 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1298 tr("Open Python script file"), "",
1299 tr("py (*.py);;All Files (*)"));
1300 _line_PythonSalome->setReadOnly(false);
1301 _line_PythonSalome->setText(PythonSalome_file);
1302 _line_PythonSalome->setReadOnly(true);
1306 BL::PythonSalomeMainPage::choose_env_file()
1308 QString env_file = QFileDialog::getOpenFileName(this,
1309 tr("Open environnement file"), "",
1310 tr("sh (*.sh);;All Files (*)"));
1311 _line_env_file->setReadOnly(false);
1312 _line_env_file->setText(env_file);
1313 _line_env_file->setReadOnly(true);
1317 BL::PythonSalomeMainPage::validatePage()
1319 QString PythonSalome = field("PythonSalome").toString();
1320 if (PythonSalome == "")
1322 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1330 BL::PythonSalomeMainPage::nextId() const
1332 return BL::CreateJobWizard::Page_Resource;
1337 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1338 : QWizardPage(parent),
1339 ui(new Ui::AdvancedParametersWizardPage)
1342 registerField("wckey", ui->line_wckey);
1345 AdvancedParametersPage::~AdvancedParametersPage()
1351 AdvancedParametersPage::nextId() const
1353 return BL::CreateJobWizard::Page_Conclusion;