]> SALOME platform Git repositories - modules/jobmanager.git/commitdiff
Salome HOME
- Edit Job and Restart Job work
authorribes <ribes>
Tue, 26 Jan 2010 10:19:39 +0000 (10:19 +0000)
committerribes <ribes>
Tue, 26 Jan 2010 10:19:39 +0000 (10:19 +0000)
src/genericgui/BL_Buttons.cxx
src/genericgui/BL_Buttons.hxx
src/genericgui/BL_CreateJobWizard.cxx
src/genericgui/BL_CreateJobWizard.hxx
src/genericgui/BL_GenericGui.cxx
src/genericgui/BL_GenericGui.hxx
src/genericgui/BL_JobsManager_QT.cxx
src/genericgui/BL_JobsManager_QT.hxx

index 2e82557fa939a3b936336d3d5f3cd171bf44c813..b634a93e6e06bda378a6c418ef4e784455b8d2e4 100644 (file)
@@ -28,6 +28,7 @@ BL::Buttons::Buttons(QWidget * parent) : QGroupBox(parent)
   _create_button = new QPushButton("Create a Job", this);
   _edit_clone_button = new QPushButton("Edit/Clone a Job", this);
   _start_button = new QPushButton("Start a Job", this);
+  _restart_button = new QPushButton("Restart a Job", this);
   _delete_button = new QPushButton("Delete a Job", this);
   _get_results_button = new QPushButton("Get Job Results", this);
   _refresh_button = new QPushButton("Refresh Jobs", this);
@@ -36,6 +37,7 @@ BL::Buttons::Buttons(QWidget * parent) : QGroupBox(parent)
   mainLayout->addWidget(_create_button);
   mainLayout->addWidget(_edit_clone_button);
   mainLayout->addWidget(_start_button);
+  mainLayout->addWidget(_restart_button);
   mainLayout->addWidget(_delete_button);
   mainLayout->addWidget(_get_results_button);
   mainLayout->addWidget(_refresh_button);
@@ -73,6 +75,12 @@ BL::Buttons::setStartButtonSlot(QObject * receiver, const char * name)
   connect(_start_button, SIGNAL(clicked()), receiver, name);
 }
 
+void
+BL::Buttons::setReStartButtonSlot(QObject * receiver, const char * name)
+{
+  connect(_restart_button, SIGNAL(clicked()), receiver, name);
+}
+
 void
 BL::Buttons::setDeleteButtonSlot(QObject * receiver, const char * name)
 {
@@ -115,6 +123,18 @@ BL::Buttons::disable_start_button()
   _start_button->setEnabled(false);
 }
 
