*/
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
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
"(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)
{
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
##############################
# 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)
# 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
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)
# 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