From: Anthony Geay Date: Fri, 14 Jun 2024 11:56:16 +0000 (+0200) Subject: [EDF30356] : Extend management of maximum_time attribute format from pylauncher to... X-Git-Tag: emc2p_2.1.0-rc1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=caf21d9d4b1d179eb1cefde8d43ea29bf0e2baea;p=modules%2Fkernel.git [EDF30356] : Extend management of maximum_time attribute format from pylauncher to libbatch --- diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 2002a187a..4a72dc716 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -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) { diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index 0cd4e6987..c8fa51818 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -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); diff --git a/src/Launcher/Launcher_Job.cxx b/src/Launcher/Launcher_Job.cxx index f4bfede8b..0f71c5de1 100644 --- a/src/Launcher/Launcher_Job.cxx +++ b/src/Launcher/Launcher_Job.cxx @@ -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 diff --git a/src/Launcher/Launcher_Job.hxx b/src/Launcher/Launcher_Job.hxx index 8b85f6edb..a7e30752c 100644 --- a/src/Launcher/Launcher_Job.hxx +++ b/src/Launcher/Launcher_Job.hxx @@ -97,6 +97,7 @@ namespace Launcher const std::list & get_in_files() const; const std::list & 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; diff --git a/src/Launcher_SWIG/Launcher.i b/src/Launcher_SWIG/Launcher.i index 04646de0b..92c3dfc46 100644 --- a/src/Launcher_SWIG/Launcher.i +++ b/src/Launcher_SWIG/Launcher.i @@ -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); diff --git a/src/Launcher_SWIG/Test/test_swig_launcher.py b/src/Launcher_SWIG/Test/test_swig_launcher.py index 2acbaecac..6db53049b 100755 --- a/src/Launcher_SWIG/Test/test_swig_launcher.py +++ b/src/Launcher_SWIG/Test/test_swig_launcher.py @@ -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