]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF29150] : Ease access to the NamingService for external monitoring
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 10 Jan 2024 09:39:48 +0000 (10:39 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 10 Jan 2024 09:39:48 +0000 (10:39 +0100)
idl/SALOME_Embedded_NamingService.idl
src/KERNEL_PY/__init__.py
src/Launcher/KernelLauncher.cxx
src/Launcher/Test/testPerfLogManager1.py
src/NamingService/NamingService.i
src/NamingService/SALOME_Embedded_NamingService.cxx
src/NamingService/SALOME_Embedded_NamingService.hxx
src/NamingService/SALOME_Embedded_NamingService_ClientPy.py

index 89a1fc1e3830ca188eec39d340553577ff76bf55..91fa6dda4816ed0d859d448dc2181a50ccca9fa7 100644 (file)
@@ -23,6 +23,7 @@
 module Engines
 {
   typedef sequence<octet> IORType;
+  typedef sequence<string> 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();
   };
 };
 
index 1aad6951641fd56bc766eedd68164dc873fa93a4..81f53a391a6289c0be1e2c13ef472325015082a1 100644 (file)
@@ -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:
index f7939f4bb9eebbc56d2c989f3976acda11316e0c..7abd1411a21b1c3cced709ccc6364dd24426bf83 100644 (file)
@@ -32,6 +32,7 @@
 #include <sstream>
 
 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());
 }
 
index df06f726baa7f000bc5ad0fbc9fb65188e0a00ff..7a387a658e95138a0c2f791c0db33db24f2f249f 100644 (file)
@@ -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()
index 8515746f3a157229977aa1bb70d08630a5954150..197315f2a20e29c4bb72ba2f2468a9c946de4b30 100644 (file)
@@ -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
index 22390efec2318e20c7731c6b0883fcb90d181b40..ab6080da6875dab465f749d1bee4db4cdbff885b 100644 (file)
@@ -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<std::string> 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;
+}
index 0a8d3dfd5b338248414d13adfb9e3111bb0db084..0d5c2cafacd1bd304808e694448ff436e8044f9d 100644 (file)
@@ -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;
 };
index da482e9a35b4b6aba2ed667f8058c1f9b5a579f5..686abb48e22b64ea94698cf061b2766be157ab2a 100644 (file)
@@ -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)