Salome HOME
Adding new Launcher method: stop_job
authorribes <ribes>
Tue, 11 Oct 2011 16:01:52 +0000 (16:01 +0000)
committerribes <ribes>
Tue, 11 Oct 2011 16:01:52 +0000 (16:01 +0000)
Bug tracker PAL Id: #1960

idl/SALOME_ContainerManager.idl
src/Launcher/Launcher.cxx
src/Launcher/Launcher.hxx
src/Launcher/Launcher_Job.cxx
src/Launcher/Launcher_Job.hxx
src/Launcher/SALOME_Launcher.cxx
src/Launcher/SALOME_Launcher.hxx

index 8c36eb64afc7c97aef7ec6ecfb0767ec04dbed95..c984ace36d78883e4f1bd2094e862941e8e69db9 100644 (file)
@@ -210,6 +210,7 @@ interface SalomeLauncher
   string getJobState  (in long job_id)                           raises (SALOME::SALOME_Exception);
   void   getJobResults(in long job_id, in string directory)      raises (SALOME::SALOME_Exception);
   boolean getJobDumpState(in long job_id, in string directory)   raises (SALOME::SALOME_Exception);
+  void   stopJob      (in long job_id)                           raises (SALOME::SALOME_Exception);
   void   removeJob    (in long job_id)                           raises (SALOME::SALOME_Exception);
 
   // Useful methods
index 38d3243ffab2d2780e78cdfe8770ee55bcd9b3f2..c2d506d75aea941e9987c2f744ec45c490ae53de 100644 (file)
@@ -270,6 +270,27 @@ Launcher_cpp::removeJob(int job_id)
   _launcher_job_map.erase(it_job);
 }
 
+//=============================================================================
+/*!
+ * stop the job
+ */ 
+//=============================================================================
+void
+Launcher_cpp::stopJob(int job_id)
+{
+  LAUNCHER_MESSAGE("Stop Job");
+
+  // Check if job exist
+  std::map<int, Launcher::Job *>::iterator it_job = _launcher_job_map.find(job_id);
+  if (it_job == _launcher_job_map.end())
+  {
+    LAUNCHER_INFOS("Cannot find the job, is it created ? job number: " << job_id);
+    throw LauncherException("Cannot find the job, is it created ?");
+  }
+
+  it_job->second->stopJob();
+}
+
 //=============================================================================
 /*! 
  *  create a launcher job based on a file
index b07463f0debd93f412f2d8f96ba2887eae1010a0..2059e0eb4e060e4f07754476d3cca4d532c3cff0 100644 (file)
@@ -63,6 +63,7 @@ public:
   const char * getJobState(int job_id);
   void         getJobResults(int job_id, std::string directory);
   bool         getJobDumpState(int job_id, std::string directory);
+  void         stopJob(int job_id);
   void         removeJob(int job_id);
 
   // Useful methods
index 52622cd23ca83d97a451a5587c5e9d78d9791d1f..5728af45ee5a2a62bcca60bd9b12e4db4c18e7c7 100644 (file)
@@ -67,6 +67,27 @@ Launcher::Job::~Job()
 #endif
 }
 
+void
+Launcher::Job::stopJob()
+{
+  LAUNCHER_MESSAGE("Stop resquested for job number: " << _number);
+  setState("FAILED");
+#ifdef WITH_LIBBATCH
+  if (_batch_job_id.getReference() != "undefined")
+  {
+    try 
+    {
+      _batch_job_id.deleteJob();
+    }
+    catch (const Batch::EmulationException &ex)
+    {
+      LAUNCHER_INFOS("WARNING: exception when stopping the job: " << ex.message);
+    }
+  }
+#endif
+}
+
+
 void
 Launcher::Job::removeJob()
 {
@@ -404,8 +425,8 @@ std::string
 Launcher::Job::updateJobState()
 {
 
-  if (_state != "FINISHED" ||
-      _state != "ERROR"    ||
+  if (_state != "FINISHED" &&
+      _state != "ERROR"    &&
       _state != "FAILED")
   {
 #ifdef WITH_LIBBATCH
index 183590a767c7b2318743965af411d4286e36c942..4c07e3974d3b639f32b9627a960a527d3350c485 100644 (file)
@@ -109,6 +109,7 @@ namespace Launcher
       // Xml method
       void addToXmlDocument(xmlNodePtr root_node);
 
+      void stopJob();
       void removeJob();
 
       // Abstract class
index 40e019d459a519388b3c36fe3f521cdd348ff56c..afca47cd499eb7d734d6a9007b1ae5055e43737c 100644 (file)
@@ -276,6 +276,23 @@ SALOME_Launcher::removeJob(CORBA::Long job_id)
   }
 }
 
+void 
+SALOME_Launcher::stopJob(CORBA::Long job_id)
+{
+  try
+  {
+    _l.stopJob(job_id);
+    std::ostringstream job_id_str;
+    job_id_str << job_id;
+    notifyObservers("UPDATE_JOB_STATE", job_id_str.str());
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }
+}
+
 //=============================================================================
 /*! CORBA Method:
  *  Create a job in the launcher with a file
index c084d0337c86fe0443f142d8417ea7cd9e952bb1..e0c90eda28d9d7d6e3de451e79c063543620f97e 100644 (file)
@@ -51,6 +51,7 @@ public:
   char *      getJobState  (CORBA::Long job_id);
   void        getJobResults(CORBA::Long job_id, const char * directory);
   CORBA::Boolean getJobDumpState(CORBA::Long job_id, const char * directory);
+  void        stopJob      (CORBA::Long job_id);
   void        removeJob    (CORBA::Long job_id);
 
   // Useful methods