From: Anthony Geay Date: Tue, 27 Feb 2024 10:50:09 +0000 (+0100) Subject: [EDF29576] : Synchronous Shutdown of containers X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7e173a4e2ddf2befc29e58383137b1e20458abe4;p=modules%2Fkernel.git [EDF29576] : Synchronous Shutdown of containers --- diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index a2a402d5f..b3585af45 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -190,9 +190,12 @@ module Engines void setVerbosity(in boolean activated, in string level); - //! Shutdown the Container process. + //! Shutdown the Container process. Shutdown is not immediate. It waits for all remaining invokation completion. void Shutdown(); + //! Shutdown the Container process. Shutdown is immediate for this method. + void ShutdownNow(); + //! Returns the hostname of the container string getHostName(); diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index be92c24c0..d06c3c06b 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -86,8 +86,11 @@ interface ContainerManager //! Currently: get, start, getorstart, findorstart, find Container GiveContainer(in ContainerParameters params) raises (SALOME::SALOME_Exception); - //! Shutdown all containers that have been launched by the container manager + //! Shutdown all containers that have been launched by the container manager. This termination is soft. It means that orb.shutdown is invoked meaning that completion of all CORBA void ShutdownContainers(); + + //! Stronger version than ShutdownContainers. This method does not wait for completion of last CORBA invokation on containers. It terminates them + void ShutdownContainersNow(); long GetTimeOutToLaunchServerInSecond(); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 547ce7f40..0ad306bb0 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -156,7 +156,7 @@ Abstract_Engines_Container_i::Abstract_Engines_Container_i (CORBA::ORB_ptr orb, { _pid = (long)getpid(); - if(ns) + if( isServantAloneInProcess ) ActSigIntHandler() ; _argc = argc ; @@ -708,6 +708,24 @@ CORBA::Long Abstract_Engines_Container_i::getTotalPhysicalMemoryInUseByMe() */ //============================================================================= void Abstract_Engines_Container_i::Shutdown() +{ + ShutdownCommonPart(); + if(_isServantAloneInProcess) + { + MESSAGE("Effective Shutdown of container Begins..."); + try + { + if(!CORBA::is_nil(_orb)) + _orb->shutdown(0); + } + catch(...) + { + } + MESSAGE("Effective Shutdown of container Ends..."); + } +} + +void Abstract_Engines_Container_i::ShutdownCommonPart() { MESSAGE("Engines_Container_i::Shutdown()"); @@ -759,12 +777,14 @@ void Abstract_Engines_Container_i::Shutdown() { } MESSAGE("Engines_Container_i::Shutdown() -- step 4"); - // - if(_isServantAloneInProcess) +} + +void Abstract_Engines_Container_i::ShutdownNow() +{ + ShutdownCommonPart();if(_isServantAloneInProcess) { - MESSAGE("Effective Shutdown of container Begins..."); - if(!CORBA::is_nil(_orb)) - _orb->shutdown(0); + AutoGIL gstate; + AutoPyRef result = PyObject_CallMethod(_pyCont, (char*)"killMe", (char*)"",nullptr); } } diff --git a/src/Container/SALOME_Container.py b/src/Container/SALOME_Container.py index 1fa1d41d0..66113499a 100644 --- a/src/Container/SALOME_Container.py +++ b/src/Container/SALOME_Container.py @@ -186,6 +186,10 @@ class SALOME_Container_i: #self._log.destroy()# TODO : choose to destroy perf report or not. For the moment we keep the report pass + def killMe(self): + import signal + os.kill( os.getpid() , signal.SIGTERM) + def setLogFileName(self, logFileName): logging.debug("setLogFileName {} PID = {}".format(logFileName,os.getpid())) if getSSLMode(): diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index d3d36bb70..66cd8fd09 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -241,9 +241,9 @@ void SALOME_ContainerManager::SetDeltaTimeBetweenCPUMemMeasureInMilliSecond(CORB */ //============================================================================= -void SALOME_ContainerManager::ShutdownContainers() +void SALOME_ContainerManager::ShutdownContainersGeneric(std::function funcToBeCalledOnContainer) { - MESSAGE("ShutdownContainers"); + MESSAGE("ShutdownContainersGeneric"); if(!_NS) return ; SALOME::Session_var session = SALOME::Session::_nil(); @@ -289,11 +289,12 @@ void SALOME_ContainerManager::ShutdownContainers() Engines::Container_var cont=Engines::Container::_narrow(obj); if(!CORBA::is_nil(cont)) { - MESSAGE("ShutdownContainers: " << (*iter)); - cont->Shutdown(); + MESSAGE("ShutdownContainersGeneric: " << (*iter)); + funcToBeCalledOnContainer( cont ); + MESSAGE("ShutdownContainersGeneric: after call of shutdown" << (*iter)); } else - MESSAGE("ShutdownContainers: no container ref for " << (*iter)); + MESSAGE("ShutdownContainersGeneric: no container ref for " << (*iter)); } catch(CORBA::SystemException& e) { @@ -311,6 +312,26 @@ void SALOME_ContainerManager::ShutdownContainers() } } +void SALOME_ContainerManager::ShutdownContainers() +{ + this->ShutdownContainersGeneric( [](Engines::Container_ptr cont) { cont->Shutdown(); } ); +} + +void SALOME_ContainerManager::ShutdownContainersNow() +{ + this->ShutdownContainersGeneric( [](Engines::Container_ptr cont) + { + try + { + cont->ShutdownNow(); + } + catch(...) + { + } + } + ); +} + void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env) { this->_override_env.clear(); diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index c1d33f9bf..330d3ed7c 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -35,6 +35,7 @@ #include #include #include +#include #include class SALOME_NamingService_Abstract; @@ -52,6 +53,8 @@ public: void ShutdownContainers() override; + void ShutdownContainersNow() override; + void SetOverrideEnvForContainers(const Engines::KeyValDict& env) override; Engines::KeyValDict *GetOverrideEnvForContainers() override; @@ -77,6 +80,10 @@ public: static const char *_ContainerManagerNameInNS; +private: + + void ShutdownContainersGeneric(std::function funcToBeCalledOnContainer); + protected: // C++ methods Engines::Container_ptr diff --git a/src/Container/SALOME_Container_SignalsHandler.cxx b/src/Container/SALOME_Container_SignalsHandler.cxx index f3539d41a..55b548428 100644 --- a/src/Container/SALOME_Container_SignalsHandler.cxx +++ b/src/Container/SALOME_Container_SignalsHandler.cxx @@ -39,6 +39,7 @@ void HandleServerSideSignals(CORBA::ORB_ptr theORB) // CASCatch_SignalsHandler aSignalsHandler; try { theORB->run(); + INFOS("ORB run finished..."); // CCRT porting // }catch(CORBA::SystemException&){ // Handle(Standard_Failure) aFail = Standard_Failure::Caught(); diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index a86c22af2..9f67a52ce 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -124,7 +124,8 @@ public: void verbosity(bool& activated, CORBA::String_out level) override; void setVerbosity(bool activated, const char *level) override; - virtual void Shutdown(); + void Shutdown() override; + void ShutdownNow() override; char *getHostName(); CORBA::Long getPID(); //! Kill current container @@ -170,6 +171,8 @@ public: PortableServer::ObjectId *getCORBAId() const { return _id; } public: static const int DFT_TIME_INTERVAL_BTW_MEASURE; +private: + void ShutdownCommonPart(); protected: static std::map _cntInstances_map; static std::map _library_map; // library names, loaded