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 ):
100 # Modification provisoire B. Secher en attendant
101 # le gestionnaire de ressources 21/10/2003
102 # Le KERNEL_ROOT_DIR sera a lire dans le catalogue de machines
103 # en attendant on suppose qu'il est identique au KERNEL_ROOT_DIR local
105 #path = self._catalog.GetPathPrefix( ComputerName )
106 path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/"
107 except SALOME_ModuleCatalog.NotFound, ex:
111 #-------------------------------------------------------------------------
113 def FindContainer(self, containerName):
114 theComputer,theContainer = self.ContainerName( containerName )
115 name = [CosNaming.NameComponent(theComputer,"dir"),
116 CosNaming.NameComponent(theContainer,"object")]
119 obj = self._containerRootContext.resolve(name)
120 MESSAGE( containerName + ".object found in Naming Service" )
122 except CosNaming.NamingContext.NotFound, ex:
123 MESSAGE( containerName + ".object not found in Naming Service" )
128 container = obj._narrow(Engines.Container)
129 if container is None:
130 MESSAGE( containerName + ".object exists but is not a Container" )
133 #-------------------------------------------------------------------------
135 def FindOrStartContainer(self, theComputer , theContainer ):
136 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
137 aContainer = self.FindContainer( theComputer + "/" + theContainer )
138 if aContainer is None :
139 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
140 if theComputer == os.getenv("HOSTNAME") :
143 rshstr = "rsh -n " + theComputer + " "
144 path = self.ComputerPath( theComputer )
146 ## rshstr = rshstr + path + "/../bin/"
148 ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
149 if theContainer == "FactoryServer" :
150 rshstr = rshstr + path + "SALOME_Container "
152 rshstr = rshstr + path + "SALOME_ContainerPy.py '"
153 rshstr = rshstr + theContainer + " -"
154 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
155 file = os.open( omniORBcfg , os.O_RDONLY )
156 ORBInitRef = os.read(file,132)
157 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
158 ORBInitRef,bsn = ORBInitRef.split('\n')
160 rshstr = rshstr + ORBInitRef
161 if theContainer == "FactoryServerPy" :
162 rshstr = rshstr + "'"
163 rshstr = rshstr + " > /tmp/" + theContainer + "_"
164 rshstr = rshstr + theComputer
165 rshstr = rshstr + ".log 2>&1 &"
167 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
169 if theContainer.find('Py') == -1 :
170 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
172 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
173 aContainer = aContainer.start_impl( theContainer )
176 while aContainer is None :
179 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
180 aContainer = self.FindContainer( theComputer + "/" + theContainer )
185 #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
187 #-------------------------------------------------------------------------
189 def FindOrLoadComponent(self, containerName, componentName):
191 theComputer,theContainer = self.ContainerName( containerName )
192 name = [CosNaming.NameComponent(theComputer,"dir"),
193 CosNaming.NameComponent(theContainer,"dir"),
194 CosNaming.NameComponent(componentName,"object")]
196 obj = self._containerRootContext.resolve(name)
197 except CosNaming.NamingContext.NotFound, ex:
198 MESSAGE( "component " + componentName + " not found, trying to load" )
199 container = self.FindContainer(theComputer + "/" + theContainer)
200 if container is None:
201 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
202 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
203 if theContainer.find('Py') == -1 :
204 theFactorycontainer = "FactoryServer"
206 theFactorycontainer = "FactoryServerPy"
207 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
208 if Factorycontainer is None:
209 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
210 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
212 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
213 if Factorycontainer != None :
214 container = self.FindOrStartContainer(theComputer,theContainer)
216 if container != None:
217 compoinfo = self._catalog.GetComponent(componentName)
218 if compoinfo is None:
219 MESSAGE( "component " + componentName + " not found in Module Catalog" )
222 machineName = theComputer
223 path = compoinfo.GetPathPrefix(machineName) + "/"
224 except SALOME_ModuleCatalog.NotFound, ex:
225 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
226 MESSAGE( "trying localhost" )
228 path = compoinfo.GetPathPrefix("localhost") + "/"
229 except SALOME_ModuleCatalog.NotFound, ex:
231 implementation = path + "lib" + componentName + "Engine.so"
232 MESSAGE( "Trying to load " + implementation )
234 component = container.load_impl(componentName, implementation)
235 MESSAGE( "component " + component._get_instanceName() + " launched !" )
238 MESSAGE( "component " + componentName + " NOT launched !" )
242 component = obj._narrow(Engines.Component)
243 if component is None:
244 MESSAGE( componentName + " is not a component !" )
246 MESSAGE( "component " + component._get_instanceName() + " found !" )
249 MESSAGE( componentName + " failure" )