SALOME_TestModuleCatalog.idl
SALOME_CommonTypes.idl
SALOME_ExternalServerLauncher.idl
+ SALOME_LogManager.idl
SALOME_Embedded_NamingService.idl
${CMAKE_CURRENT_BINARY_DIR}/Calcium_Ports.idl
)
--- /dev/null
+// Copyright (C) 2024 CEA, EDF
+//
+// 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
+//
+
+#ifndef __SALOME_LOGMANAGER_IDL__
+#define __SALOME_LOGMANAGER_IDL__
+
+#include "SALOME_Exception.idl"
+#include "SALOME_Comm.idl"
+
+module Engines
+{
+ interface ContainerScriptExecPerfLog
+ {
+ void assign(in SALOME::vectorOfByte value);
+ };
+
+ typedef sequence<ContainerScriptExecPerfLog> ListOfContainerScriptExecPerfLog;
+
+ interface ContainerScriptPerfLog
+ {
+ string getCode();
+ string getName();
+ ContainerScriptExecPerfLog addExecutionSession();
+ ListOfContainerScriptExecPerfLog listOfExecs();
+ };
+
+ typedef sequence<ContainerScriptPerfLog> ListOfContainerScriptPerfLog;
+
+ interface ContainerPerfLog
+ {
+ string getLogFile();
+ string getContainerEntryInNS();
+ ContainerScriptPerfLog addScript(in string name, in string code);
+ ListOfContainerScriptPerfLog listOfScripts();
+ };
+
+ typedef sequence<ContainerPerfLog> ListOfContainerPerfLog;
+
+ interface LogManager
+ {
+ ContainerPerfLog declareContainer(in string contInNS, in string logfile);
+ ListOfContainerPerfLog listOfContainerLogs();
+ SALOME::vectorOfByte getAllInfo();
+ };
+};
+
+#endif
_remove_ref();
_containerName = SALOME_NamingService_Abstract::BuildContainerNameForNS(containerName, hostname.c_str());
- SCRUTE(_containerName);
- _NS->Register(pCont, _containerName.c_str());
- MESSAGE("Engines_Container_i::Engines_Container_i : Container name " << _containerName);
// Python:
// import SALOME_Container
//PyThreadState_Swap(NULL);
//PyEval_ReleaseLock();
}
-
+ {// register to NS after python initialization to be sure that client invoke after py constructor execution
+ SCRUTE(_containerName);
+ _NS->Register(pCont, _containerName.c_str());
+ MESSAGE("Engines_Container_i::Engines_Container_i : Container name " << _containerName);
+ }
fileTransfer_i* aFileTransfer = new fileTransfer_i();
CORBA::Object_var obref=aFileTransfer->_this();
_fileTransfer = Engines::fileTransfer::_narrow(obref);
void Abstract_Engines_Container_i::locallogfilename(const char *name)
{
+ AutoGIL gstate;
_localfilename = name;
+ PyObject *result = PyObject_CallMethod(_pyCont,(char*)"setLogFileName","s",name,nullptr);
+ if (PyErr_Occurred())
+ {
+ std::string error("can not set logfilename");
+ PyErr_Print();
+ THROW_SALOME_CORBA_EXCEPTION(error.c_str(),SALOME::INTERNAL_ERROR);
+ }
}
CORBA::Long Abstract_Engines_Container_i::monitoringtimeresms()
from SALOME_NamingServicePy import *
from SALOME_ComponentPy import *
import SALOME_PyNode
+import logging
from SALOME_utilities import *
from Utils_Identity import getShortHostName
-from launchConfigureParser import verbose
+from salome_utils import verbose
from KernelBasis import VerbosityActivated
from SALOME_ContainerHelper import ScriptInfo
self._orb = CORBA.ORB_init(argv, CORBA.ORB_ID)
self._poa = self._orb.resolve_initial_references("RootPOA")
self._containerName = containerName
+ self._logFileName = None
self._dbg_info = []
self._timeIntervalInMs = dftTimeIntervalInMs
+ self._logm = None
+ self._log = None
+ # let verbose here because SALOME_Container_i is instanciated before the container process verbosity mecanism is initialized
if verbose(): print("SALOME_Container.SALOME_Container_i : _containerName ",self._containerName)
self._container = self._orb.string_to_object(containerIORStr)
+ @property
+ def logm(self):
+ import salome
+ if self._logm is None:
+ salome.salome_init()
+ self._logm = salome.logm
+ return self._logm
+
#-------------------------------------------------------------------------
def import_component(self, componentName):
MESSAGE( "SALOME_Container_i::import_component" )
ret=""
try:
- if verbose(): print("try import ",componentName)
+ logging.debug("try import ",componentName)
importlib.import_module(componentName)
- if verbose(): print("import ",componentName," successful")
+ logging.debug("import ",componentName," successful")
except ImportError:
#can't import python module componentName
#try to find it in python path
except ImportError as ee:
ret="ImplementationNotFound"
except Exception:
- if verbose():print("error when calling find_module")
+ print("error when calling find_module")
ret="ImplementationNotFound"
except Exception:
ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
ret=ret+traceback.format_exc(10)
- if verbose():
- traceback.print_exc()
- print("import ",componentName," not possible")
+ traceback.print_exc()
+ print("import ",componentName," not possible")
return ret
#-------------------------------------------------------------------------
def create_pyscriptnode(self,nodeName,code):
try:
self._dbg_info.append( ScriptInfo(nodeName) )
- node=SALOME_PyNode.PyScriptNode_i(nodeName,code,self._poa,self)
+ logscript = self._log.addScript(nodeName,code)
+ node=SALOME_PyNode.PyScriptNode_i(nodeName,code,self._poa,self, logscript)
node.setIDInContainer(len(self._dbg_info)-1)
self.addInfoOnLevel1(node.getIDInContainer(),"code",code)
id_o = self._poa.activate_object(node)
def monitoringtimeresms(self):
return self._timeIntervalInMs
+ def setLogFileName(self, logFileName):
+ self._log = self.logm.declareContainer( self._containerName, logFileName )
+
def SetMonitoringtimeresms(self , value):
self._timeIntervalInMs = value
class PyScriptNode_i (Engines__POA.PyScriptNode,Generic):
"""The implementation of the PyScriptNode CORBA IDL that executes a script"""
- def __init__(self, nodeName,code,poa,my_container):
+ def __init__(self, nodeName,code,poa,my_container,logscript):
"""Initialize the node : compilation in the local context"""
Generic.__init__(self,poa)
self.nodeName=nodeName
self.context[MY_CONTAINER_ENTRY_IN_GLBS] = self.my_container
self._pos = None
self._current_exec = 0
+ self._log_script = logscript
+ self._current_execution_session = None
sys.stdout.flush() ; sys.stderr.flush() # flush to correctly capture log per execution session
#start of non remote callable methods
""" Same than first part of self.execute to reduce memory peak."""
try:
#self.my_container_py.addInfoOnLevel2(self.getIDInContainer(),self._current_exec,"tracePosStart",)
+ self._current_execution_session = self._log_script.addExecutionSession()
data = None
self.my_container_py.addTimeInfoOnLevel2(self.getIDInContainer(),self._current_exec,"startInputTime")
if True: # to force call of SeqByteReceiver's destructor
# sys.setdlopenflags(flags)
# pass
-orb, lcc, naming_service, cm, sg, esm, dsm, modulcat, rm = None,None,None,None,None,None,None,None,None
+orb, lcc, naming_service, cm, sg, esm, dsm, logm, modulcat, rm = None,None,None,None,None,None,None,None,None,None
myStudy, myStudyName = None,None
salome_initial=True
A Fake NamingService is created storing reference of all servants in the current process.
"""
salome_init_without_session_common(path,embedded)
- global lcc,cm,dsm,esm,rm
+ global lcc,cm,dsm,esm,rm,logm
import KernelLauncher
cm = KernelLauncher.myContainerManager()
type(cm).SetOverrideEnvForContainersSimple = ContainerManagerSetOverrideEnvForContainersSimple
# esm inherits from SALOME_CPythonHelper singleton already initialized by GetDSMInstance
# esm inherits also from SALOME_ResourcesManager creation/initialization (concerning SingleThreadPOA POA) when KernelLauncher.GetContainerManager() has been called
esm = KernelLauncher.GetExternalServer()
+ # idem for logm
+ logm = KernelLauncher.myLogManager()
#
import KernelLogger
naming_service.Register(KernelLogger.myLogger(),"/Logger")
lcc is pointing to the FakeNamingService above.
"""
salome_init_without_session_common(path,embedded)
- global lcc,cm,dsm,esm,rm
+ global lcc,cm,dsm,esm,rm,logm
import CORBA
orb=CORBA.ORB_init([''])
import Engines
ESM_NAME_IN_NS = "/ExternalServers"
esm = orb.string_to_object( nsAbroad.Resolve(ESM_NAME_IN_NS).decode() )
naming_service.Register(esm,ESM_NAME_IN_NS)
+ #
+ LOGM_NAME_IN_NS = "/LogManager"
+ logm = orb.string_to_object( nsAbroad.Resolve(LOGM_NAME_IN_NS).decode() )
+ naming_service.Register(logm,LOGM_NAME_IN_NS)
def salome_init_with_session(path=None, embedded=False):
"""
TARGET_LINK_LIBRARIES(TestLauncher ${TestLauncher_LIBS})
INSTALL(TARGETS TestLauncher DESTINATION ${SALOME_INSTALL_BINS})
-ADD_LIBRARY(SalomeLauncher BatchTest.cxx SALOME_Launcher.cxx SALOME_ExternalServerLauncher.cxx SALOME_LauncherException.cxx SALOME_ExternalServerHandler.cxx)
+ADD_LIBRARY(SalomeLauncher BatchTest.cxx SALOME_Launcher.cxx SALOME_ExternalServerLauncher.cxx SALOME_LauncherException.cxx SALOME_ExternalServerHandler.cxx SALOME_LogManager.cxx)
TARGET_LINK_LIBRARIES(SalomeLauncher Launcher ${COMMON_LIBS})
INSTALL(TARGETS SalomeLauncher EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
Launcher_Job_SALOME.hxx
Launcher_Job_YACSFile.hxx
Launcher_Utils.hxx
+ SALOME_LogManager.hxx
SALOME_Launcher.hxx
SALOME_Launcher_Parser.hxx
SALOME_Launcher_defs.hxx
#include "SALOME_KernelServices.hxx"
#include "SALOME_ResourcesManager.hxx"
#include "SALOME_ExternalServerLauncher.hxx"
+#include "SALOME_LogManager.hxx"
#include "SALOME_CPythonHelper.hxx"
#include <cstring>
CORBA::String_var ior = orb->object_to_string(esmCPtr);
return std::string(ior.in());
}
+
+std::string GetLogManagerInstance()
+{
+ CORBA::ORB_ptr orb = KERNEL::getORB();
+ CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
+ PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
+ //
+ PortableServer::POA_var safePOA = root_poa->find_POA("SingleThreadPOA",true);
+ //
+ SALOME_CPythonHelper *cPyh(SALOME_CPythonHelper::Singleton());
+ SALOME_Fake_NamingService *ns = new SALOME_Fake_NamingService;
+ SALOME_LogManager *esm(new SALOME_LogManager(cPyh,orb,safePOA,ns));
+ esm->_remove_ref();
+ //
+ CORBA::Object_var esmPtr = safePOA->servant_to_reference(esm);
+ Engines::LogManager_var esmCPtr = Engines::LogManager::_narrow(esmPtr);
+ //
+ CORBA::String_var ior = orb->object_to_string(esmCPtr);
+ return std::string(ior.in());
+}
std::string GetContainerManagerInstance();
std::string GetResourcesManagerInstance();
std::string GetExternalServerInstance();
+std::string GetLogManagerInstance();
\ No newline at end of file
std::string GetContainerManagerInstance();
std::string GetResourcesManagerInstance();
std::string GetExternalServerInstance();
+ std::string GetLogManagerInstance();
}
%pythoncode %{
import CORBA
orb=CORBA.ORB_init([''])
return orb.string_to_object(GetExternalServerInstance())
+
+def myLogManager():
+ import Engines
+ import CORBA
+ orb=CORBA.ORB_init([''])
+ return orb.string_to_object(GetLogManagerInstance())
%}
--- /dev/null
+// Copyright (C) 2024 CEA, EDF
+//
+// 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_LogManager.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+#include "SALOME_ContainerManager.hxx"
+#include "SALOME_CPythonHelper.hxx"
+
+#ifndef WIN32
+#include <unistd.h>
+#else
+#include <windows.h>
+#include <Basics_Utils.hxx>
+#endif
+
+#include <sstream>
+#include <fstream>
+#include <algorithm>
+#include <memory>
+#include <functional>
+
+const char SALOME_LogManager::NAME_IN_NS[]="/LogManager";
+
+PortableServer::POA_var SALOME_ContainerScriptExecPerfLog::getPOA()
+{
+ return father()->getPOA();
+}
+
+void SALOME_ContainerScriptExecPerfLog::assign(const SALOME::vectorOfByte& value)
+{
+
+}
+
+/////
+
+PortableServer::POA_var SALOME_ContainerScriptPerfLog::getPOA()
+{
+ return father()->getPOA();
+}
+
+char *SALOME_ContainerScriptPerfLog::getCode()
+{
+ return CORBA::string_dup( _code.c_str() );
+}
+
+char *SALOME_ContainerScriptPerfLog::getName()
+{
+ return CORBA::string_dup( _name.c_str() );
+}
+
+Engines::ContainerScriptExecPerfLog_ptr SALOME_ContainerScriptPerfLog::addExecutionSession()
+{
+ SALOME_ContainerScriptExecPerfLog *execution = new SALOME_ContainerScriptExecPerfLog(this);
+ PortableServer::ObjectId_var id(getPOA()->activate_object(execution));
+ execution->_remove_ref();
+ CORBA::Object_var executionPtr(getPOA()->id_to_reference(id));
+ Engines::ContainerScriptExecPerfLog_var executionPtr2 = Engines::ContainerScriptExecPerfLog::_narrow(executionPtr);
+ _sessions.push_back( executionPtr2 );
+ return executionPtr2;
+}
+
+Engines::ListOfContainerScriptExecPerfLog *SALOME_ContainerScriptPerfLog::listOfExecs()
+{
+
+}
+
+/////
+
+PortableServer::POA_var SALOME_ContainerPerfLog::getPOA()
+{
+ return father()->getPOA();
+ }
+
+Engines::ContainerScriptPerfLog_ptr SALOME_ContainerPerfLog::addScript(const char *name, const char *code)
+{
+ SALOME_ContainerScriptPerfLog *script = new SALOME_ContainerScriptPerfLog(this,name,code);
+ PortableServer::ObjectId_var id(getPOA()->activate_object(script));
+ script->_remove_ref();
+ CORBA::Object_var scriptPtr(getPOA()->id_to_reference(id));
+ Engines::ContainerScriptPerfLog_var scriptPtr2 = Engines::ContainerScriptPerfLog::_narrow(scriptPtr);
+ _scripts.push_back( scriptPtr2 );
+ return scriptPtr2;
+}
+
+Engines::ListOfContainerScriptPerfLog *SALOME_ContainerPerfLog::listOfScripts()
+{
+ Engines::ListOfContainerScriptPerfLog_var ret = new Engines::ListOfContainerScriptPerfLog;
+ std::size_t len( this->_scripts.size() );
+ ret->length( len );
+ for(std::size_t i = 0 ; i < len ; ++i)
+ ret[i] = this->_scripts[i];
+ return ret._retn();
+}
+
+char *SALOME_ContainerPerfLog::getLogFile()
+{
+ return CORBA::string_dup( this->_log_file.c_str() );
+}
+
+char *SALOME_ContainerPerfLog::getContainerEntryInNS()
+{
+ return CORBA::string_dup( this->_name_in_ns.c_str() );
+}
+
+/////
+
+SALOME_LogManager::SALOME_LogManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa,SALOME_NamingService_Abstract *ns):_pyHelper(pyHelper),_poa(poa)
+{
+ _NS.reset(ns);
+ PortableServer::ObjectId_var id(_poa->activate_object(this));
+ CORBA::Object_var obj(_poa->id_to_reference(id));
+ Engines::LogManager_var refPtr(Engines::LogManager::_narrow(obj));
+ _NS->Register(refPtr,NAME_IN_NS);
+}
+
+SALOME::vectorOfByte *SALOME_LogManager::getAllInfo()
+{
+ auto length = 2;
+ SALOME::vectorOfByte *ret = new SALOME::vectorOfByte;
+ ret->length(length);
+ for(auto i = 0 ; i < length ; ++i)
+ (*ret)[i] = 1;
+ return ret;
+}
+
+Engines::ContainerPerfLog_ptr SALOME_LogManager::declareContainer(const char *contInNS, const char *logfile)
+{
+ SALOME_ContainerPerfLog *cont = new SALOME_ContainerPerfLog(this,contInNS,logfile);
+ PortableServer::ObjectId_var id(_poa->activate_object(cont));
+ CORBA::Object_var contPtr(_poa->id_to_reference(id));
+ cont->_remove_ref();
+ Engines::ContainerPerfLog_var contPtr2 = Engines::ContainerPerfLog::_narrow(contPtr);
+ _containers.push_back( contPtr2 );
+ return contPtr2;
+}
+
+Engines::ListOfContainerPerfLog *SALOME_LogManager::listOfContainerLogs()
+{
+ Engines::ListOfContainerPerfLog_var ret = new Engines::ListOfContainerPerfLog;
+ std::size_t len( this->_containers.size() );
+ ret->length( len );
+ for(std::size_t i = 0 ; i < len ; ++i)
+ ret[i] = this->_containers[i];
+ return ret._retn();
+}
--- /dev/null
+// Copyright (C) 2024 CEA, EDF
+//
+// 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
+//
+
+#pragma once
+
+#include "SALOME_Launcher_defs.hxx"
+
+#include <SALOMEconfig.h>
+
+#include CORBA_SERVER_HEADER(SALOME_LogManager)
+
+#include <vector>
+#include <string>
+#include <memory>
+
+class SALOME_NamingService_Abstract;
+class SALOME_CPythonHelper;
+class SALOME_LogManager;
+class SALOME_ContainerPerfLog;
+class SALOME_ContainerScriptPerfLog;
+
+class SALOMELAUNCHER_EXPORT SALOME_ContainerScriptExecPerfLog : public POA_Engines::ContainerScriptExecPerfLog
+{
+public:
+ SALOME_ContainerScriptExecPerfLog(SALOME_ContainerScriptPerfLog *father):_father(father) { }
+ SALOME_ContainerScriptPerfLog *father() const { return _father; }
+ PortableServer::POA_var getPOA();
+ void assign(const SALOME::vectorOfByte& value) override;
+private:
+ SALOME_ContainerScriptPerfLog *_father = nullptr;
+};
+
+class SALOMELAUNCHER_EXPORT SALOME_ContainerScriptPerfLog : public POA_Engines::ContainerScriptPerfLog
+{
+public:
+ SALOME_ContainerScriptPerfLog(SALOME_ContainerPerfLog *father, const std::string& name, const std::string& code):_father(father),_name(name),_code(code) { }
+ SALOME_ContainerPerfLog *father() const { return _father; }
+ PortableServer::POA_var getPOA();
+ Engines::ContainerScriptExecPerfLog_ptr addExecutionSession() override;
+ Engines::ListOfContainerScriptExecPerfLog *listOfExecs() override;
+ char *getCode() override;
+ char *getName() override;
+private:
+ SALOME_ContainerPerfLog *_father = nullptr;
+ std::string _name;
+ std::string _code;
+ std::vector< Engines::ContainerScriptExecPerfLog_var > _sessions;
+};
+
+class SALOMELAUNCHER_EXPORT SALOME_ContainerPerfLog : public POA_Engines::ContainerPerfLog
+{
+public:
+ SALOME_ContainerPerfLog(SALOME_LogManager *father, const std::string& nameInNS, const std::string& logFile):_father(father),_name_in_ns(nameInNS),_log_file(logFile) { }
+ SALOME_LogManager *father() const { return _father; }
+ PortableServer::POA_var getPOA();
+ char *getLogFile() override;
+ char *getContainerEntryInNS() override;
+ Engines::ContainerScriptPerfLog_ptr addScript(const char *name, const char *code) override;
+ Engines::ListOfContainerScriptPerfLog *listOfScripts() override;
+private:
+ SALOME_LogManager *_father = nullptr;
+ std::string _name_in_ns;
+ std::string _log_file;
+ std::vector< Engines::ContainerScriptPerfLog_var > _scripts;
+};
+
+class SALOMELAUNCHER_EXPORT SALOME_LogManager : public POA_Engines::LogManager
+{
+ public:
+ SALOME_LogManager(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns = nullptr);
+ PortableServer::POA_var getPOA() { return _poa; }
+ virtual ~SALOME_LogManager() = default;
+ SALOME::vectorOfByte *getAllInfo() override;
+ Engines::ContainerPerfLog_ptr declareContainer(const char *contInNS, const char *logfile) override;
+ Engines::ListOfContainerPerfLog *listOfContainerLogs() override;
+ public:
+ const SALOME_CPythonHelper *getPyHelper() const { return _pyHelper; }
+ private:
+ const SALOME_CPythonHelper *_pyHelper = nullptr;
+ std::unique_ptr<SALOME_NamingService_Abstract> _NS;
+ PortableServer::POA_var _poa;
+ std::vector<Engines::ContainerPerfLog_var> _containers;
+ public:
+ static const char NAME_IN_NS[];
+};