]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Add the possibility to retrieve one single file with SalomeLauncher.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 16 Dec 2014 15:33:15 +0000 (16:33 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Tue, 16 Dec 2014 15:33:15 +0000 (16:33 +0100)
EDF pleiade issue n° 9110.

idl/SALOME_Launcher.idl
src/Launcher/Launcher.cxx
src/Launcher/Launcher.hxx
src/Launcher/SALOME_Launcher.cxx
src/Launcher/SALOME_Launcher.hxx
src/Launcher/Test/test_launcher.py

index ca27ffa57191c9e03633835915ad2c1df0bbb54f..a1427ba61bc5a331029d68d531f2a7177f55b5dd 100644 (file)
@@ -241,6 +241,22 @@ interface SalomeLauncher
   */
   boolean getJobDumpState(in long job_id, in string directory)   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
+      progress while the job is running.
+     \param job_id    Job id returned by createJob().
+     \param work_file Path to the file to be copied, relative to the
+                      working directory of the job. If it is a directory,
+                      it will be copied recursively.
+     \param directory Local directory where to copy the file.
+                      If this value is an empty string (""), the file will be
+                      copied to the directory given by
+                      JobParameters::result_directory.
+     \return 1 if the copy succeeds.
+  */
+  boolean getJobWorkFile(in long job_id, in string work_file, in string directory)   raises (SALOME::SALOME_Exception);
+
   //! Kill the job and set its state to "FAILED"
   void   stopJob      (in long job_id)                           raises (SALOME::SALOME_Exception);
   //! Kill the job and remove it from the jobs list
index 5be41bf466f036ac3a41ac1e33c5b0ce4c7bea20..afeade7bff608eb444062b606a327d72284826dc 100644 (file)
@@ -286,6 +286,45 @@ Launcher_cpp::getJobDumpState(int job_id, std::string directory)
   return rtn;
 }
 
