From: Ovidiu Mircescu Date: Tue, 16 Dec 2014 15:33:15 +0000 (+0100) Subject: Add the possibility to retrieve one single file with SalomeLauncher. X-Git-Tag: V7_6_0a1~29^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1ab778335827ed7f0621554b6c6667637101dc6a;p=modules%2Fkernel.git Add the possibility to retrieve one single file with SalomeLauncher. EDF pleiade issue n° 9110. --- diff --git a/idl/SALOME_Launcher.idl b/idl/SALOME_Launcher.idl index ca27ffa57..a1427ba61 100644 --- a/idl/SALOME_Launcher.idl +++ b/idl/SALOME_Launcher.idl @@ -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 diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 5be41bf46..afeade7bf 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -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::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) { diff --git a/src/Launcher/Launcher.hxx b/src/Launcher/Launcher.hxx index 0372d22c2..2ec6c3c0d 100644 --- a/src/Launcher/Launcher.hxx +++ b/src/Launcher/Launcher.hxx @@ -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); diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index 3c16fdf7a..667ede1ca 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -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) { diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index ffb339e05..40b78c57b 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -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); diff --git a/src/Launcher/Test/test_launcher.py b/src/Launcher/Test/test_launcher.py index 9ae3ca55c..86d5d61aa 100755 --- a/src/Launcher/Test/test_launcher.py +++ b/src/Launcher/Test/test_launcher.py @@ -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