From d5242d0a4cc928a69e546340ce725673bf85b90a Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Wed, 5 Jun 2024 13:27:15 +0200 Subject: [PATCH] [EDF29150] : Put additionnal fault tolerant mecanism --- idl/SALOME_Component.idl | 4 ++++ src/Container/Container_i.cxx | 10 ++++++++++ src/Container/SALOME_ContainerManager.cxx | 1 + src/Container/SALOME_Container_i.hxx | 5 +++++ src/Container/SALOME_PyNode.py | 6 +++++- src/Launcher/Test/testCrashProofContainer.py | 5 +++-- 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index 2d7d3ea5b..8911badd9 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -92,6 +92,10 @@ module Engines void set_number_of_retry(in long nbRetry); + void set_startup_code(in string codeAtStartUp); + + string get_startup_code(); + void addLogFileNameGroup(in vectorOfString groupOfLogFileNames); vectorOfVectorOfString getAllLogFileNameGroups(); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 4e0d5fe93..4841ee2a0 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -1185,6 +1185,16 @@ void Abstract_Engines_Container_i::set_number_of_retry(CORBA::Long nbRetry) SALOME::SetNumberOfRetry( nbRetry ); } +void Abstract_Engines_Container_i::set_startup_code(const char *codeAtStartUp) +{ + _code_at_startup = codeAtStartUp; +} + +char *Abstract_Engines_Container_i::get_startup_code() +{ + return CORBA::string_dup( this->_code_at_startup.c_str() ); +} + Engines::vectorOfString_var FromVecStringCppToCORBA( const std::vector& group) { Engines::vectorOfString_var ret( new Engines::vectorOfString ); diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 2ee5639bc..4ac6468c8 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -566,6 +566,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con if( !_code_to_exe_on_startup.empty() ) { INFOS("[GiveContainer] container " << containerNameInNS << " python code executed " << _code_to_exe_on_startup); + cont->set_startup_code( _code_to_exe_on_startup.c_str() ); cont->execute_python_code( _code_to_exe_on_startup.c_str() ); } INFOS("[GiveContainer] container " << containerNameInNS << " verbosity positionning Activation = " << SALOME::VerbosityActivated() << " Verbosity Level = " << SALOME::VerbosityLevelStr()); diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 08c174254..b6ace750d 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -87,6 +87,10 @@ public: void set_big_obj_on_disk_directory(const char *directory) override; void set_number_of_retry(CORBA::Long nbRetry) override; + + void set_startup_code(const char *codeAtStartUp) override; + + char *get_startup_code() override; void addLogFileNameGroup(const Engines::vectorOfString& groupOfLogFileNames) override; @@ -202,6 +206,7 @@ protected: std::string _localfilename; std::string _load_script; std::string _py_container_name; + std::string _code_at_startup; CORBA::ORB_var _orb; PortableServer::POA_var _poa; PortableServer::ObjectId *_id; diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 0b0c9b3cd..cb8d1abd2 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -840,7 +840,10 @@ def ExecCrashProofGeneric( code, context, outargsname, containerRef, instanceOfL return True,StdErrTreatment(closeEyesOnErrorAtExit , stderr) if not closeEyesOnErrorAtExit: return False, stderr - return stderr[-len(MY_KEY_TO_DETECT_FINISH):] == MY_KEY_TO_DETECT_FINISH,stderr[:-len(MY_KEY_TO_DETECT_FINISH)] + if stderr[-len(MY_KEY_TO_DETECT_FINISH):] == MY_KEY_TO_DETECT_FINISH: + return True,stderr[:-len(MY_KEY_TO_DETECT_FINISH)] + else: + return False,stderr # def InternalExecResistant( code, context, outargsname): @@ -852,6 +855,7 @@ def ExecCrashProofGeneric( code, context, outargsname, containerRef, instanceOfL def RetrieveUniquePartFromPfx( fname ): return os.path.splitext( os.path.basename(fname)[len(EXEC_CODE_FNAME_PXF):] )[0] with tempfile.NamedTemporaryFile(dir=os.getcwd(),prefix=EXEC_CODE_FNAME_PXF,suffix=".py", mode="w", delete = False) as codeFd: + codeFd.write( "{}\n".format( containerRef.get_startup_code() ) ) codeFd.write( code ) if closeEyesOnErrorAtExit: codeFd.write( """ diff --git a/src/Launcher/Test/testCrashProofContainer.py b/src/Launcher/Test/testCrashProofContainer.py index 0d2a168fe..e494959d4 100644 --- a/src/Launcher/Test/testCrashProofContainer.py +++ b/src/Launcher/Test/testCrashProofContainer.py @@ -63,7 +63,7 @@ def ErrorAtexit(): atexit.register(ErrorAtexit) print("OKKKKKK") -j = 9 * i +j = 9 * i * a print("OKKKKKK3333") """ @@ -179,6 +179,7 @@ class testPerfLogManager1(unittest.TestCase): hostname = "localhost" cp = pylauncher.GetRequestForGiveContainer(hostname,"container_crash_test") salome.cm.SetNumberOfRetry( 3 ) + salome.cm.SetCodeOnContainerStartUp("""a = 2""") salome.cm.SetBigObjOnDiskThreshold(1000) salome.cm.SetOverrideEnvForContainersSimple(env = []) cont = salome.cm.GiveContainer(cp) @@ -188,7 +189,7 @@ class testPerfLogManager1(unittest.TestCase): pyscript.executeFirst(refPtr) ret = pyscript.executeSecond(["j"]) ret = pickle.loads( SALOME_PyNode.SeqByteReceiver(ret[0]).data() ) - self.assertEqual(ret,27) + self.assertEqual(ret,54) with open(cont.locallogfilename) as f: logCont = f.read( ) self.assertTrue( "WARNING : Retry #" in logCont) -- 2.39.2