+//=============================================================================
+/*!
+ * Get one file from the working directory - the result directory can be changed
+ */
+//=============================================================================
+bool
+Launcher_cpp::getJobWorkFile(int job_id,
+                             std::string work_file,
+                             std::string directory)
+{
+  bool rtn;
+  LAUNCHER_MESSAGE("Get working file " << work_file);
+
+  // 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;
+  std::string resource_name = job->getResourceDefinition().Name;
+  try
+  {
+    if (directory != "")
+      rtn = _batchmap[job_id]->importWorkFile(*(job->getBatchJob()), work_file, directory);
+    else
+      rtn = _batchmap[job_id]->importWorkFile(*(job->getBatchJob()), work_file, job->getResultDirectory());
+  }
+  catch(const Batch::GenericException &ex)
+  {
+    LAUNCHER_INFOS("getJobWorkFile is maybe incomplete, exception: " << ex.message);
+    throw LauncherException(ex.message.c_str());
+  }
+  LAUNCHER_MESSAGE("getJobWorkFile ended");
+  return rtn;
+}
+
 //=============================================================================
 /*!
  * Remove the job - into the Launcher and its batch manager
@@ -545,6 +584,14 @@ Launcher_cpp::getJobDumpState(int job_id, std::string directory)
                           "(libBatch was not present at compilation time)");
 }
 
+bool
+Launcher_cpp::getJobWorkFile(int job_id, std::string work_file, std::string directory)
+{
+  LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job dump state!!!");
+  throw LauncherException("Method Launcher_cpp::getJobWorkFile is not available "
+                          "(libBatch was not present at compilation time)");
+}
+
 void
 Launcher_cpp::removeJob(int job_id)
 {
index 0372d22c2e79a1b9964fd6ba73b114c38eebff09..2ec6c3c0d8968a5e641827e68fd7bd4845f376f5 100644 (file)
@@ -69,6 +69,7 @@ public:
   const char * getAssignedHostnames(int job_id); // Get names or ids of hosts assigned to the job
   void         getJobResults(int job_id, std::string directory);
   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);
   void         removeJob(int job_id);
 
index 3c16fdf7a026ca21a57ab77c4544de17e4bd0a67..667ede1cad9ed765a07770d4c7a435695d58c637 100644 (file)
@@ -298,6 +298,22 @@ SALOME_Launcher::getJobDumpState(CORBA::Long job_id, const char * directory)
   return rtn;
 }
 
+CORBA::Boolean
+SALOME_Launcher::getJobWorkFile(CORBA::Long job_id, const char * work_file, const char * directory)
+{
+  CORBA::Boolean rtn = false;
+  try
+  {
+    rtn = _l.getJobWorkFile(job_id, work_file, directory);
+  }
+  catch(const LauncherException &ex)
+  {
+    INFOS(ex.msg.c_str());
+    THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM);
+  }
+  return rtn;
+}
+
 void 
 SALOME_Launcher::removeJob(CORBA::Long job_id)
 {
index ffb339e05301ca46f5879d8bd5bd1c5795629020..40b78c57b14494ab1a1bf88c9098c3b7133448ff 100644 (file)
@@ -52,6 +52,7 @@ public:
   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);
   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);
   void        removeJob    (CORBA::Long job_id);
 
index 9ae3ca55cc86901a9c593356ae462d7dde08f921..86d5d61aa20731fb7f2027d3560d0f7b1e4f9a49 100755 (executable)
@@ -40,6 +40,15 @@ class TestCompo(unittest.TestCase):
     rm = salome.lcc.getResourcesManager()
     cls.ressources = rm.GetFittingResources(ressource_param)
 
+  def verifyFile(self, path, content):
+    try:
+      f = open(path, 'r')
+      text = f.read()
+      f.close()
+      self.assertEqual(text, content)
+    except IOError,ex:
+      self.fail("IO exception:" + str(ex));
+
   ##############################
   # test of python_salome job
   ##############################
@@ -107,42 +116,17 @@ f.close()
 
       # getJobResults to default directory (result_directory)
       launcher.getJobResults(job_id, "")
-      try:
-        f = open(os.path.join(job_params.result_directory, "result.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "Salut!")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
-
-      try:
-        f = open(os.path.join(job_params.result_directory,
-                              "subdir", "autre.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "Hello!")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
+      self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+                      "Salut!")
+      self.verifyFile(os.path.join(job_params.result_directory,
+                                   "subdir", "autre.txt"),
+                      "Hello!")
 
       # getJobResults to a specific directory
       mydir = os.path.join(case_test_dir, "custom_result_dir" + resource)
       launcher.getJobResults(job_id, mydir)
-      try:
-        f = open(os.path.join(mydir, "result.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "Salut!")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
-
-      try:
-        f = open(os.path.join(mydir, "subdir", "autre.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "Hello!")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
-        pass
+      self.verifyFile(os.path.join(mydir, "result.txt"), "Salut!")
+      self.verifyFile(os.path.join(mydir, "subdir", "autre.txt"), "Hello!")
       pass #for
 
     os.chdir(old_dir)
@@ -238,22 +222,23 @@ f.close()
       # verify the results
       self.assertEqual(jobState, "FINISHED")
       launcher.getJobResults(job_id, "")
-      try:
-        f = open(os.path.join(job_params.result_directory, "result.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "expected")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
-
-      try:
-        f = open(os.path.join(job_params.result_directory,
-                              "copie",'copie.txt'), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "to be copied")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex));
+      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")
+
 
   ##############################
   # test of yacs job type
@@ -338,6 +323,7 @@ f.close()
       while jobState != "FINISHED" and jobState != "FAILED" :
         time.sleep(5)
         jobState = launcher.getJobState(job_id)
+#        yacs_dump_success = launcher.getJobWorkFile(job_id, "dumpState_mySchema.xml",
         yacs_dump_success = launcher.getJobDumpState(job_id,
                                               job_params.result_directory)
         print "Job %d state: %s - dump: %s" % (job_id,jobState, yacs_dump_success)
@@ -364,13 +350,8 @@ f.close()
 
       # getJobResults to default directory (result_directory)
       launcher.getJobResults(job_id, "")
-      try:
-        f = open(os.path.join(job_params.result_directory, "result.txt"), 'r')
-        text = f.read()
-        f.close()
-        self.assertEqual(text, "expected")
-      except IOError,ex:
-        self.fail("IO exception:" + str(ex))
+      self.verifyFile(os.path.join(job_params.result_directory, "result.txt"),
+                      "expected")
     
 if __name__ == '__main__':
     # creat study