From a3226c5ce6fbc6dee5bab820ad8809dae248ab7e Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 17 Aug 2021 16:31:23 +0200 Subject: [PATCH] SDS in SSL mode. --- CTestTestfileInstall.cmake.in | 1 + src/KERNEL_PY/__init__.py | 5 +- .../SALOME_Fake_NamingService.cxx | 45 +++++++++- .../SALOME_Fake_NamingService.hxx | 3 + src/SALOMESDS/CMakeLists.txt | 5 +- src/SALOMESDS/CTestTestfileInstall.cmake | 2 +- src/SALOMESDS/KernelSDS.cxx | 16 +++- src/SALOMESDS/KernelSDS.hxx | 3 +- src/SALOMESDS/KernelSDS.i | 49 ++++++++++- src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 8 +- src/SALOMESDS/SALOMESDS_DataScopeServer.hxx | 10 +-- src/SALOMESDS/SALOMESDS_DataServerManager.cxx | 33 ++++--- src/SALOMESDS/SALOME_DataScopeServer.cxx | 58 +------------ .../SALOME_DataScopeServer_Common.cxx | 85 +++++++++++++++++++ src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx | 44 ++++++++++ src/SALOMESDS/TestSalomeSDS.py | 40 +++++++-- src/SALOMESDS/TestSalomeSDSHelper0.py | 14 ++- 17 files changed, 324 insertions(+), 97 deletions(-) create mode 100644 src/SALOMESDS/SALOME_DataScopeServer_Common.cxx create mode 100644 src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx diff --git a/CTestTestfileInstall.cmake.in b/CTestTestfileInstall.cmake.in index 3c6b54920..b6ee219e3 100644 --- a/CTestTestfileInstall.cmake.in +++ b/CTestTestfileInstall.cmake.in @@ -18,6 +18,7 @@ # SET(SALOME_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/salome_test_driver.py") +SET(PYTHON_TEST_DRIVER "$ENV{KERNEL_ROOT_DIR}/bin/salome/appliskel/python_test_driver.py") SET(COMPONENT_NAME KERNEL) SET(TIMEOUT 200) diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 5c0900e62..8e78458d2 100644 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -204,7 +204,7 @@ class StandAloneLifecyle: return self._rm def salome_init_without_session(): - global lcc,naming_service,myStudy,orb,modulcat,sg,cm + global lcc,naming_service,myStudy,orb,modulcat,sg,cm,dsm import KernelBasis KernelBasis.setSSLMode(True) import KernelDS @@ -226,6 +226,9 @@ def salome_init_without_session(): sg = SalomeOutsideGUI() salome_study_init_without_session() naming_service = NamingService() + from KernelSDS import GetDSMInstance + import sys + dsm = GetDSMInstance(sys.argv) def salome_init_with_session(path=None, embedded=False): """ diff --git a/src/NamingService/SALOME_Fake_NamingService.cxx b/src/NamingService/SALOME_Fake_NamingService.cxx index e9e19f30d..a667cc03e 100644 --- a/src/NamingService/SALOME_Fake_NamingService.cxx +++ b/src/NamingService/SALOME_Fake_NamingService.cxx @@ -60,6 +60,11 @@ void SALOME_Fake_NamingService::Register(CORBA::Object_ptr ObjRef, const char* P void SALOME_Fake_NamingService::Destroy_Name(const char* Path) { + std::lock_guard g(_mutex); + std::string pathCpp(Path); + auto it = _map.find(pathCpp); + if(it!=_map.end()) + _map.erase(it); } void SALOME_Fake_NamingService::Destroy_Directory(const char* Path) @@ -72,9 +77,33 @@ void SALOME_Fake_NamingService::Destroy_FullDirectory(const char* Path) bool SALOME_Fake_NamingService::Change_Directory(const char* Path) { + std::lock_guard g(_mutex); + _current_dir = Path; return true; } +std::vector SALOME_Fake_NamingService::SplitDir(const std::string& fullPath) +{ + constexpr char SEP = '/'; + std::vector ret; + if(fullPath.empty()) + THROW_SALOME_EXCEPTION("Empty input string"); + if(fullPath.at(0) != SEP) + THROW_SALOME_EXCEPTION("input string is expected to start with " << SEP); + auto len = fullPath.length(); + if( len == 1 ) + THROW_SALOME_EXCEPTION("input string is expected to be different from " << SEP); + std::size_t pos = 1; + while(pos < len) + { + std::size_t endPos = fullPath.find_first_of(SEP,pos); + std::string elt(fullPath.substr(pos,endPos==std::string::npos?std::string::npos:endPos-pos)); + ret.push_back(elt); + pos = endPos==std::string::npos?std::string::npos:endPos+1; + } + return ret; +} + std::vector SALOME_Fake_NamingService::list_subdirs() { return std::vector(); @@ -82,7 +111,21 @@ std::vector SALOME_Fake_NamingService::list_subdirs() std::vector SALOME_Fake_NamingService::list_directory() { - return std::vector(); + std::lock_guard g(_mutex); + std::vector ret; + std::vector splitCWD(SplitDir(_current_dir)); + auto len = _current_dir.length(); + for(auto it : _map) + { + std::vector splitIt(SplitDir(it.first)); + if(splitIt.size()<=splitCWD.size()) + continue; + std::vector partSplitIt(splitIt.cbegin(),splitIt.cbegin()+splitCWD.size()); + if(partSplitIt!=splitCWD) + continue; + ret.push_back(splitIt.at(splitCWD.size())); + } + return ret; } std::vector SALOME_Fake_NamingService::list_directory_recurs() diff --git a/src/NamingService/SALOME_Fake_NamingService.hxx b/src/NamingService/SALOME_Fake_NamingService.hxx index 295433cfa..a4a10f96b 100644 --- a/src/NamingService/SALOME_Fake_NamingService.hxx +++ b/src/NamingService/SALOME_Fake_NamingService.hxx @@ -56,9 +56,12 @@ private: static std::string ReprOfContainersIORS(); static std::vector< std::pair< std::string, Engines::Container_var> > ListOfContainersInNS_NoThreadSafe(); static void FlushLogContainersFile_NoThreadSafe(); + static std::vector SplitDir(const std::string& fullPath); private: static std::mutex _mutex; static std::map _map; static bool _log_container_file_thread_launched; static std::string _log_container_file_name; +private: + mutable std::string _current_dir; }; diff --git a/src/SALOMESDS/CMakeLists.txt b/src/SALOMESDS/CMakeLists.txt index c3195be20..14a3f7d9f 100644 --- a/src/SALOMESDS/CMakeLists.txt +++ b/src/SALOMESDS/CMakeLists.txt @@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/../Container ${CMAKE_CURRENT_SOURCE_DIR}/../ResourcesManager ${CMAKE_CURRENT_SOURCE_DIR}/../KernelHelpers + ${CMAKE_CURRENT_SOURCE_DIR}/../Basics ${CMAKE_CURRENT_SOURCE_DIR} ) @@ -62,7 +63,9 @@ INSTALL(TARGETS SalomeSDS EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME ADD_EXECUTABLE(SALOME_DataScopeServer SALOME_DataScopeServer.cxx) TARGET_LINK_LIBRARIES(SALOME_DataScopeServer SalomeSDS) -INSTALL(TARGETS SALOME_DataScopeServer DESTINATION ${SALOME_INSTALL_BINS}) +ADD_EXECUTABLE(SALOME_DataScopeServer_SSL SALOME_DataScopeServer_SSL.cxx) +TARGET_LINK_LIBRARIES(SALOME_DataScopeServer_SSL SalomeSDS) +INSTALL(TARGETS SALOME_DataScopeServer SALOME_DataScopeServer_SSL DESTINATION ${SALOME_INSTALL_BINS}) INSTALL(FILES SalomeSDSClt.py SALOMEWrappedStdType.py DESTINATION ${SALOME_INSTALL_BINS}) FILE(GLOB COMMON_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx") INSTALL(FILES ${COMMON_HEADERS_HXX} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/SALOMESDS/CTestTestfileInstall.cmake b/src/SALOMESDS/CTestTestfileInstall.cmake index aa7fecdbf..125496459 100644 --- a/src/SALOMESDS/CTestTestfileInstall.cmake +++ b/src/SALOMESDS/CTestTestfileInstall.cmake @@ -19,6 +19,6 @@ IF(NOT WIN32) SET(TEST_NAME ${COMPONENT_NAME}_SalomeSDS) - ADD_TEST(${TEST_NAME} ${SALOME_TEST_DRIVER} ${TIMEOUT} TestSalomeSDS.py) + ADD_TEST(${TEST_NAME} ${PYTHON_TEST_DRIVER} ${TIMEOUT} TestSalomeSDS.py) SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" ENVIRONMENT "PYTHONPATH=${KERNEL_TEST_LIB}:$ENV{PYTHONPATH}") ENDIF(NOT WIN32) diff --git a/src/SALOMESDS/KernelSDS.cxx b/src/SALOMESDS/KernelSDS.cxx index 3c21b267a..a76f99f14 100644 --- a/src/SALOMESDS/KernelSDS.cxx +++ b/src/SALOMESDS/KernelSDS.cxx @@ -22,9 +22,11 @@ #include "SALOME_Fake_NamingService.hxx" #include "SALOME_KernelORB.hxx" +#include + static SALOME::DataServerManager_var _dsm_singleton; -std::string GetDSMInstanceInternal() +std::string GetDSMInstanceInternal(const std::vector& argv) { CORBA::ORB_ptr orb = KERNEL::getORB(); if( CORBA::is_nil(_dsm_singleton) ) @@ -35,9 +37,15 @@ std::string GetDSMInstanceInternal() root_poa = PortableServer::POA::_narrow(obj); SALOME_CPythonHelper cPyh; { - int argc(1); - char *argv[2] = {"oops",nullptr}; - cPyh.initializePython(argc,argv); + int argcInit((int)argv.size()); + char **argvInit = new char *[argcInit+1]; + argvInit[argcInit] = nullptr; + for(int i = 0 ; i < argcInit ; ++i) + argvInit[i] = strdup(argv[i].c_str()); + cPyh.initializePython(argcInit,argvInit); + for(int i = 0 ; i < argcInit ; ++i) + free(argvInit[i]); + delete [] argvInit; } SALOME_Fake_NamingService *ns(new SALOME_Fake_NamingService); SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa,ns)); diff --git a/src/SALOMESDS/KernelSDS.hxx b/src/SALOMESDS/KernelSDS.hxx index 3f1eb0475..9782426a0 100644 --- a/src/SALOMESDS/KernelSDS.hxx +++ b/src/SALOMESDS/KernelSDS.hxx @@ -20,5 +20,6 @@ #pragma once #include +#include -std::string GetDSMInstanceInternal(); +std::string GetDSMInstanceInternal(const std::vector& argv); diff --git a/src/SALOMESDS/KernelSDS.i b/src/SALOMESDS/KernelSDS.i index cc1e46e09..74779d8b0 100644 --- a/src/SALOMESDS/KernelSDS.i +++ b/src/SALOMESDS/KernelSDS.i @@ -23,17 +23,60 @@ %{ #include "KernelSDS.hxx" +#include "Utils_SALOME_Exception.hxx" %} + +class SALOME_Exception +{ + public: + SALOME_Exception(const std::string& text); + %extend + { + std::string __str__() const + { + return std::string(self->what()); + } + } +}; + +%exception { + try { + $action + } + catch (SALOME_Exception& _e) { + // Reraise with SWIG_Python_Raise + SWIG_Python_Raise(SWIG_NewPointerObj((new SALOME_Exception(static_cast< const SALOME_Exception& >(_e.what()))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception); + SWIG_fail; + } +} + %inline { - std::string GetDSMInstanceInternal(); + std::string GetDSMInstanceInternal(PyObject *argv) + { + if(!PyList_Check(argv)) + THROW_SALOME_EXCEPTION("Not a pylist"); + Py_ssize_t sz=PyList_Size(argv); + std::vector argvCpp(sz); + for(Py_ssize_t i = 0 ; i < sz ; ++i) + { + PyObject *obj = PyList_GetItem(argv,i); + if(!PyUnicode_Check(obj)) + THROW_SALOME_EXCEPTION("Not a pylist of strings"); + { + Py_ssize_t dummy; + argvCpp[i] = PyUnicode_AsUTF8AndSize(obj,&dummy); + } + } + return GetDSMInstanceInternal(argvCpp); + } } %pythoncode %{ -def GetDSMInstance(): +def GetDSMInstance(argv): import SALOME import CORBA orb=CORBA.ORB_init(['']) - return orb.string_to_object(GetDSMInstanceInternal()) + return orb.string_to_object(GetDSMInstanceInternal(argv)) %} diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index b6c961a27..fa7d04a9e 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -71,11 +71,11 @@ void RequestSwitcher::fetchAndGetAccessOfVar(const char *varName, CORBA::String_ return _ds->fetchAndGetAccessOfVar(varName,access,data); } -DataScopeServerBase::DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):_ns(ns),_pyHelper(pyHelper),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer) +DataScopeServerBase::DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns):_ns(ns),_pyHelper(pyHelper),_orb(CORBA::ORB::_duplicate(orb)),_name(scopeName),_killer(killer) { } -DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_ns(other._ns->cloneCoVar()),_pyHelper(other._pyHelper),_name(other._name),_vars(other._vars),_killer(other._killer) +DataScopeServerBase::DataScopeServerBase(const DataScopeServerBase& other):omniServant(other),ServantBase(other),_ns(other._ns->clone()),_pyHelper(other._pyHelper),_name(other._name),_vars(other._vars),_killer(other._killer) { } @@ -473,7 +473,7 @@ std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterat /////// -DataScopeServer::DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns) +DataScopeServer::DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns) { } @@ -520,7 +520,7 @@ DataScopeServer::~DataScopeServer() //////// -DataScopeServerTransaction::DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns) +DataScopeServerTransaction::DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns):DataScopeServerBase(pyHelper,orb,killer,scopeName,ns) { CORBA::Object_var obj(_orb->resolve_initial_references("RootPOA")); PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx index a705946a1..e6e466f7b 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.hxx @@ -38,7 +38,7 @@ #include #include -class SALOME_NamingService_Abstract; +class SALOME_NamingService_Container_Abstract; namespace SALOMESDS { @@ -75,7 +75,7 @@ namespace SALOMESDS class SALOMESDS_EXPORT DataScopeServerBase : public virtual POA_SALOME::DataScopeServerBase, public POAHolder { public: - DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns); + DataScopeServerBase(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns); DataScopeServerBase(const DataScopeServerBase& other); public: // remote access methods void ping(); @@ -117,7 +117,7 @@ namespace SALOMESDS std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::const_iterator retrieveVarInternal3(const std::string& varName) const; std::list< std::pair< SALOME::BasicDataServer_var, BasicDataServer * > >::iterator retrieveVarInternal4(const std::string& varName); protected: - SALOME_NamingService_Abstract *_ns = nullptr; + SALOME_NamingService_Container_Abstract *_ns = nullptr; const SALOME_CPythonHelper *_pyHelper = nullptr; PortableServer::POA_var _poa; CORBA::ORB_var _orb; @@ -130,7 +130,7 @@ namespace SALOMESDS class SALOMESDS_EXPORT DataScopeServer : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServer { public: - DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns); + DataScopeServer(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns); DataScopeServer(const DataScopeServer& other); SALOME::BasicDataServer_ptr retrieveVar(const char *varName) { return retrieveVarInternal(varName); } SALOME::PickelizedPyObjRdOnlyServer_ptr createRdOnlyVar(const char *varName, const SALOME::ByteVec& constValue); @@ -142,7 +142,7 @@ namespace SALOMESDS class SALOMESDS_EXPORT DataScopeServerTransaction : public DataScopeServerBase, public virtual POA_SALOME::DataScopeServerTransaction { public://not remotely callable - DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Abstract *ns); + DataScopeServerTransaction(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, SALOME::DataScopeKiller_var killer, const std::string& scopeName, SALOME_NamingService_Container_Abstract *ns); DataScopeServerTransaction(const DataScopeServerTransaction& other); ~DataScopeServerTransaction(); void createRdOnlyVarInternal(const std::string& varName, const SALOME::ByteVec& constValue); diff --git a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx index 2c2d9b277..80ba9319e 100644 --- a/src/SALOMESDS/SALOMESDS_DataServerManager.cxx +++ b/src/SALOMESDS/SALOMESDS_DataServerManager.cxx @@ -23,6 +23,8 @@ #include "SALOME_ContainerManager.hxx" #include "SALOME_NamingService.hxx" +#include "SALOME_Embedded_NamingService.hxx" +#include "KernelBasis.hxx" #include #include @@ -121,7 +123,7 @@ CORBA::Boolean DataServerManager::isAliveAndKicking(const char *scopeName) } template -typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vector& scopes, SALOME_NamingService_Abstract& ns) +typename T::PtrType CreateDataScope(CORBA::ORB_ptr orb, const std::string& scopeName, const std::vector& scopes, SALOME_NamingService_Abstract& ns) { int isTransactionInt(T::IsTransaction); if(std::find(scopes.begin(),scopes.end(),scopeName)!=scopes.end()) @@ -131,8 +133,19 @@ typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vec } // std::string fullScopeName(DataServerManager::CreateAbsNameInNSFromScopeName(scopeName)); - std::ostringstream oss; oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt << " "; - SALOME_ContainerManager::AddOmninamesParams(oss,&ns); + std::ostringstream oss; + if(!getSSLMode()) + { + oss << "SALOME_DataScopeServer" << " " << scopeName << " " << isTransactionInt << " "; + SALOME_ContainerManager::AddOmninamesParams(oss,&ns); + } + else + { + oss << "SALOME_DataScopeServer_SSL" << " " << scopeName << " " << isTransactionInt << " "; + Engines::EmbeddedNamingService_var emb = GetEmbeddedNamingService(); + CORBA::String_var ior = orb->object_to_string(emb); + oss << ior.in(); + } std::string command(oss.str()); SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(command); int status(SALOME_ContainerManager::SystemThreadSafe(command.c_str())); @@ -154,12 +167,12 @@ typename T::PtrType CreateDataScope(const std::string& scopeName, const std::vec } template -typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std::vector& scopes, SALOME_NamingService_Abstract& ns, CORBA::Boolean& isCreated) +typename T::PtrType GiveADataScopeCalled(CORBA::ORB_ptr orb, const std::string& scopeName, const std::vector& scopes, SALOME_NamingService_Abstract& ns, CORBA::Boolean& isCreated) { if(std::find(scopes.begin(),scopes.end(),scopeName)==scopes.end()) { isCreated=true; - return CreateDataScope(scopeName,scopes,ns); + return CreateDataScope(orb,scopeName,scopes,ns); } else { @@ -182,7 +195,7 @@ typename T::PtrType GiveADataScopeCalled(const std::string& scopeName, const std std::string fullScopeName(SALOMESDS::DataServerManager::CreateAbsNameInNSFromScopeName(scopeName)); ns.Destroy_Name(fullScopeName.c_str()); isCreated=true; - return CreateDataScope(scopeName,scopes,ns); + return CreateDataScope(orb,scopeName,scopes,ns); } } } @@ -213,22 +226,22 @@ public: SALOME::DataScopeServer_ptr DataServerManager::createDataScope(const char *scopeName) { - return CreateDataScope(scopeName,listOfScopesCpp(),*_ns); + return CreateDataScope(_orb,scopeName,listOfScopesCpp(),*_ns); } SALOME::DataScopeServer_ptr DataServerManager::giveADataScopeCalled(const char *scopeName, CORBA::Boolean& isCreated) { - return GiveADataScopeCalled(scopeName,listOfScopesCpp(),*_ns,isCreated); + return GiveADataScopeCalled(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated); } SALOME::DataScopeServerTransaction_ptr DataServerManager::createDataScopeTransaction(const char *scopeName) { - return CreateDataScope(scopeName,listOfScopesCpp(),*_ns); + return CreateDataScope(_orb,scopeName,listOfScopesCpp(),*_ns); } SALOME::DataScopeServerTransaction_ptr DataServerManager::giveADataScopeTransactionCalled(const char *scopeName, CORBA::Boolean& isCreated) { - return GiveADataScopeCalled(scopeName,listOfScopesCpp(),*_ns,isCreated); + return GiveADataScopeCalled(_orb,scopeName,listOfScopesCpp(),*_ns,isCreated); } SALOME::DataScopeServerBase_ptr DataServerManager::retriveDataScope(const char *scopeName) diff --git a/src/SALOMESDS/SALOME_DataScopeServer.cxx b/src/SALOMESDS/SALOME_DataScopeServer.cxx index e2daee44a..5f265ad30 100644 --- a/src/SALOMESDS/SALOME_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOME_DataScopeServer.cxx @@ -18,18 +18,13 @@ // // Author : Anthony GEAY (EDF R&D) -#include "SALOMESDS_DataScopeServer.hxx" -#include "SALOMESDS_DataServerManager.hxx" -#include "SALOMESDS_Exception.hxx" -#include "SALOME_CPythonHelper.hxx" +#include "SALOME_DataScopeServer_Common.cxx" #include "SALOME_NamingService.hxx" -#include -#include - int main(int argc, char *argv[]) { + CORBA::ORB_var orb = GetCustomORB(); std::string scopeName; if(argc<=1) throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !"); @@ -37,52 +32,5 @@ int main(int argc, char *argv[]) std::istringstream isTransacSS(argv[2]); int isTransac(0); isTransacSS >> isTransac; - CORBA::ORB_var orb; - { - int argc(3); - char **argv=new char *[3]; - char *p0(strdup("DTC")),*p1(strdup("-ORBsupportCurrent")),*p2(strdup("0")); - argv[0]=p0; - argv[1]=p1;// by disabling supportCurrent it make the POAManager::hold_requests work ! - argv[2]=p2; - orb=CORBA::ORB_init(argc,argv); - free(p0); free(p1); free(p2); - delete [] argv; - } - CORBA::Object_var obj(orb->resolve_initial_references("RootPOA")); - PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); - PortableServer::POAManager_var mgr(poa->the_POAManager()); - mgr->activate(); - // - SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb)); - SALOME::DataScopeKiller_var killerObj(killer->_this()); - // - SALOME_CPythonHelper cPyHelper; - cPyHelper.initializePython(argc,argv); - // - SALOMESDS::DataScopeServerBase *server(nullptr); - if(!isTransac) - server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb)); - else - server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName,new SALOME_NamingService(orb)); - // - CORBA::PolicyList policies; - policies.length(3); - PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); - policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); - policies[1]=poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); - policies[2]=poa->create_id_uniqueness_policy(PortableServer::UNIQUE_ID); - PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies)); - threadPol->destroy(); - server->registerToSalomePiDict(); - // - server->setPOA(poa2); - obj=server->activate(); - SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj)); - server->registerInNS(serverPtr); - // - orb->run(); - delete killer; - return 0; + return CommonDataScopeServerMain(argc,argv,orb,scopeName,isTransac,[](CORBA::ORB_ptr orb2) { return new SALOME_NamingService(orb2); }); } - diff --git a/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx b/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx new file mode 100644 index 000000000..cf77e09b2 --- /dev/null +++ b/src/SALOMESDS/SALOME_DataScopeServer_Common.cxx @@ -0,0 +1,85 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#include "SALOMESDS_DataScopeServer.hxx" +#include "SALOMESDS_DataServerManager.hxx" +#include "SALOMESDS_Exception.hxx" +#include "SALOME_CPythonHelper.hxx" +#include "SALOME_NamingService_Abstract.hxx" + +#include +#include +#include + +CORBA::ORB_var GetCustomORB() +{ + CORBA::ORB_var orb; + { + int argc(3); + char **argv=new char *[3]; + char *p0(strdup("DTC")),*p1(strdup("-ORBsupportCurrent")),*p2(strdup("0")); + argv[0]=p0; + argv[1]=p1;// by disabling supportCurrent it make the POAManager::hold_requests work ! + argv[2]=p2; + orb=CORBA::ORB_init(argc,argv); + free(p0); free(p1); free(p2); + delete [] argv; + } + return orb; +} + +int CommonDataScopeServerMain(int argc, char *argv[], CORBA::ORB_var orb, const std::string& scopeName, int isTransac, std::function nsGenrator) +{ + CORBA::Object_var obj(orb->resolve_initial_references("RootPOA")); + PortableServer::POA_var poa(PortableServer::POA::_narrow(obj)); + PortableServer::POAManager_var mgr(poa->the_POAManager()); + mgr->activate(); + // + SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb)); + SALOME::DataScopeKiller_var killerObj(killer->_this()); + // + SALOME_CPythonHelper cPyHelper; + cPyHelper.initializePython(argc,argv); + // + SALOMESDS::DataScopeServerBase *server(nullptr); + if(!isTransac) + server=new SALOMESDS::DataScopeServer(&cPyHelper,orb,killerObj,scopeName,nsGenrator(orb)); + else + server=new SALOMESDS::DataScopeServerTransaction(&cPyHelper,orb,killerObj,scopeName,nsGenrator(orb)); + // + CORBA::PolicyList policies; + policies.length(3); + PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL)); + policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol); + policies[1]=poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION); + policies[2]=poa->create_id_uniqueness_policy(PortableServer::UNIQUE_ID); + PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies)); + threadPol->destroy(); + server->registerToSalomePiDict(); + // + server->setPOA(poa2); + obj=server->activate(); + SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj)); + server->registerInNS(serverPtr); + // + orb->run(); + delete killer; + return 0; +} diff --git a/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx b/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx new file mode 100644 index 000000000..ebd8f1e86 --- /dev/null +++ b/src/SALOMESDS/SALOME_DataScopeServer_SSL.cxx @@ -0,0 +1,44 @@ +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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, 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 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// Author : Anthony GEAY (EDF R&D) + +#include "SALOME_DataScopeServer_Common.cxx" + +#include "SALOME_Embedded_NamingService_Client.hxx" +#include "Utils_SALOME_Exception.hxx" + +int main(int argc, char *argv[]) +{ + CORBA::ORB_var orb = GetCustomORB(); + std::string scopeName; + if(argc<=2) + throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !"); + scopeName=argv[1]; + std::istringstream isTransacSS(argv[2]); + int isTransac(0); + isTransacSS >> isTransac; + std::string IORFakeNS(argv[3]); + CORBA::Object_var ns_serv_obj_base = orb->string_to_object(IORFakeNS.c_str()); + if( CORBA::is_nil(ns_serv_obj_base) ) + THROW_SALOME_EXCEPTION( "SALOME_DataScopeServer_SSL : argument 3 is NOT a valid IOR" ); + Engines::EmbeddedNamingService_var ns_serv_obj = Engines::EmbeddedNamingService::_narrow(ns_serv_obj_base); + if( CORBA::is_nil(ns_serv_obj) ) + THROW_SALOME_EXCEPTION( "SALOME_DataScopeServer_SSL : argument 3 is NOT a valid IOR of Engines::EmbeddedNamingService" ); + return CommonDataScopeServerMain(argc,argv,orb,scopeName,isTransac,[ns_serv_obj](CORBA::ORB_ptr orb) { return new SALOME_Embedded_NamingService_Client(ns_serv_obj); }); +} diff --git a/src/SALOMESDS/TestSalomeSDS.py b/src/SALOMESDS/TestSalomeSDS.py index c509d74fb..54d3c1947 100644 --- a/src/SALOMESDS/TestSalomeSDS.py +++ b/src/SALOMESDS/TestSalomeSDS.py @@ -43,7 +43,7 @@ def generateKey(varName,scopeName): time.sleep(3) dss.atomicApply([t]) def work(t): - i,varName,scopeName=t + IORNS,i,varName,scopeName=t if i==0: generateKey(varName,scopeName) return 0 @@ -51,7 +51,7 @@ def work(t): import TestSalomeSDSHelper0 import os,subprocess fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py" - proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(["python3", fname, IORNS], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err=proc.communicate() if proc.returncode!=0: print("-------------- work -----------") @@ -96,7 +96,8 @@ def func_test7(scopeName,cv,cv2,cv3,sharedNum): class SalomeSDSTest(unittest.TestCase): def testList1(self): - a=SalomeSDSClt.CreateRdExtGlobalVar([],"a","Scope0") + scopeName = "Scope0" + a=SalomeSDSClt.CreateRdExtGlobalVar([],"a",scopeName) self.assertEqual(a.local_copy(),[]) a.append(5) self.assertEqual(a.local_copy(),[5]) @@ -112,10 +113,15 @@ class SalomeSDSTest(unittest.TestCase): a[4].append(7) self.assertEqual(a.local_copy(),[5,["rt",8],5,["rt",8],["rt",8,7]]) a.ptr().getMyDataScopeServer().deleteVar("a") + del a + import gc + gc.collect(0) + salome.dsm.removeDataScope(scopeName) pass def testDict1(self): - a=SalomeSDSClt.CreateRdExtGlobalVar({},"a","Scope0") + scopeName = "Scope0" + a=SalomeSDSClt.CreateRdExtGlobalVar({},"a",scopeName) a["ab"]=4 self.assertEqual(a.local_copy(),{"ab":4}) a["cd"]=[5] @@ -133,13 +139,24 @@ class SalomeSDSTest(unittest.TestCase): a["gh"]["cd"].append(99) ; a["cd"].append(88) self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77,88],"ef":["a","bb","ccc"],"gh":{"ab":4,"cd":[5,77,99],"ef":["a","bb","ccc"]}}) a.ptr().getMyDataScopeServer().deleteVar("a") + del a + import gc + gc.collect(0) + salome.dsm.removeDataScope(scopeName) pass def testReadOnly1(self): - a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a","Scope0") + scopeName = "Scope0" + # + a=SalomeSDSClt.CreateRdOnlyGlobalVar({"ab":4,"cd":[5,77]},"a",scopeName) self.assertEqual(a.local_copy(),{"ab":4,"cd":[5,77]}) self.assertRaises(Exception,a.__getitem__,"ab") a.ptr().getMyDataScopeServer().deleteVar("a") + del a + import gc + gc.collect(0) + # + salome.dsm.removeDataScope(scopeName) def testTransaction1(self): scopeName="Scope1" @@ -166,7 +183,8 @@ class SalomeSDSTest(unittest.TestCase): # nbProc=8 pool=mp.Pool(processes=nbProc) - asyncResult=pool.map_async(work,[(i,varName,scopeName) for i in range(nbProc)]) + from NamingService import NamingService + asyncResult=pool.map_async(work,[(NamingService.IOROfNS(),i,varName,scopeName) for i in range(nbProc)]) print("asyncResult=", asyncResult) self.assertEqual(asyncResult.get(),nbProc*[0]) # <- the big test is here ! dsm.removeDataScope(scopeName) @@ -194,6 +212,7 @@ class SalomeSDSTest(unittest.TestCase): wk=dss.waitForKeyInVar(varName,obj2Str("cd")) wk.waitFor() self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) + dsm.removeDataScope(scopeName) def testTransaction3(self): scopeName="Scope1" @@ -216,6 +235,7 @@ class SalomeSDSTest(unittest.TestCase): t2=dss.removeKeyInVarErrorIfNotAlreadyExisting(varName,obj2Str("ab")) dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'cd':[7,8,9,10]}) + dsm.removeDataScope(scopeName) def testTransaction4(self): scopeName="Scope1" @@ -240,6 +260,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) dss.atomicApply([t2]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6]}) + dsm.removeDataScope(scopeName) def testTransaction5(self): """ Like testTransaction2 but without transactions. """ @@ -274,6 +295,7 @@ class SalomeSDSTest(unittest.TestCase): self.assertEqual(str2Obj(dss.waitForMonoThrRev(wk)),[7,8,9,10]) keys=[str2Obj(elt) for elt in dss.getAllKeysOfVarWithTypeDict(varName)] self.assertEqual(set(keys),set(['ab','cd'])) + dsm.removeDataScope(scopeName) def testTransaction6(self): """ Test to test RdWr global vars with transaction""" @@ -346,6 +368,7 @@ class SalomeSDSTest(unittest.TestCase): dss.atomicApply([t1]) self.assertEqual(dss.getAccessOfVar(varName),"RdExt") self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),{'ab':[4,5,6],'cd':[7,8,9,10]}) + dsm.removeDataScope(scopeName) pass def testTransaction8(self): @@ -383,6 +406,7 @@ class SalomeSDSTest(unittest.TestCase): t4=dss.createRdExtVarFreeStyleTransac(varName,obj2Str(value),funcContent) self.assertRaises(SALOME.SALOME_Exception,dss.atomicApply,[t4]) # d is in dict pointed by var. Func returns false -> rejected self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value3) + dsm.removeDataScope(scopeName) pass def testTransaction9(self): @@ -412,6 +436,7 @@ class SalomeSDSTest(unittest.TestCase): t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("c"),obj2Str(3)) dss.atomicApply([t1]) self.assertEqual(str2Obj(dss.fetchSerializedContent(varName)),value2) + dsm.removeDataScope(scopeName) pass @@ -466,10 +491,11 @@ class SalomeSDSTest(unittest.TestCase): self.assertTrue(s>=0.99*nbOfSecWait and s