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"
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;
53 python_salome_file = "";
58 coorm_batch_directory = "";
60 maximum_duration = "";
62 mem_req_type = BL::Job::MEM_PER_NODE;
65 // Parameters for COORM
69 result_directory = "";
71 resource_choosed = "";
78 setOptions(QWizard::NoBackButtonOnStartPage);
81 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
82 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
84 setPage(Page_JobName, _job_name_page);
85 setPage(Page_BatchParameters, _batch_parameters_page);
88 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
90 setPage(Page_Files, new BL::FilesPage(this, salome_services));
91 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
92 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
93 setPage(Page_Conclusion, new BL::ConclusionPage(this));
96 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
97 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
98 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
100 setWindowTitle("Create Job Wizard");
101 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
104 BL::CreateJobWizard::~CreateJobWizard()
106 DEBTRACE("Destroying BL::CreateJobWizard");
110 BL::CreateJobWizard::clone(const std::string & name)
112 if (_jobs_manager->job_already_exist(name) == true)
114 BL::Job * job = _jobs_manager->getJob(name);
116 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
117 if (job->getState() == BL::Job::CREATED ||
118 job->getState() == BL::Job::ERROR ||
119 job->getState() == BL::Job::FAILED ||
120 job->getState() == BL::Job::NOT_CREATED)
122 setField("job_name", QString(name.c_str()));
123 _job_name_page->_check_name = false;
126 if (job->getType() == BL::Job::YACS_SCHEMA)
128 setField("yacs_file", QString(job->getJobFile().c_str()));
129 setField("job_type_yacs", true);
130 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
131 if (job->getDumpYACSState() != -1)
134 value.setNum(job->getDumpYACSState());
135 setField("dump_yacs_state", value);
138 else if (job->getType() == BL::Job::COMMAND)
140 setField("command", QString(job->getJobFile().c_str()));
141 setField("job_type_command", true);
142 setField("env_command_file", QString(job->getEnvFile().c_str()));
144 else if (job->getType() == BL::Job::PYTHON_SALOME)
146 setField("PythonSalome", QString(job->getJobFile().c_str()));
147 setField("job_type_python_salome", true);
148 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
153 BL::Job::BatchParam batch_params = job->getBatchParameters();
154 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
155 std::string batch = resource_descr.batch.c_str();
156 if (batch == "coorm")
158 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
159 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
160 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
164 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
168 proc_value.setNum(batch_params.nb_proc);
169 setField("proc_value", proc_value);
171 setField("exclusive", batch_params.exclusive);
173 if (batch_params.maximum_duration == "")
175 setField("default_time", true);
176 setField("duration_hour", 0);
177 setField("duration_min", 0);
181 setField("user_time", true);
182 std::size_t pos = batch_params.maximum_duration.find(":");
183 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
185 std::istringstream iss_hour(hour_str);
187 setField("duration_hour", hour);
189 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
191 std::istringstream iss_min(min_str);
193 setField("duration_min", min);
196 long long mem_mb = batch_params.mem_limit;
199 setField("default_mem", true);
203 setField("user_mem", true);
204 if (mem_mb % 1024 == 0)
206 setField("mem_value", mem_mb / 1024);
207 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
211 setField("mem_value", mem_mb);
212 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
214 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
217 BL::Job::FilesParam files_params = job->getFilesParameters();
219 std::list<std::string>::iterator it = files_params.input_files_list.begin();
220 for (; it != files_params.input_files_list.end(); it++)
221 _input_files_list->addItem(QString((*it).c_str()));
222 it = files_params.output_files_list.begin();
223 for (; it != files_params.output_files_list.end(); it++)
224 _output_files_list->addItem(QString((*it).c_str()));
226 setField("result_directory", QString(files_params.result_directory.c_str()));
227 setField("resource_choosed", QString(job->getResource().c_str()));
228 setField("batch_queue", QString(job->getBatchQueue().c_str()));
229 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
230 setField("wckey", QString(job->getWCKey().c_str()));
231 setField("extra_params", QString(job->getExtraParams().c_str()));
236 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
238 _input_files_list = input_files_list;
239 _output_files_list = output_files_list;
243 BL::CreateJobWizard::end(int result)
245 DEBTRACE("End of BL::CreateJobWizard");
249 QString f_job_name = field("job_name").toString();
250 job_name = f_job_name.trimmed().toUtf8().constData();
251 if (field("job_type_yacs").toBool())
253 else if (field("job_type_command").toBool())
256 job_type = PYTHON_SALOME;
259 QString f_yacs_file = field("yacs_file").toString();
260 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
261 dump_yacs_state = field("dump_yacs_state").toInt();
264 QString f_command = field("command").toString();
265 command = f_command.trimmed().toUtf8().constData();
268 QString f_python_salome_file = field("PythonSalome").toString();
269 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
272 if (job_type == YACS)
273 f_env_file = field("env_yacs_file").toString();
274 else if (job_type == COMMAND)
275 f_env_file = field("env_command_file").toString();
276 else if (job_type == PYTHON_SALOME)
277 f_env_file = field("env_PythonSalome_file").toString();
278 env_file = f_env_file.trimmed().toUtf8().constData();
281 QString f_batch_directory = field("batch_directory").toString();
282 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
285 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
286 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
289 QString f_launcher_file = field("launcher_file").toString();
290 launcher_file = f_launcher_file.toUtf8().constData();
291 QString f_launcher_args = field("launcher_args").toString();
292 launcher_args = f_launcher_args.toUtf8().constData();
296 if (field("default_time").toBool() ||
297 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
299 maximum_duration = "";
303 if (field("duration_hour").toInt() < 10)
304 time_hour = "0" + field("duration_hour").toString().trimmed();
306 time_hour = field("duration_hour").toString().trimmed();
307 if (field("duration_min").toInt() < 10)
308 time_min = "0" + field("duration_min").toString().trimmed();
310 time_min = field("duration_min").toString().trimmed();
311 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
314 if(field("default_mem").toBool())
320 unsigned long mem = field("mem_value").toULongLong();
321 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
324 case BatchParametersPage::MB:
327 case BatchParametersPage::GB:
328 mem_limit = mem * 1024;
331 throw Exception("Invalid memory unit");
333 mem_req_type = _batch_parameters_page->getMemReqType();
336 nb_proc = field("proc_value").toInt();
337 exclusive = field("exclusive").toBool();
340 QString f_result_directory = field("result_directory").toString();
341 result_directory = f_result_directory.trimmed().toUtf8().constData();
342 for (int i = 0; i < _input_files_list->count(); ++i)
344 QListWidgetItem * item = _input_files_list->item(i);
345 QString item_text = item->text();
346 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
348 for (int i = 0; i < _output_files_list->count(); ++i)
350 QListWidgetItem * item = _output_files_list->item(i);
351 QString item_text = item->text();
352 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
356 QString f_resource_choosed = field("resource_choosed").toString();
357 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
360 QString f_batch_queue = field("batch_queue").toString();
361 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
363 // LoadLeveler JobType
364 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
365 std::string batch = resource_descr.batch.c_str();
368 QString f_ll_jobtype = field("ll_jobtype").toString();
369 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
377 QString f_wckey = field("wckey").toString();
378 wckey = f_wckey.trimmed().toUtf8().constData();
381 QString f_extra_params = field("extra_params").toString();
382 extra_params = f_extra_params.trimmed().toUtf8().constData();
384 start_job = field("start_job").toBool();
389 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
390 : QWizardPage(parent)
392 _jobs_manager = jobs_manager;
394 setTitle("Create a new job");
396 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
397 label->setWordWrap(true);
398 QLabel * nameLabel = new QLabel("Job Name:");
399 QLineEdit * _nameLineEdit = new QLineEdit(this);
400 registerField("job_name", _nameLineEdit);
402 QLabel * label_type = new QLabel("Choose type of batch job:");
403 QGroupBox *groupBox = new QGroupBox("Type of job");
404 QRadioButton * _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
405 _yacs_schema_button->setChecked(true);
406 QRadioButton * _command_button = new QRadioButton(tr("Command"));
407 QRadioButton * _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
408 QVBoxLayout *vbox = new QVBoxLayout;
409 vbox->addWidget(_yacs_schema_button);
410 vbox->addWidget(_command_button);
411 vbox->addWidget(_python_salome_button);
413 groupBox->setLayout(vbox);
414 registerField("job_type_yacs", _yacs_schema_button);
415 registerField("job_type_command", _command_button);
416 registerField("job_type_python_salome", _python_salome_button);
418 QGroupBox * explanationBox = new QGroupBox("Explanation");
419 QVBoxLayout *explanationvbox = new QVBoxLayout;
420 _explanation = new QLabel();
421 _explanation->setWordWrap(true);
422 explanationvbox->addWidget(_explanation);
423 explanationvbox->addStretch(1);
424 explanationBox->setLayout(explanationvbox);
427 QVBoxLayout * main_layout = new QVBoxLayout;
428 main_layout->addWidget(label);
429 QGridLayout *layout = new QGridLayout;
430 layout->addWidget(nameLabel, 0, 0);
431 layout->addWidget(_nameLineEdit, 0, 1);
432 main_layout->insertLayout(-1, layout);
433 layout->addWidget(label_type, 2, 0);
434 layout->addWidget(groupBox, 3, 0, 1, -1);
435 layout->addWidget(explanationBox, 4, 0, 1, -1);
436 setLayout(main_layout);
438 connect(_yacs_schema_button, SIGNAL(toggled(bool)), this, SLOT(yacs_schema_button(bool)));
439 connect(_command_button, SIGNAL(toggled(bool)), this, SLOT(command_button(bool)));
440 connect(_python_salome_button, SIGNAL(toggled(bool)), this, SLOT(python_salome_button(bool)));
443 yacs_schema_button(true);
446 BL::JobNamePage::~JobNamePage()
450 BL::JobNamePage::yacs_schema_button(bool checked)
454 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
455 setField("exclusive", true);
460 BL::JobNamePage::command_button(bool checked)
464 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
465 setField("exclusive", false);
470 BL::JobNamePage::python_salome_button(bool checked)
474 _explanation->setText("This job permits to launch a python script into a SALOME application");
475 setField("exclusive", true);
480 BL::JobNamePage::validatePage()
482 DEBTRACE("Calling validatePage of BL::JobNamePage");
484 QString job_name = field("job_name").toString();
486 // Check if job name is empty
489 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
490 return_value = false;
493 // Check if job name already exists
495 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
501 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
503 setField("job_name", value);
504 return_value = false;
512 BL::JobNamePage::nextId() const
514 if (field("job_type_yacs").toBool())
516 return BL::CreateJobWizard::Page_YACSSchema;
518 else if (field("job_type_command").toBool())
520 return BL::CreateJobWizard::Page_Command_Main_Definitions;
524 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
528 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
529 : QWizardPage(parent)
531 setTitle("Configure YACS Execution");
533 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
534 label->setWordWrap(true);
536 QGroupBox * files_param_box = new QGroupBox("YACS job files");
537 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
538 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
539 _yacs_file_text = new QLineEdit(this);
540 _yacs_file_text->setText("");
541 registerField("yacs_file", _yacs_file_text);
542 _yacs_file_text->setReadOnly(true);
543 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
544 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
545 _line_env_file = new QLineEdit(this);
546 registerField("env_yacs_file", _line_env_file);
547 _line_env_file->setReadOnly(true);
548 QGridLayout * files_layout = new QGridLayout;
549 files_layout->addWidget(yacs_file_button, 0, 0);
550 files_layout->addWidget(_yacs_file_text, 0, 1);
551 files_layout->addWidget(command_env_file_button, 1, 0);
552 files_layout->addWidget(_line_env_file, 1, 1);
553 files_param_box->setLayout(files_layout);
555 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
556 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
557 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
558 QSpinBox * spin_dump = new QSpinBox(this);
559 spin_dump->setMinimum(0);
560 spin_dump->setMaximum(1000000);
561 registerField("dump_yacs_state", spin_dump);
562 QGridLayout * specific_layout = new QGridLayout;
563 specific_layout->addWidget(label_dump, 0, 0);
564 specific_layout->addWidget(spin_dump, 0, 1);
565 specific_layout->addWidget(label_dump_warning, 1, 0);
566 spec_param_box->setLayout(specific_layout);
568 QVBoxLayout * main_layout = new QVBoxLayout;
569 main_layout->addWidget(label);
570 main_layout->addWidget(files_param_box);
571 main_layout->addWidget(spec_param_box);
573 setLayout(main_layout);
576 BL::YACSSchemaPage::~YACSSchemaPage()
580 BL::YACSSchemaPage::validatePage()
583 QString yacs_file = field("yacs_file").toString();
590 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
591 return_value = false;
597 BL::YACSSchemaPage::choose_file()
599 QString yacs_file = QFileDialog::getOpenFileName(this,
600 tr("Open YACS files"), "",
601 tr("XML (*.xml);;All Files (*)"));
602 _yacs_file_text->setReadOnly(false);
603 _yacs_file_text->setText(yacs_file);
604 _yacs_file_text->setReadOnly(true);
608 BL::YACSSchemaPage::choose_env_file()
610 QString env_file = QFileDialog::getOpenFileName(this,
611 tr("Open environnement file"), "",
612 tr("sh (*.sh);;All Files (*)"));
613 _line_env_file->setReadOnly(false);
614 _line_env_file->setText(env_file);
615 _line_env_file->setReadOnly(true);
620 BL::YACSSchemaPage::nextId() const
622 return BL::CreateJobWizard::Page_Resource;
625 BL::CommandMainPage::CommandMainPage(QWidget * parent)
626 : QWizardPage(parent)
628 setTitle("Define command job");
629 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
630 label->setWordWrap(true);
633 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
634 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
635 _line_command = new QLineEdit(this);
636 registerField("command", _line_command);
637 _line_command->setReadOnly(true);
639 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
640 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
641 _line_env_file = new QLineEdit(this);
642 registerField("env_command_file", _line_env_file);
643 _line_env_file->setReadOnly(true);
645 QGridLayout *layout = new QGridLayout;
646 layout->addWidget(command_file_button, 0, 0);
647 layout->addWidget(_line_command, 0, 1);
648 layout->addWidget(command_env_file_button, 1, 0);
649 layout->addWidget(_line_env_file, 1, 1);
651 QVBoxLayout * main_layout = new QVBoxLayout;
652 main_layout->addWidget(label);
653 main_layout->insertLayout(-1, layout);
654 setLayout(main_layout);
657 BL::CommandMainPage::~CommandMainPage()
661 BL::CommandMainPage::choose_command_file()
663 QString command_file = QFileDialog::getOpenFileName(this,
664 tr("Open command file"), "",
665 tr("sh (*.sh);;All Files (*)"));
666 _line_command->setReadOnly(false);
667 _line_command->setText(command_file);
668 _line_command->setReadOnly(true);
672 BL::CommandMainPage::choose_env_file()
674 QString env_file = QFileDialog::getOpenFileName(this,
675 tr("Open environnement file"), "",
676 tr("sh (*.sh);;All Files (*)"));
677 _line_env_file->setReadOnly(false);
678 _line_env_file->setText(env_file);
679 _line_env_file->setReadOnly(true);
683 BL::CommandMainPage::validatePage()
685 QString command = field("command").toString();
688 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
696 BL::CommandMainPage::nextId() const
698 return BL::CreateJobWizard::Page_Resource;
701 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
702 : QWizardPage(parent),
703 ui(new Ui::ResourceRequirementsWizardPage),
704 _salome_services(salome_services),
709 registerField("duration_hour", ui->spin_duration_hour);
710 registerField("duration_min", ui->spin_duration_min);
711 registerField("mem_value", ui->spin_memory);
712 registerField("proc_value", ui->spin_proc);
713 registerField("exclusive", ui->check_exclusive);
714 registerField("default_time", ui->rb_default_time);
715 registerField("user_time", ui->rb_user_time);
716 registerField("default_mem", ui->rb_default_mem);
717 registerField("user_mem", ui->rb_user_mem);
719 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
720 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
723 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
724 "per node", Job::MEM_PER_NODE);
725 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
726 "per core", Job::MEM_PER_CPU);
728 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
729 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
730 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
731 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
732 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
735 BatchParametersPage::~BatchParametersPage()
741 BatchParametersPage::initializePage()
743 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
744 if (f_resource_choosed != resource_choosed)
746 resource_choosed = f_resource_choosed;
747 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
748 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
749 if (resource_descr.batch == "slurm")
751 ui->combo_memory_req_type->setEnabled(true);
755 ui->combo_memory_req_type->setEnabled(false);
756 setMemReqType(Job::MEM_PER_NODE);
761 BatchParametersPage::MemUnit
762 BatchParametersPage::getMemUnit() const
764 int idx = ui->combo_memory_unit->currentIndex();
765 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
769 BatchParametersPage::setMemUnit(MemUnit mem_unit)
771 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
775 BatchParametersPage::getMemReqType() const
777 int idx = ui->combo_memory_req_type->currentIndex();
778 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
782 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
784 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
788 BatchParametersPage::timeChanged()
790 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
791 ui->rb_default_time->setChecked(true);
793 ui->rb_user_time->setChecked(true);
797 BatchParametersPage::memChanged()
799 ui->rb_user_mem->setChecked(true);
803 BatchParametersPage::cleanupPage()
808 BatchParametersPage::nextId() const
810 return CreateJobWizard::Page_Files;
813 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
814 : QWizardPage(parent)
816 setTitle("Enter COORM Parameters");
817 resource_choosed = "";
819 _salome_services = salome_services;
821 QLabel *label = new QLabel("In this step you define the parameters for COORM");
822 label->setWordWrap(true);
823 QVBoxLayout * main_layout = new QVBoxLayout;
824 main_layout->addWidget(label);
826 // coorm_batch_directory
827 QLabel * label_directory = new QLabel("Remote work directory: ");
828 QLineEdit * line_directory = new QLineEdit(this);
829 registerField("coorm_batch_directory", line_directory);
832 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
833 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
834 _launcher_file_text = new QLineEdit(this);
835 _launcher_file_text->setText("");
836 registerField("launcher_file", _launcher_file_text);
837 _launcher_file_text->setReadOnly(true);
840 QLabel * launcher_args_label = new QLabel("Launcher args:");
841 QLineEdit * launcher_args_text = new QLineEdit(this);
842 registerField("launcher_args", launcher_args_text);
844 QGridLayout * layout = new QGridLayout;
845 layout->addWidget(label_directory, 0, 0);
846 layout->addWidget(line_directory, 0, 1);
847 layout->addWidget(launcher_file_button, 1, 0);
848 layout->addWidget(_launcher_file_text, 1, 1);
849 layout->addWidget(launcher_args_label, 2, 0);
850 layout->addWidget(launcher_args_text, 2, 1);
852 main_layout->insertLayout(-1, layout);
854 setLayout(main_layout);
857 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
861 BL::COORM_BatchParametersPage::validatePage()
863 QString coorm_batch_directory = field("coorm_batch_directory").toString();
864 if (coorm_batch_directory == "")
866 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
870 QString launcher_file = field("launcher_file").toString();
871 if (launcher_file == "")
873 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
881 BL::COORM_BatchParametersPage::nextId() const
883 return BL::CreateJobWizard::Page_Files;
887 BL::COORM_BatchParametersPage::choose_launcher_file()
889 QString launcher_file = QFileDialog::getOpenFileName(this,
890 tr("Open launcher files"), "",
891 tr("Py (*.py);;All Files (*)"));
892 _launcher_file_text->setReadOnly(false);
893 _launcher_file_text->setText(launcher_file);
894 _launcher_file_text->setReadOnly(true);
897 void BL::COORM_BatchParametersPage::cleanupPage()
901 BL::COORM_BatchParametersPage::initializePage()
903 QString f_resource_choosed = field("resource_choosed").toString();
904 if (f_resource_choosed != resource_choosed)
906 resource_choosed = f_resource_choosed;
907 // If choosed resource has a working_directory set
908 // Generates a default remote working directory
909 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
910 QString res_work_dir = resource_descr.working_directory.c_str();
911 if (res_work_dir != "")
915 std::string launch_date = ctime(&rawtime);
916 for (int i = 0; i < launch_date.size(); i++)
917 if (launch_date[i] == '/' ||
918 launch_date[i] == '-' ||
919 launch_date[i] == ':' ||
920 launch_date[i] == ' ')
921 launch_date[i] = '_';
922 launch_date.erase(--launch_date.end()); // Last caracter is a \n
923 QString date = launch_date.c_str();
924 setField("coorm_batch_directory", res_work_dir + "/" + date);
929 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
930 : QWizardPage(parent),
931 ui(new Ui::FilesWizardPage)
935 resource_choosed = "";
936 _salome_services = salome_services;
938 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
939 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
940 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
941 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
942 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
943 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
944 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
946 registerField("batch_directory", ui->line_remote_working_dir);
947 registerField("result_directory", ui->line_result_dir);
949 // Default result directory is home directory (if we found it)
952 ui->line_result_dir->setText(getenv("HOME"));
955 ui->line_result_dir->setText(getenv("HOME"));
957 // Second try -> getpwuid
958 struct passwd * pass_struct = getpwuid(getuid());
960 ui->line_result_dir->setText(pass_struct->pw_dir);
964 parent->setFilesList(ui->input_files_list, ui->output_files_list);
966 // Check for warning messages
967 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
968 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
969 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
972 FilesPage::~FilesPage()
978 FilesPage::initializePage()
980 QString f_resource_choosed = field("resource_choosed").toString();
981 if (f_resource_choosed != resource_choosed)
983 resource_choosed = f_resource_choosed;
984 // If choosed resource has a working_directory set
985 // Generates a default remote working directory
986 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
987 QString res_work_dir = resource_descr.working_directory.c_str();
988 if (res_work_dir != "")
992 std::string launch_date = ctime(&rawtime);
993 for (int i = 0; i < launch_date.size(); i++)
994 if (launch_date[i] == '/' ||
995 launch_date[i] == '-' ||
996 launch_date[i] == ':' ||
997 launch_date[i] == ' ')
998 launch_date[i] = '_';
999 launch_date.erase(--launch_date.end()); // Last caracter is a \n
1000 QString date = launch_date.c_str();
1001 setField("batch_directory", res_work_dir + "/" + date);
1007 FilesPage::isComplete() const
1010 if (field("batch_directory").toString().isEmpty())
1011 warn_msg = "Remote working directory is mandatory.";
1012 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1014 if (!warn_msg.isEmpty()) warn_msg += "\n";
1015 warn_msg += "Result directory is mandatory if there are output files.";
1018 ui->label_warning_text->setText(warn_msg);
1019 if (warn_msg.isEmpty())
1021 ui->label_warning_icon->hide();
1026 ui->label_warning_icon->show();
1032 FilesPage::choose_input_files()
1034 QStringList files = QFileDialog::getOpenFileNames(this,
1035 tr("Add input files"), "",
1036 tr("All Files (*)"));
1037 for (int i = 0; i < files.size(); ++i)
1039 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1040 ui->input_files_list->addItem(files.at(i));
1045 FilesPage::choose_local_directory()
1047 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1049 QFileDialog::ShowDirsOnly
1050 | QFileDialog::DontResolveSymlinks);
1053 ui->line_result_dir->setText(dir);
1057 FilesPage::remove_input_files()
1059 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1060 for (int i = 0; i < list.size(); ++i)
1062 int row = ui->input_files_list->row( list.at(i) );
1063 delete ui->input_files_list->takeItem(row);
1068 FilesPage::input_itemSelectionChanged()
1070 if (ui->input_files_list->selectedItems().size() > 0)
1071 ui->remove_input_files_button->setEnabled(true);
1073 ui->remove_input_files_button->setEnabled(false);
1077 FilesPage::add_output_file()
1079 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1080 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1081 ui->output_files_list->addItem(new_item);
1082 emit completeChanged();
1086 FilesPage::remove_output_files()
1088 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1089 for (int i = 0; i < list.size(); ++i)
1091 int row = ui->output_files_list->row( list.at(i) );
1092 delete ui->output_files_list->takeItem(row);
1094 emit completeChanged();
1098 FilesPage::output_itemSelectionChanged()
1100 if (ui->output_files_list->selectedItems().size() > 0)
1101 ui->remove_output_files_button->setEnabled(true);
1103 ui->remove_output_files_button->setEnabled(false);
1107 FilesPage::nextId() const
1109 return BL::CreateJobWizard::Page_Advanced;
1112 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1113 : QWizardPage(parent)
1115 setTitle("Job definition is finished");
1116 QCheckBox * check_box = new QCheckBox("Start job after creation");
1117 registerField("start_job", check_box);
1118 QVBoxLayout * main_layout = new QVBoxLayout;
1119 main_layout->addWidget(check_box);
1120 setLayout(main_layout);
1123 BL::ConclusionPage::~ConclusionPage()
1127 BL::ConclusionPage::validatePage()
1133 BL::ConclusionPage::nextId() const
1138 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1139 : QWizardPage(parent)
1141 _salome_services = salome_services;
1142 setTitle("Select a Resource");
1144 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1145 main_label->setWordWrap(true);
1148 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1149 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1150 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1152 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1153 resource_list_layout->addWidget(_resource_list);
1154 resource_group_box->setLayout(resource_list_layout);
1156 QLabel * resource_label = new QLabel("Resource selected: ");
1157 _resource_choosed = new QLineEdit();
1158 _resource_choosed->setText("");
1159 _resource_choosed->setReadOnly(true);
1160 registerField("resource_choosed", _resource_choosed);
1162 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1163 QLineEdit * _bqLineEdit = new QLineEdit(this);
1164 registerField("batch_queue", _bqLineEdit);
1166 _ll_label = new QLabel("LoadLeveler JobType:", this);
1167 _ll_value = new QLineEdit(this);
1168 registerField("ll_jobtype", _ll_value);
1172 _main_layout = new QGridLayout;
1173 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1174 _main_layout->addWidget(resource_label, 1, 0);
1175 _main_layout->addWidget(_resource_choosed, 1, 1);
1176 _main_layout->addWidget(bqLabel, 2, 0);
1177 _main_layout->addWidget(_bqLineEdit, 2, 1);
1178 setLayout(_main_layout);
1182 BL::ResourcePage::~ResourcePage()
1186 BL::ResourcePage::initializePage()
1188 if (field("ll_jobtype").toString() != "")
1190 _main_layout->addWidget(_ll_label, 3, 0);
1191 _main_layout->addWidget(_ll_value, 3, 1);
1196 // Initialize resource_choosed with first resource in resource list
1197 if (field("resource_choosed").toString() == "")
1199 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1200 std::list<std::string>::iterator it = resource_list.begin();
1201 if (it != resource_list.end())
1203 QString first_resource((*it).c_str());
1204 setField("resource_choosed", first_resource);
1210 BL::ResourcePage::validatePage()
1212 QString resource_choosed = field("resource_choosed").toString();
1213 if (resource_choosed == "")
1215 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1219 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1220 std::string batch = resource_descr.batch.c_str();
1223 QString ll_jobtype = field("ll_jobtype").toString();
1224 if (ll_jobtype == "")
1226 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1234 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1236 _resource_choosed->setReadOnly(false);
1237 _resource_choosed->setText(item->text());
1238 _resource_choosed->setReadOnly(true);
1240 //Specific parameters for LoadLeveler
1241 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1242 std::string batch = resource_descr.batch.c_str();
1245 _main_layout->addWidget(_ll_label, 3, 0);
1246 _main_layout->addWidget(_ll_value, 3, 1);
1252 _main_layout->removeWidget(_ll_value);
1253 _main_layout->removeWidget(_ll_label);
1260 BL::ResourcePage::nextId() const
1262 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1263 std::string batch = resource_descr.batch.c_str();
1264 if (batch == "coorm")
1266 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1270 return BL::CreateJobWizard::Page_BatchParameters;
1274 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1275 : QWizardPage(parent)
1277 setTitle("Define a Python script in SALOME job");
1278 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1279 label->setWordWrap(true);
1282 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1283 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1284 _line_PythonSalome = new QLineEdit(this);
1285 registerField("PythonSalome", _line_PythonSalome);
1286 _line_PythonSalome->setReadOnly(true);
1288 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1289 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1290 _line_env_file = new QLineEdit(this);
1291 registerField("env_PythonSalome_file", _line_env_file);
1292 _line_env_file->setReadOnly(true);
1294 QGridLayout *layout = new QGridLayout;
1295 layout->addWidget(PythonSalome_file_button, 0, 0);
1296 layout->addWidget(_line_PythonSalome, 0, 1);
1297 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1298 layout->addWidget(_line_env_file, 1, 1);
1300 QVBoxLayout * main_layout = new QVBoxLayout;
1301 main_layout->addWidget(label);
1302 main_layout->insertLayout(-1, layout);
1303 setLayout(main_layout);
1306 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1310 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1312 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1313 tr("Open Python script file"), "",
1314 tr("py (*.py);;All Files (*)"));
1315 _line_PythonSalome->setReadOnly(false);
1316 _line_PythonSalome->setText(PythonSalome_file);
1317 _line_PythonSalome->setReadOnly(true);
1321 BL::PythonSalomeMainPage::choose_env_file()
1323 QString env_file = QFileDialog::getOpenFileName(this,
1324 tr("Open environnement file"), "",
1325 tr("sh (*.sh);;All Files (*)"));
1326 _line_env_file->setReadOnly(false);
1327 _line_env_file->setText(env_file);
1328 _line_env_file->setReadOnly(true);
1332 BL::PythonSalomeMainPage::validatePage()
1334 QString PythonSalome = field("PythonSalome").toString();
1335 if (PythonSalome == "")
1337 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1345 BL::PythonSalomeMainPage::nextId() const
1347 return BL::CreateJobWizard::Page_Resource;
1352 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1353 : QWizardPage(parent),
1354 ui(new Ui::AdvancedParametersWizardPage)
1357 registerField("wckey", ui->line_wckey);
1358 registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1361 AdvancedParametersPage::~AdvancedParametersPage()
1367 AdvancedParametersPage::nextId() const
1369 return BL::CreateJobWizard::Page_Conclusion;