From: caremoli Date: Fri, 21 Jan 2005 16:58:05 +0000 (+0000) Subject: CCAR: Modifications for container launching as is, ported from 2.1 to 2.2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=61be3a26a3c0e094a587b91ade8412ffd1e83dd6;p=modules%2Fkernel.git CCAR: Modifications for container launching as is, ported from 2.1 to 2.2 Need other files not in CVS to work (work in progress). --- diff --git a/Makefile.in b/Makefile.in index 426130bbd..e5a9c0e62 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,6 +97,8 @@ runSalome.csh \ runNS.sh \ launchConfigureParser.py \ salome.launch \ +envSalome.py \ +salomeConsole.py \ showNS.py # copy header files in common directory diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index 717815401..b61515d19 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -92,53 +92,18 @@ class xml_parser: # ----------------------------------------------------------------------------- -### searching for launch configuration file : $HOME/.$(application_name)/$(application_name).launch - -appname = None -dirname = None -filename = None -for bindir in glob.glob(os.environ["KERNEL_ROOT_DIR"]+"/bin/*"): - appname = string.split(bindir, "/").pop() - print 'Application name: "'+appname+'"' - # find version number - versnb = "" - try: - file = open(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/VERSION", "r") - s = file.read() - l = string.split(s, ":") - vl = string.split(l[1], " ") - i = 0 - while len(versnb) == 0: - versnb = vl[i] - i += 1 - pass - versnb = string.split(versnb, "\n")[0] - print "Version ",versnb - except: - pass - # end find version number - dirname = os.environ["HOME"]+"/."+appname+"_"+versnb - filename = dirname+"/"+appname+".launch" - if not os.path.exists(filename) and \ - not os.path.exists(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch"): - filename = None - else: - break - pass -if not appname: - print "Can not find application name" - if not os.have_key("KERNEL_ROOT_DIR"): - print "KERNEL_ROOT_DIR environment variable must be set" - pass - sys.exit(1); -elif not filename or not os.path.exists(filename): - filename = dirname+"/"+appname+".launch" - #filename = os.environ["HOME"]+"/."+appname+"/"+appname+".launch" - print "Launch configuration file does not exist. Create default:",filename - os.system("mkdir -p "+dirname) - #os.system("mkdir -p "+os.environ["HOME"]+"/."+appname) - os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch "+filename) - pass +### searching for launch configuration file : $HOME/applipath()/salome.launch + +appname="salome" +import Utils_Identity +versnb=Utils_Identity.version() +dirname = os.path.join(os.environ["HOME"],Utils_Identity.getapplipath()) +filename=os.path.join(dirname,"salome.launch") + +if not os.path.exists(filename): + print "Launch configuration file does not exist. Create default:",filename + os.system("mkdir -p "+dirname) + os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/salome/salome.launch "+filename) ### get options from launch configuration file @@ -251,28 +216,28 @@ if opts.has_key("h"): print """USAGE: runSalome.py [options] [command line options] : --help or -h : print this help - --gui or -g : lancement du GUI + --gui or -g : launching with GUI --terminal -t : launching without gui (to deny --gui) - --logger or -l : redirection des messages via CORBA - --file=filename or -l=filename: redirection des messages dans un fichier - --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre - --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue + --logger or -l : redirect messages in a CORBA collector + --file=filename or -f=filename: redirect messages in a log file + --xterm or -x : execute servers in xterm console (messages appear in xterm windows) + --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load) or -m=module1,module2,... --embedded=registry,study,moduleCatalog,cppContainer or -e=registry,study,moduleCatalog,cppContainer - : serveurs CORBA embarqués (par defaut: registry,study,moduleCatalog,cppContainer) - : (logger,pyContainer,supervContainer ne peuvent pas être embarqués + : embedded CORBA servers (default: registry,study,moduleCatalog,cppContainer) + : (logger,pyContainer,supervContainer can't be embedded --standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer - : executables serveurs CORBA indépendants (par défaut: pyContainer,supervContainer) - --containers=cpp,python,superv: (obsolete) lancement des containers cpp, python et de supervision - or -c=cpp,python,superv : = on prend les defauts de -e et -s + : standalone CORBA servers (default: pyContainer,supervContainer) + --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision + or -c=cpp,python,superv : = get default from -e and -s --portkill or -p : kill the salome with current port --killall or -k : kill salome - La variable d'environnement _ROOT_DIR doit etre préalablement - positionnée (modulen doit etre en majuscule). - KERNEL_ROOT_DIR est obligatoire. + For each Salome module, the environment variable _ROOT_DIR must be set. + The module name () must be uppercase. + KERNEL_ROOT_DIR is mandatory. """ sys.exit(1) pass diff --git a/bin/runSalome.py b/bin/runSalome.py index d7ba78d8d..a80e319f8 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -122,7 +122,7 @@ def set_env(args, modules_list, modules_root_dir): os.environ["SALOME_trace"]="local" if args['file']: - os.environ["SALOME_trace"]=args['file'][0] + os.environ["SALOME_trace"]=args['file'][0] if args['logger']: os.environ["SALOME_trace"]="with_logger" locdir=os.environ['PWD'] @@ -401,10 +401,12 @@ class NotifyServer(Server): self.modules_root_dir=modules_root_dir myLogName = os.environ["LOGNAME"] self.CMD=['notifd','-c', - self.modules_root_dir["KERNEL"] - +'/share/salome/resources/channel.cfg', + self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg', '-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior', - '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior'] + '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior', + '-DReportLogFile=/tmp/'+myLogName+'_notifd.report', + '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug', + ] # # ----------------------------------------------------------------------------- @@ -580,6 +582,8 @@ def useSalome(args, modules_list, modules_root_dir): try: clt = startSalome(args, modules_list, modules_root_dir) except: + import traceback + traceback.print_exc() print print print "--- erreur au lancement Salome ---" @@ -666,4 +670,5 @@ def main(): # ----------------------------------------------------------------------------- if __name__ == "__main__": + import user clt,args = main() diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index ecad1fa41..7dcd0b88a 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -67,6 +67,14 @@ module Engines */ Component load_impl(in string nameToRegister, in string componentName); +/*! + Loads into the container a new component, registers it and starts it's CORBA servant. + \param nameToRegister Name used to register in Naming Service, the component instance + \param componentName Name of the %component + \return a new instance of the component or the registered component if already registered or Nil if not possible +*/ + Component instance(in string nameToRegister, in string componentName); + /*! Stops the component servant, and deletes all related objects \param component_i Component to be removed diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index e36089f5e..e87321baf 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -477,3 +477,85 @@ long Engines_Container_i::getPID() { char* Engines_Container_i::getHostName() { return((char*)(GetHostname().c_str())); } + +/* + * Create one instance of componentName component and register it + * as nameToRegister in naming service + */ +Engines::Component_ptr Engines_Container_i::instance( const char* nameToRegister, + const char* componentName ) { + + _numInstanceMutex.lock() ; // lock on the instance number + BEGIN_OF( "Container_i::instance " << componentName ) ; + + string _nameToRegister = nameToRegister; + string component_registerName = _containerName + "/" + _nameToRegister; + + Engines::Component_var iobject = Engines::Component::_nil() ; + + try { + CORBA::Object_var obj = _NS->Resolve( component_registerName.c_str() ) ; + if (! CORBA::is_nil( obj ) ) { + MESSAGE( "Container_i::instance " << component_registerName.c_str() << " already registered" ) ; + iobject = Engines::Component::_narrow( obj ) ; + } + else{ + string _compo_name = componentName; + string _impl_name = "lib" + _compo_name + "Engine.so"; + SCRUTE(_impl_name); + + void* handle; + handle = dlopen( _impl_name.c_str() , RTLD_LAZY ) ; + + if ( handle ) { + string factory_name = _compo_name + "Engine_factory"; + SCRUTE(factory_name) ; + + typedef PortableServer::ObjectId * (*FACTORY_FUNCTION) + (CORBA::ORB_ptr, + PortableServer::POA_ptr, + PortableServer::ObjectId *, + const char *, + const char *) ; + FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION) dlsym(handle, factory_name.c_str()); + + char *error ; + if ( (error = dlerror() ) == NULL) { + // Instanciate required CORBA object + _numInstance++ ; + char _aNumI[12]; + sprintf( _aNumI , "%d" , _numInstance ) ; + string instanceName = _compo_name + "_inst_" + _aNumI ; + SCRUTE(instanceName); + + PortableServer::ObjectId * id ; + id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str() , + _nameToRegister.c_str() ) ; + // get reference from id + obj = _poa->id_to_reference(*id); + iobject = Engines::Component::_narrow( obj ) ; + + // register the engine under the name containerName.dir/nameToRegister.object + _NS->Register( iobject , component_registerName.c_str() ) ; + MESSAGE( "Container_i::instance " << component_registerName.c_str() << " registered" ) ; + handle_map[instanceName] = handle; + } + else{ + INFOS("Can't resolve symbol: " + factory_name); + SCRUTE(error); + } + } + else{ + INFOS("Can't load shared library : " << _impl_name); + INFOS("error dlopen: " << dlerror()); + } + } + } + catch (...) { + INFOS( "Container_i::instance exception caught" ) ; + } + END_OF("Container_i::instance"); + _numInstanceMutex.unlock() ; + return Engines::Component::_duplicate(iobject); +} + diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 417599eb9..dbaa9f65e 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -36,6 +36,8 @@ from omniORB import CORBA, PortableServer # (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes) import SALOMEDS import Engines, Engines__POA +reload(Engines) +reload(Engines__POA) from SALOME_NamingServicePy import * from SALOME_ComponentPy import * @@ -133,6 +135,22 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- + def instance(self, nameToRegister, componentName): + MESSAGE( "SALOME_ContainerPy_i::instance " + str(nameToRegister) + ' ' + str(componentName) ) + self._numInstance = self._numInstance +1 + instanceName = nameToRegister + "_inst_" + `self._numInstance` + + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, self._poa, self._this(), self._containerName, + instanceName, nameToRegister) + + MESSAGE( "SALOME_ContainerPy_i::instance : component created") + comp_o = comp_i._this() + return comp_o + + #------------------------------------------------------------------------- + def load_impl(self, nameToRegister, componentName): MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) ) self._numInstance = self._numInstance +1 @@ -150,21 +168,25 @@ class SALOME_ContainerPy_i (Engines__POA.Container): def remove_impl(self, component): MESSAGE( "SALOME_ContainerPy_i::remove_impl" ) + return None #------------------------------------------------------------------------- def finalize_removal(self): MESSAGE( "SALOME_ContainerPy_i::finalize_removal" ) + return None #------------------------------------------------------------------------- def ping(self): MESSAGE( "SALOME_ContainerPy_i::ping" ) + return None #------------------------------------------------------------------------- def _get_name(self): MESSAGE( "SALOME_ContainerPy_i::_get_name" ) + return self._containerName #------------------------------------------------------------------------- diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 6f309c50c..15674bae4 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -64,6 +64,9 @@ public: Engines::Component_ptr load_impl(const char* nameToRegister, const char* componentName); + Engines::Component_ptr instance(const char* nameToRegister, + const char* componentName); + //! Unload component from current container void remove_impl(Engines::Component_ptr component_i); void finalize_removal(); diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index 273916dd4..c6106dcb2 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -37,6 +37,8 @@ import SALOME_ModuleCatalog from SALOME_utilities import * from Utils_Identity import getShortHostName +import Utils_Identity +import Launchers class LifeCycleCORBA: _orb = None @@ -87,12 +89,10 @@ class LifeCycleCORBA: except: theComputer = "" theContainer = containerName - if theComputer == "" : - theComputer = getShortHostName() - if theComputer == "localhost" : + + if theComputer in ("","localhost") : theComputer = getShortHostName() - computerSplitName = theComputer.split('.') - theComputer = computerSplitName[0] + MESSAGE( theComputer + theContainer ) return theComputer,theContainer @@ -130,59 +130,57 @@ class LifeCycleCORBA: #------------------------------------------------------------------------- + def setLauncher(self,name): + """Change default launcher to the launcher identified by name + + See module Launchers.py + """ + Launchers.setLauncher(name) + + #------------------------------------------------------------------------- + + def StartContainer(self, theComputer , theContainer ): + """Start a container on theComputer machine with theContainer name + """ + # Get the Naming Service address + # + addr=self._orb.object_to_string(self._rootContext) + # + # If container name contains "Py" launch a Python Container + # + if theContainer.find('Py') == -1 : + CMD=['SALOME_Container',theContainer,'-ORBInitRef','NameService='+addr] + else: + CMD=['SALOME_ContainerPy.py',theContainer,'-ORBInitRef','NameService='+addr] + if theComputer in ("","localhost"): + theComputer=getShortHostName() + # + # Get the appropriate launcher and ask to launch + # + Launchers.getLauncher(theComputer).launch(theComputer,CMD) + # + # Wait until the container is registered in Naming Service + # + count =5 + aContainer=None + while aContainer is None and count > 0: + time.sleep(1) + count = count - 1 + MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer ) + aContainer = self.FindContainer( theComputer + "/" + theContainer ) + return aContainer + + #------------------------------------------------------------------------- + def FindOrStartContainer(self, theComputer , theContainer ): - MESSAGE( "FindOrStartContainer" + theComputer + theContainer ) + """Find or Start a container on theComputer machine with theContainer name + """ + MESSAGE( "FindOrStartContainer: " + theComputer + theContainer ) aContainer = self.FindContainer( theComputer + "/" + theContainer ) if aContainer is None : - if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") : - myMachine=getShortHostName() - if theComputer == myMachine : - rshstr = "" - else : - rshstr = "rsh -n " + theComputer + " " - path = self.ComputerPath( theComputer ) -## if path != "" : -## rshstr = rshstr + path + "/../bin/" -## else : -## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/" - if theContainer == "FactoryServer" : - rshstr = rshstr + path + "SALOME_Container " - else : - rshstr = rshstr + path + "SALOME_ContainerPy.py '" - rshstr = rshstr + theContainer + " -" - omniORBcfg = os.getenv( "OMNIORB_CONFIG" ) - file = os.open( omniORBcfg , os.O_RDONLY ) - ORBInitRef = os.read(file,132) - if ORBInitRef[len(ORBInitRef)-1] == '\n' : - ORBInitRef,bsn = ORBInitRef.split('\n') - os.close( file ) - rshstr = rshstr + ORBInitRef - if theContainer == "FactoryServerPy" : - rshstr = rshstr + "'" - rshstr = rshstr + " > /tmp/" + theContainer + "_" - rshstr = rshstr + theComputer - rshstr = rshstr + ".log 2>&1 &" - os.system( rshstr ) - MESSAGE( "FindOrStartContainer" + rshstr + " done" ) - else : - if theContainer.find('Py') == -1 : - aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" ) - else : - aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" ) - aContainer = aContainer.start_impl( theContainer ) - - count = 21 - while aContainer is None : - time.sleep(1) - count = count - 1 - MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer ) - aContainer = self.FindContainer( theComputer + "/" + theContainer ) - if count == 0 : - return aContainer - - return aContainer - #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515") - + aContainer= self.StartContainer(theComputer , theContainer ) + return aContainer + #------------------------------------------------------------------------- def FindOrLoadComponent(self, containerName, componentName): diff --git a/src/LifeCycleCORBA/Makefile.in b/src/LifeCycleCORBA/Makefile.in index 33ee1ac81..8926e289a 100644 --- a/src/LifeCycleCORBA/Makefile.in +++ b/src/LifeCycleCORBA/Makefile.in @@ -36,7 +36,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx -EXPORT_PYSCRIPTS = LifeCycleCORBA.py +EXPORT_PYSCRIPTS = LifeCycleCORBA.py Launchers.py # Libraries targets diff --git a/src/Utils/Utils_Identity.py b/src/Utils/Utils_Identity.py index 4f4cc4520..e73a5f596 100644 --- a/src/Utils/Utils_Identity.py +++ b/src/Utils/Utils_Identity.py @@ -57,3 +57,24 @@ class Identity: self._tc_start = time.time() self._cstart = time.ctime(self._tc_start) self._cdir = os.getcwd() + +def getapplipath(): + """ + Gives short application path (the complete path is $HOME/$APPLI) + """ + return os.environ.get("APPLI",".salome_"+versnb) + +try: + file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r") + s = file.readline() + versnb = string.strip(string.split(s, ":")[1]) + dirname=".salome_"+versnb +except: + versnb = "" + dirname=".salome" + +def version(): + """ + Gives salome version number + """ + return versnb