]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Merge branch 'omu/launcher_evol'
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 24 Jan 2018 16:36:47 +0000 (17:36 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 24 Jan 2018 16:36:47 +0000 (17:36 +0100)
For libbatch 2.4.

21 files changed:
idl/SALOME_Launcher.idl
idl/SALOME_ResourcesManager.idl
src/Launcher/CMakeLists.txt
src/Launcher/Launcher.cxx
src/Launcher/Launcher.hxx
src/Launcher/Launcher_Job.cxx
src/Launcher/Launcher_Job.hxx
src/Launcher/Launcher_Job_Command.cxx
src/Launcher/Launcher_Job_Command.hxx
src/Launcher/Launcher_Job_CommandSALOME.cxx [new file with mode: 0644]
src/Launcher/Launcher_Job_CommandSALOME.hxx [new file with mode: 0644]
src/Launcher/Launcher_Job_PythonSALOME.cxx
src/Launcher/Launcher_Job_PythonSALOME.hxx
src/Launcher/Launcher_Job_YACSFile.cxx
src/Launcher/Launcher_Job_YACSFile.hxx
src/Launcher/Launcher_XML_Persistence.cxx
src/Launcher/SALOME_Launcher.cxx
src/Launcher/SALOME_Launcher.hxx
src/Launcher/Test/CTestTestfileInstall.cmake
src/Launcher/Test/test_launcher.py
src/LifeCycleCORBA_SWIG/LifeCycleCORBA.py

index a114a998251ec9a00e9dcc8a5be25a3d8fb60af8..6f5b122111bb33879c15cc74e42e73ee5133f0e2 100644 (file)
@@ -52,6 +52,9 @@ struct JobParameters
   //! Type of the job.
   /*! There are three supported types:
         - "command" : execute #job_file script without %SALOME environment
+        - "command_salome" : execute #job_file script within %SALOME environment
+                             (salome shell) but the %SALOME application is not
+                             launched
         - "python_salome" : execute #job_file python script by %SALOME
         - "yacs_file" : execute #job_file by YACS module as a xml YACS schema
   */
@@ -66,6 +69,12 @@ struct JobParameters
   */
   string job_file;
 
+  //! Pre processing script.
+  /*! This script is called on the remote resource, from #work_directory, after
+      the copy of #in_files and before submiting the job.
+  */
+  string pre_command;
+
   //! Local path to a script to be sourced in the environment of the job.
   /*! It may contain modifications of environment variables.
   */
@@ -132,7 +141,12 @@ struct JobParameters
 
   //!  Name of the batch queue chosen - optional
   string queue;
-  
+
+  //! Name of the partition - optional
+  /*! It can be used only for slurm batch managers.
+  */
+  string partition;
+
   //! Specifies if the job must run in exclusive mode (without sharing nodes with other jobs)
   boolean exclusive;
 
@@ -198,6 +212,7 @@ interface SalomeLauncher
   /*! Launching the job consists of:
       - create the working directory on the remote file system
       - copy the input files into the working directory
+      - launch the pre processing command if one is defined
       - submit the job to the batch manager
   */
   void   launchJob    (in long job_id)                           raises (SALOME::SALOME_Exception);
@@ -243,6 +258,12 @@ interface SalomeLauncher
   */
   boolean getJobDumpState(in long job_id, in string directory)   raises (SALOME::SALOME_Exception);
 
+  //! Remove the working directory on the remote file system.
+  /*!
+     \param job_id    Job id returned by createJob().
+  */
+  void clearJobWorkingDir(in long job_id) raises (SALOME::SALOME_Exception);
+
   //! Retrieve one sigle file from the working directory.
   /*! Use this method if you don't want to copy all the results of the job,
       for instance if you want to obtain a file which contains the computing
index 4dafdf76d27a983586d05f062c966bc9c55660da..ee7461c3fc49c991da37ce1a73d0d918bb99b6da 100644 (file)
@@ -89,7 +89,7 @@ to map segment from shared object: Cannot allocate memory
   long mem_mb;
   //! required frequency
   long cpu_clock;
-  //! required number of nodes
+  //! required number of nodes. Can be used when submitting slurm jobs.
   long nb_node;
   //! required number of proc per node
   long nb_proc_per_node;
index 87737c5957889e1ea1986a32eb16cb2b5c87c91e..fe031c0dcf6948497fc7798496d30df8fab0febd 100755 (executable)
@@ -40,7 +40,7 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_BINARY_DIR}/idl
 )
 
-ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} ${OMNIORB_DEFINITIONS})
+ADD_DEFINITIONS(${LIBXML2_DEFINITIONS} ${BOOST_DEFINITIONS} ${OMNIORB_DEFINITIONS})
 IF(SALOME_USE_LIBBATCH)
   ADD_DEFINITIONS(-DWITH_LIBBATCH)
 ENDIF(SALOME_USE_LIBBATCH)
@@ -56,6 +56,8 @@ SET(COMMON_LIBS
   SALOMELocalTrace
   SALOMEBasics
   SalomeIDLKernel
+  ${Boost_FILESYSTEM_LIBRARY}
+  ${Boost_SYSTEM_LIBRARY}
   ${LIBBATCH_LIBRARIES}
   ${OMNIORB_LIBRARIES}
   ${LIBXML2_LIBRARIES}
@@ -67,6 +69,7 @@ SET(Launcher_SOURCES
   SALOME_Launcher_Handler.cxx
   Launcher_Job.cxx
   Launcher_Job_Command.cxx
+  Launcher_Job_CommandSALOME.cxx
   Launcher_Job_SALOME.cxx
   Launcher_Job_PythonSALOME.cxx
   Launcher_Job_YACSFile.cxx
@@ -83,6 +86,8 @@ SET(TestLauncher_LIBS
   ResourcesManager
   Launcher
   ${LIBBATCH_LIBRARIES}
+  ${Boost_FILESYSTEM_LIBRARY}
+  ${Boost_SYSTEM_LIBRARY}
 )
 
 # TestLauncher needs only (and must need only) libxml, libbatch, ResourceManager and Launcher libraries!
@@ -115,6 +120,7 @@ SET(COMMON_HEADERS_HXX
   Launcher.hxx
   Launcher_Job.hxx
   Launcher_Job_Command.hxx
+  Launcher_Job_CommandSALOME.hxx
   Launcher_Job_PythonSALOME.hxx
   Launcher_Job_SALOME.hxx
   Launcher_Job_YACSFile.hxx
index dfe536112ea084c6f090074717a6581dbc9d184e..b6737b1774036b9321836312d5db5c52eb080856 100644 (file)
@@ -249,6 +249,37 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
   LAUNCHER_MESSAGE("getJobResult ended");
 }
 
+//=============================================================================
+/*!
+ * Clear the remote working directory
+ */
+//=============================================================================
+void
+Launcher_cpp::clearJobWorkingDir(int job_id)
+{
+  LAUNCHER_MESSAGE("Clear the remote working directory");
+
+  // Check if job exist
+  std::map<int, Launcher::Job *>::const_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 ?");
+  }
+
+  Launcher::Job * job = it_job->second;
+  try
+  {
+    _batchmap[job_id]->clearWorkingDir(*(job->getBatchJob()));
+  }
+  catch(const Batch::GenericException &ex)
+  {
+    LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
+    throw LauncherException(ex.message.c_str());
+  }
+  LAUNCHER_MESSAGE("getJobResult ended");
+}
+
 //=============================================================================
 /*!
  * Get Job dump state - the result directory could be changed
@@ -576,6 +607,14 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
                           "(libBatch was not present at compilation time)");
 }
 
+void
+Launcher_cpp::clearJobWorkingDir(int job_id)
+{
+  LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot clear directory!!!");
+  throw LauncherException("Method Launcher_cpp::clearJobWorkingDir is not available "
+                          "(libBatch was not present at compilation time)");
+}
+
 bool
 Launcher_cpp::getJobDumpState(int job_id, std::string directory)
 {
index b7c66213746d519458c7278a9d04adfdf738b945..728694eddfe5a9047d568e43baf2d18c836cf7c1 100644 (file)
@@ -68,6 +68,7 @@ public:
   const char * getJobState(int job_id);
   const char * getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
   void         getJobResults(int job_id, std::string directory);
+  void         clearJobWorkingDir(int job_id);
   bool         getJobDumpState(int job_id, std::string directory);
   bool         getJobWorkFile(int job_id, std::string work_file, std::string directory);
   void         stopJob(int job_id);
index 2aae078fe1c87935dfc66f88c8d313d90f22da06..ed944325dbf46db0569344ec9f5a074664fbee59 100644 (file)
@@ -22,6 +22,7 @@
 //#define _DEBUG_
 #include "Launcher_Job.hxx"
 #include "Launcher.hxx"
+#include <boost/filesystem.hpp>
 
 #ifdef WITH_LIBBATCH
 #include <libbatch/Constants.hxx>
@@ -40,12 +41,14 @@ Launcher::Job::Job()
   _job_file = "";
   _job_file_name = "";
   _job_file_name_complete = "";
+  _pre_command = "";
   _work_directory = "";
   _local_directory = "";
   _result_directory = "";
   _maximum_duration = "";
   _maximum_duration_in_second = -1;
   _queue = "";
+  _partition = "";
   _job_type = "";
   _exclusive = false;
   _mem_per_cpu = 0;
@@ -305,6 +308,12 @@ Launcher::Job::setQueue(const std::string & queue)
   _queue = queue;
 }
 
+void
+Launcher::Job::setPartition(const std::string & partition)
+{
+  _partition = partition;
+}
+
 void
 Launcher::Job::setExclusive(bool exclusive)
 {
@@ -406,6 +415,12 @@ Launcher::Job::getQueue() const
   return _queue;
 }
 
+std::string
+Launcher::Job::getPartition() const
+{
+  return _partition;
+}
+
 bool
 Launcher::Job::getExclusive() const
 {
@@ -442,6 +457,18 @@ Launcher::Job::getReference() const
   return _reference;
 }
 
+void
+Launcher::Job::setPreCommand(const std::string & preCommand)
+{
+  _pre_command = preCommand;
+}
+
+std::string
+Launcher::Job::getPreCommand() const
+{
+  return _pre_command;
+}
+
 void
 Launcher::Job::checkMaximumDuration(const std::string & maximum_duration)
 {
@@ -571,6 +598,9 @@ Launcher::Job::common_job_params()
   params[Batch::NBPROC] = _resource_required_params.nb_proc;
   params[Batch::NBPROCPERNODE] = _resource_required_params.nb_proc_per_node;
 
+  if(_resource_required_params.nb_node > 0)
+    params[Batch::NBNODE] = _resource_required_params.nb_node;
+
   // Memory in megabytes
   if (_resource_required_params.mem_mb > 0)
   {
@@ -604,6 +634,13 @@ Launcher::Job::common_job_params()
     }
   }
   params[Batch::WORKDIR] = _work_directory;
+  std::string libbatch_pre_command("");
+  if(!_pre_command.empty())
+  {
+    boost::filesystem::path pre_command_path(_pre_command);
+    libbatch_pre_command += "./" + pre_command_path.filename().string();
+  }
+  params[Batch::PREPROCESS] = libbatch_pre_command;
 
   // Parameters for COORM
   params[Batch::LAUNCHER_FILE] = _launcher_file;
@@ -618,6 +655,8 @@ Launcher::Job::common_job_params()
   in_files.push_back(_job_file);
   if (_env_file != "")
           in_files.push_back(_env_file);
+  if(!_pre_command.empty())
+     in_files.push_back(_pre_command);
   for(std::list<std::string>::iterator it = in_files.begin(); it != in_files.end(); it++)
   {
     std::string file = *it;
@@ -670,6 +709,10 @@ Launcher::Job::common_job_params()
   if (_queue != "")
     params[Batch::QUEUE] = _queue;
 
+  // Partition
+  if (_partition != "")
+    params[Batch::PARTITION] = _partition;
+
   // Exclusive
   if (getExclusive())
     params[Batch::EXCLUSIVE] = true;
index 2f2322bf828eef095b4ad37182e6668c7ffd311d..44d5f75fe9862506d1879667660c8c47dd4fb2f6 100644 (file)
@@ -67,6 +67,7 @@ namespace Launcher
       // Common parameters
       void setJobName(const std::string & job_name);
       virtual void setJobFile(const std::string & job_file);
+      void setPreCommand(const std::string & preCommand);
       void setWorkDirectory(const std::string & work_directory);
       void setLocalDirectory(const std::string & local_directory);
       void setResultDirectory(const std::string & result_directory);
@@ -75,6 +76,7 @@ namespace Launcher
       void setMaximumDuration(const std::string & maximum_duration);
       void setResourceRequiredParams(const resourceParams & resource_required_params);
       void setQueue(const std::string & queue);
+      void setPartition(const std::string & partition);
       void setEnvFile(const std::string & env_file);
       void setExclusive(bool exclusive);
       void setExclusiveStr(const std::string & exclusiveStr);
@@ -82,12 +84,13 @@ namespace Launcher
       void setWCKey(const std::string & wckey);
       void setExtraParams(const std::string & extra_params);
       void setReference(const std::string & reference);
-         // For COORM
-         void setLauncherFile(const std::string & launcher_file);
-         void setLauncherArgs(const std::string & launcher_args);
+      // For COORM
+      void setLauncherFile(const std::string & launcher_file);
+      void setLauncherArgs(const std::string & launcher_args);
 
       std::string getJobName() const;
       std::string getJobFile() const;
+      std::string getPreCommand() const;
       std::string getWorkDirectory() const;
       std::string getLocalDirectory() const;
       std::string getResultDirectory() const;
@@ -96,6 +99,7 @@ namespace Launcher
       std::string getMaximumDuration() const;
       resourceParams getResourceRequiredParams() const;
       std::string getQueue() const;
+      std::string getPartition() const;
       std::string getEnvFile() const;
       std::string getJobType() const;
       bool getExclusive() const;
@@ -105,9 +109,9 @@ namespace Launcher
       std::string getExtraParams() const;
       std::string getReference() const;
 
-         // For COORM
-         std::string getLauncherFile() const;
-         std::string getLauncherArgs() const;
+      // For COORM
+      std::string getLauncherFile() const;
+      std::string getLauncherArgs() const;
 
       std::string updateJobState();
 
@@ -146,6 +150,7 @@ namespace Launcher
       std::string _job_file;
       std::string _job_file_name;
       std::string _job_file_name_complete;
+      std::string _pre_command;
 
       std::string _work_directory;
       std::string _local_directory;
@@ -157,15 +162,16 @@ namespace Launcher
       long _maximum_duration_in_second;
       resourceParams _resource_required_params;
       std::string _queue;
+      std::string _partition;
       bool _exclusive;
       unsigned long _mem_per_cpu;
       std::string _wckey;
       std::string _extra_params;
       std::string _reference; //! Reference of the job for the batch manager
 
-         // Parameters for COORM
-         std::string _launcher_file;
-         std::string _launcher_args;
+      // Parameters for COORM
+      std::string _launcher_file;
+      std::string _launcher_args;
 
 #ifdef WITH_LIBBATCH
     // Connection with LIBBATCH
index bdb0f2ec4e1303b156c0da7c7895b5443d6ef84d..ed4542bd11b6569bfeef01e1368d0279f7886e75 100644 (file)
 
 #include <sstream>
 
-Launcher::Job_Command::Job_Command() {_job_type = "command";}
+const char Launcher::Job_Command::TYPE_NAME[] = "command";
+
+Launcher::Job_Command::Job_Command()
+{
+  _job_type = Launcher::Job_Command::TYPE_NAME;
+}
 
 Launcher::Job_Command::~Job_Command() {}
 
@@ -72,7 +77,7 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
     std::string::size_type last = _env_file.find_last_of("/");
     launch_script_stream << ". ./" << _env_file.substr(last+1) << std::endl;
   }
-  launch_script_stream << "./" << _job_file_name_complete << " > " << work_directory <<"/logs/command_" << launch_date << ".log 2>&1" << std::endl;
+  launch_script_stream << runCommandString() << std::endl;
 
   // Return
   launch_script_stream.flush();
@@ -81,4 +86,11 @@ Launcher::Job_Command::buildCommandScript(Batch::Parametre params, std::string l
   chmod(_job_file.c_str(), 0x1ED);
   return launch_script;
 }
+
+std::string Launcher::Job_Command::runCommandString()
+{
+  std::ostringstream result;
+  result << "./" << _job_file_name_complete;
+  return result.str();
+}
 #endif
index 20dc95f7be4e357056cc2efd1b51d4931f93ef74..d95b01b5d0c38b3b7a5de66cc483ad1def719aa1 100644 (file)
@@ -39,9 +39,12 @@ namespace Launcher
 
       virtual void update_job();
 
+      static const char TYPE_NAME[];
+
 #ifdef WITH_LIBBATCH
     protected:
       std::string buildCommandScript(Batch::Parametre params, std::string launch_date);
+      virtual std::string runCommandString();
 #endif
   };
 }
diff --git a/src/Launcher/Launcher_Job_CommandSALOME.cxx b/src/Launcher/Launcher_Job_CommandSALOME.cxx
new file mode 100644 (file)
index 0000000..9bf0218
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2009-2017  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// Author: André RIBES - EDF R&D
+//
+#include "Launcher_Job_CommandSALOME.hxx"
+
+#ifdef WITH_LIBBATCH
+#include <libbatch/Constants.hxx>
+#endif
+
+#include <sstream>
+
+const char Launcher::Job_CommandSALOME::TYPE_NAME[] = "command_salome";
+
+Launcher::Job_CommandSALOME::Job_CommandSALOME()
+{
+  _job_type = Launcher::Job_CommandSALOME::TYPE_NAME;
+}
+
+Launcher::Job_CommandSALOME::~Job_CommandSALOME() {}
+
+
+#ifdef WITH_LIBBATCH
+
+std::string Launcher::Job_CommandSALOME::runCommandString()
+{
+  std::ostringstream result;
+  result << _resource_definition.AppliPath
+         << "/salome shell ./"
+         << _job_file_name_complete;
+  return result.str();
+}
+#endif
diff --git a/src/Launcher/Launcher_Job_CommandSALOME.hxx b/src/Launcher/Launcher_Job_CommandSALOME.hxx
new file mode 100644 (file)
index 0000000..dd3884b
--- /dev/null
@@ -0,0 +1,48 @@
+// Copyright (C) 2009-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// 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, 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// Author: André RIBES - EDF R&D
+//
+#ifndef _LAUNCHER_JOB_COMMAND_SALOME_HXX_
+#define _LAUNCHER_JOB_COMMAND_SALOME_HXX_
+
+#include "Launcher_Job_Command.hxx"
+#include "Launcher.hxx"
+
+#ifdef WITH_LIBBATCH
+#include <libbatch/Job.hxx>
+#endif
+
+namespace Launcher
+{
+  class LAUNCHER_EXPORT Job_CommandSALOME : virtual public Launcher::Job_Command
+  {
+    public:
+      Job_CommandSALOME();
+      virtual ~Job_CommandSALOME();
+      static const char TYPE_NAME[];
+
+#ifdef WITH_LIBBATCH
+    protected:
+      virtual std::string runCommandString();
+#endif
+  };
+}
+
+#endif
index 1ebc0dca888e3314e12e4d8c845f189f3680ef57..658e6c4c9689373a109c548a02d1b52b1d23d769 100644 (file)
 //
 #include "Launcher_Job_PythonSALOME.hxx"
 
+const char Launcher::Job_PythonSALOME::TYPE_NAME[] = "python_salome";
 
-Launcher::Job_PythonSALOME::Job_PythonSALOME() {_job_type = "python_salome";}
+Launcher::Job_PythonSALOME::Job_PythonSALOME()
+{
+  _job_type = Launcher::Job_PythonSALOME::TYPE_NAME;
+}
 
 Launcher::Job_PythonSALOME::~Job_PythonSALOME() {}
 
index 4a357765f74a0586dc66957da586921ba010c6dd..876f775db6b0f1f3173cea1953c7f7065aca4343 100644 (file)
@@ -34,6 +34,7 @@ namespace Launcher
 
       virtual void setJobFile(const std::string & job_file);
       virtual void addJobTypeSpecificScript(std::ofstream & launch_script_stream);
+      static const char TYPE_NAME[];
   };
 }
 
index 3880903516eb11f16dc645ab74833114e3c87d51..79e5b9a3f1a146a7437d9947f5708b7e9e6511ea 100644 (file)
 #include "Launcher_Job_YACSFile.hxx"
 #include <sstream>
 
+const char Launcher::Job_YACSFile::TYPE_NAME[] = "yacs_file";
 
 Launcher::Job_YACSFile::Job_YACSFile()
 {
-  _job_type = "yacs_file";
+  _job_type = Launcher::Job_YACSFile::TYPE_NAME;
   _dumpState = -1;
   _yacsDriverOptions = "";
 }
index 5cd2f8a1c930a121f2e0fdbb28f972465806492c..6572312442618551f21685a0288155ff3f2860fd 100644 (file)
@@ -36,6 +36,8 @@ namespace Launcher
       virtual void addJobTypeSpecificScript(std::ofstream & launch_script_stream);
       virtual void checkSpecificParameters();
 
+      static const char TYPE_NAME[];
+
     protected:
       int _dumpState;
       std::string _yacsDriverOptions;
index ab0c929b8a5a866ecb49a00ec5f5c36174fa19ff..f7db94e5825f074a8eb21051cd4d97332ef99573 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "Launcher_XML_Persistence.hxx"
 #include "Launcher_Job_Command.hxx"
+#include "Launcher_Job_CommandSALOME.hxx"
 #include "Launcher_Job_YACSFile.hxx"
 #include "Launcher_Job_PythonSALOME.hxx"
 
@@ -152,6 +153,8 @@ XML_Persistence::addJobToXmlDocument(xmlNodePtr root_node, const Job & job)
     addNode(node, "local_directory", job.getLocalDirectory());
   if (!job.getResultDirectory().empty())
     addNode(node, "result_directory", job.getResultDirectory());
+  if (!job.getPreCommand().empty())
+    addNode(node, "pre_command", job.getPreCommand());
 
   // Parameters for COORM
   if (!job.getLauncherFile().empty())
@@ -194,6 +197,8 @@ XML_Persistence::addJobToXmlDocument(xmlNodePtr root_node, const Job & job)
     addNode(node, "maximum_duration", job.getMaximumDuration());
   if (!job.getQueue().empty())
     addNode(node, "queue", job.getQueue());
+  if (!job.getPartition().empty())
+    addNode(node, "partition", job.getPartition());
   if (job.getExclusive())
     addNode(node, "exclusive", job.getExclusiveStr());
   if (job.getMemPerCpu() > 0)
@@ -237,11 +242,13 @@ XML_Persistence::createJobFromXmlNode(xmlNodePtr job_node)
   string job_type = getAttrValue(job_node, "type");
   if (job_type.empty())
     throw LauncherException(string("Invalid job \"") + job_name + "\": type is not defined");
-  if (job_type == "command")
+  if (job_type == Launcher::Job_Command::TYPE_NAME)
     new_job = new Launcher::Job_Command();
-  else if (job_type == "yacs_file")
+  else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
+    new_job = new Launcher::Job_CommandSALOME();
+  else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
     new_job = new Launcher::Job_YACSFile();
-  else if (job_type == "python_salome")
+  else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
     new_job = new Launcher::Job_PythonSALOME();
   else
   {
@@ -300,6 +307,8 @@ XML_Persistence::parseUserNode(Job * new_job, xmlNodePtr user_node)
     }
     else if (node_name == "env_file")
       new_job->setEnvFile(getNodeContent(current_node));
+    else if (node_name == "pre_command")
+      new_job->setPreCommand(getNodeContent(current_node));
     else if (node_name == "work_directory")
       new_job->setWorkDirectory(getNodeContent(current_node));
     else if (node_name == "local_directory")
@@ -332,6 +341,8 @@ XML_Persistence::parseUserNode(Job * new_job, xmlNodePtr user_node)
       new_job->setMaximumDuration(getNodeContent(current_node));
     else if (node_name == "queue")
       new_job->setQueue(getNodeContent(current_node));
+    else if (node_name == "partition")
+      new_job->setPartition(getNodeContent(current_node));
     else if (node_name == "exclusive")
       new_job->setExclusiveStr(getNodeContent(current_node));
     else if (node_name == "mem_per_cpu")
index 9a524131dd964c5ad282a1ebb350de91b89e4ba5..cc7129bf0878b7e0a88d12eb4348cc887667856a 100644 (file)
@@ -32,6 +32,7 @@
 #include "Launcher_Job_Command.hxx"
 #include "Launcher_Job_YACSFile.hxx"
 #include "Launcher_Job_PythonSALOME.hxx"
+#include "Launcher_Job_CommandSALOME.hxx"
 
 #include "utilities.h"
 
@@ -95,21 +96,22 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
 {
   std::string job_type = job_parameters.job_type.in();
 
-  if (job_type != "command" && job_type != "yacs_file" && job_type != "python_salome")
-  {
-    std::string message("SALOME_Launcher::createJob: bad job type: ");
-    message += job_type;
-    THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
-  }
-
   Launcher::Job * new_job; // It is Launcher_cpp that is going to destroy it
 
-  if (job_type == "command")
+  if (job_type == Launcher::Job_Command::TYPE_NAME)
     new_job = new Launcher::Job_Command();
-  else if (job_type == "yacs_file")
+  else if (job_type == Launcher::Job_CommandSALOME::TYPE_NAME)
+    new_job = new Launcher::Job_CommandSALOME();
+  else if (job_type == Launcher::Job_YACSFile::TYPE_NAME)
     new_job = new Launcher::Job_YACSFile();
-  else if (job_type == "python_salome")
+  else if (job_type == Launcher::Job_PythonSALOME::TYPE_NAME)
     new_job = new Launcher::Job_PythonSALOME();
+  else
+  {
+    std::string message("SALOME_Launcher::createJob: bad job type: ");
+    message += job_type;
+    THROW_SALOME_CORBA_EXCEPTION(message.c_str(), SALOME::INTERNAL_ERROR);
+  }
 
   // Name
   new_job->setJobName(job_parameters.job_name.in());
@@ -139,6 +141,7 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
     INFOS(ex.msg.c_str());
     THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR);
   }
+  new_job->setPreCommand(job_parameters.pre_command.in());
 
   // Files
   std::string env_file = job_parameters.env_file.in();
@@ -163,6 +166,10 @@ SALOME_Launcher::createJob(const Engines::JobParameters & job_parameters)
   std::string queue = job_parameters.queue.in();
   new_job->setQueue(queue);
 
+  // Partition
+  std::string partition = job_parameters.partition.in();
+  new_job->setPartition(partition);
+
   // Exclusive
   new_job->setExclusive(job_parameters.exclusive);
 
@@ -286,6 +293,20 @@ SALOME_Launcher::getJobResults(CORBA::Long job_id, const char * directory)
   }
 }
 
+void
+SALOME_Launcher::clearJobWorkingDir(CORBA::Long job_id)
+{
+  try
+  {
+    _l.clearJobWorkingDir(job_id);
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }
+}
+
 CORBA::Boolean
 SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
 {
@@ -504,6 +525,7 @@ SALOME_Launcher::getJobParameters(CORBA::Long job_id)
   job_parameters->work_directory   = CORBA::string_dup(job->getWorkDirectory().c_str());
   job_parameters->local_directory  = CORBA::string_dup(job->getLocalDirectory().c_str());
   job_parameters->result_directory = CORBA::string_dup(job->getResultDirectory().c_str());
+  job_parameters->pre_command      = CORBA::string_dup(job->getPreCommand().c_str());
 
   // Parameters for COORM
   job_parameters->launcher_file = CORBA::string_dup(job->getLauncherFile().c_str());
@@ -528,6 +550,7 @@ SALOME_Launcher::getJobParameters(CORBA::Long job_id)
 
   job_parameters->maximum_duration = CORBA::string_dup(job->getMaximumDuration().c_str());
   job_parameters->queue            = CORBA::string_dup(job->getQueue().c_str());
+  job_parameters->partition        = CORBA::string_dup(job->getPartition().c_str());
   job_parameters->exclusive        = job->getExclusive();
   job_parameters->mem_per_cpu      = job->getMemPerCpu();
   job_parameters->wckey            = CORBA::string_dup(job->getWCKey().c_str());
index cf4f5795d56090d8aa3fabeaee867fa486aa49a8..a04a5d48ee989c43e96a51096712eb1bf327e1e0 100644 (file)
@@ -51,6 +51,7 @@ public:
   char *      getJobState  (CORBA::Long job_id);
   char *      getAssignedHostnames  (CORBA::Long job_id); // Get names or ids of hosts assigned to the job
   void        getJobResults(CORBA::Long job_id, const char * directory);
+  void        clearJobWorkingDir(CORBA::Long job_id);
   CORBA::Boolean getJobDumpState(CORBA::Long job_id, const char * directory);
   CORBA::Boolean getJobWorkFile(CORBA::Long job_id, const char * work_file, const char * directory);
   void        stopJob      (CORBA::Long job_id);
index 664c74c99ca0edfa285954595fb3b5a947cbcfa3..3d4df3a2d0251415da7372351d6552d0fe1342de 100644 (file)
@@ -19,7 +19,7 @@
 
 IF(NOT WIN32)
   SET(TEST_NAME ${COMPONENT_NAME}_Launcher)
-  ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} test_launcher.py)
+  ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} 2000 test_launcher.py)
   SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}"
     #                                                 TIMEOUT 500
     )
index 59803aa7b57612f9af56ac1d728c50ef276d2739..cbbf1b8998a90fb638942b802a3128f74b063561 100755 (executable)
@@ -61,6 +61,13 @@ class TestCompo(unittest.TestCase):
     except IOError,ex:
       self.fail("IO exception:" + str(ex));
 
+  def create_JobParameters(self):
+    job_params = salome.JobParameters()
+    job_params.wckey="P11U50:CARBONES" #needed by edf clusters
+    job_params.resource_required = salome.ResourceParameters()
+    job_params.resource_required.nb_proc = 1
+    return job_params
+
   ##############################
   # test of python_salome job
   ##############################
@@ -96,13 +103,11 @@ f.close()
     f.close()
 
     local_result_dir = os.path.join(case_test_dir, "result_py_job-")
-    job_params = salome.JobParameters()
+    job_params = self.create_JobParameters()
     job_params.job_type = "python_salome"
     job_params.job_file = job_script_file
     job_params.in_files = []
     job_params.out_files = ["result.txt", "subdir"]
-    job_params.resource_required = salome.ResourceParameters()
-    job_params.resource_required.nb_proc = 1
 
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
 
@@ -194,15 +199,13 @@ f.close()
 
     # job params
     local_result_dir = os.path.join(case_test_dir, "result_com_job-")
-    job_params = salome.JobParameters()
+    job_params = self.create_JobParameters()
     job_params.job_type = "command"
     job_params.job_file = script_file
     job_params.env_file = env_file
     job_params.in_files = [data_file]
     job_params.out_files = ["result.txt", "copie"]
     job_params.local_directory = case_test_dir
-    job_params.resource_required = salome.ResourceParameters()
-    job_params.resource_required.nb_proc = 1
 
     # create and launch the job
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
@@ -299,7 +302,7 @@ f.close()
     f.close()
 
     local_result_dir = os.path.join(case_test_dir, "result_yacs_job-")
-    job_params = salome.JobParameters()
+    job_params = self.create_JobParameters()
     job_params.job_type = "yacs_file"
     job_params.job_file = job_script_file
     job_params.env_file = os.path.join(case_test_dir,env_file)
@@ -308,8 +311,6 @@ f.close()
     # define the interval between two YACS schema dumps (3 seconds)
     import Engines
     job_params.specific_parameters = [Engines.Parameter("EnableDumpYACS", "3")]
-    job_params.resource_required = salome.ResourceParameters()
-    job_params.resource_required.nb_proc = 1
 
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
     resManager= salome.lcc.getResourcesManager()
@@ -412,10 +413,9 @@ f.close()
     f.close()
 
     local_result_dir = os.path.join(case_test_dir, "result_yacsopt_job-")
-    job_params = salome.JobParameters()
+    job_params = self.create_JobParameters()
     job_params.job_type = "yacs_file"
     job_params.job_file = job_script_file
-    #job_params.env_file = os.path.join(case_test_dir,env_file)
     job_params.out_files = ["result.txt"]
 
     # define the interval between two YACS schema dumps (3 seconds)
@@ -423,8 +423,6 @@ f.close()
     job_params.specific_parameters = [Engines.Parameter("YACSDriverOptions",
                "-imynode.i=5 -imynode.d=3.7 -imynode.b=False -imynode.s=lili")]
     expected_result="i=5,d=3.7,b=False,s=lili"
-    job_params.resource_required = salome.ResourceParameters()
-    job_params.resource_required.nb_proc = 1
 
     launcher = salome.naming_service.Resolve('/SalomeLauncher')
     resManager= salome.lcc.getResourcesManager()
@@ -460,6 +458,195 @@ f.close()
       self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
                       expected_result)
 
+  ############################################
+  # test of command job type with pre_command
+  ############################################
+  def test_command_pre(self):
+    case_test_dir = os.path.join(TestCompo.test_dir, "command_pre")
+    mkdir_p(case_test_dir)
+
+    # command to be run before the job
+    pre_command = "pre_command.sh"
+    pre_command_text = "echo 'it works!' > in.txt"
+    abs_pre_command_file = os.path.join(case_test_dir, pre_command)
+    f = open(abs_pre_command_file, "w")
+    f.write(pre_command_text)
+    f.close()
+    os.chmod(abs_pre_command_file, 0o755)
+    
+    # job script
+    script_file = "myTestScript.py"
+    script_text = """#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+in_f = open("in.txt", "r")
+in_text = in_f.read()
+in_f.close()
+
+f = open('result.txt', 'w')
+f.write(in_text)
+f.close()
+"""
+    abs_script_file = os.path.join(case_test_dir, script_file)
+    f = open(abs_script_file, "w")
+    f.write(script_text)
+    f.close()
+    os.chmod(abs_script_file, 0o755)
+
+    # job params
+    local_result_dir = os.path.join(case_test_dir, "result_com_pre_job-")
+    job_params = self.create_JobParameters()
+    job_params.job_type = "command"
+    job_params.job_file = script_file
+    job_params.pre_command = pre_command
+    job_params.in_files = []
+    job_params.out_files = ["result.txt"]
+    job_params.local_directory = case_test_dir
+
+    # create and launch the job
+    launcher = salome.naming_service.Resolve('/SalomeLauncher')
+    resManager= salome.lcc.getResourcesManager()
+
+    for resource in self.ressources:
+      print "Testing command job on ", resource
+      job_params.result_directory = local_result_dir + resource
+      job_params.job_name = "CommandPreJob_" + resource
+      job_params.resource_required.name = resource
+
+      # use the working directory of the resource
+      resParams = resManager.GetResourceDefinition(resource)
+      wd = os.path.join(resParams.working_directory,
+                        "CommandPreJob" + self.suffix)
+      job_params.work_directory = wd
+
+      job_id = launcher.createJob(job_params)
+      launcher.launchJob(job_id)
+      # wait for the end of the job
+      jobState = launcher.getJobState(job_id)
+      print "Job %d state: %s" % (job_id,jobState)
+      while jobState != "FINISHED" and jobState != "FAILED" :
+        time.sleep(3)
+        jobState = launcher.getJobState(job_id)
+        print "Job %d state: %s" % (job_id,jobState)
+        pass
+
+      # verify the results
+      self.assertEqual(jobState, "FINISHED")
+      launcher.getJobResults(job_id, "")
+      self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+                      "it works!\n")
+
+  #################################
+  # test of command salome job type
+  #################################
+  def test_command_salome(self):
+    case_test_dir = os.path.join(TestCompo.test_dir, "command_salome")
+    mkdir_p(case_test_dir)
+
+    # job script
+    data_file = "in.txt"
+    script_file = "myEnvScript.py"
+    script_text = """#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os,sys
+# verify import salome
+import salome
+
+text_result = os.getenv("ENV_TEST_VAR","")
+
+f = open('result.txt', 'w')
+f.write(text_result)
+f.close()
+
+in_f = open("in.txt", "r")
+in_text = in_f.read()
+in_f.close()
+
+os.mkdir("copie")
+f = open(os.path.join("copie",'copie.txt'), 'w')
+f.write(in_text)
+f.close()
+"""
+    abs_script_file = os.path.join(case_test_dir, script_file)
+    f = open(abs_script_file, "w")
+    f.write(script_text)
+    f.close()
+    os.chmod(abs_script_file, 0o755)
+
+    #environement script
+    env_file = "myEnv.sh"
+    env_text = """export ENV_TEST_VAR="expected"
+"""
+    f = open(os.path.join(case_test_dir, env_file), "w")
+    f.write(env_text)
+    f.close()
+
+    # write data file
+    f = open(os.path.join(case_test_dir, data_file), "w")
+    f.write("to be copied")
+    f.close()
+
+    # job params
+    local_result_dir = os.path.join(case_test_dir, "result_comsalome_job-")
+    job_params = self.create_JobParameters()
+    job_params.job_type = "command_salome"
+    job_params.job_file = script_file
+    job_params.env_file = env_file
+    job_params.in_files = [data_file]
+    job_params.out_files = ["result.txt", "copie"]
+    job_params.local_directory = case_test_dir
+
+    # create and launch the job
+    launcher = salome.naming_service.Resolve('/SalomeLauncher')
+    resManager= salome.lcc.getResourcesManager()
+
+    for resource in self.ressources:
+      print "Testing command salome job on ", resource
+      job_params.result_directory = local_result_dir + resource
+      job_params.job_name = "CommandSalomeJob_" + resource
+      job_params.resource_required.name = resource
+
+      # use the working directory of the resource
+      resParams = resManager.GetResourceDefinition(resource)
+      wd = os.path.join(resParams.working_directory,
+                        "CommandSalomeJob" + self.suffix)
+      job_params.work_directory = wd
+
+      job_id = launcher.createJob(job_params)
+      launcher.launchJob(job_id)
+      # wait for the end of the job
+      jobState = launcher.getJobState(job_id)
+      print "Job %d state: %s" % (job_id,jobState)
+      while jobState != "FINISHED" and jobState != "FAILED" :
+        time.sleep(3)
+        jobState = launcher.getJobState(job_id)
+        print "Job %d state: %s" % (job_id,jobState)
+        pass
+
+      # verify the results
+      self.assertEqual(jobState, "FINISHED")
+      launcher.getJobResults(job_id, "")
+      self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+                      "expected")
+      self.verifyFile(os.path.join(job_params.result_directory,
+                                   "copie",'copie.txt'),
+                      "to be copied")
+
+      # verify getJobWorkFile
+      mydir = os.path.join(case_test_dir, "work_dir" + resource)
+      success = launcher.getJobWorkFile(job_id, "result.txt", mydir)
+      self.assertEqual(success, True)
+      self.verifyFile(os.path.join(mydir, "result.txt"), "expected")
+
+      success = launcher.getJobWorkFile(job_id, "copie", mydir)
+      self.assertEqual(success, True)
+      self.verifyFile(os.path.join(mydir, "copie", "copie.txt"),
+                      "to be copied")
+      pass
+    pass
+  pass
+
 if __name__ == '__main__':
     # create study
     import salome
index 2087b1bcf8d291f11f233dc0250a02d97c3a04e6..d7f4e634f37546ad52ed3c38e579ce03e71a4892 100644 (file)
@@ -58,9 +58,9 @@ class ResourceParameters (Engines.ResourceParameters):
                                         nb_proc_per_node, policy, resList)
 
 class JobParameters (Engines.JobParameters):
-  def __init__(self, job_name="", job_type="", job_file="", env_file="", in_files=None, out_files=None,
+  def __init__(self, job_name="", job_type="", job_file="", pre_command="", env_file="", in_files=None, out_files=None,
                      work_directory="", local_directory="", result_directory="", maximum_duration="",
-                     resource_required=None, queue="", exclusive = False, mem_per_cpu = 0,
+                     resource_required=None, queue="", partition="", exclusive = False, mem_per_cpu = 0,
                      wckey = "", extra_params = "",
                      specific_parameters=None, launcher_file = "", launcher_args = ""):
     if in_files is None:
@@ -69,9 +69,9 @@ class JobParameters (Engines.JobParameters):
       out_files = []
     if specific_parameters is None:
       specific_parameters = []
-    Engines.JobParameters.__init__(self, job_name, job_type, job_file, env_file, in_files, out_files,
+    Engines.JobParameters.__init__(self, job_name, job_type, job_file, pre_command, env_file, in_files, out_files,
                                          work_directory, local_directory, result_directory, maximum_duration,
-                                         resource_required, queue, exclusive, mem_per_cpu,
+                                         resource_required, queue, partition, exclusive, mem_per_cpu,
                                          wckey, extra_params,
                                          specific_parameters, launcher_file, launcher_args)