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 name = [CosNaming.NameComponent("ContainerManager","object")]
83 obj = self._rootContext.resolve(name)
84 except CosNaming.NamingContext.NotFound, ex:
85 MESSAGE( "ContainerManager.object not found in Naming Service" )
86 self._contManager = obj._narrow(Engines.ContainerManager)
87 if self._contManager is None:
88 MESSAGE( "ContainerManager.object exists but is not a ContainerManager")
90 #-------------------------------------------------------------------------
92 def ContainerName(self, containerName):
95 theComputer , theContainer = containerName.split('/')
98 theContainer = containerName
99 if theComputer == "" :
100 theComputer = getShortHostName()
101 if theComputer == "localhost" :
102 theComputer = getShortHostName()
103 computerSplitName = theComputer.split('.')
104 theComputer = computerSplitName[0]
105 MESSAGE( theComputer + theContainer )
106 return theComputer,theContainer
108 #-------------------------------------------------------------------------
110 def ComputerPath(self, ComputerName ):
112 #path = self._catalog.GetPathPrefix( ComputerName )
113 path = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/"
114 except SALOME_ModuleCatalog.NotFound, ex:
118 #-------------------------------------------------------------------------
120 def FindContainer(self, containerName):
121 theComputer,theContainer = self.ContainerName( containerName )
122 name = [CosNaming.NameComponent(theComputer,"dir"),
123 CosNaming.NameComponent(theContainer,"object")]
126 obj = self._containerRootContext.resolve(name)
127 MESSAGE( containerName + ".object found in Naming Service" )
129 except CosNaming.NamingContext.NotFound, ex:
130 MESSAGE( containerName + ".object not found in Naming Service" )
135 container = obj._narrow(Engines.Container)
136 if container is None:
137 MESSAGE( containerName + ".object exists but is not a Container" )
140 #-------------------------------------------------------------------------
142 def FindComponent(self,containerName,componentName,listOfMachines):
143 if containerName!="":
145 for i in range(len(listOfMachines)):
146 currentMachine=listOfMachines[i]
147 componentNameForNS= [CosNaming.NameComponent(currentMachine,"dir"),
148 CosNaming.NameComponent(containerName,"dir"),
149 CosNaming.NameComponent(componentName,"object")]
152 obj = self._containerRootContext.resolve(componentNameForNS)
153 except CosNaming.NamingContext.NotFound, ex:
154 MESSAGE( "component " + componentName + " not found on machine " + currentMachine + " , trying to load" )
157 machinesOK.append(currentMachine)
160 if len(machinesOK)!=0:
161 bestMachine=self._contManager.FindBest(machinesOK)
162 componentNameForNS= [CosNaming.NameComponent(bestMachine,"dir"),
163 CosNaming.NameComponent(containerName,"dir"),
164 CosNaming.NameComponent(componentName,"object")]
167 obj = self._containerRootContext.resolve(componentNameForNS)
171 return obj._narrow(Engines.Component)
173 MESSAGE( "Big problem !!!")
178 bestMachine=self._contManager.FindBest(listOfMachines)
179 MESSAGE("Not implemented yet ...")
183 #-------------------------------------------------------------------------
185 def LoadComponent(self,containerName,componentName,listOfMachine):
186 container=self._contManager.FindOrStartContainer(containerName,listOfMachine)
187 implementation="lib"+componentName+"Engine.so"
189 component = container.load_impl(componentName, implementation)
190 MESSAGE( "component " + component._get_instanceName() + " launched !" )
193 MESSAGE( "component " + componentName + " NOT launched !" )
196 #-------------------------------------------------------------------------
199 def FindOrLoadComponent(self, containerName, componentName):
200 sp=containerName.split("/")
203 listOfMachine.append(getShortHostName())
204 comp=self.FindComponent(containerName,componentName,listOfMachine)
206 return self.LoadComponent(containerName,componentName,listOfMachine)
211 params= Engines.MachineParameters(sp[1],sp[0],"LINUX",0,0,0,0)
212 listOfMachine=self._contManager.GetFittingResources(params,componentName)
213 ret=self.FindComponent(sp[1],componentName,listOfMachine);
215 return self.LoadComponent(sp[1],componentName,listOfMachine)