From c6c23d06b9fb980b7705b54b51d7a3afb062d313 Mon Sep 17 00:00:00 2001 From: rahuel Date: Fri, 5 Nov 2004 07:35:56 +0000 Subject: [PATCH] ContainersManager --- src/Container/SALOME_ContainerPy.py | 121 +- src/Container/SALOME_Container_i.hxx | 14 +- .../ContainersManager_Server.cxx | 173 +++ src/ContainersManager/ContainersManager_i.cxx | 1338 +++++++++++++++++ src/ContainersManager/ContainersManager_i.hxx | 162 ++ src/ContainersManager/Makefile.in | 58 + src/ContainersManager/ResourcesContainers.py | 131 ++ .../TestContainersManager.py | 620 ++++++++ src/ContainersManager/runContainer.py | 62 + src/LifeCycleCORBA/LifeCycleCORBA.py | 369 +++-- src/LifeCycleCORBA/Makefile.in | 4 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 673 +++++---- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 45 +- src/LifeCycleCORBA/TestLifeCycleCORBA.cxx | 36 +- 14 files changed, 3324 insertions(+), 482 deletions(-) create mode 100644 src/ContainersManager/ContainersManager_Server.cxx create mode 100644 src/ContainersManager/ContainersManager_i.cxx create mode 100644 src/ContainersManager/ContainersManager_i.hxx create mode 100755 src/ContainersManager/Makefile.in create mode 100644 src/ContainersManager/ResourcesContainers.py create mode 100644 src/ContainersManager/TestContainersManager.py create mode 100644 src/ContainersManager/runContainer.py diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 6444ef148..584e64951 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -49,6 +49,12 @@ class SALOME_ContainerPy_i (Engines__POA.Container): _orb = None _poa = None _numInstance = 0 + _containerName = None + _contId = None + _machineName = None + _naming_service = None + _Name = None + _Pid = None #------------------------------------------------------------------------- @@ -57,19 +63,58 @@ class SALOME_ContainerPy_i (Engines__POA.Container): self._orb = orb self._poa = poa self._containerName = containerName - - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') + self._contId = self._poa.reference_to_id( self._this() ) + #HostName = os.getenv( "HOSTNAME" ) + HostName = os.getenv( "HOST" ) + MESSAGE( "SALOME_ContainerPy_i::__init__ _machineName : " + HostName ) + myMachine = string.split( HostName , '.' ) + self._machineName = myMachine[0] naming_service = SALOME_NamingServicePy_i(self._orb) self._naming_service = naming_service Container_path = "/Containers/" + myMachine[0] + "/" + self._containerName - MESSAGE( str(Container_path) ) + self._Name = Container_path + MESSAGE( "SALOME_ContainerPy_i::__init__ _Name : " + str(Container_path) ) naming_service.Register(self._this(), Container_path) + self._Pid = os.getpid() #------------------------------------------------------------------------- - def start_impl(self, ContainerName): + def delete(self): + MESSAGE( "SALOME_ContainerPy_i::delete" ) + + #------------------------------------------------------------------------- + + def destroy(self): + MESSAGE( "SALOME_ContainerPy_i::destroy : " + self._Name ) + try : + self._naming_service.Destroy_Name( self._Name ) + #d = dir(self._poa) + #print "dir(self._poa) ",d,type(self._poa) + MESSAGE( "SALOME_ContainerPy_i::destroy _poa.deactivate_object self._contId " ) + self._poa.deactivate_object( self._contId ) + MESSAGE( "SALOME_ContainerPy_i::destroy _poa.deactivate_object done" ) + self._poa._release() + MESSAGE( "SALOME_ContainerPy_i::destroy _poa._released" ) + #d = dir(self) + #print "dir(self) ",d,type(self) + #d = dir(self._contId) + #print "dir(self._contId) ",d,type(self._contId) + #MESSAGE( "SALOME_ContainerPy_i::destroy " ) + #self.delete( self._contId ) + #self._contId.delete() + #MESSAGE( "SALOME_ContainerPy_i::destroy self._contId deleted" ) + #self._remove_ref() + #MESSAGE( "SALOME_ContainerPy_i::destroy self _removed_ref" ) + MESSAGE( "SALOME_ContainerPy_i::destroyed" ) + except : + MESSAGE( "SALOME_ContainerPy_i::destroy failed" ) + #sys.exit(0) + + #------------------------------------------------------------------------- + + def start_impl( self, ContainerName , ContainerType ): MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) ) - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') + myMachine=string.split(os.getenv( "HOST" ),'.') theContainer = "/Containers/" + myMachine[0] + "/" + ContainerName try: obj = self._naming_service.Resolve(theContainer) @@ -83,11 +128,12 @@ class SALOME_ContainerPy_i (Engines__POA.Container): if container is None: MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" ) else : - MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without runSession" ) + MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found" ) return container - #shstr = os.getenv( "PWD" ) + "/" - #shstr += "runSession ./SALOME_ContainerPy.py " - shstr = "runSession SALOME_ContainerPy.py " + if ContainerType == Engines.CppContainer : + shstr = "SALOME_Container " + else : + shstr = "SALOME_ContainerPy.py " shstr += ContainerName # mpv: fix for SAL4731 - allways create new file to write log of server @@ -104,10 +150,6 @@ class SALOME_ContainerPy_i (Engines__POA.Container): shstr += fileName shstr += " 2>&1 &" - #shstr += " > /tmp/" - #shstr += ContainerName - #shstr += ".log 2>&1 &" - MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" ) os.system( shstr ) count = 21 @@ -125,8 +167,11 @@ class SALOME_ContainerPy_i (Engines__POA.Container): container = obj._narrow(Engines.Container) if container is None: MESSAGE( str(containerName) + ".object exists but is not a Container" ) + else : + MESSAGE( str(containerName) + ".object registered" ) return container if count == 0 : + MESSAGE( "start_impl of " + str(theContainer) + " failed." ) return container #------------------------------------------------------------------------- @@ -139,9 +184,23 @@ class SALOME_ContainerPy_i (Engines__POA.Container): the_command = "import " + nameToRegister + "\n" the_command = the_command + "comp_i = " + nameToRegister + "." + nameToRegister the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n" - MESSAGE( "SALOME_ContainerPy_i::load_impl :" + str (the_command) ) - exec the_command - comp_o = comp_i._this() + valdir = dir() + print "dir() : ",valdir + print "self._orb",self._orb + print "self._poa",self._poa + print "self._this()",self._this() + print "self._containerName",self._containerName + print "instanceName",instanceName + print "interfaceName",interfaceName + print "exec the_command = '",the_command,"' :" + try : + exec the_command + comp_o = comp_i._this() + MESSAGE( "SALOME_ContainerPy_i::load_impl " + componentName + " imported" ) + except : + comp_o = None + MESSAGE( "SALOME_ContainerPy_i::load_impl " + componentName + " except" ) + print "return from SALOME_ContainerPy_i::load_impl " return comp_o #------------------------------------------------------------------------- @@ -161,16 +220,29 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- + def type(self): + MESSAGE( "SALOME_ContainerPy_i::type" ) + return Engines.PythonContainer + + #------------------------------------------------------------------------- + def _get_name(self): - MESSAGE( "SALOME_ContainerPy_i::_get_name" ) + MESSAGE( "SALOME_ContainerPy_i::_get_name " + self._Name ) + return self._Name #------------------------------------------------------------------------- def _get_machineName(self): - MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" ) - self._machineName = "localhost" + MESSAGE( "SALOME_ContainerPy_i::_get_MachineName " + self._machineName ) return self._machineName + + #------------------------------------------------------------------------- + + def getPID(self): + MESSAGE( "SALOME_ContainerPy_i::getPID" ) + return self._Pid + #============================================================================= #initialise the ORB and find the root POA @@ -179,8 +251,11 @@ poa = orb.resolve_initial_references("RootPOA") #create an instance of SALOME_ContainerPy_i and a Container reference #containerName = "FactoryServerPy" -MESSAGE( str(sys.argv) ) -containerName = sys.argv[1] +MESSAGE( "SALOME_ContainerPy.py " + str(sys.argv) ) +if len( sys.argv ) > 1 : + containerName = sys.argv[1] +else : + containerName = "FactoryServerPy" cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) cpy_o = cpy_i._this() @@ -191,6 +266,10 @@ poaManager.activate() #Block for ever orb.run() +print "SALOME_ContainerPy --> orb.destroy" +orb.destroy() +print "SALOME_ContainerPy orb.destroyed" + diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 613f3ecf7..0d2e8b9a9 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -30,6 +30,7 @@ #define _SALOME_CONTAINER_I_HXX_ #include +#include #include #include #include @@ -55,12 +56,14 @@ public: bool activ = true); virtual ~Engines_Container_i(); + void destroy() ; + // Launch a new container from the current container - Engines::Container_ptr start_impl(const char* ContainerName); + Engines::Container_ptr start_impl( const char* ContainerName , const Engines::ContainerType ); // Load component in current container - Engines::Component_ptr load_impl(const char* nameToRegister, - const char* componentName); + Engines::Component_ptr load_impl( const char* nameToRegister , + const char* componentName ) ; // Unload component from current container void remove_impl(Engines::Component_ptr component_i); @@ -69,11 +72,12 @@ public: char* name(); char* machineName(); void ping(); + Engines::ContainerType type(); // Kill current container bool Kill_impl() ; char* getHostName(); - long getPID(); + CORBA::Long getPID(); protected: @@ -96,5 +100,7 @@ protected: }; +std::ostream & operator<< (std::ostream &,const Engines::ContainerType &); + #endif diff --git a/src/ContainersManager/ContainersManager_Server.cxx b/src/ContainersManager/ContainersManager_Server.cxx new file mode 100644 index 000000000..2473fcb71 --- /dev/null +++ b/src/ContainersManager/ContainersManager_Server.cxx @@ -0,0 +1,173 @@ +// SALOME ContainersManager +// +// 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 : ContainersManager_Server.cxx +// Author : Jean Rahuel +// Module : SALOME +// $Header: + +#include +#include "SALOME_NamingService.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" + +#include "ContainersManager_i.hxx" + +using namespace std ; + +int main( int argc , char **argv ) { + try { + +// initialize the ORB +#if WITH_SINGLETON + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()) ; + CORBA::ORB_var &orb = init( argc , argv ) ; +#else + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv) ; +#endif + + long TIMESleep = 250000000 ; + int NumberOfTries = 40 ; + int a ; + int i ; + int j ; + timespec ts_req ; + ts_req.tv_nsec=TIMESleep ; + ts_req.tv_sec=0 ; + timespec ts_rem ; + ts_rem.tv_nsec=0 ; + ts_rem.tv_sec=0 ; + +// initialize POA + CosNaming::NamingContext_var inc ; + PortableServer::POA_var poa ; + CORBA::Object_var theObj = CORBA::Object::_nil() ; + CORBA::Object_var obj = CORBA::Object::_nil() ; + CORBA::Object_var object = CORBA::Object::_nil() ; +#if WITH_SINGLETON + SALOME_NamingService &naming = *SINGLETON_::Instance() ; +#else + theObj = orb->resolve_initial_references("NameService"); + inc = CosNaming::NamingContext::_narrow(theObj); +#endif + int CONTAINERS_MANAGER = 0 ; + const char * Env = getenv("USE_LOGGER") ; + int EnvL =0; + if ( ( Env != NULL ) && ( strlen(Env ) ) ) { + EnvL=1 ; + } + CosNaming::Name name ; + name.length( 1 ) ; + name[0].id = CORBA::string_dup("Logger") ; + PortableServer::POAManager_var mgr ; + for ( i = 1 ; i <= NumberOfTries ; i++ ) { + if ( i != 1 ) { + a=nanosleep( &ts_req , &ts_rem ) ; + } + try { + obj = orb->resolve_initial_references( "RootPOA" ) ; + if ( !CORBA::is_nil( obj ) ) { + poa = PortableServer::POA::_narrow( obj ) ; + } + if ( !CORBA::is_nil( poa ) ) { + mgr = poa->the_POAManager() ; + } + if ( !CORBA::is_nil( orb ) ) { + theObj = orb->resolve_initial_references( "NameService" ) ; + } + if ( !CORBA::is_nil( theObj ) ) { + inc = CosNaming::NamingContext::_narrow(theObj) ; + } + } + catch ( CORBA::COMM_FAILURE& ) { + MESSAGE( "ContainersManager : CORBA::COMM_FAILURE: Unable to contact the Naming Service" ) ; + } + if ( !CORBA::is_nil( inc ) ) { + MESSAGE( "ContainersManager : Naming Service was found" ) ; + if ( EnvL == 1 ) { + for ( j = 1 ; j <= NumberOfTries ; j++ ) { + if ( j !=1 ) { + a=nanosleep( &ts_req , &ts_rem ) ; + } + try { + object = inc->resolve( name ) ; + } + catch ( CosNaming::NamingContext::NotFound ) { + MESSAGE( "ContainersManager : Logger Server wasn't found" ) ; + } + catch (...) { + MESSAGE( "ContainersManager : Unknown exception" ) ; + } + if ( !CORBA::is_nil( object ) ) { + MESSAGE( "ContainersManager : Loger Server was found" ) ; + CONTAINERS_MANAGER = 1 ; + break; + } + } + } + } + if ( ( CONTAINERS_MANAGER == 1 ) || ( (EnvL ==0 ) && ( !CORBA::is_nil( inc ) ) ) ) { + break; + } + } + +// initialise Naming Service + SALOME_NamingService *_NS ; + _NS = new SALOME_NamingService( orb ) ; + +// Active ContainersManager +#if WITH_SINGLETON + Manager_i * MyContainersManager = SINGLETON_::Instance() ; + cout << "ContainersManager_Server -> MyContainersManager->Init" << endl ; + MyContainersManager->Init( orb , poa , _NS , argc , argv ) ; +#else + Manager_i * MyContainersManager = new Manager_i() ; + MyContainersManager->Init( orb , poa , _NS , argc , argv ) ; +#endif +// _Id = _Poa->activate_object ( MyContainersManager ) ; + cout << "ContainersManager_Server -> mgr->activate" << endl ; + mgr->activate() ; + CORBA::Object_ptr TheContainersManager = MyContainersManager->_this() ; + +// register ContainersManager in Naming Service + _NS->Register( TheContainersManager , "/Kernel/ContainersManager" ) ; + + MESSAGE("Running ContainersManager Server.") ; + + orb->run(); + + poa->destroy( 1 , 1 ) ; + + orb->destroy(); + + } + catch ( CORBA::SystemException& ) { + INFOS("Caught CORBA::SystemException.") ; + } + catch ( CORBA::Exception& ) { + INFOS("Caught CORBA::Exception.") ; + } + + return 0 ; +} diff --git a/src/ContainersManager/ContainersManager_i.cxx b/src/ContainersManager/ContainersManager_i.cxx new file mode 100644 index 000000000..10fac1063 --- /dev/null +++ b/src/ContainersManager/ContainersManager_i.cxx @@ -0,0 +1,1338 @@ +// SALOME ContainersManager +// +// 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 : ContainersManager_i.cxx +// Author : Jean Rahuel +// Module : SALOME +// $Header: + +#include "Utils_SINGLETON.hxx" + +#include "utilities.h" +#include "ContainersManager_i.hxx" + +using namespace std ; + +Manager_i::Manager_i() { + MESSAGE( "Manager_i::Manager_i default constructor" ) ; +} + +void Manager_i::Init( CORBA::ORB_ptr orb , + PortableServer::POA_ptr poa , + SALOME_NamingService * NamingService , + int argc , + char ** argv ) { + _Orb = CORBA::ORB::_duplicate( orb ) ; + _Poa = PortableServer::POA::_duplicate( poa ) ; + _Id = _Poa->activate_object ( this ) ; + _NamingService = NamingService ; + CORBA::Object_var obj = NamingService->Resolve( "/Kernel/ResourcesManager" ) ; + _ResourcesManager = Resources::Manager::_narrow( obj ) ; + if ( CORBA::is_nil( _ResourcesManager ) ) { + MESSAGE( "Manager_i::Manager_i unable to locate the ResourcesManager in the NamingService" ) ; + exit( 1 ) ; + } + int i ; + i = 0 ; + while ( argv[ i ] ) { + MESSAGE(" argv" << i << " '" << argv[ i ] << "'" ) ; + i++ ; + } + if ( argc == 3 && strcmp( argv[1] , "-ORBInitRef" ) == NULL && + strcmp( argv[2] , "NameService=corbaname::localhost" ) == NULL ) { + string ORBInitRef = &argv[2][23] ; + for ( i = 0 ; i < strlen( ORBInitRef.c_str() ) ; i++ ) { + if ( ORBInitRef[i] == ':' ) { + const char * CPort = ORBInitRef.c_str() ; + int Port ; + sscanf( &CPort[i+1] ,"%d", &_NamingServicePort) ; + ORBInitRef[i] = '\0' ; + _NamingServiceHostName = ORBInitRef ; + } + } + if ( i == strlen( ORBInitRef.c_str() ) ) { + _NamingServiceHostName = ORBInitRef ; + _NamingServicePort = 2809 ; + } + if ( strcmp( _NamingServiceHostName.c_str() , "localhost" ) == 0 ) { + _NamingServiceHostName = GetHostname().c_str() ; + } + } + else { + _NamingServiceHostName = GetHostname().c_str() ; + _NamingServicePort = 2809 ; + system( "netstat -apn | grep -F -e omniNames > /tmp/NsComputer.log" ) ; + ifstream netstat( "/tmp/NsComputer.log" ) ; + string tcp,z,ORBInitRef ; + netstat >> tcp >> z >> z >> ORBInitRef ; + system( "rm -f /tmp/NsComputer.log" ) ; + for ( i = 0 ; i < strlen( ORBInitRef.c_str() ) ; i++ ) { + if ( ORBInitRef[i] == ':' ) { + const char * CPort = ORBInitRef.c_str() ; + int Port ; + sscanf( &CPort[i+1] ,"%d", &_NamingServicePort) ; + MESSAGE( "Manager_i::Manager_i NamingService on " << _NamingServiceHostName.c_str() << " with port " + << _NamingServicePort ) ; + } + } + } + MESSAGE( "Manager_i::Manager_i NamingServiceHostName " << _NamingServiceHostName << " _NamingServicePort " + << _NamingServicePort ) ; + + pthread_mutex_init( &_MutexManager , NULL ) ; + + _ListOfComputers = new Resources::ListOfComputers() ; + _ListOfContainers = new Engines::ListOfContainers() ; + _ListOfComponents = new Engines::ListOfComponents() ; + +} + +void Manager_i::destroy() { + MESSAGE( "Manager_i::destroy" ) ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::destroy MutexManager pthread_mutex_unlock ") ; + } + int i ; + Containers::MachineParameters * MyParams = Parameters() ; + MyParams->ContainerType = Engines::UndefinedContainerType ; + MESSAGE( "Manager_i::destroy components FindComponents :" ) ; + Engines::ListOfComponents_var aListOfEnginesComponents = FindComponents( *MyParams , "" ) ; + MESSAGE( "Manager_i::destroy components FindContainers :" ) ; + Engines::ListOfContainers_var aListOfEnginesContainers = FindContainers( *MyParams ) ; + MESSAGE( "Manager_i::destroy " << aListOfEnginesComponents->length() << " components" ) ; + for ( i = 0 ; i < aListOfEnginesComponents->length() ; i++ ) { + string interfaceName = aListOfEnginesComponents[ i ]->interfaceName() ; + try { + MESSAGE( "Manager_i::destroy trying to destroy Component " << interfaceName ) ; + aListOfEnginesComponents[ i ]->destroy() ; + MESSAGE( "Manager_i::destroy Component " << interfaceName << " destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::destroy Component " << interfaceName << " failed" ) ; + } + } + MESSAGE( "Manager_i::destroy " << aListOfEnginesContainers->length() << " containers" ) ; + for ( i = 0 ; i < aListOfEnginesContainers->length() ; i++ ) { + string aContainerName ; + string aComputerName ; + ostringstream astr ; + try { + aContainerName = aListOfEnginesContainers[ i ]->name() ; + aComputerName = aListOfEnginesContainers[ i ]->machineName() ; + astr << aListOfEnginesContainers[ i ]->getPID() ; + MESSAGE( "Manager_i::destroy trying to destroy Container " << aContainerName ) ; + aListOfEnginesContainers[ i ]->destroy() ; + MESSAGE( "Manager_i::destroy Container " << aContainerName << " destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::destroy destroy of Container " << aContainerName << " failed" ) ; + } + string KillContainer ; + if ( strcmp( aComputerName.c_str() , GetHostname().c_str() ) ) { + if ( _ResourcesManager->SshAccess( aComputerName.c_str() ) ) { + KillContainer = "ssh " ; + } + else { + KillContainer = "rsh " ; + } + KillContainer += aComputerName ; + } + KillContainer += string( "kill " ) ; + KillContainer += astr.str() ; +// KillContainer += " &" ; + int status = system( KillContainer.c_str() ) ; + if ( status == 0 ) { + MESSAGE( "Manager_i::destroy kill of Container " << aContainerName << " " + << KillContainer << " successsed" ) ; + } + else { + MESSAGE( "Manager_i::destroy kill of Container " << aContainerName << " " + << KillContainer << " failed" ) ; + } + } + _Poa->deactivate_object( *_Id ) ; + CORBA::release( _Poa ) ; +#if !WITH_SINGLETON + delete( _Id ) ; + this->_remove_ref(); +#endif + MESSAGE( "Manager_i::destroy NamingService->Destroy_Name /Kernel/ContainersManager" ) ; + _NamingService->Destroy_Name( "/Kernel/ContainersManager" ) ; + MESSAGE( "Manager_i::destroyed" ) ; +} + +Manager_i::~Manager_i() { + MESSAGE( "Manager_i::~Manager_i" ) ; +} + +Containers::MachineParameters * Manager_i::Parameters() { + Containers::MachineParameters_var aMachineParameters = new Containers::MachineParameters() ; + aMachineParameters->with_xterm = 0 ; + aMachineParameters->Os = Containers::Linux ; + aMachineParameters->Memory = 0 ; + aMachineParameters->CpuClock = 0 ; + aMachineParameters->NbProc = 1 ; + aMachineParameters->NbNode = 1 ; + aMachineParameters->HostName = CORBA::string_dup( "" ) ; + aMachineParameters->ContainerName = CORBA::string_dup( "" ) ; + aMachineParameters->ContainerType = Engines::CppContainer ; + aMachineParameters->NsHostName = CORBA::string_dup( _NamingServiceHostName.c_str() ) ; + aMachineParameters->NsPort = _NamingServicePort ; + return aMachineParameters._retn(); +} + +bool Manager_i::ping() { + MESSAGE( "Manager_i::ping" ) ; + return true ; +} + +//string Manager_i::ContainerName( const char * aComputerContainer , +// string * theComputer , +// string * theContainer ) { +// char * ContainerName = new char [ strlen( aComputerContainer ) + 1 ] ; +// strcpy( ContainerName , aComputerContainer ) ; +// string theComputerContainer("/Containers/"); +// char * slash = strchr( ContainerName , '/' ) ; +// if ( !slash ) { +// *theComputer = GetHostname() ; +// theComputerContainer += *theComputer ; +// theComputerContainer += "/" ; +// *theContainer = ContainerName ; +// theComputerContainer += *theContainer ; +// } +// else { +// slash[ 0 ] = '\0' ; +// slash += 1 ; +// *theContainer = slash ; +// if ( !strcmp( ContainerName , "localhost" ) ) { +// *theComputer = GetHostname() ; +// } +// else { +// *theComputer = ContainerName ; +// } +// theComputerContainer += *theComputer ; +// theComputerContainer += "/" ; +// theComputerContainer += *theContainer ; +// } +// if ( strlen( theContainer->c_str() ) == 0 ) { +// theContainer = new string( "FactoryServer" ) ; +// } +// return theComputerContainer ; +//} + + +Engines::ListOfContainers * Manager_i::AllContainers() { + MESSAGE( "Manager_i::AllContainers" ) ; + Engines::ListOfContainers_var aListOfContainers ; + Containers::MachineParameters_var aMachineParameters = Parameters() ; + aMachineParameters->ContainerType = Engines::UndefinedContainerType ; + aListOfContainers = FindContainers( aMachineParameters ) ; + return aListOfContainers._retn() ; +} + + +Engines::Container_ptr Manager_i::FindContainer( const Containers::MachineParameters & myParams ) { + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + Engines::Container_var aContainer = Engines::Container::_nil() ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + MESSAGE( "Manager_i::FindContainer " << MyParams.HostName << " " << MyParams.ContainerName ) ; + MESSAGE( "Manager_i::FindContainer MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindContainer MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindContainer MutexManager pthread_mutex_locked" ) ; + + aContainer = FindContainerLocked( MyParams ) ; + + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindContainer MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindContainer MutexManager pthread_mutex_unlocked" ) ; + return Engines::Container::_duplicate( aContainer ) ; +} + +Engines::Container_ptr Manager_i::FindContainerLocked( Containers::MachineParameters & MyParams ) { + Engines::Container_var aContainer = Engines::Container::_nil() ; + try { + _ListOfContainers = FindContainersLocked( MyParams , false ) ; + _EnginesContainer = Engines::Container::_nil() ; + if ( _ListOfContainers->length() ) { + _EnginesContainer = _ListOfContainers[ 0 ] ; + aContainer = _ListOfContainers[ 0 ] ; + MESSAGE( "Manager_i::FindContainerLocked --> " << aContainer->machineName() << " " + << aContainer->name() ) ; + } + else { + MESSAGE( "Manager_i::FindContainerLocked --> Engines::Container::_nil" ) ; + } + } + catch ( ... ) { + MESSAGE( "Manager_i::FindContainerLocked catched" ) ; + } + return Engines::Container::_duplicate( aContainer ) ; +} + +Engines::Container_ptr Manager_i::FindOneContainer( const char * aHostName , + const char * aContainerName ) { + Containers::MachineParameters * MyParams = Parameters() ; + string theComputer = aHostName ; + string theContainer = aContainerName ; +// ContainerName( aContainerName , &theComputer , &theContainer ) ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + MyParams->ContainerType = Engines::UndefinedContainerType ; + if ( strcmp( MyParams->HostName ,"localhost" ) == 0 ) { + MyParams->HostName = GetHostname().c_str() ; + } + MESSAGE( "Manager_i::FindOneContainer " << MyParams->HostName << " " << MyParams->ContainerName ) ; + Engines::Container_ptr aContainer = FindContainer( *MyParams ) ; + delete MyParams ; + return aContainer ; +} + +Engines::ListOfContainers * Manager_i::FindContainers( const Containers::MachineParameters & myParams ) { + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + MESSAGE( "Manager_i::FindContainers MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindContainersMutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + Engines::ListOfContainers_var aListOfContainers ; + MESSAGE( "Manager_i::FindContainers MutexManager pthread_mutex_locked" ) ; + try { + aListOfContainers = FindContainersLocked( MyParams , false ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::FindContainers catched" ) ; + } +// aListOfContainers->length( _ListOfContainers->length() ) ; +// int i ; +// for ( i = 0 ; i < _ListOfContainers->length() ; i++ ) { +// aListOfContainers[ i ] = Engines::Container::_duplicate( _ListOfContainers[ i ] ) ; +// MESSAGE( "Manager_i::FindContainers " << i << ". " << _ListOfContainers[ i ]->name() ) ; +// } + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindContainers MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindContainers MutexManager pthread_mutex_unlocked" ) ; + return aListOfContainers._retn() ; +} + +Engines::ListOfContainers * Manager_i::FindContainersLocked( Containers::MachineParameters & MyParams , bool _StartContainer ) { + MESSAGE( "Manager_i::FindContainersLocked GetComputers :" ) ; + _ListOfComputers = _ResourcesManager->GetComputers( MyParams ) ; + MESSAGE( "Manager_i::FindContainersLocked " << MyParams.HostName << " " + << MyParams.ContainerName << " " << _ListOfComputers->length() + << " computers found" ) ; + _ListOfContainers = new Engines::ListOfContainers() ; + _ListOfContainers->length( 0 ) ; + int NumberOfComputers = _ListOfComputers->length() ; + if ( NumberOfComputers == 0 ) { + NumberOfComputers = 1 ; + } + int i ; + for ( i = 0 ; i < NumberOfComputers ; i++ ) { + _FullHostName = string( "/Containers/" ) ; + if ( _ListOfComputers->length() ) { + _ResourcesComputer = _ListOfComputers[ i ] ; + _ComputerParameters = _ResourcesComputer->Parameters() ; + _FullHostName += _ComputerParameters->Alias ; + } + else { + _FullHostName += MyParams.HostName ; + } + if ( strlen( MyParams.ContainerName ) ) { + _FullContainerName = _FullHostName + "/" + string( (char * ) MyParams.ContainerName ) ; + _ContainerObject = _NamingService->Resolve( _FullContainerName.c_str() ) ; + MESSAGE( "Manager_i::FindContainersLocked NamingService->Resolve( " + << _FullContainerName << " )" ) ; + if ( !CORBA::is_nil( _ContainerObject ) ) { + try { + _EnginesContainer = Engines::Container::_narrow( _ContainerObject ) ; + _EnginesContainer->ping() ; + } + catch(...) { + _ContainerObject = CORBA::Object::_nil() ; + _EnginesContainer = Engines::Container::_nil() ; + MESSAGE( "Manager_i::FindContainersLocked " << _FullContainerName << " NOT responding" ) ; + } + } + if ( !CORBA::is_nil( _ContainerObject ) ) { + try { + _EnginesContainer = Engines::Container::_narrow( _ContainerObject ) ; + if ( MyParams.ContainerType == Engines::UndefinedContainerType || + _EnginesContainer->type() == MyParams.ContainerType ) { + int size = _ListOfContainers->length() ; + _ListOfContainers->length( size + 1 ) ; + _ListOfContainers[ size ] = Engines::Container::_duplicate( _EnginesContainer ) ; + MESSAGE( "Manager_i::FindContainersLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " " << _EnginesContainer->type() ) ; + } + else { + MESSAGE( "Manager_i::FindContainersLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " " + << _EnginesContainer->type() << " # " + << MyParams.ContainerType ) ; + } + } + catch ( ... ) { + MESSAGE( "Manager_i::FindContainersLocked " << _FullContainerName + << " catched NOT responding " ) ; + } + } + else { + MESSAGE( "Manager_i::FindContainers " << _FullContainerName << " unknown" ) ; + } + } + else { + if ( _NamingService->Change_Directory( _FullHostName.c_str() ) ) { + vector theListOfContainers = _NamingService->list_directory() ; + MESSAGE( "Manager_i::FindContainersLocked " << theListOfContainers.size() + << " containers found." ) ; + int j ; + for ( j = 0 ; j < theListOfContainers.size() ; j++ ) { + _FullContainerName = _FullHostName + "/" + theListOfContainers[ j ] ; + MESSAGE( "Manager_i::FindContainersLocked " << j << " " << _FullContainerName ) ; + _ContainerObject = _NamingService->Resolve( _FullContainerName.c_str() ) ; + if ( !CORBA::is_nil( _ContainerObject ) ) { + try { + _EnginesContainer = Engines::Container::_narrow( _ContainerObject ) ; + _EnginesContainer->ping() ; + if ( MyParams.ContainerType == Engines::UndefinedContainerType || + _EnginesContainer->type() == MyParams.ContainerType ) { + int size = _ListOfContainers->length() ; + _ListOfContainers->length( size + 1 ) ; + _ListOfContainers[ size ] = Engines::Container::_duplicate( _EnginesContainer ); + MESSAGE( "Manager_i::FindContainersLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " " + << _EnginesContainer->type() ) ; + } + else { + MESSAGE( "Manager_i::FindContainersLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " " + << _EnginesContainer->type() << " # " + << MyParams.ContainerType ) ; + _EnginesContainer = Engines::Container::_nil() ; + } + } + catch( ... ) { + MESSAGE( "Manager_i::FindContainersLocked " << _FullContainerName + << " catched NOT responding" ) ; + _EnginesContainer = Engines::Container::_nil() ; + } + } + else { + MESSAGE( "Manager_i::FindContainersLocked " << _FullContainerName + << " unknown" ) ; + } + } + } + else { +// MESSAGE( "Manager_i::FindContainersLocked " << _FullHostName.c_str() +// << " not found in Naming Service" ) ; + } + } + } + return _ListOfContainers._retn() ; +} + +Engines::Container_ptr Manager_i::FindOrStartContainer( const Containers::MachineParameters & myParams ) { + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + if ( MyParams.ContainerType == Engines::UndefinedContainerType ) { + MyParams.ContainerType == Engines::CppContainer ; + } + Engines::Container_var aContainer = Engines::Container::_nil() ; + MESSAGE( "Manager_i::FindOrStartContainer " << MyParams.HostName << " " + << MyParams.ContainerName + << " " << MyParams.ContainerType << " " << MyParams.Os << " " + << MyParams.Memory << " " + << MyParams.CpuClock << " " << MyParams.NbProc << " " + << MyParams.NbNode << " " + << MyParams.NsHostName << " " << MyParams.NsPort ) ; + MESSAGE( "Manager_i::FindOrStartContainer MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindOrStartContainer MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrStartContainer MutexManager pthread_mutex_locked" ) ; + try { + aContainer = FindOrStartContainerLocked( MyParams , "" , true ) ; + } + catch ( ... ) { + MESSAGE("Manager_i::FindOrStartContainer catch") ; + } + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindOrStartContainer MutexManager pthread_nriContainmutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrStartContainer MutexManager pthread_mutex_unlocked" ) ; + return Engines::Container::_duplicate( aContainer ) ; +} + +Engines::Container_ptr Manager_i::FindOrStartContainerLocked( Containers::MachineParameters & myParams , + const char * aComponentName , + bool _StartContainer ) { + _EnginesContainer = Engines::Container::_nil() ; + _EnginesComponent = Engines::Component::_nil() ; + _ListOfComponents = new Engines::ListOfComponents() ; + _ListOfComponents->length( 0 ) ; + MESSAGE( "Manager_i::FindOrStartContainerLocked FindContainersLocked :" ) ; + _ListOfContainers = FindContainersLocked( myParams , _StartContainer ) ; + _ComponentName = aComponentName ; + MESSAGE( "MutexManager FindOrStartContainerLocked " + << _ListOfContainers->length() << " containers found" + << " CORBA::is_nil( _EnginesContainer ) " + << CORBA::is_nil( _EnginesContainer ) ) ; + if ( _ListOfContainers->length() ) { + _EnginesContainer = Engines::Container::_nil() ; + int i ; + for ( i = 0 ; i < _ListOfContainers->length() && ( ( _StartContainer && CORBA::is_nil( _EnginesContainer ) ) || !_StartContainer ) ; i++ ) { + _FullHostName = "/Containers/" ; + char * aHostName = _ListOfContainers[ i ]->machineName() ; + _HostName = string( aHostName ) ; + _FullHostName += _HostName ; + char * aContainerName = _ListOfContainers[ i ]->name() ; + aContainerName = strrchr( aContainerName , '/' ) + 1 ; + _ContainerName = string( aContainerName ) ; + _FullContainerName = _FullHostName + "/" + _ContainerName ; + MESSAGE( "Manager_i::FindOrStartContainerLocked Container " << i << " " + << _FullContainerName + << " searched Component '" << _ComponentName << "'" ) ; + if ( strlen( _ComponentName.c_str() ) ) { + _FullComponentName = _FullContainerName + "/" + _ComponentName ; + MESSAGE( "Manager_i::FindOrStartContainerLocked Component " + << _FullComponentName ) ; + _ComponentObject = _NamingService->Resolve( _FullComponentName.c_str() ) ; + if ( !CORBA::is_nil( _ComponentObject ) ) { + _EnginesContainer = _ListOfContainers[ i ] ; + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " Component " + << _ComponentName ) ; + try { + _EnginesComponent = Engines::Component::_duplicate( Engines::Component::_narrow( _ComponentObject ) ) ; + _EnginesComponent->ping() ; + int size = _ListOfComponents->length() ; + _ListOfComponents->length( size + 1 ) ; + _ListOfComponents[ size ] = Engines::Component::_duplicate( _EnginesComponent ) ; + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesComponent->instanceName() << " " + << _EnginesComponent->interfaceName() ) ; + } + catch( ... ) { + _EnginesComponent = Engines::Component::_nil() ; + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << myParams.HostName << " " + << myParams.ContainerName << " " << _ComponentName + << " NOT responding" ) ; + } + } + else { + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << myParams.HostName << " " + << myParams.ContainerName << " " << _ComponentName + << " NOT found" ) ; + } + } + else { + _EnginesContainer = _ListOfContainers[ i ] ; + if ( _NamingService->Change_Directory( _FullContainerName.c_str() ) ) { + vector theListOfComponents = _NamingService->list_directory() ; + MESSAGE( "Manager_i::FindOrStartContainerLocked " << theListOfComponents.size() + << " components found." ) ; + int j ; + for ( j = 0 ; j < theListOfComponents.size() ; j++ ) { + _FullComponentName = _FullContainerName + "/" + theListOfComponents[ j ] ; + MESSAGE( "Manager_i::FindOrStartContainerLocked " << j + << " Component " << _FullComponentName ) ; + _ComponentObject = _NamingService->Resolve( _FullComponentName.c_str() ) ; + if ( !CORBA::is_nil( _ComponentObject ) ) { + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() ) ; + try { + _EnginesComponent = Engines::Component::_duplicate( Engines::Component::_narrow( _ComponentObject ) ) ; + _EnginesComponent->ping() ; + int size = _ListOfComponents->length() ; + _ListOfComponents->length( size + 1 ) ; + _ListOfComponents[ size ] = Engines::Component::_duplicate( _EnginesComponent ) ; + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesComponent->instanceName() + << " " << _EnginesComponent->interfaceName() ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::FindOrStartContainerLocked catched NOT responding" ) ; + _EnginesComponent = Engines::Component::_nil() ; + } + } + } + } + } + } + } + else if ( !CORBA::is_nil( _EnginesContainer ) && strlen( _ComponentName.c_str() ) ) { + _FullComponentName = _FullContainerName + "/" + _ComponentName ; + MESSAGE( "Manager_i::FindOrStartContainerLocked Component " + << _FullComponentName ) ; + _ComponentObject = _NamingService->Resolve( _FullComponentName.c_str() ) ; + if ( !CORBA::is_nil( _ComponentObject ) ) { + try { + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesContainer->machineName() << " " + << _EnginesContainer->name() << " Component " + << _FullComponentName ) ; + _EnginesComponent = Engines::Component::_duplicate( Engines::Component::_narrow( _ComponentObject ) ) ; + _EnginesComponent->ping() ; + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << _EnginesComponent->instanceName() << " " + << _EnginesComponent->interfaceName() ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " + << myParams.HostName << " " + << myParams.ContainerName << " " << _ComponentName + << " catched NOT responding" ) ; + _EnginesComponent = Engines::Component::_nil() ; + } + } + else { + MESSAGE( "Manager_i::FindOrStartContainerLocked --> " << myParams.HostName + << " " << myParams.ContainerName << " " << _ComponentName + << " NOT found" ) ; + } + } + if ( CORBA::is_nil( _EnginesContainer ) && _StartContainer ) { + if ( _ListOfContainers->length() ) { + _EnginesContainer = _ListOfContainers[ 0 ] ; + } + else { + StartContainer( myParams ) ; + } + if ( strlen( _ComponentName.c_str() ) ) { + _FullComponentName = _FullContainerName + "/" + _ComponentName ; + } + } + MESSAGE( "return from FindOrStartContainerLocked " ) ; + return Engines::Container::_duplicate( _EnginesContainer ) ; +} + +Engines::Container_ptr Manager_i::StartContainer( const Containers::MachineParameters & myParams ) { + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + MESSAGE( "Manager_i::StartContainer HostName '" << MyParams.HostName + << "' ContainerName '" << MyParams.ContainerName << "'" ) ; + if ( _ListOfContainers->length() ) { + MyParams.HostName = CORBA::string_dup( _ListOfContainers[ 0 ]->machineName() ) ; + char * aContainerName = _ListOfContainers[ 0 ]->name() ; + aContainerName = strrchr( aContainerName , '/' ) + 1 ; + MyParams.ContainerName = CORBA::string_dup( aContainerName ) ; + } + else if ( _ListOfComputers->length() ) { + Resources::Computer_var aComputer = _ResourcesManager->GetComputer( _ListOfComputers ) ; + if ( !CORBA::is_nil( aComputer ) ) { + MyParams.HostName = CORBA::string_dup( aComputer->Alias() ) ; + } + if ( strlen( MyParams.ContainerName ) == 0 ) { + if ( MyParams.ContainerType == Engines::CppContainer ) { + MyParams.ContainerName = "FactoryServer" ; + } + else { + MyParams.ContainerName = "FactoryServerPy" ; + } + } + Containers::MachineParameters MyContainerParams = MyParams ; + MyContainerParams.ContainerName = "" ; + FindContainerLocked( MyContainerParams ) ; + } + MESSAGE( "Manager_i::StartContainer MyParams " << MyParams.HostName << " " + << MyParams.ContainerName << " " << MyParams.ContainerType << " " + << MyParams.Os << " " << MyParams.Memory << " " << MyParams.CpuClock + << " " << MyParams.NbProc << " " << MyParams.NbNode << " " + << MyParams.NsHostName << " " << MyParams.NsPort << " " + << _ListOfContainers->length() << " containers " << _ListOfComputers->length() + << " computers localhost " << GetHostname().c_str() ) ; + _ResourcesComputer = _ResourcesManager->SearchComputer( MyParams.HostName ) ; + if ( CORBA::is_nil( _EnginesContainer ) ) { + Resources::ComputerEnvironment * aComputerEnvironment = NULL ; + if ( !CORBA::is_nil( _ResourcesComputer ) ) { + aComputerEnvironment = _ResourcesComputer->Environment() ; + } + string rsh( "" ) ; + char * HostName = MyParams.HostName ; + MESSAGE( "Manager_i::StartContainer MyParams '" << MyParams.HostName + << "' GetHostname '" << GetHostname().c_str() << "'" ) ; + if ( strcmp( HostName , GetHostname().c_str() ) ) { + if ( aComputerEnvironment == NULL || _ResourcesManager->SshAccess( HostName ) ) { + rsh += "ssh " ; + } + else { + rsh += "rsh " ; + } + if ( !CORBA::is_nil( _ResourcesComputer ) ) { + string aUserName = _ResourcesManager->UserName( HostName ) ; + if ( aUserName.length() ) { + rsh += "-l " ; + rsh += aUserName ; + rsh += " " ; + } + } + rsh += MyParams.HostName ; + rsh += " sh -c \"'" ; + if ( aComputerEnvironment != NULL ) { + int size = aComputerEnvironment->Module_Root_Dir_Names.length() ; + int i ; +// bool GeomModule = false ; + for ( i = 0 ; i < size ; i++ ) { + if ( i > 0 ) { + rsh += " ; " ; + } + rsh += aComputerEnvironment->Module_Root_Dir_Names[ i ] ; +// if ( strcmp( aComputerEnvironment->Module_Root_Dir_Names[ i ] , "GEOM_ROOT_DIR" ) == 0 ) { +// GeomModule = true ; +// } + rsh += "=" ; + rsh += aComputerEnvironment->Module_Root_Dir_Values[ i ] ; + rsh += " ; export " ; + rsh += aComputerEnvironment->Module_Root_Dir_Names[ i ] ; + } + if ( size > 0 ) { + rsh += " ; " ; + } +// rsh += "${PRODUCTS_ROOT_DIR}/env_products.sh ; " ; + rsh += "${KERNEL_ROOT_DIR}/env_products.sh ; " ; // Pour l'instant + rsh += "${KERNEL_ROOT_DIR}/env_modules.sh ; " ; +// rsh += "PATH=" ; +// int j ; +// string Path = (char * ) aComputerEnvironment->Path ; +// for ( j = 0 ; j < Path.size() ; j++ ) { +// if ( Path[ j ] == '$' ) { +// rsh += "\\" ; +// } +// rsh += Path[ j ] ; +// } +// rsh += " ; export PATH" ; +// rsh += " ; LD_LIBRARY_PATH=" ; +// string Ld_Library_Path = (char * ) aComputerEnvironment->Ld_Library_Path ; +// for ( j = 0 ; j < Ld_Library_Path.size() ; j++ ) { +// if ( Ld_Library_Path[ j ] == '$' ) { +// rsh += "\\" ; +// } +// rsh += Ld_Library_Path[ j ] ; +// } +// rsh += " ; export LD_LIBRARY_PATH" ; +// rsh += " ; PYTHONPATH=" ; +// string PythonPath = (char * ) aComputerEnvironment->PythonPath ; +// for ( j = 0 ; j < PythonPath.size() ; j++ ) { +// if ( PythonPath[ j ] == '$' ) { +// rsh += "\\" ; +// } +// rsh += PythonPath[ j ] ; +// } +// rsh += " ; export PYTHONPATH" ; +// rsh += " ; CASROOT=" ; +// rsh += aComputerEnvironment->CasRoot ; +// rsh += " ; export CASROOT" ; +// rsh += " ; CSF_PluginDefaults=" ; +// rsh += "\\" ; +// rsh += "${KERNEL_ROOT_DIR}/share/salome/resources" ; +// rsh += " ; export CSF_PluginDefaults" ; +// rsh += " ; CSF_SALOMEDS_ResourcesDefaults=" ; +// rsh += "\\" ; +// rsh += "${KERNEL_ROOT_DIR}/share/salome/resources" ; +// rsh += " ; export CSF_SALOMEDS_ResourcesDefaults" ; +// if ( GeomModule ) { +// rsh += " ; CSF_GEOMDS_ResourcesDefaults=" ; +// rsh += "\\" ; +// rsh += "${GEOM_ROOT_DIR}/share/salome/resources" ; +// rsh += " ; export CSF_GEOMDS_ResourcesDefaults" ; +// } +// rsh += " ; " ; + } + } + if ( MyParams.ContainerType == Engines::CppContainer || MyParams.ContainerType == Engines::UndefinedContainerType ) { + rsh += "SALOME_Container " ; + } + else if ( MyParams.ContainerType == Engines::PythonContainer ) { + rsh += "SALOME_ContainerPy.py " ; + } + rsh += MyParams.ContainerName ; + rsh += " -ORBInitRef NameService=corbaname::" ; + rsh += MyParams.NsHostName ; + if ( MyParams.NsPort != 0 ) { + rsh += ":" ; + ostringstream astr ; + astr << MyParams.NsPort ; + rsh += astr.str().c_str() ; + } + rsh += " > /tmp/" ; +//CCRT char * tmpdir = getenv( "TMPDIR" ) ; +//CCRT rsh += " > " ; +//CCRT if ( tmpdir ) { +//CCRT rsh += tmpdir ; +//CCRT rsh += "/" ; +//CCRT } +//CCRT else { +//CCRT rsh += "/tmp/" ; +//CCRT } + rsh += MyParams.ContainerName ; + if ( MyParams.ContainerType == Engines::CppContainer || MyParams.ContainerType == Engines::UndefinedContainerType ) { + rsh += "_Cpp_" ; + } + else if ( MyParams.ContainerType == Engines::PythonContainer ) { + rsh += "_Py_" ; + } + rsh += MyParams.HostName ; + rsh += ".log 2>&1 " ; + if ( strcmp( HostName , GetHostname().c_str() ) ) { + rsh += "'\"" ; + } + rsh += " &" ; + cout << endl << endl << "Manager_i::StartContainer " << rsh << endl << endl ; + MESSAGE( "Manager_i::StartContainer " << rsh ) ; + int status = system( rsh.c_str() ) ; + if (status == -1) { + INFOS("StartContainer rsh/ssh failed (system command status -1)") ; + } + else if (status == 217) { + INFOS("StartContainer rsh/ssh failed (system command status 217)") ; + } + else { + int count = 21 ; + while ( CORBA::is_nil( _EnginesContainer ) && count ) { + sleep( 1 ) ; + count-- ; + if ( count != 21 ) { + MESSAGE( "StartContainer" << count << ". Waiting for " + << MyParams.ContainerName << " on " << MyParams.HostName ) ; + } + FindContainersLocked( MyParams , false ) ; + } + if ( CORBA::is_nil( _EnginesContainer ) ) { + INFOS("StartContainer rsh/ssh failed " ) ; + } + } + } + else { + MESSAGE( "Manager_i::StartContainer -> Container start_impl( " << _EnginesContainer->name() << ") for " + << MyParams.ContainerName ) ; + _EnginesContainer = _EnginesContainer->start_impl( MyParams.ContainerName , MyParams.ContainerType ) ; + } + return Engines::Container::_duplicate( _EnginesContainer ) ; +} + +Engines::ListOfComponents * Manager_i::AllComponents() { + MESSAGE( "Manager_i::AllComponents" ) ; + Engines::ListOfComponents_var aListOfComponents ; + Containers::MachineParameters_var aMachineParameters = Parameters() ; + aMachineParameters->ContainerType = Engines::UndefinedContainerType ; + aListOfComponents = FindComponents( aMachineParameters , "" ) ; + return aListOfComponents._retn() ; +} + +Engines::Component_ptr Manager_i::FindComponent( const Containers::MachineParameters & myParams , + const char * ComponentName ) { + MESSAGE( "Manager_i::FindComponent MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindComponent MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindComponent MutexManager pthread_mutex_locked" ) ; + Engines::Component_ptr aComponent = Engines::Component::_nil() ; + try { + aComponent = FindComponentLocked( myParams , ComponentName , false ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::FindComponent catched" ) ; + } + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindComponent MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindComponent MutexManager pthread_mutex_unlocked" ) ; + return aComponent ; +} + +Engines::Component_ptr Manager_i::FindComponentLocked( const Containers::MachineParameters & myParams , + const char * ComponentName , + bool _StartContainer ) { + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + MESSAGE( "FindComponentLocked HostName " << MyParams.HostName + << " ContainerName " << MyParams.ContainerName + << " ComponentName " << ComponentName ) ; + FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName , _StartContainer ) ; + if ( CORBA::is_nil( _EnginesComponent ) ) { + MESSAGE( "FindComponentLocked ComponentName " << ComponentName << " NOT found" ) ; + } + else { + MESSAGE( "FindComponentLocked instanceName " << _EnginesComponent->instanceName() + << " interfaceName " << _EnginesComponent->interfaceName() ) ; + } + return Engines::Component::_duplicate( _EnginesComponent ) ; +} + +Engines::Component_ptr Manager_i::FindOneComponent( const char * aHostName , + const char * aContainerName , + const char * ComponentName ) { + Containers::MachineParameters * MyParams = Parameters() ; + string theComputer = aHostName ; + string theContainer = aContainerName ; +// ContainerName( aContainerName , &theComputer , &theContainer ) ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + MyParams->ContainerType = Engines::UndefinedContainerType ; + if ( strcmp( MyParams->HostName ,"localhost" ) == 0 ) { + MyParams->HostName = GetHostname().c_str() ; + } + MESSAGE( "Manager_i::FindOneComponent HostName " << MyParams->HostName + << " ContainerName " << MyParams->ContainerName + << " ComponentName " << ComponentName ) ; + MESSAGE( "Manager_i::FindOneComponent MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindOneComponent MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOneComponent MutexManager pthread_mutex_locked" ) ; + Engines::Component_ptr aComponent = FindComponentLocked( *MyParams , ComponentName , false ) ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindOneComponent MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOneComponent MutexManager pthread_mutex_unlocked" ) ; + delete MyParams ; + return aComponent ; +} + +Engines::ListOfComponents * Manager_i::FindComponents( const Containers::MachineParameters & myParams , + const char * ComponentName ) { + MESSAGE( "FindComponents HostName " << myParams.HostName << " ContainerName " + << myParams.ContainerName + << " ComponentName " << ComponentName ) ; + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + MESSAGE( "FindComponents HostName " << MyParams.HostName << " ContainerName " + << MyParams.ContainerName + << " ComponentName " << ComponentName ) ; + MESSAGE( "Manager_i::FindComponents MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindComponents MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindComponents MutexManager pthread_mutex_locked" ) ; + Engines::ListOfComponents_var aListOfComponents = FindComponentsLocked( MyParams , ComponentName ) ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindComponents MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindComponents MutexManager pthread_mutex_unlocked" ) ; + return aListOfComponents._retn() ; +} + + +Engines::ListOfComponents * Manager_i::FindComponentsLocked( const Containers::MachineParameters & MyParams , + const char * ComponentName ) { + Engines::ListOfComponents_var aListOfComponents = new Engines::ListOfComponents() ; + try { + MESSAGE( "Manager_i::FindComponentsLocked FindOrStartContainerLocked :" ) ; + _EnginesContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName , false ) ; + if ( _ListOfComponents->length() ) { + MESSAGE( "FindComponentsLocked " << _ListOfComponents->length() << " components" ) ; + int i ; + for ( i = 0 ; i < _ListOfComponents->length() ; i++ ) { + MESSAGE( "FindComponentsLocked " << i << " instanceName " + << _ListOfComponents[ i ]->instanceName() + << " interfaceName " << _ListOfComponents[ i ]->interfaceName() ) ; + _ListOfComponents[ i ]->ping() ; + } + } + else if ( !CORBA::is_nil( _EnginesComponent ) ) { + _ListOfComponents->length( 1 ) ; + _ListOfComponents[ 0 ] = Engines::Component::_duplicate( _EnginesComponent ) ; + MESSAGE( "FindComponentsLocked instanceName " + << _EnginesComponent->instanceName() << " interfaceName " + << _EnginesComponent->interfaceName() << " " + << _ListOfComponents->length() << " components" ) ; + _ListOfComponents[ 0 ]->ping() ; + } + else { + MESSAGE( "FindComponentsLocked ComponentName " << ComponentName + << " NOT found" ) ; + } + aListOfComponents = _ListOfComponents ; + } + catch ( ... ) { + MESSAGE( "Manager_i::FindComponentsLocked catched" ) ; + } + return aListOfComponents._retn() ; +} + + +Engines::Component_ptr Manager_i::FindOrLoad_ComponentPath( const Containers::MachineParameters & myParams , + const char * ComponentName , + const char * ImplementationPath ) { + Engines::Container_var aContainer = Engines::Container::_nil() ; + Engines::Component_var EnginesComponent = Engines::Component::_nil() ; + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + BEGIN_OF("FindOrLoad_Component( const Containers::MachineParameters & MyParams , const char * ComponentName , const char * ImplementationPath 1)"); + MESSAGE( "Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_locked" ) ; + try { + EnginesComponent = FindComponentLocked( MyParams , ComponentName , true ) ; + if ( CORBA::is_nil( EnginesComponent ) ) { + MESSAGE("FindOrLoad_ComponentPath Component not found " << _ComponentName ) ; +// aContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; + } + else { + MESSAGE("FindOrLoad_ComponentPath Component was found " << _ComponentName ) ; + } + aContainer = _EnginesContainer ; + } + catch ( ... ) { + MESSAGE("FindOrLoad_ComponentPath catch") ; + } + string aComponentName = _ComponentName ; + string aFullComponentName = _FullComponentName ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_unlocked" ) ; + if ( !CORBA::is_nil( aContainer ) && CORBA::is_nil( EnginesComponent ) ) { + MESSAGE("FindOrLoad_ComponentPath Component not found ! trying to load " + << aFullComponentName ) ; + EnginesComponent = aContainer->load_impl( ComponentName, ImplementationPath ) ; + if ( !CORBA::is_nil( EnginesComponent ) ) { + MESSAGE( "FindOrLoad_ComponentPath Component launched ! " + << aFullComponentName ) ; + try { + EnginesComponent->ping() ; + } + catch ( CORBA::COMM_FAILURE& ) { + INFOS("FindOrLoad_ComponentPath Caught CORBA::SystemException CommFailure. Engine " + << aFullComponentName << "does not respond" ) ; + EnginesComponent = Engines::Component::_nil() ; + } + } + else { + MESSAGE( "FindOrLoad_ComponentPath Component NOT launched ! " + << aFullComponentName ) ; + } + } + return Engines::Component::_duplicate( EnginesComponent ) ; +} + +Engines::Component_ptr Manager_i::FindOrLoad_Component( const Containers::MachineParameters & myParams , + const char * ComponentName ) { + Engines::Container_var aContainer = Engines::Container::_nil() ; + Engines::Component_var EnginesComponent = Engines::Component::_nil() ; + Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + if ( !strcmp( MyParams.ContainerName , "" ) && + MyParams.ContainerType == Engines::UndefinedContainerType ) { + MyParams.ContainerType = Engines::CppContainer ; + } + BEGIN_OF("FindOrLoad_Component HostName " << MyParams.HostName << " ContainerName " + << MyParams.ContainerName << " ContainerType " << MyParams.ContainerType + << " ComponentName " << ComponentName ); + MESSAGE( "Manager_i::FindOrLoad_Component MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::FindOrLoad_Component MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrLoad_Component MutexManager pthread_mutex_locked" ) ; + try { + EnginesComponent = FindComponentLocked( MyParams , ComponentName , true ) ; + if ( CORBA::is_nil( EnginesComponent ) ) { + MESSAGE("FindOrLoad_Component Component not found " << _FullComponentName ) ; +// aContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; + } + else { + MESSAGE("FindOrLoad_Component Component was found " << _FullComponentName ) ; + } + aContainer = _EnginesContainer ; + } + catch ( ... ) { + MESSAGE("FindOrLoad_Component catch") ; + } + string aComponentName = _ComponentName ; + string aFullComponentName = _FullComponentName ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::FindOrLoad_Component MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindOrLoad_Component MutexManager pthread_mutex_unlocked" ) ; + if ( !CORBA::is_nil( aContainer ) && CORBA::is_nil( EnginesComponent ) ) { + string ImplementationPath ; + if ( MyParams.ContainerType == Engines::PythonContainer ) { + ImplementationPath += ComponentName ; + } + else { + ImplementationPath += string( "lib" ) ; + ImplementationPath += ComponentName ; + ImplementationPath += "Engine.so" ; + } + MESSAGE("FindOrLoad_Component Component not found ! trying to load " + << aFullComponentName << " " << ImplementationPath ) ; + try { + EnginesComponent = aContainer->load_impl( ComponentName, ImplementationPath.c_str() ) ; + if ( !CORBA::is_nil( EnginesComponent ) ) { + MESSAGE( "FindOrLoad_Component Component launched ! " << _ComponentName + << " on " << aFullComponentName ) ; + try { + EnginesComponent->ping() ; + } + catch ( CORBA::COMM_FAILURE& ) { + INFOS("FindOrLoad_Component Caught CORBA::SystemException CommFailure. Engine " + << aFullComponentName << "does not respond" ) ; + EnginesComponent = Engines::Component::_nil() ; + } + } + else { + MESSAGE( "FindOrLoad_Component Component NOT launched ! " + << aFullComponentName ) ; + } + } + catch (...) { + EnginesComponent = Engines::Component::_nil() ; + MESSAGE( "Component NOT launched ! " << aFullComponentName << " load_impl catched" ) ; + } + } + return Engines::Component::_duplicate( EnginesComponent ) ; +} +// try { +// CORBA::Object_var obj = _NS->Resolve(path.c_str()); +// if ( CORBA::is_nil( obj ) ) { +// MESSAGE("Component not found ! trying to load " << path); +// CORBA::Object_var obj2 = _NS->Resolve("/Kernel/ModulCatalog"); +// SALOME_ModuleCatalog::ModuleCatalog_var Catalog = +// SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj2); + +// SALOME_ModuleCatalog::Acomponent_ptr compoInfo = +// Catalog->GetComponent(componentName); +// if (CORBA::is_nil (compoInfo)) +// { +// INFOS("Catalog Error : Component not found in the catalog") +// return Engines::Component::_nil(); +// exit (-1); +// } + +// string path; +// try +// { +// path = compoInfo->GetPathPrefix( machine ) ; +// path += "/" ; +// } +// catch (SALOME_ModuleCatalog::NotFound&) +// { +// MESSAGE("GetPathPrefix(" << machine << ") not found!" +// << "trying localhost"); +// try { +// path = compoInfo->GetPathPrefix("localhost") ; +// path += "/" ; +// } +// catch (SALOME_ModuleCatalog::NotFound&) { +// MESSAGE("GetPathPrefix(localhost) not found!") ; +// path = "" ; +// } +// } + +// SCRUTE(path); +// string implementation(path); +// implementation += "lib"; +// implementation += componentName; +// implementation += "Engine.so"; + +// Engines::Component_var compo +// = cont->load_impl(componentName, implementation.c_str()); + +// ASSERT(!CORBA::is_nil(compo)); +// MESSAGE("Component launched !" << path); +// return compo; +// } +// else +// { +// MESSAGE("Component found !" << path); +// Engines::Component_var compo = Engines::Component::_narrow(obj); +// ASSERT(!CORBA::is_nil(compo)); +// try +// { +// string instanceName = compo->instanceName(); +// } +// catch (CORBA::COMM_FAILURE&) +// { +// INFOS("Caught CORBA::SystemException CommFailure. Engine " +// << path << "does not respond" ); +// } +// return compo; +// } +// } +// catch (ServiceUnreachable&) +// { +// INFOS("Caught exception: Naming Service Unreachable"); +// } +// catch (...) +// { +// INFOS("Caught unknown exception."); +// } +// return Engines::Component::_nil(); +//} + +bool Manager_i::DestroyContainer( const char * aHostName , + const char * aContainerName ) { + Containers::MachineParameters * MyParams = Parameters() ; + string theComputer = aHostName ; + string theContainer = aContainerName ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + int l = strlen( aContainerName ) ; + MyParams->ContainerType = Engines::UndefinedContainerType ; + if ( strcmp( MyParams->HostName ,"localhost" ) == 0 ) { + MyParams->HostName = GetHostname().c_str() ; + } + MESSAGE( "Manager_i::DestroyContainer HostName " << MyParams->HostName + << " ContainerName " << MyParams->ContainerName ) ; + MESSAGE( "Manager_i::DestroyContainer MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::DestroyContainer MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::DestroyContainer MutexManager pthread_mutex_locked" ) ; + Engines::ListOfComponents_var aListOfComponents = FindComponentsLocked( *MyParams , "" ) ; + Engines::Container_ptr aContainer = _EnginesContainer ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::DestroyContainer MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::DestroyContainer MutexManager pthread_mutex_unlocked" ) ; + int i ; + for ( i = 0 ; i < aListOfComponents->length() ; i++ ) { + try { + MESSAGE( "Manager_i::DestroyContainer trying to destroy component " + << aListOfComponents[ i ]->interfaceName() ) ; + aListOfComponents[ i ]->ping() ; + aListOfComponents[ i ]->destroy() ; + MESSAGE( "Manager_i::DestroyContainer component destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::DestroyContainer destroy component catched" ) ; + } + } + try { + MESSAGE( "Manager_i::DestroyContainer trying to destroy container " << aContainer->name() ) ; + aContainer->ping() ; + aContainer->destroy() ; + MESSAGE( "Manager_i::DestroyContainer " << aContainerName << " on " << aHostName + << " destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::DestroyContainer " << aContainerName << " on " << aHostName + << " catched" ) ; + } + delete MyParams ; + return true ; +} + +bool Manager_i::DestroyContainers( const Containers::MachineParameters & MyParams ) { + MESSAGE( "Manager_i::DestroyContainers HostName " << MyParams.HostName + << " ContainerName " << MyParams.ContainerName ) ; + MESSAGE( "Manager_i::DestroyContainers MutexManager pthread_mutex_lock :" ) ; + if ( pthread_mutex_lock( &_MutexManager ) ) { + perror("Manager_i::DestroyContainers MutexManager pthread_mutex_lock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::DestroyContainers MutexManager pthread_mutex_locked" ) ; + Engines::ListOfComponents_var aListOfComponents = FindComponentsLocked( MyParams , "" ) ; + Engines::ListOfContainers_var aListOfContainers = _ListOfContainers ; + if ( pthread_mutex_unlock( &_MutexManager ) ) { + perror("Manager_i::DestroyContainers MutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::DestroyContainers MutexManager pthread_mutex_unlocked" ) ; + int i ; + for ( i = 0 ; i < aListOfComponents->length() ; i++ ) { + try { + aListOfComponents[ i ]->destroy() ; + MESSAGE( "Manager_i::DestroyContainers component destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::DestroyContainers destroy component catched" ) ; + } + } + for ( i = 0 ; i < aListOfContainers->length() ; i++ ) { + try { + MESSAGE( "Manager_i::DestroyContainers destroy of " << aListOfContainers[ i ]->name() ) ; + aListOfContainers[ i ]->destroy() ; + } + catch ( ... ) { + MESSAGE( "Manager_i::DestroyContainers catched" ) ; + } + } + return true ; +} + +ostream & operator<< (ostream & f ,const Engines::ContainerType & t ) { + switch (t) { + case Engines::UndefinedContainerType : + f << "UndefinedContainer"; + break; + case Engines::CppContainer : + f << "CppContainer"; + break; + case Engines::PythonContainer : + f << "PythonContainer"; + break; + default : + f << "UnknownContainerType"; + break; + } + + return f; +} + diff --git a/src/ContainersManager/ContainersManager_i.hxx b/src/ContainersManager/ContainersManager_i.hxx new file mode 100644 index 000000000..2613cbf5d --- /dev/null +++ b/src/ContainersManager/ContainersManager_i.hxx @@ -0,0 +1,162 @@ +// SALOME ContainersManager +// +// 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 : ContainersManager_i.hxx +// Author : Jean Rahuel +// Module : SALOME +// $Header: + +#ifndef __CONTAINERSMANAGER_I_HXX__ +#define __CONTAINERSMANAGER_I_HXX__ + +// std C++ headers +#include +#include +#include +#include +#include +#include +#include + +#include "utilities.h" +#include "OpUtil.hxx" + +#include + +#include "SALOME_NamingService.hxx" + +// IDL headers +#include +#include CORBA_SERVER_HEADER(ContainersManager) +#include CORBA_SERVER_HEADER(ResourcesManager) +#include CORBA_CLIENT_HEADER(SALOME_Component) + + +// use of normal destroy xor of ATEXIT +#define WITH_SINGLETON 1 + + + +class Manager_i : public POA_Containers::Manager , + public PortableServer::RefCountServantBase { + private: + + CORBA::ORB_ptr _Orb ; + PortableServer::POA_ptr _Poa ; + PortableServer::ObjectId * _Id ; + SALOME_NamingService * _NamingService ; + Resources::Manager_var _ResourcesManager ; + string _NamingServiceHostName ; + long _NamingServicePort ; + pthread_mutex_t _MutexManager ; + string _HostName ; + string _FullHostName ; + string _ContainerName ; + string _FullContainerName ; + Engines::ContainerType _ContainerType ; + string _ComponentName ; + string _FullComponentName ; + Resources::ListOfComputers_var _ListOfComputers ; + Resources::Computer_var _ResourcesComputer ; + Resources::ComputerParameters_var _ComputerParameters ; + Engines::ListOfContainers_var _ListOfContainers ; + CORBA::Object_var _ContainerObject ; + Engines::Container_var _EnginesContainer ; + Engines::ListOfComponents_var _ListOfComponents ; + CORBA::Object_var _ComponentObject ; + Engines::Component_var _EnginesComponent ; + + Engines::Container_ptr FindContainerLocked( Containers::MachineParameters & MyParams ) ; + Engines::Container_ptr StartContainer( const Containers::MachineParameters & myParams ) ; + + Engines::ListOfContainers * FindContainersLocked( Containers::MachineParameters & MyParams , bool _StartContainer ) ; + + Engines::Container_ptr FindOrStartContainerLocked( Containers::MachineParameters & MyParams , + const char * ComponentName , + bool _StartContainer ) ; + + Engines::Component_ptr FindComponentLocked( const Containers::MachineParameters & MyParams , + const char * ComponentName , + bool _StartContainer ) ; + + Engines::ListOfComponents * FindComponentsLocked( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + + public: + + Manager_i() ; + + void Init( CORBA::ORB_ptr orb , + PortableServer::POA_ptr poa , + SALOME_NamingService * NamingService , + int argc , + char** argv ) ; + + virtual ~Manager_i() ; + + virtual void destroy() ; + + virtual bool ping() ; + + virtual Engines::ListOfContainers * AllContainers() ; + + virtual Containers::MachineParameters * Parameters() ; + + virtual Engines::Container_ptr FindContainer( const Containers::MachineParameters & MyParams ) ; + + virtual Engines::Container_ptr FindOneContainer( const char * aHostName , + const char * aContainerName ) ; + + virtual Engines::ListOfContainers * FindContainers( const Containers::MachineParameters & MyParams ) ; + + virtual Engines::Container_ptr FindOrStartContainer( const Containers::MachineParameters & MyParams ) ; + + virtual Engines::ListOfComponents * AllComponents() ; + + virtual Engines::Component_ptr FindComponent( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + + virtual Engines::Component_ptr FindOneComponent( const char * aHostName , + const char * aContainerName , + const char * ComponentName ) ; + + virtual Engines::ListOfComponents * FindComponents( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + + virtual Engines::Component_ptr FindOrLoad_ComponentPath( const Containers::MachineParameters & MyParams , + const char * ComponentName , + const char * ImplementationPath ) ; + + virtual Engines::Component_ptr FindOrLoad_Component( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + + virtual bool DestroyContainer( const char * aHostName , + const char * aContainerName ) ; + + virtual bool DestroyContainers( const Containers::MachineParameters & MyParams ) ; + +} ; + +ostream & operator<< (ostream &,const Engines::ContainerType &); + +#endif diff --git a/src/ContainersManager/Makefile.in b/src/ContainersManager/Makefile.in new file mode 100755 index 000000000..995989910 --- /dev/null +++ b/src/ContainersManager/Makefile.in @@ -0,0 +1,58 @@ +# SALOME ContainersManager : data structure of SALOME and sources of Salome data server +# +# 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 : Jean Rahuel +# Module : SALOME + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl:$(top_srcdir)/idl + + +@COMMENCE@ + +EXPORT_PYSCRIPTS = runContainer.py ResourcesContainers.py TestContainersManager.py + +# Libraries targets + +LIB = libContainersManager.la +LIB_SRC = \ + ContainersManager_i.hxx \ + ContainersManager_i.cxx +# Executables targets +BIN = ContainersManager_Server +BIN_SRC = + +LIB_SERVER_IDL = ResourcesManager.idl ContainersManager.idl SALOME_Component.idl +BIN_SERVER_IDL = +BIN_CLIENT_IDL = + +#CPPFLAGS+= +#CXXFLAGS+= +LDFLAGS+= -lResourcesManager -lSalomeNS -lOpUtil -lSALOMELocalTrace + +@CONCLUDE@ + + diff --git a/src/ContainersManager/ResourcesContainers.py b/src/ContainersManager/ResourcesContainers.py new file mode 100644 index 000000000..6f7e9004e --- /dev/null +++ b/src/ContainersManager/ResourcesContainers.py @@ -0,0 +1,131 @@ + +#ContainersManager_Server -ORBInitRef NameService=corbaname::localhost + +def ContainerParameters( Params ) : + print "ContainerParameters :" + print "Os :",Params.Os + print "Memory :",Params.Memory + print "CpuClock :",Params.CpuClock + print "NbProc :",Params.NbProc + print "NbNode :",Params.NbNode + print "HostName : '" + Params.HostName + "'" + print "ContainerName : '" + Params.ContainerName + "'" + print "ContainerType :",Params.ContainerType + print "NsHostName : '" + Params.NsHostName + "'" + print "NsPort :",Params.NsPort + +def ComputerParameters( Params ) : + print "ComputerParameters :" + print "FullName : '" + Params.FullName + "'" + print "Alias : '" + Params.Alias + "'" + print "SshAccess :",Params.SshAccess + print "Interactive :",Params.Interactive + print "Batch :",Params.Batch + print "UserName :",Params.UserName + print "Os :",Params.Os + print "Memory :",Params.Memory + print "Swap :",Params.Swap + print "CpuClock :",Params.CpuClock + print "NbProc :",Params.NbProc + print "NbNode :",Params.NbNode + + +def ComputerEnvironement( env ) : + rootNames = env.Module_Root_Dir_Names + rootValues = env.Module_Root_Dir_Values + j = 0 + while j < len( rootNames ) : + print rootNames[ j ],rootValues[ j ] + j = j + 1 + #print 'Path ',env.Path + #print 'Ld_Library_Path',env.Ld_Library_Path + #print 'PythonPath ',env.PythonPath + #print 'CasRoot ',env.CasRoot + +def ListComputers() : + AllComputers = MyResourcesMgr.AllComputers() + print '' + print 'ListComputers',len( AllComputers ),'computers found' + i = 0 + while i < len( AllComputers ) : + print AllComputers[i].FullName(),AllComputers[i].Alias(),'IsAlive',AllComputers[i].IsAlive() + i = i + 1 + +def ListContainers() : + AllContainers = MyContainersMgr.AllContainers() + print '' + print 'ListContainers',len( AllContainers ),'containers found' + i = 0 + while i < len( AllContainers ) : + print AllContainers[i]._get_name(),'on',AllContainers[i]._get_machineName(),AllContainers[i].type() + i = i + 1 + +def ListComponents() : + AllComponents = MyContainersMgr.AllComponents() + print '' + print 'ListComponents',len( AllComponents ),'components found' + i = 0 + while i < len( AllComponents ) : + print AllComponents[i]._get_instanceName(),'of interface',AllComponents[i]._get_interfaceName(),'on',AllComponents[i].GetContainerRef()._get_name(),'of',AllComponents[i].GetContainerRef()._get_machineName(),AllComponents[i].GetContainerRef().type() + i = i + 1 + + + +import sys,os,time +import string +from omniORB import CORBA + +# Import the stubs for the Naming service +import CosNaming + +import Engines + +import Containers + +import Resources + +from LifeCycleCORBA import * +orb = CORBA.ORB_init([''], CORBA.ORB_ID) +lcc = LifeCycleCORBA( orb ) + +# ------------------------NameService-------------------------------------------------- + +obj = orb.resolve_initial_references("NameService") +rootContext = obj._narrow(CosNaming.NamingContext) + +# ------------------------ContainersManager-------------------------------------------------- + +#MyContainersMgr = clt.waitNS("/Kernel/ContainersManager",Containers.Manager) +name = [CosNaming.NameComponent("Kernel","dir"), + CosNaming.NameComponent("ContainersManager","object")] +try: + obj = rootContext.resolve(name) +except CosNaming.NamingContext.NotFound, ex: + print "/Kernel.dir/ContainersManager.object not found in Naming Service" + exit(0) + +MyContainersMgr = obj._narrow( Containers.Manager ) + +MyContainersMgr.ping() + +#ResourcesManager_Server -common /home/Salome2/KERNEL_install/share/salome/resources/ResourcesCatalog.xml -ORBInitRef NameService=corbaname::localhost + +#gdb ResourcesManager_Server +#run -common /home/rahuel/SALOME_BR_JR2/KERNEL_build_withoutihm/share/salome/resources/ResourcesCatalog.xml + +# ------------------------ResourcesManager-------------------------------------------------- + +#MyResourcesMgr = clt.waitNS("/Kernel/ResourcesManager",Resources.Manager) +name = [CosNaming.NameComponent("Kernel","dir"), + CosNaming.NameComponent("ResourcesManager","object")] +try: + obj = rootContext.resolve(name) +except CosNaming.NamingContext.NotFound, ex: + print "/Kernel.dir/ResourcesManager.object not found in Naming Service" + exit(0) + +MyResourcesMgr = obj._narrow( Resources.Manager ) + +MyResourcesMgr.ping() + + diff --git a/src/ContainersManager/TestContainersManager.py b/src/ContainersManager/TestContainersManager.py new file mode 100644 index 000000000..2fc1596f3 --- /dev/null +++ b/src/ContainersManager/TestContainersManager.py @@ -0,0 +1,620 @@ + +#python bin/killSalome.py + +from ResourcesContainers import * + +# ------------------------FactoryServer-------------------------------------------------- + +DefaultParams = MyContainersMgr.Parameters() + +ContainerParameters( DefaultParams ) + +FactoryServer = MyContainersMgr.FindOrStartContainer( DefaultParams ) + +FactoryServer.ping() + +print "Container FactoryServer is running on",FactoryServer._get_machineName(),"with name",FactoryServer._get_name(),"and type",FactoryServer.type() + +FactoryServer.destroy() +clt.showNS() + +#python /home/rahuel/SALOME_BR_JR2/KERNEL_install_withoutihm/bin/salome/SALOME_ContainerPy.py FactoryServerPy -ORBInitRef NameService=corbaname::localhost +# ------------------------FactoryServerPy-------------------------------------------------- + +DefaultParams.ContainerType = Engines.PythonContainer + +FactoryServerPy = MyContainersMgr.FindOrStartContainer( DefaultParams ) + +FactoryServerPy.ping() + +print "Container FactoryServerPy is running on",FactoryServerPy._get_machineName(),"with name",FactoryServerPy._get_name(),"and type",FactoryServerPy.type() + +FactoryServerPy.destroy() +clt.showNS() + +# ------------------------SuperVisionContainer-------------------------------------------------- + +DefaultParams.ContainerType = Engines.UndefinedContainerType + +DefaultParams.ContainerName = "SuperVisionContainer" + +SuperVisionContainer = MyContainersMgr.FindOrStartContainer( DefaultParams ) + +SuperVisionContainer.ping() + +print "Container SuperVisionContainer is running on",SuperVisionContainer._get_machineName(),"with name",SuperVisionContainer._get_name(),"and type",SuperVisionContainer.type() + + +# ------------------------RunningContainers-------------------------------------------------- + +ListContainers() + + + +# ------------------------AllComputers-------------------------------------------------- + +ListComputers() + +AllComputers = MyResourcesMgr.AllComputers() +print 'AllComputers',len( AllComputers ),'computers found' +i = 0 +while i < len( AllComputers ) : + print '' + ComputerParameters( AllComputers[i].Parameters() ) + ComputerEnvironement( AllComputers[i].Environment() ) + i = i + 1 + +i = 0 +while i < len( AllComputers ) : + print '' + print AllComputers[i].FullName(),AllComputers[i].Alias(),'IsAlive',AllComputers[i].IsAlive() + i = i + 1 + +# ------------------------ListOfComputers( Params )--------------------------------------------- + +ListOfComputers = MyResourcesMgr.GetComputers( DefaultParams ) +print '' +print 'ListOfComputers',len( ListOfComputers ),'computers found' +i = 0 +while i < len( ListOfComputers ) : + print '' + ComputerParameters( ListOfComputers[i].Parameters() ) + ComputerEnvironement( ListOfComputers[i].Environment() ) + i = i + 1 + +i = 0 +while i < len( ListOfComputers ) : + print '' + print ListOfComputers[i].FullName(),ListOfComputers[i].Alias(),'IsAlive',ListOfComputers[i].IsAlive() + i = i + 1 + +# ------------------------SelectComputer( Params )---------------------------------------------- + +aComputer = MyResourcesMgr.SelectComputer( DefaultParams ) +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +# ------------------------GetComputer( ListOfComputers )---------------------------------------- + +aComputer = MyResourcesMgr.GetComputer( ListOfComputers ) +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +# ------------------------SearchComputer( HostName )-------------------------------------------- + +aComputer = MyResourcesMgr.SearchComputer("is109973") +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +aComputer = MyResourcesMgr.SearchComputer("is109974") +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +aComputer = MyResourcesMgr.SearchComputer("dunex") +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +aComputer = MyResourcesMgr.SearchComputer("bojolex") +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +aComputer = MyResourcesMgr.SearchComputer("xmen.saclay.opencascade.com") +print aComputer.Parameters().FullName,'IsAlive',aComputer.IsAlive() + +aComputer = MyResourcesMgr.SearchComputer("unknown") +if aComputer is None : + print "unknown is None Ok" +else : + print "Error :",aComputer.Parameters().FullName + + +# ------------------------GetComputers( Params )-------------------------------------------------- + +DefaultParams.Memory = 500 + +ListOfComputers = MyResourcesMgr.GetComputers( DefaultParams ) +print '' +print 'ListOfComputers',len( ListOfComputers ),'computers found' +i = 0 +while i < len( ListOfComputers ) : + print '' + ComputerParameters( ListOfComputers[i].Parameters() ) + ComputerEnvironement( ListOfComputers[i].Environment() ) + i = i + 1 + +i = 0 +while i < len( ListOfComputers ) : + print '' + print ListOfComputers[i].FullName(),ListOfComputers[i].Alias(),'Memory',ListOfComputers[i].Memory(),'IsAlive',ListOfComputers[i].IsAlive() + i = i + 1 + +# ------------------------SelectComputer( Params )------------------------------------------------ + +aComputer = MyResourcesMgr.SelectComputer( DefaultParams ) +aComputer.Parameters().FullName + +# ------------------------GetComputer( ListOfComputers )------------------------------------------ + +aComputer = MyResourcesMgr.GetComputer( ListOfComputers ) +aComputer.Parameters().FullName + +# ------------------------GetComputers( Params )-------------------------------------------------- + +DefaultParams.Memory = 1000 + +ListOfComputers = MyResourcesMgr.GetComputers( DefaultParams ) +print '' +if len( ListOfComputers ) > 0 : + print "Error",len( ListOfComputers ),"Computers found" + i = 0 + while i < len( ListOfComputers ) : + print '' + ComputerParameters( ListOfComputers[i].Parameters() ) + ComputerEnvironement( ListOfComputers[i].Environment() ) + i = i + 1 +else : + print 'ListOfComputers',len( ListOfComputers ),'computers found Ok' + +aComputer = MyResourcesMgr.SelectComputer( DefaultParams ) +if aComputer is None : + print "aComputer is None Ok" +else : + print "Error :",aComputer.Parameters().FullName + +aComputer = MyResourcesMgr.GetComputer( ListOfComputers ) +if aComputer is None : + print "aComputer is None Ok" +else : + print "Error :",aComputer.Parameters().FullName + + + +from ResourcesContainers import * + +# ------------------------FindOrStartContainer( Params )-------------------------------------------------- + +DefaultParams = MyContainersMgr.Parameters() + +DefaultParams.Memory = 500 +DefaultParams.ContainerName = '' +DefaultParams.ContainerType = Engines.CppContainer +ContainerParameters( DefaultParams ) + +is109974Server = MyContainersMgr.FindOrStartContainer( DefaultParams ) + +is109974Computer = MyResourcesMgr.SearchComputer( is109974Server._get_machineName() ) + +print "ping",is109974Computer.ping() +print "FullName",is109974Computer.FullName() +print "Alias",is109974Computer.Alias() +print "IsAlive",is109974Computer.IsAlive() +print "SshAccess",is109974Computer.SshAccess() +print "RshAccess",is109974Computer.RshAccess() +print "Interactive",is109974Computer.Interactive() +print "Batch",is109974Computer.Batch() +print "UserName",is109974Computer.UserName() +print "Os",is109974Computer.Os() +print "Memory",is109974Computer.Memory() +print "Swap",is109974Computer.Swap() +print "CpuClock",is109974Computer.CpuClock() +print "NbProc",is109974Computer.NbProc() +print "NbNode",is109974Computer.NbNode() + +ComputerEnvironement( is109974Computer.Environment() ) + +TestComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "SalomeTestComponent" ) + +# ------------------------RunningContainers( DefaultParams )-------------------------------------------------- + +DefaultParams.ContainerName = '' +DefaultParams.ContainerType = Engines.UndefinedContainerType +ContainerParameters( DefaultParams ) +Containers = MyContainersMgr.FindContainers( DefaultParams ) +ContainerParameters( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------RunningContainers-------------------------------------------------- + +ListContainers() + + +# ------------------------FindOrLoad_Component( Params , "MED" )--------------------------------- + +ContainerParameters( DefaultParams ) + +MED = MyContainersMgr.FindOrLoad_Component( DefaultParams , "MED" ) + +MED._get_instanceName() +MED._get_interfaceName() +theContainer = MED.GetContainerRef() +theContainer.getHostName() + + +# ------------------------FindOrLoad_Component( Params , "AddComponent" )--------------------------------- + +AddComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "AddComponent" ) + +AddComponent._get_instanceName() +AddComponent._get_interfaceName() +theContainer = AddComponent.GetContainerRef() +theContainer.getHostName() + + +# ------------------------RunningComponents-------------------------------------------------- + +ListComponents() + + +# ------------------------FindOrLoad_Component( Params , "AddComponent" )--------------------------------- + +DefaultParams.ContainerName = 'AddComponentServer' + +AddComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "AddComponent" ) + +# ------------------------RunningComponents-------------------------------------------------- + +ListComponents() + + +# ------------------------RunningContainers-------------------------------------------------- + +ListContainers() + +DefaultParams.Memory = 0 +DefaultParams.ContainerName = '' + + + + +# ------------------------FindContainer-------------------------------------------------- + +aContainer = MyContainersMgr.FindContainer( DefaultParams ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +# ------------------------FindOneContainer-------------------------------------------------- + +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'FactoryServer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'FactoryServerPy' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'SuperVisionContainer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +aContainer = MyContainersMgr.FindOneContainer( '' , 'SuperVisionContainer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + + +aContainer = MyContainersMgr.FindOneContainer( '' , 'AddComponentServer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + + +# ------------------------C++ Servers-------------------------------------------------- + +DefaultParams.ContainerType = Engines.CppContainer +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------Python Servers-------------------------------------------------- + +DefaultParams.ContainerType = Engines.PythonContainer +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------AddComponentServer-------------------------------------------------- + +DefaultParams.ContainerType = Engines.UndefinedContainerType +DefaultParams.ContainerName = 'AddComponentServer' +aContainer = MyContainersMgr.FindOrStartContainer( DefaultParams ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +ContainerParameters( DefaultParams ) + +# ------------------------FactoryServers-------------------------------------------------- + +DefaultParams.ContainerName = 'FactoryServer' +DefaultParams.ContainerType = Engines.UndefinedContainerType +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + + +# ------------------------AddComponent-------------------------------------------------- + +DefaultParams.ContainerType = Engines.CppContainer +DefaultParams.ContainerName = 'FactoryServer' +FactoryServerAddComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "AddComponent" ) +print FactoryServerAddComponent.GetContainerRef()._get_name(),FactoryServerAddComponent._get_instanceName(),FactoryServerAddComponent._get_interfaceName() + + +# ------------------------is109973 Containers-------------------------------------------------- + +DefaultParams.ContainerType = Engines.UndefinedContainerType +DefaultParams.ContainerName = '' +DefaultParams.HostName = 'is109973' +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------is109974 Containers-------------------------------------------------- + +DefaultParams.HostName = 'is109974' +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------is109974FactoryServerPy-------------------------------------------------- + +DefaultParams.Memory = 500 +DefaultParams.HostName = '' +DefaultParams.ContainerType = Engines.PythonContainer +is109974FactoryServerPy = MyContainersMgr.FindOrStartContainer( DefaultParams ) + +is109974FactoryServerPy.ping() + +# ------------------------Python Containers-------------------------------------------------- + +DefaultParams.Memory = 0 +DefaultParams.ContainerType = Engines.PythonContainer +DefaultParams.ContainerName = '' +Containers = MyContainersMgr.FindContainers( DefaultParams ) +i = 0 +while i < len( Containers ) : + print "Container running on",Containers[ i ]._get_machineName(),"with name",Containers[ i ]._get_name(),"and type",Containers[ i ].type() + i = i + 1 + +# ------------------------Python FactorialComponent-------------------------------------------------- + +DefaultParams.Memory = 500 +aFactorialComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "FactorialComponent" ) +print aFactorialComponent.GetContainerRef()._get_name(),aFactorialComponent._get_instanceName(),aFactorialComponent._get_interfaceName() + + +# ------------------------RunningComponents-------------------------------------------------- + +ListComponents() + + + + +ContainerParameters( DefaultParams ) + +AddComponent = MyContainersMgr.FindComponent( DefaultParams , 'AddComponent' ) +print AddComponent.GetContainerRef()._get_name(),AddComponent._get_instanceName(),AddComponent._get_interfaceName() + +ListOfAddComponent = MyContainersMgr.FindComponents( DefaultParams , 'AddComponent' ) +i = 0 +while i < len( ListOfAddComponent ) : + print ListOfAddComponent[ i ].GetContainerRef()._get_name(),ListOfAddComponent[ i ]._get_instanceName(),ListOfAddComponent[ i ]._get_interfaceName() + i = i + 1 + +aSameAddComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "AddComponent" ) +print aSameAddComponent.GetContainerRef()._get_name(),aSameAddComponent._get_instanceName(),aSameAddComponent._get_interfaceName() + +ListOfAddComponent = MyContainersMgr.FindComponents( DefaultParams , 'AddComponent' ) +i = 0 +while i < len( ListOfAddComponent ) : + print ListOfAddComponent[ i ].GetContainerRef()._get_name(),ListOfAddComponent[ i ]._get_instanceName(),ListOfAddComponent[ i ]._get_interfaceName() + i = i + 1 + +ContainerParameters( DefaultParams ) + +FactoryServerSubComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "SubComponent" ) +ListOfComponents = MyContainersMgr.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + +DefaultParams.ContainerName = 'ServerPy' +ServerPy = FindOrStartContainer( DefaultParams ) +ServerPy = FindOrStartContainer( DefaultParams ) +ServerPy = MyContainersMgr.FindContainer( DefaultParams ) +print "Container running on",ServerPy._get_machineName(),"with name",ServerPy._get_name(),"and type",ServerPy.type() + +DefaultParams.ContainerName = 'SuperVisionContainer' +SuperVisionContainerAddComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "AddComponent" ) +DefaultParams.ContainerName = '' +ListOfAddComponent = MyContainersMgr.FindComponents( DefaultParams , 'AddComponent' ) +i = 0 +while i < len( ListOfAddComponent ) : + print ListOfAddComponent[ i ].GetContainerRef()._get_name(),ListOfAddComponent[ i ]._get_instanceName(),ListOfAddComponent[ i ]._get_interfaceName() + i = i + 1 + + +ListOfComponents = MyContainersMgr.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + + +ListOfComponents = MyContainersMgr.FindComponents( DefaultParams , 'SubComponent' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + +aAddComponent = MyContainersMgr.FindOneComponent( '' , 'FactoryServer' , "AddComponent" ) +print aAddComponent.GetContainerRef()._get_name(),aAddComponent._get_instanceName(),aAddComponent._get_interfaceName() + +aSubComponent = MyContainersMgr.FindOneComponent( '' , 'FactoryServer' , "SubComponent" ) +print aSubComponent.GetContainerRef()._get_name(),aSubComponent._get_instanceName(),aSubComponent._get_interfaceName() + +aSUPERVComponent = MyContainersMgr.FindOneComponent( '' , 'SuperVisionContainer' , "SUPERV" ) +print aSUPERVComponent.GetContainerRef()._get_name(),aSUPERVComponent._get_instanceName(),aSUPERVComponent._get_interfaceName() + +aAddComponent = MyContainersMgr.FindOneComponent( '' , '' , "AddComponent" ) +print aAddComponent.GetContainerRef()._get_name(),aAddComponent._get_instanceName(),aAddComponent._get_interfaceName() + +aSubComponent = MyContainersMgr.FindOneComponent( '' , '' , "SubComponent" ) +print aSubComponent.GetContainerRef()._get_name(),aSubComponent._get_instanceName(),aSubComponent._get_interfaceName() + +aSubComponent = MyContainersMgr.FindOneComponent( 'is109973' , '' , "SubComponent" ) +print aSubComponent.GetContainerRef()._get_name(),aSubComponent._get_instanceName(),aSubComponent._get_interfaceName() + +aSubComponent = MyContainersMgr.FindOneComponent( 'localhost' , '' , "SubComponent" ) +print aSubComponent.GetContainerRef()._get_name(),aSubComponent._get_instanceName(),aSubComponent._get_interfaceName() + +aSUPERVComponent = MyContainersMgr.FindOneComponent( '' , '' , "SUPERV" ) +print aSUPERVComponent.GetContainerRef()._get_name(),aSUPERVComponent._get_instanceName(),aSUPERVComponent._get_interfaceName() + +ServerPy = MyContainersMgr.FindOneContainer( '' , 'ServerPy' ) +print "Container running on",ServerPy._get_machineName(),"with name",ServerPy._get_name(),"and type",ServerPy.type() + +DefaultParams.ContainerType = Engines.PythonContainer +ContainerParameters( DefaultParams ) +TestComponentPy = MyContainersMgr.FindOrLoad_Component( DefaultParams , "SALOME_TestComponentPy" ) +print TestComponentPy.GetContainerRef()._get_name(),TestComponentPy._get_instanceName(),TestComponentPy._get_interfaceName() +ListOfComponents = MyContainersMgr.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + +DefaultParams.ContainerType = Engines.CppContainer +ContainerParameters( DefaultParams ) +TestComponent = MyContainersMgr.FindOrLoad_Component( DefaultParams , "SalomeTestComponent" ) +print TestComponent.GetContainerRef()._get_name(),TestComponent._get_instanceName(),TestComponent._get_interfaceName() +ListOfComponents = MyContainersMgr.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + + + + + +from LifeCycleCORBA import * +orb = CORBA.ORB_init([''], CORBA.ORB_ID) +lcc = LifeCycleCORBA( orb ) + +TestComponent = lcc.FindOrLoadComponent( 'FactoryServer' , 'SalomeTestComponent' ) +print TestComponent.GetContainerRef()._get_name(),TestComponent._get_instanceName(),TestComponent._get_interfaceName() + +TestComponent = lcc.FindOrLoadComponent( '' , 'SalomeTestComponent' ) +print TestComponent.GetContainerRef()._get_name(),TestComponent._get_instanceName(),TestComponent._get_interfaceName() + +TestComponentPy = lcc.FindOrLoadComponent( '' , 'SALOME_TestComponentPy' ) +if TestComponentPy is None : + print 'SALOME_TestComponentPy not found : Ok' +else : + print 'Error',TestComponentPy.GetContainerRef()._get_name(),TestComponentPy._get_instanceName(),TestComponentPy._get_interfaceName(),'was found' + +TestComponentPy = lcc.FindOrLoadComponent( 'ServerPy' , 'SALOME_TestComponentPy' ) +print TestComponentPy.GetContainerRef()._get_name(),TestComponentPy._get_instanceName(),TestComponentPy._get_interfaceName() + +lccMulComponent = lcc.FindOrLoadComponent( 'SuperVisionContainer' , "MulComponent" ) +print lccMulComponent.GetContainerRef()._get_name(),lccMulComponent._get_instanceName(),lccMulComponent._get_interfaceName() + +lccDivComponent = lcc.FindOrLoadComponent( 'DivComponentContainer' , "DivComponent" ) +print lccDivComponent.GetContainerRef()._get_name(),lccDivComponent._get_instanceName(),lccDivComponent._get_interfaceName() + + +DefaultParams = lcc.Parameters() + +DefaultParams.ContainerName = 'SuperVisionContainer' + +lccAddComponent = lcc.FindOrLoadComponent( DefaultParams , "AddComponent" ) +print lccAddComponent.GetContainerRef()._get_name(),lccAddComponent._get_instanceName(),lccAddComponent._get_interfaceName() + +DefaultParams.ContainerName = 'SubComponentContainer' +lccSubComponent = lcc.FindOrLoadComponent( DefaultParams , "SubComponent" ) +print lccSubComponent.GetContainerRef()._get_name(),lccSubComponent._get_instanceName(),lccSubComponent._get_interfaceName() + +aContainer = lcc.FindContainer( DefaultParams ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +aContainer = lcc.FindContainer( 'FactoryServer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + +aContainer = lcc.FindContainer( 'localhost/FactoryServer' ) +print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() + + +ContainerParameters( DefaultParams ) + +DefaultParams.ContainerName = '' + +ListOfContainers = lcc.FindContainers( DefaultParams ) +i = 0 +while i < len( ListOfContainers ) : + print "Container running on",ListOfContainers[ i ]._get_machineName(),"with name",ListOfContainers[ i ]._get_name(),"and type",ListOfContainers[ i ].type() + i = i + 1 + +ListOfComponents = lcc.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + + +aComponent = lcc.FindComponent( DefaultParams , 'SubComponent' ) +print aComponent.GetContainerRef()._get_name(),aComponent._get_instanceName(),aComponent._get_interfaceName() + +lccMulComponent = lcc.FindOrLoadComponent( DefaultParams , "MulComponent" ) +print lccMulComponent.GetContainerRef()._get_name(),lccMulComponent._get_instanceName(),lccMulComponent._get_interfaceName() + +DefaultParams.HostName = 'bojolex' + +lccbojolexMulComponent = lcc.FindOrLoadComponent( DefaultParams , "MulComponent" ) + +DefaultParams.HostName = 'toto' + +lcctotoMulComponent = lcc.FindOrLoadComponent( DefaultParams , "MulComponent" ) + + +MyContainersMgr.DestroyContainer( '' , 'FactoryServer' ) +MyContainersMgr.DestroyContainer( '' , 'FactoryServerPy' ) + + +DefaultParams.HostName = '' +DefaultParams.ContainerName = '' +DefaultParams.ContainerType = Engines.UndefinedContainerType + +ListOfContainers = lcc.FindContainers( DefaultParams ) +i = 0 +while i < len( ListOfContainers ) : + print "Container running on",ListOfContainers[ i ]._get_machineName(),"with name",ListOfContainers[ i ]._get_name(),"and type",ListOfContainers[ i ].type() + i = i + 1 + +ListOfComponents = lcc.FindComponents( DefaultParams , '' ) +i = 0 +while i < len( ListOfComponents ) : + print ListOfComponents[ i ].GetContainerRef()._get_name(),ListOfComponents[ i ]._get_instanceName(),ListOfComponents[ i ]._get_interfaceName() + i = i + 1 + + +MyContainersMgr.destroy() + diff --git a/src/ContainersManager/runContainer.py b/src/ContainersManager/runContainer.py new file mode 100644 index 000000000..4ee79d816 --- /dev/null +++ b/src/ContainersManager/runContainer.py @@ -0,0 +1,62 @@ +#! /usr/bin/env python +# +# SALOME runContainer : implementation of container and engine for Kernel +# +# 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 : runContainer.py +# Author : Jean Rahuel, CEA +# Module : SALOME +# $Header: + +import os +import sys +import string +from omniORB import CORBA, PortableServer +import Containers +import Engines +from SALOME_NamingServicePy import * + +if sys.argv[1] == '--help' : + print 'USAGE : runContainer.py ContainerName ContainerType NSHostName NSHostPort Path Ld_Library_Path PythonPath CasRoot' + print ' ContainerType : Engines.Cpp or Engines.Python' + sys.exit(0) + +if ContainerType == 'Engines.Cpp' : + Container = 'SALOME_Container ' +elif ContainerType == 'Engines.Python' : + Container = 'SALOME_ContainerPy.py ' +else : + print 'ContainerType is bad' + Container = '' + +if len( Container ) > 0 : + Container = Container + ' -ORBInitRef NameService=corbaname::' + Container = Container + NSHostName + ':' + NSHostPort + os.environ["PATH"] = Path + os.environ["LD_LIBRARY_PATH"] = Ld_Library_Path + os.environ["PYTHONPATH"] = PythonPath + os.environ["CASROOT"] = CasRoot + os.environ["CSF_PluginDefaults"] = os.path.join( CasRoot , "share" , "salome" , "resources" ) + print Container + exec Container + diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index 550a88ff9..1033bffac 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -32,6 +32,8 @@ import time from omniORB import CORBA import CosNaming import Engines +import Resources +import Containers import SALOME_ModuleCatalog from SALOME_utilities import * @@ -41,6 +43,7 @@ class LifeCycleCORBA: _rootcontext = None _containerRootContext = None _catalog = None + _containermgr = None #------------------------------------------------------------------------- @@ -54,197 +57,273 @@ class LifeCycleCORBA: if self._rootContext is None: MESSAGE( "Name Service Reference is invalid" ) - name = [CosNaming.NameComponent("Containers","dir")] - try: - self._containerRootContext = self._rootContext.bind_new_context(name) + #name = [CosNaming.NameComponent("Containers","dir")] + #try: + #self._containerRootContext = self._rootContext.bind_new_context(name) - except CosNaming.NamingContext.AlreadyBound, ex: - MESSAGE( "/Containers.dir Context already exists" ) - obj = self._rootContext.resolve(name) - self._containerRootContext = obj._narrow(CosNaming.NamingContext) - if self._containerRootContext is None: - MESSAGE( "Containers.dir exists but it is not a NamingContext" ) + #except CosNaming.NamingContext.AlreadyBound, ex: + #MESSAGE( "/Containers.dir Context already exists" ) + #obj = self._rootContext.resolve(name) + #self._containerRootContext = obj._narrow(CosNaming.NamingContext) + #if self._containerRootContext is None: + #MESSAGE( "Containers.dir exists but it is not a NamingContext" ) + + #name = [CosNaming.NameComponent("Kernel","dir"), + #CosNaming.NameComponent("ModulCatalog","object")] + #try: + #obj = self._rootContext.resolve(name) + #except CosNaming.NamingContext.NotFound, ex: + #MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" ) + + #self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) + #if self._catalog is None: + #MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" ) name = [CosNaming.NameComponent("Kernel","dir"), - CosNaming.NameComponent("ModulCatalog","object")] + CosNaming.NameComponent("ContainersManager","object")] try: obj = self._rootContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: - MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" ) + MESSAGE( "/Kernel.dir/ContainersManager.object not found in Naming Service" ) + + self._containermgr = obj._narrow( Containers.Manager ) + self._containermgr.ping() + + + #------------------------------------------------------------------------- + + def Parameters( self ): + return self._containermgr.Parameters() - self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) - if self._catalog is None: - MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" ) #------------------------------------------------------------------------- def ContainerName(self, containerName): - theComputer = "" + MESSAGE( "ContainerName( " + containerName + " )" ) + theComputer = None try: theComputer , theContainer = containerName.split('/') except: - theComputer = "" + theComputer = None theContainer = containerName - if theComputer == "" : + #CCRT HOST instead of HOSTNAME + if theComputer == None : theComputer = os.getenv("HOSTNAME") + if theComputer == None : + theComputer = os.getenv("HOST") if theComputer == "localhost" : theComputer = os.getenv("HOSTNAME") + if theComputer == None : + theComputer = os.getenv("HOST") + MESSAGE( "ContainerName " + theComputer + " " + theContainer ) computerSplitName = theComputer.split('.') theComputer = computerSplitName[0] - MESSAGE( theComputer + theContainer ) + MESSAGE( "ContainerName returns " + theComputer + ','+ theContainer ) return theComputer,theContainer #------------------------------------------------------------------------- - def ComputerPath(self, ComputerName ): + #def ComputerPath(self, ComputerName ): # Modification provisoire B. Secher en attendant # le gestionnaire de ressources 21/10/2003 # Le KERNEL_ROOT_DIR sera a lire dans le catalogue de machines # en attendant on suppose qu'il est identique au KERNEL_ROOT_DIR local - try: + #try: #path = self._catalog.GetPathPrefix( ComputerName ) - path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/" - except SALOME_ModuleCatalog.NotFound, ex: - path = "" - return path + #path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/" + #except SALOME_ModuleCatalog.NotFound, ex: + #path = "" + #return path #------------------------------------------------------------------------- def FindContainer(self, containerName): - theComputer,theContainer = self.ContainerName( containerName ) - name = [CosNaming.NameComponent(theComputer,"dir"), - CosNaming.NameComponent(theContainer,"object")] - obj = None - try: - obj = self._containerRootContext.resolve(name) - MESSAGE( containerName + ".object found in Naming Service" ) + #theComputer,theContainer = self.ContainerName( containerName ) + #name = [CosNaming.NameComponent(theComputer,"dir"), + #CosNaming.NameComponent(theContainer,"object")] + #obj = None + #try: + #obj = self._containerRootContext.resolve(name) + #MESSAGE( containerName + ".object found in Naming Service" ) - except CosNaming.NamingContext.NotFound, ex: - MESSAGE( containerName + ".object not found in Naming Service" ) - - if obj is None: - container = None - else: - container = obj._narrow(Engines.Container) - if container is None: - MESSAGE( containerName + ".object exists but is not a Container" ) + #except CosNaming.NamingContext.NotFound, ex: + #MESSAGE( containerName + ".object not found in Naming Service" ) + + #if obj is None: + #container = None + #else: + #container = obj._narrow(Engines.Container) + #if container is None: + #MESSAGE( containerName + ".object exists but is not a Container" ) + try : + theComputer,theContainer = self.ContainerName( containerName ) + MyParams = self._containermgr.Parameters() + MyParams.HostName = theComputer + MyParams.ContainerName = theContainer + if theContainer.find('Py') == -1 : + MyParams.ContainerType = Engines.CppContainer + else : + MyParams.ContainerType = Engines.PythonContainer + except : + MyParams = containerName + container = self._containermgr.FindContainer( MyParams ) return container #------------------------------------------------------------------------- - def FindOrStartContainer(self, theComputer , theContainer ): - MESSAGE( "FindOrStartContainer" + theComputer + theContainer ) - aContainer = self.FindContainer( theComputer + "/" + theContainer ) - if aContainer is None : - if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") : - if theComputer == os.getenv("HOSTNAME") : - rshstr = "" - else : - rshstr = "rsh -n " + theComputer + " " - path = self.ComputerPath( theComputer ) + def FindContainers( self , MyParams ) : + if MyParams.HostName == 'localhost' : + MyParams.HostName = os.getenv("HOSTNAME") + return self._containermgr.FindContainers( MyParams ) + + + #------------------------------------------------------------------------- + + def FindComponent( self , MyParams , ComponentName ) : + if MyParams.HostName == 'localhost' : + MyParams.HostName = os.getenv("HOSTNAME") + return self._containermgr.FindComponent( MyParams , ComponentName ) + + + #------------------------------------------------------------------------- + + def FindComponents( self , MyParams , ComponentName ) : + if MyParams.HostName == 'localhost' : + MyParams.HostName = os.getenv("HOSTNAME") + return self._containermgr.FindComponents( MyParams , ComponentName ) + + + #------------------------------------------------------------------------- + + #def FindOrStartContainer(self, theComputer , theContainer ): + #MESSAGE( "FindOrStartContainer" + theComputer + theContainer ) + #aContainer = self.FindContainer( theComputer + "/" + theContainer ) + #if aContainer is None : + #if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") : + #if theComputer == os.getenv("HOSTNAME") : + #rshstr = "" + #else : + #rshstr = "rsh -n " + theComputer + " " + #path = self.ComputerPath( theComputer ) ## if path != "" : ## rshstr = rshstr + path + "/../bin/" ## else : ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/" - if theContainer == "FactoryServer" : - rshstr = rshstr + path + "SALOME_Container " - else : - rshstr = rshstr + path + "SALOME_ContainerPy.py '" - rshstr = rshstr + theContainer + " -" - omniORBcfg = os.getenv( "OMNIORB_CONFIG" ) - file = os.open( omniORBcfg , os.O_RDONLY ) - ORBInitRef = os.read(file,132) - if ORBInitRef[len(ORBInitRef)-1] == '\n' : - ORBInitRef,bsn = ORBInitRef.split('\n') - os.close( file ) - rshstr = rshstr + ORBInitRef - if theContainer == "FactoryServerPy" : - rshstr = rshstr + "'" - rshstr = rshstr + " > /tmp/" + theContainer + "_" - rshstr = rshstr + theComputer - rshstr = rshstr + ".log 2>&1 &" - os.system( rshstr ) - MESSAGE( "FindOrStartContainer" + rshstr + " done" ) - else : - if theContainer.find('Py') == -1 : - aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" ) - else : - aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" ) - aContainer = aContainer.start_impl( theContainer ) - - count = 21 - while aContainer is None : - time.sleep(1) - count = count - 1 - MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer ) - aContainer = self.FindContainer( theComputer + "/" + theContainer ) - if count == 0 : - return aContainer + #if theContainer == "FactoryServer" : + #rshstr = rshstr + path + "SALOME_Container " + #else : + #rshstr = rshstr + path + "SALOME_ContainerPy.py '" + #rshstr = rshstr + theContainer + " -" + #omniORBcfg = os.getenv( "OMNIORB_CONFIG" ) + #file = os.open( omniORBcfg , os.O_RDONLY ) + #ORBInitRef = os.read(file,132) + #if ORBInitRef[len(ORBInitRef)-1] == '\n' : + #ORBInitRef,bsn = ORBInitRef.split('\n') + #os.close( file ) + #rshstr = rshstr + ORBInitRef + #if theContainer == "FactoryServerPy" : + #rshstr = rshstr + "'" + #rshstr = rshstr + " > /tmp/" + theContainer + "_" + #rshstr = rshstr + theComputer + #rshstr = rshstr + ".log 2>&1 &" + #os.system( rshstr ) + #MESSAGE( "FindOrStartContainer" + rshstr + " done" ) + #else : + #if theContainer.find('Py') == -1 : + #aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" ) + #else : + #aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" ) + #aContainer = aContainer.start_impl( theContainer ) + + #count = 21 + #while aContainer is None : + #time.sleep(1) + #count = count - 1 + #MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer ) + #aContainer = self.FindContainer( theComputer + "/" + theContainer ) + #if count == 0 : + #return aContainer - return aContainer + #return aContainer #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515") #------------------------------------------------------------------------- def FindOrLoadComponent(self, containerName, componentName): + MESSAGE( "FindOrLoadComponent( " + containerName + " , " + componentName + " )" ) + #theComputer,theContainer = self.ContainerName( containerName ) + #name = [CosNaming.NameComponent(theComputer,"dir"), + #CosNaming.NameComponent(theContainer,"dir"), + #CosNaming.NameComponent(componentName,"object")] + #try: + #obj = self._containerRootContext.resolve(name) + #except CosNaming.NamingContext.NotFound, ex: + #MESSAGE( "component " + componentName + " not found, trying to load" ) + #container = self.FindContainer(theComputer + "/" + theContainer) + #if container is None: + #MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" ) + #if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") : + #if theContainer.find('Py') == -1 : + #theFactorycontainer = "FactoryServer" + #else : + #theFactorycontainer = "FactoryServerPy" + #Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer) + #if Factorycontainer is None: + #MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" ) + #Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer) + #else: + #Factorycontainer = self.FindOrStartContainer(theComputer,theContainer) + #if Factorycontainer != None : + #container = self.FindOrStartContainer(theComputer,theContainer) - theComputer,theContainer = self.ContainerName( containerName ) - name = [CosNaming.NameComponent(theComputer,"dir"), - CosNaming.NameComponent(theContainer,"dir"), - CosNaming.NameComponent(componentName,"object")] - try: - obj = self._containerRootContext.resolve(name) - except CosNaming.NamingContext.NotFound, ex: - MESSAGE( "component " + componentName + " not found, trying to load" ) - container = self.FindContainer(theComputer + "/" + theContainer) - if container is None: - MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" ) - if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") : - if theContainer.find('Py') == -1 : - theFactorycontainer = "FactoryServer" - else : - theFactorycontainer = "FactoryServerPy" - Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer) - if Factorycontainer is None: - MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" ) - Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer) - else: - Factorycontainer = self.FindOrStartContainer(theComputer,theContainer) - if Factorycontainer != None : - container = self.FindOrStartContainer(theComputer,theContainer) - - if container != None: - compoinfo = self._catalog.GetComponent(componentName) - if compoinfo is None: - MESSAGE( "component " + componentName + " not found in Module Catalog" ) - else: - try: - machineName = theComputer - path = compoinfo.GetPathPrefix(machineName) + "/" - except SALOME_ModuleCatalog.NotFound, ex: - MESSAGE( "machine " + machineName + " not found in Module Catalog" ) - MESSAGE( "trying localhost" ) - try: - path = compoinfo.GetPathPrefix("localhost") + "/" - except SALOME_ModuleCatalog.NotFound, ex: - path = "" - implementation = path + "lib" + componentName + "Engine.so" - MESSAGE( "Trying to load " + implementation ) - try: - component = container.load_impl(componentName, implementation) - MESSAGE( "component " + component._get_instanceName() + " launched !" ) - return component - except: - MESSAGE( "component " + componentName + " NOT launched !" ) - - else: - try: - component = obj._narrow(Engines.Component) - if component is None: - MESSAGE( componentName + " is not a component !" ) - else: - MESSAGE( "component " + component._get_instanceName() + " found !" ) - return component - except: - MESSAGE( componentName + " failure" ) - return None + #if container != None: + #compoinfo = self._catalog.GetComponent(componentName) + #if compoinfo is None: + #MESSAGE( "component " + componentName + " not found in Module Catalog" ) + #else: + #try: + #machineName = theComputer + #path = compoinfo.GetPathPrefix(machineName) + "/" + #except SALOME_ModuleCatalog.NotFound, ex: + #MESSAGE( "machine " + machineName + " not found in Module Catalog" ) + #MESSAGE( "trying localhost" ) + #try: + #path = compoinfo.GetPathPrefix("localhost") + "/" + #except SALOME_ModuleCatalog.NotFound, ex: + #path = "" + #implementation = path + "lib" + componentName + "Engine.so" + #MESSAGE( "Trying to load " + implementation ) + #try: + #component = container.load_impl(componentName, implementation) + #MESSAGE( "component " + component._get_instanceName() + " launched !" ) + #return component + #except: + #MESSAGE( "component " + componentName + " NOT launched !" ) + + #else: + #try: + #component = obj._narrow(Engines.Component) + #if component is None: + #MESSAGE( componentName + " is not a component !" ) + #else: + #MESSAGE( "component " + component._get_instanceName() + " found !" ) + #return component + #except: + #MESSAGE( componentName + " failure" ) + #return None + try : + theComputer,theContainer = self.ContainerName( containerName ) + MESSAGE( "FindOrLoadComponent " + theComputer + " " + theContainer ) + MyParams = self._containermgr.Parameters() + MyParams.HostName = theComputer + MyParams.ContainerName = theContainer + if theContainer.find('Py') == -1 : + MESSAGE( "FindOrLoadComponent " + str(Engines.CppContainer) ) + MyParams.ContainerType = Engines.CppContainer + else : + MESSAGE( "FindOrLoadComponent " + str(Engines.PythonContainer) ) + MyParams.ContainerType = Engines.PythonContainer + except : + MESSAGE( "FindOrLoadComponent except" + containerName ) + MyParams = containerName + return self._containermgr.FindOrLoad_Component( MyParams , componentName ) diff --git a/src/LifeCycleCORBA/Makefile.in b/src/LifeCycleCORBA/Makefile.in index 33ee1ac81..d98e8e9c7 100644 --- a/src/LifeCycleCORBA/Makefile.in +++ b/src/LifeCycleCORBA/Makefile.in @@ -43,13 +43,13 @@ EXPORT_PYSCRIPTS = LifeCycleCORBA.py LIB = libSalomeLifeCycleCORBA.la LIB_SRC = SALOME_LifeCycleCORBA.cxx LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ - SALOME_ModuleCatalog.idl + SALOME_ModuleCatalog.idl ContainersManager.idl # Executables targets BIN = TestLifeCycleCORBA BIN_SRC = BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ - SALOME_ModuleCatalog.idl + SALOME_ModuleCatalog.idl ContainersManager.idl LDFLAGS += -lSalomeNS -lOpUtil -lSALOMELocalTrace diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 6e48df6b9..b1af7f5ff 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -38,18 +38,21 @@ using namespace std; #include #include "SALOME_LifeCycleCORBA.hxx" -#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) +//#include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) #include "SALOME_NamingService.hxx" SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA() { - _NS = NULL; + _NamingService = NULL; + _MyContainersMgr = NULL ; _FactoryServer = NULL ; } SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) { - _NS = ns; + _NamingService = ns; + CORBA::Object_var ContainersMgrObject = _NamingService->Resolve( "/Kernel/ContainersManager" ) ; + _MyContainersMgr = Containers::Manager::_narrow( ContainersMgrObject ) ; _FactoryServer = NULL ; } @@ -57,10 +60,13 @@ SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA() { } -string SALOME_LifeCycleCORBA::ContainerName( - const char * aComputerContainer , - string * theComputer , - string * theContainer ) { +Containers::MachineParameters_var SALOME_LifeCycleCORBA::Parameters() { + return _MyContainersMgr->Parameters() ; +} + +string SALOME_LifeCycleCORBA::ContainerName( const char * aComputerContainer , + string * theComputer , + string * theContainer ) { char * ContainerName = new char [ strlen( aComputerContainer ) + 1 ] ; strcpy( ContainerName , aComputerContainer ) ; string theComputerContainer("/Containers/"); @@ -86,13 +92,15 @@ string SALOME_LifeCycleCORBA::ContainerName( theComputerContainer += "/" ; theComputerContainer += *theContainer ; } + if ( strlen( theContainer->c_str() ) == 0 ) { + theContainer = new string( "FactoryServer" ) ; + } return theComputerContainer ; } -string SALOME_LifeCycleCORBA::ComputerPath( - const char * theComputer ) { +//string SALOME_LifeCycleCORBA::ComputerPath( const char * theComputer ) { // CORBA::String_var path; -// CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog"); +// CORBA::Object_var obj = _NamingService->Resolve("/Kernel/ModulCatalog"); // SALOME_ModuleCatalog::ModuleCatalog_var Catalog = // SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ; // try { @@ -106,318 +114,403 @@ string SALOME_LifeCycleCORBA::ComputerPath( // 21/10/2003 // Le KERNEL_ROOT_DIR sera a lire dans le catalogue de machines // en attendant on suppose qu'il est identique au KERNEL_ROOT_DIR local - string path = string(getenv("KERNEL_ROOT_DIR")) + "/bin/salome/"; - SCRUTE( path ) ; - return path; -} +// string path = string(getenv("KERNEL_ROOT_DIR")) + "/bin/salome/"; +// SCRUTE( path ) ; +// return path; +//} Engines::Container_var SALOME_LifeCycleCORBA::FindContainer(const char *containerName ) { - ASSERT(_NS != NULL); - string cont ; - if ( strncmp( containerName , "/Containers/" , 12 ) ) { // Compatibility ... - string theComputer ; - string theContainer ; - cont = ContainerName( containerName , &theComputer , &theContainer ) ; + Containers::MachineParameters * MyParams = _MyContainersMgr->Parameters() ; + string theComputer ; + string theContainer ; + ContainerName( containerName , &theComputer , &theContainer ) ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + int l = strlen( containerName ) ; + if ( strcmp( &containerName[ l-2 ] , "Py" ) ) { + MyParams->ContainerType = Engines::CppContainer ; } else { - cont = containerName ; + MyParams->ContainerType = Engines::PythonContainer ; } - try { + return FindContainer( *MyParams ) ; +// ASSERT(_NamingService != NULL); +// string cont ; +// if ( strncmp( containerName , "/Containers/" , 12 ) ) { // Compatibility ... +// string theComputer ; +// string theContainer ; +// cont = ContainerName( containerName , &theComputer , &theContainer ) ; +// } +// else { +// cont = containerName ; +// } +// try { - SCRUTE( cont ); +// SCRUTE( cont ); - CORBA::Object_var obj = _NS->Resolve( cont.c_str() ); - if( !CORBA::is_nil( obj ) ) { - return Engines::Container::_narrow( obj ) ; - } - } - catch (ServiceUnreachable&) { - INFOS("Caught exception: Naming Service Unreachable"); - } - catch (...) { - INFOS("Caught unknown exception."); +// CORBA::Object_var obj = _NamingService->Resolve( cont.c_str() ); +// if( !CORBA::is_nil( obj ) ) { +// return Engines::Container::_narrow( obj ) ; +// } +// } +// catch (ServiceUnreachable&) { +// INFOS("Caught exception: Naming Service Unreachable"); +// } +// catch (...) { +// INFOS("Caught unknown exception."); +// } +// return Engines::Container::_nil(); +} + +//Engines::Container_var SALOME_LifeCycleCORBA::FindOrStartContainer( +// const string aComputerContainer , +// const string theComputer , +// const string theContainer ) { +// Engines::Container_var aContainer = FindContainer( aComputerContainer.c_str() ) ; +// Engines::Container_var aFactoryServer ; +// SCRUTE( aComputerContainer ) ; +// SCRUTE( theComputer ) ; +// SCRUTE( theContainer ) ; +// bool pyCont = false ; +// int len = theContainer.length() ; +// if ( !strcmp( &theContainer.c_str()[len-2] , "Py" ) ) { +// pyCont = true ; +// } +// if ( !CORBA::is_nil( aContainer ) ) { +// return aContainer ; +// } +// else { +// string FactoryServer = theComputer ; +// if ( pyCont ) { +// FactoryServer += "/FactoryServerPy" ; +// } +// else { +// FactoryServer += "/FactoryServer" ; +// } +// aFactoryServer = FindContainer( FactoryServer.c_str() ) ; +// if ( CORBA::is_nil( aFactoryServer ) ) { +// rsh -n machine_name ${KERNEL_ROOT_DIR}/bin/salome SALOME_Container -ORBInitRef NameService=corbaname::localhost:1515 & +// string rsh( "" ) ; +// if ( theComputer!= GetHostname() ) { +// rsh += "rsh -n " ; +// rsh += theComputer ; +// rsh += " " ; +// } +// string path = ComputerPath( theComputer.c_str() ) ; +// SCRUTE( path ) ; +// rsh += path; +// rsh += "runSession " ; +// if ( pyCont ) { +// rsh += "SALOME_ContainerPy.py " ; +// rsh += "FactoryServerPy -" ; +// } +// else { +// rsh += "SALOME_Container " ; +// rsh += "FactoryServer -" ; +// } +// string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; +// ifstream omniORBfile( omniORBcfg.c_str() ) ; +// char ORBInitRef[12] ; +// char nameservice[132] ; +// omniORBfile >> ORBInitRef ; +// rsh += ORBInitRef ; +// rsh += " " ; +// omniORBfile >> nameservice ; +// omniORBfile.close() ; +// char * bsn = strchr( nameservice , '\n' ) ; +// if ( bsn ) { +// bsn[ 0 ] = '\0' ; +// } +// rsh += nameservice ; +// if ( pyCont ) { +// rsh += " > /tmp/FactoryServerPy_" ; +// } +// else { +// rsh += " > /tmp/FactoryServer_" ; +// } +// rsh += theComputer ; +// rsh += ".log 2>&1 &" ; +// SCRUTE( rsh ); +// int status = system( rsh.c_str() ) ; +// if (status == -1) { +// INFOS("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)") ; +// } +// else if (status == 217) { +// INFOS("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 " << theComputer) +// aFactoryServer = FindContainer( FactoryServer.c_str() ) ; +// } +// if ( CORBA::is_nil( aFactoryServer ) ) { +// INFOS("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ; +// } +// else if ( strcmp( theComputer.c_str() , GetHostname().c_str() ) ) { +// _FactoryServer = aFactoryServer ; +// } +// } +// } +// if ( !CORBA::is_nil( aFactoryServer ) ) { +// if ( strcmp( theContainer.c_str() , "FactoryServer" ) || +// strcmp( theContainer.c_str() , "FactoryServerPy" ) ) { +// MESSAGE("Container not found ! trying to start " << aComputerContainer); +// Engines::Container_var myContainer = aFactoryServer->start_impl( theContainer.c_str() ) ; +// if ( !CORBA::is_nil( myContainer ) ) { +// MESSAGE("Container " << aComputerContainer << " started"); +// return myContainer ; +// } +// else { +// MESSAGE("Container " << aComputerContainer << " NOT started"); +// } +// } +// else { +// MESSAGE("Container " << aComputerContainer << " started"); +// return aFactoryServer ; +// } +// } +// } +// return Engines::Container::_nil(); +//} + +Engines::Container_var SALOME_LifeCycleCORBA::FindContainer( Containers::MachineParameters & MyParams ) { + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; } - return Engines::Container::_nil(); + return _MyContainersMgr->FindContainer( MyParams ) ; } -Engines::Container_var SALOME_LifeCycleCORBA::FindOrStartContainer( - const string aComputerContainer , - const string theComputer , - const string theContainer ) { - Engines::Container_var aContainer = FindContainer( aComputerContainer.c_str() ) ; - Engines::Container_var aFactoryServer ; - SCRUTE( aComputerContainer ) ; - SCRUTE( theComputer ) ; - SCRUTE( theContainer ) ; - bool pyCont = false ; - int len = theContainer.length() ; - if ( !strcmp( &theContainer.c_str()[len-2] , "Py" ) ) { - pyCont = true ; +Engines::ListOfContainers_var SALOME_LifeCycleCORBA::FindContainers( Containers::MachineParameters & MyParams ) { + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; } - if ( !CORBA::is_nil( aContainer ) ) { - return aContainer ; + return _MyContainersMgr->FindContainers( MyParams ) ; +} + +Engines::Component_var SALOME_LifeCycleCORBA::FindComponent( Containers::MachineParameters & MyParams , + const char * ComponentName ) { + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; } - else { - string FactoryServer = theComputer ; - if ( pyCont ) { - FactoryServer += "/FactoryServerPy" ; - } - else { - FactoryServer += "/FactoryServer" ; - } - aFactoryServer = FindContainer( FactoryServer.c_str() ) ; - if ( CORBA::is_nil( aFactoryServer ) ) { -// rsh -n machine_name ${KERNEL_ROOT_DIR}/bin/salome SALOME_Container -ORBInitRef NameService=corbaname::localhost:1515 & - string rsh( "" ) ; - if ( theComputer!= GetHostname() ) { - rsh += "rsh -n " ; - rsh += theComputer ; - rsh += " " ; - } - string path = ComputerPath( theComputer.c_str() ) ; - SCRUTE( path ) ; - rsh += path; -// rsh += "runSession " ; - if ( pyCont ) { - rsh += "SALOME_ContainerPy.py " ; - rsh += "FactoryServerPy -" ; - } - else { - rsh += "SALOME_Container " ; - rsh += "FactoryServer -" ; - } - string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; - ifstream omniORBfile( omniORBcfg.c_str() ) ; - char ORBInitRef[12] ; - char nameservice[132] ; - omniORBfile >> ORBInitRef ; - rsh += ORBInitRef ; - rsh += " " ; - omniORBfile >> nameservice ; - omniORBfile.close() ; - char * bsn = strchr( nameservice , '\n' ) ; - if ( bsn ) { - bsn[ 0 ] = '\0' ; - } - rsh += nameservice ; - if ( pyCont ) { - rsh += " > /tmp/FactoryServerPy_" ; - } - else { - rsh += " > /tmp/FactoryServer_" ; - } - rsh += theComputer ; - rsh += ".log 2>&1 &" ; - SCRUTE( rsh ); - int status = system( rsh.c_str() ) ; - if (status == -1) { - INFOS("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)") ; - } - else if (status == 217) { - INFOS("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 " << theComputer) - aFactoryServer = FindContainer( FactoryServer.c_str() ) ; - } - if ( CORBA::is_nil( aFactoryServer ) ) { - INFOS("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed") ; - } - else if ( strcmp( theComputer.c_str() , GetHostname().c_str() ) ) { - _FactoryServer = aFactoryServer ; - } - } - } - if ( !CORBA::is_nil( aFactoryServer ) ) { - if ( strcmp( theContainer.c_str() , "FactoryServer" ) || - strcmp( theContainer.c_str() , "FactoryServerPy" ) ) { - MESSAGE("Container not found ! trying to start " << aComputerContainer); - Engines::Container_var myContainer = aFactoryServer->start_impl( theContainer.c_str() ) ; - if ( !CORBA::is_nil( myContainer ) ) { - MESSAGE("Container " << aComputerContainer << " started"); - return myContainer ; - } - else { - MESSAGE("Container " << aComputerContainer << " NOT started"); - } - } - else { - MESSAGE("Container " << aComputerContainer << " started"); - return aFactoryServer ; - } - } + return _MyContainersMgr->FindComponent( MyParams , ComponentName ) ; +} + +Engines::ListOfComponents_var SALOME_LifeCycleCORBA::FindComponents( Containers::MachineParameters & MyParams , + const char * ComponentName ) { + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; } - return Engines::Container::_nil(); + return _MyContainersMgr->FindComponents( MyParams , ComponentName ) ; } -Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component - (const char *containerName, - const char *componentName, - const char *implementation) -{ - BEGIN_OF("FindOrLoad_Component(1)"); - ASSERT(_NS != NULL); +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component( const char *containerName , + const char *componentName , + const char *implementation ) { + Containers::MachineParameters * MyParams = _MyContainersMgr->Parameters() ; string theComputer ; string theContainer ; - string theComputerContainer = ContainerName( containerName , - &theComputer , - &theContainer ) ; - Engines::Container_var cont = FindOrStartContainer( theComputerContainer , - theComputer , - theContainer ) ; + ContainerName( containerName , &theComputer , &theContainer ) ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + int l = strlen( containerName ) ; + if ( strcmp( &containerName[ l-2 ] , "Py" ) ) { + MyParams->ContainerType = Engines::CppContainer ; + } + else { + MyParams->ContainerType = Engines::PythonContainer ; + } + return FindOrLoad_Component( *MyParams , componentName , implementation ) ; +} +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component( Containers::MachineParameters & MyParams , + const char * componentName , + const char * implementation ) { + + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + return _MyContainersMgr->FindOrLoad_ComponentPath( MyParams , componentName , implementation ) ; +// BEGIN_OF("FindOrLoad_Component(1)"); +// ASSERT(_NamingService != NULL); +// string theComputer ; +// string theContainer ; +// string theComputerContainer = ContainerName( containerName , +// &theComputer , +// &theContainer ) ; +// Engines::Container_var cont = FindOrStartContainer( theComputerContainer , +// theComputer , +// theContainer ) ; // ASSERT(!CORBA::is_nil(cont)); - string path( theComputerContainer ); - path = path + "/"; - path = path + componentName; - SCRUTE(path); - try - { - CORBA::Object_var obj = _NS->Resolve(path.c_str()); - if (CORBA::is_nil(obj)) - { - MESSAGE("Component not found ! trying to load " << path); - Engines::Component_var compo - = cont->load_impl(componentName, implementation); +// string path( theComputerContainer ); +// path = path + "/"; +// path = path + componentName; +// SCRUTE(path); +// try +// { +// CORBA::Object_var obj = _NamingService->Resolve(path.c_str()); +// if (CORBA::is_nil(obj)) +// { +// MESSAGE("Component not found ! trying to load " << path); +// Engines::Component_var compo +// = cont->load_impl(componentName, implementation); // ASSERT(!CORBA::is_nil(compo)); - MESSAGE("Component launched !" << path); - return compo; - } - else - { - MESSAGE("Component found !" << path); - Engines::Component_var compo = Engines::Component::_narrow(obj); +// MESSAGE("Component launched !" << path); +// return compo; +// } +// else +// { +// MESSAGE("Component found !" << path); +// Engines::Component_var compo = Engines::Component::_narrow(obj); // ASSERT(!CORBA::is_nil(compo)); - try - { - compo->ping(); - } - catch (CORBA::COMM_FAILURE&) - { - INFOS("Caught CORBA::SystemException CommFailure. Engine " - << path << "does not respond" ); - } - return compo; - } - } - catch (ServiceUnreachable&) - { - INFOS("Caught exception: Naming Service Unreachable"); - } - catch (...) - { - INFOS("Caught unknown exception."); - } - return Engines::Component::_nil(); +// try +// { +// compo->ping(); +// } +// catch (CORBA::COMM_FAILURE&) +// { +// INFOS("Caught CORBA::SystemException CommFailure. Engine " +// << path << "does not respond" ); +// } +// return compo; +// } +// } +// catch (ServiceUnreachable&) +// { +// INFOS("Caught exception: Naming Service Unreachable"); +// } +// catch (...) +// { +// INFOS("Caught unknown exception."); +// } +// return Engines::Component::_nil(); } -Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component - (const char *containerName, - const char *componentName) -{ -// BEGIN_OF("FindOrLoad_Component(2)"); - ASSERT(_NS != NULL); +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component( Containers::MachineParameters & MyParams , + const char * componentName ) { + if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { + MyParams.HostName = GetHostname().c_str() ; + } + return _MyContainersMgr->FindOrLoad_Component( MyParams , componentName ) ; +} + +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component( const char *containerName , + const char *componentName ) { + Containers::MachineParameters * MyParams = _MyContainersMgr->Parameters() ; string theComputer ; string theContainer ; - string theComputerContainer = ContainerName( containerName , - &theComputer , - &theContainer ) ; - Engines::Container_var cont = FindOrStartContainer( theComputerContainer , - theComputer , - theContainer ) ; - - if ( CORBA::is_nil( cont ) ) { - MESSAGE("Container not found ! " << theComputerContainer ); - return Engines::Component::_nil(); + ContainerName( containerName , &theComputer , &theContainer ) ; + MyParams->HostName = theComputer.c_str() ; + MyParams->ContainerName = theContainer.c_str() ; + int l = strlen( containerName ) ; + if ( strcmp( &containerName[ l-2 ] , "Py" ) ) { + MyParams->ContainerType = Engines::CppContainer ; } + else { + MyParams->ContainerType = Engines::PythonContainer ; + } + return FindOrLoad_Component( *MyParams , componentName ) ; +// BEGIN_OF("FindOrLoad_Component(2)"); +// ASSERT(_NamingService != NULL); +// string theComputer ; +// string theContainer ; +// string theComputerContainer = ContainerName( containerName , +// &theComputer , +// &theContainer ) ; +// Engines::Container_var cont = FindOrStartContainer( theComputerContainer , +// theComputer , +// theContainer ) ; +// +// if ( CORBA::is_nil( cont ) ) { +// MESSAGE("Container not found ! " << theComputerContainer ); +// return Engines::Component::_nil(); +// } // char * machine = cont->machineName() ; - const char * machine = theComputer.c_str() ; +// const char * machine = theComputer.c_str() ; - string path( theComputerContainer ); - path += "/"; - path += componentName; - SCRUTE(path); +// string path( theComputerContainer ); +// path += "/"; +// path += componentName; +// SCRUTE(path); - try { - CORBA::Object_var obj = _NS->Resolve(path.c_str()); - if ( CORBA::is_nil( obj ) ) { - MESSAGE("Component not found ! trying to load " << path); - CORBA::Object_var obj2 = _NS->Resolve("/Kernel/ModulCatalog"); - SALOME_ModuleCatalog::ModuleCatalog_var Catalog = - SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj2); - - SALOME_ModuleCatalog::Acomponent_ptr compoInfo = - Catalog->GetComponent(componentName); - if (CORBA::is_nil (compoInfo)) - { - INFOS("Catalog Error : Component not found in the catalog") - return Engines::Component::_nil(); +// try { +// CORBA::Object_var obj = _NamingService->Resolve(path.c_str()); +// if ( CORBA::is_nil( obj ) ) { +// MESSAGE("Component not found ! trying to load " << path); +// CORBA::Object_var obj2 = _NamingService->Resolve("/Kernel/ModulCatalog"); +// SALOME_ModuleCatalog::ModuleCatalog_var Catalog = +// SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj2); +// +// SALOME_ModuleCatalog::Acomponent_ptr compoInfo = +// Catalog->GetComponent(componentName); +// if (CORBA::is_nil (compoInfo)) +// { +// INFOS("Catalog Error : Component not found in the catalog") +// return Engines::Component::_nil(); // exit (-1); - } - - string path; - try - { - path = compoInfo->GetPathPrefix( machine ) ; - path += "/" ; - } - catch (SALOME_ModuleCatalog::NotFound&) - { - MESSAGE("GetPathPrefix(" << machine << ") not found!" - << "trying localhost"); - try { - path = compoInfo->GetPathPrefix("localhost") ; - path += "/" ; - } - catch (SALOME_ModuleCatalog::NotFound&) { - MESSAGE("GetPathPrefix(localhost) not found!") ; - path = "" ; - } - } - - SCRUTE(path); - string implementation(path); - implementation += "lib"; - implementation += componentName; - implementation += "Engine.so"; - - Engines::Component_var compo - = cont->load_impl(componentName, implementation.c_str()); - +// } +// +// string path; +// try +// { +// path = compoInfo->GetPathPrefix( machine ) ; +// path += "/" ; +// } +// catch (SALOME_ModuleCatalog::NotFound&) +// { +// MESSAGE("GetPathPrefix(" << machine << ") not found!" +// << "trying localhost"); +// try { +// path = compoInfo->GetPathPrefix("localhost") ; +// path += "/" ; +// } +// catch (SALOME_ModuleCatalog::NotFound&) { +// MESSAGE("GetPathPrefix(localhost) not found!") ; +// path = "" ; +// } +// } +// +// SCRUTE(path); +// string implementation(path); +// implementation += "lib"; +// implementation += componentName; +// implementation += "Engine.so"; +// +// Engines::Component_var compo +// = cont->load_impl(componentName, implementation.c_str()); +// // ASSERT(!CORBA::is_nil(compo)); // MESSAGE("Component launched !" << path); - return compo; - } - else - { - MESSAGE("Component found !" << path); - Engines::Component_var compo = Engines::Component::_narrow(obj); +// return compo; +// } +// else +// { +// MESSAGE("Component found !" << path); +// Engines::Component_var compo = Engines::Component::_narrow(obj); // ASSERT(!CORBA::is_nil(compo)); - try - { - string instanceName = compo->instanceName(); - } - catch (CORBA::COMM_FAILURE&) - { - INFOS("Caught CORBA::SystemException CommFailure. Engine " - << path << "does not respond" ); - } - return compo; - } - } - catch (ServiceUnreachable&) - { - INFOS("Caught exception: Naming Service Unreachable"); - } - catch (...) - { - INFOS("Caught unknown exception."); - } - return Engines::Component::_nil(); +// try +// { +// string instanceName = compo->instanceName(); +// } +// catch (CORBA::COMM_FAILURE&) +// { +// INFOS("Caught CORBA::SystemException CommFailure. Engine " +// << path << "does not respond" ); +// } +// return compo; +// } +// } +// catch (ServiceUnreachable&) +// { +// INFOS("Caught exception: Naming Service Unreachable"); +// } +// catch (...) +// { +// INFOS("Caught unknown exception."); +// } +// return Engines::Component::_nil(); } diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index d562f43f3..4ac0e1574 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -36,6 +36,8 @@ #include #include CORBA_CLIENT_HEADER(SALOME_Component) +#include CORBA_CLIENT_HEADER( ContainersManager ) + class SALOME_NamingService; class SALOME_LifeCycleCORBA @@ -45,24 +47,39 @@ public: SALOME_LifeCycleCORBA(SALOME_NamingService *ns); virtual ~SALOME_LifeCycleCORBA(); - Engines::Container_var FindContainer(const char *containerName); - Engines::Component_var FindOrLoad_Component(const char *containerName, - const char *componentName, - const char *implementationPath); - Engines::Component_var FindOrLoad_Component(const char *containerName, - const char *componentName); + Containers::MachineParameters_var Parameters() ; + + Engines::Container_var FindContainer( const char *containerName ) ; + Engines::Container_var FindContainer( Containers::MachineParameters & MyParams ) ; + Engines::ListOfContainers_var FindContainers( Containers::MachineParameters & MyParams ) ; + Engines::Component_var FindComponent( Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + Engines::ListOfComponents_var FindComponents( Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + Engines::Component_var FindOrLoad_Component( const char *containerName , + const char *componentName , + const char *implementationPath ) ; + Engines::Component_var FindOrLoad_Component( Containers::MachineParameters & MyParams , + const char *componentName , + const char *implementationPath ) ; + Engines::Component_var FindOrLoad_Component( const char *containerName , + const char *componentName ) ; + Engines::Component_var FindOrLoad_Component( Containers::MachineParameters & MyParams , + const char *componentName ) ; protected: - SALOME_NamingService *_NS; + Containers::Manager_var _MyContainersMgr ; + SALOME_NamingService * _NamingService ; Engines::Container_var _FactoryServer ; - std::string ComputerPath( const char * theComputer ) ; - std::string ContainerName( const char * aComputerContainer , - std::string * theComputer , - std::string * theContainer ) ; +// std::string ComputerPath( const char * theComputer ) ; private: - Engines::Container_var FindOrStartContainer(const std::string aComputerContainer , - const std::string theComputer , - const std::string theContainer ) ; + std::string ContainerName( const char * aComputerContainer , + std::string * theComputer , + std::string * theContainer ) ; + +// Engines::Container_var FindOrStartContainer(const std::string aComputerContainer , +// const std::string theComputer , +// const std::string theContainer ) ; } ; diff --git a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx b/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx index 603c32814..901b72dca 100644 --- a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx @@ -40,8 +40,10 @@ using namespace std; int main (int argc, char * argv[]) { - try - { + try { + int i = 0 ; + while ( argv[ i ] ) { + MESSAGE(" argv" << i << " " << argv[ i ]) ; // Initializing omniORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); @@ -49,15 +51,26 @@ int main (int argc, char * argv[]) CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ; PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ; + MESSAGE( "SALOME_NamingService :" ) ; SALOME_NamingService _NS(orb) ; + MESSAGE( "SALOME_LifeCycleCORBA :" ) ; SALOME_LifeCycleCORBA _LCC(&_NS) ; // get a local container (with a name based on local hostname), // load an engine, and invoque methods on that engine - string containerName = GetHostname(); - + string containerName ; + if ( i == 0 ) { + containerName = GetHostname() ; + } + else { + containerName = argv[ i ] ; + } + containerName += "/" ; + containerName += "TestComponentCpp" ; + + MESSAGE("FindOrLoad_Component( " << containerName << " , SalomeTestComponent )" ) ; Engines::Component_var mycompo = _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); @@ -74,8 +87,17 @@ int main (int argc, char * argv[]) // get another container (with a fixed name), // load an engine, and invoque methods on that engine - string containerName2 = "FactoryServerPy"; - + string containerName2 ; + if ( i == 0 ) { + containerName2 = GetHostname() ; + } + else { + containerName2 = argv[ i ] ; + } + containerName2 += "/" ; + containerName2 += "TestComponentPy" ; + + MESSAGE("FindOrLoad_Component( " << containerName2 << " , SALOME_TestComponentPy )" ) ; Engines::Component_var mycompo2 = _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy"); @@ -88,7 +110,9 @@ int main (int argc, char * argv[]) SCRUTE(m2->instanceName()); MESSAGE("Coucou " << m2->Coucou(1L)); + i++ ; } + } catch(CORBA::COMM_FAILURE& ex) { INFOS("Caught system exception COMM_FAILURE -- unable to contact the object."); -- 2.39.2