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
32 from omniORB import CORBA
35 import SALOME_ModuleCatalog
37 from SALOME_utilities import *
42 _containerRootContext = None
45 #-------------------------------------------------------------------------
47 def __init__(self, orb):
48 MESSAGE( "LifeCycleCORBA::__init__" )
51 obj = self._orb.resolve_initial_references("NameService")
52 self._rootContext = obj._narrow(CosNaming.NamingContext)
54 if self._rootContext is None:
55 MESSAGE( "Name Service Reference is invalid" )
57 name = [CosNaming.NameComponent("Containers","dir")]
59 self._containerRootContext = self._rootContext.bind_new_context(name)
61 except CosNaming.NamingContext.AlreadyBound, ex:
62 MESSAGE( "/Containers.dir Context already exists" )
63 obj = self._rootContext.resolve(name)
64 self._containerRootContext = obj._narrow(CosNaming.NamingContext)
65 if self._containerRootContext is None:
66 MESSAGE( "Containers.dir exists but it is not a NamingContext" )
68 name = [CosNaming.NameComponent("Kernel","dir"),
69 CosNaming.NameComponent("ModulCatalog","object")]
71 obj = self._rootContext.resolve(name)
72 except CosNaming.NamingContext.NotFound, ex:
73 MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" )
75 self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
76 if self._catalog is None:
77 MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" )
79 #-------------------------------------------------------------------------
81 def ContainerName(self, containerName):
84 theComputer , theContainer = containerName.split('/')
87 theContainer = containerName
88 if theComputer == "" :
89 theComputer = os.getenv("HOSTNAME")
90 if theComputer == "localhost" :
91 theComputer = os.getenv("HOSTNAME")
92 computerSplitName = theComputer.split('.')
93 theComputer = computerSplitName[0]
94 MESSAGE( theComputer + theContainer )
95 return theComputer,theContainer
97 #-------------------------------------------------------------------------
99 def ComputerPath(self, ComputerName ):
101 path = self._catalog.GetPathPrefix( ComputerName )
102 except SALOME_ModuleCatalog.NotFound, ex:
106 #-------------------------------------------------------------------------
108 def FindContainer(self, containerName):
109 theComputer,theContainer = self.ContainerName( containerName )
110 name = [CosNaming.NameComponent(theComputer,"dir"),
111 CosNaming.NameComponent(theContainer,"object")]
114 obj = self._containerRootContext.resolve(name)
115 MESSAGE( containerName + ".object found in Naming Service" )
117 except CosNaming.NamingContext.NotFound, ex:
118 MESSAGE( containerName + ".object not found in Naming Service" )
123 container = obj._narrow(Engines.Container)
124 if container is None:
125 MESSAGE( containerName + ".object exists but is not a Container" )
128 #-------------------------------------------------------------------------
130 def FindOrStartContainer(self, theComputer , theContainer ):
131 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
132 aContainer = self.FindContainer( theComputer + "/" + theContainer )
133 if aContainer is None :
134 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
135 if theComputer == os.getenv("HOSTNAME") :
138 rshstr = "rsh -n " + theComputer + " "
139 path = self.ComputerPath( theComputer )
141 rshstr = rshstr + path + "/../bin/"
143 rshstr = rshstr + os.getenv( "SALOME_ROOT_DIR" ) + "/bin/"
144 if theContainer == "FactoryServer" :
145 rshstr = rshstr + "./runSession ./SALOME_Container "
147 rshstr = rshstr + "./runSession ./SALOME_ContainerPy.py '"
148 rshstr = rshstr + theContainer + " -"
149 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
150 file = os.open( omniORBcfg , os.O_RDONLY )
151 ORBInitRef = os.read(file,132)
152 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
153 ORBInitRef,bsn = ORBInitRef.split('\n')
155 rshstr = rshstr + ORBInitRef
156 if theContainer == "FactoryServerPy" :
157 rshstr = rshstr + "'"
158 rshstr = rshstr + " > /tmp/" + theContainer + "_"
159 rshstr = rshstr + theComputer
160 rshstr = rshstr + ".log 2>&1 &"
162 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
164 if theContainer.find('Py') == -1 :
165 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
167 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
168 aContainer = aContainer.start_impl( theContainer )
171 while aContainer is None :
174 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
175 aContainer = self.FindContainer( theComputer + "/" + theContainer )
180 #os.system("rsh -n dm2s0017 /export/home/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
182 #-------------------------------------------------------------------------
184 def FindOrLoadComponent(self, containerName, componentName):
186 theComputer,theContainer = self.ContainerName( containerName )
187 name = [CosNaming.NameComponent(theComputer,"dir"),
188 CosNaming.NameComponent(theContainer,"dir"),
189 CosNaming.NameComponent(componentName,"object")]
191 obj = self._containerRootContext.resolve(name)
192 except CosNaming.NamingContext.NotFound, ex:
193 MESSAGE( "component " + componentName + " not found, trying to load" )
194 container = self.FindContainer(theComputer + "/" + theContainer)
195 if container is None:
196 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
197 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
198 if theContainer.find('Py') == -1 :
199 theFactorycontainer = "FactoryServer"
201 theFactorycontainer = "FactoryServerPy"
202 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
203 if Factorycontainer is None:
204 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
205 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
207 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
208 if Factorycontainer != None :
209 container = self.FindOrStartContainer(theComputer,theContainer)
211 if container != None:
212 compoinfo = self._catalog.GetComponent(componentName)
213 if compoinfo is None:
214 MESSAGE( "component " + componentName + " not found in Module Catalog" )
217 machineName = theComputer
218 path = compoinfo.GetPathPrefix(machineName) + "/"
219 except SALOME_ModuleCatalog.NotFound, ex:
220 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
221 MESSAGE( "trying localhost" )
223 path = compoinfo.GetPathPrefix("localhost") + "/"
224 except SALOME_ModuleCatalog.NotFound, ex:
226 implementation = path + "lib" + componentName + "Engine.so"
227 MESSAGE( "Trying to load " + implementation )
229 component = container.load_impl(componentName, implementation)
230 MESSAGE( "component " + component._get_instanceName() + " launched !" )
233 MESSAGE( "component " + componentName + " NOT launched !" )
237 component = obj._narrow(Engines.Component)
238 if component is None:
239 MESSAGE( componentName + " is not a component !" )
241 MESSAGE( "component " + component._get_instanceName() + " found !" )
244 MESSAGE( componentName + " failure" )