+void 
+BL::Buttons::enable_restart_button()
+{
+  _restart_button->setEnabled(true);
+}
+
+void 
+BL::Buttons::disable_restart_button()
+{
+  _restart_button->setEnabled(false);
+}
+
 void 
 BL::Buttons::enable_delete_button()
 {
index e364cd7e57954b24a7b60fe1d9ef90585ab35f12..b26f5837af4ba655431ceda601586dfad81ca296 100644 (file)
@@ -37,6 +37,7 @@ namespace BL
       void setCreateButtonSlot(QObject * receiver, const char * name);
       void setEditCloneButtonSlot(QObject * receiver, const char * name);
       void setStartButtonSlot(QObject * receiver, const char * name);
+      void setReStartButtonSlot(QObject * receiver, const char * name);
       void setDeleteButtonSlot(QObject * receiver, const char * name);
       void setRefreshButtonSlot(QObject * receiver, const char * name);
       void setGetResultsButtonSlot(QObject * receiver, const char * name);
@@ -47,6 +48,9 @@ namespace BL
       void enable_start_button();
       void disable_start_button();
 
+      void enable_restart_button();
+      void disable_restart_button();
+
       void enable_delete_button();
       void disable_delete_button();
 
@@ -57,6 +61,7 @@ namespace BL
       QPushButton * _create_button;
       QPushButton * _edit_clone_button;
       QPushButton * _start_button;
+      QPushButton * _restart_button;
       QPushButton * _delete_button;
       QPushButton * _get_results_button;
       QPushButton * _refresh_button;
index e247c8708bef979b7c84b62ea0f63b1600a8f9b7..a2eab56c46dfc4ca89b9d43ad80b460a0f02aa73 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "BL_CreateJobWizard.hxx"
+#include "BL_JobsManager_QT.hxx"
 
 BL::CreateJobWizard::CreateJobWizard(BL::JobsManager_QT * jobs_manager, BL::SALOMEServices * salome_services)
 {
@@ -75,10 +76,11 @@ BL::CreateJobWizard::clone(const std::string & name)
   {
     BL::Job * job = _jobs_manager->getJob(name);
 
-    // We can only edit a job in CREATED, ERROR or FINISHED
-    if (job->getState() == BL::Job::CREATED or BL::Job::FINISHED or BL::Job::ERROR)
+    // We can only edit a job in CREATED, ERROR
+    if (job->getState() == BL::Job::CREATED or job->getState() == BL::Job::ERROR)
     { 
       setField("job_name", QString(name.c_str()));
+      _job_name_page->_check_name = false;
     }
 
     if (job->getType() == BL::Job::YACS_SCHEMA)
@@ -241,6 +243,7 @@ BL::JobNamePage::JobNamePage(QWidget * parent, BL::JobsManager_QT * jobs_manager
 : QWizardPage(parent)
 {
   _jobs_manager = jobs_manager;
+  _check_name = true;
   setTitle("Create a new job");
 
   QLabel *label = new QLabel("Enter Job name, you cannot add two jobs with the same name");
@@ -330,7 +333,7 @@ BL::JobNamePage::validatePage()
 
   // Check if job name already exists
   else {
-    if (_jobs_manager->job_already_exist(job_name.toStdString()) == false)
+    if (_jobs_manager->job_already_exist(job_name.toStdString()) == false or _check_name == false)
     {
       return_value = true;
     }
index 9ee578911e651718f8ee61ca64d39ad10238db94..15a08815dfb89393b207c0fee41f996b84022bf7 100644 (file)
@@ -23,7 +23,6 @@
 #include <QtGui>
 
 #include "BL_Traces.hxx"
-#include "BL_JobsManager_QT.hxx"
 #include "BL_SALOMEServices.hxx"
 #include "JM_ResourceCatalog.hxx"
 
@@ -117,6 +116,7 @@ namespace BL{
       QRadioButton * _yacs_schema_button;
       QRadioButton * _command_button;
       QRadioButton * _python_salome_button;
+      bool _check_name;
   };
 
   class ConclusionPage: virtual public QWizardPage
index 66e912a37131579f3a8f7634eb41b8ac6190d009..022f939200a52cf29981e9a8cb0fb9d74f63e9b8 100644 (file)
@@ -33,7 +33,7 @@ BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->ge
   _salome_services = new BL::SALOMEServices();
   if (_salome_services->initNS() == false)
     DEBMSG("WARNING !!!!! SALOME IS NOT REACHABLE !!!!");
-  _jobs_manager = new BL::JobsManager_QT(_dock_parent, _salome_services);
+  _jobs_manager = new BL::JobsManager_QT(_dock_parent, this, _salome_services);
   _model_manager = new BL::QModelManager(this, _jobs_manager);
 
   _model = _model_manager->getModel();
@@ -45,6 +45,7 @@ BL::GenericGui::GenericGui(BL::MainWindows_Wrap * wrapper) : QObject(wrapper->ge
   _buttons->setCreateButtonSlot(this, SLOT(create_job()));
   _buttons->setEditCloneButtonSlot(this, SLOT(edit_clone_job()));
   _buttons->setStartButtonSlot(this, SLOT(start_job()));
+  _buttons->setReStartButtonSlot(this, SLOT(restart_job()));
   _buttons->setDeleteButtonSlot(this, SLOT(delete_job()));
   _buttons->setRefreshButtonSlot(this, SLOT(refresh_job()));
   _buttons->setGetResultsButtonSlot(this, SLOT(get_results_job()));
@@ -141,6 +142,7 @@ BL::GenericGui::createActions()
   _create_job_action = _wrapper->createAction("Create a Job", QIcon(), "Create a Job", "Create a Job", 0, _dock_parent, false, this, SLOT(create_job()));
   _edit_clone_job_action = _wrapper->createAction("Edit/Clone a Job", QIcon(), "Edit/Clone a Job", "Edit/Clone a Job", 0, _dock_parent, false, this, SLOT(edit_clone_job()));
   _start_job_action = _wrapper->createAction("Start a Job", QIcon(), "Start a Job", "Start a Job", 0, _dock_parent, false, this, SLOT(start_job()));
+  _restart_job_action = _wrapper->createAction("Restart a Job", QIcon(), "Restart a Job", "Restart a Job", 0, _dock_parent, false, this, SLOT(restart_job()));
   _delete_job_action = _wrapper->createAction("Delete a Job", QIcon(), "Delete a Job", "Delete a Job", 0, _dock_parent, false, this, SLOT(delete_job()));
   _refresh_job_action = _wrapper->createAction("Refresh Jobs", QIcon(), "Refresh Jobs", "Refresh Jobs", 0, _dock_parent, false, this, SLOT(refresh_job()));
   _get_results_job_action = _wrapper->createAction("Get Job Results", QIcon(), "Get Job Results", "Get Job Results", 0, _dock_parent, false, this, SLOT(refresh_job()));
@@ -154,6 +156,7 @@ BL::GenericGui::createMenus()
   _wrapper->addActionToMenu(_create_job_action, menu_id);
   _wrapper->addActionToMenu(_edit_clone_job_action, menu_id);
   _wrapper->addActionToMenu(_start_job_action, menu_id);
+  _wrapper->addActionToMenu(_restart_job_action, menu_id);
   _wrapper->addActionToMenu(_delete_job_action, menu_id);
   _wrapper->addActionToMenu(_get_results_job_action, menu_id);
   _wrapper->addActionToMenu(_refresh_job_action, menu_id);
@@ -163,14 +166,14 @@ void
 BL::GenericGui::create_job()
 {
   DEBTRACE("Create Job Slot BL::GenericGui");
-  _jobs_manager->create_job_wizard();
+  _jobs_manager->create_job();
 }
 
 void
 BL::GenericGui::edit_clone_job()
 {
   DEBTRACE("Edit/Clone Job Slot BL::GenericGui");
-  _jobs_manager->create_job_wizard(_job_name_selected.toStdString());
+  _jobs_manager->edit_clone_job(_job_name_selected.toStdString());
 }
 
 void
@@ -181,6 +184,14 @@ BL::GenericGui::start_job()
   updateButtonsStates();
 }
 
+void
+BL::GenericGui::restart_job()
+{
+  DEBTRACE("Restart Job Slot BL::GenericGui");
+  _jobs_manager->restart_job(_job_name_selected.toStdString());
+  updateButtonsStates();
+}
+
 void
 BL::GenericGui::refresh_job()
 {
@@ -204,15 +215,21 @@ BL::GenericGui::delete_job()
                                 QMessageBox::Ok);
   if (ret == QMessageBox::Ok)
   {
-    _jobs_manager->delete_job(_job_name_selected);
-    _model_manager->deleteJob(_row_selected);
-    emit job_deleted(_job_name_selected);
-    _row_selected = -1;
-    _job_name_selected = "";
-    updateButtonsStates();
+    delete_job_internal();
   }
 }
 
+void
+BL::GenericGui::delete_job_internal()
+{
+  _jobs_manager->delete_job(_job_name_selected);
+  _model_manager->deleteJob(_row_selected);
+  emit job_deleted(_job_name_selected);
+  _row_selected = -1;
+  _job_name_selected = "";
+  updateButtonsStates();
+}
+
 void
 BL::GenericGui::job_selected(const QModelIndex & index)
 {
@@ -246,6 +263,8 @@ BL::GenericGui::updateButtonsStates()
     _buttons->disable_get_results_button();
     _edit_clone_job_action->setEnabled(false);
     _buttons->disable_edit_clone_button();
+    _restart_job_action->setEnabled(false);
+    _buttons->disable_restart_button();
   }
   else if (_job_name_selected != "" and _row_selected != -1)
   {
@@ -263,6 +282,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_start_button();
        _buttons->enable_delete_button();
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(false);
+       _buttons->disable_restart_button();
        break;
 
       case BL::Job::IN_PROCESS:
@@ -272,6 +293,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->disable_delete_button();
        _get_results_job_action->setEnabled(false);
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(false);
+       _buttons->disable_restart_button();
        break;
 
       case BL::Job::QUEUED:
@@ -281,6 +304,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_delete_button();
        _get_results_job_action->setEnabled(false);
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(false);
+       _buttons->disable_restart_button();
        break;
 
       case BL::Job::RUNNING:
@@ -290,6 +315,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_delete_button();
        _get_results_job_action->setEnabled(false);
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(false);
+       _buttons->disable_restart_button();
        break;
 
       case BL::Job::PAUSED:
@@ -299,6 +326,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_delete_button();
        _get_results_job_action->setEnabled(false);
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(false);
+       _buttons->disable_restart_button();
        break;
 
       case BL::Job::ERROR:
@@ -308,6 +337,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_delete_button();
        _get_results_job_action->setEnabled(false);
        _buttons->disable_get_results_button();
+       _restart_job_action->setEnabled(true);
+       _buttons->enable_restart_button();
        break;
 
       case BL::Job::FINISHED:
@@ -317,6 +348,8 @@ BL::GenericGui::updateButtonsStates()
        _buttons->enable_delete_button();
        _get_results_job_action->setEnabled(true);
        _buttons->enable_get_results_button();
+       _restart_job_action->setEnabled(true);
+       _buttons->enable_restart_button();
        break;
     }
   }
index 0d0c03d2c87c7e87da7eb35a1b7a5b8ba29be95d..bc623b6943d1f28dceec8fae9326e9e18bebb55e 100644 (file)
@@ -50,10 +50,13 @@ namespace BL
       void createActions();
       void createMenus();
 
+      void delete_job_internal();
+
     public slots:
       void create_job();
       void edit_clone_job();
       void start_job();
+      void restart_job();
       void delete_job();
       void refresh_job();
       void get_results_job();
@@ -83,6 +86,7 @@ namespace BL
       QAction * _create_job_action;
       QAction * _edit_clone_job_action;
       QAction * _start_job_action;
+      QAction * _restart_job_action;
       QAction * _delete_job_action;
       QAction * _get_results_job_action;
       QAction * _refresh_job_action;
index db22286fc89e74321f5bd1275f39f4b25da7882a..5e75ecb409e4cab5766c06a4cd55abd71ca7abcc 100644 (file)
@@ -18,6 +18,7 @@
 //
 
 #include "BL_JobsManager_QT.hxx"
+#include "BL_GenericGui.hxx"
 
 BL::JobManagerEvent::JobManagerEvent(const std::string & action_i, 
                                     const std::string & event_name_i, 
@@ -32,10 +33,11 @@ BL::JobManagerEvent::JobManagerEvent(const std::string & action_i,
 
 BL::JobManagerEvent::~JobManagerEvent() {}  
 
-BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::SALOMEServices * salome_services) : 
+BL::JobsManager_QT::JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui, BL::SALOMEServices * salome_services) : 
   QDockWidget(parent), BL::JobsManager(salome_services)
 {
   DEBTRACE("Creating BL::JobsManager_QT");
+  _main_gui = main_gui;
   setObserver(this);
 
   // Widget Part
@@ -149,57 +151,51 @@ BL::JobsManager_QT::one_hour_refresh()
   _timer->start(1 * 60 * 60 * 1000);
 }
 
+void 
+BL::JobsManager_QT::restart_job(const std::string & name)
+{
+  DEBTRACE("Restart job with name: " << name);
+  BL::CreateJobWizard wizard(this, _salome_services);
+  wizard.clone(name);
+  wizard.end(1);
+  wizard.job_name = name;
+  wizard.start_job = true;
+  _main_gui->delete_job_internal();
+  create_job_with_wizard(wizard);
+}
+
+void 
+BL::JobsManager_QT::edit_clone_job(const std::string & name)
+{
+  BL::CreateJobWizard wizard(this, _salome_services);
+  wizard.clone(name);
+  wizard.exec();
+
+  // Check if the job has the same name
+  if (name == wizard.job_name)
+  {
+    DEBTRACE("Job " << name << " has been changed");
+    _main_gui->delete_job_internal();
+  }
+
+  if (wizard.job_name != "")
+  {
+    create_job_with_wizard(wizard);
+  }
+  else
+  {
+    DEBTRACE("User cancel Create Job Wizard");
+  }
+}
+
 void
-BL::JobsManager_QT::create_job_wizard(const std::string & name)
+BL::JobsManager_QT::create_job()
 {
     BL::CreateJobWizard wizard(this, _salome_services);
-    if (name != "")
-      wizard.clone(name);
     wizard.exec();
-
     if (wizard.job_name != "")
     {
-      BL::Job * new_job = createJob(wizard.job_name);
-      if (wizard.yacs_file != "")
-      {
-       // YACS schema job
-       new_job->setType(BL::Job::YACS_SCHEMA);
-       new_job->setJobFile(wizard.yacs_file);
-      }
-      else if (wizard.command != "")
-      {
-       // Command Job
-       new_job->setType(BL::Job::COMMAND);
-       new_job->setJobFile(wizard.command);
-      }
-      else if (wizard.python_salome_file != "")
-      {
-       // Command Job
-       new_job->setType(BL::Job::PYTHON_SALOME);
-       new_job->setJobFile(wizard.python_salome_file);
-      }
-
-      // For all jobs
-      new_job->setEnvFile(wizard.env_file);
-      BL::Job::BatchParam param;
-      param.batch_directory = wizard.batch_directory;
-      param.maximum_duration = wizard.maximum_duration;
-      param.expected_memory = wizard.expected_memory;
-      param.nb_proc = wizard.nb_proc;
-      new_job->setBatchParameters(param);
-      BL::Job::FilesParam files_params;
-      files_params.result_directory = wizard.result_directory;
-      files_params.input_files_list = wizard.input_files_list;
-      files_params.output_files_list = wizard.output_files_list;
-      new_job->setFilesParameters(files_params);
-      new_job->setResource(wizard.resource_choosed);
-      new_job->setBatchQueue(wizard.batch_queue);
-      
-      // End
-      addJobToLauncher(wizard.job_name);
-      emit new_job_added(QString::fromStdString(wizard.job_name));
-      if (wizard.start_job)
-       start_job(wizard.job_name);
+      create_job_with_wizard(wizard);
     }
     else
     {
@@ -207,6 +203,52 @@ BL::JobsManager_QT::create_job_wizard(const std::string & name)
     }
 }
 
+void 
+BL::JobsManager_QT::create_job_with_wizard(BL::CreateJobWizard & wizard)
+{
+  BL::Job * new_job = createJob(wizard.job_name);
+  if (wizard.yacs_file != "")
+  {
+    // YACS schema job
+    new_job->setType(BL::Job::YACS_SCHEMA);
+    new_job->setJobFile(wizard.yacs_file);
+  }
+  else if (wizard.command != "")
+  {
+    // Command Job
+    new_job->setType(BL::Job::COMMAND);
+    new_job->setJobFile(wizard.command);
+  }
+  else if (wizard.python_salome_file != "")
+  {
+    // Command Job
+    new_job->setType(BL::Job::PYTHON_SALOME);
+    new_job->setJobFile(wizard.python_salome_file);
+  }
+
+  // For all jobs
+  new_job->setEnvFile(wizard.env_file);
+  BL::Job::BatchParam param;
+  param.batch_directory = wizard.batch_directory;
+  param.maximum_duration = wizard.maximum_duration;
+  param.expected_memory = wizard.expected_memory;
+  param.nb_proc = wizard.nb_proc;
+  new_job->setBatchParameters(param);
+  BL::Job::FilesParam files_params;
+  files_params.result_directory = wizard.result_directory;
+  files_params.input_files_list = wizard.input_files_list;
+  files_params.output_files_list = wizard.output_files_list;
+  new_job->setFilesParameters(files_params);
+  new_job->setResource(wizard.resource_choosed);
+  new_job->setBatchQueue(wizard.batch_queue);
+
+  // End
+  addJobToLauncher(wizard.job_name);
+  emit new_job_added(QString::fromStdString(wizard.job_name));
+  if (wizard.start_job)
+    start_job(wizard.job_name);
+}
+
 void
 BL::JobsManager_QT::delete_job(QString job_name)
 {
index 86cfb1a82bf0561d97a68e43933304c616044132..46f19a257f9129230eeb36995a2ea3343c962832 100644 (file)
@@ -46,6 +46,7 @@ namespace BL{
       std::string data;
   };
 
+  class GenericGui;
   class JobsManager_QT: virtual public QDockWidget,
                        virtual public BL::JobsManager,
                        virtual public BL::Observer
@@ -53,11 +54,14 @@ namespace BL{
     Q_OBJECT
 
     public:
-      JobsManager_QT(QWidget * parent, BL::SALOMEServices * salome_services);
+      JobsManager_QT(QWidget * parent, BL::GenericGui * main_gui, BL::SALOMEServices * salome_services);
       virtual ~JobsManager_QT();
 
       void delete_job(QString job_name);
-      void create_job_wizard(const std::string & name = "");
+
+      void create_job();
+      void edit_clone_job(const std::string & name);
+      void restart_job(const std::string & name);
 
       virtual void sendEvent(const std::string & action, 
                             const std::string & event_name, 
@@ -68,6 +72,9 @@ namespace BL{
       void write_normal_text(const QString & text);
       void write_error_text(const QString & text);
 
+    protected:
+      void create_job_with_wizard(BL::CreateJobWizard & wizard);
+
     public slots:
       void RefreshJobs();
       void no_auto_refresh();
@@ -88,6 +95,7 @@ namespace BL{
       QPushButton * _auto_refresh_jobs;
       QTimer * _timer;
       QTextEdit * _log;
+      BL::GenericGui * _main_gui;
   };
 
 }