From 76bb0c06541d45cc94ff0ec9b0500d617617dc19 Mon Sep 17 00:00:00 2001 From: rahuel Date: Mon, 8 Nov 2004 08:28:44 +0000 Subject: [PATCH] Restore previous state without ContainersManager & ContainersManager --- src/LifeCycleCORBA/LifeCycleCORBA.py | 369 ++++------ src/LifeCycleCORBA/Makefile.in | 6 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 673 ++++++++----------- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 45 +- src/LifeCycleCORBA/TestLifeCycleCORBA.cxx | 36 +- src/TestContainer/Makefile.in | 4 +- src/TestContainer/SALOME_TestComponentPy.py | 1 - src/TestContainer/SALOME_TestComponent_i.hxx | 1 + src/TestContainer/TestComponentPy.py | 81 +-- src/TestContainer/TestContainer.cxx | 131 +--- 10 files changed, 484 insertions(+), 863 deletions(-) diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index 1033bffac..550a88ff9 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -32,8 +32,6 @@ import time from omniORB import CORBA import CosNaming import Engines -import Resources -import Containers import SALOME_ModuleCatalog from SALOME_utilities import * @@ -43,7 +41,6 @@ class LifeCycleCORBA: _rootcontext = None _containerRootContext = None _catalog = None - _containermgr = None #------------------------------------------------------------------------- @@ -57,273 +54,197 @@ 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) - - #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" ) + name = [CosNaming.NameComponent("Containers","dir")] + try: + self._containerRootContext = self._rootContext.bind_new_context(name) - #self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog) - #if self._catalog is None: - #MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" ) + 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("ContainersManager","object")] + CosNaming.NameComponent("ModulCatalog","object")] try: obj = self._rootContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: - 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() + 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" ) #------------------------------------------------------------------------- def ContainerName(self, containerName): - MESSAGE( "ContainerName( " + containerName + " )" ) - theComputer = None + theComputer = "" try: theComputer , theContainer = containerName.split('/') except: - theComputer = None + theComputer = "" theContainer = containerName - #CCRT HOST instead of HOSTNAME - if theComputer == None : + if theComputer == "" : 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( "ContainerName returns " + theComputer + ','+ theContainer ) + MESSAGE( 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" ) - - #except CosNaming.NamingContext.NotFound, ex: - #MESSAGE( containerName + ".object not 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" ) - #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 ) + 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" ) return container #------------------------------------------------------------------------- - 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 ) + 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) - #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 ) + 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 diff --git a/src/LifeCycleCORBA/Makefile.in b/src/LifeCycleCORBA/Makefile.in index d98e8e9c7..6f4a461ea 100644 --- a/src/LifeCycleCORBA/Makefile.in +++ b/src/LifeCycleCORBA/Makefile.in @@ -43,15 +43,15 @@ EXPORT_PYSCRIPTS = LifeCycleCORBA.py LIB = libSalomeLifeCycleCORBA.la LIB_SRC = SALOME_LifeCycleCORBA.cxx LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ - SALOME_ModuleCatalog.idl ContainersManager.idl + SALOME_ModuleCatalog.idl # Executables targets BIN = TestLifeCycleCORBA BIN_SRC = BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ - SALOME_ModuleCatalog.idl ContainersManager.idl + SALOME_ModuleCatalog.idl -LDFLAGS += -lSalomeNS -lOpUtil -lSALOMELocalTrace +LDFLAGS += -lSalomeNS -lOpUtil -lSalomeLoggerServer @CONCLUDE@ diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index b1af7f5ff..6e48df6b9 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -38,21 +38,18 @@ 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() { - _NamingService = NULL; - _MyContainersMgr = NULL ; + _NS = NULL; _FactoryServer = NULL ; } SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) { - _NamingService = ns; - CORBA::Object_var ContainersMgrObject = _NamingService->Resolve( "/Kernel/ContainersManager" ) ; - _MyContainersMgr = Containers::Manager::_narrow( ContainersMgrObject ) ; + _NS = ns; _FactoryServer = NULL ; } @@ -60,13 +57,10 @@ SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA() { } -Containers::MachineParameters_var SALOME_LifeCycleCORBA::Parameters() { - return _MyContainersMgr->Parameters() ; -} - -string SALOME_LifeCycleCORBA::ContainerName( const char * aComputerContainer , - string * theComputer , - string * theContainer ) { +string SALOME_LifeCycleCORBA::ContainerName( + const char * aComputerContainer , + string * theComputer , + string * theContainer ) { char * ContainerName = new char [ strlen( aComputerContainer ) + 1 ] ; strcpy( ContainerName , aComputerContainer ) ; string theComputerContainer("/Containers/"); @@ -92,15 +86,13 @@ string SALOME_LifeCycleCORBA::ContainerName( const char * aComputerContainer , 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 = _NamingService->Resolve("/Kernel/ModulCatalog"); +// CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog"); // SALOME_ModuleCatalog::ModuleCatalog_var Catalog = // SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ; // try { @@ -114,403 +106,318 @@ string SALOME_LifeCycleCORBA::ContainerName( const char * aComputerContainer , // 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 ) { - 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 ; + ASSERT(_NS != NULL); + string cont ; + if ( strncmp( containerName , "/Containers/" , 12 ) ) { // Compatibility ... + string theComputer ; + string theContainer ; + cont = ContainerName( containerName , &theComputer , &theContainer ) ; } else { - MyParams->ContainerType = Engines::PythonContainer ; + cont = containerName ; } - 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 ); + try { -// 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(); -//} + SCRUTE( cont ); -Engines::Container_var SALOME_LifeCycleCORBA::FindContainer( Containers::MachineParameters & MyParams ) { - if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { - MyParams.HostName = GetHostname().c_str() ; + CORBA::Object_var obj = _NS->Resolve( cont.c_str() ); + if( !CORBA::is_nil( obj ) ) { + return Engines::Container::_narrow( obj ) ; + } } - return _MyContainersMgr->FindContainer( MyParams ) ; -} - -Engines::ListOfContainers_var SALOME_LifeCycleCORBA::FindContainers( Containers::MachineParameters & MyParams ) { - if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { - MyParams.HostName = GetHostname().c_str() ; + catch (ServiceUnreachable&) { + INFOS("Caught exception: Naming Service Unreachable"); } - 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() ; + catch (...) { + INFOS("Caught unknown exception."); } - return _MyContainersMgr->FindComponent( MyParams , ComponentName ) ; + return Engines::Container::_nil(); } -Engines::ListOfComponents_var SALOME_LifeCycleCORBA::FindComponents( Containers::MachineParameters & MyParams , - const char * ComponentName ) { - if ( strcmp( MyParams.HostName ,"localhost" ) == 0 ) { - MyParams.HostName = GetHostname().c_str() ; +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 ; } - return _MyContainersMgr->FindComponents( MyParams , ComponentName ) ; -} - -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 ; - 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 ; + if ( !CORBA::is_nil( aContainer ) ) { + return aContainer ; } else { - MyParams->ContainerType = Engines::PythonContainer ; + 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 FindOrLoad_Component( *MyParams , componentName , implementation ) ; + return Engines::Container::_nil(); } -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 ) ; + +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component + (const char *containerName, + const char *componentName, + const char *implementation) +{ + BEGIN_OF("FindOrLoad_Component(1)"); + ASSERT(_NS != 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 = _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); + 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); // 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(); -} - -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 ) ; + 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 ) { - Containers::MachineParameters * MyParams = _MyContainersMgr->Parameters() ; +Engines::Component_var SALOME_LifeCycleCORBA::FindOrLoad_Component + (const char *containerName, + const char *componentName) +{ +// BEGIN_OF("FindOrLoad_Component(2)"); + ASSERT(_NS != NULL); 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 { - MyParams->ContainerType = Engines::PythonContainer ; + 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(); } - 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 = _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(); + 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()); -// + } + + 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 4ac0e1574..d562f43f3 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -36,8 +36,6 @@ #include #include CORBA_CLIENT_HEADER(SALOME_Component) -#include CORBA_CLIENT_HEADER( ContainersManager ) - class SALOME_NamingService; class SALOME_LifeCycleCORBA @@ -47,39 +45,24 @@ public: SALOME_LifeCycleCORBA(SALOME_NamingService *ns); virtual ~SALOME_LifeCycleCORBA(); - 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 ) ; + 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); protected: - Containers::Manager_var _MyContainersMgr ; - SALOME_NamingService * _NamingService ; + SALOME_NamingService *_NS; Engines::Container_var _FactoryServer ; -// std::string ComputerPath( const char * theComputer ) ; - -private: + std::string ComputerPath( const char * theComputer ) ; std::string ContainerName( const char * aComputerContainer , - std::string * theComputer , - std::string * theContainer ) ; + std::string * theComputer , + std::string * theContainer ) ; -// Engines::Container_var FindOrStartContainer(const std::string aComputerContainer , -// const std::string theComputer , -// const std::string theContainer ) ; +private: + 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 901b72dca..603c32814 100644 --- a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx @@ -40,10 +40,8 @@ using namespace std; int main (int argc, char * argv[]) { - try { - int i = 0 ; - while ( argv[ i ] ) { - MESSAGE(" argv" << i << " " << argv[ i ]) ; + try + { // Initializing omniORB CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); @@ -51,26 +49,15 @@ 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 ; - if ( i == 0 ) { - containerName = GetHostname() ; - } - else { - containerName = argv[ i ] ; - } - containerName += "/" ; - containerName += "TestComponentCpp" ; - - MESSAGE("FindOrLoad_Component( " << containerName << " , SalomeTestComponent )" ) ; + string containerName = GetHostname(); + Engines::Component_var mycompo = _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); @@ -87,17 +74,8 @@ int main (int argc, char * argv[]) // get another container (with a fixed name), // load an engine, and invoque methods on that engine - string containerName2 ; - if ( i == 0 ) { - containerName2 = GetHostname() ; - } - else { - containerName2 = argv[ i ] ; - } - containerName2 += "/" ; - containerName2 += "TestComponentPy" ; - - MESSAGE("FindOrLoad_Component( " << containerName2 << " , SALOME_TestComponentPy )" ) ; + string containerName2 = "FactoryServerPy"; + Engines::Component_var mycompo2 = _LCC.FindOrLoad_Component(containerName2.c_str(),"SALOME_TestComponentPy"); @@ -110,9 +88,7 @@ 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."); diff --git a/src/TestContainer/Makefile.in b/src/TestContainer/Makefile.in index eec3bda33..8d2709d60 100644 --- a/src/TestContainer/Makefile.in +++ b/src/TestContainer/Makefile.in @@ -39,13 +39,13 @@ EXPORT_PYSCRIPTS = SALOME_TestComponentPy.py TestComponentPy.py LIB = libSalomeTestComponentEngine.la LIB_SRC = SALOME_TestComponent_i.cxx -LIB_CLIENT_IDL = ContainersManager.idl SALOME_Component.idl SALOME_TestComponent.idl +LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl # Executables targets BIN = TestContainer TestLogger BIN_SRC = -LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSALOMELocalTrace +LDFLAGS+= -lSalomeNotification -lSalomeNS -lSalomeContainer -lRegistry -lOpUtil -lSalomeLoggerServer @CONCLUDE@ diff --git a/src/TestContainer/SALOME_TestComponentPy.py b/src/TestContainer/SALOME_TestComponentPy.py index 8ad7f3908..eb9867ab3 100755 --- a/src/TestContainer/SALOME_TestComponentPy.py +++ b/src/TestContainer/SALOME_TestComponentPy.py @@ -42,7 +42,6 @@ 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) diff --git a/src/TestContainer/SALOME_TestComponent_i.hxx b/src/TestContainer/SALOME_TestComponent_i.hxx index b5bddc3df..1f135d3d4 100644 --- a/src/TestContainer/SALOME_TestComponent_i.hxx +++ b/src/TestContainer/SALOME_TestComponent_i.hxx @@ -49,6 +49,7 @@ public: virtual ~Engines_TestComponent_i(); char* Coucou(CORBA::Long L); + void Setenv(); private: diff --git a/src/TestContainer/TestComponentPy.py b/src/TestContainer/TestComponentPy.py index f6397f326..2dacf6dbb 100755 --- a/src/TestContainer/TestComponentPy.py +++ b/src/TestContainer/TestComponentPy.py @@ -34,7 +34,6 @@ import string from omniORB import CORBA import CosNaming import Engines -import Containers #initialise the ORB @@ -48,78 +47,28 @@ if rootContext is None: print "Name Service Reference is invalid" sys.exit(1) -name = [CosNaming.NameComponent("Kernel","dir"), - CosNaming.NameComponent("ContainersManager","object")] +#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")] try: - obj = rootContext.resolve( name ) + obj = rootContext.resolve(name) except CosNaming.NamingContext.NotFound, ex: - print "/Kernel/ContainersManager not found in Naming Service" + print containerName , " not found in Naming Service" sys.exit(1) -MyContainersMgr = obj._narrow(Containers.Manager) - -MyContainersMgr.ping() - -Params = MyContainersMgr.Parameters() - -Params.ContainerName = 'TestContainerPy' -Params.ContainerType = Engines.PythonContainer - -#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")] -comp = MyContainersMgr.FindOrLoad_Component( Params , "SALOME_TestComponentPy" ) +container = obj._narrow(Engines.Container) +print container._get_machineName() +comp = container.load_impl("SALOME_TestComponentPy","SALOME_TestComponentPy") +print comp._get_instanceName() comp.ping() - comptest = comp._narrow(Engines.TestComponent) if comptest is None: - 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" - + print "probleme cast" +print comptest.Coucou(1) diff --git a/src/TestContainer/TestContainer.cxx b/src/TestContainer/TestContainer.cxx index 2fcc21eb5..14de77051 100644 --- a/src/TestContainer/TestContainer.cxx +++ b/src/TestContainer/TestContainer.cxx @@ -26,21 +26,16 @@ // Module : SALOME // $Header$ +using namespace std; #include "utilities.h" #include #include #include #include CORBA_CLIENT_HEADER(SALOME_Component) -#include CORBA_CLIENT_HEADER(ContainersManager) #include CORBA_CLIENT_HEADER(SALOME_TestComponent) #include "SALOME_NamingService.hxx" #include "OpUtil.hxx" -#include "Utils_ORB_INIT.hxx" -#include "Utils_SINGLETON.hxx" -#include "Utils_SALOME_Exception.hxx" -#include "Utils_CommException.hxx" -using namespace std; int main (int argc, char * argv[]) { @@ -56,131 +51,25 @@ int main (int argc, char * argv[]) //Engines::Container_var iGenFact = Engines::Container::_narrow(obj); // Obtain a reference to the root POA - // - long TIMESleep = 250000000; - int NumberOfTries = 40; - int a; - 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; - CosNaming::NamingContext_var inc; - PortableServer::POA_var poa; - CORBA::Object_var theObj; - CORBA::Object_var obj; - CORBA::Object_var object; - SALOME_NamingService &naming = *SINGLETON_::Instance() ; - int TEST_CONTAINER=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 manager; - for (int 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)) - manager = 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( "Test Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ) - } - if(!CORBA::is_nil(inc)) - { - MESSAGE( "Test Container: Naming Service was found" ) - if(EnvL==1) - { - for(int j=1; j<=NumberOfTries; j++) - { - if (j!=1) - a=nanosleep(&ts_req, &ts_rem); - try - { - object = inc->resolve(name); - } - catch(CosNaming::NamingContext::NotFound) - { - MESSAGE( "Test Container: Logger Server wasn't found" ); - } - catch(...) - { - MESSAGE( "Test Container: Unknown exception" ); - } - if (!CORBA::is_nil(object)) - { - MESSAGE( "Test Container: Loger Server was found" ); - TEST_CONTAINER=1; - break; - } - } - } - } - if ((TEST_CONTAINER==1)||((EnvL==0)&&(!CORBA::is_nil(inc)))) - break; - } - + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ; + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ; + // Use Name Service to find container SALOME_NamingService _NS(orb) ; string containerName = "/Containers/" ; string hostName = GetHostname(); - containerName += hostName + "/TestContainerCpp"; + containerName += hostName + "/FactoryServer"; - Engines::Container_var iGenFact = Engines::Container::_nil() ; - MESSAGE( "TestContainer : " << containerName.c_str() ) ; obj = _NS.Resolve(containerName.c_str()) ; - 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") ; - } - } - } - -// obj = _NS.Resolve(containerName.c_str()) ; -// Engines::Container_var iGenFact = Engines::Container::_narrow(obj); + Engines::Container_var iGenFact = Engines::Container::_narrow(obj); Engines::TestComponent_var m1; for (int iter = 0; iter < 3 ; iter++) { INFOS("----------------------------------------------------" << iter); -// string dirn = getenv("KERNEL_ROOT_DIR"); -// dirn += "/lib/salome/libSalomeTestComponentEngine.so"; - iGenFact->ping() ; - string dirn = "libSalomeTestComponentEngine.so"; + string dirn = getenv("SALOME_ROOT_DIR"); + dirn += "/lib/salome/libSalomeTestComponentEngine.so"; obj = iGenFact->load_impl("SalomeTestComponent",dirn.c_str()); m1 = Engines::TestComponent::_narrow(obj); INFOS("recup m1"); @@ -192,11 +81,7 @@ 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" ); } catch(CORBA::COMM_FAILURE& ex) { INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.") -- 2.39.2