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 path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/"
103 except SALOME_ModuleCatalog.NotFound, ex:
107 #-------------------------------------------------------------------------
109 def FindContainer(self, containerName):
110 theComputer,theContainer = self.ContainerName( containerName )
111 name = [CosNaming.NameComponent(theComputer,"dir"),
112 CosNaming.NameComponent(theContainer,"object")]
115 obj = self._containerRootContext.resolve(name)
116 MESSAGE( containerName + ".object found in Naming Service" )
118 except CosNaming.NamingContext.NotFound, ex:
119 MESSAGE( containerName + ".object not found in Naming Service" )
124 container = obj._narrow(Engines.Container)
125 if container is None:
126 MESSAGE( containerName + ".object exists but is not a Container" )
129 #-------------------------------------------------------------------------
131 def FindOrStartContainer(self, theComputer , theContainer ):
132 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
133 aContainer = self.FindContainer( theComputer + "/" + theContainer )
134 if aContainer is None :
135 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
136 if theComputer == os.getenv("HOSTNAME") :
139 rshstr = "rsh -n " + theComputer + " "
140 path = self.ComputerPath( theComputer )
142 ## rshstr = rshstr + path + "/../bin/"
144 ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
145 if theContainer == "FactoryServer" :
146 rshstr = rshstr + path + "SALOME_Container "
148 rshstr = rshstr + path + "SALOME_ContainerPy.py '"
149 rshstr = rshstr + theContainer + " -"
150 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
151 file = os.open( omniORBcfg , os.O_RDONLY )
152 ORBInitRef = os.read(file,132)
153 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
154 ORBInitRef,bsn = ORBInitRef.split('\n')
156 rshstr = rshstr + ORBInitRef
157 if theContainer == "FactoryServerPy" :
158 rshstr = rshstr + "'"
159 rshstr = rshstr + " > /tmp/" + theContainer + "_"
160 rshstr = rshstr + theComputer
161 rshstr = rshstr + ".log 2>&1 &"
163 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
165 if theContainer.find('Py') == -1 :
166 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
168 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
169 aContainer = aContainer.start_impl( theContainer )
172 while aContainer is None :
175 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
176 aContainer = self.FindContainer( theComputer + "/" + theContainer )
181 #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
183 #-------------------------------------------------------------------------
185 def FindOrLoadComponent(self, containerName, componentName):
187 theComputer,theContainer = self.ContainerName( containerName )
188 name = [CosNaming.NameComponent(theComputer,"dir"),
189 CosNaming.NameComponent(theContainer,"dir"),
190 CosNaming.NameComponent(componentName,"object")]
192 obj = self._containerRootContext.resolve(name)
193 except CosNaming.NamingContext.NotFound, ex:
194 MESSAGE( "component " + componentName + " not found, trying to load" )
195 container = self.FindContainer(theComputer + "/" + theContainer)
196 if container is None:
197 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
198 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
199 if theContainer.find('Py') == -1 :
200 theFactorycontainer = "FactoryServer"
202 theFactorycontainer = "FactoryServerPy"
203 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
204 if Factorycontainer is None:
205 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
206 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
208 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
209 if Factorycontainer != None :
210 container = self.FindOrStartContainer(theComputer,theContainer)
212 if container != None:
213 compoinfo = self._catalog.GetComponent(componentName)
214 if compoinfo is None:
215 MESSAGE( "component " + componentName + " not found in Module Catalog" )
218 machineName = theComputer
219 path = compoinfo.GetPathPrefix(machineName) + "/"
220 except SALOME_ModuleCatalog.NotFound, ex:
221 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
222 MESSAGE( "trying localhost" )
224 path = compoinfo.GetPathPrefix("localhost") + "/"
225 except SALOME_ModuleCatalog.NotFound, ex:
227 implementation = path + "lib" + componentName + "Engine.so"
228 MESSAGE( "Trying to load " + implementation )
230 component = container.load_impl(componentName, implementation)
231 MESSAGE( "component " + component._get_instanceName() + " launched !" )
234 MESSAGE( "component " + componentName + " NOT launched !" )
238 component = obj._narrow(Engines.Component)
239 if component is None:
240 MESSAGE( componentName + " is not a component !" )
242 MESSAGE( "component " + component._get_instanceName() + " found !" )
245 MESSAGE( componentName + " failure" )