From 27b7d56b2dbc348d4de099da1eb6b1782273f753 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 13 Sep 2023 14:42:24 +0200 Subject: [PATCH] WIP --- idl/SALOME_ContainerManager.idl | 10 ++++ src/Container/SALOME_ContainerManager.cxx | 57 ++++++++++++++++++++--- src/Container/SALOME_ContainerManager.hxx | 14 ++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index f4de98ae1..207b0ed9f 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -89,6 +89,16 @@ interface ContainerManager //! Shutdown all containers that have been launched by the container manager void ShutdownContainers(); + long GetTimeOutToLaunchServerInSecond(); + + void SetTimeOutToLaunchServerInSecond(in long timeInSecond); + + long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(); + + void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(in long timeInMS); + + void MakeThisProcessAServer() raises (SALOME::SALOME_Exception); + void SetOverrideEnvForContainers(in KeyValDict env); KeyValDict GetOverrideEnvForContainers(); diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index ee251440d..23788a1fd 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include CORBA_CLIENT_HEADER(SALOME_Session) @@ -66,8 +68,9 @@ const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60; -const char *SALOME_ContainerManager::_ContainerManagerNameInNS = - "/ContainerManager"; +const int SALOME_ContainerManager::DFT_DELTA_TIME_NS_LOOKUP_IN_MS=1000; + +const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager"; omni_mutex SALOME_ContainerManager::_numInstanceMutex; @@ -85,11 +88,12 @@ Utils_Mutex SALOME_ContainerManager::_systemMutex; //============================================================================= SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns) - : _nbprocUsed(1) + : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS) { MESSAGE("constructor"); _NS = ns; _resManager = new SALOME_ResourcesManager_Client(ns); + _time_out_in_second = GetTimeOutToLoaunchServer(); PortableServer::POAManager_var pman = poa->the_POAManager(); _orb = CORBA::ORB::_duplicate(orb) ; @@ -203,6 +207,41 @@ void SALOME_ContainerManager::Shutdown() _poa->deactivate_object(oid); } +CORBA::Long SALOME_ContainerManager::GetTimeOutToLaunchServerInSecond() +{ + return this->_time_out_in_second; +} + +void SALOME_ContainerManager::SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) +{ + this->_time_out_in_second = timeInSecond; +} + +CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() +{ + return this->_delta_time_ns_lookup_in_ms; +} + +void SALOME_ContainerManager::SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) +{ + this->_delta_time_ns_lookup_in_ms = timeInMS; +} + +/*! + * Launch a this->_orb->run() in order to respond to CORBA requests from the outside. + */ +void SALOME_ContainerManager::MakeThisProcessAServer() +{ + if(_server_thread_launched) + { + THROW_SALOME_CORBA_EXCEPTION("orb.run() thread has already been launched. You are not supposed to launch it more than once",SALOME::BAD_PARAM); + } + _server_thread_launched = true; + auto ORBRunLauncher = [](CORBA::ORB_var orb) { MESSAGE("[SALOME_ContainerManager::MakeThisProcessAServer] ORB is running in a thread ...."); orb->run(); }; + std::thread t(ORBRunLauncher,this->_orb); + t.detach(); +} + //============================================================================= //! Loop on all the containers listed in naming service, ask shutdown on each /*! CORBA Method: @@ -670,11 +709,13 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par else { // Step 4: Wait for the container - int count(GetTimeOutToLoaunchServer()); - INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS); + double nbTurn = ( (double)this->_time_out_in_second ) * ( 1000.0 / ( (double) this->_delta_time_ns_lookup_in_ms) ); + int count( (int)nbTurn ); + INFOS("[GiveContainer] # attempts : " << count << " name in NS : \"" << containerNameInNS << "\""); + INFOS("[GiveContainer] # attempts : Time in second before time out : " << this->_time_out_in_second << " Delta time in ms between NS lookup : " << this->_delta_time_ns_lookup_in_ms); while (CORBA::is_nil(ret) && count) { - SleepInSecond(1); + std::this_thread::sleep_for(std::chrono::milliseconds(_delta_time_ns_lookup_in_ms)); count--; MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected << " with entry in NS = \"" << containerNameInNS << "\"" ); CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str())); @@ -1154,6 +1195,10 @@ void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& comma #endif } +/*! + * Return in second the time out to give chance to server to be launched and + * to register into NS + */ int SALOME_ContainerManager::GetTimeOutToLoaunchServer() { int count(TIME_OUT_TO_LAUNCH_CONT); diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 1e458769f..5f8388e51 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -61,6 +61,16 @@ public: void DeclareUsingSalomeSession() { _isSSL = false; } + CORBA::Long GetTimeOutToLaunchServerInSecond() override; + + void SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond) override; + + CORBA::Long GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond() override; + + void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override; + + void MakeThisProcessAServer(); + static const char *_ContainerManagerNameInNS; protected: @@ -197,9 +207,13 @@ public: static void SleepInSecond(int ellapseTimeInSecond); private: static const int TIME_OUT_TO_LAUNCH_CONT; + static const int DFT_DELTA_TIME_NS_LOOKUP_IN_MS; static Utils_Mutex _getenvMutex; static Utils_Mutex _systemMutex; private: std::vector< std::pair > _override_env; + int _time_out_in_second; + int _delta_time_ns_lookup_in_ms; + bool _server_thread_launched = false; }; #endif -- 2.39.2