1 // Copyright (C) 2009-2016 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 = "";
80 yacs_driver_options = "";
83 setOptions(QWizard::NoBackButtonOnStartPage);
86 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
87 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
89 setPage(Page_JobName, _job_name_page);
90 setPage(Page_BatchParameters, _batch_parameters_page);
93 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
95 setPage(Page_Files, new BL::FilesPage(this, salome_services));
96 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
97 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
98 setPage(Page_Conclusion, new BL::ConclusionPage(this));
101 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
102 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
103 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
105 setWindowTitle("Create Job Wizard");
106 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
109 BL::CreateJobWizard::~CreateJobWizard()
111 DEBTRACE("Destroying BL::CreateJobWizard");
115 BL::CreateJobWizard::clone(const std::string & name)
117 if (_jobs_manager->job_already_exist(name) == true)
119 BL::Job * job = _jobs_manager->getJob(name);
121 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
122 if (job->getState() == BL::Job::CREATED ||
123 job->getState() == BL::Job::ERROR ||
124 job->getState() == BL::Job::FAILED ||
125 job->getState() == BL::Job::NOT_CREATED)
127 setField("job_name", QString(name.c_str()));
128 _job_name_page->_check_name = false;
131 if (job->getType() == BL::Job::YACS_SCHEMA)
133 setField("yacs_file", QString(job->getJobFile().c_str()));
134 setField("job_type_yacs", true);
135 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
136 if (job->getDumpYACSState() != -1)
139 value.setNum(job->getDumpYACSState());
140 setField("dump_yacs_state", value);
142 if (not job->getYacsDriverOptions().empty())
144 setField("yacs_driver_options", job->getYacsDriverOptions().c_str());
147 else if (job->getType() == BL::Job::COMMAND)
149 setField("command", QString(job->getJobFile().c_str()));
150 setField("job_type_command", true);
151 setField("env_command_file", QString(job->getEnvFile().c_str()));
153 else if (job->getType() == BL::Job::PYTHON_SALOME)
155 setField("PythonSalome", QString(job->getJobFile().c_str()));
156 setField("job_type_python_salome", true);
157 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
162 BL::Job::BatchParam batch_params = job->getBatchParameters();
163 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
164 std::string batch = resource_descr.batch.c_str();
165 if (batch == "coorm")
167 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
168 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
169 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
173 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
177 proc_value.setNum(batch_params.nb_proc);
178 setField("proc_value", proc_value);
180 setField("exclusive", batch_params.exclusive);
182 if (batch_params.maximum_duration == "")
184 setField("default_time", true);
185 setField("duration_hour", 0);
186 setField("duration_min", 0);
190 setField("user_time", true);
191 std::size_t pos = batch_params.maximum_duration.find(":");
192 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
194 std::istringstream iss_hour(hour_str);
196 setField("duration_hour", hour);
198 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
200 std::istringstream iss_min(min_str);
202 setField("duration_min", min);
205 long long mem_mb = batch_params.mem_limit;
208 setField("default_mem", true);
212 setField("user_mem", true);
213 if (mem_mb % 1024 == 0)
215 setField("mem_value", mem_mb / 1024);
216 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
220 setField("mem_value", mem_mb);
221 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
223 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
226 BL::Job::FilesParam files_params = job->getFilesParameters();
228 std::list<std::string>::iterator it = files_params.input_files_list.begin();
229 for (; it != files_params.input_files_list.end(); it++)
230 _input_files_list->addItem(QString((*it).c_str()));
231 it = files_params.output_files_list.begin();
232 for (; it != files_params.output_files_list.end(); it++)
233 _output_files_list->addItem(QString((*it).c_str()));
235 setField("result_directory", QString(files_params.result_directory.c_str()));
236 setField("resource_choosed", QString(job->getResource().c_str()));
237 setField("batch_queue", QString(job->getBatchQueue().c_str()));
238 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
239 setField("wckey", QString(job->getWCKey().c_str()));
240 setField("extra_params", QString(job->getExtraParams().c_str()));
245 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
247 _input_files_list = input_files_list;
248 _output_files_list = output_files_list;
252 BL::CreateJobWizard::end(int result)
254 DEBTRACE("End of BL::CreateJobWizard");
258 QString f_job_name = field("job_name").toString();
259 job_name = f_job_name.trimmed().toUtf8().constData();
260 if (field("job_type_yacs").toBool())
262 else if (field("job_type_command").toBool())
265 job_type = PYTHON_SALOME;
268 QString f_yacs_file = field("yacs_file").toString();
269 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
270 dump_yacs_state = field("dump_yacs_state").toInt();
271 yacs_driver_options = field("yacs_driver_options").toString().trimmed().toUtf8().constData();
274 QString f_command = field("command").toString();
275 command = f_command.trimmed().toUtf8().constData();
278 QString f_python_salome_file = field("PythonSalome").toString();
279 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
282 if (job_type == YACS)
283 f_env_file = field("env_yacs_file").toString();
284 else if (job_type == COMMAND)
285 f_env_file = field("env_command_file").toString();
286 else if (job_type == PYTHON_SALOME)
287 f_env_file = field("env_PythonSalome_file").toString();
288 env_file = f_env_file.trimmed().toUtf8().constData();
291 QString f_batch_directory = field("batch_directory").toString();
292 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
295 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
296 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
299 QString f_launcher_file = field("launcher_file").toString();
300 launcher_file = f_launcher_file.toUtf8().constData();
301 QString f_launcher_args = field("launcher_args").toString();
302 launcher_args = f_launcher_args.toUtf8().constData();
306 if (field("default_time").toBool() ||
307 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
309 maximum_duration = "";
313 if (field("duration_hour").toInt() < 10)
314 time_hour = "0" + field("duration_hour").toString().trimmed();
316 time_hour = field("duration_hour").toString().trimmed();
317 if (field("duration_min").toInt() < 10)
318 time_min = "0" + field("duration_min").toString().trimmed();
320 time_min = field("duration_min").toString().trimmed();
321 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
324 if(field("default_mem").toBool())
330 unsigned long mem = field("mem_value").toULongLong();
331 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
334 case BatchParametersPage::MB:
337 case BatchParametersPage::GB:
338 mem_limit = mem * 1024;
341 throw Exception("Invalid memory unit");
343 mem_req_type = _batch_parameters_page->getMemReqType();
346 nb_proc = field("proc_value").toInt();
347 exclusive = field("exclusive").toBool();
350 QString f_result_directory = field("result_directory").toString();
351 result_directory = f_result_directory.trimmed().toUtf8().constData();
352 for (int i = 0; i < _input_files_list->count(); ++i)
354 QListWidgetItem * item = _input_files_list->item(i);
355 QString item_text = item->text();
356 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
358 for (int i = 0; i < _output_files_list->count(); ++i)
360 QListWidgetItem * item = _output_files_list->item(i);
361 QString item_text = item->text();
362 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
366 QString f_resource_choosed = field("resource_choosed").toString();
367 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
370 QString f_batch_queue = field("batch_queue").toString();
371 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
373 // LoadLeveler JobType
374 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
375 std::string batch = resource_descr.batch.c_str();
378 QString f_ll_jobtype = field("ll_jobtype").toString();
379 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
387 QString f_wckey = field("wckey").toString();
388 wckey = f_wckey.trimmed().toUtf8().constData();
391 QString f_extra_params = field("extra_params").toString();
392 extra_params = f_extra_params.trimmed().toUtf8().constData();
394 start_job = field("start_job").toBool();
399 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
400 : QWizardPage(parent)
402 _jobs_manager = jobs_manager;
404 setTitle("Create a new job");
406 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
407 label->setWordWrap(true);
408 QLabel * nameLabel = new QLabel("Job Name:");
409 QLineEdit * _nameLineEdit = new QLineEdit(this);
410 registerField("job_name", _nameLineEdit);
412 QLabel * label_type = new QLabel("Choose type of batch job:");
413 QGroupBox *groupBox = new QGroupBox("Type of job");
414 QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
415 _yacs_schema_button->setChecked(true);
416 QRadioButton * _command_button = new QRadioButton(tr("Command"));
417 QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
418 QVBoxLayout *vbox = new QVBoxLayout;
419 vbox->addWidget(_yacs_schema_button);
420 vbox->addWidget(_command_button);
421 vbox->addWidget(_python_salome_button);
423 groupBox->setLayout(vbox);
424 registerField("job_type_yacs", _yacs_schema_button);
425 registerField("job_type_command", _command_button);
426 registerField("job_type_python_salome", _python_salome_button);
428 QGroupBox * explanationBox = new QGroupBox("Explanation");
429 QVBoxLayout *explanationvbox = new QVBoxLayout;
430 _explanation = new QLabel();
431 _explanation->setWordWrap(true);
432 explanationvbox->addWidget(_explanation);
433 explanationvbox->addStretch(1);
434 explanationBox->setLayout(explanationvbox);
437 QVBoxLayout * main_layout = new QVBoxLayout;
438 main_layout->addWidget(label);
439 QGridLayout *layout = new QGridLayout;
440 layout->addWidget(nameLabel, 0, 0);
441 layout->addWidget(_nameLineEdit, 0, 1);
442 main_layout->insertLayout(-1, layout);
443 layout->addWidget(label_type, 2, 0);
444 layout->addWidget(groupBox, 3, 0, 1, -1);
445 layout->addWidget(explanationBox, 4, 0, 1, -1);
446 setLayout(main_layout);
448 connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
449 connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
450 connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
453 yacs_schema_button(true);
456 BL::JobNamePage::~JobNamePage()
460 BL::JobNamePage::yacs_schema_button(bool checked)
464 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
465 setField("exclusive", true);
470 BL::JobNamePage::command_button(bool checked)
474 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
475 setField("exclusive", false);
480 BL::JobNamePage::python_salome_button(bool checked)
484 _explanation->setText("This job permits to launch a python script into a SALOME application");
485 setField("exclusive", true);
490 BL::JobNamePage::validatePage()
492 DEBTRACE("Calling validatePage of BL::JobNamePage");
494 QString job_name = field("job_name").toString();
496 // Check if job name is empty
499 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
500 return_value = false;
503 // Check if job name already exists
505 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
511 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
513 setField("job_name", value);
514 return_value = false;
522 BL::JobNamePage::nextId() const
524 if (field("job_type_yacs").toBool())
526 return BL::CreateJobWizard::Page_YACSSchema;
528 else if (field("job_type_command").toBool())
530 return BL::CreateJobWizard::Page_Command_Main_Definitions;
534 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
538 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
539 : QWizardPage(parent)
541 setTitle("Configure YACS Execution");
543 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
544 label->setWordWrap(true);
546 QGroupBox * files_param_box = new QGroupBox("YACS job files");
547 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
548 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
549 _yacs_file_text = new QLineEdit(this);
550 _yacs_file_text->setText("");
551 registerField("yacs_file", _yacs_file_text);
552 _yacs_file_text->setReadOnly(true);
553 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
554 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
555 _line_env_file = new QLineEdit(this);
556 registerField("env_yacs_file", _line_env_file);
557 _line_env_file->setReadOnly(true);
558 QGridLayout * files_layout = new QGridLayout;
559 files_layout->addWidget(yacs_file_button, 0, 0);
560 files_layout->addWidget(_yacs_file_text, 0, 1);
561 files_layout->addWidget(command_env_file_button, 1, 0);
562 files_layout->addWidget(_line_env_file, 1, 1);
563 files_param_box->setLayout(files_layout);
565 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
566 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
567 QLabel * label_driver_options = new QLabel("YACS driver options - see YACS driver documentation.");
568 QSpinBox * spin_dump = new QSpinBox(this);
569 spin_dump->setMinimum(0);
570 spin_dump->setMaximum(1000000);
571 registerField("dump_yacs_state", spin_dump);
572 QLineEdit* edit_yacs_driver_options = new QLineEdit(this);
573 registerField("yacs_driver_options", edit_yacs_driver_options);
574 QGridLayout * specific_layout = new QGridLayout;
575 specific_layout->addWidget(label_dump, 0, 0);
576 specific_layout->addWidget(spin_dump, 0, 1);
577 specific_layout->addWidget(label_driver_options, 1, 0);
578 specific_layout->addWidget(edit_yacs_driver_options, 1, 1);
579 spec_param_box->setLayout(specific_layout);
581 QVBoxLayout * main_layout = new QVBoxLayout;
582 main_layout->addWidget(label);
583 main_layout->addWidget(files_param_box);
584 main_layout->addWidget(spec_param_box);
586 setLayout(main_layout);
589 BL::YACSSchemaPage::~YACSSchemaPage()
593 BL::YACSSchemaPage::validatePage()
596 QString yacs_file = field("yacs_file").toString();
603 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
604 return_value = false;
610 BL::YACSSchemaPage::choose_file()
612 QString yacs_file = QFileDialog::getOpenFileName(this,
613 tr("Open YACS files"), "",
614 tr("XML (*.xml);;All Files (*)"));
615 _yacs_file_text->setReadOnly(false);
616 _yacs_file_text->setText(yacs_file);
617 _yacs_file_text->setReadOnly(true);
621 BL::YACSSchemaPage::choose_env_file()
623 QString env_file = QFileDialog::getOpenFileName(this,
624 tr("Open environnement file"), "",
625 tr("sh (*.sh);;All Files (*)"));
626 _line_env_file->setReadOnly(false);
627 _line_env_file->setText(env_file);
628 _line_env_file->setReadOnly(true);
633 BL::YACSSchemaPage::nextId() const
635 return BL::CreateJobWizard::Page_Resource;
638 BL::CommandMainPage::CommandMainPage(QWidget * parent)
639 : QWizardPage(parent)
641 setTitle("Define command job");
642 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
643 label->setWordWrap(true);
646 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
647 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
648 _line_command = new QLineEdit(this);
649 registerField("command", _line_command);
650 _line_command->setReadOnly(true);
652 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
653 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
654 _line_env_file = new QLineEdit(this);
655 registerField("env_command_file", _line_env_file);
656 _line_env_file->setReadOnly(true);
658 QGridLayout *layout = new QGridLayout;
659 layout->addWidget(command_file_button, 0, 0);
660 layout->addWidget(_line_command, 0, 1);
661 layout->addWidget(command_env_file_button, 1, 0);
662 layout->addWidget(_line_env_file, 1, 1);
664 QVBoxLayout * main_layout = new QVBoxLayout;
665 main_layout->addWidget(label);
666 main_layout->insertLayout(-1, layout);
667 setLayout(main_layout);
670 BL::CommandMainPage::~CommandMainPage()
674 BL::CommandMainPage::choose_command_file()
676 QString command_file = QFileDialog::getOpenFileName(this,
677 tr("Open command file"), "",
678 tr("sh (*.sh);;All Files (*)"));
679 _line_command->setReadOnly(false);
680 _line_command->setText(command_file);
681 _line_command->setReadOnly(true);
685 BL::CommandMainPage::choose_env_file()
687 QString env_file = QFileDialog::getOpenFileName(this,
688 tr("Open environnement file"), "",
689 tr("sh (*.sh);;All Files (*)"));
690 _line_env_file->setReadOnly(false);
691 _line_env_file->setText(env_file);
692 _line_env_file->setReadOnly(true);
696 BL::CommandMainPage::validatePage()
698 QString command = field("command").toString();
701 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
709 BL::CommandMainPage::nextId() const
711 return BL::CreateJobWizard::Page_Resource;
714 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
715 : QWizardPage(parent),
716 ui(new Ui::ResourceRequirementsWizardPage),
717 _salome_services(salome_services),
722 registerField("duration_hour", ui->spin_duration_hour);
723 registerField("duration_min", ui->spin_duration_min);
724 registerField("mem_value", ui->spin_memory);
725 registerField("proc_value", ui->spin_proc);
726 registerField("exclusive", ui->check_exclusive);
727 registerField("default_time", ui->rb_default_time);
728 registerField("user_time", ui->rb_user_time);
729 registerField("default_mem", ui->rb_default_mem);
730 registerField("user_mem", ui->rb_user_mem);
732 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
733 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
736 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
737 "per node", Job::MEM_PER_NODE);
738 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
739 "per core", Job::MEM_PER_CPU);
741 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
742 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
743 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
744 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
745 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
748 BatchParametersPage::~BatchParametersPage()
754 BatchParametersPage::initializePage()
756 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
757 if (f_resource_choosed != resource_choosed)
759 resource_choosed = f_resource_choosed;
760 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
761 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
762 if (resource_descr.batch == "slurm")
764 ui->combo_memory_req_type->setEnabled(true);
768 ui->combo_memory_req_type->setEnabled(false);
769 setMemReqType(Job::MEM_PER_NODE);
774 BatchParametersPage::MemUnit
775 BatchParametersPage::getMemUnit() const
777 int idx = ui->combo_memory_unit->currentIndex();
778 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
782 BatchParametersPage::setMemUnit(MemUnit mem_unit)
784 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
788 BatchParametersPage::getMemReqType() const
790 int idx = ui->combo_memory_req_type->currentIndex();
791 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
795 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
797 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
801 BatchParametersPage::timeChanged()
803 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
804 ui->rb_default_time->setChecked(true);
806 ui->rb_user_time->setChecked(true);
810 BatchParametersPage::memChanged()
812 ui->rb_user_mem->setChecked(true);
816 BatchParametersPage::cleanupPage()
821 BatchParametersPage::nextId() const
823 return CreateJobWizard::Page_Files;
826 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
827 : QWizardPage(parent)
829 setTitle("Enter COORM Parameters");
830 resource_choosed = "";
832 _salome_services = salome_services;
834 QLabel *label = new QLabel("In this step you define the parameters for COORM");
835 label->setWordWrap(true);
836 QVBoxLayout * main_layout = new QVBoxLayout;
837 main_layout->addWidget(label);
839 // coorm_batch_directory
840 QLabel * label_directory = new QLabel("Remote work directory: ");
841 QLineEdit * line_directory = new QLineEdit(this);
842 registerField("coorm_batch_directory", line_directory);
845 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
846 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
847 _launcher_file_text = new QLineEdit(this);
848 _launcher_file_text->setText("");
849 registerField("launcher_file", _launcher_file_text);
850 _launcher_file_text->setReadOnly(true);
853 QLabel * launcher_args_label = new QLabel("Launcher args:");
854 QLineEdit * launcher_args_text = new QLineEdit(this);
855 registerField("launcher_args", launcher_args_text);
857 QGridLayout * layout = new QGridLayout;
858 layout->addWidget(label_directory, 0, 0);
859 layout->addWidget(line_directory, 0, 1);
860 layout->addWidget(launcher_file_button, 1, 0);
861 layout->addWidget(_launcher_file_text, 1, 1);
862 layout->addWidget(launcher_args_label, 2, 0);
863 layout->addWidget(launcher_args_text, 2, 1);
865 main_layout->insertLayout(-1, layout);
867 setLayout(main_layout);
870 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
874 BL::COORM_BatchParametersPage::validatePage()
876 QString coorm_batch_directory = field("coorm_batch_directory").toString();
877 if (coorm_batch_directory == "")
879 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
883 QString launcher_file = field("launcher_file").toString();
884 if (launcher_file == "")
886 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
894 BL::COORM_BatchParametersPage::nextId() const
896 return BL::CreateJobWizard::Page_Files;
900 BL::COORM_BatchParametersPage::choose_launcher_file()
902 QString launcher_file = QFileDialog::getOpenFileName(this,
903 tr("Open launcher files"), "",
904 tr("Py (*.py);;All Files (*)"));
905 _launcher_file_text->setReadOnly(false);
906 _launcher_file_text->setText(launcher_file);
907 _launcher_file_text->setReadOnly(true);
910 void BL::COORM_BatchParametersPage::cleanupPage()
914 BL::COORM_BatchParametersPage::initializePage()
916 QString f_resource_choosed = field("resource_choosed").toString();
917 if (f_resource_choosed != resource_choosed)
919 resource_choosed = f_resource_choosed;
920 // If choosed resource has a working_directory set
921 // Generates a default remote working directory
922 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
923 QString res_work_dir = resource_descr.working_directory.c_str();
924 if (res_work_dir != "")
928 std::string launch_date = ctime(&rawtime);
929 for (int i = 0; i < launch_date.size(); i++)
930 if (launch_date[i] == '/' ||
931 launch_date[i] == '-' ||
932 launch_date[i] == ':' ||
933 launch_date[i] == ' ')
934 launch_date[i] = '_';
935 launch_date.erase(--launch_date.end()); // Last caracter is a \n
936 QString date = launch_date.c_str();
937 setField("coorm_batch_directory", res_work_dir + "/" + date);
942 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
943 : QWizardPage(parent),
944 ui(new Ui::FilesWizardPage)
948 resource_choosed = "";
949 _salome_services = salome_services;
951 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
952 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
953 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
954 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
955 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
956 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
957 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
959 registerField("batch_directory", ui->line_remote_working_dir);
960 registerField("result_directory", ui->line_result_dir);
962 // Default result directory is home directory (if we found it)
965 ui->line_result_dir->setText(getenv("HOME"));
968 ui->line_result_dir->setText(getenv("HOME"));
970 // Second try -> getpwuid
971 struct passwd * pass_struct = getpwuid(getuid());
973 ui->line_result_dir->setText(pass_struct->pw_dir);
977 parent->setFilesList(ui->input_files_list, ui->output_files_list);
979 // Check for warning messages
980 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
981 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
982 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
985 FilesPage::~FilesPage()
991 FilesPage::initializePage()
993 QString f_resource_choosed = field("resource_choosed").toString();
994 if (f_resource_choosed != resource_choosed)
996 resource_choosed = f_resource_choosed;
997 // If choosed resource has a working_directory set
998 // Generates a default remote working directory
999 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1000 QString res_work_dir = resource_descr.working_directory.c_str();
1001 if (res_work_dir != "")
1005 std::string launch_date = ctime(&rawtime);
1006 for (int i = 0; i < launch_date.size(); i++)
1007 if (launch_date[i] == '/' ||
1008 launch_date[i] == '-' ||
1009 launch_date[i] == ':' ||
1010 launch_date[i] == ' ')
1011 launch_date[i] = '_';
1012 launch_date.erase(--launch_date.end()); // Last caracter is a \n
1013 QString date = launch_date.c_str();
1014 setField("batch_directory", res_work_dir + "/" + date);
1020 FilesPage::isComplete() const
1023 if (field("batch_directory").toString().isEmpty())
1024 warn_msg = "Remote working directory is mandatory.";
1025 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1027 if (!warn_msg.isEmpty()) warn_msg += "\n";
1028 warn_msg += "Result directory is mandatory if there are output files.";
1031 ui->label_warning_text->setText(warn_msg);
1032 if (warn_msg.isEmpty())
1034 ui->label_warning_icon->hide();
1039 ui->label_warning_icon->show();
1045 FilesPage::choose_input_files()
1047 QStringList files = QFileDialog::getOpenFileNames(this,
1048 tr("Add input files"), "",
1049 tr("All Files (*)"));
1050 for (int i = 0; i < files.size(); ++i)
1052 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1053 ui->input_files_list->addItem(files.at(i));
1058 FilesPage::choose_local_directory()
1060 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1062 QFileDialog::ShowDirsOnly
1063 | QFileDialog::DontResolveSymlinks);
1066 ui->line_result_dir->setText(dir);
1070 FilesPage::remove_input_files()
1072 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1073 for (int i = 0; i < list.size(); ++i)
1075 int row = ui->input_files_list->row( list.at(i) );
1076 delete ui->input_files_list->takeItem(row);
1081 FilesPage::input_itemSelectionChanged()
1083 if (ui->input_files_list->selectedItems().size() > 0)
1084 ui->remove_input_files_button->setEnabled(true);
1086 ui->remove_input_files_button->setEnabled(false);
1090 FilesPage::add_output_file()
1092 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1093 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1094 ui->output_files_list->addItem(new_item);
1095 emit completeChanged();
1099 FilesPage::remove_output_files()
1101 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1102 for (int i = 0; i < list.size(); ++i)
1104 int row = ui->output_files_list->row( list.at(i) );
1105 delete ui->output_files_list->takeItem(row);
1107 emit completeChanged();
1111 FilesPage::output_itemSelectionChanged()
1113 if (ui->output_files_list->selectedItems().size() > 0)
1114 ui->remove_output_files_button->setEnabled(true);
1116 ui->remove_output_files_button->setEnabled(false);
1120 FilesPage::nextId() const
1122 return BL::CreateJobWizard::Page_Advanced;
1125 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1126 : QWizardPage(parent)
1128 setTitle("Job definition is finished");
1129 QCheckBox * check_box = new QCheckBox("Start job after creation");
1130 registerField("start_job", check_box);
1131 QVBoxLayout * main_layout = new QVBoxLayout;
1132 main_layout->addWidget(check_box);
1133 setLayout(main_layout);
1136 BL::ConclusionPage::~ConclusionPage()
1140 BL::ConclusionPage::validatePage()
1146 BL::ConclusionPage::nextId() const
1151 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1152 : QWizardPage(parent)
1154 _salome_services = salome_services;
1155 setTitle("Select a Resource");
1157 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1158 main_label->setWordWrap(true);
1161 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1162 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1163 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1165 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1166 resource_list_layout->addWidget(_resource_list);
1167 resource_group_box->setLayout(resource_list_layout);
1169 QLabel * resource_label = new QLabel("Resource selected: ");
1170 _resource_choosed = new QLineEdit();
1171 _resource_choosed->setText("");
1172 _resource_choosed->setReadOnly(true);
1173 registerField("resource_choosed", _resource_choosed);
1175 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1176 QLineEdit * _bqLineEdit = new QLineEdit(this);
1177 registerField("batch_queue", _bqLineEdit);
1179 _ll_label = new QLabel("LoadLeveler JobType:", this);
1180 _ll_value = new QLineEdit(this);
1181 registerField("ll_jobtype", _ll_value);
1185 _main_layout = new QGridLayout;
1186 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1187 _main_layout->addWidget(resource_label, 1, 0);
1188 _main_layout->addWidget(_resource_choosed, 1, 1);
1189 _main_layout->addWidget(bqLabel, 2, 0);
1190 _main_layout->addWidget(_bqLineEdit, 2, 1);
1191 setLayout(_main_layout);
1195 BL::ResourcePage::~ResourcePage()
1199 BL::ResourcePage::initializePage()
1201 if (field("ll_jobtype").toString() != "")
1203 _main_layout->addWidget(_ll_label, 3, 0);
1204 _main_layout->addWidget(_ll_value, 3, 1);
1209 // Initialize resource_choosed with first resource in resource list
1210 if (field("resource_choosed").toString() == "")
1212 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1213 std::list<std::string>::iterator it = resource_list.begin();
1214 if (it != resource_list.end())
1216 QString first_resource((*it).c_str());
1217 setField("resource_choosed", first_resource);
1223 BL::ResourcePage::validatePage()
1225 QString resource_choosed = field("resource_choosed").toString();
1226 if (resource_choosed == "")
1228 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1232 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1233 std::string batch = resource_descr.batch.c_str();
1236 QString ll_jobtype = field("ll_jobtype").toString();
1237 if (ll_jobtype == "")
1239 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1247 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1249 _resource_choosed->setReadOnly(false);
1250 _resource_choosed->setText(item->text());
1251 _resource_choosed->setReadOnly(true);
1253 //Specific parameters for LoadLeveler
1254 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1255 std::string batch = resource_descr.batch.c_str();
1258 _main_layout->addWidget(_ll_label, 3, 0);
1259 _main_layout->addWidget(_ll_value, 3, 1);
1265 _main_layout->removeWidget(_ll_value);
1266 _main_layout->removeWidget(_ll_label);
1273 BL::ResourcePage::nextId() const
1275 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1276 std::string batch = resource_descr.batch.c_str();
1277 if (batch == "coorm")
1279 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1283 return BL::CreateJobWizard::Page_BatchParameters;
1287 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1288 : QWizardPage(parent)
1290 setTitle("Define a Python script in SALOME job");
1291 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1292 label->setWordWrap(true);
1295 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1296 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1297 _line_PythonSalome = new QLineEdit(this);
1298 registerField("PythonSalome", _line_PythonSalome);
1299 _line_PythonSalome->setReadOnly(true);
1301 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1302 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1303 _line_env_file = new QLineEdit(this);
1304 registerField("env_PythonSalome_file", _line_env_file);
1305 _line_env_file->setReadOnly(true);
1307 QGridLayout *layout = new QGridLayout;
1308 layout->addWidget(PythonSalome_file_button, 0, 0);
1309 layout->addWidget(_line_PythonSalome, 0, 1);
1310 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1311 layout->addWidget(_line_env_file, 1, 1);
1313 QVBoxLayout * main_layout = new QVBoxLayout;
1314 main_layout->addWidget(label);
1315 main_layout->insertLayout(-1, layout);
1316 setLayout(main_layout);
1319 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1323 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1325 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1326 tr("Open Python script file"), "",
1327 tr("py (*.py);;All Files (*)"));
1328 _line_PythonSalome->setReadOnly(false);
1329 _line_PythonSalome->setText(PythonSalome_file);
1330 _line_PythonSalome->setReadOnly(true);
1334 BL::PythonSalomeMainPage::choose_env_file()
1336 QString env_file = QFileDialog::getOpenFileName(this,
1337 tr("Open environnement file"), "",
1338 tr("sh (*.sh);;All Files (*)"));
1339 _line_env_file->setReadOnly(false);
1340 _line_env_file->setText(env_file);
1341 _line_env_file->setReadOnly(true);
1345 BL::PythonSalomeMainPage::validatePage()
1347 QString PythonSalome = field("PythonSalome").toString();
1348 if (PythonSalome == "")
1350 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1358 BL::PythonSalomeMainPage::nextId() const
1360 return BL::CreateJobWizard::Page_Resource;
1365 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1366 : QWizardPage(parent),
1367 ui(new Ui::AdvancedParametersWizardPage)
1370 registerField("wckey", ui->line_wckey);
1371 registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1374 AdvancedParametersPage::~AdvancedParametersPage()
1380 AdvancedParametersPage::nextId() const
1382 return BL::CreateJobWizard::Page_Conclusion;