1 # SALOME LifeCycleC RBA : implementation of containers and engines life cycle both in Python and C++
3 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 # File : LifeCycleCORBA.py
25 # Author : Paul RASCLE, EDF
33 from omniORB import CORBA
36 import SALOME_ModuleCatalog
38 from SALOME_utilities import *
43 _containerRootContext = None
46 #-------------------------------------------------------------------------
48 def __init__(self, orb):
49 MESSAGE( "LifeCycleCORBA::__init__" )
52 obj = self._orb.resolve_initial_references("NameService")
53 self._rootContext = obj._narrow(CosNaming.NamingContext)
55 if self._rootContext is None:
56 MESSAGE( "Name Service Reference is invalid" )
58 name = [CosNaming.NameComponent("Containers","dir")]
60 self._containerRootContext = self._rootContext.bind_new_context(name)
62 except CosNaming.NamingContext.AlreadyBound, ex:
63 MESSAGE( "/Containers.dir Context already exists" )
64 obj = self._rootContext.resolve(name)
65 self._containerRootContext = obj._narrow(CosNaming.NamingContext)
66 if self._containerRootContext is None:
67 MESSAGE( "Containers.dir exists but it is not a NamingContext" )
69 name = [CosNaming.NameComponent("Kernel","dir"),
70 CosNaming.NameComponent("ModulCatalog","object")]
72 obj = self._rootContext.resolve(name)
73 except CosNaming.NamingContext.NotFound, ex:
74 MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" )
76 self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
77 if self._catalog is None:
78 MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" )
80 #-------------------------------------------------------------------------
82 def ContainerName(self, containerName):
85 theComputer , theContainer = containerName.split('/')
88 theContainer = containerName
89 if theComputer == "" :
90 theComputer = os.getenv("HOSTNAME")
91 if theComputer == "localhost" :
92 theComputer = os.getenv("HOSTNAME")
93 computerSplitName = theComputer.split('.')
94 theComputer = computerSplitName[0]
95 MESSAGE( theComputer + theContainer )
96 return theComputer,theContainer
98 #-------------------------------------------------------------------------
100 def ComputerPath(self, ComputerName ):
102 #path = self._catalog.GetPathPrefix( ComputerName )
103 path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/"
104 except SALOME_ModuleCatalog.NotFound, ex:
108 #-------------------------------------------------------------------------
110 def FindContainer(self, containerName):
111 theComputer,theContainer = self.ContainerName( containerName )
112 name = [CosNaming.NameComponent(theComputer,"dir"),
113 CosNaming.NameComponent(theContainer,"object")]
116 obj = self._containerRootContext.resolve(name)
117 MESSAGE( containerName + ".object found in Naming Service" )
119 except CosNaming.NamingContext.NotFound, ex:
120 MESSAGE( containerName + ".object not found in Naming Service" )
125 container = obj._narrow(Engines.Container)
126 if container is None:
127 MESSAGE( containerName + ".object exists but is not a Container" )
130 #-------------------------------------------------------------------------
132 def FindOrStartContainer(self, theComputer , theContainer ):
133 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
134 aContainer = self.FindContainer( theComputer + "/" + theContainer )
135 if aContainer is None :
136 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
137 myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
138 if theComputer == myMachine[0] :
141 rshstr = "rsh -n " + theComputer + " "
142 path = self.ComputerPath( theComputer )
144 ## rshstr = rshstr + path + "/../bin/"
146 ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
147 if theContainer == "FactoryServer" :
148 rshstr = rshstr + path + "SALOME_Container "
150 rshstr = rshstr + path + "SALOME_ContainerPy.py '"
151 rshstr = rshstr + theContainer + " -"
152 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
153 file = os.open( omniORBcfg , os.O_RDONLY )
154 ORBInitRef = os.read(file,132)
155 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
156 ORBInitRef,bsn = ORBInitRef.split('\n')
158 rshstr = rshstr + ORBInitRef
159 if theContainer == "FactoryServerPy" :
160 rshstr = rshstr + "'"
161 rshstr = rshstr + " > /tmp/" + theContainer + "_"
162 rshstr = rshstr + theComputer
163 rshstr = rshstr + ".log 2>&1 &"
165 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
167 if theContainer.find('Py') == -1 :
168 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
170 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
171 aContainer = aContainer.start_impl( theContainer )
174 while aContainer is None :
177 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
178 aContainer = self.FindContainer( theComputer + "/" + theContainer )
183 #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
185 #-------------------------------------------------------------------------
187 def FindOrLoadComponent(self, containerName, componentName):
189 theComputer,theContainer = self.ContainerName( containerName )
190 name = [CosNaming.NameComponent(theComputer,"dir"),
191 CosNaming.NameComponent(theContainer,"dir"),
192 CosNaming.NameComponent(componentName,"object")]
194 obj = self._containerRootContext.resolve(name)
195 except CosNaming.NamingContext.NotFound, ex:
196 MESSAGE( "component " + componentName + " not found, trying to load" )
197 container = self.FindContainer(theComputer + "/" + theContainer)
198 if container is None:
199 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
200 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
201 if theContainer.find('Py') == -1 :
202 theFactorycontainer = "FactoryServer"
204 theFactorycontainer = "FactoryServerPy"
205 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
206 if Factorycontainer is None:
207 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
208 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
210 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
211 if Factorycontainer != None :
212 container = self.FindOrStartContainer(theComputer,theContainer)
214 if container != None:
215 compoinfo = self._catalog.GetComponent(componentName)
216 if compoinfo is None:
217 MESSAGE( "component " + componentName + " not found in Module Catalog" )
220 machineName = theComputer
221 path = compoinfo.GetPathPrefix(machineName) + "/"
222 except SALOME_ModuleCatalog.NotFound, ex:
223 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
224 MESSAGE( "trying localhost" )
226 path = compoinfo.GetPathPrefix("localhost") + "/"
227 except SALOME_ModuleCatalog.NotFound, ex:
229 implementation = path + "lib" + componentName + "Engine.so"
230 MESSAGE( "Trying to load " + implementation )
232 component = container.load_impl(componentName, implementation)
233 MESSAGE( "component " + component._get_instanceName() + " launched !" )
236 MESSAGE( "component " + componentName + " NOT launched !" )
240 component = obj._narrow(Engines.Component)
241 if component is None:
242 MESSAGE( componentName + " is not a component !" )
244 MESSAGE( "component " + component._get_instanceName() + " found !" )
247 MESSAGE( componentName + " failure" )