From 8d688e076f71e8f7b5443513885509bc2f1ef042 Mon Sep 17 00:00:00 2001 From: secher Date: Thu, 19 Apr 2007 12:42:53 +0000 Subject: [PATCH] add cyclic policy in container launching --- idl/SALOME_ContainerManager.idl | 5 + src/Container/Makefile.am | 13 +- src/Container/SALOME_ContainerManager.cxx | 160 ++++++++++++------ src/Container/SALOME_ContainerManager.hxx | 9 + src/Container/TestContainerManager.cxx | 129 ++++++++++++++ .../SALOME_LoadRateManager.cxx | 56 +++++- .../SALOME_LoadRateManager.hxx | 6 +- .../SALOME_ResourcesManager.cxx | 25 +++ .../SALOME_ResourcesManager.hxx | 2 + 9 files changed, 345 insertions(+), 60 deletions(-) create mode 100644 src/Container/TestContainerManager.cxx diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index e2999e9e8..894701482 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -51,6 +51,8 @@ struct MachineParameters */ exception NotFound {}; + enum policy {P_FIRST,P_CYCL,P_BEST}; + typedef policy ResPolicy; /*! \brief Interface of the %containerManager This interface is used for interaction with the unique instance @@ -61,6 +63,9 @@ struct MachineParameters Container FindOrStartContainer( in MachineParameters params, in MachineList possibleComputers); + Container StartContainer( in MachineParameters params, + in ResPolicy policy); + string FindBest(in MachineList possibleComputers); MachineList GetFittingResources( in MachineParameters params, diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 4d3629531..ca72bd532 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -121,7 +121,7 @@ libSalomeContainer_la_LIBADD =\ # Executables targets # =============================================================== # -bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer +bin_PROGRAMS = SALOME_Container SALOME_ContainerManagerServer TestContainerManager SALOME_Container_SOURCES =\ SALOME_Container.cxx \ SALOME_Container_SignalsHandler.cxx @@ -146,3 +146,14 @@ SALOME_ContainerManagerServer_LDADD =\ libSalomeContainer.la \ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la + +TestContainerManager_SOURCES =\ + TestContainerManager.cxx + +TestContainerManager_CPPFLAGS=\ + $(COMMON_CPPFLAGS) + +TestContainerManager_LDADD =\ + libSalomeContainer.la \ + $(COMMON_LIBS) \ + ../Basics/libSALOMEBasics.la diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 8998aa2e3..61656b179 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -162,10 +162,52 @@ FindOrStartContainer(const Engines::MachineParameters& params, if(!CORBA::is_nil(ret)) return ret; MESSAGE("Container doesn't exist try to launch it ..."); - MESSAGE("SALOME_ContainerManager::FindOrStartContainer " << + + return StartContainer(params,possibleComputers,Engines::P_FIRST); + +} + +//============================================================================= +/*! CORBA Method: + * Start a suitable Container in a list of machines + * \param params Machine Parameters required for the container + * \param possibleComputers list of machines usable for start + */ +//============================================================================= + +Engines::Container_ptr +SALOME_ContainerManager:: +StartContainer(const Engines::MachineParameters& params, + const Engines::MachineList& possibleComputers, + Engines::ResPolicy policy) +{ + long id; + string containerNameInNS; + char idc[3*sizeof(long)]; + Engines::Container_ptr ret = Engines::Container::_nil(); + + MESSAGE("SALOME_ContainerManager::StartContainer " << possibleComputers.length()); - //vector vector; - string theMachine=_ResManager->FindBest(possibleComputers); + + string theMachine; + try{ + switch(policy){ + case Engines::P_FIRST: + theMachine=_ResManager->FindFirst(possibleComputers); + break; + case Engines::P_CYCL: + theMachine=_ResManager->FindNext(possibleComputers); + break; + case Engines::P_BEST: + theMachine=_ResManager->FindBest(possibleComputers); + break; + } + } + catch( const SALOME_Exception &ex ){ + MESSAGE(ex.what()); + return Engines::Container::_nil(); + } + MESSAGE("try to launch it on " << theMachine); // Get Id for container: a parallel container registers in Naming Service @@ -178,66 +220,76 @@ FindOrStartContainer(const Engines::MachineParameters& params, id = GetIdForContainer(); string command; - if(theMachine=="") - { - MESSAGE("SALOME_ContainerManager::FindOrStartContainer : " << - "no possible computer"); - return Engines::Container::_nil(); - } + if(theMachine==""){ + MESSAGE("SALOME_ContainerManager::StartContainer : " << + "no possible computer"); + return Engines::Container::_nil(); + } else if(theMachine==GetHostname()) - { - command=_ResManager->BuildCommandToLaunchLocalContainer(params,id); - } + command=_ResManager->BuildCommandToLaunchLocalContainer(params,id); else - command = - _ResManager->BuildCommandToLaunchRemoteContainer(theMachine,params,id); + command = _ResManager->BuildCommandToLaunchRemoteContainer(theMachine,params,id); _ResManager->RmTmpFile(); int status=system(command.c_str()); - if (status == -1) - { - MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " << - "(system command status -1)"); - return Engines::Container::_nil(); - } - else if (status == 217) - { - MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " << - "(system command status 217)"); - return Engines::Container::_nil(); - } - else - { - int count=TIME_OUT_TO_LAUNCH_CONT; - while ( CORBA::is_nil(ret) && count ) - { + if (status == -1){ + MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " << + "(system command status -1)"); + return Engines::Container::_nil(); + } + else if (status == 217){ + MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed " << + "(system command status 217)"); + return Engines::Container::_nil(); + } + else{ + int count=TIME_OUT_TO_LAUNCH_CONT; + MESSAGE("count = "<BuildContainerNameForNS(params,theMachine.c_str()); - SCRUTE(containerNameInNS); - CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str()); - ret=Engines::Container::_narrow(obj); - } - if ( CORBA::is_nil(ret) ) - { - MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed"); - } - return ret; + count-- ; + if ( count != 10 ) + MESSAGE( count << ". Waiting for FactoryServer on " << theMachine); + + if(params.isMPI){ + containerNameInNS = "/ContainerManager/id"; + sprintf(idc,"%ld",id); + containerNameInNS += idc; + } + else + containerNameInNS = _NS->BuildContainerNameForNS(params,theMachine.c_str()); + + SCRUTE(containerNameInNS); + CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str()); + ret=Engines::Container::_narrow(obj); } + + if ( CORBA::is_nil(ret) ) + MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed"); + + return ret; + } +} + +//============================================================================= +/*! CORBA Method: + * Start a suitable Container in a list of machines + * \param params Machine Parameters required for the container + * \param possibleComputers list of machines usable for start + */ +//============================================================================= + +Engines::Container_ptr +SALOME_ContainerManager:: +StartContainer(const Engines::MachineParameters& params, + Engines::ResPolicy policy) +{ + Engines::MachineList_var possibleComputers = GetFittingResources(params,""); + return StartContainer(params,possibleComputers,policy); } //============================================================================= diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 82492f71e..9573e06e3 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -57,6 +57,15 @@ public: FindOrStartContainer(const Engines::MachineParameters& params, const Engines::MachineList& possibleComputer); + Engines::Container_ptr + StartContainer(const Engines::MachineParameters& params, + const Engines::MachineList& possibleComputer, + Engines::ResPolicy policy); + + Engines::Container_ptr + StartContainer(const Engines::MachineParameters& params, + Engines::ResPolicy policy); + Engines::MachineList * GetFittingResources(const Engines::MachineParameters& params, const char *componentName); diff --git a/src/Container/TestContainerManager.cxx b/src/Container/TestContainerManager.cxx new file mode 100644 index 000000000..6aca42160 --- /dev/null +++ b/src/Container/TestContainerManager.cxx @@ -0,0 +1,129 @@ +// SALOME TestContainer : test of container creation and its life cycle +// +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : TestContainer.cxx +// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA +// Module : SALOME +// $Header$ + +#include "utilities.h" +#include +#include +#include +#include "SALOME_NamingService.hxx" +#include "SALOME_ContainerManager.hxx" +#include "NamingService_WaitForServerReadiness.hxx" +#include "OpUtil.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "Utils_SALOME_Exception.hxx" +#include "Utils_CommException.hxx" +using namespace std; + +int main (int argc, char * argv[]) +{ + map cycle; + map first; + + // Initializing omniORB + ORB_INIT &init = *SINGLETON_::Instance() ; + CORBA::ORB_ptr orb = init( argc , argv ) ; + + SALOME_NamingService *_NS=new SALOME_NamingService(orb); + + CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); + ASSERT( !CORBA::is_nil(obj)); + Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj); + + Engines::MachineParameters p; + + p.hostname = ""; + p.OS = "LINUX"; + p.mem_mb = 1000; + p.cpu_clock = 1000; + p.nb_proc_per_node = 1; + p.nb_node = 1; + p.isMPI = false; + + char st[10]; + for(int i=0;i<10;i++){ + sprintf(st,"cycl_%d",i); + p.container_name = CORBA::string_dup(st); + _ContManager->StartContainer(p,Engines::P_CYCL); + } + + for(int i=0;i<10;i++){ + sprintf(st,"first_%d",i); + p.container_name = CORBA::string_dup(st); + _ContManager->StartContainer(p,Engines::P_FIRST); + } + + p.container_name = CORBA::string_dup("best"); + _ContManager->StartContainer(p,Engines::P_BEST); + + _NS->Change_Directory("/Containers"); + + vector vec = _NS->list_directory_recurs(); + list lstCont; + for(vector::iterator iter = vec.begin();iter!=vec.end();iter++){ + CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); + Engines::Container_var cont=Engines::Container::_narrow(obj); + if(!CORBA::is_nil(cont)){ + cycle[cont->getHostName()]=0; + first[cont->getHostName()]=0; + lstCont.push_back((*iter)); + } + } + for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){ + CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); + Engines::Container_var cont=Engines::Container::_narrow(obj); + if(!CORBA::is_nil(cont)){ + if(strncmp(basename(cont->name()),"cycl",4)==0) + cycle[cont->getHostName()]++; + if(strncmp(basename(cont->name()),"first",5)==0) + first[cont->getHostName()]++; + } + } + _ContManager->ShutdownContainers(); + + int cmin=10; + int cmax=0; + int fmin=10; + int fmax=0; + for(map::iterator iter=cycle.begin();iter!=cycle.end();iter++){ + if(strcmp((*iter).first.c_str(),"localhost")!=0){ + if(cycle[(*iter).first]cmax) cmax=cycle[(*iter).first]; + if(first[(*iter).first]fmax) fmax=first[(*iter).first]; + } + } + if( ((cmax-cmin) <= 1) && (fmax == 10)){ + MESSAGE("TEST OK"); + return 0; + } + else{ + MESSAGE("TEST KO"); + return 1; + } +} diff --git a/src/ResourcesManager/SALOME_LoadRateManager.cxx b/src/ResourcesManager/SALOME_LoadRateManager.cxx index 5841ced68..527cade0a 100644 --- a/src/ResourcesManager/SALOME_LoadRateManager.cxx +++ b/src/ResourcesManager/SALOME_LoadRateManager.cxx @@ -20,16 +20,66 @@ #include "SALOME_LoadRateManager.hxx" #include "utilities.h" #include +#include using namespace std; -string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts) +string SALOME_LoadRateManager::FindFirst(const Engines::MachineList& hosts) { - // for the moment then "maui" will be used for dynamic selection ... - MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length()); + MESSAGE("SALOME_LoadRateManager::FindFirst " << hosts.length()); if (hosts.length() == 0) return string(""); return string(hosts[0]); } + +string SALOME_LoadRateManager::FindNext(const Engines::MachineList& hosts,SALOME_NamingService *ns) +{ + MESSAGE("SALOME_LoadRateManager::FindNext " << hosts.length()); + map machines; + + if (hosts.length() == 0) + return string(""); + + for(int i=0;iChange_Directory("/Containers"); + vector vec = ns->list_directory_recurs(); + list lstCont; + for(vector::iterator iter = vec.begin();iter!=vec.end();iter++){ + CORBA::Object_var obj=ns->Resolve((*iter).c_str()); + Engines::Container_var cont=Engines::Container::_narrow(obj); + if(!CORBA::is_nil(cont)){ + lstCont.push_back((*iter)); + } + } + for(list::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){ + CORBA::Object_var obj=ns->Resolve((*iter).c_str()); + Engines::Container_var cont=Engines::Container::_narrow(obj); + if(!CORBA::is_nil(cont)){ + string mach = cont->getHostName(); + machines[mach]++; + } + } + + int imin = 0; + int min = machines[string(hosts[0])]; + for(int i=1;i #include CORBA_CLIENT_HEADER(SALOME_ContainerManager) #include - +#include "SALOME_NamingService.hxx" #if defined RESOURCESMANAGER_EXPORTS #if defined WIN32 @@ -43,7 +43,9 @@ class RESOURCESMANAGER_EXPORT SALOME_LoadRateManager { public: - std::string FindBest(const Engines::MachineList& hosts); + std::string FindFirst(const Engines::MachineList& hosts); + std::string FindNext(const Engines::MachineList& hosts,SALOME_NamingService *ns); + std::string FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception); }; #endif diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index cd903db26..c5e1a4a68 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -127,6 +127,7 @@ throw(SALOME_Exception) // MESSAGE("ResourcesManager::GetFittingResources"); vector ret; + // --- To be sure that we search in a correct list. ParseXmlFile(); @@ -334,6 +335,29 @@ const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const } +//============================================================================= +/*! + * dynamically obtains the first machines + */ +//============================================================================= + +string +SALOME_ResourcesManager::FindFirst(const Engines::MachineList& listOfMachines) +{ + return _dynamicResourcesSelecter.FindFirst(listOfMachines); +} + +//============================================================================= +/*! + * dynamically obtains the best machines + */ +//============================================================================= + +string +SALOME_ResourcesManager::FindNext(const Engines::MachineList& listOfMachines) +{ + return _dynamicResourcesSelecter.FindNext(listOfMachines,_NS); +} //============================================================================= /*! * dynamically obtains the best machines @@ -347,6 +371,7 @@ SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines) } + //============================================================================= /*! * This is no longer valid (C++ container are also python containers) diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 34a8a93d4..7e0391adf 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -68,6 +68,8 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager const char *moduleName) throw(SALOME_Exception); + std::string FindFirst(const Engines::MachineList& listOfMachines); + std::string FindNext(const Engines::MachineList& listOfMachines); std::string FindBest(const Engines::MachineList& listOfMachines); std::string BuildCommandToLaunchRemoteContainer -- 2.39.2