}
_listInstances_map.clear();
- _NS->Destroy_FullDirectory(_containerName.c_str());
- _NS->Destroy_Name(_containerName.c_str());
+ // NS unregistering may throw in SSL mode if master process hosting SALOME_Embedded_NamingService servant has vanished
+ // In this case it's skip it and still continue.
+ try
+ {
+ _NS->Destroy_FullDirectory(_containerName.c_str());
+ _NS->Destroy_Name(_containerName.c_str());
+ }
+ catch(...)
+ {
+ }
+ //
if(_isServantAloneInProcess)
{
MESSAGE("Effective Shutdown of container Begins...");
bool _isSupervContainer;
- SALOME_NamingService_Container_Abstract *_NS ;
+ SALOME_NamingService_Container_Abstract *_NS ;
std::string _library_path;
std::string _containerName;
std::string _logfilename;
%{
#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
#include "SALOME_KernelORB.hxx"
+#include "Utils_SALOME_Exception.hxx"
%}
%include "std_string.i"
%template(svec) std::vector<std::string>;
+%exceptionclass SALOME_Exception;
+
+class SALOME_Exception
+{
+public:
+ SALOME_Exception(const std::string& text);
+ ~SALOME_Exception() noexcept;
+ const char *what() const noexcept;
+ %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))),SWIGTYPE_p_SALOME_Exception,SWIG_POINTER_OWN), "SALOME_Exception", SWIGTYPE_p_SALOME_Exception);
+ SWIG_fail;
+ }
+}
+
class SALOME_Fake_NamingService
{
public:
SALOME_Fake_NamingService();
std::vector< std::string > repr();
- static void LaunchLogContainersFile(const std::string& logFileName);
static std::string GetLogContainersFile();
+ static void FlushLogContainersFile();
%extend {
+ static void SetLogContainersFileInternal(const std::string& logFileName)
+ {
+ SALOME_Fake_NamingService::SetLogContainersFile(logFileName);
+ }
std::string _ResolveInternal(const char *Path)
{
CORBA::Object_var obj = self->Resolve(Path);
CORBA::Object_var obj = orb->string_to_object(ior);
self->Register(obj,Path);
}
+ static std::string IOROfNS()
+ {
+ CORBA::ORB_ptr orb = KERNEL::getORB();
+ Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+ CORBA::String_var ior = orb->object_to_string(ns);
+ return std::string(ior);
+ }
}
};
self._RegisterInternal( orb.object_to_string(obj) , Path)
NamingService.Resolve = NamingService_Resolve
NamingService.Register = NamingService_Register
+def NamingService_SetLogContainersFile(cls,logFileName = None):
+ if logFileName is None:
+ import tempfile
+ with tempfile.NamedTemporaryFile() as f:
+ logFileName = f.name
+ cls.SetLogContainersFileInternal(logFileName)
+NamingService.SetLogContainersFile = classmethod(NamingService_SetLogContainersFile)
+def NamingService_RefOfNS(cls):
+ ret = cls.IOROfNS()
+ import Engines
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ return orb.string_to_object(ret)
+NamingService.RefOfNS = classmethod(NamingService_RefOfNS)
+def NamingService_KillContainersInFile(cls,logFileName):
+ import Engines
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ with open(logFileName) as f:
+ cont_to_kill = [elt.split(" : ") for elt in f]
+ for name,ior in cont_to_kill:
+ try:
+ ref = orb.string_to_object(ior)
+ ref.Shutdown()
+ except Exception as e:
+ print("Failed to kill container remotely \"{}\"".format(name))
+NamingService.KillContainersInFile = classmethod(NamingService_KillContainersInFile)
%}
#include <sstream>
#include <fstream>
-#include <thread>
-#include <chrono>
std::mutex SALOME_Fake_NamingService::_mutex;
std::map<std::string,CORBA::Object_var> SALOME_Fake_NamingService::_map;
std::lock_guard<std::mutex> g(_mutex);
CORBA::Object_var ObjRefAuto = CORBA::Object::_duplicate(ObjRef);
_map[Path] = ObjRefAuto;
+ FlushLogContainersFile_NoThreadSafe();
}
void SALOME_Fake_NamingService::Destroy_Name(const char* Path)
return Resolve(entryToFind.c_str());
}
-std::vector<Engines::Container_var> SALOME_Fake_NamingService::ListOfContainersInNS()
+std::vector< std::pair< std::string, Engines::Container_var> > SALOME_Fake_NamingService::ListOfContainersInNS_NoThreadSafe()
{
- std::lock_guard<std::mutex> g(_mutex);
- std::vector<Engines::Container_var> ret;
+ std::vector< std::pair< std::string, Engines::Container_var> > ret;
for(auto it : _map)
{
Engines::Container_var elt = Engines::Container::_narrow(it.second);
if(!CORBA::is_nil(elt))
- ret.push_back(elt);
+ ret.push_back({it.first,elt});
}
return ret;
}
-std::string SALOME_Fake_NamingService::DumpInFileIORS()
+std::string SALOME_Fake_NamingService::ReprOfContainersIORS_NoThreadSafe()
{
- std::vector<Engines::Container_var> conts( ListOfContainersInNS() );
+ std::vector< std::pair< std::string, Engines::Container_var> > conts( ListOfContainersInNS_NoThreadSafe() );
std::ostringstream oss;
CORBA::ORB_ptr orb = KERNEL::getORB();
- char SEP[2] = { '\0', '\0'};
+ char SEP[2] = { '\0', '\0' };
+ constexpr char SEP2[] = " : ";
for(auto it : conts)
{
- CORBA::String_var ior(orb->object_to_string(it));
- oss << SEP << ior;
+ CORBA::String_var ior(orb->object_to_string(it.second));
+ oss << SEP << it.first << SEP2 << ior;
SEP[0] = '\n';
}
return oss.str();
}
-void WriteContinuously(const std::string& logFileName)
+std::string SALOME_Fake_NamingService::ReprOfContainersIORS()
{
- while(true)
- {
- std::chrono::milliseconds delta( 2000 );
- std::this_thread::sleep_for( delta );
- std::string content(SALOME_Fake_NamingService::DumpInFileIORS());
- {
- std::ofstream ofs(logFileName);
- ofs.write(content.c_str(),content.length());
- }
- }
+ std::lock_guard<std::mutex> g(_mutex);
+ return ReprOfContainersIORS_NoThreadSafe();
}
-void SALOME_Fake_NamingService::LaunchLogContainersFile(const std::string& logFileName)
+std::string SALOME_Fake_NamingService::GetLogContainersFile()
{
- if(_log_container_file_thread_launched)
- THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::LaunchLogContainersFile : Thread lready launched !");
- _log_container_file_name = logFileName;
- std::thread t(WriteContinuously,logFileName);
- t.detach();
+ return _log_container_file_name;
}
-std::string SALOME_Fake_NamingService::GetLogContainersFile()
+void SALOME_Fake_NamingService::FlushLogContainersFile()
{
- return _log_container_file_name;
+ std::lock_guard<std::mutex> g(_mutex);
+ FlushLogContainersFile_NoThreadSafe();
+}
+
+void SALOME_Fake_NamingService::FlushLogContainersFile_NoThreadSafe()
+{
+ if(!_log_container_file_name.empty())
+ {
+ std::string content( ReprOfContainersIORS_NoThreadSafe() );
+ std::ofstream ofs(_log_container_file_name);
+ ofs.write(content.c_str(),content.length());
+ }
+}
+
+void SALOME_Fake_NamingService::SetLogContainersFile(const std::string& logFileName)
+{
+ if(logFileName.empty())
+ THROW_SALOME_EXCEPTION("SALOME_Fake_NamingService::SetLogContainersFile : empty log name !");
+ constexpr char EXPT_CONTENT[] = "SALOME_Fake_NamingService::SetLogContainersFile : input logFileName write access failed ! no log file set !";
+ {
+ std::ofstream ofs(logFileName);
+ if(!ofs)
+ THROW_SALOME_EXCEPTION(EXPT_CONTENT);
+ }
+ _log_container_file_name = logFileName;
}
#include "SALOME_NamingService_Abstract.hxx"
#include <mutex>
+#include <utility>
#include <string>
#include <map>
public:
SALOME_Fake_NamingService(CORBA::ORB_ptr orb);
SALOME_Fake_NamingService() = default;
- static void LaunchLogContainersFile(const std::string& logFileName);
+ static void SetLogContainersFile(const std::string& logFileName);
static std::string GetLogContainersFile();
+ static void FlushLogContainersFile();
std::vector< std::string > repr() override;
void init_orb(CORBA::ORB_ptr orb=0) override;
void Register(CORBA::Object_ptr ObjRef, const char* Path) override;
std::vector<std::string> list_directory_recurs() override;
SALOME_NamingService_Abstract *clone() override;
CORBA::Object_ptr ResolveComponent(const char* hostname, const char* containerName, const char* componentName, const int nbproc=0) override;
- static std::string DumpInFileIORS();
private:
- static std::vector<Engines::Container_var> ListOfContainersInNS();
+ static std::string ReprOfContainersIORS_NoThreadSafe();
+ static std::string ReprOfContainersIORS();
+ static std::vector< std::pair< std::string, Engines::Container_var> > ListOfContainersInNS_NoThreadSafe();
+ static void FlushLogContainersFile_NoThreadSafe();
private:
static std::mutex _mutex;
static std::map<std::string,CORBA::Object_var> _map;