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 *
39 from Utils_Identity import getShortHostName
44 _containerRootContext = None
47 #-------------------------------------------------------------------------
49 def __init__(self, orb):
50 MESSAGE( "LifeCycleCORBA::__init__" )
53 obj = self._orb.resolve_initial_references("NameService")
54 self._rootContext = obj._narrow(CosNaming.NamingContext)
56 if self._rootContext is None:
57 MESSAGE( "Name Service Reference is invalid" )
59 name = [CosNaming.NameComponent("Containers","dir")]
61 self._containerRootContext = self._rootContext.bind_new_context(name)
63 except CosNaming.NamingContext.AlreadyBound, ex:
64 MESSAGE( "/Containers.dir Context already exists" )
65 obj = self._rootContext.resolve(name)
66 self._containerRootContext = obj._narrow(CosNaming.NamingContext)
67 if self._containerRootContext is None:
68 MESSAGE( "Containers.dir exists but it is not a NamingContext" )
70 name = [CosNaming.NameComponent("Kernel","dir"),
71 CosNaming.NameComponent("ModulCatalog","object")]
73 obj = self._rootContext.resolve(name)
74 except CosNaming.NamingContext.NotFound, ex:
75 MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" )
77 self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
78 if self._catalog is None:
79 MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" )
81 #-------------------------------------------------------------------------
83 def ContainerName(self, containerName):
86 theComputer , theContainer = containerName.split('/')
89 theContainer = containerName
90 if theComputer == "" :
91 theComputer = getShortHostName()
92 if theComputer == "localhost" :
93 theComputer = getShortHostName()
94 computerSplitName = theComputer.split('.')
95 theComputer = computerSplitName[0]
96 MESSAGE( theComputer + theContainer )
97 return theComputer,theContainer
99 #-------------------------------------------------------------------------
101 def ComputerPath(self, ComputerName ):
103 #path = self._catalog.GetPathPrefix( ComputerName )
104 path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/"
105 except SALOME_ModuleCatalog.NotFound, ex:
109 #-------------------------------------------------------------------------
111 def FindContainer(self, containerName):
112 theComputer,theContainer = self.ContainerName( containerName )
113 name = [CosNaming.NameComponent(theComputer,"dir"),
114 CosNaming.NameComponent(theContainer,"object")]
117 obj = self._containerRootContext.resolve(name)
118 MESSAGE( containerName + ".object found in Naming Service" )
120 except CosNaming.NamingContext.NotFound, ex:
121 MESSAGE( containerName + ".object not found in Naming Service" )
126 container = obj._narrow(Engines.Container)
127 if container is None:
128 MESSAGE( containerName + ".object exists but is not a Container" )
131 #-------------------------------------------------------------------------
133 def FindOrStartContainer(self, theComputer , theContainer ):
134 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
135 aContainer = self.FindContainer( theComputer + "/" + theContainer )
136 if aContainer is None :
137 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
138 myMachine=getShortHostName()
139 if theComputer == myMachine :
142 rshstr = "rsh -n " + theComputer + " "
143 path = self.ComputerPath( theComputer )
145 ## rshstr = rshstr + path + "/../bin/"
147 ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
148 if theContainer == "FactoryServer" :
149 rshstr = rshstr + path + "SALOME_Container "
151 rshstr = rshstr + path + "SALOME_ContainerPy.py '"
152 rshstr = rshstr + theContainer + " -"
153 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
154 file = os.open( omniORBcfg , os.O_RDONLY )
155 ORBInitRef = os.read(file,132)
156 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
157 ORBInitRef,bsn = ORBInitRef.split('\n')
159 rshstr = rshstr + ORBInitRef
160 if theContainer == "FactoryServerPy" :
161 rshstr = rshstr + "'"
162 rshstr = rshstr + " > /tmp/" + theContainer + "_"
163 rshstr = rshstr + theComputer
164 rshstr = rshstr + ".log 2>&1 &"
166 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
168 if theContainer.find('Py') == -1 :
169 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
171 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
172 aContainer = aContainer.start_impl( theContainer )
175 while aContainer is None :
178 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
179 aContainer = self.FindContainer( theComputer + "/" + theContainer )
184 #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
186 #-------------------------------------------------------------------------
188 def FindOrLoadComponent(self, containerName, componentName):
190 theComputer,theContainer = self.ContainerName( containerName )
191 name = [CosNaming.NameComponent(theComputer,"dir"),
192 CosNaming.NameComponent(theContainer,"dir"),
193 CosNaming.NameComponent(componentName,"object")]
195 obj = self._containerRootContext.resolve(name)
196 except CosNaming.NamingContext.NotFound, ex:
197 MESSAGE( "component " + componentName + " not found, trying to load" )
198 container = self.FindContainer(theComputer + "/" + theContainer)
199 if container is None:
200 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
201 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
202 if theContainer.find('Py') == -1 :
203 theFactorycontainer = "FactoryServer"
205 theFactorycontainer = "FactoryServerPy"
206 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
207 if Factorycontainer is None:
208 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
209 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
211 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
212 if Factorycontainer != None :
213 container = self.FindOrStartContainer(theComputer,theContainer)
215 if container != None:
216 compoinfo = self._catalog.GetComponent(componentName)
217 if compoinfo is None:
218 MESSAGE( "component " + componentName + " not found in Module Catalog" )
221 machineName = theComputer
222 path = compoinfo.GetPathPrefix(machineName) + "/"
223 except SALOME_ModuleCatalog.NotFound, ex:
224 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
225 MESSAGE( "trying localhost" )
227 path = compoinfo.GetPathPrefix("localhost") + "/"
228 except SALOME_ModuleCatalog.NotFound, ex:
230 implementation = path + "lib" + componentName + "Engine.so"
231 MESSAGE( "Trying to load " + implementation )
233 component = container.load_impl(componentName, implementation)
234 MESSAGE( "component " + component._get_instanceName() + " launched !" )
237 MESSAGE( "component " + componentName + " NOT launched !" )
241 component = obj._narrow(Engines.Component)
242 if component is None:
243 MESSAGE( componentName + " is not a component !" )
245 MESSAGE( "component " + component._get_instanceName() + " found !" )
248 MESSAGE( componentName + " failure" )