From d25e22a0ede62c83ffcc00dffa6d12c2c3d68edc Mon Sep 17 00:00:00 2001 From: prascle Date: Tue, 15 May 2007 06:35:12 +0000 Subject: [PATCH] merge from tag BR_V326p4_20070428 --- idl/SALOME_ContainerManager.idl | 7 +- src/Container/Makefile.am | 4 +- src/Container/SALOME_ContainerManager.cxx | 164 ++++++++++++------ src/Container/SALOME_ContainerManager.hxx | 11 +- src/Container/TestContainerManager.cxx | 149 ++++++++++++++++ src/LifeCycleCORBA/LifeCycleCORBA.py | 4 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 2 +- .../SALOME_LoadRateManager.cxx | 56 +++++- .../SALOME_LoadRateManager.hxx | 6 +- .../SALOME_ResourcesManager.cxx | 25 +++ .../SALOME_ResourcesManager.hxx | 2 + 11 files changed, 361 insertions(+), 69 deletions(-) create mode 100644 src/Container/TestContainerManager.cxx diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 9814c828f..84ec3c794 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -55,6 +55,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 @@ -76,7 +78,10 @@ struct MachineParameters Container FindOrStartParallelContainer( in MachineParameters params, in MachineList possibleComputers); - string FindBest(in MachineList possibleComputers); + Container StartContainer( in MachineParameters params, + in ResPolicy policy); + + string FindFirst(in MachineList possibleComputers); MachineList GetFittingResources( in MachineParameters params, in string componentName ) diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index 6134220a7..bf0b79045 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -146,6 +146,4 @@ SALOME_ContainerManagerServer_CPPFLAGS=\ SALOME_ContainerManagerServer_LDADD =\ libSalomeContainer.la \ $(COMMON_LIBS) \ - ../Basics/libSALOMEBasics.la - - + ../Basics/libSALOMEBasics.la diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index e98a7b77c..f5e1eb1fb 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -166,10 +166,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 @@ -182,66 +224,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); } #ifdef WITH_PACO_PARALLEL @@ -420,9 +472,9 @@ GetFittingResources(const Engines::MachineParameters& params, char* SALOME_ContainerManager:: -FindBest(const Engines::MachineList& possibleComputers) +FindFirst(const Engines::MachineList& possibleComputers) { - string theMachine=_ResManager->FindBest(possibleComputers); + string theMachine=_ResManager->FindFirst(possibleComputers); return CORBA::string_dup(theMachine.c_str()); } diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 9c24963f7..aa7ab18c2 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -44,11 +44,20 @@ 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); - char* FindBest(const Engines::MachineList& possibleComputers); + char* FindFirst(const Engines::MachineList& possibleComputers); void Shutdown(); void ShutdownContainers(); diff --git a/src/Container/TestContainerManager.cxx b/src/Container/TestContainerManager.cxx new file mode 100644 index 000000000..3d991bbdd --- /dev/null +++ b/src/Container/TestContainerManager.cxx @@ -0,0 +1,149 @@ +// 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 "SALOME_LifeCycleCORBA.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; + Engines::Container_ptr cont; + Engines::Component_ptr compo; + bool error = false; + bool bestImplemented; + + // 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); + cont = _ContManager->StartContainer(p,Engines::P_CYCL); + if(CORBA::is_nil(cont)) error = true; + } + + for(int i=0;i<10;i++){ + sprintf(st,"first_%d",i); + p.container_name = CORBA::string_dup(st); + cont = _ContManager->StartContainer(p,Engines::P_FIRST); + if(CORBA::is_nil(cont)) error = true; + } + + p.container_name = CORBA::string_dup("best"); + cont = _ContManager->StartContainer(p,Engines::P_BEST); + if(CORBA::is_nil(cont)) bestImplemented = false; + else bestImplemented = true; + + SALOME_LifeCycleCORBA LCC(_NS); + compo = LCC.FindOrLoad_Component("FactoryServer","GEOM"); + if(CORBA::is_nil(compo)) error = true; + compo = LCC.FindOrLoad_Component("FactoryServer","GEOM"); + if(CORBA::is_nil(compo)) error = true; + + _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) && !error ){ + string msg; + if(bestImplemented) + msg = "TEST OK"; + else + msg = "TEST OK but FindBest not implemented!"; + MESSAGE(msg); + return 0; + } + else{ + MESSAGE("TEST KO"); + return 1; + } +} diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index e0a7ac0f3..928c83cea 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -159,7 +159,7 @@ class LifeCycleCORBA: pass pass if len(machinesOK)!=0: - bestMachine=self._contManager.FindBest(machinesOK) + bestMachine=self._contManager.FindFirst(machinesOK) componentNameForNS= [CosNaming.NameComponent(bestMachine,"dir"), CosNaming.NameComponent(containerName,"dir"), CosNaming.NameComponent(componentName,"object")] @@ -176,7 +176,7 @@ class LifeCycleCORBA: else: return None else: - bestMachine=self._contManager.FindBest(listOfMachines) + bestMachine=self._contManager.FindFirst(listOfMachines) MESSAGE("Not implemented yet ...") return None pass diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 7f6ad28ac..10047091c 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -425,7 +425,7 @@ _FindComponent(const Engines::MachineParameters& params, if(lghtOfmachinesOK != 0) { machinesOK->length(lghtOfmachinesOK); - CORBA::String_var bestMachine = _ContManager->FindBest(machinesOK); + CORBA::String_var bestMachine = _ContManager->FindFirst(machinesOK); CORBA::Object_var obj = _NS->ResolveComponent(bestMachine, containerName, componentName, 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 dd87b6406..f47b37ace 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -129,6 +129,7 @@ throw(SALOME_Exception) // MESSAGE("ResourcesManager::GetFittingResources"); vector ret; + // --- To be sure that we search in a correct list. ParseXmlFile(); @@ -336,6 +337,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 @@ -349,6 +373,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 e96993808..42cc984cd 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -52,6 +52,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