]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[EDF28648] : On container launch time from ContainerManager it s possible to execute...
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 27 Sep 2023 11:54:41 +0000 (13:54 +0200)
committerNabil Ghodbane <nabil.ghodbane@cea.fr>
Mon, 2 Oct 2023 11:03:59 +0000 (13:03 +0200)
idl/SALOME_Component.idl
idl/SALOME_ContainerManager.idl
src/Container/Container_i.cxx
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerManager.hxx
src/Container/SALOME_Container_i.hxx
src/Launcher_SWIG/Launcher.i

index 11a21e1cc5627db3e7a65f7730f641886e255701..2e3b662f49efe032a164fd8ed4369463e88bfd7c 100644 (file)
@@ -84,6 +84,8 @@ module Engines
 
     FieldsDict get_os_environment();
 
+    void execute_python_code( in string code ) raises(SALOME::SALOME_Exception);
+
     /*! \brief Loads a new component class (dynamic library).
 
       \param componentName like COMPONENT, (Python or C++ implementation)
index 9251df6ab82ea1f3022d1eb6e3bb27f540d4e907..474d51642a6adde5eededc1542a2ea0ce5b85c96 100644 (file)
@@ -100,6 +100,8 @@ interface ContainerManager
   void SetOverrideEnvForContainers(in KeyValDict env);
 
   KeyValDict GetOverrideEnvForContainers();
+
+  void SetCodeOnContainerStartUp(in string code);
 } ;
 
 };
index 8e740c5a87ca5bb46091374ff1cbc7cfe3b7ce15..dd8ea1843ca8ccf9a506bbab6000ffa51ccf04fa 100644 (file)
@@ -32,6 +32,7 @@
 #include <time.h>
 #include <sys/types.h>
 #include <memory>
+#include <vector>
 #ifndef WIN32
 #include <sys/time.h>
 #include <dlfcn.h>
@@ -63,6 +64,7 @@ int SIGUSR1 = 1000;
 #include "SALOME_Embedded_NamingService.hxx"
 #include "Basics_Utils.hxx"
 #include "PythonCppUtils.hxx"
+#include "Utils_CorbaException.hxx"
 
 #ifdef _XOPEN_SOURCE
 #undef _XOPEN_SOURCE
@@ -1090,6 +1092,16 @@ Engines::FieldsDict *Abstract_Engines_Container_i::get_os_environment()
   return ret.release();
 }
 
+void Abstract_Engines_Container_i::execute_python_code(const char *code)
+{
+  AutoGIL gstate;
+  if( PyRun_SimpleString( code ) != 0 )
+  {
+    std::string error = parseException();
+    THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR);
+  }
+}
+
 //=============================================================================
 //! Create a new component instance with environment variables specified
 /*! 
@@ -2330,9 +2342,24 @@ Engines_Container_SSL_i *KERNEL::getContainerSA()
     CORBA::PolicyList policies;
     policies.length(0);
     //
-    char *argv[4] = {"Container","FactoryServer","toto",nullptr};
+    constexpr int ARGC = 4;
+    constexpr const char *ARGV[ARGC] = {"Container","FactoryServer","toto",nullptr};
+    std::unique_ptr<char*[]> argv( new char *[ARGC+1] );
+    std::vector< std::unique_ptr<char[]> > argvv(ARGC);
+    argv[ARGC] = nullptr;
+    for(int i = 0 ; i < ARGC ; ++i)
+    {
+      if(ARGV[i])
+      {
+        argvv[i].reset( new char[strlen(ARGV[i])+1] );
+        strcpy(argvv[i].get(),ARGV[i]);
+        argv[i] = argvv[i].get();
+      }
+      else
+        argv[i] = nullptr;
+    }
     SALOME_Fake_NamingService ns;
-    _container_singleton_ssl = new Engines_Container_SSL_i(orb,poa,"FactoryServer",2,argv,&ns,false);
+    _container_singleton_ssl = new Engines_Container_SSL_i(orb,poa,(char *)"FactoryServer",2,argv.get(),&ns,false);
     PortableServer::ObjectId * cont_id = _container_singleton_ssl->getCORBAId();
     //
     CORBA::Object_var zeRef = poa->id_to_reference(*cont_id);
index b8ad494e2982ecf9dbdb9bcf8e6a50f679684dc6..84480b4e6999a820fb07309db22799562fcbe39b 100644 (file)
@@ -324,6 +324,11 @@ Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
   return ret.release();
 }
 
+void SALOME_ContainerManager::SetCodeOnContainerStartUp(const char *code)
+{
+  _code_to_exe_on_startup = code;
+}
+
 //=============================================================================
 //! Give a suitable Container given constraints
 /*! CORBA Method:
@@ -498,6 +503,8 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
           }
         }
         cont->override_environment_python( envCorba );
+        if( !_code_to_exe_on_startup.empty() )
+          cont->execute_python_code( _code_to_exe_on_startup.c_str() );
         return cont._retn();
       }
       else
index 67a333482df2c55960b76f931a2f8c2a22d09737..b579d5c3dd1dccc53f3153930b3a3684b05135f4 100644 (file)
@@ -56,6 +56,8 @@ public:
 
   Engines::KeyValDict *GetOverrideEnvForContainers() override;
 
+  void SetCodeOnContainerStartUp(const char *code) override;
+
   // C++ Methods
   void Shutdown();
 
@@ -212,5 +214,6 @@ private:
   std::vector< std::pair<std::string, std::string> > _override_env;
   int _time_out_in_second;
   int _delta_time_ns_lookup_in_ms;
+  std::string _code_to_exe_on_startup;
 };
 #endif
index f68b9652c91611ae2742ed986a39b020d4d18973..ca2fac0a354aeb7b477a68bdfbbb6c61f4e2714a 100644 (file)
@@ -77,6 +77,8 @@ public:
   void override_environment( const Engines::FieldsDict& env ) override;
 
   Engines::FieldsDict *get_os_environment() override;
+  
+  void execute_python_code(const char *code) override;
 
   virtual Engines::EngineComponent_ptr
   create_component_instance_env(const char *componentName,
index f01e3126ef67d510a5fa39349e0600e93dbe067d..2681d2dbed2751d123ff93c5b4f11a01ee00c0d7 100644 (file)
@@ -365,6 +365,32 @@ def BuildCatalogFromScratch(protocol):
       contRes = CreateContainerResource(hostname=k,applipath=os.environ["APPLI"],protocol=protocol,nbOfNodes=v)
       rmcpp.AddResourceInCatalog(contRes)
 
+def GetRequestForGiveContainer(hostname, contName):
+  import Engines
+  import os
+  rp=Engines.ResourceParameters(name=hostname,
+                                hostname=hostname,
+                                can_launch_batch_jobs=False,
+                                can_run_containers=True,
+                                OS="Linux",
+                                componentList=[],
+                                nb_proc=1,
+                                mem_mb=1000,
+                                cpu_clock=1000,
+                                nb_node=1,
+                                nb_proc_per_node=1,
+                                policy="first",
+                                resList=[])
+
+  cp=Engines.ContainerParameters(container_name=contName,
+                                  mode="start",
+                                  workingdir=os.path.expanduser("~"),
+                                  nb_proc=1,
+                                  isMPI=False,
+                                  parallelLib="",
+                                  resource_params=rp)
+  return cp
+
 ResourceDefinition_cpp.repr = ResourceDefinition_cpp_repr
 ResourceDefinition_cpp.__repr__ = ResourceDefinition_cpp_repr
 ResourcesManager_cpp.GetList = ResourcesManager_cpp_GetList