From: Anthony Geay Date: Wed, 10 Jan 2024 09:39:48 +0000 (+0100) Subject: [EDF29150] : Ease access to the NamingService for external monitoring X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=68a16dd609d75245c2d11dfb029bc19fe78f6400;p=modules%2Fkernel.git [EDF29150] : Ease access to the NamingService for external monitoring --- diff --git a/idl/SALOME_Embedded_NamingService.idl b/idl/SALOME_Embedded_NamingService.idl index 89a1fc1e3..91fa6dda4 100644 --- a/idl/SALOME_Embedded_NamingService.idl +++ b/idl/SALOME_Embedded_NamingService.idl @@ -23,6 +23,7 @@ module Engines { typedef sequence IORType; + typedef sequence NSListOfStrings; interface EmbeddedNamingService { @@ -31,6 +32,7 @@ module Engines void Destroy_Name(in string Path); IORType Resolve(in string Path); IORType ResolveFirst(in string Path); + NSListOfStrings keys(); }; }; diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 1aad69516..81f53a391 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -273,6 +273,7 @@ def salome_init_without_session(path=None, embedded=False, iorfakensfile=None): type(logm).DumpInFile = LogManagerDumpInFile type(logm).LaunchMonitoringDumpFile = LogManagerLaunchMonitoringDumpFile type(logm).GetLatestMonitoringDumpFile = LogManagerGetLatestMonitoringDumpFile + type(logm).DumpIORInFile = LogManagerDumpIORInFile # import KernelLogger naming_service.Register(KernelLogger.myLogger(),"/Logger") @@ -537,6 +538,11 @@ while(True): pid = KernelBasis.LaunchMonitoring( tempPyFile ) return SALOME_PyNode.MonitoringInfo(pyFileName,None,pid) +def LogManagerDumpIORInFile(self, iorFileName): + global logm + with open(iorFileName,"w") as f: + f.write( orb.object_to_string( logm ) ) + def LogManagerLoadFromFile(fileName): from SALOME_ContainerHelper import unserializeLogManager with open(fileName,"rb") as f: diff --git a/src/Launcher/KernelLauncher.cxx b/src/Launcher/KernelLauncher.cxx index f7939f4bb..7abd1411a 100644 --- a/src/Launcher/KernelLauncher.cxx +++ b/src/Launcher/KernelLauncher.cxx @@ -32,6 +32,7 @@ #include static Engines::LogManager_var LogManagerInstanceSingleton; +static SALOME::ExternalServerLauncher_var ExternalServerLauncherSingleton; std::string RetrieveInternalInstanceOfLocalCppResourcesManager() { @@ -69,20 +70,23 @@ std::string GetResourcesManagerInstance() std::string GetExternalServerInstance() { CORBA::ORB_ptr orb = KERNEL::getORB(); - CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); - PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); - // - PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true); - // - SALOME_CPythonHelper *cPyh(SALOME_CPythonHelper::Singleton()); - SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService; - SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(cPyh,orb,safePOA,ns)); - esm->_remove_ref(); - // - CORBA::Object_var esmPtr = safePOA->servant_to_reference(esm); - SALOME::ExternalServerLauncher_var esmCPtr = SALOME::ExternalServerLauncher::_narrow(esmPtr); + if( CORBA::is_nil(ExternalServerLauncherSingleton) ) + { + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); + // + PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true); + // + SALOME_CPythonHelper *cPyh(SALOME_CPythonHelper::Singleton()); + SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService; + SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(cPyh,orb,safePOA,ns)); + esm->_remove_ref(); + // + CORBA::Object_var esmPtr = safePOA->servant_to_reference(esm); + ExternalServerLauncherSingleton = SALOME::ExternalServerLauncher::_narrow(esmPtr); + } // - CORBA::String_var ior = orb->object_to_string(esmCPtr); + CORBA::String_var ior = orb->object_to_string(ExternalServerLauncherSingleton); return std::string(ior.in()); } diff --git a/src/Launcher/Test/testPerfLogManager1.py b/src/Launcher/Test/testPerfLogManager1.py index df06f726b..7a387a658 100644 --- a/src/Launcher/Test/testPerfLogManager1.py +++ b/src/Launcher/Test/testPerfLogManager1.py @@ -58,7 +58,7 @@ def unProxyfy( objs ): return ret, fileNamesProxyOut class testPerfLogManager1(unittest.TestCase): - def testPerfLogManager0(self): + def tessPerfLogManager0(self): """ [EDF29150] : This test checks measure performance methods """ @@ -70,6 +70,8 @@ class testPerfLogManager1(unittest.TestCase): monitoringFile = os.path.join( str( tmpdirnameMonitoring ), "zeHtop.pckl" ) monitoringFileTwo = os.path.join( str( tmpdirnameMonitoring ), "zeHtopTwo.pckl" ) iorLogm = os.path.join( str( tmpdirnameMonitoring ), "logm.ior" ) + with open(iorLogm,"w") as f: + f.write( salome.orb.object_to_string(salome.logm) ) logging.debug("Monitoring file : {}".format(monitoringFile)) with tempfile.TemporaryDirectory() as tmpdirname: with salome.LogManagerLaunchMonitoringFileCtxMgr(250,monitoringFile) as monitoringParams: @@ -161,6 +163,7 @@ time.sleep(1) logging.debug( logManagerInst0[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important logManagerInst = salome.logm.Fetch(True) logManagerInst2 = salome.logm.Fetch(True) + logging.debug( salome.LogManagerLoadFromIORFile( iorLogm )[0][1][0].get() ) salome.logm.putStructInFileAtomic(False,monitoringFileTwo) logging.debug( salome.LogManagerLoadFromFile(monitoringFileTwo)[0][1][0].get() ) logging.debug( logManagerInst[0][1][0].get()._input_hdd_mem._data[1]._data[0]._data[0]._hdd_mem ) # important @@ -179,6 +182,34 @@ time.sleep(1) self.assertFalse( os.path.exists(pyFileContainingCodeOfMonitoring) ) cont.Shutdown() + def testEasyNamingService(self): + """ + [EDF29150] : This test checks measure performance methods + """ + hostname = "localhost" + cp = pylauncher.GetRequestForGiveContainer(hostname,"container_test_two") + PROXY_THRES = "1" + with tempfile.TemporaryDirectory() as tmpdirname: + ior_ns_file = os.path.join(tmpdirname,"ns.ior") + val_for_big_obj = str( tmpdirname ) + salome.cm.SetOverrideEnvForContainersSimple(env = [("SALOME_FILE_BIG_OBJ_DIR",val_for_big_obj),("SALOME_BIG_OBJ_ON_DISK_THRES",PROXY_THRES)]) + salome.cm.SetDeltaTimeBetweenCPUMemMeasureInMilliSecond( 250 ) + salome.naming_service.DumpIORInFile( ior_ns_file ) + cont = salome.cm.GiveContainer(cp) + script_st = """ +from SALOME_Embedded_NamingService_ClientPy import SALOME_Embedded_NamingService_ClientPy +ior_ns_file = "{ior_ns_file}" +ns = SALOME_Embedded_NamingService_ClientPy.BuildFromIORFile( ior_ns_file ) +ret = ns.repr() +""".format(**locals()) + cont = salome.cm.GiveContainer(cp) + pyscript2 = cont.createPyScriptNode("testScript3",script_st) + retCoarse = pickle.loads( pyscript2.execute( ["ret"], pickle.dumps( ([],{} ) ) ) ) + ret = retCoarse[0] + self.assertTrue( isinstance(ret,list) and isinstance(ret[0],str) ) + cont.Shutdown() + pass + if __name__ == '__main__': from salome_utils import positionVerbosityOfLoggerRegardingState,setVerboseLevel,setVerbose salome.standalone() diff --git a/src/NamingService/NamingService.i b/src/NamingService/NamingService.i index 8515746f3..197315f2a 100644 --- a/src/NamingService/NamingService.i +++ b/src/NamingService/NamingService.i @@ -137,6 +137,10 @@ def NamingService_RefOfNS(cls): orb=CORBA.ORB_init(['']) return orb.string_to_object(ret) NamingService.RefOfNS = classmethod(NamingService_RefOfNS) +def NamingService_DumpIORInFile(cls,iorFileName): + with open( iorFileName, "w" ) as f: + f.write( cls.IOROfNS() ) +NamingService.DumpIORInFile = classmethod(NamingService_DumpIORInFile) def NamingService_KillContainersInFile(cls,logFileName): import Engines import CORBA diff --git a/src/NamingService/SALOME_Embedded_NamingService.cxx b/src/NamingService/SALOME_Embedded_NamingService.cxx index 22390efec..ab6080da6 100644 --- a/src/NamingService/SALOME_Embedded_NamingService.cxx +++ b/src/NamingService/SALOME_Embedded_NamingService.cxx @@ -69,3 +69,15 @@ Engines::IORType *SALOME_Embedded_NamingService::ResolveFirst(const char *Path) CORBA::Object_var obj = ns.ResolveFirst(Path); return ObjectToIOR(obj); } + +Engines::NSListOfStrings *SALOME_Embedded_NamingService::keys() +{ + SALOME_Fake_NamingService ns; + std::vector ks = ns.repr(); + Engines::NSListOfStrings *ret = new Engines::NSListOfStrings; + std::size_t sz(ks.size()); + ret->length( sz ); + for(std::size_t i = 0 ; i < sz ; ++i) + (*ret)[i] = CORBA::string_dup( ks[i].c_str() ); + return ret; +} diff --git a/src/NamingService/SALOME_Embedded_NamingService.hxx b/src/NamingService/SALOME_Embedded_NamingService.hxx index 0a8d3dfd5..0d5c2cafa 100644 --- a/src/NamingService/SALOME_Embedded_NamingService.hxx +++ b/src/NamingService/SALOME_Embedded_NamingService.hxx @@ -34,4 +34,5 @@ public: void Destroy_Name(const char *Path) override; Engines::IORType *Resolve(const char *Path) override; Engines::IORType *ResolveFirst(const char *Path) override; + Engines::NSListOfStrings *keys() override; }; diff --git a/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py b/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py index da482e9a3..686abb48e 100644 --- a/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py +++ b/src/NamingService/SALOME_Embedded_NamingService_ClientPy.py @@ -28,7 +28,7 @@ class SALOME_Embedded_NamingService_ClientPy: #------------------------------------------------------------------------- def __init__(self, serv): - self._orb=CORBA.ORB_init([''], CORBA.ORB_ID) + self._orb = CORBA.ORB_init([''], CORBA.ORB_ID) self._obj = serv #------------------------------------------------------------------------- @@ -41,3 +41,19 @@ class SALOME_Embedded_NamingService_ClientPy: def Resolve(self, Path): ret = self._obj.Resolve(Path) return self._orb.string_to_object(ret.decode()) + + def keys(self): + return self._obj.keys() + + def repr(self): + return self.keys() + +def SALOME_Embedded_NamingService_ClientPy_BuildFromIORFile(cls, iorNSFile): + import Engines + orb = CORBA.ORB_init([''], CORBA.ORB_ID) + with open(iorNSFile,"r") as f: + ior = f.read() + serv = orb.string_to_object( ior ) + return SALOME_Embedded_NamingService_ClientPy(serv) + +SALOME_Embedded_NamingService_ClientPy.BuildFromIORFile = classmethod(SALOME_Embedded_NamingService_ClientPy_BuildFromIORFile)