X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FLifeCycleCORBA%2FSALOME_LifeCycleCORBA.cxx;h=d8e39f3efd4bdc1f3f01e3c56d6ddc7e6a6180b2;hb=437d4c85cf1299465130f37c01202450eb22c4e6;hp=7b341e213beacd80aaab1d16b58fb86f03110a70;hpb=b83f7739ffb0509786b791c57366a57a4cc7c3e2;p=modules%2Fkernel.git diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index 7b341e213..d8e39f3ef 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -6,7 +6,7 @@ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -37,19 +37,26 @@ #endif #include "Basics_Utils.hxx" +#include "OpUtil.hxx" #include "utilities.h" #include #include "SALOME_LifeCycleCORBA.hxx" +#include "SALOME_ResourcesManager.hxx" +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOME_ExternalServerLauncher.hxx" + #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog) #include CORBA_CLIENT_HEADER(SALOME_Session) #include CORBA_CLIENT_HEADER(DSC_Engines) #include CORBA_CLIENT_HEADER(SALOME_Registry) #include CORBA_CLIENT_HEADER(SALOMEDS) +#include CORBA_CLIENT_HEADER(SALOME_SDS) #include CORBA_CLIENT_HEADER(Logger) #include CORBA_CLIENT_HEADER(SALOME_Launcher) +#include "SALOME_ResourcesManager.hxx" #include "SALOME_ContainerManager.hxx" #include "SALOME_Component_i.hxx" #include "SALOME_NamingService.hxx" @@ -61,7 +68,7 @@ IncompatibleComponent::IncompatibleComponent( void ): } IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex): - SALOME_Exception( ex ) + SALOME_Exception( ex ) { } @@ -71,21 +78,18 @@ IncompatibleComponent::IncompatibleComponent(const IncompatibleComponent &ex): */ //============================================================================= -/*! +/*! * Constructor */ //============================================================================= -SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) +SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService_Abstract *ns) { // be sure to have an instance of traceCollector, when used via SWIG // in a Python module - int argc = 0; - char *xargv = (char*)""; - char **argv = &xargv; - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + CORBA::ORB_var orb = KERNEL::GetRefToORB(); // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb); - _NSnew=0; + _NSnew = nullptr; if (!ns) { _NS = new SALOME_NamingService(orb); @@ -93,26 +97,28 @@ SALOME_LifeCycleCORBA::SALOME_LifeCycleCORBA(SALOME_NamingService *ns) } else _NS = ns; //add try catch - _NS->Change_Directory("/"); // mpv 250105: current directory may be not root + _NS->Change_Directory("/"); // mpv 250105: current directory may be not root // (in SALOMEDS for an example) // not enough: set a current directory in naming service is not thread safe // if naming service instance is shared among several threads... - // ==> allways use absolute path and dot rely on current directory! - - CORBA::Object_var obj = - _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); - if (CORBA::is_nil(obj)) - throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service"); - _ContManager=Engines::ContainerManager::_narrow(obj); - - obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); - if (CORBA::is_nil(obj)) - throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service"); - _ResManager=Engines::ResourcesManager::_narrow(obj); + // ==> always use absolute path and don't rely on current directory! + //if( dynamic_cast(_NS) ) + { + CORBA::Object_var obj = + _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS); + if (CORBA::is_nil(obj)) + throw SALOME_Exception("Error: Cannot resolve ContainerManager in Naming Service"); + _ContManager=Engines::ContainerManager::_narrow(obj); + + obj = _NS->Resolve(SALOME_ResourcesManager::_ResourcesManagerNameInNS); + if (CORBA::is_nil(obj)) + throw SALOME_Exception("Error: Cannot resolve ResourceManager in Naming Service"); + _ResManager=Engines::ResourcesManager::_narrow(obj); + } } //============================================================================= -/*! +/*! * Destructor */ //============================================================================= @@ -127,14 +133,12 @@ SALOME_LifeCycleCORBA::~SALOME_LifeCycleCORBA() * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if not found */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { if (! isKnownComponentClass(componentName)) return Engines::EngineComponent::_nil(); @@ -148,14 +152,13 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, { listOfResources = _ResManager->GetFittingResources(new_params.resource_params); } - catch( const SALOME::SALOME_Exception& ex ) + catch( const SALOME::SALOME_Exception& /*ex*/ ) //!< TODO: unused variable { return Engines::EngineComponent::_nil(); } Engines::EngineComponent_var compo = _FindComponent(new_params, componentName, - studyId, listOfResources); return compo._retn(); @@ -166,15 +169,13 @@ SALOME_LifeCycleCORBA::FindComponent(const Engines::ContainerParameters& params, * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { // --- Check if Component Name is known in ModuleCatalog @@ -191,15 +192,14 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, { listOfResources = _ResManager->GetFittingResources(new_params.resource_params); } - catch( const SALOME::SALOME_Exception& ex ) + catch( const SALOME::SALOME_Exception& /*ex*/ ) //!< TODO: unused variable { return Engines::EngineComponent::_nil(); } new_params.resource_params.resList = listOfResources; Engines::EngineComponent_var compo = _LoadComponent(new_params, - componentName, - studyId); + componentName); return compo._retn(); } @@ -210,7 +210,6 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, * * \param params container parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= @@ -218,8 +217,7 @@ SALOME_LifeCycleCORBA::LoadComponent(const Engines::ContainerParameters& params, Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: FindOrLoad_Component(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { // --- Check if Component Name is known in ModuleCatalog @@ -236,22 +234,20 @@ FindOrLoad_Component(const Engines::ContainerParameters& params, { listOfResources = _ResManager->GetFittingResources(new_params.resource_params); } - catch( const SALOME::SALOME_Exception& ex ) + catch( const SALOME::SALOME_Exception& /*ex*/ ) //!< TODO: unused variable { return Engines::EngineComponent::_nil(); } Engines::EngineComponent_var compo = _FindComponent(new_params, - componentName, - studyId, - listOfResources); + componentName, + listOfResources); if(CORBA::is_nil(compo)) { new_params.resource_params.resList = listOfResources; compo = _LoadComponent(new_params, - componentName, - studyId); + componentName); } return compo._retn(); @@ -282,16 +278,16 @@ SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName, // --- Check if containerName contains machine name (if yes: rg>0) char *stContainer=strdup(containerName); std::string st2Container(stContainer); - int rg=st2Container.find("/"); + size_t rg=st2Container.find("/"); Engines::ContainerParameters params; preSet(params); - if (rg<0) + if (rg == std::string::npos) { // containerName doesn't contain "/" => Local container params.container_name = CORBA::string_dup(stContainer); } - else + else { stContainer[rg]='\0'; params.container_name = CORBA::string_dup(stContainer+rg+1); @@ -316,12 +312,12 @@ bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName) try { CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog"); - SALOME_ModuleCatalog::ModuleCatalog_var Catalog = + SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ; ASSERT(! CORBA::is_nil(Catalog)); - SALOME_ModuleCatalog::Acomponent_var compoInfo = + SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(componentName); - if (CORBA::is_nil (compoInfo)) + if (CORBA::is_nil (compoInfo)) { MESSAGE("Catalog Error: Component not found in the catalog " << componentName); return false; @@ -344,7 +340,7 @@ bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName) */ //============================================================================= -void +void SALOME_LifeCycleCORBA::preSet(Engines::ResourceParameters& params) { params.name = ""; @@ -377,7 +373,7 @@ void SALOME_LifeCycleCORBA::preSet( Engines::ContainerParameters& params) } //============================================================================= -/*! +/*! * \return a number of processors not 0, only for MPI containers */ //============================================================================= @@ -421,15 +417,15 @@ Engines::ResourcesManager_ptr SALOME_LifeCycleCORBA::getResourcesManager() } //============================================================================= -/*! \brief shutdown all the SALOME servers except SALOME_Session_Server, omniNames and notifd +/*! \brief shutdown all the SALOME servers except SALOME_Session_Server and omniNames */ //============================================================================= -void SALOME_LifeCycleCORBA::shutdownServers() +void SALOME_LifeCycleCORBA::shutdownServers(bool shutdownLauncher) { // get each Container from NamingService => shutdown it // (the order is inverse to the order of servers initialization) - + SALOME::Session_var session = SALOME::Session::_nil(); CORBA::Long pid = 0; CORBA::Object_var objS = _NS->Resolve("/Kernel/Session"); @@ -444,7 +440,7 @@ void SALOME_LifeCycleCORBA::shutdownServers() } std::string hostname = Kernel_Utils::GetHostname(); - + // 1) ConnectionManager try { @@ -453,7 +449,7 @@ void SALOME_LifeCycleCORBA::shutdownServers() if ( !CORBA::is_nil(connMan) && ( pid != connMan->getPID() ) ) connMan->ShutdownWithExit(); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable { // ignore and continue } @@ -470,12 +466,13 @@ void SALOME_LifeCycleCORBA::shutdownServers() // 2) SALOMEDS try { - CORBA::Object_var objSDS = _NS->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var studyManager = SALOMEDS::StudyManager::_narrow(objSDS) ; - if ( !CORBA::is_nil(studyManager) && ( pid != studyManager->getPID() ) ) - studyManager->Shutdown(); + CORBA::Object_var objSDS = _NS->Resolve("/Study"); + SALOMEDS::Study_var study = SALOMEDS::Study::_narrow(objSDS) ; + if ( !CORBA::is_nil(study) && ( pid != study->getPID() ) ) + study->Shutdown(); + _NS->Destroy_Name("/Study"); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable { // ignore and continue } @@ -492,8 +489,9 @@ void SALOME_LifeCycleCORBA::shutdownServers() SALOME_ModuleCatalog::ModuleCatalog_var catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objMC); if ( !CORBA::is_nil(catalog) && ( pid != catalog->getPID() ) ) catalog->shutdown(); + _NS->Destroy_Name("/Kernel/ModulCatalog"); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable { // ignore and continue } @@ -502,57 +500,66 @@ void SALOME_LifeCycleCORBA::shutdownServers() #ifndef WIN32 nanosleep(&ts_req,0); #endif - - // 4) SalomeLauncher + // 4 ) Remote ScopeServer (the DataServer is hosted by SalomeLauncher shutdown right after on point 6) try { - CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); - Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL); - if (!CORBA::is_nil(launcher) && (pid != launcher->getPID())) - launcher->Shutdown(); + CORBA::Object_var objDSM(_NS->Resolve(SALOMESDS::DataServerManager::NAME_IN_NS)); + SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM)); + if ( !CORBA::is_nil(dsm) ) + dsm->shutdownScopes(); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable { // ignore and continue } - + // 5) External server launcher (the ExternalServer is hosted by SalomeLauncher shutdown right after on point 6) + try + { + CORBA::Object_var objDSM(_NS->Resolve(SALOME_ExternalServerLauncher::NAME_IN_NS)); + SALOME::ExternalServerLauncher_var dsm(SALOME::ExternalServerLauncher::_narrow(objDSM)); + if ( !CORBA::is_nil(dsm) ) + dsm->shutdownServers(); + } + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable + { + // ignore and continue + } + // 6) SalomeLauncher + try + { + if(shutdownLauncher){ + CORBA::Object_var objSL = _NS->Resolve("/SalomeLauncher"); + Engines::SalomeLauncher_var launcher = Engines::SalomeLauncher::_narrow(objSL); + if (!CORBA::is_nil(launcher) && (pid != launcher->getPID())) + launcher->Shutdown(); + } + } + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable + { + // ignore and continue + } + //Wait some time so that launcher be completely shutdown #ifndef WIN32 nanosleep(&ts_req,0); #endif - // 5) Registry + // 6) Registry try { CORBA::Object_var objR = _NS->Resolve("/Registry"); Registry::Components_var registry = Registry::Components::_narrow(objR); if ( !CORBA::is_nil(registry) && ( pid != registry->getPID() ) ) registry->Shutdown(); + _NS->Destroy_Name("/Registry"); } - catch(const CORBA::Exception& e) + catch(const CORBA::Exception& /*e*/) //!< TODO: unused variable { // ignore and continue } - /* - // 6) Session - if ( !CORBA::is_nil( session ) ) { - try - { - session->Shutdown(); - } - catch(const CORBA::Exception& e) - { - // ignore and continue - } - } - */ - // 7) Logger - int argc = 0; - char *xargv = (char*)""; - char **argv = &xargv; - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + CORBA::ORB_var orb = KERNEL::GetRefToORB(); CORBA::Object_var objLog = CORBA::Object::_nil(); CosNaming::NamingContext_var inc; @@ -562,8 +569,8 @@ void SALOME_LifeCycleCORBA::shutdownServers() name.length(1); name[0].id = CORBA::string_dup(stdname.c_str()); try - { - if(!CORBA::is_nil(orb)) + { + if(!CORBA::is_nil(orb)) theObj = orb->resolve_initial_references("NameService"); if (!CORBA::is_nil(theObj)) inc = CosNaming::NamingContext::_narrow(theObj); @@ -571,7 +578,7 @@ void SALOME_LifeCycleCORBA::shutdownServers() catch(...) { } - if(!CORBA::is_nil(inc)) + if(!CORBA::is_nil(inc)) { try { @@ -587,36 +594,42 @@ void SALOME_LifeCycleCORBA::shutdownServers() } //============================================================================= -/*! \brief shutdown omniNames and notifd +/*! \brief shutdown omniNames */ //============================================================================= void SALOME_LifeCycleCORBA::killOmniNames() { std::string portNumber (::getenv ("NSPORT") ); - if ( !portNumber.empty() ) + std::string python_exe; + + python_exe = std::string("python3"); + + if ( !portNumber.empty() ) { -#ifdef WNT -#else - std::string cmd ; - cmd = std::string( "ps -eo pid,command | grep -v grep | grep -E \"omniNames.*") - + portNumber - + std::string("\" | awk '{cmd=sprintf(\"kill -9 %s\",$1); system(cmd)}'" ); + std::string cmd; + + cmd = std::string("from salome_utils import killOmniNames; "); + cmd += std::string("killOmniNames(") + portNumber + "); "; + cmd = python_exe + std::string(" -c \"") + cmd +"\""; MESSAGE(cmd); - try { - system ( cmd.c_str() ); - } - catch ( ... ) { - } -#endif + system( cmd.c_str() ); + + cmd = std::string("from killSalomeWithPort import cleanApplication; "); + cmd += std::string("cleanApplication(") + portNumber + "); "; + cmd = python_exe + std::string(" -c \"") + cmd +"\""; + MESSAGE(cmd); + system( cmd.c_str() ); } - - // NPAL 18309 (Kill Notifd) - if ( !portNumber.empty() ) + + // shutdown portmanager + if ( !portNumber.empty() ) { - std::string cmd = ("from killSalomeWithPort import killNotifdAndClean; "); - cmd += std::string("killNotifdAndClean(") + portNumber + "); "; - cmd = std::string("python -c \"") + cmd +"\" > /dev/null 2> /dev/null"; + std::string cmd; + + cmd = std::string("from PortManager import releasePort; "); + cmd += std::string("releasePort(") + portNumber + "); "; + cmd = python_exe + std::string(" -c \"") + cmd +"\""; MESSAGE(cmd); system( cmd.c_str() ); } @@ -630,7 +643,6 @@ void SALOME_LifeCycleCORBA::killOmniNames() * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \param listOfMachines list of machine address * \return a CORBA reference of the component instance, or _nil if not found */ @@ -640,7 +652,6 @@ Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: _FindComponent(const Engines::ContainerParameters& params, const char *componentName, - int studyId, const Engines::ResourceList& listOfResources) { // --- build the list of machines on which the component is already running @@ -691,16 +702,14 @@ _FindComponent(const Engines::ContainerParameters& params, * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the component instance, or _nil if problem */ //============================================================================= -Engines::EngineComponent_ptr +Engines::EngineComponent_ptr SALOME_LifeCycleCORBA:: -_LoadComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) +_LoadComponent(const Engines::ContainerParameters& params, + const char *componentName) { MESSAGE("_LoadComponent, required " << params.container_name << " " << componentName << " " << NbProc(params)); @@ -712,7 +721,7 @@ _LoadComponent(const Engines::ContainerParameters& params, char* reason; bool isLoadable = cont->load_component_Library(componentName,reason); - if (!isLoadable) + if (!isLoadable) { //std::cerr << reason << std::endl; CORBA::string_free(reason); @@ -721,7 +730,7 @@ _LoadComponent(const Engines::ContainerParameters& params, CORBA::string_free(reason); Engines::EngineComponent_var myInstance = - cont->create_component_instance(componentName, studyId); + cont->create_component_instance(componentName); return myInstance._retn(); } @@ -730,14 +739,12 @@ _LoadComponent(const Engines::ContainerParameters& params, * * \param params machine parameters like type or name... * \param componentName the name of component class - * \param studyId default = 0 : multistudy instance * \return a CORBA reference of the parallel component instance, or _nil if problem */ //============================================================================= Engines::EngineComponent_ptr SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters& params, - const char *componentName, - int studyId) + const char *componentName) { MESSAGE("Entering LoadParallelComponent"); @@ -773,7 +780,7 @@ SALOME_LifeCycleCORBA::Load_ParallelComponent(const Engines::ContainerParameters // @PARALLEL@ permits to identify that the component requested // is a parallel component. std::string name = std::string(componentName); - Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str(), studyId); + Engines::EngineComponent_var myInstance = cont->create_component_instance(name.c_str()); if (CORBA::is_nil(myInstance)) INFOS("create_component_instance returns a NULL component !"); return myInstance._retn(); @@ -814,7 +821,7 @@ void SALOME_LifeCycleCORBA::copyFile(const char* hostSrc, const char* fileSrc, c * * \return the naming service */ -SALOME_NamingService * SALOME_LifeCycleCORBA::namingService() +SALOME_NamingService_Abstract * SALOME_LifeCycleCORBA::namingService() { return _NS; } @@ -825,5 +832,15 @@ SALOME_NamingService * SALOME_LifeCycleCORBA::namingService() */ CORBA::ORB_ptr SALOME_LifeCycleCORBA::orb() { - return _NS->orb(); + SALOME_NamingService *NSC = dynamic_cast(_NS); + if(!_NS) + THROW_SALOME_EXCEPTION("SALOME_LifeCycleCORBA::orb : not a CORBA SALOME_NamingService "); + return NSC->orb(); +} + +#include "SALOME_Fake_NamingService.hxx" + +SALOME_LifeCycleCORBASSL::SALOME_LifeCycleCORBASSL():SALOME_LifeCycleCORBA(new SALOME_Fake_NamingService) +{ + _NSnew = _NS;//give to SALOME_LifeCycleCORBA owenership of _NS }