From: ribes Date: Tue, 11 Oct 2011 16:01:52 +0000 (+0000) Subject: Adding new Launcher method: stop_job X-Git-Tag: Before_0020136~18 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0068c6c6e98b59f5ba83efd537de361bae3a9f66;p=modules%2Fkernel.git Adding new Launcher method: stop_job Bug tracker PAL Id: #1960 --- diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 8c36eb64a..c984ace36 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -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 diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 38d3243ff..c2d506d75 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -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::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 diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index b07463f0d..2059e0eb4 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -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 diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index 52622cd23..5728af45e 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -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 diff --git a/src/Launcher/Launcher_Job.hxx b/src/Launcher/Launcher_Job.hxx index 183590a76..4c07e3974 100644 --- a/src/Launcher/Launcher_Job.hxx +++ b/src/Launcher/Launcher_Job.hxx @@ -109,6 +109,7 @@ namespace Launcher // Xml method void addToXmlDocument(xmlNodePtr root_node); + void stopJob(); void removeJob(); // Abstract class diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 40e019d45..afca47cd4 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -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 diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index c084d0337..e0c90eda2 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -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