1 // Copyright (C) 2009-2013 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.
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>
34 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
36 DEBTRACE("Creating BL::CreateJobWizard");
37 BL_ASSERT(jobs_manager);
38 BL_ASSERT(salome_services);
39 _jobs_manager = jobs_manager;
40 _salome_services = salome_services;
45 python_salome_file = "";
50 coorm_batch_directory = "";
52 maximum_duration = "";
56 // Parameters for COORM
60 result_directory = "";
62 resource_choosed = "";
69 setOptions(QWizard::NoBackButtonOnStartPage);
72 _job_name_page = new BL::JobNamePage(this, _jobs_manager);
74 setPage(Page_JobName, _job_name_page);
75 setPage(Page_BatchParameters, new BL::BatchParametersPage(this, salome_services));
78 setPage(Page_COORM_BatchParameters, new BL::COORM_BatchParametersPage(this, salome_services));
80 setPage(Page_Files, new BL::FilesPage(this));
81 setPage(Page_Resource, new BL::ResourcePage(this, salome_services));
82 setPage(Page_Conclusion, new BL::ConclusionPage(this));
85 setPage(Page_YACSSchema, new BL::YACSSchemaPage(this));
86 setPage(Page_Command_Main_Definitions, new BL::CommandMainPage(this));
87 setPage(Page_PythonSalome_Main_Definitions, new BL::PythonSalomeMainPage(this));
89 setWindowTitle("Create Job Wizard");
90 connect(this, SIGNAL(finished(int)), this, SLOT(end(int)));
93 BL::CreateJobWizard::~CreateJobWizard()
95 DEBTRACE("Destroying BL::CreateJobWizard");
99 BL::CreateJobWizard::clone(const std::string & name)
101 if (_jobs_manager->job_already_exist(name) == true)
103 BL::Job * job = _jobs_manager->getJob(name);
105 // We can only edit a job in CREATED, ERROR, FAILED and NOT_CREATED
106 if (job->getState() == BL::Job::CREATED ||
107 job->getState() == BL::Job::ERROR ||
108 job->getState() == BL::Job::FAILED ||
109 job->getState() == BL::Job::NOT_CREATED)
111 setField("job_name", QString(name.c_str()));
112 _job_name_page->_check_name = false;
115 if (job->getType() == BL::Job::YACS_SCHEMA)
117 setField("yacs_file", QString(job->getJobFile().c_str()));
118 _job_name_page->_yacs_schema_button->click();
119 setField("env_yacs_file", QString(job->getEnvFile().c_str()));
120 if (job->getDumpYACSState() != -1)
123 value.setNum(job->getDumpYACSState());
124 setField("dump_yacs_state", value);
127 else if (job->getType() == BL::Job::COMMAND)
129 setField("command", QString(job->getJobFile().c_str()));
130 _job_name_page->_command_button->click();
131 setField("env_command_file", QString(job->getEnvFile().c_str()));
133 else if (job->getType() == BL::Job::PYTHON_SALOME)
135 setField("PythonSalome", QString(job->getJobFile().c_str()));
136 _job_name_page->_python_salome_button->click();
137 setField("env_PythonSalome_file", QString(job->getEnvFile().c_str()));
142 BL::Job::BatchParam batch_params = job->getBatchParameters();
143 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(job->getResource().c_str());
144 std::string batch = resource_descr.batch.c_str();
145 if (batch == "coorm")
147 setField("coorm_batch_directory", QString(batch_params.batch_directory.c_str()));
148 setField("launcher_file", QString(batch_params.launcher_file.c_str()));
149 setField("launcher_args", QString(batch_params.launcher_args.c_str()));
153 setField("batch_directory", QString(batch_params.batch_directory.c_str()));
157 proc_value.setNum(batch_params.nb_proc);
158 setField("proc_value", proc_value);
160 setField("exclusive", batch_params.exclusive);
162 if (batch_params.maximum_duration == "")
164 setField("duration_hour", 0);
165 setField("duration_min", 0);
169 std::size_t pos = batch_params.maximum_duration.find(":");
170 std::string hour_str = batch_params.maximum_duration.substr(0, pos);
172 std::istringstream iss_hour(hour_str);
174 setField("duration_hour", hour);
176 std::string min_str = batch_params.maximum_duration.substr(pos + 1, batch_params.maximum_duration.npos);
178 std::istringstream iss_min(min_str);
180 setField("duration_min", min);
183 std::string mem_type = batch_params.expected_memory.substr(batch_params.expected_memory.size() - 2, 2);
184 if (mem_type == "mb")
185 setField("mem_type", 0);
187 setField("mem_type", 1);
188 std::string mem_value = batch_params.expected_memory.substr(0, batch_params.expected_memory.find(mem_type));
190 std::istringstream iss_mem(mem_value);
192 setField("mem_value", mem_val);
194 BL::Job::FilesParam files_params = job->getFilesParameters();
196 std::list<std::string>::iterator it = files_params.input_files_list.begin();
197 for (; it != files_params.input_files_list.end(); it++)
198 _input_files_list->addItem(QString((*it).c_str()));
199 it = files_params.output_files_list.begin();
200 for (; it != files_params.output_files_list.end(); it++)
201 _output_files_list->addItem(QString((*it).c_str()));
203 setField("result_directory", QString(files_params.result_directory.c_str()));
204 setField("resource_choosed", QString(job->getResource().c_str()));
205 setField("batch_queue", QString(job->getBatchQueue().c_str()));
206 setField("ll_jobtype", QString(job->getLoadLevelerJobType().c_str()));
211 BL::CreateJobWizard::setFilesList(QListWidget * input_files_list, QListWidget * output_files_list)
213 _input_files_list = input_files_list;
214 _output_files_list = output_files_list;
218 BL::CreateJobWizard::end(int result)
220 DEBTRACE("End of BL::CreateJobWizard");
224 QString f_job_name = field("job_name").toString();
225 job_name = f_job_name.trimmed().toStdString();
228 QString f_yacs_file = field("yacs_file").toString();
229 yacs_file = f_yacs_file.trimmed().toStdString();
230 dump_yacs_state = field("dump_yacs_state").toInt();
233 QString f_command = field("command").toString();
234 command = f_command.trimmed().toStdString();
237 QString f_python_salome_file = field("PythonSalome").toString();
238 python_salome_file = f_python_salome_file.trimmed().toStdString();
242 f_env_file = field("env_yacs_file").toString();
243 else if (command != "")
244 f_env_file = field("env_command_file").toString();
245 else if (python_salome_file != "")
246 f_env_file = field("env_PythonSalome_file").toString();
247 env_file = f_env_file.trimmed().toStdString();
250 QString f_batch_directory = field("batch_directory").toString();
251 batch_directory = f_batch_directory.trimmed().toStdString();
254 QString f_coorm_batch_directory = field("coorm_batch_directory").toString();
255 coorm_batch_directory = f_coorm_batch_directory.toStdString();
258 QString f_launcher_file = field("launcher_file").toString();
259 launcher_file = f_launcher_file.toStdString();
260 QString f_launcher_args = field("launcher_args").toString();
261 launcher_args = f_launcher_args.toStdString();
265 if(field("duration_hour").toInt() == 0 && field("duration_min").toInt() == 0)
267 maximum_duration = "";
271 if (field("duration_hour").toInt() < 10)
272 time_hour = "0" + field("duration_hour").toString().trimmed();
274 time_hour = field("duration_hour").toString().trimmed();
275 if (field("duration_min").toInt() < 10)
276 time_min = "0" + field("duration_min").toString().trimmed();
278 time_min = field("duration_min").toString().trimmed();
279 maximum_duration = time_hour.toStdString() + ":" + time_min.toStdString();
282 QString mem = field("mem_value").toString();
283 int mem_type_i = field("mem_type").toInt();
284 QString mem_type("gb");
287 expected_memory = mem.trimmed().toStdString() + mem_type.toStdString();
289 nb_proc = field("proc_value").toInt();
290 exclusive = field("exclusive").toBool();
293 QString f_result_directory = field("result_directory").toString();
294 result_directory = f_result_directory.trimmed().toStdString();
295 for (int i = 0; i < _input_files_list->count(); ++i)
297 QListWidgetItem * item = _input_files_list->item(i);
298 QString item_text = item->text();
299 input_files_list.push_back(item_text.trimmed().toStdString());
301 for (int i = 0; i < _output_files_list->count(); ++i)
303 QListWidgetItem * item = _output_files_list->item(i);
304 QString item_text = item->text();
305 output_files_list.push_back(item_text.trimmed().toStdString());
309 QString f_resource_choosed = field("resource_choosed").toString();
310 resource_choosed = f_resource_choosed.trimmed().toStdString();
313 QString f_batch_queue = field("batch_queue").toString();
314 batch_queue = f_batch_queue.trimmed().toStdString();
316 // LoadLeveler JobType
317 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed);
318 std::string batch = resource_descr.batch.c_str();
321 QString f_ll_jobtype = field("ll_jobtype").toString();
322 ll_jobtype = f_ll_jobtype.trimmed().toStdString();
329 start_job = field("start_job").toBool();
334 BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager)
335 : QWizardPage(parent)
337 _jobs_manager = jobs_manager;
339 setTitle("Create a new job");
341 QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
342 label->setWordWrap(true);
343 QLabel * nameLabel = new QLabel("Job Name:");
344 QLineEdit * _nameLineEdit = new QLineEdit(this);
345 registerField("job_name", _nameLineEdit);
347 QLabel * label_type = new QLabel("Choose type of batch job:");
348 QGroupBox *groupBox = new QGroupBox("Type of job");
349 _yacs_schema_button = new QRadioButton(tr("YACS Schema"));
350 _yacs_schema_button->setChecked(true);
351 _command_button = new QRadioButton(tr("Command"));
352 _python_salome_button = new QRadioButton(tr("Python script in SALOME"));
353 QVBoxLayout *vbox = new QVBoxLayout;
354 vbox->addWidget(_yacs_schema_button);
355 vbox->addWidget(_command_button);
356 vbox->addWidget(_python_salome_button);
358 groupBox->setLayout(vbox);
360 QGroupBox * explanationBox = new QGroupBox("Explanation");
361 QVBoxLayout *explanationvbox = new QVBoxLayout;
362 _explanation = new QLabel();
363 _explanation->setWordWrap(true);
364 explanationvbox->addWidget(_explanation);
365 explanationvbox->addStretch(1);
366 explanationBox->setLayout(explanationvbox);
369 QVBoxLayout * main_layout = new QVBoxLayout;
370 main_layout->addWidget(label);
371 QGridLayout *layout = new QGridLayout;
372 layout->addWidget(nameLabel, 0, 0);
373 layout->addWidget(_nameLineEdit, 0, 1);
374 main_layout->insertLayout(-1, layout);
375 layout->addWidget(label_type, 2, 0);
376 layout->addWidget(groupBox, 3, 0, 1, -1);
377 layout->addWidget(explanationBox, 4, 0, 1, -1);
378 setLayout(main_layout);
380 connect(_yacs_schema_button, SIGNAL(clicked(bool)), this, SLOT(yacs_schema_button(bool)));
381 connect(_command_button, SIGNAL(clicked(bool)), this, SLOT(command_button(bool)));
382 connect(_python_salome_button, SIGNAL(clicked(bool)), this, SLOT(python_salome_button(bool)));
385 yacs_schema_button(true);
388 BL::JobNamePage::~JobNamePage()
392 BL::JobNamePage::yacs_schema_button(bool checked)
396 _explanation->setText("This job permits to launch a YACS schema into a SALOME application");
397 setField("exclusive", true);
402 BL::JobNamePage::command_button(bool checked)
406 _explanation->setText("This job permits to launch a script into a distributed resource. This script is not launched into a SALOME application");
407 setField("exclusive", false);
412 BL::JobNamePage::python_salome_button(bool checked)
416 _explanation->setText("This job permits to launch a python script into a SALOME application");
417 setField("exclusive", true);
422 BL::JobNamePage::validatePage()
424 DEBTRACE("Calling validatePage of BL::JobNamePage");
426 QString job_name = field("job_name").toString();
428 // Check if job name is empty
431 QMessageBox::warning(NULL, "Job Name Error", "Job name entered is empty, enter a job name or cancel the wizard");
432 return_value = false;
435 // Check if job name already exists
437 if (_jobs_manager->job_already_exist(job_name.toStdString()) == false || _check_name == false)
443 QMessageBox::critical(NULL, "Job Name Error", "Job name entered is already used");
445 setField("job_name", value);
446 return_value = false;
454 BL::JobNamePage::nextId() const
456 if (_yacs_schema_button->isChecked())
458 return BL::CreateJobWizard::Page_YACSSchema;
460 else if (_command_button->isChecked())
462 return BL::CreateJobWizard::Page_Command_Main_Definitions;
466 return BL::CreateJobWizard::Page_PythonSalome_Main_Definitions;
470 BL::YACSSchemaPage::YACSSchemaPage(QWidget * parent)
471 : QWizardPage(parent)
473 setTitle("Configure YACS Execution");
475 QLabel *label = new QLabel("In this step you have to configure your YACS execution");
476 label->setWordWrap(true);
478 QGroupBox * files_param_box = new QGroupBox("YACS job files");
479 QPushButton * yacs_file_button = new QPushButton(tr("Choose YACS Schema file"));
480 connect(yacs_file_button, SIGNAL(clicked()), this, SLOT(choose_file()));
481 _yacs_file_text = new QLineEdit(this);
482 _yacs_file_text->setText("");
483 registerField("yacs_file", _yacs_file_text);
484 _yacs_file_text->setReadOnly(true);
485 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
486 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
487 _line_env_file = new QLineEdit(this);
488 registerField("env_yacs_file", _line_env_file);
489 _line_env_file->setReadOnly(true);
490 QGridLayout * files_layout = new QGridLayout;
491 files_layout->addWidget(yacs_file_button, 0, 0);
492 files_layout->addWidget(_yacs_file_text, 0, 1);
493 files_layout->addWidget(command_env_file_button, 1, 0);
494 files_layout->addWidget(_line_env_file, 1, 1);
495 files_param_box->setLayout(files_layout);
497 QGroupBox * spec_param_box = new QGroupBox("YACS specific parameters");
498 QLabel * label_dump = new QLabel("Dump YACS state each secs (0 disable this feature)");
499 QLabel * label_dump_warning = new QLabel("(WARNING: can only be used with SALOME >= 6.3.0)");
500 QSpinBox * spin_dump = new QSpinBox(this);
501 spin_dump->setMinimum(0);
502 spin_dump->setMaximum(1000000);
503 registerField("dump_yacs_state", spin_dump);
504 QGridLayout * specific_layout = new QGridLayout;
505 specific_layout->addWidget(label_dump, 0, 0);
506 specific_layout->addWidget(spin_dump, 0, 1);
507 specific_layout->addWidget(label_dump_warning, 1, 0);
508 spec_param_box->setLayout(specific_layout);
510 QVBoxLayout * main_layout = new QVBoxLayout;
511 main_layout->addWidget(label);
512 main_layout->addWidget(files_param_box);
513 main_layout->addWidget(spec_param_box);
515 setLayout(main_layout);
518 BL::YACSSchemaPage::~YACSSchemaPage()
522 BL::YACSSchemaPage::validatePage()
525 QString yacs_file = field("yacs_file").toString();
532 QMessageBox::warning(NULL, "YACS File Error", "Please choose a YACS File");
533 return_value = false;
539 BL::YACSSchemaPage::choose_file()
541 QString yacs_file = QFileDialog::getOpenFileName(this,
542 tr("Open YACS files"), "",
543 tr("XML (*.xml);;All Files (*)"));
544 _yacs_file_text->setReadOnly(false);
545 _yacs_file_text->setText(yacs_file);
546 _yacs_file_text->setReadOnly(true);
550 BL::YACSSchemaPage::choose_env_file()
552 QString env_file = QFileDialog::getOpenFileName(this,
553 tr("Open environnement file"), "",
554 tr("sh (*.sh);;All Files (*)"));
555 _line_env_file->setReadOnly(false);
556 _line_env_file->setText(env_file);
557 _line_env_file->setReadOnly(true);
562 BL::YACSSchemaPage::nextId() const
564 return BL::CreateJobWizard::Page_Resource;
567 BL::CommandMainPage::CommandMainPage(QWidget * parent)
568 : QWizardPage(parent)
570 setTitle("Define command job");
571 QLabel *label = new QLabel("Enter the command that will be executed into the resource");
572 label->setWordWrap(true);
575 QPushButton * command_file_button = new QPushButton(tr("Choose a command file"));
576 connect(command_file_button, SIGNAL(clicked()), this, SLOT(choose_command_file()));
577 _line_command = new QLineEdit(this);
578 registerField("command", _line_command);
579 _line_command->setReadOnly(true);
581 QPushButton * command_env_file_button = new QPushButton(tr("Choose an environnement file"));
582 connect(command_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
583 _line_env_file = new QLineEdit(this);
584 registerField("env_command_file", _line_env_file);
585 _line_env_file->setReadOnly(true);
587 QGridLayout *layout = new QGridLayout;
588 layout->addWidget(command_file_button, 0, 0);
589 layout->addWidget(_line_command, 0, 1);
590 layout->addWidget(command_env_file_button, 1, 0);
591 layout->addWidget(_line_env_file, 1, 1);
593 QVBoxLayout * main_layout = new QVBoxLayout;
594 main_layout->addWidget(label);
595 main_layout->insertLayout(-1, layout);
596 setLayout(main_layout);
599 BL::CommandMainPage::~CommandMainPage()
603 BL::CommandMainPage::choose_command_file()
605 QString command_file = QFileDialog::getOpenFileName(this,
606 tr("Open command file"), "",
607 tr("sh (*.sh);;All Files (*)"));
608 _line_command->setReadOnly(false);
609 _line_command->setText(command_file);
610 _line_command->setReadOnly(true);
614 BL::CommandMainPage::choose_env_file()
616 QString env_file = QFileDialog::getOpenFileName(this,
617 tr("Open environnement file"), "",
618 tr("sh (*.sh);;All Files (*)"));
619 _line_env_file->setReadOnly(false);
620 _line_env_file->setText(env_file);
621 _line_env_file->setReadOnly(true);
625 BL::CommandMainPage::validatePage()
627 QString command = field("command").toString();
630 QMessageBox::warning(NULL, "Command Error", "Please enter a command");
638 BL::CommandMainPage::nextId() const
640 return BL::CreateJobWizard::Page_Resource;
643 BL::BatchParametersPage::BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
644 : QWizardPage(parent)
646 setTitle("Enter Batch Parameters");
647 resource_choosed = "";
649 _salome_services = salome_services;
651 QLabel *label = new QLabel("In this step you define the parameters of your job");
652 label->setWordWrap(true);
653 QVBoxLayout * main_layout = new QVBoxLayout;
654 main_layout->addWidget(label);
657 QLabel * label_directory = new QLabel("Remote work directory: ");
658 QLineEdit * line_directory = new QLineEdit(this);
659 registerField("batch_directory", line_directory);
661 // exected during time
662 QLabel * label_duration = new QLabel("Time limit: ");
663 QSpinBox * spin_duration_hour = new QSpinBox(this);
664 QLabel * label_duration_hour = new QLabel("Hours");
665 spin_duration_hour->setMinimum(0);
666 spin_duration_hour->setMaximum(1000000);
667 registerField("duration_hour", spin_duration_hour);
668 QSpinBox * spin_duration_min = new QSpinBox(this);
669 QLabel * label_duration_min = new QLabel("Minutes");
670 spin_duration_min->setMinimum(0);
671 spin_duration_min->setMaximum(59);
672 registerField("duration_min", spin_duration_min);
675 QLabel * label_memory = new QLabel("Memory per node: ");
676 QSpinBox * spin_memory = new QSpinBox(this);
677 spin_memory->setMinimum(0);
678 spin_memory->setMaximum(1000000);
679 registerField("mem_value", spin_memory);
680 QComboBox * combo_memory = new QComboBox(this);
681 combo_memory->addItem("MB");
682 combo_memory->addItem("GB");
683 combo_memory->setCurrentIndex(1);
684 registerField("mem_type", combo_memory);
687 QLabel * label_proc = new QLabel("Number of cores: ");
688 QSpinBox * spin_proc = new QSpinBox(this);
689 spin_proc->setMinimum(1);
690 spin_proc->setMaximum(1000000);
691 registerField("proc_value", spin_proc);
694 QLabel * label_exclusive = new QLabel("Exclusive (do not share nodes with other jobs): ");
695 QCheckBox * check_exclusive = new QCheckBox(this);
696 check_exclusive->setChecked(true);
697 registerField("exclusive", check_exclusive);
699 QGridLayout *layout = new QGridLayout;
700 layout->addWidget(label_directory, 0, 0);
701 layout->addWidget(line_directory, 0, 1, 1, -1);
702 layout->addWidget(label_duration, 1, 0);
703 layout->addWidget(spin_duration_hour, 1, 1);
704 layout->addWidget(label_duration_hour, 1, 2);
705 layout->addWidget(spin_duration_min, 1, 3);
706 layout->addWidget(label_duration_min, 1, 4);
707 layout->addWidget(label_memory, 2, 0);
708 layout->addWidget(spin_memory, 2, 1);
709 layout->addWidget(combo_memory, 2, 2);
710 layout->addWidget(label_proc, 3, 0);
711 layout->addWidget(spin_proc, 3, 1);
712 layout->addWidget(label_exclusive, 4, 0);
713 layout->addWidget(check_exclusive, 4, 1);
715 main_layout->insertLayout(-1, layout);
717 setLayout(main_layout);
720 BL::BatchParametersPage::~BatchParametersPage()
723 void BL::BatchParametersPage::cleanupPage() {}
726 BL::BatchParametersPage::initializePage()
728 QString f_resource_choosed = field("resource_choosed").toString();
729 if (f_resource_choosed != resource_choosed)
731 resource_choosed = f_resource_choosed;
732 // If choosed resource has a working_directory set
733 // Generates a default remote working directory
734 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toStdString());
735 QString res_work_dir = resource_descr.working_directory.c_str();
736 if (res_work_dir != "")
740 std::string launch_date = ctime(&rawtime);
741 for (int i = 0; i < launch_date.size(); i++)
742 if (launch_date[i] == '/' ||
743 launch_date[i] == '-' ||
744 launch_date[i] == ':' ||
745 launch_date[i] == ' ')
746 launch_date[i] = '_';
747 launch_date.erase(--launch_date.end()); // Last caracter is a \n
748 QString date = launch_date.c_str();
749 setField("batch_directory", res_work_dir + "/" + date);
755 BL::BatchParametersPage::validatePage()
757 QString batch_directory = field("batch_directory").toString();
758 if (batch_directory == "")
760 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
764 int mem = field("mem_value").toInt();
767 QMessageBox::warning(NULL, "Memory Error", "Please enter an expected memory");
775 BL::BatchParametersPage::nextId() const
777 return BL::CreateJobWizard::Page_Files;
780 BL::COORM_BatchParametersPage::COORM_BatchParametersPage(QWidget * parent, BL::SALOMEServices * salome_services)
781 : QWizardPage(parent)
783 setTitle("Enter COORM Parameters");
784 resource_choosed = "";
786 _salome_services = salome_services;
788 QLabel *label = new QLabel("In this step you define the parameters for COORM");
789 label->setWordWrap(true);
790 QVBoxLayout * main_layout = new QVBoxLayout;
791 main_layout->addWidget(label);
793 // coorm_batch_directory
794 QLabel * label_directory = new QLabel("Remote work directory: ");
795 QLineEdit * line_directory = new QLineEdit(this);
796 registerField("coorm_batch_directory", line_directory);
799 QPushButton * launcher_file_button = new QPushButton(tr("Choose a launcher file"));
800 connect(launcher_file_button, SIGNAL(clicked()), this, SLOT(choose_launcher_file()));
801 _launcher_file_text = new QLineEdit(this);
802 _launcher_file_text->setText("");
803 registerField("launcher_file", _launcher_file_text);
804 _launcher_file_text->setReadOnly(true);
807 QLabel * launcher_args_label = new QLabel("Launcher args:");
808 QLineEdit * launcher_args_text = new QLineEdit(this);
809 registerField("launcher_args", launcher_args_text);
811 QGridLayout * layout = new QGridLayout;
812 layout->addWidget(label_directory, 0, 0);
813 layout->addWidget(line_directory, 0, 1);
814 layout->addWidget(launcher_file_button, 1, 0);
815 layout->addWidget(_launcher_file_text, 1, 1);
816 layout->addWidget(launcher_args_label, 2, 0);
817 layout->addWidget(launcher_args_text, 2, 1);
819 main_layout->insertLayout(-1, layout);
821 setLayout(main_layout);
824 BL::COORM_BatchParametersPage::~COORM_BatchParametersPage()
828 BL::COORM_BatchParametersPage::validatePage()
830 QString coorm_batch_directory = field("coorm_batch_directory").toString();
831 if (coorm_batch_directory == "")
833 QMessageBox::warning(NULL, "Batch Directory Error", "Please enter a batch directory");
837 QString launcher_file = field("launcher_file").toString();
838 if (launcher_file == "")
840 QMessageBox::warning(NULL, "Launcher File Error", "Please enter a launcher file");
848 BL::COORM_BatchParametersPage::nextId() const
850 return BL::CreateJobWizard::Page_Files;
854 BL::COORM_BatchParametersPage::choose_launcher_file()
856 QString launcher_file = QFileDialog::getOpenFileName(this,
857 tr("Open launcher files"), "",
858 tr("Py (*.py);;All Files (*)"));
859 _launcher_file_text->setReadOnly(false);
860 _launcher_file_text->setText(launcher_file);
861 _launcher_file_text->setReadOnly(true);
864 void BL::COORM_BatchParametersPage::cleanupPage()
868 BL::COORM_BatchParametersPage::initializePage()
870 QString f_resource_choosed = field("resource_choosed").toString();
871 if (f_resource_choosed != resource_choosed)
873 resource_choosed = f_resource_choosed;
874 // If choosed resource has a working_directory set
875 // Generates a default remote working directory
876 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toStdString());
877 QString res_work_dir = resource_descr.working_directory.c_str();
878 if (res_work_dir != "")
882 std::string launch_date = ctime(&rawtime);
883 for (int i = 0; i < launch_date.size(); i++)
884 if (launch_date[i] == '/' ||
885 launch_date[i] == '-' ||
886 launch_date[i] == ':' ||
887 launch_date[i] == ' ')
888 launch_date[i] = '_';
889 launch_date.erase(--launch_date.end()); // Last caracter is a \n
890 QString date = launch_date.c_str();
891 setField("coorm_batch_directory", res_work_dir + "/" + date);
896 BL::FilesPage::FilesPage(BL::CreateJobWizard * parent)
897 : QWizardPage(parent)
899 setTitle("Enter Input and Output Files");
901 QLabel * main_label = new QLabel("In this step you define input and output files of your job");
902 main_label->setWordWrap(true);
905 QGroupBox * input_group_box = new QGroupBox("Input Files");
906 _input_files_button = new QPushButton("Add input files");
907 _input_files_button->show();
908 connect(_input_files_button, SIGNAL(clicked()), this, SLOT(choose_input_files()));
909 _remove_input_files_button = new QPushButton("Remove input files");
910 _remove_input_files_button->show();
911 _remove_input_files_button->setEnabled(false);
912 connect(_remove_input_files_button, SIGNAL(clicked()), this, SLOT(remove_input_files()));
913 _input_files_list = new QListWidget();
914 _input_files_list->setSelectionMode(QAbstractItemView::MultiSelection);
915 connect(_input_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(input_itemSelectionChanged()));
917 QGridLayout * input_box = new QGridLayout;
918 input_box->addWidget(_input_files_button, 0, 0);
919 input_box->addWidget(_remove_input_files_button, 0, 1);
920 input_box->addWidget(_input_files_list, 1, 0, 1, -1);
921 input_group_box->setLayout(input_box);
924 QGroupBox * output_group_box = new QGroupBox("Output Files");
925 _output_files_button = new QPushButton("Add output file");
926 _output_files_button->show();
927 connect(_output_files_button, SIGNAL(clicked()), this, SLOT(add_output_file()));
928 _remove_output_files_button = new QPushButton("Remove output files");
929 _remove_output_files_button->show();
930 _remove_output_files_button->setEnabled(false);
931 connect(_remove_output_files_button, SIGNAL(clicked()), this, SLOT(remove_output_files()));
932 _output_files_list = new QListWidget();
933 _output_files_list->setSelectionMode(QAbstractItemView::MultiSelection);
934 _output_files_list->setEditTriggers(QAbstractItemView::DoubleClicked);
935 connect(_output_files_list, SIGNAL(itemSelectionChanged()), this, SLOT(output_itemSelectionChanged()));
938 QPushButton * button_result = new QPushButton("Local Result directory");
939 connect(button_result, SIGNAL(clicked()), this, SLOT(choose_local_directory()));
940 _result_directory = new QLineEdit(this);
942 // Default result directory is home directory (if we found it)
945 _result_directory->setText(getenv("HOME"));
948 _result_directory->setText(getenv("HOME"));
950 // Second try -> getpwuid
951 struct passwd * pass_struct = getpwuid(getuid());
953 _result_directory->setText(pass_struct->pw_dir);
956 registerField("result_directory", _result_directory);
958 QGridLayout * output_box = new QGridLayout;
959 output_box->addWidget(_output_files_button, 0, 0);
960 output_box->addWidget(_remove_output_files_button, 0, 1);
961 output_box->addWidget(_output_files_list, 1, 0, 1, -1);
962 output_box->addWidget(button_result, 2, 0);
963 output_box->addWidget(_result_directory, 2, 1, 1, -1);
964 output_group_box->setLayout(output_box);
966 QVBoxLayout * main_layout = new QVBoxLayout;
967 main_layout->addWidget(main_label);
968 main_layout->addWidget(input_group_box);
969 main_layout->addWidget(output_group_box);
970 setLayout(main_layout);
972 parent->setFilesList(_input_files_list, _output_files_list);
975 BL::FilesPage::~FilesPage()
979 BL::FilesPage::validatePage()
981 QString result_directory = field("result_directory").toString();
983 for (int i = 0; i < _output_files_list->count(); ++i)
985 QListWidgetItem * item = _output_files_list->item(i);
986 if (item->text() == "TO EDIT!")
988 QMessageBox::warning(NULL, "Ouput Files Error", "Some output files are not defined !");
993 if (result_directory == "" && _output_files_list->count() != 0)
995 QMessageBox::warning(NULL, "Result Directory Error", "Please enter a result directory or remove output files");
1003 BL::FilesPage::choose_input_files()
1005 QStringList files = QFileDialog::getOpenFileNames(this,
1006 tr("Add input files"), "",
1007 tr("All Files (*)"));
1008 for (int i = 0; i < files.size(); ++i)
1010 if (_input_files_list->findItems(files.at(i), Qt::MatchFixedString).size() == 0)
1011 _input_files_list->addItem(files.at(i));
1016 BL::FilesPage::choose_local_directory()
1018 QString dir = QFileDialog::getExistingDirectory(this, tr("Choose local result directory"),
1020 QFileDialog::ShowDirsOnly
1021 | QFileDialog::DontResolveSymlinks);
1024 _result_directory->setText(dir);
1028 BL::FilesPage::remove_input_files()
1030 QList<QListWidgetItem *> list = _input_files_list->selectedItems();
1031 for (int i = 0; i < list.size(); ++i)
1033 int row = _input_files_list->row( list.at(i) );
1034 delete _input_files_list->takeItem(row);
1039 BL::FilesPage::input_itemSelectionChanged()
1041 if (_input_files_list->selectedItems().size() > 0)
1042 _remove_input_files_button->setEnabled(true);
1044 _remove_input_files_button->setEnabled(false);
1048 BL::FilesPage::add_output_file()
1050 QListWidgetItem * new_item = new QListWidgetItem("TO EDIT!");
1051 new_item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEditable|Qt::ItemIsUserCheckable|Qt::ItemIsEnabled);
1052 _output_files_list->addItem(new_item);
1056 BL::FilesPage::remove_output_files()
1058 QList<QListWidgetItem *> list = _output_files_list->selectedItems();
1059 for (int i = 0; i < list.size(); ++i)
1061 int row = _output_files_list->row( list.at(i) );
1062 delete _output_files_list->takeItem(row);
1067 BL::FilesPage::output_itemSelectionChanged()
1069 if (_output_files_list->selectedItems().size() > 0)
1070 _remove_output_files_button->setEnabled(true);
1072 _remove_output_files_button->setEnabled(false);
1076 BL::FilesPage::nextId() const
1078 return BL::CreateJobWizard::Page_Conclusion;
1081 BL::ConclusionPage::ConclusionPage(QWidget * parent)
1082 : QWizardPage(parent)
1084 setTitle("Job definition is finished");
1085 QCheckBox * check_box = new QCheckBox("Start job after creation");
1086 registerField("start_job", check_box);
1087 QVBoxLayout * main_layout = new QVBoxLayout;
1088 main_layout->addWidget(check_box);
1089 setLayout(main_layout);
1092 BL::ConclusionPage::~ConclusionPage()
1096 BL::ConclusionPage::validatePage()
1102 BL::ConclusionPage::nextId() const
1107 BL::ResourcePage::ResourcePage(BL::CreateJobWizard * parent, BL::SALOMEServices * salome_services)
1108 : QWizardPage(parent)
1110 _salome_services = salome_services;
1111 setTitle("Select a Resource");
1113 QLabel * main_label = new QLabel("In this step you select the resource of your job");
1114 main_label->setWordWrap(true);
1117 QGroupBox * resource_group_box = new QGroupBox("Resource List");
1118 _resource_list = new JM::ResourceCatalog(this, _salome_services, true);
1119 connect(_resource_list->getQListWidget(), SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemSelected(QListWidgetItem*)));
1121 QVBoxLayout * resource_list_layout = new QVBoxLayout();
1122 resource_list_layout->addWidget(_resource_list);
1123 resource_group_box->setLayout(resource_list_layout);
1125 QLabel * resource_label = new QLabel("Resource selected: ");
1126 _resource_choosed = new QLineEdit();
1127 _resource_choosed->setText("");
1128 _resource_choosed->setReadOnly(true);
1129 registerField("resource_choosed", _resource_choosed);
1131 QLabel * bqLabel = new QLabel("Batch Queue (could be optional):");
1132 QLineEdit * _bqLineEdit = new QLineEdit(this);
1133 registerField("batch_queue", _bqLineEdit);
1135 _ll_label = new QLabel("LoadLeveler JobType:", this);
1136 _ll_value = new QLineEdit(this);
1137 registerField("ll_jobtype", _ll_value);
1141 _main_layout = new QGridLayout;
1142 _main_layout->addWidget(resource_group_box, 0, 0, 1, -1);
1143 _main_layout->addWidget(resource_label, 1, 0);
1144 _main_layout->addWidget(_resource_choosed, 1, 1);
1145 _main_layout->addWidget(bqLabel, 2, 0);
1146 _main_layout->addWidget(_bqLineEdit, 2, 1);
1147 setLayout(_main_layout);
1151 BL::ResourcePage::~ResourcePage()
1155 BL::ResourcePage::initializePage()
1157 if (field("ll_jobtype").toString() != "")
1159 _main_layout->addWidget(_ll_label, 3, 0);
1160 _main_layout->addWidget(_ll_value, 3, 1);
1165 // Initialize resource_choosed with first resource in resource list
1166 if (field("resource_choosed").toString() == "")
1168 std::list<std::string> resource_list = _salome_services->getResourceList(true);
1169 std::list<std::string>::iterator it = resource_list.begin();
1170 if (it != resource_list.end())
1172 QString first_resource((*it).c_str());
1173 setField("resource_choosed", first_resource);
1179 BL::ResourcePage::validatePage()
1181 QString resource_choosed = field("resource_choosed").toString();
1182 if (resource_choosed == "")
1184 QMessageBox::warning(NULL, "Resource Error", "Please choose a resource");
1188 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(resource_choosed.toStdString());
1189 std::string batch = resource_descr.batch.c_str();
1192 QString ll_jobtype = field("ll_jobtype").toString();
1193 if (ll_jobtype == "")
1195 QMessageBox::warning(NULL, "LoadLeveler Error", "Please define a LoadLeveler JobType");
1203 BL::ResourcePage::itemSelected(QListWidgetItem * item)
1205 _resource_choosed->setReadOnly(false);
1206 _resource_choosed->setText(item->text());
1207 _resource_choosed->setReadOnly(true);
1209 //Specific parameters for LoadLeveler
1210 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(item->text().toStdString());
1211 std::string batch = resource_descr.batch.c_str();
1214 _main_layout->addWidget(_ll_label, 3, 0);
1215 _main_layout->addWidget(_ll_value, 3, 1);
1221 _main_layout->removeWidget(_ll_value);
1222 _main_layout->removeWidget(_ll_label);
1229 BL::ResourcePage::nextId() const
1231 BL::ResourceDescr resource_descr = _salome_services->getResourceDescr(_resource_choosed->text().toStdString());
1232 std::string batch = resource_descr.batch.c_str();
1233 if (batch == "coorm")
1235 return BL::CreateJobWizard::Page_COORM_BatchParameters;
1239 return BL::CreateJobWizard::Page_BatchParameters;
1243 BL::PythonSalomeMainPage::PythonSalomeMainPage(QWidget * parent)
1244 : QWizardPage(parent)
1246 setTitle("Define a Python script in SALOME job");
1247 QLabel *label = new QLabel("Enter the Python script that will be executed into the resource");
1248 label->setWordWrap(true);
1251 QPushButton * PythonSalome_file_button = new QPushButton(tr("Choose a Python file"));
1252 connect(PythonSalome_file_button, SIGNAL(clicked()), this, SLOT(choose_PythonSalome_file()));
1253 _line_PythonSalome = new QLineEdit(this);
1254 registerField("PythonSalome", _line_PythonSalome);
1255 _line_PythonSalome->setReadOnly(true);
1257 QPushButton * PythonSalome_env_file_button = new QPushButton(tr("Choose an environnement file"));
1258 connect(PythonSalome_env_file_button, SIGNAL(clicked()), this, SLOT(choose_env_file()));
1259 _line_env_file = new QLineEdit(this);
1260 registerField("env_PythonSalome_file", _line_env_file);
1261 _line_env_file->setReadOnly(true);
1263 QGridLayout *layout = new QGridLayout;
1264 layout->addWidget(PythonSalome_file_button, 0, 0);
1265 layout->addWidget(_line_PythonSalome, 0, 1);
1266 layout->addWidget(PythonSalome_env_file_button, 1, 0);
1267 layout->addWidget(_line_env_file, 1, 1);
1269 QVBoxLayout * main_layout = new QVBoxLayout;
1270 main_layout->addWidget(label);
1271 main_layout->insertLayout(-1, layout);
1272 setLayout(main_layout);
1275 BL::PythonSalomeMainPage::~PythonSalomeMainPage()
1279 BL::PythonSalomeMainPage::choose_PythonSalome_file()
1281 QString PythonSalome_file = QFileDialog::getOpenFileName(this,
1282 tr("Open Python script file"), "",
1283 tr("py (*.py);;All Files (*)"));
1284 _line_PythonSalome->setReadOnly(false);
1285 _line_PythonSalome->setText(PythonSalome_file);
1286 _line_PythonSalome->setReadOnly(true);
1290 BL::PythonSalomeMainPage::choose_env_file()
1292 QString env_file = QFileDialog::getOpenFileName(this,
1293 tr("Open environnement file"), "",
1294 tr("sh (*.sh);;All Files (*)"));
1295 _line_env_file->setReadOnly(false);
1296 _line_env_file->setText(env_file);
1297 _line_env_file->setReadOnly(true);
1301 BL::PythonSalomeMainPage::validatePage()
1303 QString PythonSalome = field("PythonSalome").toString();
1304 if (PythonSalome == "")
1306 QMessageBox::warning(NULL, "Python script in SALOME Error", "Please enter a Python script");
1314 BL::PythonSalomeMainPage::nextId() const
1316 return BL::CreateJobWizard::Page_Resource;