From 0b73a4e698c6804e985bdee149b1fc7ed43c972e Mon Sep 17 00:00:00 2001 From: ribes Date: Wed, 20 Jan 2010 16:05:16 +0000 Subject: [PATCH] - Adding a new method to SALOME_ResourceManager: //! Add a new resource to the resource_manager /*! write -> true, resource manager will add it into a xml_file xml_file -> could be empty, in this case if write is true, resource manager will write the resource in its first ResourceCatalog file */ void AddResourceDefinition(in ResourceDefinition new_resource, in boolean write, in string xml_file) raises (SALOME::SALOME_Exception); --- idl/SALOME_ContainerManager.idl | 11 ++ src/ResourcesManager/ResourcesManager.cxx | 49 +++----- src/ResourcesManager/ResourcesManager.hxx | 9 +- .../SALOME_ResourcesCatalog_Handler.cxx | 20 +++- .../SALOME_ResourcesManager.cxx | 109 ++++++++++++++++++ .../SALOME_ResourcesManager.hxx | 3 + 6 files changed, 153 insertions(+), 48 deletions(-) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 66d51d569..dff835faf 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -125,6 +125,8 @@ struct ResourceDefinition string applipath; //! list of available components CompoList componentList; + //! Type of resource: interactive or batch + string mode; //! operating system string OS; @@ -239,6 +241,15 @@ interface ResourcesManager //! Get definition of a resource ResourceDefinition GetResourceDefinition(in string name); + + //! Add a new resource to the resource_manager + /*! + write -> true, resource manager will add it into a xml_file + xml_file -> could be empty, in this case if write is true, resource manager will write + the resource in its first ResourceCatalog file + */ + void AddResourceDefinition(in ResourceDefinition new_resource, in boolean write, in string xml_file) + raises (SALOME::SALOME_Exception); }; diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index fe92bda97..6a100a4c6 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -258,44 +258,15 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re //============================================================================= /*! - * add an entry in the ressources catalog xml file. - * Return 0 if OK (KERNEL found in new resources components) else throw exception + * add an entry in the ressources catalog xml file. */ //============================================================================= -int -ResourcesManager_cpp::AddResourceInCatalog(const resourceParams& paramsOfNewResources, - const vector& componentsOnNewResources, - const char *userName, - AccessModeType mode, - AccessProtocolType prot, - AccessProtocolType iprot) throw(ResourcesException) +void +ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException) { - vector::const_iterator iter = find(componentsOnNewResources.begin(), - componentsOnNewResources.end(), - "KERNEL"); - - if (iter != componentsOnNewResources.end()) - { - ParserResourcesType newElt; - newElt.DataForSort._Name = paramsOfNewResources.name; - newElt.HostName = paramsOfNewResources.hostname; - newElt.Protocol = prot; - newElt.ClusterInternalProtocol = iprot; - newElt.Mode = mode; - newElt.UserName = userName; - newElt.ComponentsList = componentsOnNewResources; - newElt.OS = paramsOfNewResources.OS; - newElt.DataForSort._memInMB = paramsOfNewResources.mem_mb; - newElt.DataForSort._CPUFreqMHz = paramsOfNewResources.cpu_clock; - newElt.DataForSort._nbOfNodes = paramsOfNewResources.nb_node; - newElt.DataForSort._nbOfProcPerNode = - paramsOfNewResources.nb_proc_per_node; - _resourcesList[newElt.DataForSort._Name] = newElt; - return 0; - } - else - throw ResourcesException("KERNEL is not present in this resource"); + // TODO - Add minimal check + _resourcesList[new_resource.Name] = new_resource; } //============================================================================= @@ -315,10 +286,16 @@ void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name) */ //============================================================================= -void ResourcesManager_cpp::WriteInXmlFile(std::string & xml_file) +void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file) { RES_MESSAGE("WriteInXmlFile : start"); + if (xml_file == "") + { + _path_resources_it = _path_resources.begin(); + xml_file = *_path_resources_it; + } + const char* aFilePath = xml_file.c_str(); FILE* aFile = fopen(aFilePath, "w"); @@ -336,7 +313,7 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string & xml_file) handler->PrepareDocToXmlFile(aDoc); delete handler; - int isOk = xmlSaveFile(aFilePath, aDoc); + int isOk = xmlSaveFormatFile(aFilePath, aDoc, 1); if (!isOk) std::cerr << "Error while XML file saving : " << xml_file << std::endl; diff --git a/src/ResourcesManager/ResourcesManager.hxx b/src/ResourcesManager/ResourcesManager.hxx index 9d1e42921..1afcf69a5 100644 --- a/src/ResourcesManager/ResourcesManager.hxx +++ b/src/ResourcesManager/ResourcesManager.hxx @@ -81,16 +81,11 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp std::string Find(const std::string& policy, const std::vector& listOfResources); - int AddResourceInCatalog (const resourceParams& paramsOfNewResources, - const std::vector& componentsOnNewResources, - const char *userName, - AccessModeType mode, - AccessProtocolType prot, - AccessProtocolType iprot) throw(ResourcesException); + void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException); void DeleteResourceInCatalog(const char * name); - void WriteInXmlFile(std::string & xml_file); + void WriteInXmlFile(std::string xml_file); const MapOfParserResourcesType& ParseXmlFiles(); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index 2cf3e8b72..f33f830a6 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -28,6 +28,7 @@ #include "SALOME_ResourcesCatalog_Handler.hxx" #include "Basics_Utils.hxx" #include +#include #include using namespace std; @@ -657,7 +658,6 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc) { // Node pointers xmlNodePtr root_node = NULL, node = NULL, node1 = NULL; - char string_buf[80]; root_node = xmlNewNode(NULL, BAD_CAST "resources"); xmlDocSetRootElement(theDoc, root_node); @@ -666,8 +666,10 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc) for (; iter != _resources_list.end(); iter++) { node = xmlNewChild(root_node, NULL, BAD_CAST test_machine, NULL); + RES_MESSAGE("Add resource name = " << (*iter).second.Name.c_str()); xmlNewProp(node, BAD_CAST test_name, BAD_CAST (*iter).second.Name.c_str()); xmlNewProp(node, BAD_CAST test_hostname, BAD_CAST (*iter).second.HostName.c_str()); + xmlNewProp(node, BAD_CAST test_appli_path, BAD_CAST (*iter).second.AppliPath.c_str()); xmlNewProp(node, BAD_CAST test_batch_queue, BAD_CAST (*iter).second.batchQueue.c_str()); xmlNewProp(node, BAD_CAST test_user_commands, BAD_CAST (*iter).second.userCommands.c_str()); @@ -759,9 +761,17 @@ void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(xmlDocPtr theDoc) } xmlNewProp(node, BAD_CAST test_os, BAD_CAST (*iter).second.OS.c_str()); - xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._memInMB)); - xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._CPUFreqMHz)); - xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfNodes)); - xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST sprintf(string_buf, "%u", (*iter).second.DataForSort._nbOfProcPerNode)); + std::ostringstream mem_stream; + mem_stream << (*iter).second.DataForSort._memInMB; + xmlNewProp(node, BAD_CAST test_mem_in_mb, BAD_CAST mem_stream.str().c_str()); + std::ostringstream cpu_stream; + cpu_stream << (*iter).second.DataForSort._CPUFreqMHz; + xmlNewProp(node, BAD_CAST test_cpu_freq_mhz, BAD_CAST cpu_stream.str().c_str()); + std::ostringstream nb_nodes_stream; + nb_nodes_stream << (*iter).second.DataForSort._nbOfNodes; + xmlNewProp(node, BAD_CAST test_nb_of_nodes, BAD_CAST nb_nodes_stream.str().c_str()); + std::ostringstream nb_proc_per_nodes_stream; + nb_proc_per_nodes_stream << (*iter).second.DataForSort._nbOfProcPerNode; + xmlNewProp(node, BAD_CAST test_nb_of_proc_per_node, BAD_CAST nb_proc_per_nodes_stream.str().c_str()); } } diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index a84eca4d1..74973d463 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -259,6 +259,115 @@ SALOME_ResourcesManager::GetResourceDefinition(const char * name) return p_ptr; } +void +SALOME_ResourcesManager::AddResourceDefinition(const Engines::ResourceDefinition& new_resource, + CORBA::Boolean write, + const char * xml_file) +{ + ParserResourcesType resource; + resource.Name = new_resource.name.in(); + resource.HostName = new_resource.hostname.in(); + resource.OS = new_resource.OS.in(); + resource.DataForSort._memInMB = new_resource.mem_mb; + resource.DataForSort._CPUFreqMHz = new_resource.cpu_clock; + resource.DataForSort._nbOfNodes = new_resource.nb_node; + resource.DataForSort._nbOfProcPerNode = new_resource.nb_proc_per_node; + resource.UserName = new_resource.username.in(); + + std::string aBatch = new_resource.batch.in(); + if (aBatch == "pbs") + resource.Batch = pbs; + else if (aBatch == "lsf") + resource.Batch = lsf; + else if (aBatch == "sge") + resource.Batch = sge; + else if (aBatch == "ssh_batch") + resource.Batch = ssh_batch; + else if (aBatch == "") + resource.Batch = none; + else { + INFOS("Bad Batch definition in AddResourceDefinition: " << aBatch); + std::string message("Bad Batch definition in AddResourceDefinition: "); + message += aBatch; + THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM); + } + + std::string anMpi = new_resource.mpiImpl.in(); + if (anMpi == "lam") + resource.mpi = lam; + else if (anMpi == "mpich1") + resource.mpi = mpich1; + else if (anMpi == "mpich2") + resource.mpi = mpich2; + else if (anMpi == "openmpi") + resource.mpi = openmpi; + else if (anMpi == "slurm") + resource.mpi = slurm; + else if (anMpi == "prun") + resource.mpi = prun; + else if (anMpi == "") + resource.mpi = nompi; + else { + INFOS("Bad MPI definition in AddResourceDefinition: " << anMpi); + std::string message("Bad MPI definition in AddResourceDefinition: "); + message += anMpi; + THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM); + } + + std::string mode_str = new_resource.mode.in(); + if (mode_str == "interactive") + resource.Mode = interactive; + else if (mode_str == "batch") + resource.Mode = batch; + else if (mode_str == "") + resource.Mode = interactive; + else { + INFOS("Bad mode definition in AddResourceDefinition: " << mode_str); + std::string message("Bad mode definition in AddResourceDefinition: "); + message += mode_str; + THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM); + } + + std::string protocol = new_resource.protocol.in(); + if (protocol == "rsh") + resource.Protocol = rsh; + else if (protocol == "ssh") + resource.Protocol = ssh; + else if (protocol == "") + resource.Protocol = rsh; + else { + INFOS("Bad protocol definition in AddResourceDefinition: " << protocol); + std::string message("Bad protocol definition in AddResourceDefinition: "); + message += protocol; + THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM); + } + + std::string iprotocol = new_resource.iprotocol.in(); + if (iprotocol == "rsh") + resource.ClusterInternalProtocol = rsh; + else if (iprotocol == "ssh") + resource.ClusterInternalProtocol = ssh; + else if (iprotocol == "") + resource.ClusterInternalProtocol = rsh; + else { + INFOS("Bad iprotocol definition in AddResourceDefinition: " << iprotocol); + std::string message("Bad iprotocol definition in AddResourceDefinition: "); + message += iprotocol; + THROW_SALOME_CORBA_EXCEPTION(message.c_str(),SALOME::BAD_PARAM); + } + + for (CORBA::ULong i = 0; i < new_resource.componentList.length(); i++) + resource.ComponentsList.push_back(new_resource.componentList[i].in()); + + _rm.AddResourceInCatalog(resource); + + if (write) + { + _rm.WriteInXmlFile(std::string(xml_file)); + _rm.ParseXmlFiles(); + } +} + std::string SALOME_ResourcesManager::getMachineFile(std::string hostname, CORBA::Long nb_procs, diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 5fd4e7145..38fa9eff2 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -68,6 +68,9 @@ class SALOMERESOURCESMANAGER_EXPORT SALOME_ResourcesManager: char* FindFirst(const Engines::ResourceList& listOfResources); char* Find(const char *policy, const Engines::ResourceList& listOfResources); Engines::ResourceDefinition * GetResourceDefinition(const char * name); + void AddResourceDefinition(const Engines::ResourceDefinition& new_resource, + CORBA::Boolean write, + const char * xml_file); // Cpp Methods void Shutdown(); -- 2.39.2