From b21679048b02aa12f1635955cae68cc9f154bc2d Mon Sep 17 00:00:00 2001 From: secher Date: Wed, 25 May 2005 09:01:00 +0000 Subject: [PATCH] destroy container name in naming service on shutdown --- idl/SALOME_MPIContainer.idl | 9 +- src/Container/Container_i.cxx | 2 +- src/Container/SALOME_ContainerManager.cxx | 2 - src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 1 - src/MPIContainer/MPIContainer_i.cxx | 121 ++----------------- src/MPIContainer/MPIContainer_i.hxx | 10 +- src/NamingService/SALOME_NamingService.cxx | 21 ++++ src/NamingService/SALOME_NamingService.hxx | 4 + 8 files changed, 39 insertions(+), 131 deletions(-) diff --git a/idl/SALOME_MPIContainer.idl b/idl/SALOME_MPIContainer.idl index 8265c7380..dfe23ec5e 100644 --- a/idl/SALOME_MPIContainer.idl +++ b/idl/SALOME_MPIContainer.idl @@ -31,13 +31,10 @@ module Engines { interface MPIContainer:Container,MPIObject { - // start MPI container executable - MPIContainer start_MPIimpl( in string ContainerName, in short nbproc ); - // asynchronous version to load and remove parallel component in parallel - oneway void SPload_impl(in string nameToRegister, in string componentName); - oneway void SPremove_impl(in Component component_i); - oneway void SPfinalize_removal(); + oneway void Asload_impl(in string nameToRegister, in string componentName); + oneway void Asremove_impl(in Component component_i); + oneway void Asfinalize_removal(); }; } ; diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 919bbf03b..ed5140f7f 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -146,7 +146,7 @@ void Engines_Container_i::ping() void Engines_Container_i::Shutdown() { MESSAGE("Engines_Container_i::Shutdown()"); - _NS->Destroy_Name(_containerName.c_str()); + _NS->Destroy_FullDirectory(_containerName.c_str()); //_remove_ref(); //_poa->deactivate_object(*_id); if(_isServantAloneInProcess) diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index d3b5f53ff..38b104c0e 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -51,7 +51,6 @@ void SALOME_ContainerManager::ShutdownContainers() vector vec=_NS->list_directory_recurs(); for(vector::iterator iter=vec.begin();iter!=vec.end();iter++) { - cerr << "SALOME_ContainerManager::ShutdownContainers : " << (*iter).c_str() << endl; SCRUTE((*iter)); CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); Engines::Container_var cont=Engines::Container::_narrow(obj); @@ -76,7 +75,6 @@ Engines::Container_ptr SALOME_ContainerManager::FindOrStartContainer(const Engin command=_ResManager->BuildTempFileToLaunchRemoteContainer(theMachine,params); _ResManager->RmTmpFile(); int status=system(command.c_str()); - cerr << status << endl; if (status == -1) { MESSAGE("SALOME_LifeCycleCORBA::StartOrFindContainer rsh failed (system command status -1)"); return Engines::Container::_nil(); diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 82408c66a..be445e1d8 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -176,7 +176,6 @@ Engines::Component_ptr SALOME_LifeCycleCORBA::FindComponent(const Engines::Machi { const char *containerName = params.container_name; int nbproc = NbProc(params); - cerr << nbproc << endl;; if (! isKnownComponentClass(componentName)) return Engines::Component::_nil(); diff --git a/src/MPIContainer/MPIContainer_i.cxx b/src/MPIContainer/MPIContainer_i.cxx index f95236226..77467d78f 100644 --- a/src/MPIContainer/MPIContainer_i.cxx +++ b/src/MPIContainer/MPIContainer_i.cxx @@ -81,107 +81,6 @@ Engines_MPIContainer_i::~Engines_MPIContainer_i(void) } } -// Start MPI Container -Engines::MPIContainer_ptr Engines_MPIContainer_i::start_MPIimpl( - const char* ContainerName, - CORBA::Short nbproc ) -{ - - char nbp[1024]; - - MESSAGE("[" << _numproc << "] start_impl argc " << _argc << " ContainerName " << ContainerName - << hex << this << dec) ; - _numInstanceMutex.lock() ; // lock on the instance number - - CORBA::Object_var obj = Engines::MPIContainer::_nil() ; - bool nilvar = true ; - try { - string cont("/Containers/"); - cont += machineName() ; - cont += "/" ; - cont += ContainerName; - INFOS("[" << _numproc << "] " << machineName() << " start_impl unknown container " << cont.c_str() - << " try to Resolve" ); - obj = _NS->Resolve( cont.c_str() ); - nilvar = CORBA::is_nil( obj ) ; - if ( nilvar ) { - INFOS("[" << _numproc << "] " << machineName() << " start_impl unknown container " - << ContainerName); - } - } - catch (ServiceUnreachable&) { - INFOS("[" << _numproc << "] " << machineName() << "Caught exception: Naming Service Unreachable"); - } - catch (...) { - INFOS("[" << _numproc << "] " << machineName() << "Caught unknown exception."); - } - if ( !nilvar ) { - _numInstanceMutex.unlock() ; - MESSAGE("[" << _numproc << "] start_impl container found without new launch") ; - return Engines::MPIContainer::_narrow(obj); - } - int i = 0 ; - while ( _argv[ i ] ) { - MESSAGE("[" << _numproc << "] argv" << i << " " << _argv[ i ]) ; - i++ ; - } - sprintf(nbp,"mpirun -np %d SALOME_MPIContainer ",nbproc); - string shstr(nbp); - shstr += ContainerName ; - if ( _argc == 4 ) { - shstr += " " ; - shstr += _argv[ 2 ] ; - shstr += " " ; - shstr += _argv[ 3 ] ; - } - shstr += " > /tmp/" ; - shstr += ContainerName ; - shstr += ".log 2>&1 &" ; - MESSAGE("system(" << shstr << ")") ; - int status = system( shstr.c_str() ) ; - if (status == -1) { - INFOS("[" << _numproc << "] Engines_MPIContainer_i::start_impl SALOME_MPIContainer failed (system command status -1)") ; - } - else if (status == 217) { - INFOS("[" << _numproc << "] Engines_MPIContainer_i::start_impl SALOME_MPIContainer failed (system command status 217)") ; - } - INFOS("[" << _numproc << "] " << machineName() << " Engines_MPIContainer_i::start_impl SALOME_MPIContainer launch done"); - - obj = Engines::MPIContainer::_nil() ; - try { - string cont("/Containers/"); - cont += machineName() ; - cont += "/" ; - cont += ContainerName; - nilvar = true ; - int count = 20 ; - while ( nilvar && count >= 0) { - sleep( 1 ) ; - obj = _NS->Resolve(cont.c_str()); - nilvar = CORBA::is_nil( obj ) ; - if ( nilvar ) { - INFOS("[" << _numproc << "] " << count << ". " << machineName() - << " start_impl unknown container " << cont.c_str()); - count -= 1 ; - } - } - _numInstanceMutex.unlock() ; - if ( !nilvar ) { - MESSAGE("[" << _numproc << "] start_impl container found after new launch of SALOME_MPIContainer") ; - } - return Engines::MPIContainer::_narrow(obj); - } - catch (ServiceUnreachable&) { - INFOS("[" << _numproc << "] " << machineName() << "Caught exception: Naming Service Unreachable"); - } - catch (...) { - INFOS("[" << _numproc << "] " << machineName() << "Caught unknown exception."); - } - _numInstanceMutex.unlock() ; - MESSAGE("[" << _numproc << "] start_impl MPI container not found after new launch of SALOME_MPIContainer") ; - return Engines::MPIContainer::_nil() ; -} - // Load component Engines::Component_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegister, const char* componentName) @@ -191,7 +90,7 @@ Engines::Component_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegis if( _numproc == 0 ){ // Invocation du chargement du composant dans les autres process for(ip= 1;ip<_nbproc;ip++) - (Engines::MPIContainer::_narrow((*_tior)[ip]))->SPload_impl(nameToRegister, + (Engines::MPIContainer::_narrow((*_tior)[ip]))->Asload_impl(nameToRegister, componentName); } @@ -200,7 +99,7 @@ Engines::Component_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegis } // Load component -void Engines_MPIContainer_i::SPload_impl(const char* nameToRegister, +void Engines_MPIContainer_i::Asload_impl(const char* nameToRegister, const char* componentName) { Lload_impl(nameToRegister,componentName); @@ -306,25 +205,20 @@ void Engines_MPIContainer_i::remove_impl(Engines::Component_ptr component_i) for(ip= 1;ip<_nbproc;ip++){ spcptr = Engines::MPIObject::_narrow((*(pcptr->tior()))[ip]); cptr = (Engines::Component_ptr)spcptr; - (Engines::MPIContainer::_narrow((*_tior)[ip]))->SPremove_impl(cptr); + (Engines::MPIContainer::_narrow((*_tior)[ip]))->Asremove_impl(cptr); } } Lremove_impl(component_i); } -void Engines_MPIContainer_i::SPremove_impl(Engines::Component_ptr component_i) +void Engines_MPIContainer_i::Asremove_impl(Engines::Component_ptr component_i) { Lremove_impl(component_i); } void Engines_MPIContainer_i::Lremove_impl(Engines::Component_ptr component_i) { - int ip; - Engines::Component_ptr cptr; - Engines::MPIObject_ptr pcptr; - Engines::MPIObject_ptr spcptr; - BEGIN_OF("[" << _numproc << "] MPIContainer_i::Lremove_impl"); ASSERT(! CORBA::is_nil(component_i)); @@ -359,13 +253,13 @@ void Engines_MPIContainer_i::finalize_removal() if( _numproc == 0 ){ // Invocation de la destruction du composant dans les autres process for(ip= 1;ip<_nbproc;ip++) - (Engines::MPIContainer::_narrow((*_tior)[ip]))->SPfinalize_removal(); + (Engines::MPIContainer::_narrow((*_tior)[ip]))->Asfinalize_removal(); } Lfinalize_removal(); } -void Engines_MPIContainer_i::SPfinalize_removal() +void Engines_MPIContainer_i::Asfinalize_removal() { Lfinalize_removal(); } @@ -396,8 +290,7 @@ void Engines_MPIContainer_i::Shutdown() int ip; MESSAGE("[" << _numproc << "] shutdown of MPI Corba Server"); if( _numproc == 0 ){ - MESSAGE("[" << _numproc << "] destroy from Naming Service of " << _containerName); - _NS->Destroy_Name(_containerName.c_str()); + _NS->Destroy_FullDirectory(_containerName.c_str()); for(ip= 1;ip<_nbproc;ip++) (Engines::MPIContainer::_narrow((*_tior)[ip]))->Shutdown(); } diff --git a/src/MPIContainer/MPIContainer_i.hxx b/src/MPIContainer/MPIContainer_i.hxx index d58aef574..a805639a1 100644 --- a/src/MPIContainer/MPIContainer_i.hxx +++ b/src/MPIContainer/MPIContainer_i.hxx @@ -48,10 +48,6 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, // Destructor ~Engines_MPIContainer_i(); - // Launch a new MPI container from the current container - Engines::MPIContainer_ptr start_MPIimpl(const char* ContainerName, - CORBA::Short nbproc); - // Load a component in current MPI container // synchronous version for process 0 Engines::Component_ptr load_impl(const char* nameToRegister, @@ -60,18 +56,18 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, void Shutdown(); // asynchronous version for other process - void SPload_impl(const char* nameToRegister, const char* componentName); + void Asload_impl(const char* nameToRegister, const char* componentName); // Unload a component from current MPI container // synchronous version for process 0 void remove_impl(Engines::Component_ptr component_i); // asynchronous version for other process - void SPremove_impl(Engines::Component_ptr component_i); + void Asremove_impl(Engines::Component_ptr component_i); // synchronous version for process 0 void finalize_removal(); // asynchronous version for other process - void SPfinalize_removal(); + void Asfinalize_removal(); private: // local version to not duplicate code diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 70ea6e56a..845c8be3e 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -1157,6 +1157,27 @@ void SALOME_NamingService::Destroy_Directory(const char* Path) delete[] resultat_resolve_Path ; } +//---------------------------------------------------------------------- +/*! Function : Destroy_Directory. + * Purpose : method to destroy a directory if it is empty. + * WARNING : The complete Path to the directory (from the root_context) + * to destroy should be given. + * If the NamingService is out, the exception ServiceUnreachable is thrown. + * \param Path const char* arguments + */ +//---------------------------------------------------------------------- + +void SALOME_NamingService::Destroy_FullDirectory(const char* Path) + throw(ServiceUnreachable) +{ + Change_Directory(Path); + vector contList = list_directory(); + for(unsigned int ind = 0; ind < contList.size(); ind++) + Destroy_Name(contList[ind].c_str()); + Destroy_Directory(Path); + Destroy_Name(Path); +} + //---------------------------------------------------------------------- /*! Function : _initialize_root_context * Purpose : method called by constructor to initialize _root_context diff --git a/src/NamingService/SALOME_NamingService.hxx b/src/NamingService/SALOME_NamingService.hxx index 31866d4c8..3e5ff8f81 100644 --- a/src/NamingService/SALOME_NamingService.hxx +++ b/src/NamingService/SALOME_NamingService.hxx @@ -109,6 +109,10 @@ public: virtual void Destroy_Directory(const char* Path) throw(ServiceUnreachable); + //! method to destroy a directory even if it is not empty + virtual void Destroy_FullDirectory(const char* Path) + throw(ServiceUnreachable); + //! get IORstring naming service address char * getIORaddr(); -- 2.39.2