From 9ba68bdbfb87edcd5b9b9e721cb5b89e227de81e Mon Sep 17 00:00:00 2001 From: secher Date: Tue, 24 Jul 2007 13:04:59 +0000 Subject: [PATCH] add batch manager factory --- .../SALOME_ResourcesCatalog_Handler.cxx | 32 ++++++++ .../SALOME_ResourcesCatalog_Handler.hxx | 1 + .../SALOME_ResourcesCatalog_Parser.cxx | 2 + .../SALOME_ResourcesCatalog_Parser.hxx | 3 + .../SALOME_ResourcesManager.cxx | 74 +++++++++++-------- .../SALOME_ResourcesManager.hxx | 5 +- 6 files changed, 83 insertions(+), 34 deletions(-) diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index 79fd376eb..1fa7967bc 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -54,6 +54,7 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): test_alias = "alias"; test_protocol = "protocol"; test_mode = "mode"; + test_batch = "batch"; test_user_name = "userName"; test_appli_path = "appliPath"; test_modules = "modules"; @@ -178,6 +179,18 @@ startElement( const QString&, } } + if ((qName.compare(QString(test_batch)) == 0)) + { + if( content.compare("pbs") == 0 ) + _resource.Batch = pbs; + else if( content.compare("lsf") == 0 ) + _resource.Batch = lsf; + else if( content.compare("slurm") == 0 ) + _resource.Batch = slurm; + else + _resource.Batch = none; + } + if ((qName.compare(QString(test_user_name)) == 0)) _resource.UserName = content; @@ -365,6 +378,25 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc) eltRoot.setAttribute((char *)test_mode, "interactive"); } + switch ((*iter).second.Batch) + { + + case pbs: + eltRoot.setAttribute((char *)test_batch, "pbs"); + break; + + case lsf: + eltRoot.setAttribute((char *)test_batch, "lsf"); + break; + + case slurm: + eltRoot.setAttribute((char *)test_batch, "slurm"); + break; + + default: + eltRoot.setAttribute((char *)test_batch, ""); + } + eltRoot.setAttribute((char *)test_user_name, (*iter).second.UserName.c_str()); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx index 49e42c3f8..9bd4e2a5c 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx @@ -82,6 +82,7 @@ class SALOME_ResourcesCatalog_Handler : public QXmlDefaultHandler const char *test_alias; const char *test_protocol; const char *test_mode; + const char *test_batch; const char *test_user_name; const char *test_appli_path; const char *test_modules; diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx index 4d4727f62..57154b3f0 100644 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -124,6 +124,7 @@ void ParserResourcesType::Print() const "MemInMB : " << DataForSort._memInMB << endl << "Protocol : " << Protocol << endl << "Mode : " << Mode << endl << + "Batch : " << Batch << endl << "UserName : " << UserName << endl << "AppliPath : " << AppliPath << endl << "OS : " << OS << endl << @@ -146,6 +147,7 @@ void ParserResourcesType::Clear() Alias = ""; Protocol = rsh; Mode = interactive; + Batch = none; UserName = ""; AppliPath = ""; ModulesList.clear(); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx index 025d1e628..5c49924eb 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -38,6 +38,8 @@ enum AccessProtocolType {rsh, ssh}; enum AccessModeType {interactive, batch}; +enum BatchType {none, pbs, lsf, slurm}; + class ResourceDataToSort { @@ -72,6 +74,7 @@ struct ParserResourcesType std::string Alias; AccessProtocolType Protocol; AccessModeType Mode; + BatchType Batch; std::string UserName; std::string AppliPath; std::vector ModulesList; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 38d1a12dd..c93b8847d 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -102,7 +102,7 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb) SALOME_ResourcesManager::~SALOME_ResourcesManager() { delete _NS; - std::map < string, const BatchLight::BatchManager * >::const_iterator it; + std::map < string, BatchLight::BatchManager * >::const_iterator it; for(it=_batchmap.begin();it!=_batchmap.end();it++) delete it->second; } @@ -526,7 +526,7 @@ CORBA::Long SALOME_ResourcesManager::submitSalomeJob( const char * fileToExecute const Engines::FilesList& filesToExport , const Engines::FilesList& filesToImport , const CORBA::Long NumberOfProcessors , - const Engines::MachineParameters& params) + const Engines::MachineParameters& params) throw(SALOME_Exception) { BEGIN_OF("SALOME_ResourcesManager::submitSalomeJob"); CORBA::Long jobId; @@ -538,32 +538,48 @@ CORBA::Long SALOME_ResourcesManager::submitSalomeJob( const char * fileToExecute string clustername = resInfo.Alias; // search batch manager for that cluster in map or instanciate one - std::map < string, const BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()){ - // define structure for batch manager - BatchLight::batchParams p; - p.hostname = clustername; - if( resInfo.Protocol == rsh ) - p.protocol = "rsh"; - else if( resInfo.Protocol == ssh ) - p.protocol = "ssh"; - else - throw SALOME_Exception("Unknown protocol"); - p.username = resInfo.UserName; - p.applipath = resInfo.AppliPath; - p.modulesList = resInfo.ModulesList; - _batchmap[clustername] = new BatchLight::BatchManager_SLURM(p); - } - BatchLight::BatchManager_SLURM* bms = (BatchLight::BatchManager_SLURM*)_batchmap[clustername]; + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + if(it == _batchmap.end()) + _batchmap[clustername] = FactoryBatchManager( resInfo ); // submit job on cluster BatchLight::Job* job = new BatchLight::Job( fileToExecute, filesToExport, filesToImport, NumberOfProcessors ); - jobId = bms->submitJob(job); + jobId = _batchmap[clustername]->submitJob(job); return(jobId); END_OF("SALOME_ResourcesManager::submitSalomeJob"); } +//============================================================================= +/*! + * Factory to instanciate the good batch manager for choosen cluster. + */ +//============================================================================= + +BatchLight::BatchManager *SALOME_ResourcesManager::FactoryBatchManager( const ParserResourcesType& resInfo ) throw(SALOME_Exception) +{ + // Fill structure for batch manager + BatchLight::batchParams p; + p.hostname = resInfo.Alias; + if( resInfo.Protocol == rsh ) + p.protocol = "rsh"; + else if( resInfo.Protocol == ssh ) + p.protocol = "ssh"; + else + throw SALOME_Exception("Unknown protocol"); + p.username = resInfo.UserName; + p.applipath = resInfo.AppliPath; + p.modulesList = resInfo.ModulesList; + + switch( resInfo.Batch ){ + case slurm: + return new BatchLight::BatchManager_SLURM(p); + default: + MESSAGE("BATCH = " << resInfo.Batch); + throw SALOME_Exception("no batchmanager for that cluster"); + } +} + //============================================================================= /*! CORBA Method: * query a batch job on a cluster and returns the status of the job @@ -582,13 +598,11 @@ string SALOME_ResourcesManager::querySalomeJob( const CORBA::Long jobId, const E string clustername = resInfo.Alias; // search batch manager for that cluster in map - std::map < string, const BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); if(it == _batchmap.end()) throw SALOME_Exception("no batchmanager for that cluster"); - BatchLight::BatchManager_SLURM* bms = (BatchLight::BatchManager_SLURM*)_batchmap[clustername]; - - status = bms->queryJob(jobId); + status = _batchmap[clustername]->queryJob(jobId); return(status); } @@ -609,13 +623,11 @@ void SALOME_ResourcesManager::deleteSalomeJob( const CORBA::Long jobId, const En string clustername = resInfo.Alias; // search batch manager for that cluster in map - std::map < string, const BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); if(it == _batchmap.end()) throw SALOME_Exception("no batchmanager for that cluster"); - BatchLight::BatchManager_SLURM* bms = (BatchLight::BatchManager_SLURM*)_batchmap[clustername]; - - bms->deleteJob(jobId); + _batchmap[clustername]->deleteJob(jobId); } //============================================================================= @@ -636,13 +648,11 @@ void SALOME_ResourcesManager::getResultSalomeJob( const char *directory, string clustername = resInfo.Alias; // search batch manager for that cluster in map - std::map < string, const BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); if(it == _batchmap.end()) throw SALOME_Exception("no batchmanager for that cluster"); - BatchLight::BatchManager_SLURM* bms = (BatchLight::BatchManager_SLURM*)_batchmap[clustername]; - - bms->importOutputFiles( directory, jobId ); + _batchmap[clustername]->importOutputFiles( directory, jobId ); } //============================================================================= diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index f6a622fa3..ec751ec75 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -79,7 +79,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager const Engines::FilesList& filesToExport , const Engines::FilesList& filesToImport , const CORBA::Long NumberOfProcessors , - const Engines::MachineParameters& params); + const Engines::MachineParameters& params) throw(SALOME_Exception); std::string querySalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params) throw(SALOME_Exception); void deleteSalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params) throw(SALOME_Exception); @@ -116,7 +116,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager protected: SALOME_NamingService *_NS; - std::map _batchmap; + std::map _batchmap; std::string BuildTempFileToLaunchRemoteContainer (const std::string& machine, @@ -136,6 +136,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager std::string BuildTemporaryFileName() const; + BatchLight::BatchManager *FactoryBatchManager( const ParserResourcesType& resInfo ) throw(SALOME_Exception); //! will contain the path to the ressources catalog QString _path_resources; -- 2.39.2