1 #==============================================================================
2 # File : LifeCycleCORBA.py
3 # Created : mer oct 17 08:42:01 CEST 2001
4 # Author : Paul RASCLE, EDF
8 #==============================================================================
13 from omniORB import CORBA
16 import SALOME_ModuleCatalog
18 from SALOME_utilities import *
23 _containerRootContext = None
26 #-------------------------------------------------------------------------
28 def __init__(self, orb):
29 MESSAGE( "LifeCycleCORBA::__init__" )
32 obj = self._orb.resolve_initial_references("NameService")
33 self._rootContext = obj._narrow(CosNaming.NamingContext)
35 if self._rootContext is None:
36 MESSAGE( "Name Service Reference is invalid" )
38 name = [CosNaming.NameComponent("Containers","dir")]
40 self._containerRootContext = self._rootContext.bind_new_context(name)
42 except CosNaming.NamingContext.AlreadyBound, ex:
43 MESSAGE( "/Containers.dir Context already exists" )
44 obj = self._rootContext.resolve(name)
45 self._containerRootContext = obj._narrow(CosNaming.NamingContext)
46 if self._containerRootContext is None:
47 MESSAGE( "Containers.dir exists but it is not a NamingContext" )
49 name = [CosNaming.NameComponent("Kernel","dir"),
50 CosNaming.NameComponent("ModulCatalog","object")]
52 obj = self._rootContext.resolve(name)
53 except CosNaming.NamingContext.NotFound, ex:
54 MESSAGE( "/Kernel.dir/ModulCatalog.object not found in Naming Service" )
56 self._catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
57 if self._catalog is None:
58 MESSAGE( "/Kernel.dir/ModulCatalog.object exists but is not a ModulCatalog" )
60 #-------------------------------------------------------------------------
62 def ContainerName(self, containerName):
64 theComputer , theContainer = containerName.split('/')
67 theContainer = containerName
68 if theComputer == "" :
69 theComputer = os.getenv("HOSTNAME")
70 if theComputer == "localhost" :
71 theComputer = os.getenv("HOSTNAME")
72 computerSplitName = theComputer.split('.')
73 theComputer = computerSplitName[0]
74 MESSAGE( theComputer + theContainer )
75 return theComputer,theContainer
77 #-------------------------------------------------------------------------
79 def ComputerPath(self, ComputerName ):
81 path = self._catalog.GetPathPrefix( ComputerName )
82 except SALOME_ModuleCatalog.NotFound, ex:
86 #-------------------------------------------------------------------------
88 def FindContainer(self, containerName):
89 theComputer,theContainer = self.ContainerName( containerName )
90 name = [CosNaming.NameComponent(theComputer,"dir"),
91 CosNaming.NameComponent(theContainer,"object")]
94 obj = self._containerRootContext.resolve(name)
95 MESSAGE( containerName + ".object found in Naming Service" )
97 except CosNaming.NamingContext.NotFound, ex:
98 MESSAGE( containerName + ".object not found in Naming Service" )
103 container = obj._narrow(Engines.Container)
104 if container is None:
105 MESSAGE( containerName + ".object exists but is not a Container" )
108 #-------------------------------------------------------------------------
110 def FindOrStartContainer(self, theComputer , theContainer ):
111 MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
112 aContainer = self.FindContainer( theComputer + "/" + theContainer )
113 if aContainer is None :
114 if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
115 if theComputer == os.getenv("HOSTNAME") :
118 rshstr = "rsh -n " + theComputer + " "
119 path = self.ComputerPath( theComputer )
121 rshstr = rshstr + path + "/../bin/"
123 rshstr = rshstr + os.getenv( "PWD" ) + "/"
124 if theContainer == "FactoryServer" :
125 rshstr = rshstr + "./runSession ./SALOME_Container "
127 rshstr = rshstr + "./runSession ./SALOME_ContainerPy.py '"
128 rshstr = rshstr + theContainer + " -"
129 omniORBcfg = os.getenv( "HOME" ) + "/omniORB.cfg"
130 # omniORBcfg = os.getenv( "HOME" ) + "/.omniORB.cfg"
131 file = os.open( omniORBcfg , os.O_RDONLY )
132 ORBInitRef = os.read(file,132)
133 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
134 ORBInitRef,bsn = ORBInitRef.split('\n')
136 rshstr = rshstr + ORBInitRef
137 if theContainer == "FactoryServerPy" :
138 rshstr = rshstr + "'"
139 rshstr = rshstr + " > /tmp/" + theContainer + "_"
140 rshstr = rshstr + theComputer
141 rshstr = rshstr + ".log 2>&1 &"
143 MESSAGE( "FindOrStartContainer" + rshstr + " done" )
145 if theContainer.find('Py') == -1 :
146 aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
148 aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
149 aContainer = aContainer.start_impl( theContainer )
152 while aContainer is None :
155 MESSAGE( count + ". Waiting for " + theComputer + "/" + theContainer )
156 aContainer = self.FindContainer( theComputer + "/" + theContainer )
161 #os.system("rsh -n dm2s0017 /export/home/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
163 #-------------------------------------------------------------------------
165 def FindOrLoadComponent(self, containerName, componentName):
167 theComputer,theContainer = self.ContainerName( containerName )
168 name = [CosNaming.NameComponent(theComputer,"dir"),
169 CosNaming.NameComponent(theContainer,"dir"),
170 CosNaming.NameComponent(componentName,"object")]
172 obj = self._containerRootContext.resolve(name)
173 except CosNaming.NamingContext.NotFound, ex:
174 MESSAGE( "component " + componentName + " not found, trying to load" )
175 container = self.FindContainer(theComputer + "/" + theContainer)
176 if container is None:
177 MESSAGE( "container " + theComputer + "/" + theContainer + " not found in Naming Service, trying to start" )
178 if (theContainer != "FactoryServer") & (theContainer != "FactoryServerPy") :
179 if theContainer.find('Py') == -1 :
180 theFactorycontainer = "FactoryServer"
182 theFactorycontainer = "FactoryServerPy"
183 Factorycontainer = self.FindContainer(theComputer + "/" + theFactorycontainer)
184 if Factorycontainer is None:
185 MESSAGE( "container " + theComputer + "/" + theFactorycontainer + " not found in Naming Service, trying to start" )
186 Factorycontainer = self.FindOrStartContainer(theComputer,theFactorycontainer)
188 Factorycontainer = self.FindOrStartContainer(theComputer,theContainer)
189 if Factorycontainer != None :
190 container = self.FindOrStartContainer(theComputer,theContainer)
192 if container != None:
193 compoinfo = self._catalog.GetComponent(componentName)
194 if compoinfo is None:
195 MESSAGE( "component " + componentName + " not found in Module Catalog" )
198 machineName = theComputer
199 path = compoinfo.GetPathPrefix(machineName) + "/"
200 except SALOME_ModuleCatalog.NotFound, ex:
201 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
202 MESSAGE( "trying localhost" )
204 path = compoinfo.GetPathPrefix("localhost") + "/"
205 except SALOME_ModuleCatalog.NotFound, ex:
207 implementation = path + "lib" + componentName + "Engine.so"
208 MESSAGE( "Trying to load " + implementation )
210 component = container.load_impl(componentName, implementation)
211 MESSAGE( "component " + component._get_instanceName() + " launched !" )
214 MESSAGE( "component " + componentName + " NOT launched !" )
218 component = obj._narrow(Engines.Component)
219 if component is None:
220 MESSAGE( componentName + " is not a component !" )
222 MESSAGE( "component " + component._get_instanceName() + " found !" )
225 MESSAGE( componentName + " failure" )