1 // Copyright (C) 2009-2015 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>
30 #include <sys/types.h>
34 #include <ui_ResourceRequirementsWizardPage.h>
35 #include <ui_FilesWizardPage.h>
36 #include <ui_AdvancedParametersWizardPage.h>
45 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
47 DEBTRACE("Creating BL::CreateJobWizard");
48 BL_ASSERT(jobs_manager);
49 BL_ASSERT(salome_services);
50 _jobs_manager = jobs_manager;
51 _salome_services = salome_services;
57 python_salome_file = "";
62 coorm_batch_directory = "";
64 maximum_duration = "";
66 mem_req_type = BL::Job::MEM_PER_NODE;
69 // Parameters for COORM
73 result_directory = "";
75 resource_choosed = "";
82 setOptions(QWizard::NoBackButtonOnStartPage);
85 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
86 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
88 setPage(Page_JobName, _job_name_page);
89 setPage(Page_BatchParameters, _batch_parameters_page);
92 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
94 setPage(Page_Files, new BL::FilesPage(this, salome_services));
95 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
96 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
97 setPage(Page_Conclusion, new BL::ConclusionPage(this));
100 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
101 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
102 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
104 setWindowTitle("Create Job Wizard");
105 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
108 BL::CreateJobWizard::~CreateJobWizard()
110 DEBTRACE("Destroying BL::CreateJobWizard");
114 BL::CreateJobWizard::clone(const std::string & name)
116 if (_jobs_manager->job_already_exist(name) == true)
118 BL::Job * job = _jobs_manager->getJob(name);
120 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
121 if (job->getState() == BL::Job::CREATED ||
122 job->getState() == BL::Job::ERROR ||
123 job->getState() == BL::Job::FAILED ||
124 job->getState() == BL::Job::NOT_CREATED)
126 setField("job_name", QString(name.c_str()));
127 _job_name_page->_check_name = false;
130 if (job->getType() == BL::Job::YACS_SCHEMA)
132 setField("yacs_file", QString(job->getJobFile().c_str()));
133 setField("job_type_yacs", true);
134 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
135 if (job->getDumpYACSState() != -1)
138 value.setNum(job->getDumpYACSState());
139 setField("dump_yacs_state", value);
142 else if (job->getType() == BL::Job::COMMAND)
144 setField("command", QString(job->getJobFile().c_str()));
145 setField("job_type_command", true);
146 setField("env_command_file", QString(job->getEnvFile().c_str()));
148 else if (job->getType() == BL::Job::PYTHON_SALOME)
150 setField("PythonSalome", QString(job->getJobFile().c_str()));
151 setField("job_type_python_salome", true);
152 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
157 BL::Job::BatchParam batch_params = job->getBatchParameters();
158 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
159 std::string batch = resource_descr.batch.c_str();
160 if (batch == "coorm")
162 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
163 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
164 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
168 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
172 proc_value.setNum(batch_params.nb_proc);
173 setField("proc_value", proc_value);
175 setField("exclusive", batch_params.exclusive);
177 if (batch_params.maximum_duration == "")
179 setField("default_time", true);
180 setField("duration_hour", 0);
181 setField("duration_min", 0);
185 setField("user_time", true);
186 std::size_t pos = batch_params.maximum_duration.find(":");
187 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
189 std::istringstream iss_hour(hour_str);
191 setField("duration_hour", hour);
193 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
195 std::istringstream iss_min(min_str);
197 setField("duration_min", min);
200 long long mem_mb = batch_params.mem_limit;
203 setField("default_mem", true);
207 setField("user_mem", true);
208 if (mem_mb % 1024 == 0)
210 setField("mem_value", mem_mb / 1024);
211 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
215 setField("mem_value", mem_mb);
216 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
218 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
221 BL::Job::FilesParam files_params = job->getFilesParameters();
223 std::list<std::string>::iterator it = files_params.input_files_list.begin();
224 for (; it != files_params.input_files_list.end(); it++)
225 _input_files_list->addItem(QString((*it).c_str()));
226 it = files_params.output_files_list.begin();
227 for (; it != files_params.output_files_list.end(); it++)
228 _output_files_list->addItem(QString((*it).c_str()));
230 setField("result_directory", QString(files_params.result_directory.c_str()));
231 setField("resource_choosed", QString(job->getResource().c_str()));
232 setField("batch_queue", QString(job->getBatchQueue().c_str()));
233 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
234 setField("wckey", QString(job->getWCKey().c_str()));
235 setField("extra_params", QString(job->getExtraParams().c_str()));
240 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
242 _input_files_list = input_files_list;
243 _output_files_list = output_files_list;
247 BL::CreateJobWizard::end(int result)
249 DEBTRACE("End of BL::CreateJobWizard");
253 QString f_job_name = field("job_name").toString();
254 job_name = f_job_name.trimmed().toUtf8().constData();
255 if (field("job_type_yacs").toBool())
257 else if (field("job_type_command").toBool())
260 job_type = PYTHON_SALOME;
263 QString f_yacs_file = field("yacs_file").toString();
264 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
265 dump_yacs_state = field("dump_yacs_state").toInt();
268 QString f_command = field("command").toString();
269 command = f_command.trimmed().toUtf8().constData();
272 QString f_python_salome_file = field("PythonSalome").toString();
273 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
276 if (job_type == YACS)
277 f_env_file = field("env_yacs_file").toString();
278 else if (job_type == COMMAND)
279 f_env_file = field("env_command_file").toString();
280 else if (job_type == PYTHON_SALOME)
281 f_env_file = field("env_PythonSalome_file").toString();
282 env_file = f_env_file.trimmed().toUtf8().constData();
285 QString f_batch_directory = field("batch_directory").toString();
286 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
289 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
290 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
293 QString f_launcher_file = field("launcher_file").toString();
294 launcher_file = f_launcher_file.toUtf8().constData();
295 QString f_launcher_args = field("launcher_args").toString();
296 launcher_args = f_launcher_args.toUtf8().constData();
300 if (field("default_time").toBool() ||
301 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
303 maximum_duration = "";
307 if (field("duration_hour").toInt() < 10)
308 time_hour = "0" + field("duration_hour").toString().trimmed();
310 time_hour = field("duration_hour").toString().trimmed();
311 if (field("duration_min").toInt() < 10)
312 time_min = "0" + field("duration_min").toString().trimmed();
314 time_min = field("duration_min").toString().trimmed();
315 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
318 if(field("default_mem").toBool())
324 unsigned long mem = field("mem_value").toULongLong();
325 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
328 case BatchParametersPage::MB:
331 case BatchParametersPage::GB:
332 mem_limit = mem * 1024;
335 throw Exception("Invalid memory unit");
337 mem_req_type = _batch_parameters_page->getMemReqType();
340 nb_proc = field("proc_value").toInt();
341 exclusive = field("exclusive").toBool();
344 QString f_result_directory = field("result_directory").toString();
345 result_directory = f_result_directory.trimmed().toUtf8().constData();
346 for (int i = 0; i < _input_files_list->count(); ++i)
348 QListWidgetItem * item = _input_files_list->item(i);
349 QString item_text = item->text();
350 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
352 for (int i = 0; i < _output_files_list->count(); ++i)
354 QListWidgetItem * item = _output_files_list->item(i);
355 QString item_text = item->text();
356 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
360 QString f_resource_choosed = field("resource_choosed").toString();
361 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
364 QString f_batch_queue = field("batch_queue").toString();
365 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
367 // LoadLeveler JobType
368 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
369 std::string batch = resource_descr.batch.c_str();
372 QString f_ll_jobtype = field("ll_jobtype").toString();
373 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
381 QString f_wckey = field("wckey").toString();
382 wckey = f_wckey.trimmed().toUtf8().constData();
385 QString f_extra_params = field("extra_params").toString();
386 extra_params = f_extra_params.trimmed().toUtf8().constData();
388 start_job = field("start_job").toBool();
393 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
394 : QWizardPage(parent)
396 _jobs_manager = jobs_manager;
398 setTitle("Create a new job");
400 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
401 label->setWordWrap(true);
402 QLabel * nameLabel = new QLabel("Job Name:");
403 QLineEdit * _nameLineEdit = new QLineEdit(this);
404 registerField("job_name", _nameLineEdit);
406 QLabel * label_type = new QLabel("Choose type of batch job:");
407 QGroupBox *groupBox = new QGroupBox("Type of job");
408 QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
409 _yacs_schema_button->setChecked(true);
410 QRadioButton * _command_button = new QRadioButton(tr("Command"));
411 QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
412 QVBoxLayout *vbox = new QVBoxLayout;
413 vbox->addWidget(_yacs_schema_button);
414 vbox->addWidget(_command_button);
415 vbox->addWidget(_python_salome_button);
417 groupBox->setLayout(vbox);
418 registerField("job_type_yacs", _yacs_schema_button);
419 registerField("job_type_command", _command_button);
420 registerField("job_type_python_salome", _python_salome_button);
422 QGroupBox * explanationBox = new QGroupBox("Explanation");
423 QVBoxLayout *explanationvbox = new QVBoxLayout;
424 _explanation = new QLabel();
425 _explanation->setWordWrap(true);
426 explanationvbox->addWidget(_explanation);
427 explanationvbox->addStretch(1);
428 explanationBox->setLayout(explanationvbox);
431 QVBoxLayout * main_layout = new QVBoxLayout;
432 main_layout->addWidget(label);
433 QGridLayout *layout = new QGridLayout;
434 layout->addWidget(nameLabel, 0, 0);
435 layout->addWidget(_nameLineEdit, 0, 1);
436 main_layout->insertLayout(-1, layout);
437 layout->addWidget(label_type, 2, 0);
438 layout->addWidget(groupBox, 3, 0, 1, -1);
439 layout->addWidget(explanationBox, 4, 0, 1, -1);
440 setLayout(main_layout);
442 connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
443 connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
444 connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
447 yacs_schema_button(true);
450 BL::JobNamePage::~JobNamePage()
454 BL::JobNamePage::yacs_schema_button(bool checked)
458 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
459 setField("exclusive", true);
464 BL::JobNamePage::command_button(bool checked)
468 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
469 setField("exclusive", false);
474 BL::JobNamePage::python_salome_button(bool checked)
478 _explanation->setText("This job permits to launch a python script into a SALOME application");
479 setField("exclusive", true);
484 BL::JobNamePage::validatePage()
486 DEBTRACE("Calling validatePage of BL::JobNamePage");
488 QString job_name = field("job_name").toString();
490 // Check if job name is empty
493 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
494 return_value = false;
497 // Check if job name already exists
499 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
505 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
507 setField("job_name", value);
508 return_value = false;
516 BL::JobNamePage::nextId() const
518 if (field("job_type_yacs").toBool())
520 return BL::CreateJobWizard::Page_YACSSchema;
522 else if (field("job_type_command").toBool())
524 return BL::CreateJobWizard::Page_Command_Main_Definitions;
528 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
532 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
533 : QWizardPage(parent)
535 setTitle("Configure YACS Execution");
537 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
538 label->setWordWrap(true);
540 QGroupBox * files_param_box = new QGroupBox("YACS job files");
541 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
542 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
543 _yacs_file_text = new QLineEdit(this);
544 _yacs_file_text->setText("");
545 registerField("yacs_file", _yacs_file_text);
546 _yacs_file_text->setReadOnly(true);
547 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
548 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
549 _line_env_file = new QLineEdit(this);
550 registerField("env_yacs_file", _line_env_file);
551 _line_env_file->setReadOnly(true);
552 QGridLayout * files_layout = new QGridLayout;
553 files_layout->addWidget(yacs_file_button, 0, 0);
554 files_layout->addWidget(_yacs_file_text, 0, 1);
555 files_layout->addWidget(command_env_file_button, 1, 0);
556 files_layout->addWidget(_line_env_file, 1, 1);
557 files_param_box->setLayout(files_layout);
559 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
560 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
561 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
562 QSpinBox * spin_dump = new QSpinBox(this);
563 spin_dump->setMinimum(0);
564 spin_dump->setMaximum(1000000);
565 registerField("dump_yacs_state", spin_dump);
566 QGridLayout * specific_layout = new QGridLayout;
567 specific_layout->addWidget(label_dump, 0, 0);
568 specific_layout->addWidget(spin_dump, 0, 1);
569 specific_layout->addWidget(label_dump_warning, 1, 0);
570 spec_param_box->setLayout(specific_layout);
572 QVBoxLayout * main_layout = new QVBoxLayout;
573 main_layout->addWidget(label);
574 main_layout->addWidget(files_param_box);
575 main_layout->addWidget(spec_param_box);
577 setLayout(main_layout);
580 BL::YACSSchemaPage::~YACSSchemaPage()
584 BL::YACSSchemaPage::validatePage()
587 QString yacs_file = field("yacs_file").toString();
594 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
595 return_value = false;
601 BL::YACSSchemaPage::choose_file()
603 QString yacs_file = QFileDialog::getOpenFileName(this,
604 tr("Open YACS files"), "",
605 tr("XML (*.xml);;All Files (*)"));
606 _yacs_file_text->setReadOnly(false);
607 _yacs_file_text->setText(yacs_file);
608 _yacs_file_text->setReadOnly(true);
612 BL::YACSSchemaPage::choose_env_file()
614 QString env_file = QFileDialog::getOpenFileName(this,
615 tr("Open environnement file"), "",
616 tr("sh (*.sh);;All Files (*)"));
617 _line_env_file->setReadOnly(false);
618 _line_env_file->setText(env_file);
619 _line_env_file->setReadOnly(true);
624 BL::YACSSchemaPage::nextId() const
626 return BL::CreateJobWizard::Page_Resource;
629 BL::CommandMainPage::CommandMainPage(QWidget * parent)
630 : QWizardPage(parent)
632 setTitle("Define command job");
633 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
634 label->setWordWrap(true);
637 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
638 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
639 _line_command = new QLineEdit(this);
640 registerField("command", _line_command);
641 _line_command->setReadOnly(true);
643 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
644 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
645 _line_env_file = new QLineEdit(this);
646 registerField("env_command_file", _line_env_file);
647 _line_env_file->setReadOnly(true);
649 QGridLayout *layout = new QGridLayout;
650 layout->addWidget(command_file_button, 0, 0);
651 layout->addWidget(_line_command, 0, 1);
652 layout->addWidget(command_env_file_button, 1, 0);
653 layout->addWidget(_line_env_file, 1, 1);
655 QVBoxLayout * main_layout = new QVBoxLayout;
656 main_layout->addWidget(label);
657 main_layout->insertLayout(-1, layout);
658 setLayout(main_layout);
661 BL::CommandMainPage::~CommandMainPage()
665 BL::CommandMainPage::choose_command_file()
667 QString command_file = QFileDialog::getOpenFileName(this,
668 tr("Open command file"), "",
669 tr("sh (*.sh);;All Files (*)"));
670 _line_command->setReadOnly(false);
671 _line_command->setText(command_file);
672 _line_command->setReadOnly(true);
676 BL::CommandMainPage::choose_env_file()
678 QString env_file = QFileDialog::getOpenFileName(this,
679 tr("Open environnement file"), "",
680 tr("sh (*.sh);;All Files (*)"));
681 _line_env_file->setReadOnly(false);
682 _line_env_file->setText(env_file);
683 _line_env_file->setReadOnly(true);
687 BL::CommandMainPage::validatePage()
689 QString command = field("command").toString();
692 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
700 BL::CommandMainPage::nextId() const
702 return BL::CreateJobWizard::Page_Resource;
705 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
706 : QWizardPage(parent),
707 ui(new Ui::ResourceRequirementsWizardPage),
708 _salome_services(salome_services),
713 registerField("duration_hour", ui->spin_duration_hour);
714 registerField("duration_min", ui->spin_duration_min);
715 registerField("mem_value", ui->spin_memory);
716 registerField("proc_value", ui->spin_proc);
717 registerField("exclusive", ui->check_exclusive);
718 registerField("default_time", ui->rb_default_time);
719 registerField("user_time", ui->rb_user_time);
720 registerField("default_mem", ui->rb_default_mem);
721 registerField("user_mem", ui->rb_user_mem);
723 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
724 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
727 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
728 "per node", Job::MEM_PER_NODE);
729 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
730 "per core", Job::MEM_PER_CPU);
732 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
733 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
734 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
735 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
736 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
739 BatchParametersPage::~BatchParametersPage()
745 BatchParametersPage::initializePage()
747 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
748 if (f_resource_choosed != resource_choosed)
750 resource_choosed = f_resource_choosed;
751 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
752 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
753 if (resource_descr.batch == "slurm")
755 ui->combo_memory_req_type->setEnabled(true);
759 ui->combo_memory_req_type->setEnabled(false);
760 setMemReqType(Job::MEM_PER_NODE);
765 BatchParametersPage::MemUnit
766 BatchParametersPage::getMemUnit() const
768 int idx = ui->combo_memory_unit->currentIndex();
769 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
773 BatchParametersPage::setMemUnit(MemUnit mem_unit)
775 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
779 BatchParametersPage::getMemReqType() const
781 int idx = ui->combo_memory_req_type->currentIndex();
782 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
786 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
788 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
792 BatchParametersPage::timeChanged()
794 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
795 ui->rb_default_time->setChecked(true);
797 ui->rb_user_time->setChecked(true);
801 BatchParametersPage::memChanged()
803 ui->rb_user_mem->setChecked(true);
807 BatchParametersPage::cleanupPage()
812 BatchParametersPage::nextId() const
814 return CreateJobWizard::Page_Files;
817 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
818 : QWizardPage(parent)
820 setTitle("Enter COORM Parameters");
821 resource_choosed = "";
823 _salome_services = salome_services;
825 QLabel *label = new QLabel("In this step you define the parameters for COORM");
826 label->setWordWrap(true);
827 QVBoxLayout * main_layout = new QVBoxLayout;
828 main_layout->addWidget(label);
830 // coorm_batch_directory
831 QLabel * label_directory = new QLabel("Remote work directory: ");
832 QLineEdit * line_directory = new QLineEdit(this);
833 registerField("coorm_batch_directory", line_directory);
836 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
837 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
838 _launcher_file_text = new QLineEdit(this);
839 _launcher_file_text->setText("");
840 registerField("launcher_file", _launcher_file_text);
841 _launcher_file_text->setReadOnly(true);
844 QLabel * launcher_args_label = new QLabel("Launcher args:");
845 QLineEdit * launcher_args_text = new QLineEdit(this);
846 registerField("launcher_args", launcher_args_text);
848 QGridLayout * layout = new QGridLayout;
849 layout->addWidget(label_directory, 0, 0);
850 layout->addWidget(line_directory, 0, 1);
851 layout->addWidget(launcher_file_button, 1, 0);
852 layout->addWidget(_launcher_file_text, 1, 1);
853 layout->addWidget(launcher_args_label, 2, 0);
854 layout->addWidget(launcher_args_text, 2, 1);
856 main_layout->insertLayout(-1, layout);
858 setLayout(main_layout);
861 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
865 BL::COORM_BatchParametersPage::validatePage()
867 QString coorm_batch_directory = field("coorm_batch_directory").toString();
868 if (coorm_batch_directory == "")
870 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
874 QString launcher_file = field("launcher_file").toString();
875 if (launcher_file == "")
877 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
885 BL::COORM_BatchParametersPage::nextId() const
887 return BL::CreateJobWizard::Page_Files;
891 BL::COORM_BatchParametersPage::choose_launcher_file()
893 QString launcher_file = QFileDialog::getOpenFileName(this,
894 tr("Open launcher files"), "",
895 tr("Py (*.py);;All Files (*)"));
896 _launcher_file_text->setReadOnly(false);
897 _launcher_file_text->setText(launcher_file);
898 _launcher_file_text->setReadOnly(true);
901 void BL::COORM_BatchParametersPage::cleanupPage()
905 BL::COORM_BatchParametersPage::initializePage()
907 QString f_resource_choosed = field("resource_choosed").toString();
908 if (f_resource_choosed != resource_choosed)
910 resource_choosed = f_resource_choosed;
911 // If choosed resource has a working_directory set
912 // Generates a default remote working directory
913 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
914 QString res_work_dir = resource_descr.working_directory.c_str();
915 if (res_work_dir != "")
919 std::string launch_date = ctime(&rawtime);
920 for (int i = 0; i < launch_date.size(); i++)
921 if (launch_date[i] == '/' ||
922 launch_date[i] == '-' ||
923 launch_date[i] == ':' ||
924 launch_date[i] == ' ')
925 launch_date[i] = '_';
926 launch_date.erase(--launch_date.end()); // Last caracter is a \n
927 QString date = launch_date.c_str();
928 setField("coorm_batch_directory", res_work_dir + "/" + date);
933 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
934 : QWizardPage(parent),
935 ui(new Ui::FilesWizardPage)
939 resource_choosed = "";
940 _salome_services = salome_services;
942 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
943 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
944 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
945 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
946 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
947 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
948 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
950 registerField("batch_directory", ui->line_remote_working_dir);
951 registerField("result_directory", ui->line_result_dir);
953 // Default result directory is home directory (if we found it)
956 ui->line_result_dir->setText(getenv("HOME"));
959 ui->line_result_dir->setText(getenv("HOME"));
961 // Second try -> getpwuid
962 struct passwd * pass_struct = getpwuid(getuid());
964 ui->line_result_dir->setText(pass_struct->pw_dir);
968 parent->setFilesList(ui->input_files_list, ui->output_files_list);
970 // Check for warning messages
971 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
972 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
973 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
976 FilesPage::~FilesPage()
982 FilesPage::initializePage()
984 QString f_resource_choosed = field("resource_choosed").toString();
985 if (f_resource_choosed != resource_choosed)
987 resource_choosed = f_resource_choosed;
988 // If choosed resource has a working_directory set
989 // Generates a default remote working directory
990 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
991 QString res_work_dir = resource_descr.working_directory.c_str();
992 if (res_work_dir != "")
996 std::string launch_date = ctime(&rawtime);
997 for (int i = 0; i < launch_date.size(); i++)
998 if (launch_date[i] == '/' ||
999 launch_date[i] == '-' ||
1000 launch_date[i] == ':' ||
1001 launch_date[i] == ' ')
1002 launch_date[i] = '_';
1003 launch_date.erase(--launch_date.end()); // Last caracter is a \n
1004 QString date = launch_date.c_str();
1005 setField("batch_directory", res_work_dir + "/" + date);
1011 FilesPage::isComplete() const
1014 if (field("batch_directory").toString().isEmpty())
1015 warn_msg = "Remote working directory is mandatory.";
1016 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1018 if (!warn_msg.isEmpty()) warn_msg += "\n";
1019 warn_msg += "Result directory is mandatory if there are output files.";
1022 ui->label_warning_text->setText(warn_msg);
1023 if (warn_msg.isEmpty())
1025 ui->label_warning_icon->hide();
1030 ui->label_warning_icon->show();
1036 FilesPage::choose_input_files()
1038 QStringList files = QFileDialog::getOpenFileNames(this,
1039 tr("Add input files"), "",
1040 tr("All Files (*)"));
1041 for (int i = 0; i < files.size(); ++i)
1043 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1044 ui->input_files_list->addItem(files.at(i));
1049 FilesPage::choose_local_directory()
1051 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1053 QFileDialog::ShowDirsOnly
1054 | QFileDialog::DontResolveSymlinks);
1057 ui->line_result_dir->setText(dir);
1061 FilesPage::remove_input_files()
1063 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1064 for (int i = 0; i < list.size(); ++i)
1066 int row = ui->input_files_list->row( list.at(i) );
1067 delete ui->input_files_list->takeItem(row);
1072 FilesPage::input_itemSelectionChanged()
1074 if (ui->input_files_list->selectedItems().size() > 0)
1075 ui->remove_input_files_button->setEnabled(true);
1077 ui->remove_input_files_button->setEnabled(false);
1081 FilesPage::add_output_file()
1083 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1084 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1085 ui->output_files_list->addItem(new_item);
1086 emit completeChanged();
1090 FilesPage::remove_output_files()
1092 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1093 for (int i = 0; i < list.size(); ++i)
1095 int row = ui->output_files_list->row( list.at(i) );
1096 delete ui->output_files_list->takeItem(row);
1098 emit completeChanged();
1102 FilesPage::output_itemSelectionChanged()
1104 if (ui->output_files_list->selectedItems().size() > 0)
1105 ui->remove_output_files_button->setEnabled(true);
1107 ui->remove_output_files_button->setEnabled(false);
1111 FilesPage::nextId() const
1113 return BL::CreateJobWizard::Page_Advanced;
1116 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1117 : QWizardPage(parent)
1119 setTitle("Job definition is finished");
1120 QCheckBox * check_box = new QCheckBox("Start job after creation");
1121 registerField("start_job", check_box);
1122 QVBoxLayout * main_layout = new QVBoxLayout;
1123 main_layout->addWidget(check_box);
1124 setLayout(main_layout);
1127 BL::ConclusionPage::~ConclusionPage()
1131 BL::ConclusionPage::validatePage()
1137 BL::ConclusionPage::nextId() const
1142 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1143 : QWizardPage(parent)
1145 _salome_services = salome_services;
1146 setTitle("Select a Resource");
1148 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1149 main_label->setWordWrap(true);
1152 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1153 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1154 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1156 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1157 resource_list_layout->addWidget(_resource_list);
1158 resource_group_box->setLayout(resource_list_layout);
1160 QLabel * resource_label = new QLabel("Resource selected: ");
1161 _resource_choosed = new QLineEdit();
1162 _resource_choosed->setText("");
1163 _resource_choosed->setReadOnly(true);
1164 registerField("resource_choosed", _resource_choosed);
1166 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1167 QLineEdit * _bqLineEdit = new QLineEdit(this);
1168 registerField("batch_queue", _bqLineEdit);
1170 _ll_label = new QLabel("LoadLeveler JobType:", this);
1171 _ll_value = new QLineEdit(this);
1172 registerField("ll_jobtype", _ll_value);
1176 _main_layout = new QGridLayout;
1177 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1178 _main_layout->addWidget(resource_label, 1, 0);
1179 _main_layout->addWidget(_resource_choosed, 1, 1);
1180 _main_layout->addWidget(bqLabel, 2, 0);
1181 _main_layout->addWidget(_bqLineEdit, 2, 1);
1182 setLayout(_main_layout);
1186 BL::ResourcePage::~ResourcePage()
1190 BL::ResourcePage::initializePage()
1192 if (field("ll_jobtype").toString() != "")
1194 _main_layout->addWidget(_ll_label, 3, 0);
1195 _main_layout->addWidget(_ll_value, 3, 1);
1200 // Initialize resource_choosed with first resource in resource list
1201 if (field("resource_choosed").toString() == "")
1203 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1204 std::list<std::string>::iterator it = resource_list.begin();
1205 if (it != resource_list.end())
1207 QString first_resource((*it).c_str());
1208 setField("resource_choosed", first_resource);
1214 BL::ResourcePage::validatePage()
1216 QString resource_choosed = field("resource_choosed").toString();
1217 if (resource_choosed == "")
1219 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1223 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1224 std::string batch = resource_descr.batch.c_str();
1227 QString ll_jobtype = field("ll_jobtype").toString();
1228 if (ll_jobtype == "")
1230 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1238 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1240 _resource_choosed->setReadOnly(false);
1241 _resource_choosed->setText(item->text());
1242 _resource_choosed->setReadOnly(true);
1244 //Specific parameters for LoadLeveler
1245 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1246 std::string batch = resource_descr.batch.c_str();
1249 _main_layout->addWidget(_ll_label, 3, 0);
1250 _main_layout->addWidget(_ll_value, 3, 1);
1256 _main_layout->removeWidget(_ll_value);
1257 _main_layout->removeWidget(_ll_label);
1264 BL::ResourcePage::nextId() const
1266 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1267 std::string batch = resource_descr.batch.c_str();
1268 if (batch == "coorm")
1270 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1274 return BL::CreateJobWizard::Page_BatchParameters;
1278 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1279 : QWizardPage(parent)
1281 setTitle("Define a Python script in SALOME job");
1282 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1283 label->setWordWrap(true);
1286 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1287 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1288 _line_PythonSalome = new QLineEdit(this);
1289 registerField("PythonSalome", _line_PythonSalome);
1290 _line_PythonSalome->setReadOnly(true);
1292 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1293 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1294 _line_env_file = new QLineEdit(this);
1295 registerField("env_PythonSalome_file", _line_env_file);
1296 _line_env_file->setReadOnly(true);
1298 QGridLayout *layout = new QGridLayout;
1299 layout->addWidget(PythonSalome_file_button, 0, 0);
1300 layout->addWidget(_line_PythonSalome, 0, 1);
1301 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1302 layout->addWidget(_line_env_file, 1, 1);
1304 QVBoxLayout * main_layout = new QVBoxLayout;
1305 main_layout->addWidget(label);
1306 main_layout->insertLayout(-1, layout);
1307 setLayout(main_layout);
1310 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1314 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1316 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1317 tr("Open Python script file"), "",
1318 tr("py (*.py);;All Files (*)"));
1319 _line_PythonSalome->setReadOnly(false);
1320 _line_PythonSalome->setText(PythonSalome_file);
1321 _line_PythonSalome->setReadOnly(true);
1325 BL::PythonSalomeMainPage::choose_env_file()
1327 QString env_file = QFileDialog::getOpenFileName(this,
1328 tr("Open environnement file"), "",
1329 tr("sh (*.sh);;All Files (*)"));
1330 _line_env_file->setReadOnly(false);
1331 _line_env_file->setText(env_file);
1332 _line_env_file->setReadOnly(true);
1336 BL::PythonSalomeMainPage::validatePage()
1338 QString PythonSalome = field("PythonSalome").toString();
1339 if (PythonSalome == "")
1341 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1349 BL::PythonSalomeMainPage::nextId() const
1351 return BL::CreateJobWizard::Page_Resource;
1356 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1357 : QWizardPage(parent),
1358 ui(new Ui::AdvancedParametersWizardPage)
1361 registerField("wckey", ui->line_wckey);
1362 registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1365 AdvancedParametersPage::~AdvancedParametersPage()
1371 AdvancedParametersPage::nextId() const
1373 return BL::CreateJobWizard::Page_Conclusion;