From: Anthony Geay Date: Thu, 14 Sep 2023 13:32:01 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=15b247b9f78d11b7afeb1ce8eac68840ef753116;p=modules%2Fkernel.git WIP --- diff --git a/src/GenericObj/SALOME_GenericObj_i.cc b/src/GenericObj/SALOME_GenericObj_i.cc index 5d14412b6..5a5c7d888 100644 --- a/src/GenericObj/SALOME_GenericObj_i.cc +++ b/src/GenericObj/SALOME_GenericObj_i.cc @@ -73,8 +73,6 @@ namespace SALOME */ GenericObj_i::GenericObj_i(PortableServer::POA_ptr thePOA): myRefCounter(1) { - MESSAGE("GenericObj_i::GenericObj_i() - this = " << this << - "; CORBA::is_nil(thePOA) = " << CORBA::is_nil(thePOA)); if(CORBA::is_nil(thePOA)) { #ifndef WIN32 @@ -86,8 +84,6 @@ namespace SALOME else { myPOA = PortableServer::POA::_duplicate(thePOA); } - - MESSAGE("GenericObj_i::GenericObj_i thePOA: " << thePOA << " myPOA: " << myPOA); } /*! @@ -100,7 +96,6 @@ namespace SALOME */ PortableServer::POA_ptr GenericObj_i::_default_POA() { - MESSAGE("GenericObj_i::_default_POA: " << myPOA); return PortableServer::POA::_duplicate(myPOA); } diff --git a/src/Launcher/KernelLauncher.cxx b/src/Launcher/KernelLauncher.cxx index d66cb99de..5ed46f83c 100644 --- a/src/Launcher/KernelLauncher.cxx +++ b/src/Launcher/KernelLauncher.cxx @@ -28,6 +28,20 @@ #include "SALOME_CPythonHelper.hxx" #include +#include + +std::string RetrieveInternalInstanceOfLocalCppResourcesManager() +{ + SALOME_Launcher *launcher = KERNEL::getLauncherSA(); + SALOME_ResourcesManager *rm(launcher->getResourcesManager()); + if(rm) + { + std::shared_ptr *ret1(new std::shared_ptr(rm->GetImpl())); + std::ostringstream oss; oss << ret1; + return oss.str(); + } + return std::string(); +} std::string GetContainerManagerInstance() { diff --git a/src/Launcher/KernelLauncher.hxx b/src/Launcher/KernelLauncher.hxx index 9963f0bb3..d7f8c880e 100644 --- a/src/Launcher/KernelLauncher.hxx +++ b/src/Launcher/KernelLauncher.hxx @@ -21,6 +21,7 @@ #include +std::string RetrieveInternalInstanceOfLocalCppResourcesManager(); std::string GetContainerManagerInstance(); std::string GetResourcesManagerInstance(); std::string GetExternalServerInstance(); diff --git a/src/Launcher/KernelLauncher.i b/src/Launcher/KernelLauncher.i index 2e40c1f5d..7a97e9a11 100644 --- a/src/Launcher/KernelLauncher.i +++ b/src/Launcher/KernelLauncher.i @@ -27,6 +27,7 @@ %inline { + std::string RetrieveInternalInstanceOfLocalCppResourcesManager(); std::string GetContainerManagerInstance(); std::string GetResourcesManagerInstance(); std::string GetExternalServerInstance(); diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index bcb084953..188cc5e3e 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -80,6 +80,8 @@ public: void DeclareUsingSalomeSession(); + SALOME_ResourcesManager *getResourcesManager() const { return _ResManager; } + static const char *_LauncherNameInNS; static JobParameters_cpp diff --git a/src/Launcher_SWIG/Launcher.i b/src/Launcher_SWIG/Launcher.i index 72913846d..b3c3401aa 100644 --- a/src/Launcher_SWIG/Launcher.i +++ b/src/Launcher_SWIG/Launcher.i @@ -23,6 +23,8 @@ #include "Launcher.hxx" #include "ResourcesManager.hxx" +#include + struct ResourceDefinition_cpp { public: @@ -44,6 +46,17 @@ public: bool can_run_containers; std::string working_directory; }; + +std::shared_ptr HandleToLocalInstance(const std::string& ptrInStringFrmt) +{ + std::istringstream iss(ptrInStringFrmt); + void *zePtr(nullptr); + iss >> zePtr; + std::shared_ptr *effPtr = reinterpret_cast *>(zePtr); + std::shared_ptr ret(*effPtr); + delete effPtr; + return ret; +} %} %include "std_string.i" @@ -159,6 +172,8 @@ class ResourcesManager_cpp public: ResourcesManager_cpp(const char *xmlFilePath); std::vector GetFittingResources(const resourceParams& params); + void WriteInXmlFile(std::string xml_file); + %extend { ResourceDefinition_cpp GetResourceDefinition(const std::string& name) @@ -186,9 +201,56 @@ public: return swig_result; } + + void DeleteResourceInCatalog(const std::string& name) + { + $self->DeleteResourceInCatalog(name.c_str()); + } + + void AddResourceInCatalog (const ResourceDefinition_cpp& new_resource) + { + ParserResourcesType new_resource_cpp; + new_resource_cpp.Name = new_resource.name; + new_resource_cpp.HostName = new_resource.hostname; + new_resource_cpp.setResourceTypeStr( new_resource.type ); + new_resource_cpp.setAccessProtocolTypeStr( new_resource.protocol ); + new_resource_cpp.UserName = new_resource.username; + new_resource_cpp.AppliPath = new_resource.applipath; + new_resource_cpp.OS = new_resource.OS; + new_resource_cpp.DataForSort._memInMB = new_resource.mem_mb; + new_resource_cpp.DataForSort._CPUFreqMHz = new_resource.cpu_clock; + new_resource_cpp.DataForSort._nbOfNodes = new_resource.nb_node; + new_resource_cpp.DataForSort._nbOfProcPerNode = new_resource.nb_proc_per_node; + new_resource_cpp.setBatchTypeStr(new_resource.batch); + new_resource_cpp.setMpiImplTypeStr(new_resource.mpiImpl); + new_resource_cpp.setClusterInternalProtocolStr(new_resource.iprotocol); + new_resource_cpp.can_launch_batch_jobs = new_resource.can_launch_batch_jobs; + new_resource_cpp.can_run_containers = new_resource.can_run_containers; + new_resource_cpp.working_directory = new_resource.working_directory; + $self->AddResourceInCatalog(new_resource_cpp); + } + + void ParseXmlFiles() + { + $self->ParseXmlFiles(); + } + + std::vector GetListOfEntries() const + { + const MapOfParserResourcesType& allRes = $self->GetList(); + std::vector ret; + for(auto it : allRes) + ret.push_back(it.first); + return ret; + } } }; +%inline +{ + std::shared_ptr HandleToLocalInstance(const std::string& ptrInStringFrmt); +} + %exception { try @@ -229,3 +291,54 @@ public: long createJobWithFile(std::string xmlExecuteFile, std::string clusterName); void SetResourcesManager(std::shared_ptr& rm ); }; + +%pythoncode %{ +def CreateSSHContainerResource(hostname,applipath,nbOfNodes=1): + return CreateContainerResource(hostname,applipath,"ssh",nbOfNodes) + +def CreateSRUNContainerResource(hostname,applipath,nbOfNodes=1): + return CreateContainerResource(hostname,applipath,"srun",nbOfNodes) + +def CreateContainerResource(hostname,applipath,protocol,nbOfNodes=1): + import getpass + ret = ResourceDefinition_cpp() + ret.name = hostname.split(".")[0] + ret.hostname = ret.name + ret.protocol = protocol + ret.applipath = applipath + ret.nb_node = nbOfNodes + ret.nb_proc_per_node = 1 + ret.can_run_containers = True + ret.can_launch_batch_jobs = False + ret.mpiImpl = "no mpi" + ret.iprotocol = protocol + ret.type = "single_machine" + ret.username = getpass.getuser() + return ret + +def ResourceDefinition_cpp_repr(self): + pat0 = "{} = {}" + pat1 = "{} = \"{}\"" + data = [("name","name",pat0), + ("hostname","hostname",pat0), + ("type","type",pat0), + ("protocol","protocol",pat0), + ("userName","username",pat0), + ("appliPath","applipath",pat1), + ("mpi","mpiImpl",pat0), + ("nbOfNodes","nb_node",pat0), + ("nbOfProcPerNode","nb_proc_per_node",pat0), + ("canRunContainer","can_run_containers",pat0) + ] + ret = [c.format(a,getattr(self,b)) for a,b,c in data] + return "\n".join( ret ) + +def ResourcesManager_cpp_GetList(self): + return {name:self.GetResourceDefinition(name) for name in self.GetListOfEntries()} + + +ResourceDefinition_cpp.repr = ResourceDefinition_cpp_repr +ResourceDefinition_cpp.__repr__ = ResourceDefinition_cpp_repr +ResourcesManager_cpp.GetList = ResourcesManager_cpp_GetList + +%}