From 720898c648302d0ff43ce3017dee9088b2e013a3 Mon Sep 17 00:00:00 2001 From: ribes Date: Tue, 10 Nov 2009 10:12:59 +0000 Subject: [PATCH] expected_during_time to maximum_during_time --- src/engine/BL_Job.cxx | 20 +++- src/engine/BL_Job.hxx | 5 +- src/engine/BL_JobsManager.cxx | 31 ++++++- src/engine/BL_JobsManager.hxx | 3 +- src/engine/BL_SALOMEServices.cxx | 127 +++++++++++++++----------- src/engine/BL_SALOMEServices.hxx | 4 +- src/genericgui/BL_CreateJobWizard.cxx | 14 ++- src/genericgui/BL_CreateJobWizard.hxx | 3 +- src/genericgui/BL_JobTab.cxx | 10 +- src/genericgui/BL_JobTab.hxx | 2 +- src/genericgui/BL_JobsManager_QT.cxx | 27 +++++- 11 files changed, 165 insertions(+), 81 deletions(-) diff --git a/src/engine/BL_Job.cxx b/src/engine/BL_Job.cxx index 85bbb65..3d92445 100644 --- a/src/engine/BL_Job.cxx +++ b/src/engine/BL_Job.cxx @@ -25,8 +25,9 @@ BL::Job::Job() _name = ""; _yacs_file = ""; _command = ""; + _env_file = ""; _batch_params.batch_directory = ""; - _batch_params.expected_during_time = ""; + _batch_params.maximum_during_time = ""; _batch_params.expected_memory = ""; _batch_params.nb_proc = 0; _files_params.result_directory = ""; @@ -42,8 +43,9 @@ BL::Job::Job(const std::string & name) _name = name; _yacs_file = ""; _command = ""; + _env_file = ""; _batch_params.batch_directory = ""; - _batch_params.expected_during_time = ""; + _batch_params.maximum_during_time = ""; _batch_params.expected_memory = ""; _batch_params.nb_proc = 0; _files_params.result_directory = ""; @@ -104,11 +106,23 @@ BL::Job::getCommand() return _command; } +void +BL::Job::setEnvFile(std::string & env_file) +{ + _env_file = env_file; +} + +std::string & +BL::Job::getEnvFile() +{ + return _env_file; +} + void BL::Job::setBatchParameters(BL::Job::BatchParam & param) { _batch_params.batch_directory = param.batch_directory; - _batch_params.expected_during_time = param.expected_during_time; + _batch_params.maximum_during_time = param.maximum_during_time; _batch_params.expected_memory = param.expected_memory; _batch_params.nb_proc = param.nb_proc; } diff --git a/src/engine/BL_Job.hxx b/src/engine/BL_Job.hxx index 6a78e1c..2525a96 100644 --- a/src/engine/BL_Job.hxx +++ b/src/engine/BL_Job.hxx @@ -46,11 +46,13 @@ namespace BL{ void setCommand(std::string & command); std::string & getCommand(); + void setEnvFile(std::string & env_file); + std::string & getEnvFile(); struct BatchParam { std::string batch_directory; - std::string expected_during_time; + std::string maximum_during_time; std::string expected_memory; int nb_proc; }; @@ -90,6 +92,7 @@ namespace BL{ BL::Job::JobType _type; std::string _yacs_file; std::string _command; + std::string _env_file; BL::Job::BatchParam _batch_params; BL::Job::FilesParam _files_params; diff --git a/src/engine/BL_JobsManager.cxx b/src/engine/BL_JobsManager.cxx index 985d280..eabee2e 100644 --- a/src/engine/BL_JobsManager.cxx +++ b/src/engine/BL_JobsManager.cxx @@ -45,9 +45,9 @@ BL::JobsManager::setObserver(BL::Observer * observer) } BL::Job * -BL::JobsManager::addNewJob(const std::string & name) +BL::JobsManager::createJob(const std::string & name) { - DEBTRACE("addNewJob BL::JobsManager"); + DEBTRACE("createJob BL::JobsManager"); BL::Job * new_job = NULL; @@ -60,11 +60,35 @@ BL::JobsManager::addNewJob(const std::string & name) _jobs[name] = new_job; } else - DEBTRACE("addNewJob Error !!!! Job already exist: " << name); + DEBTRACE("createJob Error !!!! Job already exist: " << name); return new_job; } +void +BL::JobsManager::addJobToLauncher(const std::string & name) +{ + DEBTRACE("addJobToLauncher BL::JobsManager"); + + _jobs_it = _jobs.find(name); + if (_jobs_it == _jobs.end()) + { + // TODO: SHOULD SEND an exeception... + DEBMSG("[addJobToLauncher] failed, job was not found"); + } + + std::string result = ""; + result = _salome_services->create_job(_jobs_it->second); + if (_observer) + if (result != "") + { + _observer->sendEvent("create_job", "Error", name, result); + _jobs_it->second->setState(BL::Job::ERROR); + } + else + _observer->sendEvent("create_job", "Ok", name, ""); +} + void BL::JobsManager::removeJob(const std::string & name) { @@ -111,7 +135,6 @@ BL::JobsManager::job_already_exist(const std::string & name) return false; else return true; - } void diff --git a/src/engine/BL_JobsManager.hxx b/src/engine/BL_JobsManager.hxx index 675a5ab..a4b137c 100644 --- a/src/engine/BL_JobsManager.hxx +++ b/src/engine/BL_JobsManager.hxx @@ -40,7 +40,8 @@ namespace BL{ void setObserver(BL::Observer * observer); - BL::Job * addNewJob(const std::string & name); + BL::Job * createJob(const std::string & name); + void addJobToLauncher(const std::string & name); void removeJob(const std::string & name); BL::Job * getJob(const std::string & name); diff --git a/src/engine/BL_SALOMEServices.cxx b/src/engine/BL_SALOMEServices.cxx index 8f6a9d0..78f827b 100644 --- a/src/engine/BL_SALOMEServices.cxx +++ b/src/engine/BL_SALOMEServices.cxx @@ -84,85 +84,109 @@ BL::SALOMEServices::getMachineList() } std::string -BL::SALOMEServices::start_job(BL::Job * job) -{ - return start_yacs_job(job); -} - -std::string -BL::SALOMEServices::start_yacs_job(BL::Job * job) +BL::SALOMEServices::create_job(BL::Job * job) { + DEBTRACE("Begin of create_job"); std::string ret = ""; - // Prepare Arguments - const char * fileToExecute = job->getYACSFile().c_str(); + Engines::JobParameters_var job_parameters = new Engines::JobParameters; + + // Job type + if (job->getType() == BL::Job::COMMAND) + { + job_parameters->job_type = CORBA::string_dup("command"); + job_parameters->command = CORBA::string_dup(job->getCommand().c_str()); + job_parameters->env_file = CORBA::string_dup(job->getEnvFile().c_str()); + } + else if (job->getType() == BL::Job::YACS_SCHEMA) + { + job_parameters->job_type = CORBA::string_dup("yacs_file"); + job_parameters->yacs_file = CORBA::string_dup(job->getYACSFile().c_str()); + } + // Files BL::Job::FilesParam files = job->getFilesParameters(); - Engines::FilesList_var filesToExport = new Engines::FilesList; - filesToExport->length(files.input_files_list.size()); std::list::iterator it; - int i = 0; - for (it=files.input_files_list.begin() ; it != files.input_files_list.end(); it++) + int i,j = 0; + + job_parameters->in_files.length(files.input_files_list.size()); + for (it = files.input_files_list.begin() ; it != files.input_files_list.end(); it++) { - filesToExport[i] = CORBA::string_dup((*it).c_str()); + job_parameters->in_files[i] = CORBA::string_dup((*it).c_str()); i++; } - Engines::FilesList_var filesToImport = new Engines::FilesList; - filesToImport->length(files.output_files_list.size()); - i = 0; - for (it=files.output_files_list.begin() ; it != files.output_files_list.end(); it++) + + job_parameters->out_files.length(files.output_files_list.size()); + for (it = files.output_files_list.begin() ; it != files.output_files_list.end(); it++) { - filesToImport[i] = CORBA::string_dup((*it).c_str()); - i++; + job_parameters->out_files[j] = CORBA::string_dup((*it).c_str()); + j++; } + job_parameters->local_directory = CORBA::string_dup(""); + job_parameters->result_directory = CORBA::string_dup(files.result_directory.c_str()); BL::Job::BatchParam cpp_batch_params = job->getBatchParameters(); - Engines::BatchParameters_var batch_params = new Engines::BatchParameters; - batch_params->batch_directory = CORBA::string_dup(cpp_batch_params.batch_directory.c_str()); - batch_params->expected_during_time = CORBA::string_dup(cpp_batch_params.expected_during_time.c_str()); - batch_params->mem = CORBA::string_dup(cpp_batch_params.expected_memory.c_str()); - batch_params->nb_proc = cpp_batch_params.nb_proc; - - Engines::MachineParameters_var machine = new Engines::MachineParameters; - machine->hostname = CORBA::string_dup(job->getMachine().c_str()); - - // Start Job ! + job_parameters->work_directory = CORBA::string_dup(cpp_batch_params.batch_directory.c_str()); + + // Resource + job_parameters->maximum_during_time = CORBA::string_dup(cpp_batch_params.maximum_during_time.c_str()); + job_parameters->resource_required.hostname = CORBA::string_dup(job->getMachine().c_str()); + job_parameters->resource_required.nb_node = cpp_batch_params.nb_proc; + + // Memory + CORBA::Long memory; + std::string ram = cpp_batch_params.expected_memory.substr(0,cpp_batch_params.expected_memory.size()-2); + std::istringstream iss(ram); + iss >> memory; + std::string unity = cpp_batch_params.expected_memory.substr(cpp_batch_params.expected_memory.size()-2, 2); + if((unity.find("gb") != std::string::npos)) + memory = memory * 1024; + job_parameters->resource_required.mem_mb = memory; + + // Create Job try { - int job_id = _salome_launcher->submitSalomeJob(fileToExecute, filesToExport, - filesToImport, batch_params, machine); + int job_id = _salome_launcher->createJob(job_parameters); job->setSalomeLauncherId(job_id); } catch (const SALOME::SALOME_Exception & ex) { - DEBTRACE("SALOME Exception in submitSalomeJob !"); + DEBTRACE("SALOME Exception in createJob !"); ret = ex.details.text.in(); } return ret; } std::string -BL::SALOMEServices::refresh_job(BL::Job * job) +BL::SALOMEServices::start_job(BL::Job * job) { std::string ret = ""; + // Launch Job ! + try + { + _salome_launcher->launchJob(job->getSalomeLauncherId()); + } + catch (const SALOME::SALOME_Exception & ex) + { + DEBTRACE("SALOME Exception in launchJob !"); + ret = ex.details.text.in(); + } + return ret; +} - Engines::MachineParameters_var machine = new Engines::MachineParameters; - machine->hostname = CORBA::string_dup(job->getMachine().c_str()); +std::string +BL::SALOMEServices::refresh_job(BL::Job * job) +{ + std::string ret = ""; // Refresh Job ! try { - CORBA::String_var result = _salome_launcher->queryJob(job->getSalomeLauncherId(), machine); - std::string res = result.in(); - if (res == "Running") - return "RUNNING"; - else if (res == "Done") - return "FINISHED"; - else - return result.in(); + CORBA::String_var result = _salome_launcher->getJobState(job->getSalomeLauncherId()); + ret = result.in(); } catch (const SALOME::SALOME_Exception & ex) { - DEBTRACE("SALOME Exception in refresh_job !"); + DEBTRACE("SALOME Exception in getJobState !"); ret = ex.details.text.in(); } return ret; @@ -172,18 +196,14 @@ std::string BL::SALOMEServices::delete_job(BL::Job * job) { std::string ret = ""; - - Engines::MachineParameters_var machine = new Engines::MachineParameters; - machine->hostname = CORBA::string_dup(job->getMachine().c_str()); - // Delete Job ! try { - _salome_launcher->deleteJob(job->getSalomeLauncherId(), machine); + _salome_launcher->removeJob(job->getSalomeLauncherId()); } catch (const SALOME::SALOME_Exception & ex) { - DEBTRACE("SALOME Exception in refresh_job !"); + DEBTRACE("SALOME Exception in removeJob !"); ret = ex.details.text.in(); } return ret; @@ -194,16 +214,13 @@ BL::SALOMEServices::get_results_job(BL::Job * job) { std::string ret = ""; - Engines::MachineParameters_var machine = new Engines::MachineParameters; - machine->hostname = CORBA::string_dup(job->getMachine().c_str()); - BL::Job::FilesParam files = job->getFilesParameters(); CORBA::String_var directory = CORBA::string_dup(files.result_directory.c_str()); // get job results ! try { - _salome_launcher->getResultsJob(directory, job->getSalomeLauncherId(), machine); + _salome_launcher->getJobResults(job->getSalomeLauncherId(), directory); } catch (const SALOME::SALOME_Exception & ex) { diff --git a/src/engine/BL_SALOMEServices.hxx b/src/engine/BL_SALOMEServices.hxx index f5e597d..ef8ac95 100644 --- a/src/engine/BL_SALOMEServices.hxx +++ b/src/engine/BL_SALOMEServices.hxx @@ -43,14 +43,12 @@ namespace BL{ std::list getMachineList(); + std::string create_job(BL::Job * job); std::string start_job(BL::Job * job); std::string refresh_job(BL::Job * job); std::string delete_job(BL::Job * job); std::string get_results_job(BL::Job * job); - protected: - std::string start_yacs_job(BL::Job * job); - private: CORBA::ORB_var _orb; SALOME_NamingService * _salome_naming_service; diff --git a/src/genericgui/BL_CreateJobWizard.cxx b/src/genericgui/BL_CreateJobWizard.cxx index 99ae4ee..4253821 100644 --- a/src/genericgui/BL_CreateJobWizard.cxx +++ b/src/genericgui/BL_CreateJobWizard.cxx @@ -29,8 +29,9 @@ BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALO job_name = ""; yacs_file = ""; command = ""; + env_file = ""; batch_directory = ""; - expected_during_time = ""; + maximum_during_time = ""; expected_memory = ""; nb_proc = 1; @@ -83,6 +84,8 @@ BL::CreateJobWizard::end(int result) // Command Panel QString f_command = field("command").toString(); command = f_command.toStdString(); + QString f_env_file = field("env_file").toString(); + env_file = f_env_file.toStdString(); // Batch Panel QString f_batch_directory = field("batch_directory").toString(); @@ -98,7 +101,7 @@ BL::CreateJobWizard::end(int result) time_min = "0" + field("during_time_min").toString(); else time_min = field("during_time_min").toString(); - expected_during_time = time_hour.toStdString() + ":" + time_min.toStdString() + ":00"; + maximum_during_time = time_hour.toStdString() + ":" + time_min.toStdString() + ":00"; QString mem = field("mem_value").toString(); int mem_type_i = field("mem_type").toInt(); @@ -291,10 +294,15 @@ BL::CreateJobWizard::CommandMainPage::CommandMainPage(QWidget * parent) QLabel * label_command = new QLabel("Command: "); QLineEdit * line_command = new QLineEdit(this); registerField("command", line_command); + QLabel * label_env_file = new QLabel("Environnement file: "); + QLineEdit * line_env_file = new QLineEdit(this); + registerField("env_file", line_env_file); QGridLayout *layout = new QGridLayout; layout->addWidget(label_command, 0, 0); layout->addWidget(line_command, 0, 1); + layout->addWidget(label_env_file, 1, 0); + layout->addWidget(line_env_file, 1, 1); QVBoxLayout * main_layout = new QVBoxLayout; main_layout->addWidget(label); @@ -340,7 +348,7 @@ BL::BatchParametersPage::BatchParametersPage(QWidget * parent) registerField("batch_directory", line_directory); // exected during time - QLabel * label_during_time = new QLabel("Expected during time: "); + QLabel * label_during_time = new QLabel("Maximum during time: "); QSpinBox * spin_during_time_hour = new QSpinBox(this); QLabel * label_during_time_hour = new QLabel("Hours"); spin_during_time_hour->setMinimum(0); diff --git a/src/genericgui/BL_CreateJobWizard.hxx b/src/genericgui/BL_CreateJobWizard.hxx index ede4b4b..a241e9c 100644 --- a/src/genericgui/BL_CreateJobWizard.hxx +++ b/src/genericgui/BL_CreateJobWizard.hxx @@ -59,9 +59,10 @@ namespace BL{ std::string yacs_file; std::string command; + std::string env_file; std::string batch_directory; - std::string expected_during_time; + std::string maximum_during_time; std::string expected_memory; int nb_proc; diff --git a/src/genericgui/BL_JobTab.cxx b/src/genericgui/BL_JobTab.cxx index 5f139cc..d08d6df 100644 --- a/src/genericgui/BL_JobTab.cxx +++ b/src/genericgui/BL_JobTab.cxx @@ -84,8 +84,8 @@ BL::JobTab::createJobSummaryTab() QLabel * job_rd_label = new QLabel("Result directory:"); _job_rd_label_value = new QLabel(""); - QLabel * job_edt_label = new QLabel("Expected during time:"); - _job_edt_label_value = new QLabel(""); + QLabel * job_mdt_label = new QLabel("Maximum during time:"); + _job_mdt_label_value = new QLabel(""); QLabel * job_em_label = new QLabel("Expected memory:"); _job_em_label_value = new QLabel(""); QLabel * job_nop_label = new QLabel("Number of processors:"); @@ -98,7 +98,7 @@ BL::JobTab::createJobSummaryTab() run_values_form->insertRow(2, job_bd_label, _job_bd_label_value); run_values_form->insertRow(3, job_rd_label, _job_rd_label_value); QFormLayout * other_run_values_form = new QFormLayout; - other_run_values_form->insertRow(0, job_edt_label, _job_edt_label_value); + other_run_values_form->insertRow(0, job_mdt_label, _job_mdt_label_value); other_run_values_form->insertRow(1, job_em_label, _job_em_label_value); other_run_values_form->insertRow(2, job_nop_label, _job_nop_label_value); QHBoxLayout * box_layout = new QHBoxLayout(); @@ -189,7 +189,7 @@ BL::JobTab::job_selected(const QModelIndex & index) _job_bd_label_value->setText(QString(batch_params.batch_directory.c_str())); _job_rd_label_value->setText(QString(files_params.result_directory.c_str())); - _job_edt_label_value->setText(QString(batch_params.expected_during_time.c_str())); + _job_mdt_label_value->setText(QString(batch_params.maximum_during_time.c_str())); _job_em_label_value->setText(QString(batch_params.expected_memory.c_str())); _job_nop_label_value->setText(QVariant(batch_params.nb_proc).toString()); @@ -248,7 +248,7 @@ BL::JobTab::reset(QString job_name) _job_nof_label_value->setText(""); _job_bd_label_value->setText(""); _job_rd_label_value->setText(""); - _job_edt_label_value->setText(""); + _job_mdt_label_value->setText(""); _job_em_label_value->setText(""); _job_nop_label_value->setText(""); _job_command_label->setText("Schema or Command:"); diff --git a/src/genericgui/BL_JobTab.hxx b/src/genericgui/BL_JobTab.hxx index 2f68cc0..7f1031e 100644 --- a/src/genericgui/BL_JobTab.hxx +++ b/src/genericgui/BL_JobTab.hxx @@ -63,7 +63,7 @@ namespace BL QLabel * _job_nof_label_value; QLabel * _job_bd_label_value; QLabel * _job_rd_label_value; - QLabel * _job_edt_label_value; + QLabel * _job_mdt_label_value; QLabel * _job_em_label_value; QLabel * _job_nop_label_value; diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index 04cc1b5..3bc5f4e 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -155,7 +155,7 @@ BL::JobsManager_QT::create_job_wizard() if (wizard.job_name != "") { - BL::Job * new_job = addNewJob(wizard.job_name); + BL::Job * new_job = createJob(wizard.job_name); if (wizard.yacs_file != "") { // YACS schema job @@ -163,7 +163,7 @@ BL::JobsManager_QT::create_job_wizard() new_job->setYACSFile(wizard.yacs_file); BL::Job::BatchParam param; param.batch_directory = wizard.batch_directory; - param.expected_during_time = wizard.expected_during_time; + param.maximum_during_time = wizard.maximum_during_time; param.expected_memory = wizard.expected_memory; param.nb_proc = wizard.nb_proc; new_job->setBatchParameters(param); @@ -179,9 +179,10 @@ BL::JobsManager_QT::create_job_wizard() // Command Job new_job->setType(BL::Job::COMMAND); new_job->setCommand(wizard.command); + new_job->setEnvFile(wizard.env_file); BL::Job::BatchParam param; param.batch_directory = wizard.batch_directory; - param.expected_during_time = wizard.expected_during_time; + param.maximum_during_time = wizard.maximum_during_time; param.expected_memory = wizard.expected_memory; param.nb_proc = wizard.nb_proc; new_job->setBatchParameters(param); @@ -192,6 +193,7 @@ BL::JobsManager_QT::create_job_wizard() new_job->setFilesParameters(files_params); new_job->setMachine(wizard.machine_choosed); } + addJobToLauncher(wizard.job_name); emit new_job_added(QString::fromStdString(wizard.job_name)); if (wizard.start_job) start_job(wizard.job_name); @@ -233,7 +235,24 @@ BL::JobsManager_QT::event(QEvent * e) << event->event_name << " " << event->job_name << " " << event->data); - if (event->action == "start_job") + + if (event->action == "create_job") + { + if (event->event_name == "Ok") + { + QString str((event->job_name).c_str()); + write_normal_text("Job " + str + " created\n"); + } + else + { + QString str((event->job_name).c_str()); + write_error_text("Error in creating job: " + str + "\n"); + write_error_text("*** "); + write_error_text((event->data).c_str()); + write_error_text(" ***\n"); + } + } + else if (event->action == "start_job") { if (event->event_name == "Ok") { -- 2.39.2