From: rahuel Date: Wed, 10 Mar 2004 12:33:28 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e9d444f39c8c06a92438f8c3b8580b838f960f3b;p=modules%2Fkernel.git *** empty log message *** --- diff --git a/bin/killSalome.py b/bin/killSalome.py index 814420dfa..b113d04ed 100755 --- a/bin/killSalome.py +++ b/bin/killSalome.py @@ -10,13 +10,40 @@ process_id={} # def killSalome(): + print "arret du serveur ContainersManager ==> arret des containers" + import os + import sys + import string + from omniORB import CORBA + import CosNaming + import Engines + import Containers + try : + orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + obj = orb.resolve_initial_references("NameService") + rootContext = obj._narrow(CosNaming.NamingContext) + if rootContext is None: + print "Name Service Reference is invalid" + else : + name = [CosNaming.NameComponent("Kernel","dir"), + CosNaming.NameComponent("ContainersManager","object")] + obj = rootContext.resolve( name ) + MyContainersMgr = obj._narrow(Containers.Manager) + print "MyContainersMgr.ping :",MyContainersMgr.ping() + MyContainersMgr.destroy() + MyContainersMgrdestroyed = 1 + except : + print "Cannot destroy the ContainersManager" + MyContainersMgrdestroyed = 0 + print "arret des serveurs SALOME" for pid, cmd in process_id.items(): - print "arret du process %s : %s"% (pid, cmd[0]) - try: - os.kill(pid,signal.SIGKILL) - except: - print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) + if ((cmd[0] != 'ContainersManager_Server') | (MyContainersMgrdestroyed == 0)) & (cmd[0] != 'startContainer.py') : + print "arret du process %s : %s"% (pid, cmd[0]) + try: + os.kill(pid,signal.SIGKILL) + except: + print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) print "arret du naming service" os.system("killall -9 omniNames") diff --git a/bin/runSalome.py b/bin/runSalome.py index 1f267ed6f..6deefa915 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -23,13 +23,40 @@ usage="""USAGE: runSalome.py [options] # def killSalome(): + print "arret du serveur ContainersManager ==> arret des containers" + import os + import sys + import string + from omniORB import CORBA + import CosNaming + import Engines + import Containers + try : + orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + obj = orb.resolve_initial_references("NameService") + rootContext = obj._narrow(CosNaming.NamingContext) + if rootContext is None: + print "Name Service Reference is invalid" + else : + name = [CosNaming.NameComponent("Kernel","dir"), + CosNaming.NameComponent("ContainersManager","object")] + obj = rootContext.resolve( name ) + MyContainersMgr = obj._narrow(Containers.Manager) + print "MyContainersMgr.ping :",MyContainersMgr.ping() + MyContainersMgr.destroy() + MyContainersMgrdestroyed = 1 + except : + print "Cannot destroy the ContainersManager" + MyContainersMgrdestroyed = 0 + print "arret des serveurs SALOME" for pid, cmd in process_id.items(): - print "arret du process %s : %s"% (pid, cmd[0]) - try: - os.kill(pid,signal.SIGKILL) - except: - print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) + if ((cmd[0] != 'ContainersManager_Server') | (MyContainersMgrdestroyed == 0)) & (cmd[0] != 'startContainer.py') : + print "arret du process %s : %s"% (pid, cmd[0]) + try: + os.kill(pid,signal.SIGKILL) + except: + print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) print "arret du naming service" os.system("killall -9 omniNames") diff --git a/idl/ContainersManager.idl b/idl/ContainersManager.idl index 57b6eccb8..fbf5e7c09 100644 --- a/idl/ContainersManager.idl +++ b/idl/ContainersManager.idl @@ -55,7 +55,8 @@ module Containers { boolean ping() ; - Engines::Container FindOneContainer( in string aContainerName ) ; + Engines::Container FindOneContainer( in string aHostName , + in string aContainerName ) ; Engines::Container FindContainer( in MachineParameters MyParams ) ; @@ -66,7 +67,8 @@ module Containers { Engines::Component FindComponent( in MachineParameters MyParams , in string ComponentName ) ; - Engines::Component FindOneComponent( in string aContainerName , + Engines::Component FindOneComponent( in string aHostName , + in string aContainerName , in string ComponentName ) ; Engines::ListOfComponents FindComponents( in MachineParameters MyParams , @@ -79,6 +81,10 @@ module Containers { Engines::Component FindOrLoad_Component( in MachineParameters MyParams , in string ComponentName ) ; + boolean DestroyContainer( in string aHostName , in string aContainerName ) ; + + boolean DestroyContainers( in MachineParameters MyParams ) ; + void destroy() ; } ; diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index 09d463416..374b3fd5b 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -28,6 +28,7 @@ using namespace std; #include "SALOME_Component_i.hxx" +#include "SALOME_NamingService.hxx" #include "RegistryConnexion.hxx" #include "OpUtil.hxx" #include @@ -91,6 +92,27 @@ Engines_Component_i::~Engines_Component_i() // _myConnexionToRegistry = 0 ; } +void Engines_Component_i::destroy() +{ + MESSAGE("Engines_Component_i::destroy()"); + + delete _notifSupplier; + _notifSupplier = 0; + + delete _myConnexionToRegistry; + _myConnexionToRegistry = 0 ; + string aRegisteredName = GetContainerRef()->name() + string("/") + _interfaceName ; + SALOME_NamingService * _NamingService = new SALOME_NamingService( _orb ) ; + MESSAGE("Engines_Component_i::destroy NamingService->Destroy_Name " << aRegisteredName ) ; + _NamingService->Destroy_Name( aRegisteredName.c_str() ) ; + delete _NamingService ; + _poa->deactivate_object( *_id ) ; + CORBA::release( _poa ) ; + delete( _id ) ; + _thisObj->_remove_ref(); + MESSAGE("Engines_Component_i::destroyed") ; +} + char* Engines_Component_i::instanceName() { return CORBA::string_dup(_instanceName.c_str()) ; } @@ -105,22 +127,6 @@ void Engines_Component_i::ping() << pthread_self()); } -void Engines_Component_i::destroy() -{ - MESSAGE("Engines_Component_i::destroy()"); - - delete _notifSupplier; - _notifSupplier = 0; - - delete _myConnexionToRegistry; - _myConnexionToRegistry = 0 ; - _poa->deactivate_object(*_id) ; - CORBA::release(_poa) ; - delete(_id) ; - _thisObj->_remove_ref(); - MESSAGE("Engines_Component_i::destroyed") ; -} - Engines::Container_ptr Engines_Component_i::GetContainerRef() { MESSAGE("Engines_Component_i::GetContainerRef"); diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index c2c40cf73..5bfa2d2fc 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -150,9 +150,10 @@ Engines_Container_i::~Engines_Container_i() void Engines_Container_i::destroy() { MESSAGE( "Container_i::destroy" ) ; - _poa->deactivate_object(*_id) ; - CORBA::release(_poa) ; - delete(_id) ; + _NS->Destroy_Name( _containerName.c_str() ) ; + _poa->deactivate_object( *_id ) ; + CORBA::release( _poa ) ; + delete( _id ) ; this->_remove_ref(); } @@ -241,7 +242,8 @@ Engines::Container_ptr Engines_Container_i::start_impl( const char* ContainerNam } shstr += " > /tmp/" ; shstr += ContainerName ; - shstr += ".log 2>&1 &" ; + shstr += ".log 2>&1" ; + shstr += " &" ; MESSAGE("system(" << shstr << ")") ; int status = system( shstr.c_str() ) ; if (status == -1) { @@ -378,7 +380,7 @@ void Engines_Container_i::remove_impl(Engines::Component_ptr component_i) { ASSERT(! CORBA::is_nil(component_i)); string component_registerName = _containerName + "/" + component_i->interfaceName() ; - _NS->Destroy_Name( component_registerName.c_str() ) ; +// _NS->Destroy_Name( component_registerName.c_str() ) ; string instanceName = component_i->instanceName() ; MESSAGE("unload component " << instanceName); component_i->destroy() ; diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 6de14924a..edc5e05e1 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -59,9 +59,11 @@ class SALOME_ComponentPy_i (Engines__POA.Component): MESSAGE( "SALOME_ComponentPy_i::__init__" + " " + str (containerName) + " " + str(instanceName) + " " + str(interfaceName) ) self._orb = orb self._poa = poa + self._contId = self._poa.reference_to_id( contID ) self._instanceName = instanceName self._interfaceName = interfaceName self._containerName = containerName + self._Id = None self._notif = notif self._myConnexionToRegistry = 0 self._graphName = '' @@ -72,9 +74,11 @@ class SALOME_ComponentPy_i (Engines__POA.Component): self._Executed = 0 naming_service = SALOME_NamingServicePy_i(self._orb) + self.naming_service = naming_service Component_path = "/Containers/" + os.getenv( "HOSTNAME" ) + "/" + self._containerName + "/" + self._interfaceName MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) ) - naming_service.Register(self._this(), Component_path) + naming_service.Register( self._this(), Component_path ) + self.Component_path = Component_path # Add componentinstance to registry obj = naming_service.Resolve('/Registry') @@ -126,13 +130,28 @@ class SALOME_ComponentPy_i (Engines__POA.Component): def destroy(self): MESSAGE( "SALOME_ComponentPy_i::destroy" ) - poa.deactivate_object(self) - CORBA.release(_poa) + self.naming_service.Destroy_Name( self.Component_path ) + self._poa.deactivate_object( self._Id ) + MESSAGE( "SALOME_ComponentPy_i::destroy _poa.deactivate_object done" ) + #self._poa._release() + #self._delete( self._Id ) + #self._remove_ref() + MESSAGE( "SALOME_ComponentPy_i::destroyed" ) #------------------------------------------------------------------------- def GetContainerRef(self): MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" ) + theContainer = None + try : + obj = self._poa.id_to_reference( self._contId ) + try : + theContainer = obj._narrow( Engines.Container ) + except : + print "SALOME_ComponentPy_i::GetContainerRef _narrow( Engines.Container ) exception" + except : + print "SALOME_ComponentPy_i::GetContainerRef _poa.id_to_reference( _contId ) exception" + return theContainer #------------------------------------------------------------------------- diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 42ade5739..3e2eeff6a 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -52,23 +52,40 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- - def __init__(self, orb, poa, containerName): - MESSAGE( "SALOME_ContainerPy_i::__init__" ) + def __init__( self , orb , poa , containerName ): + MESSAGE( "SALOME_ContainerPy_i::__init__ " + containerName ) self._orb = orb self._poa = poa self._containerName = containerName + self._contId = self._poa.reference_to_id( self._this() ) myMachine=string.split(os.getenv( "HOSTNAME" ),'.') self._machineName = myMachine[0] - naming_service = SALOME_NamingServicePy_i(self._orb) - self._naming_service = naming_service + self.naming_service = SALOME_NamingServicePy_i(self._orb) Container_path = "/Containers/" + myMachine[0] + "/" + self._containerName self._Name = Container_path MESSAGE( str(Container_path) ) - naming_service.Register(self._this(), Container_path) + self.naming_service.Register( self._this() , Container_path ) #------------------------------------------------------------------------- + def destroy(self): + MESSAGE( "SALOME_ContainerPy_i::destroy" ) + self.naming_service.Destroy_Name( self._Name ) ; + print "SALOME_ContainerPy_i::destroy _poa.deactivate_object id",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" ) + #self.delete( self._contId ) + #MESSAGE( "SALOME_ContainerPy_i::destroy self._contId deleted" ) + #self._remove_ref() + #MESSAGE( "SALOME_ContainerPy_i::destroy self _removed_ref" ) + MESSAGE( "SALOME_ContainerPy_i::destroyed" ) + sys.exit(0) + + #------------------------------------------------------------------------- + def start_impl( self , ContainerName , ContainerType ) : MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) ) myMachine=string.split(os.getenv( "HOSTNAME" ),'.') @@ -105,11 +122,8 @@ class SALOME_ContainerPy_i (Engines__POA.Container): shstr += " > " shstr += fileName - shstr += " 2>&1 &" - - #shstr += " > /tmp/" - #shstr += ContainerName - #shstr += ".log 2>&1 &" + shstr += " 2>&1" + shstr += " &" MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" ) os.system( shstr ) @@ -184,11 +198,13 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #initialise the ORB and find the root POA orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) +print "CORBA.ORB_init done" poa = orb.resolve_initial_references("RootPOA") +print "orb.resolve_initial_references('RootPOA') done" #create an instance of SALOME_ContainerPy_i and a Container reference #containerName = "FactoryServerPy" -MESSAGE( str(sys.argv) ) +MESSAGE( "SALOME_ContainerPy.py " + str(sys.argv) ) containerName = sys.argv[1] cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) cpy_o = cpy_i._this() @@ -200,8 +216,7 @@ poaManager.activate() #Block for ever orb.run() - - - - +print "SALOME_ContainerPy --> orb.destroy" +orb.destroy() +print "SALOME_ContainerPy orb.destroyed" diff --git a/src/ContainersManager/ContainersManager_i.cxx b/src/ContainersManager/ContainersManager_i.cxx index 8907437ac..cddddc870 100644 --- a/src/ContainersManager/ContainersManager_i.cxx +++ b/src/ContainersManager/ContainersManager_i.cxx @@ -113,8 +113,9 @@ void Manager_i::destroy() { for ( i = 0 ; i < _ListOfEnginesComponents.size() ; i++ ) { try { // _NamingService->Destroy_Name( _ListOfComponentsNames[ i ].c_str() ) ; + MESSAGE( "Manager_i::destroy try destroy Component " << _ListOfComponentsNames[ i ] ) ; _ListOfEnginesComponents[ i ]->destroy() ; - MESSAGE( "Manager_i::destroy Component " << _ListOfComponentsNames[ i ] ) ; + MESSAGE( "Manager_i::destroy Component " << _ListOfComponentsNames[ i ] << " destroyed" ) ; } catch ( ... ) { MESSAGE( "Manager_i::destroy Component " << _ListOfComponentsNames[ i ] << " failed" ) ; @@ -164,39 +165,39 @@ bool 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 ; -} +//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::Container_ptr Manager_i::FindContainer( const Containers::MachineParameters & myParams ) { Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; @@ -235,20 +236,15 @@ Engines::Container_ptr Manager_i::FindContainer( const Containers::MachineParame return Engines::Container::_duplicate( aContainer ) ; } -Engines::Container_ptr Manager_i::FindOneContainer( const char * aContainerName ) { +Engines::Container_ptr Manager_i::FindOneContainer( const char * aHostName , + const char * aContainerName ) { Containers::MachineParameters * MyParams = Parameters() ; - string theComputer ; - string theContainer ; - ContainerName( aContainerName , &theComputer , &theContainer ) ; + string theComputer = aHostName ; + string theContainer = aContainerName ; +// ContainerName( aContainerName , &theComputer , &theContainer ) ; MyParams->HostName = theComputer.c_str() ; MyParams->ContainerName = theContainer.c_str() ; - int l = strlen( aContainerName ) ; - if ( strcmp( &aContainerName[ l-2 ] , "Py" ) ) { - MyParams->ContainerType = Engines::Cpp ; - } - else { - MyParams->ContainerType = Engines::Python ; - } + MyParams->ContainerType = Engines::Undefined ; if ( strcmp( MyParams->HostName ,"localhost" ) == 0 ) { MyParams->HostName = GetHostname().c_str() ; } @@ -263,9 +259,6 @@ Engines::ListOfContainers * Manager_i::FindContainers( const Containers::Machine if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { MyParams.HostName = GetHostname().c_str() ; } - if ( strlen( MyParams.ContainerName ) && MyParams.ContainerType == Engines::Undefined ) { - MyParams.ContainerType = Engines::Cpp ; - } MESSAGE( "Manager_i::FindContainers MutexManager pthread_mutex_lock :" ) ; if ( pthread_mutex_lock( &_MutexManager ) ) { perror("Manager_i::FindContainersMutexManager pthread_mutex_lock ") ; @@ -357,6 +350,7 @@ Engines::ListOfContainers * Manager_i::FindContainersLocked( Containers::Machine if ( !CORBA::is_nil( _ContainerObject ) ) { try { _EnginesContainer = Engines::Container::_narrow( _ContainerObject ) ; + _EnginesContainer->ping() ; if ( MyParams.ContainerType == Engines::Undefined || _EnginesContainer->type() == MyParams.ContainerType ) { int size = _ListOfContainers->length() ; @@ -374,6 +368,7 @@ Engines::ListOfContainers * Manager_i::FindContainersLocked( Containers::Machine } catch( ... ) { MESSAGE( "Manager_i::FindContainers " << _FullContainerName << " catched NOT responding" ) ; + _EnginesContainer = Engines::Container::_nil() ; } } else { @@ -486,6 +481,7 @@ Engines::Container_ptr Manager_i::FindOrStartContainerLocked( Containers::Machin << _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 ) ; @@ -494,6 +490,7 @@ Engines::Container_ptr Manager_i::FindOrStartContainerLocked( Containers::Machin } catch ( ... ) { MESSAGE( "Manager_i::FindOrStartContainerLocked catched NOT responding" ) ; + _EnginesComponent = Engines::Component::_nil() ; } } } @@ -506,16 +503,20 @@ Engines::Container_ptr Manager_i::FindOrStartContainerLocked( Containers::Machin MESSAGE( "Manager_i::FindOrStartContainerLocked Component " << _FullComponentName ) ; _ComponentObject = _NamingService->Resolve( _FullComponentName.c_str() ) ; if ( !CORBA::is_nil( _ComponentObject ) ) { - MESSAGE( "Manager_i::FindOrStartContainerLocked --> " << _EnginesContainer->machineName() << " " - << _EnginesContainer->name() << " Component " << _FullComponentName ) ; 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 { @@ -733,7 +734,7 @@ Engines::Component_ptr Manager_i::FindComponent( const Containers::MachineParame Engines::Component_ptr aComponent = Engines::Component::_nil() ; try { _StartContainer = false ; - aComponent = Find_Component( myParams , ComponentName ) ; + aComponent = FindComponentLocked( myParams , ComponentName ) ; } catch ( ... ) { MESSAGE( "Manager_i::FindComponent catched" ) ; @@ -746,45 +747,40 @@ Engines::Component_ptr Manager_i::FindComponent( const Containers::MachineParame return aComponent ; } -Engines::Component_ptr Manager_i::Find_Component( const Containers::MachineParameters & myParams , - const char * ComponentName ) { +Engines::Component_ptr Manager_i::FindComponentLocked( const Containers::MachineParameters & myParams , + const char * ComponentName ) { Containers::MachineParameters MyParams = (Containers::MachineParameters & ) myParams ; if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { MyParams.HostName = GetHostname().c_str() ; } - MESSAGE( "FindComponent HostName " << MyParams.HostName << " ContainerName " << MyParams.ContainerName + MESSAGE( "FindComponentLocked HostName " << MyParams.HostName << " ContainerName " << MyParams.ContainerName << " ComponentName " << ComponentName ) ; FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; if ( CORBA::is_nil( _EnginesComponent ) ) { - MESSAGE( "FindComponent ComponentName " << ComponentName << " NOT found" ) ; + MESSAGE( "FindComponentLocked ComponentName " << ComponentName << " NOT found" ) ; } else { - MESSAGE( "FindComponent instanceName " << _EnginesComponent->instanceName() << " interfaceName " - << _EnginesComponent->interfaceName() ) ; + MESSAGE( "FindComponentLocked instanceName " << _EnginesComponent->instanceName() + << " interfaceName " << _EnginesComponent->interfaceName() ) ; } return Engines::Component::_duplicate( _EnginesComponent ) ; } -Engines::Component_ptr Manager_i::FindOneComponent( const char * aContainerName , +Engines::Component_ptr Manager_i::FindOneComponent( const char * aHostName , + const char * aContainerName , const char * ComponentName ) { Containers::MachineParameters * MyParams = Parameters() ; - string theComputer ; - string theContainer ; - ContainerName( aContainerName , &theComputer , &theContainer ) ; + string theComputer = aHostName ; + string theContainer = aContainerName ; +// ContainerName( aContainerName , &theComputer , &theContainer ) ; MyParams->HostName = theComputer.c_str() ; MyParams->ContainerName = theContainer.c_str() ; - int l = strlen( aContainerName ) ; - if ( strcmp( &aContainerName[ l-2 ] , "Py" ) ) { - MyParams->ContainerType = Engines::Cpp ; - } - else { - MyParams->ContainerType = Engines::Python ; - } + MyParams->ContainerType = Engines::Undefined ; if ( strcmp( MyParams->HostName ,"localhost" ) == 0 ) { MyParams->HostName = GetHostname().c_str() ; } - MESSAGE( "Manager_i::FindOneComponent " << MyParams->HostName << " " << MyParams->ContainerName ) ; - MESSAGE( "FindComponents HostName " << MyParams->HostName << " ContainerName " << MyParams->ContainerName + 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 ) ) { @@ -792,7 +788,7 @@ Engines::Component_ptr Manager_i::FindOneComponent( const char * aContainerName exit( 0 ) ; } MESSAGE( "Manager_i::FindOneComponent MutexManager pthread_mutex_locked" ) ; - Engines::Component_ptr aComponent = Find_Component( *MyParams , ComponentName ) ; + Engines::Component_ptr aComponent = FindComponentLocked( *MyParams , ComponentName ) ; if ( pthread_mutex_unlock( &_MutexManager ) ) { perror("Manager_i::FindOneComponent MutexManager pthread_mutex_unlock ") ; exit( 0 ) ; @@ -816,15 +812,27 @@ Engines::ListOfComponents * Manager_i::FindComponents( const Containers::Machine 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::FindComponentsMutexManager pthread_mutex_unlock ") ; + exit( 0 ) ; + } + MESSAGE( "Manager_i::FindComponentsMutexManager 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 { _StartContainer = false ; _EnginesContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; if ( _ListOfComponents->length() ) { - MESSAGE( "FindComponents " << _ListOfComponents->length() << " components" ) ; + MESSAGE( "FindComponentsLocked " << _ListOfComponents->length() << " components" ) ; int i ; for ( i = 0 ; i < _ListOfComponents->length() ; i++ ) { - MESSAGE( "FindComponents" << i << " instanceName " << _ListOfComponents[ i ]->instanceName() + MESSAGE( "FindComponentsLocked " << i << " instanceName " << _ListOfComponents[ i ]->instanceName() << " interfaceName " << _ListOfComponents[ i ]->interfaceName() ) ; _ListOfComponents[ i ]->ping() ; } @@ -832,23 +840,18 @@ Engines::ListOfComponents * Manager_i::FindComponents( const Containers::Machine else if ( !CORBA::is_nil( _EnginesComponent ) ) { _ListOfComponents->length( 1 ) ; _ListOfComponents[ 0 ] = Engines::Component::_duplicate( _EnginesComponent ) ; - MESSAGE( "FindComponents instanceName " << _EnginesComponent->instanceName() << " interfaceName " + MESSAGE( "FindComponentsLocked instanceName " << _EnginesComponent->instanceName() << " interfaceName " << _EnginesComponent->interfaceName() << " " << _ListOfComponents->length() << " components" ) ; _ListOfComponents[ 0 ]->ping() ; } else { - MESSAGE( "FindComponents ComponentName " << ComponentName << " NOT found" ) ; + MESSAGE( "FindComponentsLocked ComponentName " << ComponentName << " NOT found" ) ; } aListOfComponents = _ListOfComponents ; } catch ( ... ) { - MESSAGE( "Manager_i::FindComponents catched" ) ; + MESSAGE( "Manager_i::FindComponentsLocked catched" ) ; } - if ( pthread_mutex_unlock( &_MutexManager ) ) { - perror("Manager_i::FindComponentsMutexManager pthread_mutex_unlock ") ; - exit( 0 ) ; - } - MESSAGE( "Manager_i::FindComponentsMutexManager pthread_mutex_unlocked" ) ; return aListOfComponents._retn() ; } @@ -871,7 +874,7 @@ Engines::Component_ptr Manager_i::FindOrLoad_ComponentPath( const Containers::Ma MESSAGE( "Manager_i::FindOrLoad_ComponentPath MutexManager pthread_mutex_locked" ) ; try { _StartContainer = true ; - EnginesComponent = Find_Component( MyParams , ComponentName ) ; + EnginesComponent = FindComponentLocked( MyParams , ComponentName ) ; if ( CORBA::is_nil( EnginesComponent ) ) { MESSAGE("FindOrLoad_ComponentPath Component not found " << _ComponentName ) ; // aContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; @@ -937,7 +940,9 @@ Engines::Component_ptr Manager_i::FindOrLoad_Component( const Containers::Machin if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { MyParams.HostName = GetHostname().c_str() ; } - BEGIN_OF("FindOrLoad_Component( const Containers::MachineParameters & MyParams , const char * ComponentName )"); + 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 ") ; @@ -946,7 +951,7 @@ Engines::Component_ptr Manager_i::FindOrLoad_Component( const Containers::Machin MESSAGE( "Manager_i::FindOrLoad_Component MutexManager pthread_mutex_locked" ) ; try { _StartContainer = true ; - EnginesComponent = Find_Component( MyParams , ComponentName ) ; + EnginesComponent = FindComponentLocked( MyParams , ComponentName ) ; if ( CORBA::is_nil( EnginesComponent ) ) { MESSAGE("FindOrLoad_Component Component not found " << _FullComponentName ) ; // aContainer = FindOrStartContainerLocked( (Containers::MachineParameters & ) MyParams , ComponentName ) ; @@ -967,10 +972,17 @@ Engines::Component_ptr Manager_i::FindOrLoad_Component( const Containers::Machin } MESSAGE( "Manager_i::FindOrLoad_Component MutexManager pthread_mutex_unlocked" ) ; if ( !CORBA::is_nil( aContainer ) && CORBA::is_nil( EnginesComponent ) ) { - MESSAGE("FindOrLoad_Component Component not found ! trying to load " << aFullComponentName ) ; - string ImplementationPath( "lib" ) ; - ImplementationPath += ComponentName ; - ImplementationPath += "Engine.so" ; + string ImplementationPath ; + if ( MyParams.ContainerType == Engines::Python ) { + 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 ) ) { @@ -1095,3 +1107,91 @@ Engines::Component_ptr Manager_i::FindOrLoad_Component( const Containers::Machin // 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::Undefined ; + 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 { + aListOfComponents[ i ]->destroy() ; + MESSAGE( "Manager_i::DestroyContainer component destroyed" ) ; + } + catch ( ... ) { + MESSAGE( "Manager_i::DestroyContainer destroy component catched" ) ; + } + } + try { + 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 ; +} + diff --git a/src/ContainersManager/ContainersManager_i.hxx b/src/ContainersManager/ContainersManager_i.hxx index cc538e95b..b0bcd2d47 100644 --- a/src/ContainersManager/ContainersManager_i.hxx +++ b/src/ContainersManager/ContainersManager_i.hxx @@ -88,9 +88,9 @@ class Manager_i : public POA_Containers::Manager , vector< string > _ListOfComponentsNames ; vector< Engines::Component_var > _ListOfEnginesComponents ; - std::string ContainerName( const char * aComputerContainer , - std::string * theComputer , - std::string * theContainer ) ; +// std::string ContainerName( const char * aComputerContainer , +// std::string * theComputer , +// std::string * theContainer ) ; Engines::Container_ptr StartContainer( const Containers::MachineParameters & myParams ) ; @@ -99,8 +99,11 @@ class Manager_i : public POA_Containers::Manager , Engines::Container_ptr FindOrStartContainerLocked( Containers::MachineParameters & MyParams , const char * ComponentName ) ; - Engines::Component_ptr Find_Component( const Containers::MachineParameters & MyParams , - const char * ComponentName ) ; + Engines::Component_ptr FindComponentLocked( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; + + Engines::ListOfComponents * FindComponentsLocked( const Containers::MachineParameters & MyParams , + const char * ComponentName ) ; public: @@ -122,7 +125,8 @@ class Manager_i : public POA_Containers::Manager , virtual Engines::Container_ptr FindContainer( const Containers::MachineParameters & MyParams ) ; - virtual Engines::Container_ptr FindOneContainer( const char * aContainerName ) ; + virtual Engines::Container_ptr FindOneContainer( const char * aHostName , + const char * aContainerName ) ; virtual Engines::ListOfContainers * FindContainers( const Containers::MachineParameters & MyParams ) ; @@ -131,7 +135,8 @@ class Manager_i : public POA_Containers::Manager , virtual Engines::Component_ptr FindComponent( const Containers::MachineParameters & MyParams , const char * ComponentName ) ; - virtual Engines::Component_ptr FindOneComponent( const char * aContainerName , + virtual Engines::Component_ptr FindOneComponent( const char * aHostName , + const char * aContainerName , const char * ComponentName ) ; virtual Engines::ListOfComponents * FindComponents( const Containers::MachineParameters & MyParams , @@ -144,6 +149,11 @@ class Manager_i : public POA_Containers::Manager , 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 ) ; + } ; #endif diff --git a/src/ContainersManager/TestContainersManager.py b/src/ContainersManager/TestContainersManager.py index 7b8c62f78..e2dd9348a 100644 --- a/src/ContainersManager/TestContainersManager.py +++ b/src/ContainersManager/TestContainersManager.py @@ -1,10 +1,6 @@ #ContainersManager_Server -ORBInitRef NameService=corbaname::localhost -import Engines - -import Containers - def ContainerParameters( Params ) : print "ContainerParameters :" print "Os :",Params.Os @@ -47,6 +43,12 @@ def ComputerEnvironement( env ) : print 'CasRoot ',env.CasRoot +import Engines + +import Containers + +import Resources + MyContainersMgr = clt.waitNS("/Kernel/ContainersManager",Containers.Manager) @@ -95,8 +97,6 @@ while i < len( Containers ) : #ResourcesManager_Server -common /home/Salome2/KERNEL_install/share/salome/resources/ResourcesCatalog.xml -ORBInitRef NameService=corbaname::localhost -import Resources - MyResourcesMgr = clt.waitNS("/Kernel/ResourcesManager",Resources.Manager) MyResourcesMgr.ping() @@ -218,24 +218,18 @@ while i < len( Containers ) : aContainer = MyContainersMgr.FindContainer( DefaultParams ) print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() -aContainer = MyContainersMgr.FindOneContainer( 'FactoryServer' ) +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'FactoryServer' ) print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() -aContainer = MyContainersMgr.FindOneContainer( 'FactoryServerPy' ) +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'FactoryServerPy' ) print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() -aContainer = MyContainersMgr.FindOneContainer( 'SuperVisionContainer' ) +aContainer = MyContainersMgr.FindOneContainer( 'localhost' , 'SuperVisionContainer' ) print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() -aContainer = MyContainersMgr.FindOneContainer( 'localhost/FactoryServer' ) +aContainer = MyContainersMgr.FindOneContainer( '' , 'SuperVisionContainer' ) print "Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() -aContainer = MyContainersMgr.FindOneContainer( 'bojolex/SuperVisionContainer' ) -if aContainer is None : - print "None Container : Ok" -else : - print "ERROR Container running on",aContainer._get_machineName(),"with name",aContainer._get_name(),"and type",aContainer.type() - DefaultParams.ContainerType = Engines.Cpp Containers = MyContainersMgr.FindContainers( DefaultParams ) i = 0 @@ -321,15 +315,59 @@ 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" ) + +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 + +aAddComponent = MyContainersMgr.FindOneComponent( '' , 'FactoryServer' , "AddComponent" ) print aAddComponent.GetContainerRef()._get_name(),aAddComponent._get_instanceName(),aAddComponent._get_interfaceName() -aSubComponent = MyContainersMgr.FindOneComponent( 'FactoryServer' , "SubComponent" ) +aSubComponent = MyContainersMgr.FindOneComponent( '' , 'FactoryServer' , "SubComponent" ) print aSubComponent.GetContainerRef()._get_name(),aSubComponent._get_instanceName(),aSubComponent._get_interfaceName() -aSUPERVComponent = MyContainersMgr.FindOneComponent( 'SuperVisionContainer' , "SUPERV" ) +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( 'dunex' , '' , "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.Python +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.Cpp +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 @@ -339,8 +377,20 @@ from LifeCycleCORBA import * orb = CORBA.ORB_init([''], CORBA.ORB_ID) lcc = LifeCycleCORBA( orb ) -t = lcc.FindOrLoadComponent( 'FactoryServer' , 'SalomeTestComponent' ) -print t +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() @@ -369,6 +419,7 @@ print "Container running on",aContainer._get_machineName(),"with name",aContaine 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 = '' @@ -401,5 +452,26 @@ DefaultParams.HostName = 'toto' lcctotoMulComponent = lcc.FindOrLoadComponent( DefaultParams , "MulComponent" ) +MyContainersMgr.DestroyContainer( '' , 'FactoryServer' ) +MyContainersMgr.DestroyContainer( '' , 'FactoryServerPy' ) + + +DefaultParams.HostName = '' +DefaultParams.ContainerName = '' +DefaultParams.ContainerType = Engines.Undefined + +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/NamingService/SALOME_NamingServicePy.py b/src/NamingService/SALOME_NamingServicePy.py index 2bc3c553c..38d15d18e 100644 --- a/src/NamingService/SALOME_NamingServicePy.py +++ b/src/NamingService/SALOME_NamingServicePy.py @@ -195,5 +195,44 @@ class SALOME_NamingServicePy_i: MESSAGE ( "Create_Directory : CORBA.COMM_FAILURE" ) + + #------------------------------------------------------------------------- + def Destroy_Name(self, Path): + #MESSAGE ( "SALOME_NamingServicePy_i::Destroy_Name" ) + path_list = list(Path) + if path_list[0]=='/': + self._current_context = self._root_context + #delete first '/' before split + Path=Path[1:] + + result_resolve_path = split(Path,'/') + _context_name=[] + print "Destroy_Name :" + for i in range(len(result_resolve_path)-1): + _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir")) + print result_resolve_path[i],"dir" + #_context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")) + print result_resolve_path[len(result_resolve_path)-1],"object" + try: + self._obj = self._current_context.resolve( _context_name ) + self._current_context = self._obj._narrow(CosNaming.NamingContext) + _context_name=[] + _context_name.append(CosNaming.NameComponent(result_resolve_path[len(result_resolve_path)-1],"object")) + self._current_context.unbind( _context_name ); + except CosNaming.NamingContext.NotFound, ex: + MESSAGE ( "Resolve : CosNaming.NamingContext.NotFound" ) + self._obj = None + except CosNaming.NamingContext.InvalidName, ex: + MESSAGE ( "Resolve : CosNaming.NamingContext.InvalidName" ) + self._obj = None + except CosNaming.NamingContext.CannotProceed, ex: + MESSAGE ( "Resolve : CosNaming.NamingContext.CannotProceed" ) + self._obj = None + except CORBA.COMM_FAILURE, ex: + MESSAGE ( "Resolve : CORBA.COMM_FAILURE" ) + self._obj = None + + + diff --git a/src/TestContainer/Makefile.in b/src/TestContainer/Makefile.in index 8ee409d99..eec3bda33 100644 --- a/src/TestContainer/Makefile.in +++ b/src/TestContainer/Makefile.in @@ -39,7 +39,7 @@ EXPORT_PYSCRIPTS = SALOME_TestComponentPy.py TestComponentPy.py LIB = libSalomeTestComponentEngine.la LIB_SRC = SALOME_TestComponent_i.cxx -LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl +LIB_CLIENT_IDL = ContainersManager.idl SALOME_Component.idl SALOME_TestComponent.idl # Executables targets BIN = TestContainer TestLogger diff --git a/src/TestContainer/SALOME_TestComponentPy.py b/src/TestContainer/SALOME_TestComponentPy.py index eb9867ab3..1b82ba324 100755 --- a/src/TestContainer/SALOME_TestComponentPy.py +++ b/src/TestContainer/SALOME_TestComponentPy.py @@ -42,8 +42,10 @@ class SALOME_TestComponentPy( Engines__POA.TestComponent, SALOME_ComponentPy_i): return result def __init__(self, orb, poa, contID, containerName, instanceName, interfaceName): + print "SALOME_TestComponentPy::__init__ --> SALOME_ComponentPy_i.__init__" notif = 0 SALOME_ComponentPy_i.__init__(self, orb, poa, contID, containerName, instanceName, interfaceName, notif) - print "SALOME_TestComponentPy::__init__" + self._Id = self._poa.reference_to_id( self._this() ) + print "SALOME_TestComponentPy::__init__ done" diff --git a/src/TestContainer/TestComponentPy.py b/src/TestContainer/TestComponentPy.py index 2dacf6dbb..d300cd995 100755 --- a/src/TestContainer/TestComponentPy.py +++ b/src/TestContainer/TestComponentPy.py @@ -28,13 +28,19 @@ # Module : SALOME # $Header$ +#python /home/Salome2/KERNEL_install/bin/salome/SALOME_ContainerPy.py TestContainerPy + import os import sys import string from omniORB import CORBA import CosNaming + import Engines +import Containers + +import SALOME_TestComponent_idl #initialise the ORB orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) @@ -47,28 +53,70 @@ if rootContext is None: print "Name Service Reference is invalid" sys.exit(1) -#resolve the name /Containers.dir/FactoryServerPy.object -myMachine=string.split(os.getenv( "HOSTNAME" ),'.') -machineName= myMachine[0] -containerName = "FactoryServerPy" -name = [CosNaming.NameComponent("Containers","dir"), - CosNaming.NameComponent(machineName,"dir"), - CosNaming.NameComponent(containerName,"object")] +name = [CosNaming.NameComponent("Kernel","dir"), + CosNaming.NameComponent("ContainersManager","object")] try: - obj = rootContext.resolve(name) + obj = rootContext.resolve( name ) except CosNaming.NamingContext.NotFound, ex: - print containerName , " not found in Naming Service" + print "/Kernel/ContainersManager not found in Naming Service" sys.exit(1) -container = obj._narrow(Engines.Container) -print container._get_machineName() -comp = container.load_impl("SALOME_TestComponentPy","SALOME_TestComponentPy") -print comp._get_instanceName() +MyContainersMgr = obj._narrow(Containers.Manager) + +MyContainersMgr.ping() + +Params = MyContainersMgr.Parameters() + +Params.ContainerName = 'TestContainerPy' +Params.ContainerType = Engines.Python + +comp = MyContainersMgr.FindOrLoad_Component( Params , "SALOME_TestComponentPy" ) comp.ping() + comptest = comp._narrow(Engines.TestComponent) if comptest is None: - print "probleme cast" -print comptest.Coucou(1) + print "probleme narrow(Engines.TestComponent)" + sys.exit(1) + +print "comptest",comptest.Coucou(1) + +container = comptest.GetContainerRef() +container.ping() +print "container._get_name()",container._get_name() +print "container._get_machineName()",container._get_machineName() + +comptest.destroy() +print "Component SALOME_TestComponentPy destroyed" + +try : + container.destroy() +except : + print "" + +print "Container TestContainerPy destroyed" + + +from LifeCycleCORBA import * +lcc = LifeCycleCORBA( orb ) + +lcccomptest = lcc.FindOrLoadComponent( 'TestContainerPy' , 'SALOME_TestComponentPy' ) + +print "lcccomptest",lcccomptest.Coucou(1) + +lcccontainer = lcccomptest.GetContainerRef() +lcccontainer.ping() +print "lcccontainer._get_name()",lcccontainer._get_name() +print "lcccontainer._get_machineName()",lcccontainer._get_machineName() + +lcccomptest.destroy() +print "Component SALOME_TestComponentPy destroyed" + +try : + lcccontainer.destroy() +except : + print "" + +print "Container TestContainerPy destroyed" diff --git a/src/TestContainer/TestContainer.cxx b/src/TestContainer/TestContainer.cxx index f80e92a4a..a02d01199 100644 --- a/src/TestContainer/TestContainer.cxx +++ b/src/TestContainer/TestContainer.cxx @@ -31,6 +31,7 @@ #include #include #include CORBA_CLIENT_HEADER(SALOME_Component) +#include CORBA_CLIENT_HEADER(ContainersManager) #include CORBA_CLIENT_HEADER(SALOME_TestComponent) #include "SALOME_NamingService.hxx" @@ -39,6 +40,7 @@ #include "Utils_SINGLETON.hxx" #include "Utils_SALOME_Exception.hxx" #include "Utils_CommException.hxx" + using namespace std; int main (int argc, char * argv[]) @@ -138,11 +140,34 @@ int main (int argc, char * argv[]) SALOME_NamingService _NS(orb) ; string containerName = "/Containers/" ; string hostName = GetHostname(); - containerName += hostName + "/FactoryServer"; + containerName += hostName + "/TestContainerCpp"; + Engines::Container_var iGenFact = Engines::Container::_nil() ; obj = _NS.Resolve(containerName.c_str()) ; - Engines::Container_var iGenFact = Engines::Container::_narrow(obj); - + if ( !CORBA::is_nil( obj ) ) { + try { + iGenFact = Engines::Container::_narrow( obj ) ; + iGenFact->ping() ; + } + catch ( ... ) { + INFOS("TestContainerCpp unreachable") ; + } + } + if ( CORBA::is_nil( iGenFact ) ) { + obj = _NS.Resolve( "/Kernel/ContainersManager" ) ; + if ( !CORBA::is_nil( obj ) ) { + try { + Containers::Manager_var MyContainersMgr = Containers::Manager::_narrow( obj ) ; + MyContainersMgr->ping() ; + Containers::MachineParameters * Params = MyContainersMgr->Parameters() ; + Params->ContainerName = "TestContainerCpp" ; + iGenFact = MyContainersMgr->FindOrStartContainer( *Params ) ; + } + catch ( ... ) { + INFOS("ContainersManager unreachable") ; + } + } + } Engines::TestComponent_var m1; for (int iter = 0; iter < 3 ; iter++) @@ -165,6 +190,8 @@ int main (int argc, char * argv[]) // Clean-up. iGenFact->finalize_removal() ; INFOS("finalize_removal done" ); + iGenFact->destroy() ; + INFOS("Container destroyed" ); orb->destroy(); INFOS("orb destroyed" ); }