Salome HOME
Adding a new batch system LoadLeveler (IBM tool) in Launcher
[modules/kernel.git] / src / Launcher / Launcher.cxx
index c169487a2d6c04b3f543f315afe0842938557550..e416a934c26b2adfe7bd9808619417faa99b2bbf 100644 (file)
@@ -62,12 +62,12 @@ Launcher_cpp::~Launcher_cpp()
 {
   LAUNCHER_MESSAGE("Launcher_cpp destructor");
 #ifdef WITH_LIBBATCH
-  std::map < std::string, Batch::BatchManager_eClient * >::const_iterator it1;
-  for(it1=_batchmap.begin();it1!=_batchmap.end();it1++)
-    delete it1->second;
   std::map<int, Launcher::Job *>::const_iterator it_job;
   for(it_job = _launcher_job_map.begin(); it_job != _launcher_job_map.end(); it_job++)
     delete it_job->second;
+  std::map < std::string, Batch::BatchManager_eClient * >::const_iterator it1;
+  for(it1=_batchmap.begin();it1!=_batchmap.end();it1++)
+    delete it1->second;
 #endif
 
   pthread_mutex_destroy(_job_cpt_mutex);
@@ -119,6 +119,7 @@ Launcher_cpp::createJob(Launcher::Job * new_job)
   }
 
   // Third step search batch manager for the resource into the map -> instanciate one if does not exist
+#ifdef WITH_LIBBATCH
   std::string resource_name = resource_definition.Name;
   std::map<std::string, Batch::BatchManager_eClient *>::const_iterator it = _batchmap.find(resource_name);
   if(it == _batchmap.end())
@@ -143,8 +144,13 @@ Launcher_cpp::createJob(Launcher::Job * new_job)
       delete new_job;
       throw LauncherException(ex.message);
     }
+    catch(const Batch::InvalidArgumentException &ex)
+    {
+      LAUNCHER_INFOS("Error during creation of the batch manager of the resource, mess: " << ex.message);
+      throw LauncherException(ex.message);
+    }
   }
-
+#endif
 
   // Final step - add job to the jobs map
   pthread_mutex_lock(_job_cpt_mutex);
@@ -263,6 +269,43 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
   LAUNCHER_MESSAGE("getJobResult ended");
 }
 
+//=============================================================================
+/*!
+ * Get Job dump state - the result directory could be changed
+ */ 
+//=============================================================================
+bool
+Launcher_cpp::getJobDumpState(int job_id, std::string directory)
+{
+  bool rtn;
+  LAUNCHER_MESSAGE("Get Job dump state");
+
+  // 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[resource_name]->importDumpStateFile(*(job->getBatchJob()), directory);
+    else
+      rtn = _batchmap[resource_name]->importDumpStateFile(*(job->getBatchJob()), job->getResultDirectory());
+  }
+  catch(const Batch::EmulationException &ex)
+  {
+    LAUNCHER_INFOS("getJobResult is maybe incomplete, exception: " << ex.message);
+    throw LauncherException(ex.message.c_str());
+  }
+  LAUNCHER_MESSAGE("getJobResult ended");
+  return rtn;
+}
+
 //=============================================================================
 /*!
  * Remove the job - into the Launcher and its batch manager
@@ -410,6 +453,9 @@ Launcher_cpp::FactoryBatchManager(ParserResourcesType& params)
     case ssh_batch:
       bmType = "eSSH";
       break;
+    case ll:
+      bmType = "eLL";
+      break;
     default:
       LAUNCHER_MESSAGE("Bad batch description of the resource: Batch = " << params.Batch);
       throw LauncherException("No batchmanager for that cluster - Bad batch description of the resource");
@@ -421,8 +467,8 @@ Launcher_cpp::FactoryBatchManager(ParserResourcesType& params)
     throw LauncherException("Cannot find batch manager factory");
   }
   LAUNCHER_MESSAGE("Instanciation of batch manager of type: " << bmType);
-  Batch::BatchManager_eClient * batch_client = (*fact)(hostname.c_str(), protocol, mpi.c_str(), nb_proc_per_node);
-  batch_client->setUsername(params.UserName);
+  Batch::BatchManager_eClient * batch_client = (*fact)(hostname.c_str(), params.UserName.c_str(),
+                                                       protocol, mpi.c_str(), nb_proc_per_node);
   return batch_client;
 }
 
@@ -464,6 +510,14 @@ Launcher_cpp::getJobResults(int job_id, std::string directory)
                           "(libBatch was not present at compilation time)");
 }
 
+bool
+Launcher_cpp::getJobDumpState(int job_id, std::string directory)
+{
+  LAUNCHER_INFOS("Launcher compiled without LIBBATCH - cannot get job dump state!!!");
+  throw LauncherException("Method Launcher_cpp::getJobDumpState is not available "
+                          "(libBatch was not present at compilation time)");
+}
+
 void
 Launcher_cpp::removeJob(int job_id)
 {
@@ -541,6 +595,7 @@ Launcher_cpp::checkFactoryForResource(const std::string & resource_name)
   }
 
   // Step 2: We can now add a Factory is the resource is correctly define
+#ifdef WITH_LIBBATCH
   std::map<std::string, Batch::BatchManager_eClient *>::const_iterator it = _batchmap.find(resource_name);
   if(it == _batchmap.end())
   {
@@ -562,7 +617,13 @@ Launcher_cpp::checkFactoryForResource(const std::string & resource_name)
       LAUNCHER_INFOS("Error during creation of the batch manager of the resource, mess: " << ex.message);
       throw LauncherException(ex.message);
     }
+    catch(const Batch::InvalidArgumentException &ex)
+    {
+      LAUNCHER_INFOS("Error during creation of the batch manager of the resource, mess: " << ex.message);
+      throw LauncherException(ex.message);
+    }
   }
+#endif
 }
 
 void 
@@ -575,6 +636,7 @@ Launcher_cpp::addJobDirectlyToMap(Launcher::Job * new_job, const std::string job
   new_job->setResourceDefinition(resource_definition);
 
   // Step 2: add the job to the batch manager
+#ifdef WITH_LIBBATCH
   try
   {
     Batch::JobId batch_manager_job_id = _batchmap[resource_name]->addJob(*(new_job->getBatchJob()), 
@@ -602,4 +664,5 @@ Launcher_cpp::addJobDirectlyToMap(Launcher::Job * new_job, const std::string job
     throw LauncherException("A job as already the same id - job is not created !");
   }
   LAUNCHER_MESSAGE("New job added");
+#endif
 }