#ifdef WITH_LIBBATCH
#include <Batch/Batch_Date.hxx>
-#include <Batch/Batch_FactBatchManager_eCCC.hxx>
-#include <Batch/Batch_FactBatchManager_eLSF.hxx>
-#include <Batch/Batch_FactBatchManager_ePBS.hxx>
+#include <Batch/Batch_BatchManagerCatalog.hxx>
+#include <Batch/Batch_FactBatchManager_eClient.hxx>
#include <Batch/Batch_BatchManager_eClient.hxx>
-#include <Batch/Batch_FactBatchManager_eSGE.hxx>
-#include <Batch/Batch_FactBatchManager_eSSH.hxx>
#endif
#include "Basics_Utils.hxx"
{
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);
}
// 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())
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);
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
mpi = "nompi";
}
- std::string message = "Instanciation of batch manager of type: ";
+ const char * bmType;
switch( params.Batch )
{
case pbs:
- message += "ePBS";
- fact = new Batch::FactBatchManager_ePBS;
+ bmType = "ePBS";
break;
case lsf:
- message += "eLSF";
- fact = new Batch::FactBatchManager_eLSF;
+ bmType = "eLSF";
break;
case sge:
- message += "eSGE";
- fact = new Batch::FactBatchManager_eSGE;
+ bmType = "eSGE";
break;
case ccc:
- message += "eCCC";
- fact = new Batch::FactBatchManager_eCCC;
+ bmType = "eCCC";
break;
case ssh_batch:
- message += "eSSH";
- fact = new Batch::FactBatchManager_eSSH;
+ 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");
}
- LAUNCHER_MESSAGE(message);
- return (*fact)(hostname.c_str(), protocol, mpi.c_str(), nb_proc_per_node);
+ Batch::BatchManagerCatalog & cata = Batch::BatchManagerCatalog::getInstance();
+ fact = dynamic_cast<Batch::FactBatchManager_eClient*>(cata(bmType));
+ if (fact == NULL) {
+ 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);
+ Batch::BatchManager_eClient * batch_client = (*fact)(hostname.c_str(), params.UserName.c_str(),
+ protocol, mpi.c_str(), nb_proc_per_node);
+ return batch_client;
}
//----------------------------------------------------------
"(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)
{
return job_params;
}
+std::map<int, Launcher::Job *>
+Launcher_cpp::getJobs()
+{
+ return _launcher_job_map;
+}
+
+void
+Launcher_cpp::checkFactoryForResource(const std::string & resource_name)
+{
+ // Step 1: Check if resource exist in the resource manager
+ ParserResourcesType resource_definition;
+ try
+ {
+ resource_definition = _ResManager->GetResourcesDescr(resource_name);
+ }
+ catch(const ResourcesException &ex)
+ {
+ LAUNCHER_INFOS(ex.msg);
+ throw LauncherException(ex.msg);
+ }
+
+ // 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())
+ {
+ try
+ {
+ // Warning cannot write on one line like this, because map object is constructed before
+ // the method is called...
+ //_batchmap.[resource_name] = FactoryBatchManager(resource_definition);
+ Batch::BatchManager_eClient * batch_client = FactoryBatchManager(resource_definition);
+ _batchmap[resource_name] = batch_client;
+ }
+ catch(const LauncherException &ex)
+ {
+ LAUNCHER_INFOS("Error during creation of the batch manager of the resource, mess: " << ex.msg);
+ throw ex;
+ }
+ catch(const Batch::EmulationException &ex)
+ {
+ 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
+Launcher_cpp::addJobDirectlyToMap(Launcher::Job * new_job, const std::string job_reference)
+{
+ // Step 1: check if resource is already in the map
+ std::string resource_name = new_job->getResourceDefinition().Name;
+ checkFactoryForResource(resource_name);
+ ParserResourcesType resource_definition = _ResManager->GetResourcesDescr(resource_name);
+ 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()),
+ job_reference);
+ new_job->setBatchManagerJobId(batch_manager_job_id);
+ }
+ catch(const Batch::EmulationException &ex)
+ {
+ LAUNCHER_INFOS("Job is not launched, exception in submitJob: " << ex.message);
+ throw LauncherException(ex.message.c_str());
+ }
+
+ // Step 3: add job to launcher map
+ pthread_mutex_lock(_job_cpt_mutex);
+ new_job->setNumber(_job_cpt);
+ _job_cpt++;
+ pthread_mutex_unlock(_job_cpt_mutex);
+ std::map<int, Launcher::Job *>::const_iterator it_job = _launcher_job_map.find(new_job->getNumber());
+ if (it_job == _launcher_job_map.end())
+ _launcher_job_map[new_job->getNumber()] = new_job;
+ else
+ {
+ LAUNCHER_INFOS("A job as already the same id: " << new_job->getNumber());
+ delete new_job;
+ throw LauncherException("A job as already the same id - job is not created !");
+ }
+ LAUNCHER_MESSAGE("New job added");
+#endif
+}