1 // Copyright (C) 2009-2014 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "BL_CreateJobWizard.hxx"
21 #include "BL_JobsManager_QT.hxx"
26 #include <sys/types.h>
30 #include <ui_ResourceRequirementsWizardPage.h>
31 #include <ui_FilesWizardPage.h>
32 #include <ui_AdvancedParametersWizardPage.h>
41 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
43 DEBTRACE("Creating BL::CreateJobWizard");
44 BL_ASSERT(jobs_manager);
45 BL_ASSERT(salome_services);
46 _jobs_manager = jobs_manager;
47 _salome_services = salome_services;
52 python_salome_file = "";
57 coorm_batch_directory = "";
59 maximum_duration = "";
61 mem_req_type = BL::Job::MEM_PER_NODE;
64 // Parameters for COORM
68 result_directory = "";
70 resource_choosed = "";
77 setOptions(QWizard::NoBackButtonOnStartPage);
80 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
81 _batch_parameters_page = new BL::BatchParametersPage(this, salome_services);
83 setPage(Page_JobName, _job_name_page);
84 setPage(Page_BatchParameters, _batch_parameters_page);
87 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
89 setPage(Page_Files, new BL::FilesPage(this, salome_services));
90 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
91 setPage(Page_Advanced, new BL::AdvancedParametersPage(this));
92 setPage(Page_Conclusion, new BL::ConclusionPage(this));
95 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
96 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
97 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
99 setWindowTitle("Create Job Wizard");
100 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
103 BL::CreateJobWizard::~CreateJobWizard()
105 DEBTRACE("Destroying BL::CreateJobWizard");
109 BL::CreateJobWizard::clone(const std::string & name)
111 if (_jobs_manager->job_already_exist(name) == true)
113 BL::Job * job = _jobs_manager->getJob(name);
115 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
116 if (job->getState() == BL::Job::CREATED ||
117 job->getState() == BL::Job::ERROR ||
118 job->getState() == BL::Job::FAILED ||
119 job->getState() == BL::Job::NOT_CREATED)
121 setField("job_name", QString(name.c_str()));
122 _job_name_page->_check_name = false;
125 if (job->getType() == BL::Job::YACS_SCHEMA)
127 setField("yacs_file", QString(job->getJobFile().c_str()));
128 _job_name_page->_yacs_schema_button->click();
129 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
130 if (job->getDumpYACSState() != -1)
133 value.setNum(job->getDumpYACSState());
134 setField("dump_yacs_state", value);
137 else if (job->getType() == BL::Job::COMMAND)
139 setField("command", QString(job->getJobFile().c_str()));
140 _job_name_page->_command_button->click();
141 setField("env_command_file", QString(job->getEnvFile().c_str()));
143 else if (job->getType() == BL::Job::PYTHON_SALOME)
145 setField("PythonSalome", QString(job->getJobFile().c_str()));
146 _job_name_page->_python_salome_button->click();
147 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
152 BL::Job::BatchParam batch_params = job->getBatchParameters();
153 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
154 std::string batch = resource_descr.batch.c_str();
155 if (batch == "coorm")
157 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
158 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
159 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
163 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
167 proc_value.setNum(batch_params.nb_proc);
168 setField("proc_value", proc_value);
170 setField("exclusive", batch_params.exclusive);
172 if (batch_params.maximum_duration == "")
174 setField("default_time", true);
175 setField("duration_hour", 0);
176 setField("duration_min", 0);
180 setField("user_time", true);
181 std::size_t pos = batch_params.maximum_duration.find(":");
182 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
184 std::istringstream iss_hour(hour_str);
186 setField("duration_hour", hour);
188 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
190 std::istringstream iss_min(min_str);
192 setField("duration_min", min);
195 long long mem_mb = batch_params.mem_limit;
198 setField("default_mem", true);
202 setField("user_mem", true);
203 if (mem_mb % 1024 == 0)
205 setField("mem_value", mem_mb / 1024);
206 _batch_parameters_page->setMemUnit(BatchParametersPage::GB);
210 setField("mem_value", mem_mb);
211 _batch_parameters_page->setMemUnit(BatchParametersPage::MB);
213 _batch_parameters_page->setMemReqType(batch_params.mem_req_type);
216 BL::Job::FilesParam files_params = job->getFilesParameters();
218 std::list<std::string>::iterator it = files_params.input_files_list.begin();
219 for (; it != files_params.input_files_list.end(); it++)
220 _input_files_list->addItem(QString((*it).c_str()));
221 it = files_params.output_files_list.begin();
222 for (; it != files_params.output_files_list.end(); it++)
223 _output_files_list->addItem(QString((*it).c_str()));
225 setField("result_directory", QString(files_params.result_directory.c_str()));
226 setField("resource_choosed", QString(job->getResource().c_str()));
227 setField("batch_queue", QString(job->getBatchQueue().c_str()));
228 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
229 setField("wckey", QString(job->getWCKey().c_str()));
230 setField("extra_params", QString(job->getExtraParams().c_str()));
235 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
237 _input_files_list = input_files_list;
238 _output_files_list = output_files_list;
242 BL::CreateJobWizard::end(int result)
244 DEBTRACE("End of BL::CreateJobWizard");
248 QString f_job_name = field("job_name").toString();
249 job_name = f_job_name.trimmed().toUtf8().constData();
252 QString f_yacs_file = field("yacs_file").toString();
253 yacs_file = f_yacs_file.trimmed().toUtf8().constData();
254 dump_yacs_state = field("dump_yacs_state").toInt();
257 QString f_command = field("command").toString();
258 command = f_command.trimmed().toUtf8().constData();
261 QString f_python_salome_file = field("PythonSalome").toString();
262 python_salome_file = f_python_salome_file.trimmed().toUtf8().constData();
266 f_env_file = field("env_yacs_file").toString();
267 else if (command != "")
268 f_env_file = field("env_command_file").toString();
269 else if (python_salome_file != "")
270 f_env_file = field("env_PythonSalome_file").toString();
271 env_file = f_env_file.trimmed().toUtf8().constData();
274 QString f_batch_directory = field("batch_directory").toString();
275 batch_directory = f_batch_directory.trimmed().toUtf8().constData();
278 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
279 coorm_batch_directory = f_coorm_batch_directory.toUtf8().constData();
282 QString f_launcher_file = field("launcher_file").toString();
283 launcher_file = f_launcher_file.toUtf8().constData();
284 QString f_launcher_args = field("launcher_args").toString();
285 launcher_args = f_launcher_args.toUtf8().constData();
289 if (field("default_time").toBool() ||
290 (field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0))
292 maximum_duration = "";
296 if (field("duration_hour").toInt() < 10)
297 time_hour = "0" + field("duration_hour").toString().trimmed();
299 time_hour = field("duration_hour").toString().trimmed();
300 if (field("duration_min").toInt() < 10)
301 time_min = "0" + field("duration_min").toString().trimmed();
303 time_min = field("duration_min").toString().trimmed();
304 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
307 if(field("default_mem").toBool())
313 unsigned long mem = field("mem_value").toULongLong();
314 BatchParametersPage::MemUnit mem_unit = _batch_parameters_page->getMemUnit();
317 case BatchParametersPage::MB:
320 case BatchParametersPage::GB:
321 mem_limit = mem * 1024;
324 throw Exception("Invalid memory unit");
326 mem_req_type = _batch_parameters_page->getMemReqType();
329 nb_proc = field("proc_value").toInt();
330 exclusive = field("exclusive").toBool();
333 QString f_result_directory = field("result_directory").toString();
334 result_directory = f_result_directory.trimmed().toUtf8().constData();
335 for (int i = 0; i < _input_files_list->count(); ++i)
337 QListWidgetItem * item = _input_files_list->item(i);
338 QString item_text = item->text();
339 input_files_list.push_back(item_text.trimmed().toUtf8().constData());
341 for (int i = 0; i < _output_files_list->count(); ++i)
343 QListWidgetItem * item = _output_files_list->item(i);
344 QString item_text = item->text();
345 output_files_list.push_back(item_text.trimmed().toUtf8().constData());
349 QString f_resource_choosed = field("resource_choosed").toString();
350 resource_choosed = f_resource_choosed.trimmed().toUtf8().constData();
353 QString f_batch_queue = field("batch_queue").toString();
354 batch_queue = f_batch_queue.trimmed().toUtf8().constData();
356 // LoadLeveler JobType
357 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
358 std::string batch = resource_descr.batch.c_str();
361 QString f_ll_jobtype = field("ll_jobtype").toString();
362 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
370 QString f_wckey = field("wckey").toString();
371 wckey = f_wckey.trimmed().toUtf8().constData();
374 QString f_extra_params = field("extra_params").toString();
375 extra_params = f_extra_params.trimmed().toUtf8().constData();
377 start_job = field("start_job").toBool();
382 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
383 : QWizardPage(parent)
385 _jobs_manager = jobs_manager;
387 setTitle("Create a new job");
389 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
390 label->setWordWrap(true);
391 QLabel * nameLabel = new QLabel("Job Name:");
392 QLineEdit * _nameLineEdit = new QLineEdit(this);
393 registerField("job_name", _nameLineEdit);
395 QLabel * label_type = new QLabel("Choose type of batch job:");
396 QGroupBox *groupBox = new QGroupBox("Type of job");
397 _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
398 _yacs_schema_button->setChecked(true);
399 _command_button = new QRadioButton(tr("Command"));
400 _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
401 QVBoxLayout *vbox = new QVBoxLayout;
402 vbox->addWidget(_yacs_schema_button);
403 vbox->addWidget(_command_button);
404 vbox->addWidget(_python_salome_button);
406 groupBox->setLayout(vbox);
408 QGroupBox * explanationBox = new QGroupBox("Explanation");
409 QVBoxLayout *explanationvbox = new QVBoxLayout;
410 _explanation = new QLabel();
411 _explanation->setWordWrap(true);
412 explanationvbox->addWidget(_explanation);
413 explanationvbox->addStretch(1);
414 explanationBox->setLayout(explanationvbox);
417 QVBoxLayout * main_layout = new QVBoxLayout;
418 main_layout->addWidget(label);
419 QGridLayout *layout = new QGridLayout;
420 layout->addWidget(nameLabel, 0, 0);
421 layout->addWidget(_nameLineEdit, 0, 1);
422 main_layout->insertLayout(-1, layout);
423 layout->addWidget(label_type, 2, 0);
424 layout->addWidget(groupBox, 3, 0, 1, -1);
425 layout->addWidget(explanationBox, 4, 0, 1, -1);
426 setLayout(main_layout);
428 connect(_yacs_schema_button, SIGNAL(clicked(bool)), this, SLOT(yacs_schema_button(bool)));
429 connect(_command_button, SIGNAL(clicked(bool)), this, SLOT(command_button(bool)));
430 connect(_python_salome_button, SIGNAL(clicked(bool)), this, SLOT(python_salome_button(bool)));
433 yacs_schema_button(true);
436 BL::JobNamePage::~JobNamePage()
440 BL::JobNamePage::yacs_schema_button(bool checked)
444 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
445 setField("exclusive", true);
450 BL::JobNamePage::command_button(bool checked)
454 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
455 setField("exclusive", false);
460 BL::JobNamePage::python_salome_button(bool checked)
464 _explanation->setText("This job permits to launch a python script into a SALOME application");
465 setField("exclusive", true);
470 BL::JobNamePage::validatePage()
472 DEBTRACE("Calling validatePage of BL::JobNamePage");
474 QString job_name = field("job_name").toString();
476 // Check if job name is empty
479 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
480 return_value = false;
483 // Check if job name already exists
485 if (_jobs_manager->job_already_exist(job_name.toUtf8().constData()) == false || _check_name == false)
491 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
493 setField("job_name", value);
494 return_value = false;
502 BL::JobNamePage::nextId() const
504 if (_yacs_schema_button->isChecked())
506 return BL::CreateJobWizard::Page_YACSSchema;
508 else if (_command_button->isChecked())
510 return BL::CreateJobWizard::Page_Command_Main_Definitions;
514 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
518 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
519 : QWizardPage(parent)
521 setTitle("Configure YACS Execution");
523 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
524 label->setWordWrap(true);
526 QGroupBox * files_param_box = new QGroupBox("YACS job files");
527 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
528 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
529 _yacs_file_text = new QLineEdit(this);
530 _yacs_file_text->setText("");
531 registerField("yacs_file", _yacs_file_text);
532 _yacs_file_text->setReadOnly(true);
533 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
534 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
535 _line_env_file = new QLineEdit(this);
536 registerField("env_yacs_file", _line_env_file);
537 _line_env_file->setReadOnly(true);
538 QGridLayout * files_layout = new QGridLayout;
539 files_layout->addWidget(yacs_file_button, 0, 0);
540 files_layout->addWidget(_yacs_file_text, 0, 1);
541 files_layout->addWidget(command_env_file_button, 1, 0);
542 files_layout->addWidget(_line_env_file, 1, 1);
543 files_param_box->setLayout(files_layout);
545 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
546 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
547 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
548 QSpinBox * spin_dump = new QSpinBox(this);
549 spin_dump->setMinimum(0);
550 spin_dump->setMaximum(1000000);
551 registerField("dump_yacs_state", spin_dump);
552 QGridLayout * specific_layout = new QGridLayout;
553 specific_layout->addWidget(label_dump, 0, 0);
554 specific_layout->addWidget(spin_dump, 0, 1);
555 specific_layout->addWidget(label_dump_warning, 1, 0);
556 spec_param_box->setLayout(specific_layout);
558 QVBoxLayout * main_layout = new QVBoxLayout;
559 main_layout->addWidget(label);
560 main_layout->addWidget(files_param_box);
561 main_layout->addWidget(spec_param_box);
563 setLayout(main_layout);
566 BL::YACSSchemaPage::~YACSSchemaPage()
570 BL::YACSSchemaPage::validatePage()
573 QString yacs_file = field("yacs_file").toString();
580 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
581 return_value = false;
587 BL::YACSSchemaPage::choose_file()
589 QString yacs_file = QFileDialog::getOpenFileName(this,
590 tr("Open YACS files"), "",
591 tr("XML (*.xml);;All Files (*)"));
592 _yacs_file_text->setReadOnly(false);
593 _yacs_file_text->setText(yacs_file);
594 _yacs_file_text->setReadOnly(true);
598 BL::YACSSchemaPage::choose_env_file()
600 QString env_file = QFileDialog::getOpenFileName(this,
601 tr("Open environnement file"), "",
602 tr("sh (*.sh);;All Files (*)"));
603 _line_env_file->setReadOnly(false);
604 _line_env_file->setText(env_file);
605 _line_env_file->setReadOnly(true);
610 BL::YACSSchemaPage::nextId() const
612 return BL::CreateJobWizard::Page_Resource;
615 BL::CommandMainPage::CommandMainPage(QWidget * parent)
616 : QWizardPage(parent)
618 setTitle("Define command job");
619 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
620 label->setWordWrap(true);
623 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
624 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
625 _line_command = new QLineEdit(this);
626 registerField("command", _line_command);
627 _line_command->setReadOnly(true);
629 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
630 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
631 _line_env_file = new QLineEdit(this);
632 registerField("env_command_file", _line_env_file);
633 _line_env_file->setReadOnly(true);
635 QGridLayout *layout = new QGridLayout;
636 layout->addWidget(command_file_button, 0, 0);
637 layout->addWidget(_line_command, 0, 1);
638 layout->addWidget(command_env_file_button, 1, 0);
639 layout->addWidget(_line_env_file, 1, 1);
641 QVBoxLayout * main_layout = new QVBoxLayout;
642 main_layout->addWidget(label);
643 main_layout->insertLayout(-1, layout);
644 setLayout(main_layout);
647 BL::CommandMainPage::~CommandMainPage()
651 BL::CommandMainPage::choose_command_file()
653 QString command_file = QFileDialog::getOpenFileName(this,
654 tr("Open command file"), "",
655 tr("sh (*.sh);;All Files (*)"));
656 _line_command->setReadOnly(false);
657 _line_command->setText(command_file);
658 _line_command->setReadOnly(true);
662 BL::CommandMainPage::choose_env_file()
664 QString env_file = QFileDialog::getOpenFileName(this,
665 tr("Open environnement file"), "",
666 tr("sh (*.sh);;All Files (*)"));
667 _line_env_file->setReadOnly(false);
668 _line_env_file->setText(env_file);
669 _line_env_file->setReadOnly(true);
673 BL::CommandMainPage::validatePage()
675 QString command = field("command").toString();
678 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
686 BL::CommandMainPage::nextId() const
688 return BL::CreateJobWizard::Page_Resource;
691 BatchParametersPage::BatchParametersPage(QWidget * parent, SALOMEServices * salome_services)
692 : QWizardPage(parent),
693 ui(new Ui::ResourceRequirementsWizardPage),
694 _salome_services(salome_services),
699 registerField("duration_hour", ui->spin_duration_hour);
700 registerField("duration_min", ui->spin_duration_min);
701 registerField("mem_value", ui->spin_memory);
702 registerField("proc_value", ui->spin_proc);
703 registerField("exclusive", ui->check_exclusive);
704 registerField("default_time", ui->rb_default_time);
705 registerField("user_time", ui->rb_user_time);
706 registerField("default_mem", ui->rb_default_mem);
707 registerField("user_mem", ui->rb_user_mem);
709 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "MB", MB);
710 ui->combo_memory_unit->insertItem(ui->combo_memory_unit->count(), "GB", GB);
713 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
714 "per node", Job::MEM_PER_NODE);
715 ui->combo_memory_req_type->insertItem(ui->combo_memory_req_type->count(),
716 "per core", Job::MEM_PER_CPU);
718 connect(ui->spin_duration_hour, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
719 connect(ui->spin_duration_min, SIGNAL(valueChanged(int)), this, SLOT(timeChanged()));
720 connect(ui->spin_memory, SIGNAL(valueChanged(int)), this, SLOT(memChanged()));
721 connect(ui->combo_memory_unit, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
722 connect(ui->combo_memory_req_type, SIGNAL(currentIndexChanged(int)), this, SLOT(memChanged()));
725 BatchParametersPage::~BatchParametersPage()
731 BatchParametersPage::initializePage()
733 string f_resource_choosed = field("resource_choosed").toString().toUtf8().constData();
734 if (f_resource_choosed != resource_choosed)
736 resource_choosed = f_resource_choosed;
737 // If choosed resource has a SLURM batch manager, activate option "memory per cpu"
738 ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
739 if (resource_descr.batch == "slurm")
741 ui->combo_memory_req_type->setEnabled(true);
745 ui->combo_memory_req_type->setEnabled(false);
746 setMemReqType(Job::MEM_PER_NODE);
751 BatchParametersPage::MemUnit
752 BatchParametersPage::getMemUnit() const
754 int idx = ui->combo_memory_unit->currentIndex();
755 return (MemUnit)(ui->combo_memory_unit->itemData(idx).toInt());
759 BatchParametersPage::setMemUnit(MemUnit mem_unit)
761 ui->combo_memory_unit->setCurrentIndex(ui->combo_memory_unit->findData(mem_unit));
765 BatchParametersPage::getMemReqType() const
767 int idx = ui->combo_memory_req_type->currentIndex();
768 return (Job::MemReqType)(ui->combo_memory_req_type->itemData(idx).toInt());
772 BatchParametersPage::setMemReqType(Job::MemReqType mem_req_type)
774 ui->combo_memory_req_type->setCurrentIndex(ui->combo_memory_req_type->findData(mem_req_type));
778 BatchParametersPage::timeChanged()
780 if (ui->spin_duration_hour->value() == 0 && ui->spin_duration_min->value() == 0)
781 ui->rb_default_time->setChecked(true);
783 ui->rb_user_time->setChecked(true);
787 BatchParametersPage::memChanged()
789 ui->rb_user_mem->setChecked(true);
793 BatchParametersPage::cleanupPage()
798 BatchParametersPage::nextId() const
800 return CreateJobWizard::Page_Files;
803 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
804 : QWizardPage(parent)
806 setTitle("Enter COORM Parameters");
807 resource_choosed = "";
809 _salome_services = salome_services;
811 QLabel *label = new QLabel("In this step you define the parameters for COORM");
812 label->setWordWrap(true);
813 QVBoxLayout * main_layout = new QVBoxLayout;
814 main_layout->addWidget(label);
816 // coorm_batch_directory
817 QLabel * label_directory = new QLabel("Remote work directory: ");
818 QLineEdit * line_directory = new QLineEdit(this);
819 registerField("coorm_batch_directory", line_directory);
822 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
823 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
824 _launcher_file_text = new QLineEdit(this);
825 _launcher_file_text->setText("");
826 registerField("launcher_file", _launcher_file_text);
827 _launcher_file_text->setReadOnly(true);
830 QLabel * launcher_args_label = new QLabel("Launcher args:");
831 QLineEdit * launcher_args_text = new QLineEdit(this);
832 registerField("launcher_args", launcher_args_text);
834 QGridLayout * layout = new QGridLayout;
835 layout->addWidget(label_directory, 0, 0);
836 layout->addWidget(line_directory, 0, 1);
837 layout->addWidget(launcher_file_button, 1, 0);
838 layout->addWidget(_launcher_file_text, 1, 1);
839 layout->addWidget(launcher_args_label, 2, 0);
840 layout->addWidget(launcher_args_text, 2, 1);
842 main_layout->insertLayout(-1, layout);
844 setLayout(main_layout);
847 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
851 BL::COORM_BatchParametersPage::validatePage()
853 QString coorm_batch_directory = field("coorm_batch_directory").toString();
854 if (coorm_batch_directory == "")
856 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
860 QString launcher_file = field("launcher_file").toString();
861 if (launcher_file == "")
863 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
871 BL::COORM_BatchParametersPage::nextId() const
873 return BL::CreateJobWizard::Page_Files;
877 BL::COORM_BatchParametersPage::choose_launcher_file()
879 QString launcher_file = QFileDialog::getOpenFileName(this,
880 tr("Open launcher files"), "",
881 tr("Py (*.py);;All Files (*)"));
882 _launcher_file_text->setReadOnly(false);
883 _launcher_file_text->setText(launcher_file);
884 _launcher_file_text->setReadOnly(true);
887 void BL::COORM_BatchParametersPage::cleanupPage()
891 BL::COORM_BatchParametersPage::initializePage()
893 QString f_resource_choosed = field("resource_choosed").toString();
894 if (f_resource_choosed != resource_choosed)
896 resource_choosed = f_resource_choosed;
897 // If choosed resource has a working_directory set
898 // Generates a default remote working directory
899 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
900 QString res_work_dir = resource_descr.working_directory.c_str();
901 if (res_work_dir != "")
905 std::string launch_date = ctime(&rawtime);
906 for (int i = 0; i < launch_date.size(); i++)
907 if (launch_date[i] == '/' ||
908 launch_date[i] == '-' ||
909 launch_date[i] == ':' ||
910 launch_date[i] == ' ')
911 launch_date[i] = '_';
912 launch_date.erase(--launch_date.end()); // Last caracter is a \n
913 QString date = launch_date.c_str();
914 setField("coorm_batch_directory", res_work_dir + "/" + date);
919 FilesPage::FilesPage(CreateJobWizard * parent, SALOMEServices * salome_services)
920 : QWizardPage(parent),
921 ui(new Ui::FilesWizardPage)
925 resource_choosed = "";
926 _salome_services = salome_services;
928 connect(ui->add_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
929 connect(ui->remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
930 connect(ui->input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
931 connect(ui->add_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
932 connect(ui->remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
933 connect(ui->output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
934 connect(ui->button_choose_result_dir, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
936 registerField("batch_directory", ui->line_remote_working_dir);
937 registerField("result_directory", ui->line_result_dir);
939 // Default result directory is home directory (if we found it)
942 ui->line_result_dir->setText(getenv("HOME"));
945 ui->line_result_dir->setText(getenv("HOME"));
947 // Second try -> getpwuid
948 struct passwd * pass_struct = getpwuid(getuid());
950 ui->line_result_dir->setText(pass_struct->pw_dir);
954 parent->setFilesList(ui->input_files_list, ui->output_files_list);
956 // Check for warning messages
957 ui->label_warning_icon->setPixmap(QIcon::fromTheme("dialog-error").pixmap(16, 16));
958 connect(ui->line_remote_working_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
959 connect(ui->line_result_dir, SIGNAL(textChanged(const QString &)), this, SIGNAL(completeChanged()));
962 FilesPage::~FilesPage()
968 FilesPage::initializePage()
970 QString f_resource_choosed = field("resource_choosed").toString();
971 if (f_resource_choosed != resource_choosed)
973 resource_choosed = f_resource_choosed;
974 // If choosed resource has a working_directory set
975 // Generates a default remote working directory
976 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
977 QString res_work_dir = resource_descr.working_directory.c_str();
978 if (res_work_dir != "")
982 std::string launch_date = ctime(&rawtime);
983 for (int i = 0; i < launch_date.size(); i++)
984 if (launch_date[i] == '/' ||
985 launch_date[i] == '-' ||
986 launch_date[i] == ':' ||
987 launch_date[i] == ' ')
988 launch_date[i] = '_';
989 launch_date.erase(--launch_date.end()); // Last caracter is a \n
990 QString date = launch_date.c_str();
991 setField("batch_directory", res_work_dir + "/" + date);
997 FilesPage::isComplete() const
1000 if (field("batch_directory").toString().isEmpty())
1001 warn_msg = "Remote working directory is mandatory.";
1002 if (field("result_directory").toString().isEmpty() && ui->output_files_list->count() != 0)
1004 if (!warn_msg.isEmpty()) warn_msg += "\n";
1005 warn_msg += "Result directory is mandatory if there are output files.";
1008 ui->label_warning_text->setText(warn_msg);
1009 if (warn_msg.isEmpty())
1011 ui->label_warning_icon->hide();
1016 ui->label_warning_icon->show();
1022 FilesPage::choose_input_files()
1024 QStringList files = QFileDialog::getOpenFileNames(this,
1025 tr("Add input files"), "",
1026 tr("All Files (*)"));
1027 for (int i = 0; i < files.size(); ++i)
1029 if (ui->input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1030 ui->input_files_list->addItem(files.at(i));
1035 FilesPage::choose_local_directory()
1037 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1039 QFileDialog::ShowDirsOnly
1040 | QFileDialog::DontResolveSymlinks);
1043 ui->line_result_dir->setText(dir);
1047 FilesPage::remove_input_files()
1049 QList<QListWidgetItem *> list = ui->input_files_list->selectedItems();
1050 for (int i = 0; i < list.size(); ++i)
1052 int row = ui->input_files_list->row( list.at(i) );
1053 delete ui->input_files_list->takeItem(row);
1058 FilesPage::input_itemSelectionChanged()
1060 if (ui->input_files_list->selectedItems().size() > 0)
1061 ui->remove_input_files_button->setEnabled(true);
1063 ui->remove_input_files_button->setEnabled(false);
1067 FilesPage::add_output_file()
1069 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1070 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1071 ui->output_files_list->addItem(new_item);
1072 emit completeChanged();
1076 FilesPage::remove_output_files()
1078 QList<QListWidgetItem *> list = ui->output_files_list->selectedItems();
1079 for (int i = 0; i < list.size(); ++i)
1081 int row = ui->output_files_list->row( list.at(i) );
1082 delete ui->output_files_list->takeItem(row);
1084 emit completeChanged();
1088 FilesPage::output_itemSelectionChanged()
1090 if (ui->output_files_list->selectedItems().size() > 0)
1091 ui->remove_output_files_button->setEnabled(true);
1093 ui->remove_output_files_button->setEnabled(false);
1097 FilesPage::nextId() const
1099 return BL::CreateJobWizard::Page_Advanced;
1102 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1103 : QWizardPage(parent)
1105 setTitle("Job definition is finished");
1106 QCheckBox * check_box = new QCheckBox("Start job after creation");
1107 registerField("start_job", check_box);
1108 QVBoxLayout * main_layout = new QVBoxLayout;
1109 main_layout->addWidget(check_box);
1110 setLayout(main_layout);
1113 BL::ConclusionPage::~ConclusionPage()
1117 BL::ConclusionPage::validatePage()
1123 BL::ConclusionPage::nextId() const
1128 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1129 : QWizardPage(parent)
1131 _salome_services = salome_services;
1132 setTitle("Select a Resource");
1134 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1135 main_label->setWordWrap(true);
1138 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1139 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1140 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1142 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1143 resource_list_layout->addWidget(_resource_list);
1144 resource_group_box->setLayout(resource_list_layout);
1146 QLabel * resource_label = new QLabel("Resource selected: ");
1147 _resource_choosed = new QLineEdit();
1148 _resource_choosed->setText("");
1149 _resource_choosed->setReadOnly(true);
1150 registerField("resource_choosed", _resource_choosed);
1152 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1153 QLineEdit * _bqLineEdit = new QLineEdit(this);
1154 registerField("batch_queue", _bqLineEdit);
1156 _ll_label = new QLabel("LoadLeveler JobType:", this);
1157 _ll_value = new QLineEdit(this);
1158 registerField("ll_jobtype", _ll_value);
1162 _main_layout = new QGridLayout;
1163 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1164 _main_layout->addWidget(resource_label, 1, 0);
1165 _main_layout->addWidget(_resource_choosed, 1, 1);
1166 _main_layout->addWidget(bqLabel, 2, 0);
1167 _main_layout->addWidget(_bqLineEdit, 2, 1);
1168 setLayout(_main_layout);
1172 BL::ResourcePage::~ResourcePage()
1176 BL::ResourcePage::initializePage()
1178 if (field("ll_jobtype").toString() != "")
1180 _main_layout->addWidget(_ll_label, 3, 0);
1181 _main_layout->addWidget(_ll_value, 3, 1);
1186 // Initialize resource_choosed with first resource in resource list
1187 if (field("resource_choosed").toString() == "")
1189 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1190 std::list<std::string>::iterator it = resource_list.begin();
1191 if (it != resource_list.end())
1193 QString first_resource((*it).c_str());
1194 setField("resource_choosed", first_resource);
1200 BL::ResourcePage::validatePage()
1202 QString resource_choosed = field("resource_choosed").toString();
1203 if (resource_choosed == "")
1205 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1209 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toUtf8().constData());
1210 std::string batch = resource_descr.batch.c_str();
1213 QString ll_jobtype = field("ll_jobtype").toString();
1214 if (ll_jobtype == "")
1216 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1224 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1226 _resource_choosed->setReadOnly(false);
1227 _resource_choosed->setText(item->text());
1228 _resource_choosed->setReadOnly(true);
1230 //Specific parameters for LoadLeveler
1231 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toUtf8().constData());
1232 std::string batch = resource_descr.batch.c_str();
1235 _main_layout->addWidget(_ll_label, 3, 0);
1236 _main_layout->addWidget(_ll_value, 3, 1);
1242 _main_layout->removeWidget(_ll_value);
1243 _main_layout->removeWidget(_ll_label);
1250 BL::ResourcePage::nextId() const
1252 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toUtf8().constData());
1253 std::string batch = resource_descr.batch.c_str();
1254 if (batch == "coorm")
1256 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1260 return BL::CreateJobWizard::Page_BatchParameters;
1264 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1265 : QWizardPage(parent)
1267 setTitle("Define a Python script in SALOME job");
1268 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1269 label->setWordWrap(true);
1272 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1273 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1274 _line_PythonSalome = new QLineEdit(this);
1275 registerField("PythonSalome", _line_PythonSalome);
1276 _line_PythonSalome->setReadOnly(true);
1278 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1279 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1280 _line_env_file = new QLineEdit(this);
1281 registerField("env_PythonSalome_file", _line_env_file);
1282 _line_env_file->setReadOnly(true);
1284 QGridLayout *layout = new QGridLayout;
1285 layout->addWidget(PythonSalome_file_button, 0, 0);
1286 layout->addWidget(_line_PythonSalome, 0, 1);
1287 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1288 layout->addWidget(_line_env_file, 1, 1);
1290 QVBoxLayout * main_layout = new QVBoxLayout;
1291 main_layout->addWidget(label);
1292 main_layout->insertLayout(-1, layout);
1293 setLayout(main_layout);
1296 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1300 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1302 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1303 tr("Open Python script file"), "",
1304 tr("py (*.py);;All Files (*)"));
1305 _line_PythonSalome->setReadOnly(false);
1306 _line_PythonSalome->setText(PythonSalome_file);
1307 _line_PythonSalome->setReadOnly(true);
1311 BL::PythonSalomeMainPage::choose_env_file()
1313 QString env_file = QFileDialog::getOpenFileName(this,
1314 tr("Open environnement file"), "",
1315 tr("sh (*.sh);;All Files (*)"));
1316 _line_env_file->setReadOnly(false);
1317 _line_env_file->setText(env_file);
1318 _line_env_file->setReadOnly(true);
1322 BL::PythonSalomeMainPage::validatePage()
1324 QString PythonSalome = field("PythonSalome").toString();
1325 if (PythonSalome == "")
1327 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1335 BL::PythonSalomeMainPage::nextId() const
1337 return BL::CreateJobWizard::Page_Resource;
1342 AdvancedParametersPage::AdvancedParametersPage(CreateJobWizard * parent)
1343 : QWizardPage(parent),
1344 ui(new Ui::AdvancedParametersWizardPage)
1347 registerField("wckey", ui->line_wckey);
1348 registerField("extra_params", ui->text_extra_params, "plainText", "textChanged()");
1351 AdvancedParametersPage::~AdvancedParametersPage()
1357 AdvancedParametersPage::nextId() const
1359 return BL::CreateJobWizard::Page_Conclusion;