From fd79dfc21b957d17db0f515ff5a4034b6b015bfa Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 7 Jan 2005 13:24:55 +0000 Subject: [PATCH] Draft --- src/Container/Makefile.in | 12 +- src/Container/SALOME_ContainerManager.cxx | 107 ++++++++++++++++++ src/Container/SALOME_ContainerManager.hxx | 35 ++++++ .../SALOME_ContainerManagerServer.cxx | 41 +++++++ 4 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 src/Container/SALOME_ContainerManager.cxx create mode 100644 src/Container/SALOME_ContainerManager.hxx create mode 100644 src/Container/SALOME_ContainerManagerServer.cxx diff --git a/src/Container/Makefile.in b/src/Container/Makefile.in index 308814390..729ee6679 100644 --- a/src/Container/Makefile.in +++ b/src/Container/Makefile.in @@ -38,23 +38,25 @@ EXPORT_PYSCRIPTS = SALOME_ComponentPy.py SALOME_ContainerPy.py EXPORT_HEADERS = \ SALOME_Component_i.hxx \ + SALOME_ContainerManager.hxx \ SALOME_Container_i.hxx # Libraries targets LIB = libSalomeContainer.la -LIB_SRC = Component_i.cxx Container_i.cxx +LIB_SRC = Component_i.cxx Container_i.cxx SALOME_ContainerManager.cxx LIB_SERVER_IDL = SALOME_Registry.idl SALOME_Component.idl +LIB_CLIENT_IDL = SALOME_ContainerManager.idl # Executables targets -BIN = SALOME_Container +BIN = SALOME_Container SALOME_ContainerManagerServer BIN_SRC = SALOME_Container_SignalsHandler.cxx -BIN_SERVER_IDL = SALOME_Component.idl +BIN_SERVER_IDL = SALOME_Component.idl SALOME_ContainerManager.idl -CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES) +CPPFLAGS+= $(PYTHON_INCLUDES) $(MPI_INCLUDE) $(OCC_INCLUDES) $(QT_MT_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+= -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace +LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace LIBS += @LDEXPDYNFLAGS@ $(PYTHON_LIBS) $(MPI_LIBS) -lCASCatch diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx new file mode 100644 index 000000000..66d2e2eee --- /dev/null +++ b/src/Container/SALOME_ContainerManager.cxx @@ -0,0 +1,107 @@ +#include "SALOME_ContainerManager.hxx" +#include "SALOME_NamingService.hxx" +#include "OpUtil.hxx" +#include +#include +#define TIME_OUT_TO_LAUNCH_CONT 21 + +using namespace std; + +const char *SALOME_ContainerManager::_ContainerManagerNameInNS="ContainerManager"; + +SALOME_ContainerManager::SALOME_ContainerManager(SALOME_NamingService *ns):_NS(ns) +{ +} + +Engines::Container_ptr SALOME_ContainerManager::FindOrStartContainer(const char *containerName, const MachineList& possibleComputers) +{ + Engines::Container_ptr ret=DoesExistContainer(containerName,possibleComputers); + if(!CORBA::is_nil(ret)) + return ret; + // Container doesn't exist try to launch it ... + vector vector; + string theMachine=_LoadManager.FindBest(possibleComputers); + string command; + if(theMachine==GetHostname()) + command=_ResManager.BuildCommandToLaunchLocalContainer(containerName); + else + command=_ResManager.BuildTempFileToLaunchRemoteContainer(theMachine,containerName); + _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 ) { + sleep( 1 ) ; + count-- ; + if ( count != 10 ) + MESSAGE( count << ". Waiting for FactoryServer on " << theMachine); + string containerNameInNS=BuildContainerNameInNS(containerName,theMachine.c_str()); + 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; + } +} + +MachineList *SALOME_ContainerManager::GetResourcesFitting(const MachineParameters& params, const char *componentName) +{ + vector vec=_ResManager.GetResourcesFitting(params,componentName); + MachineList *ret=new MachineList; + ret->length(vec.size()); + for(unsigned int i=0;iResolve(containerNameInNS.c_str()); + if( !CORBA::is_nil(obj) ) + return Engines::Container::_narrow(obj); + else + return Engines::Container::_nil(); +} + +Engines::Container_ptr SALOME_ContainerManager::DoesExistContainer(const char *containerName,const MachineList& possibleComputers) +{ + for(unsigned int i=0;i +#include CORBA_CLIENT_HEADER(SALOME_Component) +#include CORBA_CLIENT_HEADER(SALOME_ContainerManager) +#include "SALOME_ResourcesManager.hxx" +#include "SALOME_LoadRateManager.hxx" + +#include +#include + +class SALOME_NamingService; + +class SALOME_ContainerManager: public POA_Engines::ContainerManager, + public PortableServer::RefCountServantBase { +private: + SALOME_ResourcesManager _ResManager; + SALOME_LoadRateManager _LoadManager; + SALOME_NamingService *_NS; +public: + SALOME_ContainerManager(SALOME_NamingService *ns); + Engines::Container_ptr FindOrStartContainer(const char *containerName, const MachineList& possibleComputer); + MachineList *GetResourcesFitting(const MachineParameters& params, const char *componentName); + char* FindBest(const MachineList& possibleComputers); + void ShutdownContainers(); + + static const char *_ContainerManagerNameInNS; +private: + Engines::Container_ptr DoesExistContainer(const char *containerName,const MachineList& possibleComputers); + Engines::Container_ptr FindContainer(const char *containerName,const char *theMachine); + std::string BuildContainerNameInNS(const char *containerName,const char *machineName); +}; + +#endif diff --git a/src/Container/SALOME_ContainerManagerServer.cxx b/src/Container/SALOME_ContainerManagerServer.cxx new file mode 100644 index 000000000..d1a5a0766 --- /dev/null +++ b/src/Container/SALOME_ContainerManagerServer.cxx @@ -0,0 +1,41 @@ +#include "SALOME_ContainerManager.hxx" +#include "SALOME_NamingService.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "LocalTraceCollector.hxx" + +#include + +using namespace std; + +int main(int argc, char *argv[]) +{ + ORB_INIT &init = *SINGLETON_::Instance() ; + CORBA::ORB_var &orb = init( argc , argv ) ; + LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance(orb); + try { + SALOME_NamingService *ns=new SALOME_NamingService(orb); + SALOME_ContainerManager *contManager=new SALOME_ContainerManager(ns); + Engines::ContainerManager_ptr contManagerServant=contManager->_this(); + ns->Register(contManagerServant,SALOME_ContainerManager::_ContainerManagerNameInNS); + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj); + PortableServer::POAManager_var pman = root_poa->the_POAManager(); + pman->activate(); + orb->run(); + delete myThreadTrace; + }catch(CORBA::SystemException&){ + INFOS("Caught CORBA::SystemException."); + }catch(PortableServer::POA::WrongPolicy&){ + INFOS("Caught CORBA::WrongPolicyException."); + }catch(PortableServer::POA::ServantAlreadyActive&){ + INFOS("Caught CORBA::ServantAlreadyActiveException"); + }catch(CORBA::Exception&){ + INFOS("Caught CORBA::Exception."); + }catch(std::exception& exc){ + INFOS("Caught std::exception - "<