Salome HOME
Merge branch 'omu/launcher_evol'
[modules/kernel.git] / src / Launcher / Launcher.cxx
index 5be41bf466f036ac3a41ac1e33c5b0ce4c7bea20..b6737b1774036b9321836312d5db5c52eb080856 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -133,7 +133,7 @@ Launcher_cpp::launchJob(int job_id)
     throw LauncherException("Bad state of the job: " + job->getState());
   }
 
-  // Third step search batch manager for the job into the map -> instanciate one if does not exist
+  // Third step search batch manager for the job into the map -> instantiate one if does not exist
 #ifdef WITH_LIBBATCH
   std::map<int, Batch::BatchManager *>::const_iterator it = _batchmap.find(job_id);
   if(it == _batchmap.end())
@@ -249,6 +249,37 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
   LAUNCHER_MESSAGE("getJobResult ended");
 }
 
+//=============================================================================
+/*!
+ * Clear the remote working directory
+ */
+//=============================================================================
+void
+Launcher_cpp::clearJobWorkingDir(int job_id)
+{
+  LAUNCHER_MESSAGE("Clear the remote working directory");
+
+  // 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;
+  try
+  {
+    _batchmap[job_id]->clearWorkingDir(*(job->getBatchJob()));
+  }
+  catch(const Batch::GenericException &ex)
+  {
+    LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
+    throw LauncherException(ex.message.c_str());
+  }
+  LAUNCHER_MESSAGE("getJobResult ended");
+}
+
 //=============================================================================
 /*!
  * Get Job dump state - the result directory could be changed
@@ -286,6 +317,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
@@ -387,7 +457,7 @@ Launcher_cpp::createJobWithFile(const std::string xmlExecuteFile,
 
 //=============================================================================
 /*!
- *  Factory to instanciate the good batch manager for choosen cluster.
+ *  Factory to instantiate the good batch manager for chosen cluster.
  */ 
 //=============================================================================
 Batch::BatchManager *
@@ -485,7 +555,7 @@ Launcher_cpp::FactoryBatchManager(ParserResourcesType& params)
     LAUNCHER_MESSAGE("Cannot find batch manager factory for " << bmType << ". Check your version of libBatch.");
     throw LauncherException("Cannot find batch manager factory");
   }
-  LAUNCHER_MESSAGE("Instanciation of batch manager of type: " << bmType);
+  LAUNCHER_MESSAGE("Instantiation of batch manager of type: " << bmType);
   Batch::BatchManager * batch_client = (*fact)(hostname.c_str(), params.UserName.c_str(),
                                                protocol, mpi.c_str());
   return batch_client;
@@ -537,6 +607,14 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
                           "(libBatch was not present at compilation time)");
 }
 
+void
+Launcher_cpp::clearJobWorkingDir(int job_id)
+{
+  LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot clear directory!!!");
+  throw LauncherException("Method Launcher_cpp::clearJobWorkingDir is not available "
+                          "(libBatch was not present at compilation time)");
+}
+
 bool
 Launcher_cpp::getJobDumpState(int job_id, std::string directory)
 {
@@ -545,6 +623,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)
 {
@@ -618,7 +704,7 @@ Launcher_cpp::createBatchManagerForJob(Launcher::Job * job)
 {
   int job_id = job->getNumber();
 
-  // Select a ressource for the job
+  // Select a resource for the job
   std::vector<std::string> ResourceList;
   resourceParams params = job->getResourceRequiredParams();
   // Consider only resources that can launch batch jobs
@@ -741,7 +827,7 @@ Launcher_cpp::loadJobs(const char* jobs_file)
     {
       if (job_state == "CREATED")
       {
-        // In this case, we ignore run_part informations
+        // In this case, we ignore run_part information
         createJob(new_job);
         new_jobs_id_list.push_back(new_job->getNumber());
       }
@@ -767,7 +853,7 @@ Launcher_cpp::loadJobs(const char* jobs_file)
                job_state == "FAILED"   ||
                job_state == "ERROR")
       {
-        // Step 2: We add run_part informations
+        // Step 2: We add run_part information
         addJobDirectlyToMap(new_job);
         new_jobs_id_list.push_back(new_job->getNumber());
       }