]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF30356] : Extend management of maximum_time attribute format from pylauncher to...
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 14 Jun 2024 11:56:16 +0000 (13:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 14 Jun 2024 11:56:16 +0000 (13:56 +0200)
src/Launcher/Launcher.cxx
src/Launcher/Launcher.hxx
src/Launcher/Launcher_Job.cxx
src/Launcher/Launcher_Job.hxx
src/Launcher_SWIG/Launcher.i
src/Launcher_SWIG/Test/test_swig_launcher.py

index 2002a187a32982fd403b55540227ebf36a6b619b..4a72dc7161501a2689a99de2dc62b6f0dafe3ef5 100644 (file)
@@ -392,6 +392,12 @@ Launcher_cpp::getJobWorkFile(int job_id,
   return rtn;
 }
 
+long Launcher_cpp::getMaximumDurationInSecond(int job_id)
+{
+  Launcher::Job *job = findJob(job_id);
+  return job->getMaximumDurationInSecond();
+}
+
 //=============================================================================
 /*!
  * Remove the job - into the Launcher and its batch manager
@@ -756,6 +762,13 @@ Launcher_cpp::getJobWorkFile(int job_id, std::string work_file, std::string dire
                           "(libBatch was not present at compilation time)");
 }
 
+long Launcher_cpp::getMaximumDurationInSecond(int job_id)
+{
+  LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job dump state!!!");
+  throw LauncherException("Method Launcher_cpp::getMaximumDurationInSecond is not available "
+                          "(libBatch was not present at compilation time)");
+}
+
 void
 Launcher_cpp::removeJob(int job_id)
 {
index 0cd4e6987c969bf3ab86e7f6f1d78d7c896063a6..c8fa51818a621f0b5acb038263eee25229d709e2 100644 (file)
@@ -85,6 +85,7 @@ public:
   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);
+  long         getMaximumDurationInSecond(int job_id);
   void         stopJob(int job_id);
   void         removeJob(int job_id);
   std::string  dumpJob(int job_id);
index f4bfede8b676f468465dacb0d687b6e5b6a32375..0f71c5de1d95c836db447b696b3424a33995d37f 100644 (file)
@@ -540,22 +540,32 @@ Launcher::Job::checkResourceRequiredParams(const resourceParams & resource_requi
 long
 Launcher::Job::convertMaximumDuration(const std::string & edt)
 {
-  long hh, mm, ret;
+  long dd(0), hh(0), mm(0);
 
   if( edt.size() == 0 )
     return -1;
 
-  std::string::size_type pos = edt.find(":");
-  std::string h = edt.substr(0,pos);
-  std::string m = edt.substr(pos+1,edt.size()-pos+1);
+  std::string remain( edt );
+
+  auto pos_day = edt.find('-');
+  if( pos_day != std::string::npos)
+  {
+    std::string d = edt.substr(0,pos_day);
+    if(pos_day == edt.size()-1)
+      return -1;
+    remain = edt.substr(pos_day+1);
+    std::istringstream issd(d);
+    issd >> dd;
+  }
+  std::string::size_type pos = remain.find(':');
+  std::string h = remain.substr(0,pos);
+  std::string m = remain.substr(pos+1,remain.size()-pos+1);
   std::istringstream issh(h);
   issh >> hh;
   std::istringstream issm(m);
   issm >> mm;
-  ret = hh*60 + mm;
-  ret = ret * 60;
-
-  return ret;
+  long ret = dd*60*24 + hh*60 + mm;
+  return 60*ret;
 }
 
 std::string
index 8b85f6edb7b12f805d8ffda8767c6bdddf3632cc..a7e30752c0ad58048f86bb77237dfa278c5afde9 100644 (file)
@@ -97,6 +97,7 @@ namespace Launcher
       const std::list<std::string> & get_in_files() const;
       const std::list<std::string> & get_out_files() const;
       std::string getMaximumDuration() const;
+      long getMaximumDurationInSecond() const { return this->_maximum_duration_in_second; }
       resourceParams getResourceRequiredParams() const;
       std::string getQueue() const;
       std::string getPartition() const;
index 04646de0b31facb847c8c6c2f1cd426e5774f389..92c3dfc46c6adf8becafc67b1f145e3f3e1d0e67 100644 (file)
@@ -306,6 +306,7 @@ public:
   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);
+  long         getMaximumDurationInSecond(int job_id);
   void         stopJob(int job_id);
   void         removeJob(int job_id);
   std::string  dumpJob(int job_id);
index 2acbaecac4ad693a51d17f38309c2a2a8453fd5b..6db53049b1f9c02d72bc93cedef23a55c1842bfb 100755 (executable)
@@ -674,6 +674,30 @@ f.close()
       self.verifyFile(os.path.join(mydir, "copie", "copie.txt"),
                       "to be copied")
       pass
+
+
+  def test_maximum_duration_management_0(self):
+    """
+    [EDF30356] : Check correct conversion of format DD-HH:MM into second before sending it to libbatch
+    """
+    def EndUserMaxDurationToSecond( endUserEntry ):
+        params = pylauncher.JobParameters_cpp()
+        params.maximum_duration = endUserEntry
+        launcher = pylauncher.Launcher_cpp()
+        params.job_type = "command_salome"
+        params.resource_required = pylauncher.resourceParams()
+        params.job_file = "test.py"
+        params.resource_required.nb_proc = 1
+        jobId = launcher.createJob( params )
+        return launcher.getMaximumDurationInSecond( jobId )
+    
+    self.assertEqual( EndUserMaxDurationToSecond( "15:10" ), 54600)
+    self.assertEqual( EndUserMaxDurationToSecond( "0-02:10" ), 7800)
+    self.assertEqual( EndUserMaxDurationToSecond( "0-00:59" ), 3540)
+    self.assertEqual( EndUserMaxDurationToSecond( "1-00:00" ), 86400)
+    self.assertEqual( EndUserMaxDurationToSecond( "2-00:00" ), 172800)
+    self.assertEqual( EndUserMaxDurationToSecond( "2-03:04" ), 183840)
+
     pass
   pass