From: barate Date: Tue, 22 Jan 2013 13:10:13 +0000 (+0000) Subject: Changes for ResourceManager default resource: X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1eedb8f016d804270d2c358f209218945b5e84ab;p=modules%2Fkernel.git Changes for ResourceManager default resource: - File CatalogResources.xml is no more generated by appli_gen.py. - The default resource "localhost" is always generated by the ResourceManager. It can't be edited or deleted. - This default resource can be used for local batch jobs. --- diff --git a/bin/appli_gen.py b/bin/appli_gen.py index 648656c83..b627b5649 100644 --- a/bin/appli_gen.py +++ b/bin/appli_gen.py @@ -270,17 +270,6 @@ export MMGT_REENTRANT=1 f.write(command % ",".join(mods)) f.close() - #Add default CatalogResources.xml file - f =open(os.path.join(home_dir,'CatalogResources.xml'),'w') - command=""" - - - -""" - f.write(command) - f.close() - #Add USERS directory with 777 permission to store users configuration files users_dir=os.path.join(home_dir,'USERS') makedirs(users_dir) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index b15f357f7..d209ef71d 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -273,7 +273,7 @@ interface ResourcesManager ResourceList GetFittingResources(in ResourceParameters params) raises (SALOME::SALOME_Exception); //! Get definition of a resource - ResourceDefinition GetResourceDefinition(in string name); + ResourceDefinition GetResourceDefinition(in string name) raises (SALOME::SALOME_Exception); //! Add a new resource to the resource_manager /*! diff --git a/src/Launcher/Launcher.cxx b/src/Launcher/Launcher.cxx index 29538c893..986ec6703 100644 --- a/src/Launcher/Launcher.cxx +++ b/src/Launcher/Launcher.cxx @@ -372,6 +372,9 @@ Launcher_cpp::FactoryBatchManager(ParserResourcesType& params) switch(params.Protocol) { + case sh: + protocol = Batch::SH; + break; case rsh: protocol = Batch::RSH; break; diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 6d138af19..eb35541bc 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -234,7 +234,7 @@ FindOrLoad_Component(const Engines::MachineParameters& params, if (std::string(new_params.resource_params.hostname.in()) == "localhost") { new_params.resource_params.hostname = CORBA::string_dup(Kernel_Utils::GetHostname().c_str()); - new_params.resource_params.name = CORBA::string_dup(Kernel_Utils::GetHostname().c_str()); + new_params.resource_params.name = CORBA::string_dup("localhost"); } Engines::ResourceList_var listOfResources; diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index 23d8e781e..2426cfcc8 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -38,8 +38,14 @@ #include +#include "Utils_SALOME_Exception.hxx" + #define MAX_SIZE_FOR_HOSTNAME 256; +using namespace std; + +const string ResourcesManager_cpp::DEFAULT_RESOURCE_NAME = "localhost"; + static LoadRateManagerFirst first; static LoadRateManagerCycl cycl; static LoadRateManagerAltCycl altcycl; @@ -61,6 +67,8 @@ ResourcesManager_cpp(const char *xmlFilePath) _resourceManagerMap["altcycl"]=&altcycl; _resourceManagerMap["best"]=&altcycl; _resourceManagerMap[""]=&altcycl; + + AddDefaultResourceInCatalog(); } //============================================================================= @@ -84,6 +92,8 @@ ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException) _resourceManagerMap["best"]=&altcycl; _resourceManagerMap[""]=&altcycl; + AddDefaultResourceInCatalog(); + bool default_catalog_resource = true; if (getenv("USER_CATALOG_RESOURCES_FILE") != 0) { @@ -266,7 +276,7 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re // Step 5 SelectOnlyResourcesWithOS(vec, params.OS.c_str()); - + // Step 6 std::vector vec_save(vec); KeepOnlyResourcesWithComponent(vec, params.componentList); @@ -291,8 +301,11 @@ ResourcesManager_cpp::GetFittingResources(const resourceParams& params) throw(Re //============================================================================= void -ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) throw(ResourcesException) +ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resource) { + if (new_resource.Name == DEFAULT_RESOURCE_NAME) + throw SALOME_Exception((string("Cannot modify default local resource \"") + + DEFAULT_RESOURCE_NAME + "\"").c_str()); // TODO - Add minimal check _resourcesList[new_resource.Name] = new_resource; } @@ -305,6 +318,9 @@ ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resou void ResourcesManager_cpp::DeleteResourceInCatalog(const char * name) { + if (DEFAULT_RESOURCE_NAME == name) + throw SALOME_Exception((string("Cannot delete default local resource \"") + + DEFAULT_RESOURCE_NAME + "\"").c_str()); MapOfParserResourcesType_it it = _resourcesList.find(name); if (it != _resourcesList.end()) _resourcesList.erase(name); @@ -322,6 +338,16 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file) { RES_MESSAGE("WriteInXmlFile : start"); + MapOfParserResourcesType resourceListToSave(_resourcesList); + // We do not save default local resource because it is automatically created at startup + resourceListToSave.erase(DEFAULT_RESOURCE_NAME); + if (resourceListToSave.empty()) + { + RES_MESSAGE("WriteInXmlFile: nothing to do, no resource except default \"" << + DEFAULT_RESOURCE_NAME << "\""); + return; + } + if (xml_file == "") { _path_resources_it = _path_resources.begin(); @@ -341,7 +367,7 @@ void ResourcesManager_cpp::WriteInXmlFile(std::string xml_file) xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog"); SALOME_ResourcesCatalog_Handler* handler = - new SALOME_ResourcesCatalog_Handler(_resourcesList); + new SALOME_ResourcesCatalog_Handler(resourceListToSave); handler->PrepareDocToXmlFile(aDoc); delete handler; @@ -371,7 +397,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles() int result = stat((*_path_resources_it).c_str(), &statinfo); if (result < 0) { - std::cerr << "Error in method stat for file : " << (*_path_resources_it).c_str() << " no new xml file is parsed" << std::endl; + RES_MESSAGE("Resource file " << *_path_resources_it << " does not exist"); return _resourcesList; } @@ -385,6 +411,7 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles() if (to_parse) { _resourcesList.clear(); + AddDefaultResourceInCatalog(); // On parse tous les fichiers for(_path_resources_it = _path_resources.begin(); _path_resources_it != _path_resources.end(); ++_path_resources_it) { @@ -406,13 +433,19 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFiles() for (MapOfParserResourcesType_it i = _resourcesList_tmp.begin(); i != _resourcesList_tmp.end(); ++i) { MapOfParserResourcesType_it j = _resourcesList.find(i->first); - if (j == _resourcesList.end()) + if (i->second.HostName == "localhost" || i->second.HostName == Kernel_Utils::GetHostname()) { - _resourcesList[i->first] = i->second; + RES_MESSAGE("Resource " << i->first << " is not added because it is the same " + "machine as default local resource \"" << DEFAULT_RESOURCE_NAME << "\""); + } + else if (j != _resourcesList.end()) + { + cerr << "ParseXmlFiles Warning, two resources with the same name were found, " + "taking the first declaration : " << i->first << endl; } else { - std::cerr << "ParseXmlFiles Warning, two resources with the same name were found, taking the first declaration : " << i->first << std::endl; + _resourcesList[i->first] = i->second; } } } @@ -525,3 +558,22 @@ ResourcesManager_cpp::GetResourcesDescr(const std::string & name) throw ResourcesException(error); } } + +void ResourcesManager_cpp::AddDefaultResourceInCatalog() +{ + ParserResourcesType resource; + resource.Clear(); + resource.Name = DEFAULT_RESOURCE_NAME; + // We can't use "localhost" for parameter hostname because the containers are registered in the + // naming service with the real hostname, not "localhost" + resource.HostName = Kernel_Utils::GetHostname(); + resource.DataForSort._Name = DEFAULT_RESOURCE_NAME; + resource.Protocol = sh; + resource.Batch = ssh_batch; + if (getenv("HOME") != NULL && getenv("APPLI") != NULL) + { + resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI"); + } + resource.working_directory = "/tmp/salome_localres_workdir"; + _resourcesList[resource.Name] = resource; +} diff --git a/src/ResourcesManager/ResourcesManager.hxx b/src/ResourcesManager/ResourcesManager.hxx index a85f68497..8b55d205b 100644 --- a/src/ResourcesManager/ResourcesManager.hxx +++ b/src/ResourcesManager/ResourcesManager.hxx @@ -87,7 +87,7 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp std::string Find(const std::string& policy, const std::vector& listOfResources); - void AddResourceInCatalog (const ParserResourcesType & new_resource) throw(ResourcesException); + void AddResourceInCatalog (const ParserResourcesType & new_resource); void DeleteResourceInCatalog(const char * name); @@ -106,6 +106,11 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp void KeepOnlyResourcesWithComponent(std::vector& resources, const std::vector& componentList); + /** + * Add the default local resource in the catalog + */ + void AddDefaultResourceInCatalog(); + //! will contain the path to the ressources catalog std::list _path_resources; std::list::iterator _path_resources_it; @@ -118,6 +123,9 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp //! contain the time where resourcesList was created time_t _lasttime; + + //! the name of the default local resource + static const std::string DEFAULT_RESOURCE_NAME; }; #endif // __RESOURCESMANAGER_HXX__ diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index ae42569dd..e548b3613 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -107,13 +107,6 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) // Empty private elements _resources_list.clear(); - //default resources - _resource.Clear(); - _resource.HostName = Kernel_Utils::GetHostname(); - _resource.Name = Kernel_Utils::GetHostname(); - _resource.DataForSort._Name = Kernel_Utils::GetHostname(); - _resources_list[Kernel_Utils::GetHostname()] = _resource; - // Get the document root node xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx index 9cf3cfa99..5412c670d 100644 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -134,6 +134,8 @@ std::string ParserResourcesType::protocolToString(AccessProtocolType protocol) { switch (protocol) { + case sh: + return "sh"; case rsh: return "rsh"; case ssh: @@ -151,7 +153,9 @@ std::string ParserResourcesType::protocolToString(AccessProtocolType protocol) AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr) { - if (protocolStr == "rsh") + if (protocolStr == "sh") + return sh; + else if (protocolStr == "rsh") return rsh; else if (protocolStr == "ssh") return ssh; diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx index 1ac87b340..a0d437318 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -41,7 +41,7 @@ #pragma warning(disable:4251) // Warning DLL Interface ... #endif -enum AccessProtocolType {rsh, ssh, srun, pbsdsh, blaunch}; +enum AccessProtocolType {sh, rsh, ssh, srun, pbsdsh, blaunch}; enum AccessModeType {interactive, batch}; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 30a1c1b44..a96731b02 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -46,6 +46,8 @@ #define MAX_SIZE_FOR_HOSTNAME 256; +using namespace std; + const char *SALOME_ResourcesManager::_ResourcesManagerNameInNS = "/ResourcesManager"; //============================================================================= @@ -209,57 +211,63 @@ SALOME_ResourcesManager::Find(const char* policy, const Engines::ResourceList& l Engines::ResourceDefinition* SALOME_ResourcesManager::GetResourceDefinition(const char * name) { - ParserResourcesType resource = _rm.GetResourcesDescr(name); - Engines::ResourceDefinition *p_ptr = new Engines::ResourceDefinition; - - p_ptr->name = CORBA::string_dup(resource.Name.c_str()); - p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str()); - p_ptr->protocol = ParserResourcesType::protocolToString(resource.Protocol).c_str(); - p_ptr->iprotocol = ParserResourcesType::protocolToString(resource.ClusterInternalProtocol).c_str(); - p_ptr->username = CORBA::string_dup(resource.UserName.c_str()); - p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str()); - p_ptr->componentList.length(resource.ComponentsList.size()); - for(unsigned int i=0;icomponentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str()); - p_ptr->OS = CORBA::string_dup(resource.OS.c_str()); - p_ptr->mem_mb = resource.DataForSort._memInMB; - p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz; - p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode; - p_ptr->nb_node = resource.DataForSort._nbOfNodes; - p_ptr->is_cluster_head = resource.is_cluster_head; - p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str()); - - if( resource.mpi == lam ) - p_ptr->mpiImpl = "lam"; - else if( resource.mpi == mpich1 ) - p_ptr->mpiImpl = "mpich1"; - else if( resource.mpi == mpich2 ) - p_ptr->mpiImpl = "mpich2"; - else if( resource.mpi == openmpi ) - p_ptr->mpiImpl = "openmpi"; - else if( resource.mpi == ompi ) - p_ptr->mpiImpl = "ompi"; - else if( resource.mpi == slurmmpi ) - p_ptr->mpiImpl = "slurmmpi"; - else if( resource.mpi == prun ) - p_ptr->mpiImpl = "prun"; - - if( resource.Batch == pbs ) - p_ptr->batch = "pbs"; - else if( resource.Batch == lsf ) - p_ptr->batch = "lsf"; - else if( resource.Batch == sge ) - p_ptr->batch = "sge"; - else if( resource.Batch == ccc ) - p_ptr->batch = "ccc"; - else if( resource.Batch == slurm ) - p_ptr->batch = "slurm"; - else if( resource.Batch == ssh_batch ) - p_ptr->batch = "ssh"; - else if( resource.Batch == ll ) - p_ptr->batch = "ll"; - else if( resource.Batch == vishnu ) - p_ptr->batch = "vishnu"; + Engines::ResourceDefinition * p_ptr = NULL; + try { + ParserResourcesType resource = _rm.GetResourcesDescr(name); + p_ptr = new Engines::ResourceDefinition; + + p_ptr->name = CORBA::string_dup(resource.Name.c_str()); + p_ptr->hostname = CORBA::string_dup(resource.HostName.c_str()); + p_ptr->protocol = ParserResourcesType::protocolToString(resource.Protocol).c_str(); + p_ptr->iprotocol = ParserResourcesType::protocolToString(resource.ClusterInternalProtocol).c_str(); + p_ptr->username = CORBA::string_dup(resource.UserName.c_str()); + p_ptr->applipath = CORBA::string_dup(resource.AppliPath.c_str()); + p_ptr->componentList.length(resource.ComponentsList.size()); + for(unsigned int i=0;icomponentList[i] = CORBA::string_dup(resource.ComponentsList[i].c_str()); + p_ptr->OS = CORBA::string_dup(resource.OS.c_str()); + p_ptr->mem_mb = resource.DataForSort._memInMB; + p_ptr->cpu_clock = resource.DataForSort._CPUFreqMHz; + p_ptr->nb_proc_per_node = resource.DataForSort._nbOfProcPerNode; + p_ptr->nb_node = resource.DataForSort._nbOfNodes; + p_ptr->is_cluster_head = resource.is_cluster_head; + p_ptr->working_directory = CORBA::string_dup(resource.working_directory.c_str()); + + if( resource.mpi == lam ) + p_ptr->mpiImpl = "lam"; + else if( resource.mpi == mpich1 ) + p_ptr->mpiImpl = "mpich1"; + else if( resource.mpi == mpich2 ) + p_ptr->mpiImpl = "mpich2"; + else if( resource.mpi == openmpi ) + p_ptr->mpiImpl = "openmpi"; + else if( resource.mpi == ompi ) + p_ptr->mpiImpl = "ompi"; + else if( resource.mpi == slurmmpi ) + p_ptr->mpiImpl = "slurmmpi"; + else if( resource.mpi == prun ) + p_ptr->mpiImpl = "prun"; + + if( resource.Batch == pbs ) + p_ptr->batch = "pbs"; + else if( resource.Batch == lsf ) + p_ptr->batch = "lsf"; + else if( resource.Batch == sge ) + p_ptr->batch = "sge"; + else if( resource.Batch == ccc ) + p_ptr->batch = "ccc"; + else if( resource.Batch == slurm ) + p_ptr->batch = "slurm"; + else if( resource.Batch == ssh_batch ) + p_ptr->batch = "ssh"; + else if( resource.Batch == ll ) + p_ptr->batch = "ll"; + else if( resource.Batch == vishnu ) + p_ptr->batch = "vishnu"; + } catch (const exception & ex) { + INFOS("Caught exception in GetResourceDefinition: " << ex.what()); + THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::BAD_PARAM); + } return p_ptr; } @@ -375,7 +383,15 @@ SALOME_ResourcesManager::AddResource(const Engines::ResourceDefinition& new_reso for (CORBA::ULong i = 0; i < new_resource.componentList.length(); i++) resource.ComponentsList.push_back(new_resource.componentList[i].in()); - _rm.AddResourceInCatalog(resource); + try + { + _rm.AddResourceInCatalog(resource); + } + catch (const SALOME_Exception & e) + { + INFOS("Error in AddResourceInCatalog: " << e); + THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM); + } if (write) { @@ -389,7 +405,16 @@ SALOME_ResourcesManager::RemoveResource(const char * resource_name, CORBA::Boolean write, const char * xml_file) { - _rm.DeleteResourceInCatalog(resource_name); + try + { + _rm.DeleteResourceInCatalog(resource_name); + } + catch (const SALOME_Exception & e) + { + INFOS("Error in DeleteResourceInCatalog: " << e); + THROW_SALOME_CORBA_EXCEPTION(e.what(), SALOME::BAD_PARAM); + } + if (write) { _rm.WriteInXmlFile(std::string(xml_file));