From 693097342f4be4a545e92ad7b8c2ef97802a88fd Mon Sep 17 00:00:00 2001 From: secher Date: Mon, 9 Jul 2007 14:31:33 +0000 Subject: [PATCH] improvement to shutdown salome properly and to launch exception if problem of connection on remote host --- bin/Makefile.am | 3 +- bin/orbmodule.py | 2 +- bin/shutdownSalome.py | 28 ++++++++ idl/SALOMEDS.idl | 2 + idl/SALOME_Registry.idl | 1 + src/Container/SALOME_ContainerManager.cxx | 39 +++++----- src/Container/SALOME_ContainerManager.hxx | 1 + .../SALOME_ModuleCatalog_impl.hxx | 2 +- src/Registry/RegistryService.cxx | 2 +- src/Registry/RegistryService.hxx | 4 ++ src/Registry/SALOME_Registry_Server.cxx | 1 + .../SALOME_ResourcesManager.cxx | 71 ++++++++++++++----- .../SALOME_ResourcesManager.hxx | 12 ++-- src/SALOMEDS/SALOMEDS_StudyManager_i.hxx | 2 + 14 files changed, 125 insertions(+), 45 deletions(-) create mode 100755 bin/shutdownSalome.py diff --git a/bin/Makefile.am b/bin/Makefile.am index 97a23267f..39cfba893 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -59,7 +59,8 @@ dist_salomescript_SCRIPTS=\ addToKillList.py \ NSparam.py \ waitNS.py \ - waitContainers.py + waitContainers.py \ + shutdownSalome.py EXTRA_DIST = appliskel diff --git a/bin/orbmodule.py b/bin/orbmodule.py index 86e67d6bf..407e9b7b5 100755 --- a/bin/orbmodule.py +++ b/bin/orbmodule.py @@ -15,7 +15,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# +# import sys,os,time import string from omniORB import CORBA diff --git a/bin/shutdownSalome.py b/bin/shutdownSalome.py new file mode 100755 index 000000000..78e1001b4 --- /dev/null +++ b/bin/shutdownSalome.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +import orbmodule +import Engines +import Registry +import SALOME +import SALOMEDS +import SALOME_ModuleCatalog +clt=orbmodule.client() +obj = clt.Resolve('Kernel/Session') +if obj != None: + ses = obj._narrow(SALOME.Session) + ses.StopSession() +obj = clt.Resolve('ContainerManager') +if obj != None: + cm = obj._narrow(Engines.ContainerManager) + cm.Shutdown() +obj = clt.Resolve('Kernel/ModulCatalog') +if obj != None: + mc = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) + mc.shutdown() +obj = clt.Resolve('Registry') +if obj != None: + reg = obj._narrow(Registry.Components) + reg.Shutdown() +obj = clt.Resolve('myStudyManager') +if obj != None: + sm = obj._narrow(SALOMEDS.StudyManager) + sm.Shutdown() diff --git a/idl/SALOMEDS.idl b/idl/SALOMEDS.idl index 8920ec25b..6399acbd8 100644 --- a/idl/SALOMEDS.idl +++ b/idl/SALOMEDS.idl @@ -708,6 +708,8 @@ Searches for a definite %SObject with a definite GUID and returns True if it fin */ void ping(); + void Shutdown(); + /*! \brief Creation of a new study Creates a new study with a definite name. diff --git a/idl/SALOME_Registry.idl b/idl/SALOME_Registry.idl index e33e2ccd1..8e4433215 100644 --- a/idl/SALOME_Registry.idl +++ b/idl/SALOME_Registry.idl @@ -55,6 +55,7 @@ module Registry AllInfos history () ; oneway void end() ; oneway void hello( in unsigned long id ) ; + void Shutdown(); } ; } ; diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 44383901a..15dbff53a 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -58,6 +58,7 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb) PortableServer::POAManager_var pman = root_poa->the_POAManager(); PortableServer::POA_var my_poa; + _orb = CORBA::ORB::_duplicate(orb) ; CORBA::PolicyList policies; policies.length(1); PortableServer::ThreadPolicy_var threadPol = @@ -99,6 +100,8 @@ void SALOME_ContainerManager::Shutdown() { MESSAGE("Shutdown"); ShutdownContainers(); + _orb->shutdown(0); + _NS->Destroy_Name(_ContainerManagerNameInNS); PortableServer::ObjectId_var oid = _default_POA()->servant_to_id(this); _default_POA()->deactivate_object(oid); _remove_ref(); @@ -114,36 +117,34 @@ void SALOME_ContainerManager::Shutdown() void SALOME_ContainerManager::ShutdownContainers() { MESSAGE("ShutdownContainers"); - _NS->Change_Directory("/Containers"); - vector vec = _NS->list_directory_recurs(); - list lstCont; - for(vector::iterator iter = vec.begin();iter!=vec.end();iter++) - { + bool isOK; + isOK = _NS->Change_Directory("/Containers"); + if( isOK ){ + vector vec = _NS->list_directory_recurs(); + list lstCont; + for(vector::iterator iter = vec.begin();iter!=vec.end();iter++){ SCRUTE((*iter)); CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); Engines::Container_var cont=Engines::Container::_narrow(obj); - if(!CORBA::is_nil(cont)) - { - lstCont.push_back((*iter)); - } + if(!CORBA::is_nil(cont)){ + lstCont.push_back((*iter)); + } } - MESSAGE("Container list: "); - for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++) - { + MESSAGE("Container list: "); + for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){ SCRUTE((*iter)); } - for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++) - { + for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){ SCRUTE((*iter)); CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); Engines::Container_var cont=Engines::Container::_narrow(obj); - if(!CORBA::is_nil(cont)) - { - MESSAGE("ShutdownContainers: " << (*iter)); - cont->Shutdown(); - } + if(!CORBA::is_nil(cont)){ + MESSAGE("ShutdownContainers: " << (*iter)); + cont->Shutdown(); + } else MESSAGE("ShutdownContainers: no container ref for " << (*iter)); } + } } //============================================================================= diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 90ba170a7..f64950f87 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -103,6 +103,7 @@ protected: long GetIdForContainer(void); long _id; + CORBA::ORB_var _orb; SALOME_ResourcesManager *_ResManager; SALOME_NamingService *_NS; diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx index d09e02da6..96e1a91a9 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx @@ -119,7 +119,7 @@ public: void ping(){}; - void shutdown() { if (_orb) _orb->shutdown(1); }; + void shutdown() { if (_orb) _orb->shutdown(0); }; private: //! method to parse one module catalog diff --git a/src/Registry/RegistryService.cxx b/src/Registry/RegistryService.cxx index 21524aa8d..8e37ce26a 100644 --- a/src/Registry/RegistryService.cxx +++ b/src/Registry/RegistryService.cxx @@ -47,7 +47,7 @@ using namespace std; RegistryService::RegistryService( void ) : _SessionName(0), _Compteur(0) { MESSAGE("Passage dans RegistryService::RegistryService()") ; - + _orb = CORBA::ORB::_nil(); } diff --git a/src/Registry/RegistryService.hxx b/src/Registry/RegistryService.hxx index b52fa758d..3629403a6 100644 --- a/src/Registry/RegistryService.hxx +++ b/src/Registry/RegistryService.hxx @@ -100,9 +100,13 @@ public : void SessionName( const char *sessionName ) ; + void SetOrb( CORBA::ORB_ptr orb ) { _orb = orb; return; } + + void Shutdown() { if(!CORBA::is_nil(_orb)) _orb->shutdown(0); } protected : + CORBA::ORB_var _orb; const char *_SessionName ; int _Compteur ; std::map _reg ; diff --git a/src/Registry/SALOME_Registry_Server.cxx b/src/Registry/SALOME_Registry_Server.cxx index 7dc1b6817..470cde401 100644 --- a/src/Registry/SALOME_Registry_Server.cxx +++ b/src/Registry/SALOME_Registry_Server.cxx @@ -168,6 +168,7 @@ int main( int argc , char **argv ) naming.init_orb( orb ) ; RegistryService *ptrRegistry = SINGLETON_::Instance() ; ptrRegistry->SessionName( ptrSessionName ) ; + ptrRegistry->SetOrb(orb); varComponents = ptrRegistry->_this() ; // The RegistryService must not already exist. diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index b7627a8a5..e0b17b028 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -517,10 +517,12 @@ SALOME_ResourcesManager::BuildCommandToLaunchRemoteContainer void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, const std::string& DirForTmpFiles , const std::string& PathFileNameToExecute , - const Engines::FilesToExportList& filesToExport) { + const Engines::FilesToExportList& filesToExport) throw(SALOME_Exception) +{ BEGIN_OF("SALOME_ResourcesManager::CopyFileNamesToExecute"); const ParserResourcesType& resInfo = _resourcesList[machine]; string command; + int status; if (resInfo.Protocol == rsh) command = "rsh "; @@ -538,7 +540,10 @@ void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, command += " \"mkdir -p "; command += DirForTmpFiles ; command += "\"" ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); if (resInfo.Protocol == rsh) command = "rcp "; @@ -558,7 +563,10 @@ void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, command += resInfo.Alias; command += ":"; command += DirForTmpFiles ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); int i ; for ( i = 0 ; i < filesToExport.length() ; i++ ) { @@ -577,7 +585,10 @@ void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, command += resInfo.Alias; command += ":"; command += DirForTmpFiles ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); } END_OF("SALOME_ResourcesManager::CopyFileNamesToExecute"); @@ -605,8 +616,10 @@ void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, std::string SALOME_ResourcesManager::BuildCmdrunSalomeBatch( const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) { + const std::string& FileNameToExecute ) throw(SALOME_Exception) +{ BEGIN_OF("SALOME_ResourcesManager::BuildCmdrunSalomeBatch"); + int status; _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); @@ -634,6 +647,7 @@ std::string SALOME_ResourcesManager::BuildCmdrunSalomeBatch( tempOutputFile << " sleep 1" << endl ; tempOutputFile << " ./runSession waitContainers.py $arglist" << endl ; tempOutputFile << " ./runSession python ~/" << DirForTmpFiles << "/" << FileNameToExecute << ".py" << endl; + tempOutputFile << " ./runSession shutdownSalome.py" << endl; tempOutputFile << "else" << endl ; tempOutputFile << " sleep 1" << endl ; tempOutputFile << " ./runSession waitNS.py" << endl ; @@ -664,7 +678,10 @@ std::string SALOME_ResourcesManager::BuildCmdrunSalomeBatch( command += "/runSalome_" ; command += FileNameToExecute ; command += "_Batch.sh" ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); RmTmpFile(); END_OF("SALOME_ResourcesManager::BuildCmdrunSalomeBatch"); @@ -686,8 +703,10 @@ std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch( const std::string& machine, const long NumberOfProcessors, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) { + const std::string& FileNameToExecute ) throw(SALOME_Exception) +{ BEGIN_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch"); + int status; _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); @@ -726,7 +745,10 @@ std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch( command += "/" ; command += FileNameToExecute ; command += "_Batch.sh" ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); RmTmpFile(); END_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch"); @@ -747,9 +769,11 @@ std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch( std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub( const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) { + const std::string& FileNameToExecute ) throw(SALOME_Exception) +{ BEGIN_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub"); _TmpFileName = BuildTemporaryFileName(); + int status; ofstream tempOutputFile; tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); const ParserResourcesType& resInfo = _resourcesList[machine]; @@ -784,7 +808,11 @@ std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub( command += "/" ; command += FileNameToExecute ; command += "_bsub.sh" ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); + RmTmpFile(); END_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub"); @@ -801,11 +829,13 @@ std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub( std::string SALOME_ResourcesManager::CmdToExecute_bsub( const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) { + const std::string& FileNameToExecute ) throw(SALOME_Exception) +{ BEGIN_OF("SALOME_ResourcesManager::CmdToExecute_bsub"); const ParserResourcesType& resInfo = _resourcesList[machine]; string command; - resInfo.Print() ; + resInfo.Print(); + int status; if (resInfo.Protocol == rsh) command = "rsh " ; @@ -823,7 +853,11 @@ std::string SALOME_ResourcesManager::CmdToExecute_bsub( command += "/" ; command += FileNameToExecute ; command += "_bsub.sh\"" ; - system(command.c_str()); + SCRUTE(command.c_str()); + status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of connection on remote host"); + END_OF("SALOME_ResourcesManager::CmdToExecute_bsub"); return command; @@ -1123,8 +1157,10 @@ string SALOME_ResourcesManager::BuildTemporaryFileName() const string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer (const string& machine, - const Engines::MachineParameters& params) + const Engines::MachineParameters& params) throw(SALOME_Exception) { + int status; + _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); @@ -1198,7 +1234,7 @@ SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer commandRcp += machine; commandRcp += ":"; commandRcp += _TmpFileName; - system(commandRcp.c_str()); + status = system(commandRcp.c_str()); } else if (resInfo.Protocol == ssh) @@ -1210,11 +1246,14 @@ SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer commandRcp += machine; commandRcp += ":"; commandRcp += _TmpFileName; - system(commandRcp.c_str()); + status = system(commandRcp.c_str()); } else throw SALOME_Exception("Unknown protocol"); + if(status) + throw SALOME_Exception("Error of connection on remote host"); + command += machine; _CommandForRemAccess = command; command += " "; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index b4a8e5cb1..952e40092 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -79,20 +79,20 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager void CopyFileNamesToExecute(const std::string& machine, const std::string& DirForTmpFiles , const std::string& PathFileNameToExecute , - const Engines::FilesToExportList& filesToExport) ; + const Engines::FilesToExportList& filesToExport) throw(SALOME_Exception); std::string BuildCmdrunSalomeBatch(const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) ; + const std::string& FileNameToExecute ) throw(SALOME_Exception); std::string BuildCmdFileNameToExecute_Batch(const std::string& machine, const long NumberOfProcessors, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) ; + const std::string& FileNameToExecute ) throw(SALOME_Exception); std::string BuildCmdFileNameToExecute_bsub(const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) ; + const std::string& FileNameToExecute ) throw(SALOME_Exception); std::string CmdToExecute_bsub(const std::string& machine, const std::string& DirForTmpFiles , - const std::string& FileNameToExecute ) ; + const std::string& FileNameToExecute ) throw(SALOME_Exception); std::string BuildCommandToLaunchLocalContainer (const Engines::MachineParameters& params, const long id); @@ -126,7 +126,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager std::string BuildTempFileToLaunchRemoteContainer (const std::string& machine, - const Engines::MachineParameters& params); + const Engines::MachineParameters& params) throw(SALOME_Exception); void SelectOnlyResourcesWithOS(std::vector& hosts, const char *OS) const diff --git a/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx b/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx index 31c486f7b..ec1db4708 100644 --- a/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx +++ b/src/SALOMEDS/SALOMEDS_StudyManager_i.hxx @@ -145,6 +145,8 @@ public: virtual CORBA::LongLong GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal); static PortableServer::POA_ptr GetPOA(const SALOMEDS::Study_ptr theStudy); + + void Shutdown() { _orb->shutdown(0); return; } }; #endif -- 2.39.2