From 3da07b521c1e2f0f7ea119b7fc7c342491688c66 Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 7 Jan 2005 13:19:13 +0000 Subject: [PATCH] Draft --- idl/Makefile.in | 1 + idl/SALOME_Component.idl | 10 +- idl/SALOME_ContainerManager.idl | 38 ++ src/Makefile.in | 4 +- src/ResourcesManager/Makefile.in | 66 +++ .../SALOME_LoadRateManager.cxx | 9 + .../SALOME_LoadRateManager.hxx | 14 + .../SALOME_ResourcesCatalog_Handler.cxx | 289 +++++++++++++ .../SALOME_ResourcesCatalog_Handler.hxx | 137 +++++++ .../SALOME_ResourcesCatalog_Parser.cxx | 82 ++++ .../SALOME_ResourcesCatalog_Parser.hxx | 97 +++++ .../SALOME_ResourcesManager.cxx | 380 ++++++++++++++++++ .../SALOME_ResourcesManager.hxx | 99 +++++ 13 files changed, 1218 insertions(+), 8 deletions(-) create mode 100644 idl/SALOME_ContainerManager.idl create mode 100755 src/ResourcesManager/Makefile.in create mode 100644 src/ResourcesManager/SALOME_LoadRateManager.cxx create mode 100644 src/ResourcesManager/SALOME_LoadRateManager.hxx create mode 100755 src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx create mode 100755 src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx create mode 100644 src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx create mode 100755 src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx create mode 100644 src/ResourcesManager/SALOME_ResourcesManager.cxx create mode 100644 src/ResourcesManager/SALOME_ResourcesManager.hxx diff --git a/idl/Makefile.in b/idl/Makefile.in index 6e46e61bd..a2ff1794e 100644 --- a/idl/Makefile.in +++ b/idl/Makefile.in @@ -19,6 +19,7 @@ IDL_FILES = \ SALOMEDS.idl \ SALOMEDS_Attributes.idl \ SALOME_Session.idl \ + SALOME_ContainerManager.idl \ SALOME_Component.idl \ SALOME_TestComponent.idl \ SALOME_Registry.idl \ diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index ecad1fa41..8112ecedd 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -52,12 +52,6 @@ module Engines */ interface Container { -/*! - Initializes the %container with a definite name. - \param ContainerName Name of the container - \return an initialized container -*/ - Container start_impl( in string ContainerName ) ; /*! Loads into the container a new component, registers it and starts it's CORBA servant. @@ -94,6 +88,10 @@ module Engines Returns True if the %container has been killed */ boolean Kill_impl() ; +/*! + Shutdown the Container process. +*/ + void Shutdown(); /*! Returns the hostname of the container */ diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl new file mode 100644 index 000000000..1b9b97828 --- /dev/null +++ b/idl/SALOME_ContainerManager.idl @@ -0,0 +1,38 @@ +#ifndef _SALOME_CONTAINERMANAGER_IDL_ +#define _SALOME_CONTAINERMANAGER_IDL_ + +#include "SALOME_Component.idl" + +/*! + Type to describe properties of wanted resource. +*/ +struct MachineParameters { + string container_name; + string hostname; + string OS; + long mem_mb; + long cpu_clock; + long nb_proc_per_node; + long nb_node; +}; + +/*! + Type to transmit list of machines. +*/ + typedef sequence MachineList; + +module Engines +{ +/*! \brief Interface of the %containerManager + This interface is used for interaction with the unique instance of ContainerManager +*/ + interface ContainerManager + { + Container FindOrStartContainer( in string containerName, in MachineList possibleComputers); + string FindBest(in MachineList possibleComputers); + MachineList GetResourcesFitting( in MachineParameters params, in string componentName ); + void ShutdownContainers(); + } ; +}; + +#endif diff --git a/src/Makefile.in b/src/Makefile.in index d97b5e791..7b40708e1 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -36,7 +36,7 @@ ifeq (@WITHIHM@,yes) SUBDIRS = MSG2QM SALOMELocalTrace Logger Utils CASCatch PatchQt \ GenericObj MEDWrapper NamingService Registry \ ModuleCatalog DataTypeCatalog RessourcesCatalog \ - Notification NOTIFICATION_SWIG \ + ResourcesManager Notification NOTIFICATION_SWIG \ Container TestContainer LifeCycleCORBA HDFPersist Prs \ VTKFilter OBJECT \ TOOLSDS SALOMEDS Event \ @@ -50,7 +50,7 @@ ifeq (@WITHIHM@,no) SUBDIRS = MSG2QM SALOMELocalTrace Logger Utils CASCatch \ GenericObj NamingService Registry \ ModuleCatalog DataTypeCatalog RessourcesCatalog \ - Notification NOTIFICATION_SWIG \ + ResourcesManager Notification NOTIFICATION_SWIG \ Container TestContainer LifeCycleCORBA HDFPersist Prs \ TOOLSDS SALOMEDS Event \ SALOME_SWIG_WITHOUTIHM ModuleGenerator Loader Communication diff --git a/src/ResourcesManager/Makefile.in b/src/ResourcesManager/Makefile.in new file mode 100755 index 000000000..9712b5217 --- /dev/null +++ b/src/ResourcesManager/Makefile.in @@ -0,0 +1,66 @@ +# SALOME RessourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) +# +# Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +EXPORT_HEADERS = \ + SALOME_ResourcesCatalog_Parser.hxx \ + SALOME_ResourcesManager.hxx \ + SALOME_ResourcesCatalog_Handler.hxx \ + SALOME_LoadRateManager.hxx \ + +# Libraries targets +LIB = libSalomeResourcesManager.la +LIB_SRC = \ + SALOME_ResourcesCatalog_Parser.cxx \ + SALOME_ResourcesCatalog_Handler.cxx \ + SALOME_LoadRateManager.cxx \ + SALOME_ResourcesManager.cxx \ + +# Executables targets +# trouble we have client and serveur and build don't known about this with rule +# in fact client is a test ! So it may go away BIN ! +#BIN = test_rc +#SALOME_RessourcesCatalog_Server SALOME_RessourcesCatalog_Client test +LIB_CLIENT_IDL = SALOME_ContainerManager.idl SALOME_Component.idl +BIN_SRC = +BIN_SERVER_IDL = SALOME_ResourcesManager.idl + +CPPFLAGS+= $(QT_MT_INCLUDES) +CXXFLAGS+= +LDFLAGS+= $(QT_MT_LIBS) $(OGL_LIBS) -lSalomeNS -lOpUtil -lSALOMELocalTrace + +@CONCLUDE@ + + diff --git a/src/ResourcesManager/SALOME_LoadRateManager.cxx b/src/ResourcesManager/SALOME_LoadRateManager.cxx new file mode 100644 index 000000000..2d583c2bc --- /dev/null +++ b/src/ResourcesManager/SALOME_LoadRateManager.cxx @@ -0,0 +1,9 @@ +#include "SALOME_LoadRateManager.hxx" + +using namespace std; + +string SALOME_LoadRateManager::FindBest(const MachineList& hosts) +{ + // for the moment then "maui" will be used for dynamic selection ... + return string(hosts[0]); +} diff --git a/src/ResourcesManager/SALOME_LoadRateManager.hxx b/src/ResourcesManager/SALOME_LoadRateManager.hxx new file mode 100644 index 000000000..b076bf934 --- /dev/null +++ b/src/ResourcesManager/SALOME_LoadRateManager.hxx @@ -0,0 +1,14 @@ +#ifndef __SALOME_LOADRATEMANAGER_HXX__ +#define __SALOME_LOADRATEMANAGER_HXX__ + +#include +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) +#include + +class SALOME_LoadRateManager +{ +public: + std::string FindBest(const MachineList& hosts); +}; + +#endif diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx new file mode 100755 index 000000000..ab289af1c --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -0,0 +1,289 @@ +// SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_ResourcesCatalog_Handler.cxx +// Author : Estelle Deville +// Module : SALOME +//$Header$ + +#include "SALOME_ResourcesCatalog_Handler.hxx" +#include +#include +#include +#include "utilities.h" + +using namespace std; + +//---------------------------------------------------------------------- +//Function : SALOME_ResourcesCatalog_Handler +//Purpose: Constructor +//---------------------------------------------------------------------- +SALOME_ResourcesCatalog_Handler::SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):_resources_list(listOfResources) +{ + MESSAGE("SALOME_ResourcesCatalog_Handler creation"); + //XML tags initialisation + test_machine="machine"; + test_resources="resources"; + + test_hostname="hostname"; + test_alias="alias"; + test_protocol="protocol"; + test_mode="mode"; + test_user_name="userName"; + test_modules="modules"; + test_module_name="moduleName"; + test_module_path="modulePath"; + test_pre_req_file_path="preReqFilePath"; + test_os="OS"; + test_mem_in_mb="memInMB"; + test_cpu_freq_mhz="CPUFreqMHz"; + test_nb_of_nodes="nbOfNodes"; + test_nb_of_proc_per_node="nbOfProcPerNode"; +} + +//---------------------------------------------------------------------- +//Function : ~SALOME_ResourcesCatalog_Handler +//Purpose: Destructor +//---------------------------------------------------------------------- +SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler() +{ + MESSAGE("SALOME_ResourcesCatalog_Handler destruction"); +} + +//---------------------------------------------------------------------- +//Function : GetResourcesAfterParsing +//Purpose: Retrieves DS after the file parse. +//---------------------------------------------------------------------- +const MapOfParserResourcesType& SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const +{ + return _resources_list; +} + +//---------------------------------------------------------------------- +//Function : startDocument +//Purpose: overload handler function +//---------------------------------------------------------------------- +bool SALOME_ResourcesCatalog_Handler::startDocument() +{ + MESSAGE("Begin parse document"); + // Empty private elements + _resources_list.clear(); + return true; +} + +//---------------------------------------------------------------------- +//Function : startElement +//Purpose: overload handler function +//---------------------------------------------------------------------- +bool SALOME_ResourcesCatalog_Handler::startElement(const QString&, + const QString&, + const QString& name, + const QXmlAttributes& attrs) +{ + for(int i=0;i::iterator iter=_resources_list.begin();iter!=_resources_list.end();iter++) + { + QDomElement eltRoot = doc.createElement(test_machine); + root.appendChild( eltRoot ); + eltRoot.setAttribute((char *)test_hostname,(*iter).first.c_str()); + eltRoot.setAttribute((char *)test_alias,(*iter).second.Alias.c_str()); + switch((*iter).second.Protocol) + { + case rsh: + eltRoot.setAttribute((char *)test_protocol,"r"); + break; + case ssh: + eltRoot.setAttribute((char *)test_protocol,"s"); + break; + default: + eltRoot.setAttribute((char *)test_protocol,"r"); + } + switch((*iter).second.Mode) + { + case interactive: + eltRoot.setAttribute((char *)test_mode,"i"); + break; + case batch: + eltRoot.setAttribute((char *)test_mode,"b"); + break; + default: + eltRoot.setAttribute((char *)test_mode,"i"); + } + eltRoot.setAttribute((char *)test_user_name,(*iter).second.UserName.c_str()); + for(map::const_iterator iter2=(*iter).second.ModulesPath.begin();iter2!=(*iter).second.ModulesPath.end();iter2++) + { + QDomElement rootForModulesPaths=doc.createElement(test_modules); + rootForModulesPaths.setAttribute(test_module_name,(*iter2).first.c_str()); + rootForModulesPaths.setAttribute(test_module_path,(*iter2).second.c_str()); + eltRoot.appendChild(rootForModulesPaths); + } + eltRoot.setAttribute(test_pre_req_file_path,(*iter).second.PreReqFilePath.c_str()); + eltRoot.setAttribute(test_os,(*iter).second.OS.c_str()); + eltRoot.setAttribute(test_mem_in_mb,(*iter).second.DataForSort._memInMB); + eltRoot.setAttribute(test_cpu_freq_mhz,(*iter).second.DataForSort._CPUFreqMHz); + eltRoot.setAttribute(test_nb_of_nodes,(*iter).second.DataForSort._nbOfNodes); + eltRoot.setAttribute(test_nb_of_proc_per_node,(*iter).second.DataForSort._nbOfProcPerNode); + } +} diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx new file mode 100755 index 000000000..6e9916aab --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx @@ -0,0 +1,137 @@ +// SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_ResourcesCatalog_Handler.hxx +// Author : Estelle Deville +// Module : SALOME +//$Header$ + +#ifndef SALOME_RESOURCES_CATALOG_HANDLER +#define SALOME_RESOURCES_CATALOG_HANDLER + +#include "SALOME_ResourcesCatalog_Parser.hxx" + +#include +#include +#include + +class QDomElement; +class QDomDocument; + +class SALOME_ResourcesCatalog_Handler : public QXmlDefaultHandler +{ +public : + //! standard constructor + SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources); + + const MapOfParserResourcesType& GetResourcesAfterParsing() const; + + //! standard destructor + virtual ~SALOME_ResourcesCatalog_Handler(); + + //! method to overload handler function startDocument + /*! is called before a xml file is parsed + \return true if no error was detected + */ + virtual bool startDocument(); + + //! method to overload handler function startElement + /*! + \param QString argument by value + \param QString argument by value + \param QString qName argument by value + \param QXmlAttributes atts argument by value + \return true if no error was detected + */ + virtual bool startElement(const QString& , const QString& , + const QString& name, const QXmlAttributes& attrs); + + //! method to overload handler function endElement + /*! + \param QString argument by value + \param QString argument by value + \param QString qName argument by value + \return true if no error was detected + */ + virtual bool endElement(const QString&, const QString&, + const QString& qName); + + //! method to overload handler function characters + /*! + \param QString chars argument by value + \return true if no error was detected + */ + virtual bool characters(const QString& chars); + + //! method to overload handler function endDocument + /*! is called at the end of the parsing + \return true if no error was detected + */ + virtual bool endDocument(); + + //! method to overload handler function errorProtocol + /*! + \return the error message + */ + virtual QString errorProtocol(); + +//! method to overload handler function fatalError + /*! + \param QXmlParseException exception argument by value + \return true if no error was detected + */ + virtual bool fatalError(const QXmlParseException& exception); + +//! method to fill the document to be writen in a file + void PrepareDocToXmlFile(QDomDocument& doc); + +private : + QString errorProt; + std::string content; + std::string previous_module_name; + std::string previous_module_path; + + ParserResourcesType _resource; + MapOfParserResourcesType& _resources_list; + + const char *test_machine; + const char *test_resources; + + const char *test_hostname; + const char *test_alias; + const char *test_protocol; + const char *test_mode; + const char *test_user_name; + const char *test_modules; + const char *test_module_name; + const char *test_module_path; + const char *test_pre_req_file_path; + const char *test_os; + const char *test_mem_in_mb; + const char *test_cpu_freq_mhz; + const char *test_nb_of_nodes; + const char *test_nb_of_proc_per_node; + +}; + +#endif // SALOME_RESOURCES_CATALOG_HANDLER diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx new file mode 100644 index 000000000..d6562befc --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -0,0 +1,82 @@ +#include "SALOME_ResourcesCatalog_Parser.hxx" +#include + +#define NULL_VALUE 0 + +using namespace std; + +unsigned int ResourceDataToSort::_nbOfNodesWanted=NULL_VALUE; +unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted=NULL_VALUE; +unsigned int ResourceDataToSort::_CPUFreqMHzWanted=NULL_VALUE; +unsigned int ResourceDataToSort::_memInMBWanted=NULL_VALUE; + +ResourceDataToSort::ResourceDataToSort() +{ +} + +ResourceDataToSort::ResourceDataToSort(const string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB):_hostName(hostname),_nbOfNodes(nbOfNodes),_nbOfProcPerNode(nbOfProcPerNode),_CPUFreqMHz(CPUFreqMHz),_memInMB(memInMB) +{ +} + +//! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting +bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const +{ + unsigned int nbPts=GetNumberOfPoints(); + return nbPts_nbOfNodesWanted) + ret+=2000; + else + ret+=1000; + } + //priority 2 : Nb of proc by node + if(_nbOfProcPerNodeWanted!=NULL_VALUE) + { + if(_nbOfProcPerNode==_nbOfProcPerNodeWanted) + ret+=300; + else if(_nbOfProcPerNode > _nbOfProcPerNodeWanted) + ret+=200; + else + ret+=100; + } + //priority 3 : Cpu freq + if(_CPUFreqMHzWanted!=NULL_VALUE) + { + if(_CPUFreqMHz==_CPUFreqMHzWanted) + ret+=30; + else if(_CPUFreqMHz > _CPUFreqMHzWanted) + ret+=20; + else + ret+=10; + } + //priority 4 : memory + if(_memInMBWanted!=NULL_VALUE) + { + if(_memInMB==_memInMBWanted) + ret+=3; + else if(_memInMB > _memInMBWanted) + ret+=2; + else + ret+=1; + } + return ret; +} + +//! Method used for debug +void ResourceDataToSort::Print() const +{ + cout << "Nb of nodes : " << _nbOfNodes << endl; + cout << "Nb of proc per node : " << _nbOfProcPerNode << endl; + cout << "CPU : " << _CPUFreqMHz << endl; + cout << "Mem : " << _memInMB << endl; +} + diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx new file mode 100755 index 000000000..989db2f44 --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -0,0 +1,97 @@ +// SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) +// +// Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SALOME_ResourcesCatalog_Parser.hxx +// Author : Estelle Deville +// Module : SALOME +//$Header$ + +#ifndef SALOME_RESOURCES_CATALOG_PARSER +#define SALOME_RESOURCES_CATALOG_PARSER + +#include +#include +#include +#include + +typedef std::map MapOfModulesPath; + +enum AccessProtocolType {rsh, ssh}; + +enum AccessModeType {interactive, batch}; + +class ResourceDataToSort { +public: + std::string _hostName; + unsigned int _nbOfNodes; + unsigned int _nbOfProcPerNode; + unsigned int _CPUFreqMHz; + unsigned int _memInMB; + static unsigned int _nbOfNodesWanted; + static unsigned int _nbOfProcPerNodeWanted; + static unsigned int _CPUFreqMHzWanted; + static unsigned int _memInMBWanted; +public: + ResourceDataToSort(); + ResourceDataToSort(const std::string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB); + bool operator< (const ResourceDataToSort& other) const; + void Print() const; +private: + unsigned int GetNumberOfPoints() const; +// friend class SALOME_ResourcesCatalog_Handler; +// friend class SALOME_ResourcesManager; +// friend struct ParserResourcesType; +}; + +struct ParserResourcesType { + ResourceDataToSort DataForSort; + std::string Alias; + AccessProtocolType Protocol; + AccessModeType Mode; + std::string UserName; + MapOfModulesPath ModulesPath; + std::string PreReqFilePath; + std::string OS; + + void Print(){ + std::cout << "##############*****" << std::endl; + std::cout << "HostName : " << DataForSort._hostName << std::endl; + std::cout << "Alias : " << Alias << std::endl; + std::cout << "Protocol : " << Protocol << std::endl; + std::cout << "Mode : " << Mode << std::endl; + std::cout << "UserName : " << UserName << std::endl; + std::cout << "Modules : " << std::endl; + int i=1; + for(std::map::iterator iter=ModulesPath.begin();iter!=ModulesPath.end();iter++) + { + std::cout << " Module " << i++ << " called : " << (*iter).first << " with path : " << (*iter).second << std::endl; + } + std::cout << "PreReqFilePath : " << PreReqFilePath << std::endl; + std::cout << "OS : " << OS << std::endl; + DataForSort.Print(); + } +}; + +typedef std::map MapOfParserResourcesType; + +#endif //SALOME_RESOURCES_CATALOG_PARSER diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx new file mode 100644 index 000000000..74363b7f2 --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -0,0 +1,380 @@ +#include "SALOME_ResourcesManager.hxx" +#include "SALOME_Container_i.hxx" +#include "Utils_ExceptHandlers.hxx" +#include "OpUtil.hxx" + +#include + +#include +#include +#include +#include +#include + +#define MAX_SIZE_FOR_HOSTNAME 256; + +using namespace std; + +//just for test +SALOME_ResourcesManager::SALOME_ResourcesManager(const char *xmlFilePath):_path_resources(xmlFilePath) +{ +} + +SALOME_ResourcesManager::SALOME_ResourcesManager() +{ + _path_resources=getenv("KERNEL_ROOT_DIR"); + _path_resources+="/share/salome/resources/CatalogResources.xml"; + ParseXmlFile(); +} + +SALOME_ResourcesManager::~SALOME_ResourcesManager() +{ +} + +vector SALOME_ResourcesManager::GetResourcesFitting(const MachineParameters& params,const char *moduleName) throw(SALOME_Exception) +{ + vector ret; + //To be sure that we search in a correct list. + ParseXmlFile(); + const char *hostname=(const char *)params.hostname; + if(hostname[0]!='\0') + { + if(_resourcesList.find(hostname)!=_resourcesList.end()) + // params.hostame is in the list of resources so return it. + ret.push_back(hostname); + else + //user specified an unknown hostame so notify to him. + throw SALOME_Exception("unknown host"); + } + else + // Search for available resources sorted by priority + { + SelectOnlyResourcesWithOS(ret,params.OS); + KeepOnlyResourcesWithModule(ret,moduleName); + //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=ret.begin();iter!=ret.end();iter++) + li.push_back(_resourcesList[(*iter)].DataForSort); + li.sort(); + unsigned int i=0; + for(list::iterator iter2=li.begin();iter2!=li.end();iter2++) + ret[i++]=(*iter2)._hostName; + } +// } +// else +// // user don't specify parameters so default behaviour, only localhost returned +// { +// char *hostName=new char[MAX_SIZE_FOR_HOSTNAME]; +// gethostname(hostName,MAX_SIZE_FOR_HOSTNAME); +// ret.push_back(hostName); +// delete [] hostName; +// } + return ret; +} + +int SALOME_ResourcesManager::AddResourceInCatalog(const MachineParameters& paramsOfNewResources, const map& modulesOnNewResources, + const char *environPathOfPrerequired, + const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception) +{ + map::const_iterator iter=modulesOnNewResources.find("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.ModulesPath=modulesOnNewResources; +// for(int i=0;iPrepareDocToXmlFile(doc); + delete handler; + QFile file( _path_resources ); + if( !file.open( IO_WriteOnly ) ) + cout << "WRITING ERROR !!!" << endl; + //return -1; + + QTextStream ts( &file ); + ts << doc.toString(); + + file.close(); + cout << "WRITING DONE!!!" << endl; +} + +const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() +{ + SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList); + QFile xmlFile(_path_resources); + + QXmlInputSource source(xmlFile); + + QXmlSimpleReader reader; + reader.setContentHandler( handler ); + reader.setErrorHandler( handler ); + reader.parse( source ); + xmlFile.close(); + delete handler; + return _resourcesList; +} + +bool SALOME_ResourcesManager::_verify_resources(MapOfParserResourcesType resourceslist) +{ +// bool _return_value = true; +// bool _bool = false ; +// vector _machine_list; +// _machine_list.resize(0); + +// // Fill a list of all computers indicated in the resources list +// for (unsigned int ind = 0; ind < resourceslist.size(); ind++) +// _machine_list.push_back(resourceslist[ind].HostName); + +// // Parse if a computer name is twice in the list of computers +// for (unsigned int ind = 0; ind < _machine_list.size(); ind++) +// { +// for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++) +// { +// if(_machine_list[ind].compare(_machine_list[ind1]) == 0) +// { +// MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the resources list") +// _return_value = false; +// } +// } +// } + +// return _return_value; + return true; +} + +const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const +{ + return _resourcesList; +} + +string SALOME_ResourcesManager::FindBest(const MachineList& listOfMachines) +{ + return _dynamicResourcesSelecter.FindBest(listOfMachines); +} + +string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer(const string& machine,const char *containerName) +{ + _TmpFileName=BuildTemporaryFileName(); + ofstream tempOutputFile(_TmpFileName.c_str()); + const ParserResourcesType& resInfo=_resourcesList[machine]; + tempOutputFile << "/bin/sh <::const_iterator iter=resInfo.ModulesPath.begin();iter!=resInfo.ModulesPath.end();iter++) + { + string curModulePath((*iter).second); + tempOutputFile << "export " << (*iter).first << "_ROOT_DIR="<< curModulePath << endl; + tempOutputFile << "export LD_LIBRARY_PATH=" << curModulePath << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl; + tempOutputFile << "export PYTHONPATH=" << curModulePath << "/bin/salome:" << curModulePath << "/lib/python2.2/site-packages/salome:"; + tempOutputFile << curModulePath << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}" << endl; + } + tempOutputFile << "source " << resInfo.PreReqFilePath << endl; + // ! env vars + tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/"; + if(Engines_Container_i::isPythonContainer(containerName)) + tempOutputFile << "SALOME_ContainerPy.py "; + else + tempOutputFile << "SALOME_Container "; + tempOutputFile << containerName << " -"; + AddOmninamesParams(tempOutputFile); + tempOutputFile << " > /tmp/" << containerName << "_" << machine << ".log 2>&1 &" << endl; + tempOutputFile << "EOF" << endl; + tempOutputFile.flush(); + tempOutputFile.close(); + //Build command + string command; + if(resInfo.Protocol==rsh) + command = "rsh -n "; + else if(resInfo.Protocol==ssh) + command = "ssh -n "; + else + throw SALOME_Exception("Unknown protocol"); + command+=machine; + _CommandForRemAccess=command; + command+=" < "; + command+=_TmpFileName; + return command; +} + +string SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer(const char *containerName) +{ + _TmpFileName=""; + string command; + if(Engines_Container_i::isPythonContainer(containerName)) + command="SALOME_ContainerPy.py "; + else + command="SALOME_Container "; + command+=containerName; + command+=" -"; + AddOmninamesParams(command); + command+=" > /tmp/"; + command+=containerName; + command += "_"; + command += GetHostname(); + command += ".log 2>&1 &" ; + return command; +} + +void SALOME_ResourcesManager::RmTmpFile() +{ + if(_TmpFileName!="") + { + string command="rm "; + command+=_TmpFileName; + system(command.c_str()); + } +} + +string SALOME_ResourcesManager::BuildCommand(const string& machine,const char *containerName) +{ +// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 & + const ParserResourcesType& resInfo=_resourcesList[machine]; + bool pyCont=Engines_Container_i::isPythonContainer(containerName); + string command; + if(resInfo.Protocol==rsh) + command = "rsh -n " ; + else if(resInfo.Protocol==ssh) + command = "ssh -f -n "; + else + throw SALOME_Exception("Not implemented yet..."); + command += machine; + command += " "; + string path = (*(resInfo.ModulesPath.find("KERNEL"))).second; + command +=path; + command += "/bin/salome/"; + if ( pyCont ) + command += "SALOME_ContainerPy.py "; + else + command += "SALOME_Container "; + command += containerName; + command += " -"; + AddOmninamesParams(command); + command += " > /tmp/"; + command += containerName; + command += "_"; + command += machine; + command += ".log 2>&1 &" ; + SCRUTE( command ); + return command; +// int status = system( command.c_str() ) ; +// if (status == -1) { +// MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)") ; +// } +// else if (status == 217) { +// MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status 217)") ; +// } +// else { +// int count = 21 ; +// while ( CORBA::is_nil( aFactoryServer ) && count ) { +// sleep( 1 ) ; +// count-- ; +// if ( count != 10 ) +// MESSAGE( count << ". Waiting for FactoryServer on " << machine) +// aFactoryServer = FindContainer( FactoryServer.c_str() ) ; +// } +// if ( CORBA::is_nil( aFactoryServer ) ) { +// MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ; +// } +// else if ( strcmp( theComputer.c_str() , GetHostname().c_str() ) ) { +// _FactoryServer = aFactoryServer ; +// } +// } +} + +// Warning need an updated parsed list : _resourcesList +void SALOME_ResourcesManager::SelectOnlyResourcesWithOS(vector& 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) + hosts.push_back((*iter).first); +} + +//Warning need an updated parsed list : _resourcesList +void SALOME_ResourcesManager::KeepOnlyResourcesWithModule(vector& hosts,const char *moduleName) const throw(SALOME_Exception) +{ + for(vector::iterator iter=hosts.begin();iter!=hosts.end();iter++) + { + MapOfParserResourcesType::const_iterator it=_resourcesList.find(*iter); + const map& mapOfModulesOfCurrentHost=(((*it).second).ModulesPath); + if(mapOfModulesOfCurrentHost.find(moduleName)==mapOfModulesOfCurrentHost.end()) + { + hosts.erase(iter); + } + } +} + +void SALOME_ResourcesManager::AddOmninamesParams(string& command) const +{ + string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; + ifstream omniORBfile( omniORBcfg.c_str() ) ; + char ORBInitRef[12] ; + char nameservice[132] ; + omniORBfile >> ORBInitRef ; + command += ORBInitRef ; + command += " " ; + omniORBfile >> nameservice ; + omniORBfile.close() ; + char * bsn = strchr( nameservice , '\n' ) ; + if ( bsn ) { + bsn[ 0 ] = '\0' ; + } + command += nameservice ; +} + +void SALOME_ResourcesManager::AddOmninamesParams(ofstream& fileStream) const +{ + string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; + ifstream omniORBfile( omniORBcfg.c_str() ) ; + char ORBInitRef[12] ; + char nameservice[132] ; + omniORBfile >> ORBInitRef ; + fileStream << ORBInitRef; + fileStream << " "; + omniORBfile >> nameservice ; + omniORBfile.close() ; + char * bsn = strchr( nameservice , '\n' ) ; + if ( bsn ) { + bsn[ 0 ] = '\0' ; + } + fileStream << nameservice; +} + +string SALOME_ResourcesManager::BuildTemporaryFileName() const +{ + //build more complex file name to support multiple salome session + return "/tmp/command.sh"; +} + + diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx new file mode 100644 index 000000000..5c4070990 --- /dev/null +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -0,0 +1,99 @@ +#ifndef __SALOME_RESOURCESMANAGER_HXX__ +#define __SALOME_RESOURCESMANAGER_HXX__ + +#include "Utils_SALOME_Exception.hxx" +#include "utilities.h" +#include +#include "SALOME_ResourcesCatalog_Handler.hxx" +#include "SALOME_LoadRateManager.hxx" +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) +#include +#include +#include + +//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. + +class SALOME_ResourcesManager +{ +public: + //! standard constructor + SALOME_ResourcesManager(); + + //!just for test + SALOME_ResourcesManager(const char *xmlFilePath); + + //! standard destructor + ~SALOME_ResourcesManager(); + + //! method to get the list of name of ressources fitting for the specified module. + std::vector GetResourcesFitting(const MachineParameters& params,const char *moduleName) throw(SALOME_Exception); + + //! method to dynamically obtain the best machines + std::string FindBest(const MachineList& listOfMachines); + + //! method that builds in a temporary file the script to be launched + std::string BuildTempFileToLaunchRemoteContainer(const std::string& machine,const char *containerName); + + //! method that builds the command to be launched. + std::string BuildCommandToLaunchLocalContainer(const char *containerName); + + //! method that remove the generated temporary file in case of a remote launch. + void RmTmpFile(); + + //! method that builds the script to be launched + std::string BuildCommand(const std::string& machine,const char *containerName); + + //! add an entry in the ressources catalog xml file. Return 1 if OK. Return 0 if the ressource with the same hostname already exists. + int AddResourceInCatalog(const MachineParameters& paramsOfNewResources, const std::map& modulesOnNewResources, + const char *environPathOfPrerequired, + const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception); + + //! delete a ressource from the Catalog. + void DeleteResourceInCatalog(const char *hostname); + + //! write the current data in memory in file. + void WriteInXmlFile(); + + //! method to parse the data type catalog + const MapOfParserResourcesType& ParseXmlFile(); + + //! to consult the content of the list + const MapOfParserResourcesType& GetList() const; + +private: + + //! method to verify ressources catalog content - return true if verfication is OK + bool _verify_resources(MapOfParserResourcesType resourceslist); + + //! method that fill hosts with only resources in xml files that are on the specified OS + void SelectOnlyResourcesWithOS(std::vector& hosts,const char *OS) const throw(SALOME_Exception); + + //! method that keep from hosts only those having component of name moduleName. + void KeepOnlyResourcesWithModule(std::vector& hosts,const char *moduleName) const throw(SALOME_Exception); + + //! methode that add to command all options relative to naming service. + void AddOmninamesParams(std::string& command) const; + + //! method that add to command all options relative to naming service. + void AddOmninamesParams(std::ofstream& fileStream) const; + + //! method that generate a file name in /tmp directory + std::string BuildTemporaryFileName() const; + + // will contain the path to the ressources catalog + QString _path_resources; + + //! attribute that contains current tmp files generated + std::string _TmpFileName; + + //! attribute that contains the rsh or ssh command to access directly to machine. Only used by this->RmTmpFile in case of a remote launch. + std::string _CommandForRemAccess; + + //will contain the informations on the data type catalog(after parsing) + MapOfParserResourcesType _resourcesList; + + SALOME_LoadRateManager _dynamicResourcesSelecter; +}; + +#endif // RESSOURCESCATALOG_IMPL_H -- 2.39.2