From: secher Date: Mon, 1 Oct 2007 13:05:52 +0000 (+0000) Subject: add a SalomeLauncher. Modify ContainerManager idl to create three interfaces in it... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_V326p4_resman;p=modules%2Fkernel.git add a SalomeLauncher. Modify ContainerManager idl to create three interfaces in it: one for launcher, one for containermanager and one for resources manager. --- diff --git a/bin/runSalome.py b/bin/runSalome.py index 886ada9f8..08f58ba23 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -539,11 +539,11 @@ class SessionServer(Server): # --- -class ContainerManagerServer(Server): +class LauncherServer(Server): def __init__(self,args): self.args=args self.initArgs() - self.SCMD1=['SALOME_ContainerManagerServer'] + self.SCMD1=['SALOME_LauncherServer'] self.SCMD2=[] if args["gui"] : if 'registry' in self.args['embedded']: @@ -693,10 +693,10 @@ def startSalome(args, modules_list, modules_root_dir): clt.waitNSPID("/myStudyManager",myServer.PID) # - # Lancement ContainerManagerServer + # Lancement LauncherServer # - myCmServer = ContainerManagerServer(args) + myCmServer = LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() diff --git a/bin/shutdownSalome.py b/bin/shutdownSalome.py index 78e1001b4..0c96154bb 100755 --- a/bin/shutdownSalome.py +++ b/bin/shutdownSalome.py @@ -10,9 +10,9 @@ obj = clt.Resolve('Kernel/Session') if obj != None: ses = obj._narrow(SALOME.Session) ses.StopSession() -obj = clt.Resolve('ContainerManager') +obj = clt.Resolve('SalomeLauncher') if obj != None: - cm = obj._narrow(Engines.ContainerManager) + cm = obj._narrow(Engines.SalomeLauncher) cm.Shutdown() obj = clt.Resolve('Kernel/ModulCatalog') if obj != None: diff --git a/configure.ac b/configure.ac index 083b59e83..ae730d282 100644 --- a/configure.ac +++ b/configure.ac @@ -521,6 +521,7 @@ AC_OUTPUT([ \ ./src/GenericObj/Makefile \ ./src/HDFPersist/Makefile \ ./src/KERNEL_PY/Makefile \ + ./src/Launcher/Makefile \ ./src/LifeCycleCORBA/Makefile \ ./src/LifeCycleCORBA/Test/Makefile \ ./src/LifeCycleCORBA_SWIG/Makefile \ diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 660e7122b..0a4be4f01 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -27,27 +27,35 @@ module Engines { /*! - Type to describe properties of wanted resource. + Type to transmit list of machines. +*/ + typedef sequence MachineList; + typedef sequence CompoList; + typedef sequence FilesList; + typedef sequence ModulesList; + +/*! + Type to describe properties of resource. */ struct MachineParameters { string container_name; string hostname; + string alias; + string protocol; + string username; + string applipath; + ModulesList modList; string OS; long mem_mb; long cpu_clock; long nb_proc_per_node; long nb_node; boolean isMPI; + string mpiImpl; + string batch; }; -/*! - Type to transmit list of machines. -*/ - typedef sequence MachineList; - typedef sequence CompoList; - typedef sequence FilesList; - /*! exception thrown if a computer is not found in the catalog */ @@ -56,6 +64,25 @@ struct MachineParameters enum policy {P_FIRST,P_CYCL,P_BEST}; typedef policy ResPolicy; +/*! \brief Interface of the %salomelauncher + This interface is used for interaction with the unique instance + of SalomeLauncher +*/ + interface SalomeLauncher + { + long submitSalomeJob( in string fileToExecute, + in FilesList filesToExport, + in FilesList filesToImport, + in long NumberOfProcessors, + in MachineParameters params ) raises (SALOME::SALOME_Exception); + string querySalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + void deleteSalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + void getResultSalomeJob( in string directory, in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + + void Shutdown(); + + } ; + /*! \brief Interface of the %containerManager This interface is used for interaction with the unique instance of ContainerManager @@ -73,15 +100,15 @@ struct MachineParameters in ResPolicy policy, in CompoList componentList ); - long submitSalomeJob( in string fileToExecute, - in FilesList filesToExport, - in FilesList filesToImport, - in long NumberOfProcessors, - in MachineParameters params ) raises (SALOME::SALOME_Exception); - string querySalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void deleteSalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void getResultSalomeJob( in string directory, in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - + void ShutdownContainers(); + } ; + +/*! \brief Interface of the %resourcesManager + This interface is used for interaction with the unique instance + of ResourcesManager +*/ + interface ResourcesManager + { string FindFirst(in MachineList possibleComputers); MachineList GetFittingResources( in MachineParameters params, @@ -90,9 +117,6 @@ struct MachineParameters MachineParameters GetMachineParameters( in string hostname ); - void Shutdown(); - - void ShutdownContainers(); } ; }; diff --git a/src/Batch/BatchLight_BatchManager_PBS.cxx b/src/Batch/BatchLight_BatchManager_PBS.cxx index 9a59c4f67..d2856d828 100644 --- a/src/Batch/BatchLight_BatchManager_PBS.cxx +++ b/src/Batch/BatchLight_BatchManager_PBS.cxx @@ -167,16 +167,10 @@ namespace BatchLight { { BEGIN_OF("BatchManager_PBS::buildSalomeCouplingScript"); int status; - int lenf = strlen( fileToExecute ) ; - int i = lenf-1 ; - while ( i >= 0 && fileToExecute[i] != '/' ) { - i -= 1 ; - } - char * FileNameToExecute = new char[lenf-4-i] ; - strncpy(FileNameToExecute , &fileToExecute[i+1] , lenf-4-i) ; - _fileNameToExecute = string( FileNameToExecute ) ; - delete FileNameToExecute ; - SCRUTE(_fileNameToExecute) ; + + string::size_type p1 = string(fileToExecute).find_last_of("/"); + string::size_type p2 = string(fileToExecute).find_last_of("."); + _fileNameToExecute = string(fileToExecute).substr(p1+1,p2-p1-1); _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; @@ -191,7 +185,7 @@ namespace BatchLight { tempOutputFile << _mpiImpl->rank() ; tempOutputFile << " = 0; then" << endl ; tempOutputFile << " ./runAppli --terminal --batch --modules=" ; - for ( i = 0 ; i < _params.modulesList.size() ; i++ ) { + for ( int i = 0 ; i < _params.modulesList.size() ; i++ ) { tempOutputFile << _params.modulesList[i] ; if ( i != _params.modulesList.size()-1 ) tempOutputFile << "," ; @@ -238,6 +232,7 @@ namespace BatchLight { command += "/runSalome_" ; command += _fileNameToExecute ; command += "_Batch.sh" ; + SCRUTE(_fileNameToExecute) ; SCRUTE(command.c_str()); status = system(command.c_str()); if(status) diff --git a/src/Batch/BatchLight_BatchManager_SLURM.cxx b/src/Batch/BatchLight_BatchManager_SLURM.cxx index 23c62f92e..67c1ed6fb 100644 --- a/src/Batch/BatchLight_BatchManager_SLURM.cxx +++ b/src/Batch/BatchLight_BatchManager_SLURM.cxx @@ -147,16 +147,10 @@ namespace BatchLight { { BEGIN_OF("BatchManager_SLURM::buildSalomeCouplingScript"); int status; - int lenf = strlen( fileToExecute ) ; - int i = lenf-1 ; - while ( i >= 0 && fileToExecute[i] != '/' ) { - i -= 1 ; - } - char * FileNameToExecute = new char[lenf-4-i] ; - strncpy(FileNameToExecute , &fileToExecute[i+1] , lenf-4-i) ; - _fileNameToExecute = string( FileNameToExecute ) ; - delete FileNameToExecute ; - SCRUTE(_fileNameToExecute) ; + + string::size_type p1 = string(fileToExecute).find_last_of("/"); + string::size_type p2 = string(fileToExecute).find_last_of("."); + _fileNameToExecute = string(fileToExecute).substr(p1+1,p2-p1-1); _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; @@ -169,7 +163,7 @@ namespace BatchLight { tempOutputFile << ":$PYTHONPATH" << endl ; tempOutputFile << "if test $SLURM_PROCID = 0; then" << endl ; tempOutputFile << " ./runAppli --terminal --batch --modules=" ; - for ( i = 0 ; i < _params.modulesList.size() ; i++ ) { + for ( int i = 0 ; i < _params.modulesList.size() ; i++ ) { tempOutputFile << _params.modulesList[i] ; if ( i != _params.modulesList.size()-1 ) tempOutputFile << "," ; diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index aa958bdc1..a7000378f 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -123,7 +123,7 @@ libSalomeContainer_la_LIBADD =\ # Executables targets # =============================================================== # -bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer +bin_PROGRAMS = SALOME_Container SALOME_Container_SOURCES =\ SALOME_Container.cxx \ SALOME_Container_SignalsHandler.cxx @@ -137,18 +137,3 @@ SALOME_Container_LDADD =\ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la \ ../Batch/libSalomeBatch.la - - -SALOME_ContainerManagerServer_SOURCES =\ - SALOME_ContainerManagerServer.cxx - -SALOME_ContainerManagerServer_CPPFLAGS=\ - $(COMMON_CPPFLAGS) - -SALOME_ContainerManagerServer_LDADD =\ - libSalomeContainer.la \ - $(COMMON_LIBS) \ - ../Basics/libSALOMEBasics.la \ - ../Batch/libSalomeBatch.la - - diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index c4d49712a..0c097ab97 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -48,28 +48,25 @@ const char *SALOME_ContainerManager::_ContainerManagerNameInNS = */ //============================================================================= -SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb) +SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns) { MESSAGE("constructor"); - _NS = new SALOME_NamingService(orb); - _ResManager = new SALOME_ResourcesManager(orb); + _NS = ns; + _ResManager = rm; _id=0; - PortableServer::POA_var root_poa = PortableServer::POA::_the_root_poa(); - PortableServer::POAManager_var pman = root_poa->the_POAManager(); - PortableServer::POA_var my_poa; + PortableServer::POAManager_var pman = poa->the_POAManager(); _orb = CORBA::ORB::_duplicate(orb) ; CORBA::PolicyList policies; policies.length(1); PortableServer::ThreadPolicy_var threadPol = - root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); + poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol); - my_poa = - root_poa->create_POA("SThreadPOA",pman,policies); + _poa = poa->create_POA("SThreadPOA",pman,policies); threadPol->destroy(); - PortableServer::ObjectId_var id = my_poa->activate_object(this); - CORBA::Object_var obj = my_poa->id_to_reference(id); + PortableServer::ObjectId_var id = _poa->activate_object(this); + CORBA::Object_var obj = _poa->id_to_reference(id); Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj); @@ -86,8 +83,6 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb) SALOME_ContainerManager::~SALOME_ContainerManager() { MESSAGE("destructor"); - delete _NS; - delete _ResManager; } //============================================================================= @@ -101,11 +96,9 @@ void SALOME_ContainerManager::Shutdown() MESSAGE("Shutdown"); ShutdownContainers(); _NS->Destroy_Name(_ContainerManagerNameInNS); - PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this); - _default_POA()->deactivate_object(oid); + PortableServer::ObjectId_var oid = _poa->servant_to_id(this); + _poa->deactivate_object(oid); _remove_ref(); - if(!CORBA::is_nil(_orb)) - _orb->shutdown(0); } //============================================================================= @@ -291,7 +284,7 @@ StartContainer(const Engines::MachineParameters& params, Engines::ResPolicy policy, const Engines::CompoList& componentList) { - Engines::MachineList_var possibleComputers = GetFittingResources(params,componentList); + Engines::MachineList_var possibleComputers = _ResManager->GetFittingResources(params,componentList); return StartContainer(params,possibleComputers,policy); } @@ -318,141 +311,6 @@ GiveContainer(const Engines::MachineParameters& params, return StartContainer(params,policy,componentList); } - -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster - * \param filesToExport : to export on the batch cluster - * \param NumberOfProcessors : Number of processors needed on the batch cluster - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -CORBA::Long SALOME_ContainerManager::submitSalomeJob( const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const CORBA::Long NumberOfProcessors , - const Engines::MachineParameters& params) -{ - CORBA::Long jobId; - try{ - jobId = _ResManager->submitSalomeJob(fileToExecute, filesToExport, filesToImport, NumberOfProcessors, params); - } - catch(const SALOME_Exception &ex){ - MESSAGE(ex.what()); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR); - } - return jobId; -} - -//============================================================================= -/*! CORBA Method: - * Query a batch job on a cluster and returns the status of job - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -char* SALOME_ContainerManager::querySalomeJob( const CORBA::Long jobId, - const Engines::MachineParameters& params) -{ - string status; - try{ - status = _ResManager->querySalomeJob( jobId, params); - } - catch(const SALOME_Exception &ex){ - INFOS("Caught exception."); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); - } - return CORBA::string_dup(status.c_str()); -} - -//============================================================================= -/*! CORBA Method: - * Delete a batch job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void SALOME_ContainerManager::deleteSalomeJob( const CORBA::Long jobId, - const Engines::MachineParameters& params) -{ - try{ - _ResManager->deleteSalomeJob( jobId, params); - } - catch(const SALOME_Exception &ex){ - INFOS("Caught exception."); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); - } -} - -//============================================================================= -/*! CORBA Method: - * Get result files of job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void SALOME_ContainerManager::getResultSalomeJob( const char *directory, - const CORBA::Long jobId, - const Engines::MachineParameters& params) -{ - try{ - _ResManager->getResultSalomeJob( directory, jobId, params); - } - catch(const SALOME_Exception &ex){ - INFOS("Caught exception."); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); - } -} - -//============================================================================= -/*! - * - */ -//============================================================================= - -Engines::MachineList * -SALOME_ContainerManager:: -GetFittingResources(const Engines::MachineParameters& params, - const Engines::CompoList& componentList) -{ - MESSAGE("SALOME_ContainerManager::GetFittingResources"); - Engines::MachineList *ret=new Engines::MachineList; - vector vec; - try - { - vec = _ResManager->GetFittingResources(params,componentList); - } - catch(const SALOME_Exception &ex) - { - INFOS("Caught exception."); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); - //return ret; - } - - // MESSAGE("Machine list length "<length(vec.size()); - for(unsigned int i=0;iFindFirst(possibleComputers); - return CORBA::string_dup(theMachine.c_str()); -} - //============================================================================= /*! * @@ -513,11 +371,6 @@ long SALOME_ContainerManager::GetIdForContainer(void) return _id; } -Engines::MachineParameters* SALOME_ContainerManager::GetMachineParameters(const char *hostname) -{ - return _ResManager->GetMachineParameters(hostname); -} - void SALOME_ContainerManager::fillBatchLaunchedContainers() { _batchLaunchedContainers.clear(); diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index bb0ca1fd5..19d6f5c47 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -50,7 +50,7 @@ class CONTAINER_EXPORT SALOME_ContainerManager: { public: - SALOME_ContainerManager(CORBA::ORB_ptr orb); + SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns); ~SALOME_ContainerManager(); Engines::Container_ptr @@ -72,24 +72,6 @@ public: Engines::ResPolicy policy, const Engines::CompoList& componentList); - CORBA::Long submitSalomeJob(const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const CORBA::Long NumberOfProcessors , - const Engines::MachineParameters& params); - - char* querySalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); - void deleteSalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); - void getResultSalomeJob( const char * directory, const CORBA::Long jobId, const Engines::MachineParameters& params ); - - Engines::MachineList * - GetFittingResources(const Engines::MachineParameters& params, - const Engines::CompoList& componentList); - - char* FindFirst(const Engines::MachineList& possibleComputers); - - Engines::MachineParameters* GetMachineParameters(const char *hostname); - void Shutdown(); void ShutdownContainers(); @@ -109,6 +91,7 @@ protected: long GetIdForContainer(void); long _id; CORBA::ORB_var _orb; + PortableServer::POA_var _poa; SALOME_ResourcesManager *_ResManager; SALOME_NamingService *_NS; diff --git a/src/Container/SALOME_ContainerManagerServer.cxx b/src/Container/SALOME_ContainerManagerServer.cxx deleted file mode 100644 index d4a4399aa..000000000 --- a/src/Container/SALOME_ContainerManagerServer.cxx +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// -#include "SALOME_ContainerManager.hxx" -#include "utilities.h" - -int main(int argc, char* argv[]) -{ - PortableServer::POA_var root_poa; - PortableServer::POAManager_var pman; - CORBA::Object_var obj; - - CORBA::ORB_ptr orb = CORBA::ORB_init( argc , argv ) ; - // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); - INFOS_COMPILATION; - BEGIN_OF(argv[0]); - try{ - obj = orb->resolve_initial_references("RootPOA"); - if(!CORBA::is_nil(obj)) - root_poa = PortableServer::POA::_narrow(obj); - if(!CORBA::is_nil(root_poa)) - pman = root_poa->the_POAManager(); - } - catch(CORBA::COMM_FAILURE&){ - MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); - } - try{ - SALOME_ContainerManager *cmServ=new SALOME_ContainerManager(orb); - pman->activate(); - orb->run(); - }catch(CORBA::SystemException&){ - MESSAGE("Caught CORBA::SystemException."); - }catch(PortableServer::POA::WrongPolicy&){ - MESSAGE("Caught CORBA::WrongPolicyException."); - }catch(PortableServer::POA::ServantAlreadyActive&){ - MESSAGE("Caught CORBA::ServantAlreadyActiveException"); - }catch(CORBA::Exception&){ - MESSAGE("Caught CORBA::Exception."); - }catch(std::exception& exc){ - MESSAGE("Caught std::exception - "< +#ifndef WNT +#include +#endif +#include +#include "Utils_CorbaException.hxx" +#include "Batch_Date.hxx" + +#define TIME_OUT_TO_LAUNCH_CONT 21 + +using namespace std; + +const char *SALOME_Launcher::_LauncherNameInNS = "/SalomeLauncher"; + +//============================================================================= +/*! + * Constructor + * \param orb + * Define a CORBA single thread policy for the server, which avoid to deal + * with non thread-safe usage like Change_Directory in SALOME naming service + */ +//============================================================================= + +SALOME_Launcher::SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa) +{ + MESSAGE("constructor"); + _NS = new SALOME_NamingService(orb); + _ResManager = new SALOME_ResourcesManager(orb,poa,_NS); + _ContManager = new SALOME_ContainerManager(orb,poa,_ResManager,_NS); + + _orb = CORBA::ORB::_duplicate(orb) ; + _poa = PortableServer::POA::_duplicate(poa) ; + PortableServer::ObjectId_var id = _poa->activate_object(this); + CORBA::Object_var obj = _poa->id_to_reference(id); + Engines::SalomeLauncher_var refContMan = Engines::SalomeLauncher::_narrow(obj); + + _NS->Register(refContMan,_LauncherNameInNS); + MESSAGE("constructor end"); +} + +//============================================================================= +/*! + * destructor + */ +//============================================================================= + +SALOME_Launcher::~SALOME_Launcher() +{ + MESSAGE("destructor"); + delete _NS; + delete _ResManager; + delete _ContManager; + std::map < string, BatchLight::BatchManager * >::const_iterator it; + for(it=_batchmap.begin();it!=_batchmap.end();it++) + delete it->second; +} + +//============================================================================= +/*! CORBA method: + * shutdown all the containers, then the ContainerManager servant + */ +//============================================================================= + +void SALOME_Launcher::Shutdown() +{ + MESSAGE("Shutdown"); + _NS->Destroy_Name(_LauncherNameInNS); + _ContManager->Shutdown(); + _ResManager->Shutdown(); + PortableServer::ObjectId_var oid = _poa->servant_to_id(this); + _poa->deactivate_object(oid); + _remove_ref(); + if(!CORBA::is_nil(_orb)) + _orb->shutdown(0); +} + +//============================================================================= +/*! CORBA Method: + * Submit a batch job on a cluster and returns the JobId + * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster + * \param filesToExport : to export on the batch cluster + * \param NumberOfProcessors : Number of processors needed on the batch cluster + * \param params : Constraints for the choice of the batch cluster + */ +//============================================================================= +CORBA::Long SALOME_Launcher::submitSalomeJob( const char * fileToExecute , + const Engines::FilesList& filesToExport , + const Engines::FilesList& filesToImport , + const CORBA::Long NumberOfProcessors , + const Engines::MachineParameters& params) +{ + MESSAGE("BEGIN OF SALOME_Launcher::submitSalomeJob"); + CORBA::Long jobId; + try{ + // find a cluster matching the structure params + Engines::CompoList aCompoList ; + Engines::MachineList *aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; + const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]); + string clustername(p->alias); + + // search batch manager for that cluster in map or instanciate one + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + SCRUTE(clustername); + if(it == _batchmap.end()) + _batchmap[clustername] = FactoryBatchManager( p ); + + // submit job on cluster + BatchLight::Job* job = new BatchLight::Job( fileToExecute, filesToExport, filesToImport, NumberOfProcessors ); + jobId = _batchmap[clustername]->submitJob(job); + } + catch(const SALOME_Exception &ex){ + MESSAGE(ex.what()); + THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR); + } + return jobId; +} + +//============================================================================= +/*! CORBA Method: + * Query a batch job on a cluster and returns the status of job + * \param jobId : identification of Salome job + * \param params : Constraints for the choice of the batch cluster + */ +//============================================================================= +char* SALOME_Launcher::querySalomeJob( const CORBA::Long jobId, + const Engines::MachineParameters& params) +{ + string status; + try{ + // find a cluster matching params structure + Engines::CompoList aCompoList ; + Engines::MachineList * aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; + const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]); + string clustername(p->alias); + + // search batch manager for that cluster in map + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + if(it == _batchmap.end()) + throw SALOME_Exception("no batchmanager for that cluster"); + + status = _batchmap[clustername]->queryJob(jobId); + } + catch(const SALOME_Exception &ex){ + INFOS("Caught exception."); + THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); + } + return CORBA::string_dup(status.c_str()); +} + +//============================================================================= +/*! CORBA Method: + * Delete a batch job on a cluster + * \param jobId : identification of Salome job + * \param params : Constraints for the choice of the batch cluster + */ +//============================================================================= +void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, + const Engines::MachineParameters& params) +{ + try{ + // find a cluster matching params structure + Engines::CompoList aCompoList ; + Engines::MachineList *aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; + const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]); + string clustername(p->alias); + + // search batch manager for that cluster in map + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + if(it == _batchmap.end()) + throw SALOME_Exception("no batchmanager for that cluster"); + + _batchmap[clustername]->deleteJob(jobId); + } + catch(const SALOME_Exception &ex){ + INFOS("Caught exception."); + THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); + } +} + +//============================================================================= +/*! CORBA Method: + * Get result files of job on a cluster + * \param jobId : identification of Salome job + * \param params : Constraints for the choice of the batch cluster + */ +//============================================================================= +void SALOME_Launcher::getResultSalomeJob( const char *directory, + const CORBA::Long jobId, + const Engines::MachineParameters& params) +{ + try{ + // find a cluster matching params structure + Engines::CompoList aCompoList ; + Engines::MachineList *aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; + const Engines::MachineParameters* p = _ResManager->GetMachineParameters((*aMachineList)[0]); + string clustername(p->alias); + + // search batch manager for that cluster in map + std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); + if(it == _batchmap.end()) + throw SALOME_Exception("no batchmanager for that cluster"); + + _batchmap[clustername]->importOutputFiles( directory, jobId ); + } + catch(const SALOME_Exception &ex){ + INFOS("Caught exception."); + THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); + } +} + +//============================================================================= +/*! + * Factory to instanciate the good batch manager for choosen cluster. + */ +//============================================================================= + +BatchLight::BatchManager *SALOME_Launcher::FactoryBatchManager( const Engines::MachineParameters* params ) throw(SALOME_Exception) +{ + // Fill structure for batch manager + BatchLight::batchParams p; + p.hostname = params->alias; + p.protocol = params->protocol; + p.username = params->username; + p.applipath = params->applipath; + for(int i=0;imodList.length();i++) + p.modulesList.push_back((const char*)params->modList[i]); + p.nbnodes = params->nb_node; + p.nbprocpernode = params->nb_proc_per_node; + p.mpiImpl = params->mpiImpl; + + string sb = (const char*)params->batch; + if(sb == "pbs") + return new BatchLight::BatchManager_PBS(p); + else if(sb == "slurm") + return new BatchLight::BatchManager_SLURM(p); + else{ + MESSAGE("BATCH = " << params->batch); + throw SALOME_Exception("no batchmanager for that cluster"); + } +} + diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx new file mode 100644 index 000000000..5c83afbbf --- /dev/null +++ b/src/Launcher/SALOME_Launcher.hxx @@ -0,0 +1,80 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef __SALOME_LAUNCHER_HXX__ +#define __SALOME_LAUNCHER_HXX__ + +#include +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) +#include "SALOME_ContainerManager.hxx" +#include "BatchLight_BatchManager.hxx" + +#include + +class SALOME_NamingService; + +#if defined LAUNCHER_EXPORTS +#if defined WIN32 +#define LAUNCHER_EXPORT __declspec( dllexport ) +#else +#define LAUNCHER_EXPORT +#endif +#else +#if defined WNT +#define LAUNCHER_EXPORT __declspec( dllimport ) +#else +#define LAUNCHER_EXPORT +#endif +#endif + +class LAUNCHER_EXPORT SALOME_Launcher: + public POA_Engines::SalomeLauncher, + public PortableServer::RefCountServantBase +{ + +public: + SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa); + ~SALOME_Launcher(); + + CORBA::Long submitSalomeJob(const char * fileToExecute , + const Engines::FilesList& filesToExport , + const Engines::FilesList& filesToImport , + const CORBA::Long NumberOfProcessors , + const Engines::MachineParameters& params); + + char* querySalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); + void deleteSalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params); + void getResultSalomeJob( const char * directory, const CORBA::Long jobId, const Engines::MachineParameters& params ); + + void Shutdown(); + + static const char *_LauncherNameInNS; + +protected: + BatchLight::BatchManager *FactoryBatchManager( const Engines::MachineParameters* params ) throw(SALOME_Exception); + + std::map _batchmap; + CORBA::ORB_var _orb; + PortableServer::POA_var _poa; + SALOME_ContainerManager *_ContManager; + SALOME_ResourcesManager *_ResManager; + SALOME_NamingService *_NS; +}; + +#endif diff --git a/src/Launcher/SALOME_LauncherServer.cxx b/src/Launcher/SALOME_LauncherServer.cxx new file mode 100644 index 000000000..855b967e9 --- /dev/null +++ b/src/Launcher/SALOME_LauncherServer.cxx @@ -0,0 +1,63 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "SALOME_Launcher.hxx" +#include "utilities.h" + +int main(int argc, char* argv[]) +{ + PortableServer::POA_var root_poa; + PortableServer::POAManager_var pman; + CORBA::Object_var obj; + + CORBA::ORB_ptr orb = CORBA::ORB_init( argc , argv ) ; + // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); + INFOS_COMPILATION; + BEGIN_OF(argv[0]); + try{ + obj = orb->resolve_initial_references("RootPOA"); + if(!CORBA::is_nil(obj)) + root_poa = PortableServer::POA::_narrow(obj); + if(!CORBA::is_nil(root_poa)) + pman = root_poa->the_POAManager(); + } + catch(CORBA::COMM_FAILURE&){ + MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); + } + try{ + SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa); + pman->activate(); + orb->run(); + }catch(CORBA::SystemException&){ + MESSAGE("Caught CORBA::SystemException."); + }catch(PortableServer::POA::WrongPolicy&){ + MESSAGE("Caught CORBA::WrongPolicyException."); + }catch(PortableServer::POA::ServantAlreadyActive&){ + MESSAGE("Caught CORBA::ServantAlreadyActiveException"); + }catch(CORBA::Exception&){ + MESSAGE("Caught CORBA::Exception."); + }catch(std::exception& exc){ + MESSAGE("Caught std::exception - "<GetFittingResources(params, clist); + resManager->GetFittingResources(params, clist); container = contManager->FindOrStartContainer(params, listOfMachines); diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 8c8de44a2..16e4016d3 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -92,6 +92,10 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); ASSERT( !CORBA::is_nil(obj)); _ContManager=Engines::ContainerManager::_narrow(obj); + + obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); + ASSERT( !CORBA::is_nil(obj)); + _ResManager=Engines::ResourcesManager::_narrow(obj); } //============================================================================= @@ -126,7 +130,7 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::MachineParameters& params, clist.length(1); clist[0] = componentName; Engines::MachineList_var listOfMachines = - _ContManager->GetFittingResources(params, clist); + _ResManager->GetFittingResources(params, clist); Engines::Component_var compo = _FindComponent(params, componentName, @@ -160,7 +164,7 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::MachineParameters& params, clist.length(1); clist[0] = componentName; Engines::MachineList_var listOfMachines = - _ContManager->GetFittingResources(params, clist); + _ResManager->GetFittingResources(params, clist); Engines::Component_var compo = _LoadComponent(params, componentName, @@ -196,7 +200,7 @@ FindOrLoad_Component(const Engines::MachineParameters& params, clist.length(1); clist[0] = componentName; Engines::MachineList_var listOfMachines = - _ContManager->GetFittingResources(params,clist); + _ResManager->GetFittingResources(params,clist); Engines::Component_var compo = _FindComponent(params, componentName, @@ -396,6 +400,19 @@ Engines::ContainerManager_ptr SALOME_LifeCycleCORBA::getContainerManager() return contManager._retn(); } +//============================================================================= +/*! Public - + * \return the container Manager + */ +//============================================================================= + +Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager() +{ + Engines::ResourcesManager_var resManager = + Engines::ResourcesManager::_duplicate(_ResManager); + return resManager._retn(); +} + //============================================================================= /*! Protected - @@ -446,7 +463,7 @@ _FindComponent(const Engines::MachineParameters& params, if(lghtOfmachinesOK != 0) { machinesOK->length(lghtOfmachinesOK); - CORBA::String_var bestMachine = _ContManager->FindFirst(machinesOK); + CORBA::String_var bestMachine = _ResManager->FindFirst(machinesOK); CORBA::Object_var obj = _NS->ResolveComponent(bestMachine, containerName, componentName, diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index 0ff890dda..dd6b14885 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -99,6 +99,7 @@ public: void preSet(Engines::MachineParameters& params); Engines::ContainerManager_ptr getContainerManager(); + Engines::ResourcesManager_ptr getResourcesManager(); protected: @@ -121,6 +122,7 @@ protected: SALOME_NamingService *_NS; Engines::ContainerManager_var _ContManager; + Engines::ResourcesManager_var _ResManager; } ; diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx index dbcca2882..2c724e369 100644 --- a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -672,11 +672,11 @@ string LifeCycleCORBATest::GetRemoteHost() { SALOME_LifeCycleCORBA _LCC(&_NS); - CORBA::Object_var obj = _NS.Resolve("/ContainerManager"); + CORBA::Object_var obj = _NS.Resolve("/ResourcesManager"); CPPUNIT_ASSERT(!CORBA::is_nil(obj)); - Engines::ContainerManager_var containerManager = - Engines::ContainerManager::_narrow(obj); - CPPUNIT_ASSERT(!CORBA::is_nil(containerManager)); + Engines::ResourcesManager_var resourcesManager = + Engines::ResourcesManager::_narrow(obj); + CPPUNIT_ASSERT(!CORBA::is_nil(resourcesManager)); Engines::MachineParameters params; _LCC.preSet(params); // empty params to get all the machines @@ -685,7 +685,7 @@ string LifeCycleCORBATest::GetRemoteHost() clist.length(1); clist[0] = "SalomeTestComponent"; Engines::MachineList_var hostList = - containerManager->GetFittingResources(params,clist); + resourcesManager->GetFittingResources(params,clist); CPPUNIT_ASSERT(hostList->length() > 1); string localHost = GetHostname(); diff --git a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py index 3e3b974b3..c0f96369b 100644 --- a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py +++ b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py @@ -63,12 +63,12 @@ cataServer.setpath(modules_list,modules_root_dir) cataServer.run() clt.waitNS("/Kernel/ModulCatalog") -# launch container manager server +# launch launcher server -myCmServer = runSalome.ContainerManagerServer(args) +myCmServer = runSalome.LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() -clt.waitNS("/ContainerManager") +clt.waitNS("/SalomeLauncher") # execute Unit Test @@ -78,8 +78,8 @@ ret = os.spawnvp(os.P_WAIT, command[0], command) # kill containers created by the Container Manager import Engines -containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) -containerManager.Shutdown() +launcher = clt.waitNS("/SalomeLauncher",Engines.SalomeLauncher) +launcher.Shutdown() # kill Test process diff --git a/src/LifeCycleCORBA/TestContainerManager.cxx b/src/LifeCycleCORBA/TestContainerManager.cxx index 1d1bd6d70..9313aace7 100644 --- a/src/LifeCycleCORBA/TestContainerManager.cxx +++ b/src/LifeCycleCORBA/TestContainerManager.cxx @@ -59,6 +59,9 @@ int main (int argc, char * argv[]) CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); ASSERT( !CORBA::is_nil(obj)); Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj); + obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); + ASSERT( !CORBA::is_nil(obj)); + Engines::ResourcesManager_var _ResManager=Engines::ResourcesManager::_narrow(obj); Engines::MachineParameters p; Engines::CompoList clist; @@ -133,7 +136,7 @@ int main (int argc, char * argv[]) int nbpmax; for(map::iterator iter=cycle.begin();iter!=cycle.end();iter++){ if(strcmp((*iter).first.c_str(),"localhost")!=0){ - Engines::MachineParameters *p = _ContManager->GetMachineParameters((*iter).first.c_str()); + Engines::MachineParameters *p = _ResManager->GetMachineParameters((*iter).first.c_str()); int nbproc = p->nb_node * p->nb_proc_per_node; if(cycle[(*iter).first]/nbproccmax) cmax=cycle[(*iter).first]/nbproc; diff --git a/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py index 2157e8d38..7138c82dd 100644 --- a/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py +++ b/src/LifeCycleCORBA_SWIG/Test/TestLifeCycleCORBA_SWIG.py @@ -74,10 +74,10 @@ clt.waitNS("/Kernel/ModulCatalog") # launch container manager server -myCmServer = runSalome.ContainerManagerServer(args) +myCmServer = runSalome.LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() -clt.waitNS("/ContainerManager") +clt.waitNS("/SalomeLauncher") # execute Unit Test @@ -91,8 +91,8 @@ unittest.TextTestRunner(verbosity=2).run(LifeCycleCORBA_SWIGTest.suite()) # kill containers created by the Container Manager import Engines -containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) -containerManager.Shutdown() +launcher = clt.waitNS("/SalomeLauncher",Engines.SalomeLauncher) +launcher.Shutdown() # kill Test process diff --git a/src/Makefile.am b/src/Makefile.am index 010d8fcd6..41b73d439 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -43,6 +43,7 @@ SUBDIR_CORBA = \ NOTIFICATION_SWIG \ Container \ TestContainer \ + Launcher \ LifeCycleCORBA \ LifeCycleCORBA_SWIG \ SALOMEDSClient \ diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index d871d2f31..4760b3844 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -17,11 +17,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "BatchLight_BatchManager_PBS.hxx" -#include "BatchLight_BatchManager_SLURM.hxx" #include "SALOME_ResourcesManager.hxx" -#include "BatchLight_Job.hxx" #include "Utils_ExceptHandlers.hxx" +#include "Utils_CorbaException.hxx" #include "OpUtil.hxx" #include @@ -48,6 +46,8 @@ using namespace std; +const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager"; + //============================================================================= /*! * just for test @@ -55,11 +55,23 @@ using namespace std; //============================================================================= SALOME_ResourcesManager:: -SALOME_ResourcesManager(CORBA::ORB_ptr orb, +SALOME_ResourcesManager(CORBA::ORB_ptr orb, + PortableServer::POA_var poa, + SALOME_NamingService *ns, const char *xmlFilePath) : _path_resources(xmlFilePath) { - _NS = new SALOME_NamingService(orb); + MESSAGE("constructor"); + _NS = ns; + _orb = CORBA::ORB::_duplicate(orb) ; + _poa = PortableServer::POA::_duplicate(poa) ; + PortableServer::ObjectId_var id = _poa->activate_object(this); + CORBA::Object_var obj = _poa->id_to_reference(id); + Engines::SalomeLauncher_var refContMan = + Engines::SalomeLauncher::_narrow(obj); + + _NS->Register(refContMan,_ResourcesManagerNameInNS); + MESSAGE("constructor end"); } //============================================================================= @@ -73,9 +85,19 @@ SALOME_ResourcesManager(CORBA::ORB_ptr orb, */ //============================================================================= -SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb) +SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, + PortableServer::POA_var poa, + SALOME_NamingService *ns) { - _NS = new SALOME_NamingService(orb); + MESSAGE("constructor"); + _NS = ns; + _orb = CORBA::ORB::_duplicate(orb) ; + _poa = PortableServer::POA::_duplicate(poa) ; + PortableServer::ObjectId_var id = _poa->activate_object(this); + CORBA::Object_var obj = _poa->id_to_reference(id); + Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj); + _NS->Register(refContMan,_ResourcesManagerNameInNS); + _isAppliSalomeDefined = (getenv("APPLI") != 0); if (_isAppliSalomeDefined) @@ -93,6 +115,7 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb) } ParseXmlFile(); + MESSAGE("constructor end"); } //============================================================================= @@ -103,10 +126,23 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb) SALOME_ResourcesManager::~SALOME_ResourcesManager() { - delete _NS; - std::map < string, BatchLight::BatchManager * >::const_iterator it; - for(it=_batchmap.begin();it!=_batchmap.end();it++) - delete it->second; + MESSAGE("destructor"); +} + + +//============================================================================= +/*! CORBA method: + * shutdown all the containers, then the ContainerManager servant + */ +//============================================================================= + +void SALOME_ResourcesManager::Shutdown() +{ + MESSAGE("Shutdown"); + _NS->Destroy_Name(_ResourcesManagerNameInNS); + PortableServer::ObjectId_var oid = _poa->servant_to_id(this); + _poa->deactivate_object(oid); + _remove_ref(); } //============================================================================= @@ -123,101 +159,113 @@ SALOME_ResourcesManager::~SALOME_ResourcesManager() */ //============================================================================= -vector -SALOME_ResourcesManager:: -GetFittingResources(const Engines::MachineParameters& params, - const Engines::CompoList& componentList) +Engines::MachineList * +SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params, + const Engines::CompoList& componentList) throw(SALOME_Exception) { // MESSAGE("ResourcesManager::GetFittingResources"); - vector ret; + vector vec; + Engines::MachineList *ret=new Engines::MachineList; + try{ + // --- To be sure that we search in a correct list. + ParseXmlFile(); - // --- To be sure that we search in a correct list. - ParseXmlFile(); - - const char *hostname = (const char *)params.hostname; - MESSAGE("GetFittingResources " << hostname << " " << GetHostname().c_str()); + const char *hostname = (const char *)params.hostname; + MESSAGE("GetFittingResources " << hostname << " " << GetHostname().c_str()); - if (hostname[0] != '\0') - { + if (hostname[0] != '\0') + { // MESSAGE("ResourcesManager::GetFittingResources : hostname specified" ); - if ( strcmp(hostname, "localhost") == 0 || - strcmp(hostname, GetHostname().c_str()) == 0 ) - { -// MESSAGE("ResourcesManager::GetFittingResources : localhost" ); - ret.push_back(GetHostname().c_str()); -// MESSAGE("ResourcesManager::GetFittingResources : " << ret.size()); - } - - else if (_resourcesList.find(hostname) != _resourcesList.end()) - { - // --- params.hostname is in the list of resources so return it. - ret.push_back(hostname); - } - - else - { -// Cas d'un cluster: nombre de noeuds > 1 - int cpt=0; - for (map::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){ - if( (*iter).second.DataForSort._nbOfNodes > 1 ){ - if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){ - ret.push_back((*iter).first.c_str()); - //cout << "SALOME_ResourcesManager::GetFittingResources vector[" - // << cpt << "] = " << (*iter).first.c_str() << endl ; - cpt++; - } - } - } - if(cpt==0){ - // --- user specified an unknown hostame so notify him. - MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception"); - throw SALOME_Exception("unknown host"); - } - } - } + if ( strcmp(hostname, "localhost") == 0 || + strcmp(hostname, GetHostname().c_str()) == 0 ) + { + // MESSAGE("ResourcesManager::GetFittingResources : localhost" ); + vec.push_back(GetHostname().c_str()); + // MESSAGE("ResourcesManager::GetFittingResources : " << vec.size()); + } + + else if (_resourcesList.find(hostname) != _resourcesList.end()) + { + // --- params.hostname is in the list of resources so return it. + vec.push_back(hostname); + } + + else + { + // Cas d'un cluster: nombre de noeuds > 1 + int cpt=0; + for (map::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){ + if( (*iter).second.DataForSort._nbOfNodes > 1 ){ + if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){ + vec.push_back((*iter).first.c_str()); + //cout << "SALOME_ResourcesManager::GetFittingResources vector[" + // << cpt << "] = " << (*iter).first.c_str() << endl ; + cpt++; + } + } + } + if(cpt==0){ + // --- user specified an unknown hostame so notify him. + MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception"); + throw SALOME_Exception("unknown host"); + } + } + } + + else + // --- Search for available resources sorted by priority + { + SelectOnlyResourcesWithOS(vec, params.OS); + + KeepOnlyResourcesWithModule(vec, componentList); + + if (vec.size() == 0) + SelectOnlyResourcesWithOS(vec, params.OS); + + // --- set wanted parameters + ResourceDataToSort::_nbOfNodesWanted = params.nb_node; + + ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node; + + ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock; + + ResourceDataToSort::_memInMBWanted = params.mem_mb; + + // --- end of set + + list li; + + for (vector::iterator iter = vec.begin(); + iter != vec.end(); + iter++) + li.push_back(_resourcesList[(*iter)].DataForSort); + + li.sort(); + + unsigned int i = 0; + + for (list::iterator iter2 = li.begin(); + iter2 != li.end(); + iter2++) + vec[i++] = (*iter2)._hostName; + } + + // MESSAGE("ResourcesManager::GetFittingResources : return" << ret.size()); + ret->length(vec.size()); + for(unsigned int i=0;i li; - - for (vector::iterator iter = ret.begin(); - iter != ret.end(); - iter++) - li.push_back(_resourcesList[(*iter)].DataForSort); - - li.sort(); - - unsigned int i = 0; - - for (list::iterator iter2 = li.begin(); - iter2 != li.end(); - iter2++) - ret[i++] = (*iter2)._hostName; - } + INFOS("Caught exception."); + THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::BAD_PARAM); + //return ret; + } - // MESSAGE("ResourcesManager::GetFittingResources : return" << ret.size()); return ret; } @@ -345,10 +393,10 @@ const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const */ //============================================================================= -string +char * SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines) { - return _dynamicResourcesSelecter.FindFirst(listOfMachines); + return CORBA::string_dup(_dynamicResourcesSelecter.FindFirst(listOfMachines).c_str()); } //============================================================================= @@ -374,8 +422,6 @@ SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines) return _dynamicResourcesSelecter.FindBest(listOfMachines); } - - //============================================================================= /*! * This is no longer valid (C++ container are also python containers) @@ -514,165 +560,6 @@ SALOME_ResourcesManager::BuildCommandToLaunchRemoteContainer return command; } -//============================================================================= -/*! CORBA Method: - * Submit a batch job on a cluster and returns the JobId - * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster - * \param filesToExport : to export on the batch cluster - * \param filesToExport : to import from the batch cluster after job - * \param NumberOfProcessors : Number of processors needed on the batch cluster - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -CORBA::Long SALOME_ResourcesManager::submitSalomeJob( const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const CORBA::Long NumberOfProcessors , - const Engines::MachineParameters& params) throw(SALOME_Exception) -{ - BEGIN_OF("SALOME_ResourcesManager::submitSalomeJob"); - CORBA::Long jobId; - - // find a cluster matching the structure params - Engines::CompoList aCompoList ; - vector aMachineList = GetFittingResources( params , aCompoList ) ; - const ParserResourcesType& resInfo = _resourcesList[aMachineList[0]]; - string clustername = resInfo.Alias; - - // search batch manager for that cluster in map or instanciate one - 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 = _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; - p.nbnodes = resInfo.DataForSort._nbOfNodes; - p.nbprocpernode = resInfo.DataForSort._nbOfProcPerNode; - if( resInfo.mpi == indif ) - p.mpiImpl = "indif"; - else if( resInfo.mpi == lam ) - p.mpiImpl = "lam"; - else if( resInfo.mpi == mpich1 ) - p.mpiImpl = "mpich1"; - else if( resInfo.mpi == mpich2 ) - p.mpiImpl = "mpich2"; - else if( resInfo.mpi == openmpi ) - p.mpiImpl = "openmpi"; - else - throw SALOME_Exception("Unknown mpi implementation"); - - switch( resInfo.Batch ){ - case pbs: - return new BatchLight::BatchManager_PBS(p); - 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 - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -string SALOME_ResourcesManager::querySalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params) throw(SALOME_Exception) -{ - string status; - - // find a cluster matching params structure - Engines::CompoList aCompoList ; - vector aMachineList = GetFittingResources( params , aCompoList ) ; - const ParserResourcesType& resInfo = _resourcesList[aMachineList[0]]; - string clustername = resInfo.Alias; - - // search batch manager for that cluster in map - std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw SALOME_Exception("no batchmanager for that cluster"); - - status = _batchmap[clustername]->queryJob(jobId); - return(status); -} - - -//============================================================================= -/*! CORBA Method: - * delete a batch job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void SALOME_ResourcesManager::deleteSalomeJob( const CORBA::Long jobId, const Engines::MachineParameters& params) throw(SALOME_Exception) -{ - // find a cluster matching params structure - Engines::CompoList aCompoList ; - vector aMachineList = GetFittingResources( params , aCompoList ) ; - const ParserResourcesType& resInfo = _resourcesList[aMachineList[0]]; - string clustername = resInfo.Alias; - - // search batch manager for that cluster in map - std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw SALOME_Exception("no batchmanager for that cluster"); - - _batchmap[clustername]->deleteJob(jobId); -} - -//============================================================================= -/*! CORBA Method: - * delete a batch job on a cluster - * \param jobId : identification of Salome job - * \param params : Constraints for the choice of the batch cluster - */ -//============================================================================= -void SALOME_ResourcesManager::getResultSalomeJob( const char *directory, - const CORBA::Long jobId, - const Engines::MachineParameters& params) throw(SALOME_Exception) -{ - // find a cluster matching params structure - Engines::CompoList aCompoList ; - vector aMachineList = GetFittingResources( params , aCompoList ) ; - const ParserResourcesType& resInfo = _resourcesList[aMachineList[0]]; - string clustername = resInfo.Alias; - - // search batch manager for that cluster in map - std::map < string, BatchLight::BatchManager * >::const_iterator it = _batchmap.find(clustername); - if(it == _batchmap.end()) - throw SALOME_Exception("no batchmanager for that cluster"); - - _batchmap[clustername]->importOutputFiles( directory, jobId ); -} - //============================================================================= /*! * builds the command to be launched. @@ -1088,10 +975,36 @@ Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const Engines::MachineParameters *p_ptr = new Engines::MachineParameters; p_ptr->container_name = CORBA::string_dup(""); p_ptr->hostname = CORBA::string_dup("hostname"); + p_ptr->alias = CORBA::string_dup(resource.Alias.c_str()); + if( resource.Protocol == rsh ) + p_ptr->protocol = "rsh"; + else if( resource.Protocol == ssh ) + p_ptr->protocol = "ssh"; + p_ptr->username = CORBA::string_dup(resource.UserName.c_str()); + p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str()); + p_ptr->modList.length(resource.ModulesList.size()); + for(int i=0;imodList[i] = CORBA::string_dup(resource.ModulesList[i].c_str()); p_ptr->OS = CORBA::string_dup(resource.OS.c_str()); p_ptr->mem_mb = resource.DataForSort._memInMB; p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz; p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode; p_ptr->nb_node = resource.DataForSort._nbOfNodes; + if( resource.mpi == indif ) + p_ptr->mpiImpl = "indif"; + else if( resource.mpi == lam ) + p_ptr->mpiImpl = "lam"; + else if( resource.mpi == mpich1 ) + p_ptr->mpiImpl = "mpich1"; + else if( resource.mpi == mpich2 ) + p_ptr->mpiImpl = "mpich2"; + else if( resource.mpi == openmpi ) + p_ptr->mpiImpl = "openmpi"; + if( resource.Batch == pbs ) + p_ptr->batch = "pbs"; + else if( resource.Batch == lsf ) + p_ptr->batch = "lsf"; + else if( resource.Batch == slurm ) + p_ptr->batch = "slurm"; return p_ptr; } diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 45e370ff8..e6d79ea11 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -23,7 +23,6 @@ #include "Utils_SALOME_Exception.hxx" #include "utilities.h" #include -#include "BatchLight_BatchManager.hxx" #include "SALOME_ResourcesCatalog_Handler.hxx" #include "SALOME_LoadRateManager.hxx" #include "SALOME_NamingService.hxx" @@ -52,22 +51,24 @@ // Only one thread should use the SALOME_ResourcesManager class in a SALOME // session. -class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager +class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager: + public POA_Engines::ResourcesManager, + public PortableServer::RefCountServantBase { public: - SALOME_ResourcesManager(CORBA::ORB_ptr orb, const char *xmlFilePath); - SALOME_ResourcesManager(CORBA::ORB_ptr orb); + SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns, const char *xmlFilePath); + SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns); ~SALOME_ResourcesManager(); - std::vector + Engines::MachineList * GetFittingResources(const Engines::MachineParameters& params, const Engines::CompoList& componentList) throw(SALOME_Exception); - std::string FindFirst(const Engines::MachineList& listOfMachines); + char* FindFirst(const Engines::MachineList& listOfMachines); std::string FindNext(const Engines::MachineList& listOfMachines); std::string FindBest(const Engines::MachineList& listOfMachines); @@ -75,18 +76,6 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager (const std::string& machine, const Engines::MachineParameters& params, const long id); - CORBA::Long submitSalomeJob(const char * fileToExecute , - const Engines::FilesList& filesToExport , - const Engines::FilesList& filesToImport , - const CORBA::Long NumberOfProcessors , - 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); - void getResultSalomeJob( const char *directory, - const CORBA::Long jobId, - const Engines::MachineParameters& params) throw(SALOME_Exception); - std::string BuildCommandToLaunchLocalContainer (const Engines::MachineParameters& params, const long id); @@ -114,9 +103,14 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager Engines::MachineParameters* GetMachineParameters(const char *hostname); + void Shutdown(); + + static const char *_ResourcesManagerNameInNS; + protected: SALOME_NamingService *_NS; - std::map _batchmap; + CORBA::ORB_var _orb; + PortableServer::POA_var _poa; std::string BuildTempFileToLaunchRemoteContainer (const std::string& machine, @@ -136,8 +130,6 @@ 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; diff --git a/src/UnitTests/UnitTests.py b/src/UnitTests/UnitTests.py index 238807a6b..3c9402338 100644 --- a/src/UnitTests/UnitTests.py +++ b/src/UnitTests/UnitTests.py @@ -64,10 +64,10 @@ clt.waitNS("/Kernel/ModulCatalog") # launch container manager server -myCmServer = runSalome.ContainerManagerServer(args) +myCmServer = runSalome.LauncherServer(args) myCmServer.setpath(modules_list,modules_root_dir) myCmServer.run() -clt.waitNS("/ContainerManager") +clt.waitNS("/SalomeLauncher") # execute Unit Test @@ -77,8 +77,8 @@ ret = os.spawnvp(os.P_WAIT, command[0], command) # kill containers created by the Container Manager import Engines -containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) -containerManager.Shutdown() +launcher = clt.waitNS("/SalomeLauncher",Engines.SalomeLauncher) +launcher.Shutdown() # kill Test process