From: secher Date: Thu, 17 Apr 2008 08:03:49 +0000 (+0000) Subject: create a pure c++ resourcesManager implementation X-Git-Tag: afterMerge_V4_1_3rc1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=570b124b1a86e3fd1fcef9fa30b2342d02c56bee;p=modules%2Fkernel.git create a pure c++ resourcesManager implementation --- diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index a7cbd05da..0ad023f7a 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -83,6 +83,7 @@ COMMON_LIBS =\ ../Registry/libRegistry.la \ ../Notification/libSalomeNotification.la \ ../ResourcesManager/libSalomeResourcesManager.la \ + ../ResourcesManager/libResourcesManager.la \ ../NamingService/libSalomeNS.la \ ../Utils/libOpUtil.la \ ../SALOMELocalTrace/libSALOMELocalTrace.la \ diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index ca9984dd6..36965e71f 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -214,17 +214,21 @@ StartContainer(const Engines::MachineParameters& params, MESSAGE("SALOME_ContainerManager::StartContainer " << possibleComputers.length()); + vector lm; + for(int i=0;iFindFirst(possibleComputers); + theMachine=_ResManager->GetImpl()->FindFirst(lm); break; case Engines::P_CYCL: - theMachine=_ResManager->FindNext(possibleComputers); + theMachine=_ResManager->GetImpl()->FindNext(lm); break; case Engines::P_BEST: - theMachine=_ResManager->FindBest(possibleComputers); + theMachine=_ResManager->GetImpl()->FindBest(lm); break; } } @@ -739,7 +743,7 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer else { - const ParserResourcesType& resInfo = _ResManager->GetResourcesList(machine); + const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine); if (params.isMPI) { @@ -1012,7 +1016,7 @@ SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer _TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); - const ParserResourcesType& resInfo = _ResManager->GetResourcesList(machine); + const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine); tempOutputFile << "#! /bin/sh" << endl; // --- set env vars diff --git a/src/LifeCycleCORBA/TestContainerManager.cxx b/src/LifeCycleCORBA/TestContainerManager.cxx index b908e90f8..c53de4e84 100644 --- a/src/LifeCycleCORBA/TestContainerManager.cxx +++ b/src/LifeCycleCORBA/TestContainerManager.cxx @@ -149,7 +149,7 @@ int main (int argc, char * argv[]) } } string msg; - if( ((cmax-cmin) <= 2) && (fmax == 10/nbpmax) && !error ){ + if( ((cmax-cmin) <= 1) && (fmax == 10/nbpmax) && !error ){ if(bestImplemented) msg = "TEST OK"; else diff --git a/src/ResourcesManager/Makefile.am b/src/ResourcesManager/Makefile.am index dbb5bb380..86eb62538 100755 --- a/src/ResourcesManager/Makefile.am +++ b/src/ResourcesManager/Makefile.am @@ -70,17 +70,26 @@ COMMON_LIBS =\ # Libraries targets # =============================================================== # -lib_LTLIBRARIES = libSalomeResourcesManager.la +lib_LTLIBRARIES = libResourcesManager.la libSalomeResourcesManager.la libSalomeResourcesManager_la_SOURCES =\ - SALOME_ResourcesCatalog_Parser.cxx \ - SALOME_ResourcesCatalog_Handler.cxx \ - SALOME_LoadRateManager.cxx \ SALOME_ResourcesManager.cxx libSalomeResourcesManager_la_CPPFLAGS =\ $(COMMON_CPPFLAGS) - libSalomeResourcesManager_la_LDFLAGS = -no-undefined -version-info=0:0:0 libSalomeResourcesManager_la_LIBADD =\ - $(COMMON_LIBS) + $(COMMON_LIBS) libResourcesManager.la + +libResourcesManager_la_SOURCES =\ + SALOME_ResourcesCatalog_Parser.cxx \ + SALOME_ResourcesCatalog_Handler.cxx \ + SALOME_LoadRateManager.cxx \ + ResourcesManager.cxx + +libResourcesManager_la_CPPFLAGS =\ + @LIBXML_INCLUDES@ + +libResourcesManager_la_LDFLAGS = -no-undefined -version-info=0:0:0 +libResourcesManager_la_LIBADD =\ + @LIBXML_LIBS@ diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx new file mode 100644 index 000000000..b5226b18e --- /dev/null +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -0,0 +1,479 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "ResourcesManager.hxx" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_SIZE_FOR_HOSTNAME 256; + +using namespace std; + +//============================================================================= +/*! + * just for test + */ +//============================================================================= + +ResourcesManager_cpp:: +ResourcesManager_cpp(const char *xmlFilePath) : + _path_resources(xmlFilePath) +{ + cerr << "ResourcesManager_cpp constructor" << endl; +} + +//============================================================================= +/*! + * Standard constructor, parse resource file. + * - if ${APPLI} exists in environment, + * look for ${HOME}/${APPLI}/CatalogResources.xml + * - else look for default: + * ${KERNEL_ROOT_DIR}/share/salome/resources/kernel/CatalogResources.xml + * - parse XML resource file. + */ +//============================================================================= + +ResourcesManager_cpp::ResourcesManager_cpp() +{ + cerr << "ResourcesManager_cpp constructor" << endl; + _isAppliSalomeDefined = (getenv("APPLI") != 0); + + if (_isAppliSalomeDefined) + { + _path_resources = getenv("HOME"); + _path_resources += "/"; + _path_resources += getenv("APPLI"); + _path_resources += "/CatalogResources.xml"; + } + + else + { + _path_resources = getenv("KERNEL_ROOT_DIR"); + _path_resources += "/share/salome/resources/kernel/CatalogResources.xml"; + } + + ParseXmlFile(); + cerr << "ResourcesManager_cpp constructor end"; +} + +//============================================================================= +/*! + * Standard Destructor + */ +//============================================================================= + +ResourcesManager_cpp::~ResourcesManager_cpp() +{ + cerr << "ResourcesManager_cpp destructor" << endl; +} + +//============================================================================= +/*! + * get the list of name of ressources fitting for the specified module. + * If hostname specified, check it is local or known in resources catalog. + * + * Else + * - select first machines with corresponding OS (all machines if + * parameter OS empty), + * - then select the sublist of machines on witch the module is known + * (if the result is empty, that probably means that the inventory of + * modules is probably not done, so give complete list from previous step) + */ +//============================================================================= + +std::vector +ResourcesManager_cpp::GetFittingResources(const machineParams& params, + const std::vector& componentList) throw(ResourcesException) +{ +// cerr << "ResourcesManager_cpp::GetFittingResources" << endl; + vector vec; + + ParseXmlFile(); + + const char *hostname = params.hostname.c_str(); + cerr << "GetFittingResources " << hostname << " " << GetHostname().c_str() << endl; + + if (hostname[0] != '\0'){ + // cerr << "ResourcesManager_cpp::GetFittingResources : hostname specified" << endl; + + if ( strcmp(hostname, "localhost") == 0 || + strcmp(hostname, GetHostname().c_str()) == 0 ) + { + // cerr << "ResourcesManager_cpp::GetFittingResources : localhost" << endl; + vec.push_back(GetHostname().c_str()); + // cerr << "ResourcesManager_cpp::GetFittingResources : " << vec.size() << endl; + } + + else if (_resourcesList.find(hostname) != _resourcesList.end()) + { + // --- params.hostname is in the list of resources so return it. + vec.push_back(hostname); + } + + else + { + // Cas d'un cluster: nombre de noeuds > 1 + int cpt=0; + for (map::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){ + if( (*iter).second.DataForSort._nbOfNodes > 1 ){ + if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){ + vec.push_back((*iter).first.c_str()); + //cerr << "SALOME_ResourcesManager_cpp::GetFittingResources vector[" + // << cpt << "] = " << (*iter).first.c_str() << endl ; + cpt++; + } + } + } + if(cpt==0){ + // --- user specified an unknown hostame so notify him. + cerr << "ResourcesManager_cpp::GetFittingResources : SALOME_Exception" << endl; + throw ResourcesException("unknown host"); + } + } + } + + else{ + // --- Search for available resources sorted by priority + SelectOnlyResourcesWithOS(vec, params.OS.c_str()); + + KeepOnlyResourcesWithModule(vec, componentList); + + if (vec.size() == 0) + SelectOnlyResourcesWithOS(vec, params.OS.c_str()); + + // --- set wanted parameters + ResourceDataToSort::_nbOfNodesWanted = params.nb_node; + + ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node; + + ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock; + + ResourceDataToSort::_memInMBWanted = params.mem_mb; + + // --- end of set + + list li; + + for (vector::iterator iter = vec.begin(); + iter != vec.end(); + iter++) + li.push_back(_resourcesList[(*iter)].DataForSort); + + li.sort(); + + unsigned int i = 0; + + for (list::iterator iter2 = li.begin(); + iter2 != li.end(); + iter2++) + vec[i++] = (*iter2)._hostName; + } + + return vec; + +} + +//============================================================================= +/*! + * add an entry in the ressources catalog xml file. + * Return 0 if OK (KERNEL found in new resources modules) else throw exception + */ +//============================================================================= + +int +ResourcesManager_cpp:: +AddResourceInCatalog(const machineParams& paramsOfNewResources, + const vector& modulesOnNewResources, + const char *alias, + const char *userName, + AccessModeType mode, + AccessProtocolType prot) +throw(ResourcesException) +{ + vector::const_iterator iter = find(modulesOnNewResources.begin(), + modulesOnNewResources.end(), + "KERNEL"); + + if (iter != modulesOnNewResources.end()) + { + ParserResourcesType newElt; + newElt.DataForSort._hostName = paramsOfNewResources.hostname; + newElt.Alias = alias; + newElt.Protocol = prot; + newElt.Mode = mode; + newElt.UserName = userName; + newElt.ModulesList = modulesOnNewResources; + 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._hostName] = newElt; + return 0; + } + + else + throw ResourcesException("KERNEL is not present in this resource"); +} + +//============================================================================= +/*! + * Deletes a resource from the catalog + */ +//============================================================================= + +void ResourcesManager_cpp::DeleteResourceInCatalog(const char *hostname) +{ + _resourcesList.erase(hostname); +} + +//============================================================================= +/*! + * write the current data in memory in file. + */ +//============================================================================= + +void ResourcesManager_cpp::WriteInXmlFile() +{ + const char* aFilePath = _path_resources.c_str(); + + FILE* aFile = fopen(aFilePath, "w"); + + if (aFile == NULL) + { + cerr << "Error opening file !" << endl; + return; + } + + xmlDocPtr aDoc = xmlNewDoc(BAD_CAST "1.0"); + xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog"); + + SALOME_ResourcesCatalog_Handler* handler = + new SALOME_ResourcesCatalog_Handler(_resourcesList); + handler->PrepareDocToXmlFile(aDoc); + delete handler; + + int isOk = xmlSaveFile(aFilePath, aDoc); + + if (!isOk) + cerr << "Error while XML file saving." << endl; + + // Free the document + xmlFreeDoc(aDoc); + + fclose(aFile); + + cerr << "WRITING DONE!" << endl; +} + +//============================================================================= +/*! + * parse the data type catalog + */ +//============================================================================= + +const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile() +{ + SALOME_ResourcesCatalog_Handler* handler = + new SALOME_ResourcesCatalog_Handler(_resourcesList); + + const char* aFilePath = _path_resources.c_str(); + FILE* aFile = fopen(aFilePath, "r"); + + if (aFile != NULL) + { + xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0); + + if (aDoc != NULL) + handler->ProcessXmlDocument(aDoc); + else + cerr << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl; + + // Free the document + xmlFreeDoc(aDoc); + + fclose(aFile); + } + else + cerr << "ResourcesManager_cpp: file "<& listOfMachines) +{ + return _dynamicResourcesSelecter.FindFirst(listOfMachines); +} + +//============================================================================= +/*! + * dynamically obtains the best machines + */ +//============================================================================= + +string ResourcesManager_cpp::FindNext(const std::vector& listOfMachines) +{ + return _dynamicResourcesSelecter.FindNext(listOfMachines,_resourcesList); +} +//============================================================================= +/*! + * dynamically obtains the best machines + */ +//============================================================================= + +string ResourcesManager_cpp::FindBest(const std::vector& listOfMachines) +{ + return _dynamicResourcesSelecter.FindBest(listOfMachines); +} + +//============================================================================= +/*! + * Gives a sublist of machines with matching OS. + * If parameter OS is empty, gives the complete list of machines + */ +//============================================================================= + +// Warning need an updated parsed list : _resourcesList +void ResourcesManager_cpp::SelectOnlyResourcesWithOS( vector& hosts, const char *OS) const +throw(ResourcesException) +{ + string base(OS); + + for (map::const_iterator iter = + _resourcesList.begin(); + iter != _resourcesList.end(); + iter++) + { + if ( (*iter).second.OS == base || base.size() == 0) + hosts.push_back((*iter).first); + } +} + + +//============================================================================= +/*! + * Gives a sublist of machines on which the module is known. + */ +//============================================================================= + +//Warning need an updated parsed list : _resourcesList +void ResourcesManager_cpp::KeepOnlyResourcesWithModule( vector& hosts, const vector& componentList) const +throw(ResourcesException) +{ + for (vector::iterator iter = hosts.begin(); iter != hosts.end();) + { + MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter); + const vector& mapOfModulesOfCurrentHost = (((*it).second).ModulesList); + + bool erasedHost = false; + if( mapOfModulesOfCurrentHost.size() > 0 ){ + for(int i=0;i::const_iterator itt = find(mapOfModulesOfCurrentHost.begin(), + mapOfModulesOfCurrentHost.end(), + compoi); +// componentList[i]); + if (itt == mapOfModulesOfCurrentHost.end()){ + erasedHost = true; + break; + } + } + } + if(erasedHost) + hosts.erase(iter); + else + iter++; + } +} + + +ParserResourcesType ResourcesManager_cpp::GetResourcesList(const std::string& machine) +{ + return _resourcesList[machine]; +} + +std::string ResourcesManager_cpp::GetHostname() +{ + int ls = 100, r = 1; + char *s; + + while (ls < 10000 && r) { + ls *= 2; + s = new char[ls]; + r = gethostname(s, ls-1); + switch (r) + { + case 0: + break; + default: +#ifdef EINVAL + case EINVAL: +#endif +#ifdef ENAMETOOLONG + case ENAMETOOLONG: +#endif + delete [] s; + continue; + } + } + + if (r != 0) { + s = new char[50]; + strcpy(s, "localhost"); + } + + // remove all after '.' + char *aDot = (strchr(s,'.')); + if (aDot) aDot[0] = '\0'; + + string p = s; + delete [] s; + return p; +} + diff --git a/src/ResourcesManager/ResourcesManager.hxx b/src/ResourcesManager/ResourcesManager.hxx new file mode 100644 index 000000000..2396540a3 --- /dev/null +++ b/src/ResourcesManager/ResourcesManager.hxx @@ -0,0 +1,113 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#ifndef __RESOURCESMANAGER_HXX__ +#define __RESOURCESMANAGER_HXX__ + +#include +#include +#include +#include "SALOME_ResourcesCatalog_Parser.hxx" +#include "SALOME_ResourcesCatalog_Handler.hxx" +#include "SALOME_LoadRateManager.hxx" + +// --- WARNING --- +// The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done +// in a critical section to be sure to be clean. +// Only one thread should use the SALOME_ResourcesManager class in a SALOME +// session. + +struct machineParams{ + std::string hostname; + std::string OS; + unsigned int nb_node; + unsigned int nb_proc_per_node; + unsigned int cpu_clock; + unsigned int mem_mb; +}; + +class ResourcesException +{ +public: + const std::string msg; + + ResourcesException(const std::string m) : msg(m) {} +}; + +class ResourcesManager_cpp + { + + public: + + ResourcesManager_cpp(const char *xmlFilePath); + ResourcesManager_cpp(); + + ~ResourcesManager_cpp(); + + std::vector + GetFittingResources(const machineParams& params, + const std::vector& componentList) throw(ResourcesException); + + std::string FindFirst(const std::vector& listOfMachines); + std::string FindNext(const std::vector& listOfMachines); + std::string FindBest(const std::vector& listOfMachines); + + int AddResourceInCatalog + (const machineParams& paramsOfNewResources, + const std::vector& modulesOnNewResources, + const char *alias, + const char *userName, + AccessModeType mode, + AccessProtocolType prot) throw(ResourcesException); + + void DeleteResourceInCatalog(const char *hostname); + + void WriteInXmlFile(); + + const MapOfParserResourcesType& ParseXmlFile(); + + const MapOfParserResourcesType& GetList() const; + + ParserResourcesType GetResourcesList(const std::string& machine); + + protected: + + void SelectOnlyResourcesWithOS(std::vector& hosts, + const char *OS) const + throw(ResourcesException); + + void KeepOnlyResourcesWithModule(std::vector& hosts, + const std::vector& componentList) const + throw(ResourcesException); + + //! will contain the path to the ressources catalog + std::string _path_resources; + + //! will contain the informations on the data type catalog(after parsing) + MapOfParserResourcesType _resourcesList; + + SALOME_LoadRateManager _dynamicResourcesSelecter; + + //! different behaviour if $APPLI exists (SALOME Application) + bool _isAppliSalomeDefined; + + std::string GetHostname(); + }; + +#endif // __RESOURCESMANAGER_HXX__ diff --git a/src/ResourcesManager/SALOME_LoadRateManager.cxx b/src/ResourcesManager/SALOME_LoadRateManager.cxx index f0df795cb..85b90e8dc 100644 --- a/src/ResourcesManager/SALOME_LoadRateManager.cxx +++ b/src/ResourcesManager/SALOME_LoadRateManager.cxx @@ -18,82 +18,47 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SALOME_LoadRateManager.hxx" -#include "utilities.h" #include #include using namespace std; -string SALOME_LoadRateManager::FindFirst(const Engines::MachineList& hosts) +string SALOME_LoadRateManager::FindFirst(const vector& hosts) { - MESSAGE("SALOME_LoadRateManager::FindFirst " << hosts.length()); - - if (hosts.length() == 0) + if (hosts.size() == 0) return string(""); return string(hosts[0]); } -string SALOME_LoadRateManager::FindNext(const Engines::MachineList& hosts,MapOfParserResourcesType& resList,SALOME_NamingService *ns) +string SALOME_LoadRateManager::FindNext(const vector& hosts,MapOfParserResourcesType& resList) { - MESSAGE("SALOME_LoadRateManager::FindNext " << hosts.length()); - map machines; + static int imachine = 0; + static int iproc = 0; - if (hosts.length() == 0) + // if empty list return empty string + if (hosts.size() == 0) return string(""); - - for(int i=0;iChange_Directory("/Containers"); - vector vec = ns->list_directory_recurs(); - Engines::Container_var cont; - for(vector::iterator iter = vec.begin();iter!=vec.end();iter++){ - try - { - CORBA::Object_var obj=ns->Resolve((*iter).c_str()); - cont=Engines::Container::_narrow(obj); - } - catch(CORBA::SystemException& ex) - { - MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it"); - continue; - } - if(!CORBA::is_nil(cont)){ - try - { - CORBA::String_var hostname = cont->getHostName(); - std::string mach=(const char*)hostname; - machines[mach]++; - } - catch(CORBA::SystemException& ex) - { - MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it"); - continue; - } + else{ + ParserResourcesType resource = resList[string(hosts[imachine])]; + int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes; + if( nbproc <= 0) nbproc = 1; + if( iproc < nbproc ){ + iproc++; + return string(hosts[imachine]); } - } - - int imin = 0; - ParserResourcesType resource = resList[string(hosts[0])]; - int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes; - int min = machines[string(hosts[0])]/nbproc; - for(int i=1;i& hosts) { // for the moment then "maui" will be used for dynamic selection ... - MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length()); - throw(SALOME_Exception(LOCALIZED("not yet implemented"))); - return string(""); + return FindFirst(hosts); } diff --git a/src/ResourcesManager/SALOME_LoadRateManager.hxx b/src/ResourcesManager/SALOME_LoadRateManager.hxx index 061b925ae..7c4c3f03d 100644 --- a/src/ResourcesManager/SALOME_LoadRateManager.hxx +++ b/src/ResourcesManager/SALOME_LoadRateManager.hxx @@ -20,11 +20,8 @@ #ifndef __SALOME_LOADRATEMANAGER_HXX__ #define __SALOME_LOADRATEMANAGER_HXX__ -#include -#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) #include #include "SALOME_ResourcesCatalog_Parser.hxx" -#include "SALOME_NamingService.hxx" #if defined RESOURCESMANAGER_EXPORTS #if defined WIN32 @@ -44,9 +41,9 @@ class RESOURCESMANAGER_EXPORT SALOME_LoadRateManager { public: - std::string FindFirst(const Engines::MachineList& hosts); - std::string FindNext(const Engines::MachineList& hosts,MapOfParserResourcesType& resList,SALOME_NamingService *ns); - std::string FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception); + std::string FindFirst(const std::vector& hosts); + std::string FindNext(const std::vector& hosts,MapOfParserResourcesType& resList); + std::string FindBest(const std::vector& hosts); }; #endif diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index 0b85c6bfb..49b30b700 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -29,7 +29,6 @@ #include "SALOME_ResourcesCatalog_Handler.hxx" #include #include -#include "utilities.h" using namespace std; @@ -50,7 +49,7 @@ SALOME_ResourcesCatalog_Handler:: SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): _resources_list(listOfResources) { - MESSAGE("SALOME_ResourcesCatalog_Handler creation"); + cout << "SALOME_ResourcesCatalog_Handler creation" << endl; //XML tags initialisation test_machine = "machine"; test_resources = "resources"; @@ -80,7 +79,7 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler() { - // MESSAGE("SALOME_ResourcesCatalog_Handler destruction"); + // cout << "SALOME_ResourcesCatalog_Handler destruction") << endl; } //============================================================================= @@ -103,7 +102,7 @@ SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) { - if (MYDEBUG) MESSAGE("Begin parse document"); + if (MYDEBUG) cout << "Begin parse document" << endl; // Empty private elements _resources_list.clear(); @@ -304,15 +303,15 @@ void SALOME_ResourcesCatalog_Handler::ProcessXmlDocument(xmlDocPtr theDoc) iter != _resources_list.end(); iter++) { - SCRUTE((*iter).second.Alias); - SCRUTE((*iter).second.UserName); - SCRUTE((*iter).second.AppliPath); - SCRUTE((*iter).second.OS); - SCRUTE((*iter).second.Protocol); - SCRUTE((*iter).second.Mode); + cout << (*iter).second.Alias << endl; + cout << (*iter).second.UserName << endl; + cout << (*iter).second.AppliPath << endl; + cout << (*iter).second.OS << endl; + cout << (*iter).second.Protocol << endl; + cout << (*iter).second.Mode << endl; } - MESSAGE("This is the end of document"); + cout << "This is the end of document" << endl; } } diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx index e20dbfc6a..18765ff29 100644 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -18,8 +18,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "SALOME_ResourcesCatalog_Parser.hxx" -#include "utilities.h" #include +#include #define NULL_VALUE 0 @@ -106,10 +106,10 @@ unsigned int ResourceDataToSort::GetNumberOfPoints() const //! Method used for debug void ResourceDataToSort::Print() const { - SCRUTE(_nbOfNodes); - SCRUTE(_nbOfProcPerNode); - SCRUTE(_CPUFreqMHz); - SCRUTE(_memInMB); + cout << _nbOfNodes << endl; + cout << _nbOfProcPerNode << endl; + cout << _CPUFreqMHz << endl; + cout << _memInMB << endl; } void ParserResourcesType::Print() const @@ -134,7 +134,7 @@ void ParserResourcesType::Print() const for(int i=0;iRegister(refContMan,_ResourcesManagerNameInNS); -// _MpiStarted = false; - MESSAGE("constructor end"); + MESSAGE("SALOME_ResourcesManager constructor end"); } //============================================================================= @@ -86,9 +84,9 @@ SALOME_ResourcesManager(CORBA::ORB_ptr orb, SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, - SALOME_NamingService *ns) + SALOME_NamingService *ns) : _rm() { - MESSAGE("constructor"); + MESSAGE("SALOME_ResourcesManager constructor"); _NS = ns; _orb = CORBA::ORB::_duplicate(orb) ; _poa = PortableServer::POA::_duplicate(poa) ; @@ -97,25 +95,7 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, Engines::ResourcesManager_var refContMan = Engines::ResourcesManager::_narrow(obj); _NS->Register(refContMan,_ResourcesManagerNameInNS); - _isAppliSalomeDefined = (getenv("APPLI") != 0); -// _MpiStarted = false; - - if (_isAppliSalomeDefined) - { - _path_resources = getenv("HOME"); - _path_resources += "/"; - _path_resources += getenv("APPLI"); - _path_resources += "/CatalogResources.xml"; - } - - else - { - _path_resources = getenv("KERNEL_ROOT_DIR"); - _path_resources += "/share/salome/resources/kernel/CatalogResources.xml"; - } - - ParseXmlFile(); - MESSAGE("constructor end"); + MESSAGE("SALOME_ResourcesManager constructor end"); } //============================================================================= @@ -126,7 +106,7 @@ SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb, SALOME_ResourcesManager::~SALOME_ResourcesManager() { - MESSAGE("destructor"); + MESSAGE("SALOME_ResourcesManager destructor"); } @@ -162,255 +142,36 @@ void SALOME_ResourcesManager::Shutdown() Engines::MachineList * SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params, const Engines::CompoList& componentList) -//throw(SALOME_Exception) { // MESSAGE("ResourcesManager::GetFittingResources"); - vector vec; + machineParams p; + p.hostname = params.hostname; + p.OS = params.OS; + p.nb_node = params.nb_node; + p.nb_proc_per_node = params.nb_proc_per_node; + p.cpu_clock = params.cpu_clock; + p.mem_mb = params.mem_mb; + + vector cl; + for(int i=0;i 1 - int cpt=0; - for (map::const_iterator iter = _resourcesList.begin(); iter != _resourcesList.end(); iter++){ - if( (*iter).second.DataForSort._nbOfNodes > 1 ){ - if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){ - vec.push_back((*iter).first.c_str()); - //cout << "SALOME_ResourcesManager::GetFittingResources vector[" - // << cpt << "] = " << (*iter).first.c_str() << endl ; - cpt++; - } - } - } - if(cpt==0){ - // --- user specified an unknown hostame so notify him. - MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception"); - throw SALOME_Exception("unknown host"); - } - } - } - - else - // --- Search for available resources sorted by priority - { - SelectOnlyResourcesWithOS(vec, params.OS); - - KeepOnlyResourcesWithModule(vec, componentList); - - if (vec.size() == 0) - SelectOnlyResourcesWithOS(vec, params.OS); - - // --- set wanted parameters - ResourceDataToSort::_nbOfNodesWanted = params.nb_node; - - ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node; - - ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock; - - ResourceDataToSort::_memInMBWanted = params.mem_mb; - - // --- end of set - - list li; - - for (vector::iterator iter = vec.begin(); - iter != vec.end(); - iter++) - li.push_back(_resourcesList[(*iter)].DataForSort); - - li.sort(); - - unsigned int i = 0; - - for (list::iterator iter2 = li.begin(); - iter2 != li.end(); - iter2++) - vec[i++] = (*iter2)._hostName; - } - - // MESSAGE("ResourcesManager::GetFittingResources : return" << ret.size()); - ret->length(vec.size()); - for(unsigned int i=0;i vec = _rm.GetFittingResources(p,cl); + ret->length(vec.size()); + for(int i=0;i& modulesOnNewResources, - const char *alias, - const char *userName, - AccessModeType mode, - AccessProtocolType prot) -throw(SALOME_Exception) -{ - vector::const_iterator iter = find(modulesOnNewResources.begin(), - modulesOnNewResources.end(), - "KERNEL"); - - if (iter != modulesOnNewResources.end()) - { - ParserResourcesType newElt; - newElt.DataForSort._hostName = paramsOfNewResources.hostname; - newElt.Alias = alias; - newElt.Protocol = prot; - newElt.Mode = mode; - newElt.UserName = userName; - newElt.ModulesList = modulesOnNewResources; - 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._hostName] = newElt; - return 0; - } - - else - throw SALOME_Exception("KERNEL is not present in this resource"); -} - -//============================================================================= -/*! - * Deletes a resource from the catalog - */ -//============================================================================= - -void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname) -{ - _resourcesList.erase(hostname); -} - -//============================================================================= -/*! - * write the current data in memory in file. - */ -//============================================================================= - -void SALOME_ResourcesManager::WriteInXmlFile() -{ - const char* aFilePath = _path_resources.c_str(); - - FILE* aFile = fopen(aFilePath, "w"); - - if (aFile == NULL) - { - INFOS("Error opening file !"); - return; - } - - xmlDocPtr aDoc = xmlNewDoc(BAD_CAST "1.0"); - xmlNewDocComment(aDoc, BAD_CAST "ResourcesCatalog"); - - SALOME_ResourcesCatalog_Handler* handler = - new SALOME_ResourcesCatalog_Handler(_resourcesList); - handler->PrepareDocToXmlFile(aDoc); - delete handler; - - int isOk = xmlSaveFile(aFilePath, aDoc); - - if (!isOk) - INFOS("Error while XML file saving."); - - // Free the document - xmlFreeDoc(aDoc); - - fclose(aFile); - - MESSAGE("WRITING DONE!"); -} - -//============================================================================= -/*! - * parse the data type catalog - */ -//============================================================================= - -const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() -{ - SALOME_ResourcesCatalog_Handler* handler = - new SALOME_ResourcesCatalog_Handler(_resourcesList); - - const char* aFilePath = _path_resources.c_str(); - FILE* aFile = fopen(aFilePath, "r"); - - if (aFile != NULL) - { - xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0); - - if (aDoc != NULL) - handler->ProcessXmlDocument(aDoc); - else - INFOS("ResourcesManager: could not parse file "< ml; + for(int i=0;i& hosts, - const char *OS) const -throw(SALOME_Exception) -{ - string base(OS); - - for (map::const_iterator iter = - _resourcesList.begin(); - iter != _resourcesList.end(); - iter++) - { - if ( (*iter).second.OS == base || base.size() == 0) - hosts.push_back((*iter).first); - } + return CORBA::string_dup(_rm.FindFirst(ml).c_str()); } - -//============================================================================= -/*! - * Gives a sublist of machines on which the module is known. - */ -//============================================================================= - -//Warning need an updated parsed list : _resourcesList -void -SALOME_ResourcesManager::KeepOnlyResourcesWithModule -( vector& hosts, - const Engines::CompoList& componentList) const -throw(SALOME_Exception) -{ - for (vector::iterator iter = hosts.begin(); iter != hosts.end();) - { - MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter); - const vector& mapOfModulesOfCurrentHost = (((*it).second).ModulesList); - - bool erasedHost = false; - if( mapOfModulesOfCurrentHost.size() > 0 ){ - for(int i=0;i::const_iterator itt = find(mapOfModulesOfCurrentHost.begin(), - mapOfModulesOfCurrentHost.end(), - compoi); -// componentList[i]); - if (itt == mapOfModulesOfCurrentHost.end()){ - erasedHost = true; - break; - } - } - } - if(erasedHost) - hosts.erase(iter); - else - iter++; - } -} - - Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const char *hostname) { - ParserResourcesType resource = _resourcesList[string(hostname)]; + ParserResourcesType resource = _rm.GetResourcesList(string(hostname)); Engines::MachineParameters *p_ptr = new Engines::MachineParameters; p_ptr->container_name = CORBA::string_dup(""); p_ptr->hostname = CORBA::string_dup("hostname"); @@ -553,7 +228,3 @@ Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const return p_ptr; } -ParserResourcesType SALOME_ResourcesManager::GetResourcesList(const std::string& machine) -{ - return _resourcesList[machine]; -} diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 5bb750345..4a00444cf 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -30,6 +30,7 @@ #include #include #include +#include "ResourcesManager.hxx" #if defined RESOURCESMANAGER_EXPORTS #if defined WIN32 @@ -66,28 +67,8 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager: Engines::MachineList * GetFittingResources(const Engines::MachineParameters& params, const Engines::CompoList& componentList); -// throw(SALOME_Exception); char* FindFirst(const Engines::MachineList& listOfMachines); - std::string FindNext(const Engines::MachineList& listOfMachines); - std::string FindBest(const Engines::MachineList& listOfMachines); - - int AddResourceInCatalog - (const Engines::MachineParameters& paramsOfNewResources, - const std::vector& modulesOnNewResources, - const char *alias, - const char *userName, - AccessModeType mode, - AccessProtocolType prot) - throw(SALOME_Exception); - - void DeleteResourceInCatalog(const char *hostname); - - void WriteInXmlFile(); - - const MapOfParserResourcesType& ParseXmlFile(); - - const MapOfParserResourcesType& GetList() const; Engines::MachineParameters* GetMachineParameters(const char *hostname); @@ -95,7 +76,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager: static const char *_ResourcesManagerNameInNS; - ParserResourcesType GetResourcesList(const std::string& machine); + ResourcesManager_cpp *GetImpl() { return &_rm; } protected: @@ -103,24 +84,8 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager: CORBA::ORB_var _orb; PortableServer::POA_var _poa; - void SelectOnlyResourcesWithOS(std::vector& hosts, - const char *OS) const - throw(SALOME_Exception); - - void KeepOnlyResourcesWithModule(std::vector& hosts, - const Engines::CompoList& componentList) const - throw(SALOME_Exception); - - //! will contain the path to the ressources catalog - std::string _path_resources; - - //! will contain the informations on the data type catalog(after parsing) - MapOfParserResourcesType _resourcesList; - - SALOME_LoadRateManager _dynamicResourcesSelecter; + ResourcesManager_cpp _rm; - //! different behaviour if $APPLI exists (SALOME Application) - bool _isAppliSalomeDefined; }; #endif // RESSOURCESCATALOG_IMPL_H