Salome HOME
Add command_salome job type. omu/launcher_evol
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 24 Jan 2018 16:26:08 +0000 (17:26 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Wed, 24 Jan 2018 16:26:08 +0000 (17:26 +0100)
13 files changed:
idl/SALOME_Launcher.idl
src/Launcher/CMakeLists.txt
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/Test/test_launcher.py

index 2506fa52e7cafcb7b5cfb37a92b1e25b50992f7a..51c5af298f3ad6b223df6bc5ae3d68cdc0f23999 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
   */
index 4c8560db39e8cfb923dedfccf967e550e020b98b..4ace6169cdd535eb046e7fb44f36cc06e4823bea 100755 (executable)
@@ -69,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
@@ -119,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 9a4fdf0f84d5f0a5225fac7198f95ebbc46919fc..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 << 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 8da04042330c85370451b42573650a5faf659423..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"
 
@@ -241,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
   {
index 8849b855e8c979e00a7a5551718e9073cd86888d..3acc98d860dc3a696ae6154ca1266d5e24ecf009 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());
index 991c05599daad92faba56e9ebe2bfdcfa513e854..7c11e64e0e4e0ac210e814a31f0e59948669be5d 100755 (executable)
@@ -536,6 +536,117 @@ f.close()
       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__':
     # creat study
     import salome