X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fgenericgui%2FBL_JobsManager_QT.cxx;h=e56bde129d86812aa84a053fb9292ad164bb4df9;hb=2fd024861e52a0756c74edeec0408fdd4a7d8fac;hp=9b53f94031aabd2f226882d4e5998782b10ab6b1;hpb=70c432982839980de6c1f8efe3a8ee0130e09c73;p=modules%2Fjobmanager.git diff --git a/src/genericgui/BL_JobsManager_QT.cxx b/src/genericgui/BL_JobsManager_QT.cxx index 9b53f94..e56bde1 100644 --- a/src/genericgui/BL_JobsManager_QT.cxx +++ b/src/genericgui/BL_JobsManager_QT.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2009-2013 CEA/DEN, EDF R&D +// Copyright (C) 2009-2016 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,6 +20,24 @@ #include "BL_JobsManager_QT.hxx" #include "BL_GenericGui.hxx" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +// To tokenize a string +static void Tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters = " "); + BL::JobManagerEvent::JobManagerEvent(const std::string & action_i, const std::string & event_name_i, const std::string & job_name_i, @@ -88,6 +106,7 @@ BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui, scroll_widget->setWidgetResizable(true); setWidget(scroll_widget); setWindowTitle("Job Manager"); + setObjectName("jmJobManagerDock"); } BL::JobsManager_QT::~JobsManager_QT() @@ -113,7 +132,7 @@ BL::JobsManager_QT::load_jobs_button() write_normal_text("Load jobs action cancelled\n"); } else - load_jobs(jobs_file.toStdString()); + load_jobs(jobs_file.toUtf8().constData()); } void @@ -125,8 +144,8 @@ BL::JobsManager_QT::save_jobs_button() filters << "XML files (*.xml)" << "Any files (*)"; dialog.setFileMode(QFileDialog::AnyFile); - dialog.setFilters(filters); - dialog.selectFilter("(*.xml)"); + dialog.setNameFilters(filters); + dialog.selectNameFilter("(*.xml)"); dialog.setDefaultSuffix("xml"); dialog.setConfirmOverwrite(true); dialog.setAcceptMode(QFileDialog::AcceptSave); @@ -145,7 +164,7 @@ BL::JobsManager_QT::save_jobs_button() write_normal_text("Save jobs action cancelled\n"); } else - save_jobs(jobs_file.toStdString()); + save_jobs(jobs_file.toUtf8().constData()); } void @@ -265,33 +284,53 @@ void BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard) { BL::Job * new_job = createJob(wizard.job_name); - if (wizard.yacs_file != "") + switch (wizard.job_type) { + case BL::CreateJobWizard::YACS: // YACS schema job new_job->setType(BL::Job::YACS_SCHEMA); new_job->setJobFile(wizard.yacs_file); new_job->setDumpYACSState(wizard.dump_yacs_state); - } - else if (wizard.command != "") - { + new_job->setYacsDriverOptions(wizard.yacs_driver_options); + break; + case BL::CreateJobWizard::COMMAND: // Command Job new_job->setType(BL::Job::COMMAND); new_job->setJobFile(wizard.command); - } - else if (wizard.python_salome_file != "") - { - // Command Job + break; + case BL::CreateJobWizard::PYTHON_SALOME: + // Python Salome Job new_job->setType(BL::Job::PYTHON_SALOME); new_job->setJobFile(wizard.python_salome_file); + break; + default: + throw BL::Exception("Unknown job type"); } // For all jobs new_job->setEnvFile(wizard.env_file); BL::Job::BatchParam param; - param.batch_directory = wizard.batch_directory; + + // For COORM + if (wizard.coorm_batch_directory != "") + { + param.batch_directory = wizard.coorm_batch_directory; + } + else if (wizard.batch_directory != "") + { + param.batch_directory = wizard.batch_directory; + } + param.maximum_duration = wizard.maximum_duration; - param.expected_memory = wizard.expected_memory; + param.mem_limit = wizard.mem_limit; + param.mem_req_type = wizard.mem_req_type; param.nb_proc = wizard.nb_proc; + param.exclusive = wizard.exclusive; + + // Parameters for COORM + param.launcher_file = wizard.launcher_file; + param.launcher_args = wizard.launcher_args; + new_job->setBatchParameters(param); BL::Job::FilesParam files_params; files_params.result_directory = wizard.result_directory; @@ -301,12 +340,14 @@ BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard) new_job->setResource(wizard.resource_choosed); new_job->setBatchQueue(wizard.batch_queue); new_job->setLoadLevelerJobType(wizard.ll_jobtype); + new_job->setWCKey(wizard.wckey); + new_job->setExtraParams(wizard.extra_params); // End addJobToLauncher(wizard.job_name); - emit new_job_added(QString::fromStdString(wizard.job_name)); + emit new_job_added(QString::fromUtf8(wizard.job_name.c_str())); QStandardItemModel * model = _model_manager->getModel(); - QList item_list = model->findItems(QString::fromStdString(wizard.job_name)); + QList item_list = model->findItems(QString::fromUtf8(wizard.job_name.c_str())); QStandardItem * job_state_item = model->item(item_list.at(0)->row(), 2); _main_gui->_jobs_table->selectRow(item_list.at(0)->row()); if (wizard.start_job) @@ -316,7 +357,7 @@ BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard) void BL::JobsManager_QT::delete_job(QString job_name) { - BL::JobsManager::removeJob(job_name.toStdString()); + BL::JobsManager::removeJob(job_name.toUtf8().constData()); _model_manager->delete_job(job_name); _main_gui->_job_tab->reset(job_name); } @@ -347,17 +388,16 @@ BL::JobsManager_QT::event(QEvent * e) << event->job_name << " " << event->data); + QString job_name = QString::fromUtf8(event->job_name.c_str()); if (event->action == "create_job") { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("Job " + str + " created\n"); + write_normal_text("Job " + job_name + " created\n"); } else { - QString str((event->job_name).c_str()); - write_error_text("Error in creating job: " + str + "\n"); + write_error_text("Error in creating job: " + job_name + "\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); @@ -367,33 +407,29 @@ BL::JobsManager_QT::event(QEvent * e) { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("Job " + str + " queued\n"); + write_normal_text("Job " + job_name + " queued\n"); } else { - QString str((event->job_name).c_str()); - write_error_text("Error in starting job: " + str + "\n"); + write_error_text("Error in starting job: " + job_name + "\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); } - emit job_state_changed(QString((event->job_name).c_str())); + emit job_state_changed(job_name); } else if (event->action == "refresh_job") { if (event->event_name == "Ok") { - QString name((event->job_name).c_str()); QString state((event->data).c_str()); state = state.toLower(); - write_normal_text("Job " + name + " new state is " + state + "\n"); - emit job_state_changed(QString((event->job_name).c_str())); + write_normal_text("Job " + job_name + " new state is " + state + "\n"); + emit job_state_changed(job_name); } else { - QString str((event->job_name).c_str()); - write_error_text("Error in refreshing job: " + str + "\n"); + write_error_text("Error in refreshing job: " + job_name + "\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); @@ -403,13 +439,11 @@ BL::JobsManager_QT::event(QEvent * e) { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("Job " + str + " deleted\n"); + write_normal_text("Job " + job_name + " deleted\n"); } else { - QString str((event->job_name).c_str()); - write_error_text("Warning delete job: " + str + " maybe not complete, exception catch in SALOME Launcher service\n"); + write_error_text("Warning delete job: " + job_name + " maybe not complete, exception catch in SALOME Launcher service\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); @@ -419,13 +453,11 @@ BL::JobsManager_QT::event(QEvent * e) { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("Results of Job " + str + " are get\n"); + write_normal_text("Results of Job " + job_name + " are get\n"); } else { - QString str((event->job_name).c_str()); - write_error_text("Warning for results of job: " + str + " maybe not complete, exception catch in SALOME Launcher service\n"); + write_error_text("Warning for results of job: " + job_name + " maybe not complete, exception catch in SALOME Launcher service\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); @@ -435,18 +467,41 @@ BL::JobsManager_QT::event(QEvent * e) { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("Job " + str + " is stopped\n"); + write_normal_text("Job " + job_name + " is stopped\n"); } else { - QString str((event->job_name).c_str()); - write_error_text("Error when trying to stop job: " + str + "\n"); + write_error_text("Error when trying to stop job: " + job_name + "\n"); write_error_text("*** "); write_error_text((event->data).c_str()); write_error_text(" ***\n"); } } + else if (event->action == "get_assigned_hostnames") + { + if (event->event_name == "Ok") + { + vector hostnames; + + Tokenize(event->data, hostnames, "+"); + + vector::iterator it; + + write_normal_text("Job " + job_name + " assigned hostnames are :\n"); + + for (it = hostnames.begin(); it < hostnames.end(); it++) + { + vector hostname; + Tokenize(*it, hostname, "."); + QString assigned_hostname(hostname[0].c_str()); + write_normal_text("+ " + assigned_hostname + "\n"); + } + } + else + { + // Do nothing in case the batch manager does not support this + } + } else if (event->action == "save_jobs") { if (event->event_name == "Error") @@ -481,15 +536,14 @@ BL::JobsManager_QT::event(QEvent * e) { if (event->event_name == "Ok") { - QString str((event->job_name).c_str()); - write_normal_text("New job added " + str + "\n"); - emit new_job_added(str); + write_normal_text("New job added " + job_name + "\n"); + emit new_job_added(job_name); } } else if (event->action == "to_remove_job") { if (event->event_name == "Ok") - _main_gui->delete_job_external((event->job_name).c_str()); + _main_gui->delete_job_external(job_name); } else { @@ -522,3 +576,22 @@ BL::JobsManager_QT::write_error_text(const QString & text) _log->setTextCursor(cursor); _log->setReadOnly(true); } + +// To tokenize a string +void Tokenize(const std::string& str, std::vector& tokens, const std::string& delimiters) +{ + // Skip delimiters at beginning. + string::size_type lastPos = str.find_first_not_of(delimiters, 0); + // Find first "non-delimiter". + string::size_type pos = str.find_first_of(delimiters, lastPos); + + while (string::npos != pos || string::npos != lastPos) + { + // Found a token, add it to the vector. + tokens.push_back(str.substr(lastPos, pos - lastPos)); + // Skip delimiters. Note the "not_of" + lastPos = str.find_first_not_of(delimiters, pos); + // Find next "non-delimiter" + pos = str.find_first_of(delimiters, lastPos); + } +}