From 5c88082d02b90b056c0a647f9262305b19f08574 Mon Sep 17 00:00:00 2001 From: prascle Date: Sun, 9 Oct 2005 16:23:28 +0000 Subject: [PATCH] PR : Unit Testing - LifeCycleCORBA - in progress --- bin/launchConfigureParser.py | 6 +- bin/runSalome.py | 82 +- src/Container/SALOME_ContainerManager.cxx | 1 - src/Container/SALOME_ContainerManager.hxx | 2 + src/LifeCycleCORBA/Makefile.in | 2 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 34 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx | 2 + .../Test/LifeCycleCORBATest.cxx | 490 ++++++++++ .../Test/LifeCycleCORBATest.hxx | 54 ++ src/LifeCycleCORBA/Test/Makefile.in | 66 ++ .../Test/TestLifeCycleCORBA.cxx | 18 + src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py | 67 ++ ...CycleCORBA.cxx => Test_LifeCycleCORBA.cxx} | 0 src/Logger/Test/TestKiller.py | 3 +- src/Makefile.in | 1 + src/ModuleCatalog/Makefile.in | 6 +- .../SALOME_ModuleCatalog_impl.cxx | 29 +- .../SALOME_ModuleCatalog_impl.hxx | 1 - .../SALOME_LoadRateManager.cxx | 8 +- .../SALOME_LoadRateManager.hxx | 9 +- .../SALOME_ResourcesCatalog_Handler.cxx | 393 ++++---- .../SALOME_ResourcesCatalog_Handler.hxx | 225 ++--- .../SALOME_ResourcesCatalog_Parser.cxx | 160 ++-- .../SALOME_ResourcesCatalog_Parser.hxx | 122 ++- .../SALOME_ResourcesManager.cxx | 847 ++++++++++++------ .../SALOME_ResourcesManager.hxx | 125 +-- .../Test/SALOMELocalTraceTest.cxx | 5 +- .../Test/SALOMELocalTraceTest.hxx | 1 - .../Test/TestSALOMELocalTrace.cxx | 4 + .../Test/SALOMETraceCollectorTest.cxx | 4 - .../Test/TestSALOMETraceCollector.cxx | 5 + src/UnitTests/Makefile.in | 6 +- src/UnitTests/UnitTests.cxx | 8 + src/UnitTests/UnitTests.py | 38 + src/Utils/Test/TestUtils.cxx | 6 + src/Utils/Test/UtilsTest.cxx | 6 +- src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx | 6 +- src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx | 4 +- src/Utils/Utils_ORB_INIT.cxx | 4 +- 39 files changed, 1990 insertions(+), 860 deletions(-) create mode 100644 src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx create mode 100644 src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx create mode 100644 src/LifeCycleCORBA/Test/Makefile.in create mode 100644 src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx create mode 100644 src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py rename src/LifeCycleCORBA/{TestLifeCycleCORBA.cxx => Test_LifeCycleCORBA.cxx} (100%) diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index a9e39c1fe..1f754194e 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -234,7 +234,7 @@ def options_parser(line): list = [] pass - print "source=",source + #print "source=",source result = {} i = 0 @@ -264,7 +264,7 @@ def options_parser(line): try: opts = options_parser(sys.argv[1:]) - print "opts=",opts + #print "opts=",opts kernel_root_dir=os.environ["KERNEL_ROOT_DIR"] except: opts["h"] = 1 @@ -347,4 +347,4 @@ if 't' in opts: args[gui_nam] = 0 pass -print "args=",args +#print "args=",args diff --git a/bin/runSalome.py b/bin/runSalome.py index 96070b5b3..5a0917b8f 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -129,26 +129,14 @@ def set_env(args, modules_list, modules_root_dir): os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) - # special path for logger lib if needeed + # set trace environment variable - os.environ["SALOME_trace"]="local" + if not os.environ.has_key("SALOME_trace"): + os.environ["SALOME_trace"]="local" if args['file']: os.environ["SALOME_trace"]="file:"+args['file'][0] if args['logger']: os.environ["SALOME_trace"]="with_logger" - locdir=os.environ['PWD'] - libtracedir=os.path.join(locdir,"libSalomeTrace") - libtrace = os.path.join(modules_root_dir["KERNEL"],"lib", - salome_subdir, - "libSALOMELoggerClient.so.0.0.0") - libtraceln = os.path.join(libtracedir,"libSALOMELocalTrace.so") - aCommand = 'rm -rf ' + libtracedir + "; " - aCommand += 'mkdir ' + libtracedir + "; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + "; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0.0.0; " - os.system(aCommand) - add_path(libtracedir, "LD_LIBRARY_PATH") # set environment for SMESH plugins @@ -185,6 +173,23 @@ def set_env(args, modules_list, modules_root_dir): os.environ["ENABLE_MACRO_NODE"]="1" + os.environ["CSF_PluginDefaults"] \ + = os.path.join(modules_root_dir["KERNEL"],"share", + salome_subdir,"resources") + os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["KERNEL"],"share", + salome_subdir,"resources") + + if "GEOM" in modules_list: + print "GEOM OCAF Resources" + os.environ["CSF_GEOMDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources") + print "GEOM Shape Healing Resources" + os.environ["CSF_ShHealingDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources") + # ----------------------------------------------------------------------------- from killSalome import killAllPorts @@ -274,7 +279,7 @@ class InterpServer(Server): def run(self): global process_id command = self.CMD - print "command = ", command + #print "command = ", command pid = os.spawnvp(os.P_NOWAIT, command[0], command) process_id[pid]=self.CMD @@ -297,7 +302,7 @@ class CatalogServer(Server): for module in ["KERNEL", "GUI"] + list_modules: module_root_dir=modules_root_dir[module] module_cata=module+"Catalog.xml" - print " ", module_cata + #print " ", module_cata cata_path.extend( glob.glob(os.path.join(module_root_dir, "share",salome_subdir, @@ -354,26 +359,6 @@ class LoggerServer(Server): # --- -# class SessionLoader(Server): -# def __init__(self,args): -# self.args=args -# self.initArgs() -# self.CMD=['SALOME_Session_Loader'] -# if "cppContainer" in self.args['standalone'] \ -# or "cppContainer" in self.args['embedded']: -# self.CMD=self.CMD+['CPP'] -# if "pyContainer" in self.args['standalone'] \ -# or "pyContainer" in self.args['embedded']: -# self.CMD=self.CMD+['PY'] -# if "supervContainer" in self.args['containers'] \ -# or "supervContainer" in self.args['standalone']: -# self.CMD=self.CMD+['SUPERV'] -# if self.args['gui']: -# self.CMD=self.CMD+['GUI'] -# print self.CMD - -# --- - class SessionServer(Server): def __init__(self,args): self.args=args @@ -414,7 +399,7 @@ class SessionServer(Server): for module in ["KERNEL", "GUI"] + list_modules: module_root_dir=modules_root_dir[module] module_cata=module+"Catalog.xml" - print " ", module_cata + #print " ", module_cata cata_path.extend( glob.glob(os.path.join(module_root_dir,"share", salome_subdir,"resources", @@ -451,7 +436,7 @@ class ContainerManagerServer(Server): for module in ["KERNEL", "GUI"] + list_modules: module_root_dir=modules_root_dir[module] module_cata=module+"Catalog.xml" - print " ", module_cata + #print " ", module_cata cata_path.extend( glob.glob(os.path.join(module_root_dir,"share", self.args['appname'],"resources", @@ -544,24 +529,7 @@ def startSalome(args, modules_list, modules_root_dir): # attente de la disponibilite du SalomeDS dans le Naming Service # - os.environ["CSF_PluginDefaults"] \ - = os.path.join(modules_root_dir["KERNEL"],"share", - salome_subdir,"resources") - os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ - = os.path.join(modules_root_dir["KERNEL"],"share", - salome_subdir,"resources") - - if "GEOM" in modules_list: - print "GEOM OCAF Resources" - os.environ["CSF_GEOMDS_ResourcesDefaults"] \ - = os.path.join(modules_root_dir["GEOM"],"share", - salome_subdir,"resources") - print "GEOM Shape Healing Resources" - os.environ["CSF_ShHealingDefaults"] \ - = os.path.join(modules_root_dir["GEOM"],"share", - salome_subdir,"resources") - - print "ARGS = ",args + #print "ARGS = ",args if 'study' not in args['embedded']: print "RunStudy" myServer=SalomeDSServer(args) diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index e9caaf315..d25196395 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -201,7 +201,6 @@ GetFittingResources(const Engines::MachineParameters& params, catch(const SALOME_Exception &ex) { INFOS("Caught exception."); - cerr << ex.what() < Local container + // containerName doesn't contain "/" => Local container params->container_name=CORBA::string_dup(stContainer); params->hostname=CORBA::string_dup(GetHostname().c_str()); } @@ -271,6 +272,7 @@ bool SALOME_LifeCycleCORBA::isKnownComponentClass(const char *componentName) CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog"); SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ; + ASSERT(! CORBA::is_nil(Catalog)); SALOME_ModuleCatalog::Acomponent_ptr compoInfo = Catalog->GetComponent(componentName); if (CORBA::is_nil (compoInfo)) @@ -307,6 +309,34 @@ SALOME_LifeCycleCORBA::isMpiContainer(const Engines::MachineParameters& params) return false; } + +//============================================================================= +/*! Public - + * Pre initialisation of a given Engines::MachineParameters with default + * values. + * - container_name = "" : not relevant + * - hostname = "" : not relevant + * - OS = "" : not relevant + * - mem_mb = 0 : not relevant + * - cpu_clock = 0 : not relevant + * - nb_proc_per_node = 0 : not relevant + * - nb_node = 0 : not relevant + * - isMPI = false : standard components + */ +//============================================================================= + +void SALOME_LifeCycleCORBA::preSet( Engines::MachineParameters& params) +{ + params.container_name = ""; + params.hostname = ""; + params.OS = ""; + params.mem_mb = 0; + params.cpu_clock = 0; + params.nb_proc_per_node = 0; + params.nb_node = 0; + params.isMPI = false; +} + //============================================================================= /*! Public - * \return a number of processors not 0, only for MPI containers diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx index 8ed343c3c..dea15255f 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.hxx @@ -96,6 +96,8 @@ public: int NbProc(const Engines::MachineParameters& params); + void preSet(Engines::MachineParameters& params); + protected: /*! Establish if a component called "componentName" in a container called diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx new file mode 100644 index 000000000..d8b20edf7 --- /dev/null +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.cxx @@ -0,0 +1,490 @@ + +#include "LifeCycleCORBATest.hxx" +#include "SALOME_LifeCycleCORBA.hxx" +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "OpUtil.hxx" + +#include +#include +#include +#include + +using namespace std; + +// --- uncomment to have some traces on standard error +// (useful only when adding new tests...) +//#define _DEVDEBUG_ + +#ifdef _DEVDEBUG_ +#define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";} +#define DEVTRACE(msg) {MYDEVTRACE; std::cerr<deleteInstance(bp1); + + // --- trace on file + char *theFileName = TRACEFILE; + + string s = "file:"; + s += theFileName; + //s="local"; + CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite + + ofstream traceFile; + // traceFile.open(theFileName, ios::out | ios::trunc); + traceFile.open(theFileName, ios::out | ios::app); + CPPUNIT_ASSERT(traceFile); // file created empty, then closed + traceFile.close(); + + bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + + // --- Get or initialize the orb + + int _argc = 1; + char* _argv[] = {""}; + ORB_INIT &init = *SINGLETON_::Instance() ; + ASSERT(SINGLETON_::IsAlreadyExisting()); + _orb = init(_argc , _argv ) ; + + // --- Create a SALOME_NamingService instance + + _NS.init_orb(_orb) ; +} + +// ============================================================================ +/*! + * - delete trace classes + */ +// ============================================================================ + +void +LifeCycleCORBATest::tearDown() +{ + + LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance(); + CPPUNIT_ASSERT(bp1); + bp1->deleteInstance(bp1); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component. + * - get a local container (no hostname given), + * load an engine, check that the CORBA object is not null. + * - check narrow + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container, + // load an engine, check that the CORBA object is not null + + string containerName = "myContainer"; + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component. + * - Call 2 times FindOrLoad_Component with the same parameters + * - check if we get the same engine + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_SameInstance() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container, + // load an engine, check that the CORBA object is not null + + string containerName = "myContainer"; + + Engines::Component_var mycompo1 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1)); + + Engines::Component_var mycompo2 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo1); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); + + Engines::TestComponent_var m2; + m2 = Engines::TestComponent::_narrow(mycompo2); + CPPUNIT_ASSERT(!CORBA::is_nil(m2)); + + // --- check equality of instance names + + string name1 = m1->instanceName(); + string name2 = m2->instanceName(); + CPPUNIT_ASSERT_EQUAL(name1, name2); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component with Python Component on C++ Container + * load an engine, check that the CORBA object is not null. + * - check narrow + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_PythonInCppContainer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container, + // load an engine, check that the CORBA object is not null + + string containerName = "myContainer"; + + Engines::Component_var mycompo1 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo1); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component with Python Component on C++ Container + * - Call 2 times FindOrLoad_Component with the same parameters + * - check if we get the same engine + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_PythonSameInstance() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container (with a name based on local hostname), + // load an engine, check that the CORBA object is not null + + string containerName = "myContainer"; + + Engines::Component_var mycompo1 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1)); + + Engines::Component_var mycompo2 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo1); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); + + Engines::TestComponent_var m2; + m2 = Engines::TestComponent::_narrow(mycompo2); + CPPUNIT_ASSERT(!CORBA::is_nil(m2)); + + // --- check equality of instance names + + string name1 = m1->instanceName(); + string name2 = m2->instanceName(); + CPPUNIT_ASSERT_EQUAL(name1, name2); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component with a component name not in catalog. + * See list of catalog given to module catalog server. + * Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains + * only KERNEL, SalomeTestComponent and SALOME_TestComponentPy + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_UnknownInCatalog() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container (with a name based on local hostname), + // load an engine, check that the CORBA object is not null + + string containerName = "myContainer"; + + Engines::Component_var mycompo1 = + _LCC.FindOrLoad_Component(containerName.c_str(),"MyNewComponent"); + CPPUNIT_ASSERT(CORBA::is_nil(mycompo1)); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component with hostname given + * - get a local container : getHostName()/componentName, + * load an engine, check that the CORBA object is not null. + * - check narrow + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainerHostname() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container (with a name based on local hostname), + // load an engine, check that the CORBA object is not null + + string containerName = GetHostname(); + containerName += "/theContainer"; + DEVTRACE("containerName = " << containerName); + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component with and without local hostname given. + * We must get the same container, the same instance of component + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_SameContainer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- get a local container (with a name based on local hostname), + // load an engine, check that the CORBA object is not null + + string containerName = "aContainer"; + + Engines::Component_var mycompo1 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1)); + + containerName = GetHostname(); + containerName += "/aContainer"; + DEVTRACE("containerName = " << containerName); + Engines::Component_var mycompo2 = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo1); + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); + + Engines::TestComponent_var m2; + m2 = Engines::TestComponent::_narrow(mycompo2); + CPPUNIT_ASSERT(!CORBA::is_nil(m2)); + + // --- check equality of instance names + + string name1 = m1->instanceName(); + string name2 = m2->instanceName(); + CPPUNIT_ASSERT_EQUAL(name1, name2); + + // --- check containers are the same servant (same container name+hostname) + + Engines::Container_var c1 = m1->GetContainerRef(); + CPPUNIT_ASSERT(!CORBA::is_nil(c1)); + Engines::Container_var c2 = m2->GetContainerRef(); + CPPUNIT_ASSERT(!CORBA::is_nil(c1)); + string cname1 = c1->name(); + string cname2 = c2->name(); + CPPUNIT_ASSERT_EQUAL(cname1, cname2); + string hostname1 = c1->getHostName(); + string hostname2 = c2->getHostName(); + CPPUNIT_ASSERT_EQUAL(hostname1, hostname2); + CORBA::Long pidc1 = c1->getPID(); + CORBA::Long pidc2 = c2->getPID(); + CPPUNIT_ASSERT_EQUAL(pidc1, pidc2); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component: check behaviour when ask for an unknown computer + * We must catch a Salome Exception with "unknown host" message + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_UnknownMachine() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + // --- try to get a distant container on an unknown machine (not existing) + // check that the CORBA object is null + + string containerName = "aFarAwayComputer"; + containerName += "/theContainer"; +// CPPUNIT_ASSERT_THROW(Engines::Component_var mycompo = +// _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");,SALOME::SALOME_Exception); + try + { + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent"); + } + catch(const SALOME::SALOME_Exception &ex) + { + CPPUNIT_ASSERT(true); +// string expectedMessage = "BAD PARAM"; +// std::ostream os; +// os << ex; +// string actualMessage = os.str(); +// DEVTRACE("actual Exception Message = " << actualMessage); +// CPPUNIT_ASSERT(actualMessage.find(expectedMessage) != string::npos); + } +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component, empty params must give an instance + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_ParamsEmpty() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + Engines::MachineParameters params; + _LCC.preSet(params); + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(params,"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo); +} + +// ============================================================================ +/*! + * Check FindOrLoad_Component params = local container + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_ParamsLocalContainer() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + Engines::MachineParameters params; + _LCC.preSet(params); + string hostname=GetHostname(); + params.hostname=hostname.c_str(); + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(params,"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo); + + // --- check container is on local computer + + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); + Engines::Container_var c1 = m1->GetContainerRef(); + CPPUNIT_ASSERT(!CORBA::is_nil(c1)); + string hostname1 = c1->getHostName(); + CPPUNIT_ASSERT_EQUAL(hostname1, GetHostname()); +} + + +// ============================================================================ +/*! + * Check FindOrLoad_Component params = containerName + */ +// ============================================================================ + +void +LifeCycleCORBATest::testFindOrLoad_Component_ParamsContainerName() +{ + SALOME_LifeCycleCORBA _LCC(&_NS); + + Engines::MachineParameters params; + _LCC.preSet(params); + string containerName = "myContainer"; + params.container_name = containerName.c_str(); + Engines::Component_var mycompo = + _LCC.FindOrLoad_Component(params,"SalomeTestComponent"); + CPPUNIT_ASSERT(!CORBA::is_nil(mycompo)); + + // --- check narrow + + Engines::TestComponent_var m1; + m1 = Engines::TestComponent::_narrow(mycompo); + + // --- check container has good name + + CPPUNIT_ASSERT(!CORBA::is_nil(m1)); + Engines::Container_var c1 = m1->GetContainerRef(); + CPPUNIT_ASSERT(!CORBA::is_nil(c1)); + string hostname1 = c1->getHostName(); + CPPUNIT_ASSERT_EQUAL(hostname1, GetHostname()); + string cname1 = c1->name(); + CPPUNIT_ASSERT(cname1.find(containerName) != string::npos); +} + + +// ============================================================================ +/*! + * Check FindOrLoad_Component params = containerName + */ +// ============================================================================ + +// void +// LifeCycleCORBATest::testFindOrLoad_Component_() +// { +// } + diff --git a/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx new file mode 100644 index 000000000..56858599c --- /dev/null +++ b/src/LifeCycleCORBA/Test/LifeCycleCORBATest.hxx @@ -0,0 +1,54 @@ + +#ifndef _LIFECYCLECORBATEST_HXX_ +#define _LIFECYCLECORBATEST_HXX_ + +#include + +#include +#include CORBA_CLIENT_HEADER(SALOME_Component) +#include CORBA_CLIENT_HEADER(SALOME_TestComponent) +#include "SALOME_NamingService.hxx" + +class LifeCycleCORBATest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( LifeCycleCORBATest ); + CPPUNIT_TEST( testFindOrLoad_Component_LaunchContainer ); + CPPUNIT_TEST( testFindOrLoad_Component_SameInstance ); + CPPUNIT_TEST( testFindOrLoad_Component_PythonInCppContainer ); + CPPUNIT_TEST( testFindOrLoad_Component_PythonSameInstance ); + CPPUNIT_TEST( testFindOrLoad_Component_UnknownInCatalog ); + CPPUNIT_TEST( testFindOrLoad_Component_LaunchContainerHostname ); + CPPUNIT_TEST( testFindOrLoad_Component_SameContainer ); + CPPUNIT_TEST( testFindOrLoad_Component_UnknownMachine ); + CPPUNIT_TEST( testFindOrLoad_Component_ParamsEmpty ); + CPPUNIT_TEST( testFindOrLoad_Component_ParamsLocalContainer ); + CPPUNIT_TEST( testFindOrLoad_Component_ParamsContainerName ); +// CPPUNIT_TEST( testFindOrLoad_Component_ ); +// CPPUNIT_TEST( ); +// CPPUNIT_TEST( ); + CPPUNIT_TEST_SUITE_END(); + +public: + + void setUp(); + void tearDown(); + + void testFindOrLoad_Component_LaunchContainer(); + void testFindOrLoad_Component_SameInstance(); + void testFindOrLoad_Component_PythonInCppContainer(); + void testFindOrLoad_Component_PythonSameInstance(); + void testFindOrLoad_Component_UnknownInCatalog(); + void testFindOrLoad_Component_LaunchContainerHostname(); + void testFindOrLoad_Component_SameContainer(); + void testFindOrLoad_Component_UnknownMachine(); + void testFindOrLoad_Component_ParamsEmpty(); + void testFindOrLoad_Component_ParamsLocalContainer(); + void testFindOrLoad_Component_ParamsContainerName(); +// void testFindOrLoad_Component_(); + +protected: + CORBA::ORB_var _orb; + SALOME_NamingService _NS; +}; + +#endif diff --git a/src/LifeCycleCORBA/Test/Makefile.in b/src/LifeCycleCORBA/Test/Makefile.in new file mode 100644 index 000000000..425a816a1 --- /dev/null +++ b/src/LifeCycleCORBA/Test/Makefile.in @@ -0,0 +1,66 @@ +# SALOMELocalTrace : log on local machine +# +# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# 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. +# +# 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# +# +# +# File : Makefile.in +# Author : Paul RASCLE (EDF) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= LifeCycleCORBATest.hxx + +EXPORT_PYSCRIPTS = TestLifeCycleCORBA.py + +# Libraries targets + +LIB = libLifeCycleCORBATest.la +LIB_SRC = LifeCycleCORBATest.cxx +LIB_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ + SALOME_Exception.idl + +# Executables targets + +BIN = TestLifeCycleCORBA +BIN_SRC = + +LIBS= @LIBS@ +LDFLAGS+= + +LDFLAGSFORBIN+= \ + -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ + -lSALOMETraceCollectorTest \ + -lUtilsTest -lOpUtil \ + -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \ + -lRegistry -lSalomeNotification \ + -lLifeCycleCORBATest -lSalomeLifeCycleCORBA \ + -lcppunit + +@CONCLUDE@ diff --git a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx new file mode 100644 index 000000000..987e3049c --- /dev/null +++ b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.cxx @@ -0,0 +1,18 @@ + +// --- include all Unit Test from basics until the present directory + +#include "SALOMELocalTraceTest.hxx" +#include "SALOMETraceCollectorTest.hxx" +#include "UtilsTest.hxx" +#include "LifeCycleCORBATest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest ); + +// --- generic Main program from Basic/Test + +#include "BasicMainTest.hxx" diff --git a/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py new file mode 100644 index 000000000..a1c7135fe --- /dev/null +++ b/src/LifeCycleCORBA/Test/TestLifeCycleCORBA.py @@ -0,0 +1,67 @@ + +import sys, os,signal,string,commands +import runSalome +import orbmodule +import TestKiller + +# get SALOME environment : + +args, modules_list, modules_root_dir = runSalome.get_config() +runSalome.set_env(args, modules_list, modules_root_dir) + +# set environment for trace in logger +# (with file, servers may be killed before the write to the file...) + +#os.environ["SALOME_trace"] = "file:/tmp/traceUnitTest.log" +#os.environ["SALOME_trace"] = "local" +os.environ["SALOME_trace"] = "with_logger" + +# launch CORBA naming server + +clt=orbmodule.client() + +# launch CORBA logger server + +myServer=runSalome.LoggerServer(args) +myServer.run() +clt.waitLogger("Logger") + +# launch notify server + +myServer=runSalome.NotifyServer(args,modules_root_dir) +myServer.run() + +# launch registry server + +myServer=runSalome.RegistryServer(args) +myServer.run() +clt.waitNS("/Registry") + +# launch module catalog server + +cataServer=runSalome.CatalogServer(args) +cataServer.setpath(modules_list,modules_root_dir) +cataServer.run() +clt.waitNS("/Kernel/ModulCatalog") + +# launch container manager server + +myCmServer = runSalome.ContainerManagerServer(args) +myCmServer.setpath(modules_list,modules_root_dir) +myCmServer.run() +clt.waitNS("/ContainerManager") + +# execute Unit Test + +command = ['TestLifeCycleCORBA'] +ret = os.spawnvp(os.P_WAIT, command[0], command) + +# kill containers created by the Container Manager + +import Engines +containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) +containerManager.Shutdown() + +# kill Test process + +TestKiller.killProcess(runSalome.process_id) diff --git a/src/LifeCycleCORBA/TestLifeCycleCORBA.cxx b/src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx similarity index 100% rename from src/LifeCycleCORBA/TestLifeCycleCORBA.cxx rename to src/LifeCycleCORBA/Test_LifeCycleCORBA.cxx diff --git a/src/Logger/Test/TestKiller.py b/src/Logger/Test/TestKiller.py index 5e1e338b8..cda030b60 100644 --- a/src/Logger/Test/TestKiller.py +++ b/src/Logger/Test/TestKiller.py @@ -5,7 +5,7 @@ def killNamingService(): """ kills omniORB4 Naming Service on local machine. Selects process corresponding to the port used in $OMNIORB_CONFIG file. - works only with a single line $OMNIORB_CONFIG like + Works only with a single line $OMNIORB_CONFIG like InitRef = NameService=corbaname::: """ fic=os.environ['OMNIORB_CONFIG'] @@ -31,5 +31,6 @@ def killProcess(process_id): except: print " ---- process %s : %s inexistant"% (pid, cmd[0]) pass + del process_id[pid] pass killNamingService() diff --git a/src/Makefile.in b/src/Makefile.in index 5fcaae1ea..9db15f0e3 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -66,6 +66,7 @@ SUBDIRS = \ Logger/Test \ SALOMETraceCollector/Test \ Utils/Test \ + LifeCycleCORBA/Test \ UnitTests ifeq (@mpi_ok@,yes) diff --git a/src/ModuleCatalog/Makefile.in b/src/ModuleCatalog/Makefile.in index 0e4c01ce3..65f688f97 100644 --- a/src/ModuleCatalog/Makefile.in +++ b/src/ModuleCatalog/Makefile.in @@ -51,17 +51,21 @@ LIB_SRC = \ SALOME_ModuleCatalog_impl.cxx \ SALOME_ModuleCatalog_Acomponent_impl.cxx +LIB_SERVER_IDL = SALOME_ModuleCatalog.idl SALOME_Exception.idl + CXXFLAGS+=-ftemplate-depth-32 # Executables targets # trouble we have client and serveur and build don't known about this with rule # in fact client is a test ! So it may go away BIN ! + BIN = SALOME_ModuleCatalog_Server SALOME_ModuleCatalog_Client BIN_SRC = BIN_SERVER_IDL = SALOME_ModuleCatalog.idl SALOME_Exception.idl CPPFLAGS+= $(QT_MT_INCLUDES) -LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lSALOMELocalTrace -lOpUtil +LDFLAGS+= $(QT_MT_LIBS) -lSalomeNS -lSALOMELocalTrace -lOpUtil -lSALOMEBasics + LDFLAGSFORBIN+= -lSalomeNS -lSALOMELocalTrace -lOpUtil -lSALOMEBasics diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx index 0c63992f0..87e57d287 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.cxx @@ -35,10 +35,12 @@ #include using namespace std; +#include "utilities.h" + #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 1; #else -static int MYDEBUG = 0; +static int MYDEBUG = 1; #endif static const char* SEPARATOR = ":"; @@ -468,12 +470,12 @@ SALOME_ModuleCatalogImpl::GetComponent(const char* name) ParserComponent *C_parser = NULL; ParserPathPrefixes *pp = NULL; - SALOME_ModuleCatalog::Acomponent_ptr compo = NULL; - + SALOME_ModuleCatalog::Acomponent_ptr compo + = SALOME_ModuleCatalog::Acomponent::_nil(); C_parser = findComponent(s); if (C_parser) { -// DebugParserComponent(*C_parser); + // DebugParserComponent(*C_parser); SALOME_ModuleCatalog::Component C_corba; duplicate(C_corba, *C_parser); @@ -489,7 +491,6 @@ SALOME_ModuleCatalogImpl::GetComponent(const char* name) // return NULL object if(MYDEBUG) MESSAGE("Component with name " << name << " not found in catalog"); - compo = NULL; } return compo; @@ -520,13 +521,15 @@ SALOME_ModuleCatalogImpl::findComponent(const string & name) if (!C_parser) for (unsigned int ind=0; ind < _personal_module_list.size();ind++) - if (name.compare(_personal_module_list[ind].name) == 0) - { - if(MYDEBUG) MESSAGE("Component named " << name - << " found in the personal catalog"); - C_parser = &(_personal_module_list[ind]); - break; - } + { + if (name.compare(_personal_module_list[ind].name) == 0) + { + if(MYDEBUG) MESSAGE("Component named " << name + << " found in the personal catalog"); + C_parser = &(_personal_module_list[ind]); + break; + } + } if (!C_parser) for (unsigned int ind=0; ind < _general_module_list.size();ind++) diff --git a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx index b6c026901..aef5c2daf 100644 --- a/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx +++ b/src/ModuleCatalog/SALOME_ModuleCatalog_impl.hxx @@ -30,7 +30,6 @@ #ifndef MODULECATALOG_IMPL_H #define MODULECATALOG_IMPL_H -#include "utilities.h" #include #include diff --git a/src/ResourcesManager/SALOME_LoadRateManager.cxx b/src/ResourcesManager/SALOME_LoadRateManager.cxx index be27ac8e7..00166fec4 100644 --- a/src/ResourcesManager/SALOME_LoadRateManager.cxx +++ b/src/ResourcesManager/SALOME_LoadRateManager.cxx @@ -1,4 +1,5 @@ #include "SALOME_LoadRateManager.hxx" +#include "utilities.h" #include using namespace std; @@ -6,7 +7,10 @@ using namespace std; string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts) { // for the moment then "maui" will be used for dynamic selection ... - cout << "SALOME_LoadRateManager::FindBest" << endl; - if(hosts.length() == 0)return string(""); + MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length()); + + if (hosts.length() == 0) + return string(""); + return string(hosts[0]); } diff --git a/src/ResourcesManager/SALOME_LoadRateManager.hxx b/src/ResourcesManager/SALOME_LoadRateManager.hxx index ab45f35c1..1f2677748 100644 --- a/src/ResourcesManager/SALOME_LoadRateManager.hxx +++ b/src/ResourcesManager/SALOME_LoadRateManager.hxx @@ -21,9 +21,10 @@ #endif class RESOURCESMANAGER_EXPORT SALOME_LoadRateManager -{ -public: - std::string FindBest(const Engines::MachineList& hosts); -}; + { + + public: + std::string FindBest(const Engines::MachineList& hosts); + }; #endif diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index f8c5a6ef1..8ccecdb3f 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -1,23 +1,23 @@ // SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // @@ -38,27 +38,29 @@ using namespace std; //Function : SALOME_ResourcesCatalog_Handler //Purpose: Constructor //---------------------------------------------------------------------- -SALOME_ResourcesCatalog_Handler::SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources):_resources_list(listOfResources) +SALOME_ResourcesCatalog_Handler:: +SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): + _resources_list(listOfResources) { MESSAGE("SALOME_ResourcesCatalog_Handler creation"); //XML tags initialisation - test_machine="machine"; - test_resources="resources"; - - test_hostname="hostname"; - test_alias="alias"; - test_protocol="protocol"; - test_mode="mode"; - test_user_name="userName"; - test_modules="modules"; - test_module_name="moduleName"; - test_module_path="modulePath"; - test_pre_req_file_path="preReqFilePath"; - test_os="OS"; - test_mem_in_mb="memInMB"; - test_cpu_freq_mhz="CPUFreqMHz"; - test_nb_of_nodes="nbOfNodes"; - test_nb_of_proc_per_node="nbOfProcPerNode"; + test_machine = "machine"; + test_resources = "resources"; + + test_hostname = "hostname"; + test_alias = "alias"; + test_protocol = "protocol"; + test_mode = "mode"; + test_user_name = "userName"; + test_modules = "modules"; + test_module_name = "moduleName"; + test_module_path = "modulePath"; + test_pre_req_file_path = "preReqFilePath"; + test_os = "OS"; + test_mem_in_mb = "memInMB"; + test_cpu_freq_mhz = "CPUFreqMHz"; + test_nb_of_nodes = "nbOfNodes"; + test_nb_of_proc_per_node = "nbOfProcPerNode"; } //---------------------------------------------------------------------- @@ -74,14 +76,15 @@ SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler() //Function : GetResourcesAfterParsing //Purpose: Retrieves DS after the file parse. //---------------------------------------------------------------------- -const MapOfParserResourcesType& SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const -{ - return _resources_list; -} +const MapOfParserResourcesType& +SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const + { + return _resources_list; + } //---------------------------------------------------------------------- //Function : startDocument -//Purpose: overload handler function +//Purpose: overload handler function //---------------------------------------------------------------------- bool SALOME_ResourcesCatalog_Handler::startDocument() { @@ -93,83 +96,112 @@ bool SALOME_ResourcesCatalog_Handler::startDocument() //---------------------------------------------------------------------- //Function : startElement -//Purpose: overload handler function +//Purpose: overload handler function //---------------------------------------------------------------------- -bool SALOME_ResourcesCatalog_Handler::startElement(const QString&, - const QString&, - const QString& name, - const QXmlAttributes& attrs) +bool +SALOME_ResourcesCatalog_Handler:: +startElement( const QString&, + const QString&, + const QString& name, + const QXmlAttributes& attrs ) { - for(int i=0;i::iterator iter=_resources_list.begin();iter!=_resources_list.end();iter++) + + for (map::iterator iter = + _resources_list.begin(); + iter != _resources_list.end(); + iter++) { QDomElement eltRoot = doc.createElement(test_machine); root.appendChild( eltRoot ); - eltRoot.setAttribute((char *)test_hostname,(*iter).first.c_str()); - eltRoot.setAttribute((char *)test_alias,(*iter).second.Alias.c_str()); - switch((*iter).second.Protocol) - { - case rsh: - eltRoot.setAttribute((char *)test_protocol,"rsh"); - break; - case ssh: - eltRoot.setAttribute((char *)test_protocol,"ssh"); - break; - default: - eltRoot.setAttribute((char *)test_protocol,"rsh"); - } - switch((*iter).second.Mode) - { - case interactive: - eltRoot.setAttribute((char *)test_mode,"interactive"); - break; - case batch: - eltRoot.setAttribute((char *)test_mode,"batch"); - break; - default: - eltRoot.setAttribute((char *)test_mode,"interactive"); - } - eltRoot.setAttribute((char *)test_user_name,(*iter).second.UserName.c_str()); - for(map::const_iterator iter2=(*iter).second.ModulesPath.begin();iter2!=(*iter).second.ModulesPath.end();iter2++) - { - QDomElement rootForModulesPaths=doc.createElement(test_modules); - rootForModulesPaths.setAttribute(test_module_name,(*iter2).first.c_str()); - rootForModulesPaths.setAttribute(test_module_path,(*iter2).second.c_str()); - eltRoot.appendChild(rootForModulesPaths); - } - eltRoot.setAttribute(test_pre_req_file_path,(*iter).second.PreReqFilePath.c_str()); - eltRoot.setAttribute(test_os,(*iter).second.OS.c_str()); - eltRoot.setAttribute(test_mem_in_mb,(*iter).second.DataForSort._memInMB); - eltRoot.setAttribute(test_cpu_freq_mhz,(*iter).second.DataForSort._CPUFreqMHz); - eltRoot.setAttribute(test_nb_of_nodes,(*iter).second.DataForSort._nbOfNodes); - eltRoot.setAttribute(test_nb_of_proc_per_node,(*iter).second.DataForSort._nbOfProcPerNode); + eltRoot.setAttribute((char *)test_hostname, (*iter).first.c_str()); + eltRoot.setAttribute((char *)test_alias, (*iter).second.Alias.c_str()); + + switch ((*iter).second.Protocol) + { + + case rsh: + eltRoot.setAttribute((char *)test_protocol, "rsh"); + break; + + case ssh: + eltRoot.setAttribute((char *)test_protocol, "ssh"); + break; + + default: + eltRoot.setAttribute((char *)test_protocol, "rsh"); + } + + switch ((*iter).second.Mode) + { + + case interactive: + eltRoot.setAttribute((char *)test_mode, "interactive"); + break; + + case batch: + eltRoot.setAttribute((char *)test_mode, "batch"); + break; + + default: + eltRoot.setAttribute((char *)test_mode, "interactive"); + } + + eltRoot.setAttribute((char *)test_user_name, + (*iter).second.UserName.c_str()); + + for (map::const_iterator iter2 = + (*iter).second.ModulesPath.begin(); + iter2 != (*iter).second.ModulesPath.end(); + iter2++) + { + QDomElement rootForModulesPaths = doc.createElement(test_modules); + rootForModulesPaths.setAttribute(test_module_name, + (*iter2).first.c_str()); + rootForModulesPaths.setAttribute(test_module_path, + (*iter2).second.c_str()); + eltRoot.appendChild(rootForModulesPaths); + } + + eltRoot.setAttribute(test_pre_req_file_path, + (*iter).second.PreReqFilePath.c_str()); + eltRoot.setAttribute(test_os, (*iter).second.OS.c_str()); + eltRoot.setAttribute(test_mem_in_mb, + (*iter).second.DataForSort._memInMB); + eltRoot.setAttribute(test_cpu_freq_mhz, + (*iter).second.DataForSort._CPUFreqMHz); + eltRoot.setAttribute(test_nb_of_nodes, + (*iter).second.DataForSort._nbOfNodes); + eltRoot.setAttribute(test_nb_of_proc_per_node, + (*iter).second.DataForSort._nbOfProcPerNode); } } diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx index 6e9916aab..f97191e22 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx @@ -1,23 +1,23 @@ // SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // @@ -36,102 +36,105 @@ #include class QDomElement; + class QDomDocument; class SALOME_ResourcesCatalog_Handler : public QXmlDefaultHandler -{ -public : - //! standard constructor - SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources); - - const MapOfParserResourcesType& GetResourcesAfterParsing() const; - - //! standard destructor - virtual ~SALOME_ResourcesCatalog_Handler(); - - //! method to overload handler function startDocument - /*! is called before a xml file is parsed - \return true if no error was detected - */ - virtual bool startDocument(); - - //! method to overload handler function startElement - /*! - \param QString argument by value - \param QString argument by value - \param QString qName argument by value - \param QXmlAttributes atts argument by value - \return true if no error was detected - */ - virtual bool startElement(const QString& , const QString& , - const QString& name, const QXmlAttributes& attrs); - - //! method to overload handler function endElement - /*! - \param QString argument by value - \param QString argument by value - \param QString qName argument by value - \return true if no error was detected - */ - virtual bool endElement(const QString&, const QString&, - const QString& qName); - - //! method to overload handler function characters - /*! - \param QString chars argument by value - \return true if no error was detected - */ - virtual bool characters(const QString& chars); - - //! method to overload handler function endDocument - /*! is called at the end of the parsing - \return true if no error was detected - */ - virtual bool endDocument(); - - //! method to overload handler function errorProtocol - /*! - \return the error message - */ - virtual QString errorProtocol(); - -//! method to overload handler function fatalError - /*! - \param QXmlParseException exception argument by value - \return true if no error was detected - */ - virtual bool fatalError(const QXmlParseException& exception); - -//! method to fill the document to be writen in a file - void PrepareDocToXmlFile(QDomDocument& doc); - -private : - QString errorProt; - std::string content; - std::string previous_module_name; - std::string previous_module_path; - - ParserResourcesType _resource; - MapOfParserResourcesType& _resources_list; - - const char *test_machine; - const char *test_resources; - - const char *test_hostname; - const char *test_alias; - const char *test_protocol; - const char *test_mode; - const char *test_user_name; - const char *test_modules; - const char *test_module_name; - const char *test_module_path; - const char *test_pre_req_file_path; - const char *test_os; - const char *test_mem_in_mb; - const char *test_cpu_freq_mhz; - const char *test_nb_of_nodes; - const char *test_nb_of_proc_per_node; - -}; + { + + public : + //! standard constructor + SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources); + + const MapOfParserResourcesType& GetResourcesAfterParsing() const; + + //! standard destructor + virtual ~SALOME_ResourcesCatalog_Handler(); + + //! method to overload handler function startDocument + /*! is called before a xml file is parsed + \return true if no error was detected + */ + virtual bool startDocument(); + + //! method to overload handler function startElement + /*! + \param QString argument by value + \param QString argument by value + \param QString qName argument by value + \param QXmlAttributes atts argument by value + \return true if no error was detected + */ + virtual bool startElement(const QString& , const QString& , + const QString& name, + const QXmlAttributes& attrs); + + //! method to overload handler function endElement + /*! + \param QString argument by value + \param QString argument by value + \param QString qName argument by value + \return true if no error was detected + */ + virtual bool endElement(const QString&, const QString&, + const QString& qName); + + //! method to overload handler function characters + /*! + \param QString chars argument by value + \return true if no error was detected + */ + virtual bool characters(const QString& chars); + + //! method to overload handler function endDocument + /*! is called at the end of the parsing + \return true if no error was detected + */ + virtual bool endDocument(); + + //! method to overload handler function errorProtocol + /*! + \return the error message + */ + virtual QString errorProtocol(); + + //! method to overload handler function fatalError + /*! + \param QXmlParseException exception argument by value + \return true if no error was detected + */ + virtual bool fatalError(const QXmlParseException& exception); + + //! method to fill the document to be writen in a file + void PrepareDocToXmlFile(QDomDocument& doc); + + private : + QString errorProt; + std::string content; + std::string previous_module_name; + std::string previous_module_path; + + ParserResourcesType _resource; + MapOfParserResourcesType& _resources_list; + + const char *test_machine; + const char *test_resources; + + const char *test_hostname; + const char *test_alias; + const char *test_protocol; + const char *test_mode; + const char *test_user_name; + const char *test_modules; + const char *test_module_name; + const char *test_module_path; + const char *test_pre_req_file_path; + const char *test_os; + const char *test_mem_in_mb; + const char *test_cpu_freq_mhz; + const char *test_nb_of_nodes; + const char *test_nb_of_proc_per_node; + + }; #endif // SALOME_RESOURCES_CATALOG_HANDLER diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx index d6562befc..8747cb030 100644 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx @@ -1,82 +1,118 @@ #include "SALOME_ResourcesCatalog_Parser.hxx" +#include "utilities.h" #include #define NULL_VALUE 0 using namespace std; -unsigned int ResourceDataToSort::_nbOfNodesWanted=NULL_VALUE; -unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted=NULL_VALUE; -unsigned int ResourceDataToSort::_CPUFreqMHzWanted=NULL_VALUE; -unsigned int ResourceDataToSort::_memInMBWanted=NULL_VALUE; +unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE; +unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE; +unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE; +unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE; ResourceDataToSort::ResourceDataToSort() -{ -} +{} -ResourceDataToSort::ResourceDataToSort(const string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB):_hostName(hostname),_nbOfNodes(nbOfNodes),_nbOfProcPerNode(nbOfProcPerNode),_CPUFreqMHz(CPUFreqMHz),_memInMB(memInMB) -{ -} +ResourceDataToSort::ResourceDataToSort(const string& hostname, + unsigned int nbOfNodes, + unsigned int nbOfProcPerNode, + unsigned int CPUFreqMHz, + unsigned int memInMB): + _hostName(hostname), + _nbOfNodes(nbOfNodes), + _nbOfProcPerNode(nbOfProcPerNode), + _CPUFreqMHz(CPUFreqMHz), + _memInMB(memInMB) +{} //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const -{ - unsigned int nbPts=GetNumberOfPoints(); - return nbPts_nbOfNodesWanted) - ret+=2000; - else - ret+=1000; - } - //priority 2 : Nb of proc by node - if(_nbOfProcPerNodeWanted!=NULL_VALUE) - { - if(_nbOfProcPerNode==_nbOfProcPerNodeWanted) - ret+=300; - else if(_nbOfProcPerNode > _nbOfProcPerNodeWanted) - ret+=200; - else - ret+=100; - } - //priority 3 : Cpu freq - if(_CPUFreqMHzWanted!=NULL_VALUE) - { - if(_CPUFreqMHz==_CPUFreqMHzWanted) - ret+=30; - else if(_CPUFreqMHz > _CPUFreqMHzWanted) - ret+=20; - else - ret+=10; - } - //priority 4 : memory - if(_memInMBWanted!=NULL_VALUE) - { - if(_memInMB==_memInMBWanted) - ret+=3; - else if(_memInMB > _memInMBWanted) - ret+=2; - else - ret+=1; - } - return ret; -} + { + unsigned int ret = 0; + //priority 1 : Nb of nodes + + if (_nbOfNodesWanted != NULL_VALUE) + { + if (_nbOfNodes == _nbOfNodesWanted) + ret += 3000; + else if (_nbOfNodes > _nbOfNodesWanted) + ret += 2000; + else + ret += 1000; + } + + //priority 2 : Nb of proc by node + if (_nbOfProcPerNodeWanted != NULL_VALUE) + { + if (_nbOfProcPerNode == _nbOfProcPerNodeWanted) + ret += 300; + else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted) + ret += 200; + else + ret += 100; + } + + //priority 3 : Cpu freq + if (_CPUFreqMHzWanted != NULL_VALUE) + { + if (_CPUFreqMHz == _CPUFreqMHzWanted) + ret += 30; + else if (_CPUFreqMHz > _CPUFreqMHzWanted) + ret += 20; + else + ret += 10; + } + + //priority 4 : memory + if (_memInMBWanted != NULL_VALUE) + { + if (_memInMB == _memInMBWanted) + ret += 3; + else if (_memInMB > _memInMBWanted) + ret += 2; + else + ret += 1; + } + + return ret; + } //! Method used for debug void ResourceDataToSort::Print() const + { + SCRUTE(_nbOfNodes); + SCRUTE(_nbOfProcPerNode); + SCRUTE(_CPUFreqMHz); + SCRUTE(_memInMB); + } + +void ParserResourcesType::Print() { - cout << "Nb of nodes : " << _nbOfNodes << endl; - cout << "Nb of proc per node : " << _nbOfProcPerNode << endl; - cout << "CPU : " << _CPUFreqMHz << endl; - cout << "Mem : " << _memInMB << endl; -} + MESSAGE("##############*****"); + MESSAGE("HostName : " << DataForSort._hostName); + MESSAGE("Alias : " << Alias); + MESSAGE("Protocol : " << Protocol); + MESSAGE("Mode : " << Mode); + MESSAGE("UserName : " << UserName); + MESSAGE("Modules : "); + int i = 1; + + for (std::map::iterator iter = ModulesPath.begin(); + iter != ModulesPath.end(); + iter++) + { + MESSAGE("Module " << i++ << " called : " << (*iter).first + << " with path : " << (*iter).second); + } + MESSAGE("PreReqFilePath : " << PreReqFilePath); + MESSAGE("OS : " << OS); + DataForSort.Print(); +} diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx index 989db2f44..212462ddd 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -1,23 +1,23 @@ // SALOME ResourcesCatalog : implementation of catalog resources parsing (SALOME_ModuleCatalog.idl) // // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// 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. -// -// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// 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. +// +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org // // // @@ -40,57 +40,47 @@ enum AccessProtocolType {rsh, ssh}; enum AccessModeType {interactive, batch}; -class ResourceDataToSort { -public: - std::string _hostName; - unsigned int _nbOfNodes; - unsigned int _nbOfProcPerNode; - unsigned int _CPUFreqMHz; - unsigned int _memInMB; - static unsigned int _nbOfNodesWanted; - static unsigned int _nbOfProcPerNodeWanted; - static unsigned int _CPUFreqMHzWanted; - static unsigned int _memInMBWanted; -public: - ResourceDataToSort(); - ResourceDataToSort(const std::string& hostname,unsigned int nbOfNodes,unsigned int nbOfProcPerNode,unsigned int CPUFreqMHz,unsigned int memInMB); - bool operator< (const ResourceDataToSort& other) const; - void Print() const; -private: - unsigned int GetNumberOfPoints() const; -// friend class SALOME_ResourcesCatalog_Handler; -// friend class SALOME_ResourcesManager; -// friend struct ParserResourcesType; -}; +class ResourceDataToSort + { + + public: + std::string _hostName; + unsigned int _nbOfNodes; + unsigned int _nbOfProcPerNode; + unsigned int _CPUFreqMHz; + unsigned int _memInMB; + static unsigned int _nbOfNodesWanted; + static unsigned int _nbOfProcPerNodeWanted; + static unsigned int _CPUFreqMHzWanted; + static unsigned int _memInMBWanted; + + public: + ResourceDataToSort(); + ResourceDataToSort(const std::string& hostname, + unsigned int nbOfNodes, + unsigned int nbOfProcPerNode, + unsigned int CPUFreqMHz, + unsigned int memInMB); + bool operator< (const ResourceDataToSort& other) const; + void Print() const; + + private: + unsigned int GetNumberOfPoints() const; + }; -struct ParserResourcesType { - ResourceDataToSort DataForSort; - std::string Alias; - AccessProtocolType Protocol; - AccessModeType Mode; - std::string UserName; - MapOfModulesPath ModulesPath; - std::string PreReqFilePath; - std::string OS; +struct ParserResourcesType + { + ResourceDataToSort DataForSort; + std::string Alias; + AccessProtocolType Protocol; + AccessModeType Mode; + std::string UserName; + MapOfModulesPath ModulesPath; + std::string PreReqFilePath; + std::string OS; - void Print(){ - std::cout << "##############*****" << std::endl; - std::cout << "HostName : " << DataForSort._hostName << std::endl; - std::cout << "Alias : " << Alias << std::endl; - std::cout << "Protocol : " << Protocol << std::endl; - std::cout << "Mode : " << Mode << std::endl; - std::cout << "UserName : " << UserName << std::endl; - std::cout << "Modules : " << std::endl; - int i=1; - for(std::map::iterator iter=ModulesPath.begin();iter!=ModulesPath.end();iter++) - { - std::cout << " Module " << i++ << " called : " << (*iter).first << " with path : " << (*iter).second << std::endl; - } - std::cout << "PreReqFilePath : " << PreReqFilePath << std::endl; - std::cout << "OS : " << OS << std::endl; - DataForSort.Print(); - } -}; + void Print(); + }; typedef std::map MapOfParserResourcesType; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 02feab8b0..7e1ed8f5b 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -1,4 +1,4 @@ -#include "SALOME_ResourcesManager.hxx" +#include "SALOME_ResourcesManager.hxx" //#include "SALOME_Container_i.hxx" #include "Utils_ExceptHandlers.hxx" #include "OpUtil.hxx" @@ -27,129 +27,245 @@ using namespace std; -//just for test -SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb,const char *xmlFilePath):_path_resources(xmlFilePath) +//============================================================================= +/*! + * just for test + */ +//============================================================================= + +SALOME_ResourcesManager:: +SALOME_ResourcesManager(CORBA::ORB_ptr orb, + const char *xmlFilePath) : + _path_resources(xmlFilePath) { - _NS=new SALOME_NamingService(orb); + _NS = new SALOME_NamingService(orb); } +//============================================================================= +/*! + * Standard constructor, parse resource file. + * - if ${APPLI} exists in environment, + * look for ${HOME}/*{APPLI}/CatalogResources.xml + * - else look for default: + * ${KERNEL_ROOT_DIR}/share/salome/resources/CatalogResources.xml + * - parse XML resource file. + */ +//============================================================================= + SALOME_ResourcesManager::SALOME_ResourcesManager(CORBA::ORB_ptr orb) { - _NS=new SALOME_NamingService(orb); -// _path_resources=getenv("KERNEL_ROOT_DIR"); -// _path_resources+="/share/salome/resources/CatalogResources.xml"; - _path_resources=getenv("HOME"); - _path_resources+="/"; - _path_resources+=getenv("APPLI"); - _path_resources+="/CatalogResources.xml"; + _NS = new SALOME_NamingService(orb); + // _path_resources=getenv("KERNEL_ROOT_DIR"); + // _path_resources+="/share/salome/resources/CatalogResources.xml"; + _path_resources = getenv("HOME"); + _path_resources += "/"; + _path_resources += getenv("APPLI"); + _path_resources += "/CatalogResources.xml"; ParseXmlFile(); } +//============================================================================= +/*! + * Standard Destructor + */ +//============================================================================= + SALOME_ResourcesManager::~SALOME_ResourcesManager() { delete _NS; } -vector SALOME_ResourcesManager::GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception) +//============================================================================= +/*! + * get the list of name of ressources fitting for the specified module. + * If hostname specified, check it is local or known in resources catalog. + * + * Else + * - select first machines with corresponding OS (all machines if + * parameter OS empty), + * - then select the sublist of machines on witch the module is known + * (if the result is empty, that probably means that the inventory of + * modules is probably not done, so give complete list from previous step) + * + */ +//============================================================================= + +vector +SALOME_ResourcesManager:: +GetFittingResources(const Engines::MachineParameters& params, + const char *moduleName) +throw(SALOME_Exception) { MESSAGE("ResourcesManager::GetFittingResources"); vector ret; - //To be sure that we search in a correct list. + + // --- To be sure that we search in a correct list. ParseXmlFile(); - const char *hostname=(const char *)params.hostname; - MESSAGE("GetFittingResources " << hostname << "" << GetHostname().c_str()); - if(hostname[0]!='\0') + + const char *hostname = (const char *)params.hostname; + MESSAGE("GetFittingResources " << hostname << " " << GetHostname().c_str()); + + if (hostname[0] != '\0') { - MESSAGE("ResourcesManager::GetFittingResources : hostname specified" ); - if( strcmp(hostname,"localhost") == 0 || strcmp(hostname,GetHostname().c_str()) == 0 ){ - MESSAGE("ResourcesManager::GetFittingResources : localhost" ); - ret.push_back(GetHostname().c_str()); - MESSAGE("ResourcesManager::GetFittingResources : " << ret.size()); - } - else if(_resourcesList.find(hostname)!=_resourcesList.end()){ - // params.hostame is in the list of resources so return it. - ret.push_back(hostname); - } else{ - //user specified an unknown hostame so notify to him. - MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception"); - throw SALOME_Exception("unknown host"); - } + MESSAGE("ResourcesManager::GetFittingResources : hostname specified" ); + + if ( strcmp(hostname, "localhost") == 0 || + strcmp(hostname, GetHostname().c_str()) == 0 ) + { + MESSAGE("ResourcesManager::GetFittingResources : localhost" ); + ret.push_back(GetHostname().c_str()); + MESSAGE("ResourcesManager::GetFittingResources : " << ret.size()); + } + + else if (_resourcesList.find(hostname) != _resourcesList.end()) + { + // --- params.hostame is in the list of resources so return it. + ret.push_back(hostname); + } + + else + { + // --- user specified an unknown hostame so notify him. + MESSAGE("ResourcesManager::GetFittingResources : SALOME_Exception"); + throw SALOME_Exception("unknown host"); + } } + else - // Search for available resources sorted by priority + // --- Search for available resources sorted by priority { - SelectOnlyResourcesWithOS(ret,params.OS); - KeepOnlyResourcesWithModule(ret,moduleName); - //set wanted parameters - ResourceDataToSort::_nbOfNodesWanted=params.nb_node; - ResourceDataToSort::_nbOfProcPerNodeWanted=params.nb_proc_per_node; - ResourceDataToSort::_CPUFreqMHzWanted=params.cpu_clock; - ResourceDataToSort::_memInMBWanted=params.mem_mb; - //end of set + SelectOnlyResourcesWithOS(ret, params.OS); + + KeepOnlyResourcesWithModule(ret, moduleName); + if (ret.size() == 0) + SelectOnlyResourcesWithOS(ret, params.OS); + + // --- set wanted parameters + ResourceDataToSort::_nbOfNodesWanted = params.nb_node; + ResourceDataToSort::_nbOfProcPerNodeWanted = params.nb_proc_per_node; + ResourceDataToSort::_CPUFreqMHzWanted = params.cpu_clock; + ResourceDataToSort::_memInMBWanted = params.mem_mb; + // --- end of set + list li; - for(vector::iterator iter=ret.begin();iter!=ret.end();iter++) - li.push_back(_resourcesList[(*iter)].DataForSort); + + for (vector::iterator iter = ret.begin(); + iter != ret.end(); + iter++) + li.push_back(_resourcesList[(*iter)].DataForSort); + li.sort(); - unsigned int i=0; - for(list::iterator iter2=li.begin();iter2!=li.end();iter2++) - ret[i++]=(*iter2)._hostName; + + unsigned int i = 0; + + for (list::iterator iter2 = li.begin(); + iter2 != li.end(); + iter2++) + ret[i++] = (*iter2)._hostName; } + MESSAGE("ResourcesManager::GetFittingResources : return" << ret.size()); return ret; } -int SALOME_ResourcesManager::AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const map& modulesOnNewResources, - const char *environPathOfPrerequired, - const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception) +//============================================================================= +/*! + * add an entry in the ressources catalog xml file. + * Return 1 if OK. + * Return 0 if the ressource with the same hostname already exists. + * + */ +//============================================================================= + +int +SALOME_ResourcesManager:: +AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, + const map& modulesOnNewResources, + const char *environPathOfPrerequired, + const char *alias, + const char *userName, + AccessModeType mode, + AccessProtocolType prot) +throw(SALOME_Exception) { - map::const_iterator iter=modulesOnNewResources.find("KERNEL"); - if(iter!=modulesOnNewResources.end()) + map::const_iterator iter = + modulesOnNewResources.find("KERNEL"); + + if (iter != modulesOnNewResources.end()) { ParserResourcesType newElt; - newElt.DataForSort._hostName=paramsOfNewResources.hostname; - newElt.Alias=alias; - newElt.Protocol=prot; - newElt.Mode=mode; - newElt.UserName=userName; - newElt.ModulesPath=modulesOnNewResources; - newElt.PreReqFilePath=environPathOfPrerequired; - newElt.OS=paramsOfNewResources.OS; - newElt.DataForSort._memInMB=paramsOfNewResources.mem_mb; - newElt.DataForSort._CPUFreqMHz=paramsOfNewResources.cpu_clock; - newElt.DataForSort._nbOfNodes=paramsOfNewResources.nb_node; - newElt.DataForSort._nbOfProcPerNode=paramsOfNewResources.nb_proc_per_node; - _resourcesList[newElt.DataForSort._hostName]=newElt; + newElt.DataForSort._hostName = paramsOfNewResources.hostname; + newElt.Alias = alias; + newElt.Protocol = prot; + newElt.Mode = mode; + newElt.UserName = userName; + newElt.ModulesPath = modulesOnNewResources; + newElt.PreReqFilePath = environPathOfPrerequired; + newElt.OS = paramsOfNewResources.OS; + newElt.DataForSort._memInMB = paramsOfNewResources.mem_mb; + newElt.DataForSort._CPUFreqMHz = paramsOfNewResources.cpu_clock; + newElt.DataForSort._nbOfNodes = paramsOfNewResources.nb_node; + newElt.DataForSort._nbOfProcPerNode = + paramsOfNewResources.nb_proc_per_node; + _resourcesList[newElt.DataForSort._hostName] = newElt; return 0; } + else throw SALOME_Exception("KERNEL is not present in this resource"); } + +//============================================================================= +/*! + * Deletes a resource from the catalog + */ +//============================================================================= + void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname) { _resourcesList.erase(hostname); } + +//============================================================================= +/*! + * write the current data in memory in file. + */ +//============================================================================= + void SALOME_ResourcesManager::WriteInXmlFile() { QDomDocument doc("ResourcesCatalog"); - SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList); + SALOME_ResourcesCatalog_Handler* handler = + new SALOME_ResourcesCatalog_Handler(_resourcesList); handler->PrepareDocToXmlFile(doc); delete handler; QFile file( _path_resources ); - if( !file.open( IO_WriteOnly ) ) + + if ( !file.open( IO_WriteOnly ) ) cout << "WRITING ERROR !!!" << endl; QTextStream ts( &file ); + ts << doc.toString(); file.close(); + cout << "WRITING DONE!!!" << endl; } -const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() + +//============================================================================= +/*! + * parse the data type catalog + */ +//============================================================================= + +const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() { - SALOME_ResourcesCatalog_Handler* handler = new SALOME_ResourcesCatalog_Handler(_resourcesList); + SALOME_ResourcesCatalog_Handler* handler = + new SALOME_ResourcesCatalog_Handler(_resourcesList); QFile xmlFile(_path_resources); QXmlInputSource source(xmlFile); @@ -163,231 +279,335 @@ const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() return _resourcesList; } -bool SALOME_ResourcesManager::_verify_resources(MapOfParserResourcesType resourceslist) +//============================================================================= +/*! + * verify ressources catalog content - return true if verfication is OK + */ +//============================================================================= + + +bool +SALOME_ResourcesManager::_verify_resources +(MapOfParserResourcesType resourceslist) { -// bool _return_value = true; -// bool _bool = false ; -// vector _machine_list; -// _machine_list.resize(0); - -// // Fill a list of all computers indicated in the resources list -// for (unsigned int ind = 0; ind < resourceslist.size(); ind++) -// _machine_list.push_back(resourceslist[ind].HostName); - -// // Parse if a computer name is twice in the list of computers -// for (unsigned int ind = 0; ind < _machine_list.size(); ind++) -// { -// for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++) -// { -// if(_machine_list[ind].compare(_machine_list[ind1]) == 0) -// { -// MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the resources list") -// _return_value = false; -// } -// } -// } - -// return _return_value; + // bool _return_value = true; + // bool _bool = false ; + // vector _machine_list; + // _machine_list.resize(0); + + // // Fill a list of all computers indicated in the resources list + // for (unsigned int ind = 0; ind < resourceslist.size(); ind++) + // _machine_list.push_back(resourceslist[ind].HostName); + + // // Parse if a computer name is twice in the list of computers + // for (unsigned int ind = 0; ind < _machine_list.size(); ind++) + // { + // for (unsigned int ind1 = ind+1 ; ind1 < _machine_list.size(); ind1++) + // { + // if(_machine_list[ind].compare(_machine_list[ind1]) == 0) + // { + // MESSAGE("The computer " << _machine_list[ind] << " is indicated more than once in the resources list") + // _return_value = false; + // } + // } + // } + + // return _return_value; return true; } + +//============================================================================= +/*! + * consult the content of the list + */ +//============================================================================= + const MapOfParserResourcesType& SALOME_ResourcesManager::GetList() const -{ - return _resourcesList; -} + { + return _resourcesList; + } + -string SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines) +//============================================================================= +/*! + * dynamically obtains the best machines + */ +//============================================================================= + +string +SALOME_ResourcesManager::FindBest(const Engines::MachineList& listOfMachines) { return _dynamicResourcesSelecter.FindBest(listOfMachines); } + +//============================================================================= +/*! + * This is no longer valid (C++ container are also python containers) + */ +//============================================================================= + bool isPythonContainer(const char* ContainerName) { - bool ret=false; - int len=strlen(ContainerName); - if(len>=2) - if(strcmp(ContainerName+len-2,"Py")==0) - ret=true; + bool ret = false; + int len = strlen(ContainerName); + + if (len >= 2) + if (strcmp(ContainerName + len - 2, "Py") == 0) + ret = true; + return ret; } -string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer(const string& machine,const Engines::MachineParameters& params) + +//============================================================================= +/*! + * builds in a temporary file the script to be launched + */ +//============================================================================= + +string +SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer +(const string& machine, + const Engines::MachineParameters& params) { -// _TmpFileName=BuildTemporaryFileName(); -// ofstream tempOutputFile; -// tempOutputFile.open(_TmpFileName.c_str(),ofstream::out ); + // _TmpFileName=BuildTemporaryFileName(); + // ofstream tempOutputFile; + // tempOutputFile.open(_TmpFileName.c_str(),ofstream::out ); + const ParserResourcesType& resInfo=_resourcesList[machine]; -// tempOutputFile << "#! /bin/sh" << endl; -// //set env vars -// for(map::const_iterator iter=resInfo.ModulesPath.begin();iter!=resInfo.ModulesPath.end();iter++) -// { -// string curModulePath((*iter).second); -// tempOutputFile << (*iter).first << "_ROOT_DIR="<< curModulePath << endl; -// tempOutputFile << "export " << (*iter).first << "_ROOT_DIR" << endl; -// tempOutputFile << "LD_LIBRARY_PATH=" << curModulePath << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl; -// tempOutputFile << "PYTHONPATH=" << curModulePath << "/bin/salome:" << curModulePath << "/lib/salome:" << curModulePath << "/lib/python2.2/site-packages/salome:"; -// tempOutputFile << curModulePath << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}" << endl; -// } -// tempOutputFile << "export LD_LIBRARY_PATH" << endl; -// tempOutputFile << "export PYTHONPATH" << endl; -// tempOutputFile << "source " << resInfo.PreReqFilePath << endl; -// // ! env vars - if(params.isMPI){ -// tempOutputFile << "mpirun -np "; - int nbproc; - if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) - nbproc = 1; - else if( params.nb_node == 0 ) - nbproc = params.nb_proc_per_node; - else if( params.nb_proc_per_node == 0 ) - nbproc = params.nb_node; - else - nbproc = params.nb_node * params.nb_proc_per_node; -// std::ostringstream o; -// tempOutputFile << nbproc << " "; - } -// tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/"; -// if(params.isMPI){ -// if(isPythonContainer(params.container_name)) -// tempOutputFile << "pyMPI SALOME_ContainerPy.py "; -// else -// tempOutputFile << "SALOME_MPIContainer "; -// } -// else{ -// if(isPythonContainer(params.container_name)) -// tempOutputFile << "SALOME_ContainerPy.py "; -// else -// tempOutputFile << "SALOME_Container "; -// } -// tempOutputFile << _NS->ContainerName(params) << " -"; -// AddOmninamesParams(tempOutputFile); -// tempOutputFile << " &" << endl; -// tempOutputFile.flush(); -// tempOutputFile.close(); -// chmod(_TmpFileName.c_str(),0x1ED); + + // tempOutputFile << "#! /bin/sh" << endl; + // //set env vars + // for(map::const_iterator iter = + // resInfo.ModulesPath.begin();iter!=resInfo.ModulesPath.end();iter++) + // { + // string curModulePath((*iter).second); + // tempOutputFile << (*iter).first << "_ROOT_DIR="<< curModulePath << endl; + // tempOutputFile << "export " << (*iter).first << "_ROOT_DIR" << endl; + // tempOutputFile << "LD_LIBRARY_PATH=" << curModulePath << "/lib/salome" << ":${LD_LIBRARY_PATH}" << endl; + // tempOutputFile << "PYTHONPATH=" << curModulePath << "/bin/salome:" << curModulePath << "/lib/salome:" << curModulePath << "/lib/python2.2/site-packages/salome:"; + // tempOutputFile << curModulePath << "/lib/python2.2/site-packages/salome/shared_modules:${PYTHONPATH}" << endl; + // } + // tempOutputFile << "export LD_LIBRARY_PATH" << endl; + // tempOutputFile << "export PYTHONPATH" << endl; + // tempOutputFile << "source " << resInfo.PreReqFilePath << endl; + // // ! env vars + + if (params.isMPI) + { + // tempOutputFile << "mpirun -np "; + int nbproc; + + if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) + nbproc = 1; + else if ( params.nb_node == 0 ) + nbproc = params.nb_proc_per_node; + else if ( params.nb_proc_per_node == 0 ) + nbproc = params.nb_node; + else + nbproc = params.nb_node * params.nb_proc_per_node; + + // std::ostringstream o; + // tempOutputFile << nbproc << " "; + } + + // tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/"; + // if(params.isMPI){ + // if(isPythonContainer(params.container_name)) + // tempOutputFile << "pyMPI SALOME_ContainerPy.py "; + // else + // tempOutputFile << "SALOME_MPIContainer "; + // } + // else{ + // if(isPythonContainer(params.container_name)) + // tempOutputFile << "SALOME_ContainerPy.py "; + // else + // tempOutputFile << "SALOME_Container "; + // } + // tempOutputFile << _NS->ContainerName(params) << " -"; + // AddOmninamesParams(tempOutputFile); + // tempOutputFile << " &" << endl; + // tempOutputFile.flush(); + // tempOutputFile.close(); + // chmod(_TmpFileName.c_str(),0x1ED); //Build command string command; - if(resInfo.Protocol==rsh) + + if (resInfo.Protocol == rsh) { command = "rsh "; -// string commandRcp="rcp "; -// commandRcp+=_TmpFileName; -// commandRcp+=" "; -// commandRcp+=machine; -// commandRcp+=":"; -// commandRcp+=_TmpFileName; -// system(commandRcp.c_str()); + // string commandRcp="rcp "; + // commandRcp+=_TmpFileName; + // commandRcp+=" "; + // commandRcp+=machine; + // commandRcp+=":"; + // commandRcp+=_TmpFileName; + // system(commandRcp.c_str()); } - else if(resInfo.Protocol==ssh) + + else if (resInfo.Protocol == ssh) command = "ssh "; else throw SALOME_Exception("Unknown protocol"); - -// command+=machine; -// _CommandForRemAccess=command; -// command+=" "; -// command+=_TmpFileName; -// command += " > "; -// command += "/tmp/"; -// command += _NS->ContainerName(params); -// command += "_"; -// command += machine; -// command += ".log 2>&1 &"; -// cout << "Command is ... " << command << endl; + + // command+=machine; + // _CommandForRemAccess=command; + // command+=" "; + // command+=_TmpFileName; + // command += " > "; + // command += "/tmp/"; + // command += _NS->ContainerName(params); + // command += "_"; + // command += machine; + // command += ".log 2>&1 &"; + // cout << "Command is ... " << command << endl; command += machine; // on suppose le même user par defaut + command += " "; + command += getenv("APPLI"); // chemin relatif a $HOME + command += "/runRemote.sh "; + command += GetHostname(); // ********** A CHANGER, le naming service n'est pas obligatoirement ici + command += " "; + command += getenv("NSPORT"); + command += " SALOME_Container "; + command += _NS->ContainerName(params); + command += "&"; + MESSAGE("command =" << command); + return command; } -string SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer(const Engines::MachineParameters& params) + +//============================================================================= +/*! + * builds the command to be launched. + */ +//============================================================================= + +string +SALOME_ResourcesManager::BuildCommandToLaunchLocalContainer +(const Engines::MachineParameters& params) { - _TmpFileName=""; + _TmpFileName = ""; string command; - int nbproc=0; - if(params.isMPI){ - command="mpirun -np "; - if( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) - nbproc = 1; - else if( params.nb_node == 0 ) - nbproc = params.nb_proc_per_node; - else if( params.nb_proc_per_node == 0 ) - nbproc = params.nb_node; - else - nbproc = params.nb_node * params.nb_proc_per_node; - std::ostringstream o; - o << nbproc << " "; - command += o.str(); - if(isPythonContainer(params.container_name)) - command+="pyMPI SALOME_ContainerPy.py "; - else - command+="SALOME_MPIContainer "; - } - else{ - if(isPythonContainer(params.container_name)) - command="SALOME_ContainerPy.py "; - else - command="SALOME_Container "; - } - command+=_NS->ContainerName(params); - command+=" -"; + int nbproc = 0; + + if (params.isMPI) + { + command = "mpirun -np "; + + if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) ) + nbproc = 1; + else if ( params.nb_node == 0 ) + nbproc = params.nb_proc_per_node; + else if ( params.nb_proc_per_node == 0 ) + nbproc = params.nb_node; + else + nbproc = params.nb_node * params.nb_proc_per_node; + + std::ostringstream o; + + o << nbproc << " "; + + command += o.str(); + + if (isPythonContainer(params.container_name)) + command += "pyMPI SALOME_ContainerPy.py "; + else + command += "SALOME_MPIContainer "; + } + + else + { + if (isPythonContainer(params.container_name)) + command = "SALOME_ContainerPy.py "; + else + command = "SALOME_Container "; + } + + command += _NS->ContainerName(params); + command += " -"; AddOmninamesParams(command); - command+=" > /tmp/"; - command+=_NS->ContainerName(params); + command += " > /tmp/"; + command += _NS->ContainerName(params); command += "_"; command += GetHostname(); command += "_"; command += getenv( "USER" ) ; command += ".log 2>&1 &" ; - cout << "Command is ... " << command << endl << flush; + MESSAGE("Command is ... " << command); return command; } + +//============================================================================= +/*! + * removes the generated temporary file in case of a remote launch. + */ +//============================================================================= + void SALOME_ResourcesManager::RmTmpFile() { - if(_TmpFileName!="") + if (_TmpFileName != "") { - string command="rm "; - command+=_TmpFileName; - char *temp=strdup(command.c_str()); - int lgthTemp=strlen(temp); - temp[lgthTemp-3]='*'; - temp[lgthTemp-2]='\0'; + string command = "rm "; + command += _TmpFileName; + char *temp = strdup(command.c_str()); + int lgthTemp = strlen(temp); + temp[lgthTemp - 3] = '*'; + temp[lgthTemp - 2] = '\0'; system(temp); free(temp); } } -string SALOME_ResourcesManager::BuildCommand(const string& machine,const char *containerName) + +//============================================================================= +/*! + * builds the script to be launched + */ +//============================================================================= + +string +SALOME_ResourcesManager::BuildCommand +(const string& machine, + const char *containerName) { -// rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 & - const ParserResourcesType& resInfo=_resourcesList[machine]; - bool pyCont=isPythonContainer(containerName); + // rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 & + const ParserResourcesType& resInfo = _resourcesList[machine]; + bool pyCont = isPythonContainer(containerName); string command; - if(resInfo.Protocol==rsh) + + if (resInfo.Protocol == rsh) command = "rsh -n " ; - else if(resInfo.Protocol==ssh) + else if (resInfo.Protocol == ssh) command = "ssh -f -n "; else throw SALOME_Exception("Not implemented yet..."); - command += machine; + + command += machine; command += " "; string path = (*(resInfo.ModulesPath.find("KERNEL"))).second; - command +=path; + command += path; command += "/bin/salome/"; + if ( pyCont ) command += "SALOME_ContainerPy.py "; else command += "SALOME_Container "; + command += containerName; command += " -"; AddOmninamesParams(command); @@ -396,98 +616,155 @@ string SALOME_ResourcesManager::BuildCommand(const string& machine,const char *c command += "_"; command += machine; command += ".log 2>&1 &" ; + SCRUTE( command ); return command; } +//============================================================================= +/*! + * Gives a sublist of machines with matching OS. + * If parameter OS is empty, gives the complete list of machines + */ +//============================================================================= + // Warning need an updated parsed list : _resourcesList -void SALOME_ResourcesManager::SelectOnlyResourcesWithOS(vector& hosts,const char *OS) const throw(SALOME_Exception) +void +SALOME_ResourcesManager::SelectOnlyResourcesWithOS +( vector& hosts, + const char *OS) const +throw(SALOME_Exception) { string base(OS); - for(map::const_iterator iter=_resourcesList.begin();iter!=_resourcesList.end();iter++) + + for (map::const_iterator iter = + _resourcesList.begin(); + iter != _resourcesList.end(); + iter++) { - if((*iter).second.OS==base) - hosts.push_back((*iter).first); + if ( (*iter).second.OS == base || base.size() == 0) + hosts.push_back((*iter).first); } } + +//============================================================================= +/*! + * Gives a sublist of machines on which the module is known. + */ +//============================================================================= + //Warning need an updated parsed list : _resourcesList -void SALOME_ResourcesManager::KeepOnlyResourcesWithModule(vector& hosts,const char *moduleName) const throw(SALOME_Exception) +void +SALOME_ResourcesManager::KeepOnlyResourcesWithModule +( vector& hosts, + const char *moduleName) const +throw(SALOME_Exception) { - for(vector::iterator iter=hosts.begin();iter!=hosts.end();) - { - MapOfParserResourcesType::const_iterator it=_resourcesList.find(*iter); - const map& mapOfModulesOfCurrentHost=(((*it).second).ModulesPath); - if(mapOfModulesOfCurrentHost.find(moduleName)==mapOfModulesOfCurrentHost.end()) - hosts.erase(iter); - else - iter++; - } + for (vector::iterator iter = hosts.begin(); iter != hosts.end();) + { + MapOfParserResourcesType::const_iterator it = _resourcesList.find(*iter); + const map& mapOfModulesOfCurrentHost = + (((*it).second).ModulesPath); + + if (mapOfModulesOfCurrentHost.find(moduleName) == + mapOfModulesOfCurrentHost.end()) + hosts.erase(iter); + else + iter++; + } } + +//============================================================================= +/*! + * add to command all options relative to naming service. + */ +//============================================================================= + void SALOME_ResourcesManager::AddOmninamesParams(string& command) const -{ - // If env variable OMNIORB_CONFIG is not defined or the file is more complex than one line - // does not work - // Even if we use it we have to check if env variable exists - //string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; - //ifstream omniORBfile( omniORBcfg.c_str() ) ; - //char ORBInitRef[11] ; - //char egal[3] ; - //char nameservice[132] ; - //omniORBfile >> ORBInitRef ; - //command += "ORBInitRef " ; - //omniORBfile >> egal ; - //omniORBfile >> nameservice ; - //omniORBfile.close() ; - //char * bsn = strchr( nameservice , '\n' ) ; - //if ( bsn ) { + { + // If env variable OMNIORB_CONFIG is not defined or the file is more complex than one line + // does not work + // Even if we use it we have to check if env variable exists + //string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; + //ifstream omniORBfile( omniORBcfg.c_str() ) ; + //char ORBInitRef[11] ; + //char egal[3] ; + //char nameservice[132] ; + //omniORBfile >> ORBInitRef ; + //command += "ORBInitRef " ; + //omniORBfile >> egal ; + //omniORBfile >> nameservice ; + //omniORBfile.close() ; + //char * bsn = strchr( nameservice , '\n' ) ; + //if ( bsn ) { //bsn[ 0 ] = '\0' ; - //} - //command += nameservice ; + //} + //command += nameservice ; - char *iorstr = _NS->getIORaddr(); - command += "ORBInitRef NameService="; - command += iorstr; -} + char *iorstr = _NS->getIORaddr(); + command += "ORBInitRef NameService="; + command += iorstr; + } + + +//============================================================================= +/*! + * add to command all options relative to naming service. + */ +//============================================================================= void SALOME_ResourcesManager::AddOmninamesParams(ofstream& fileStream) const -{ - string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; - ifstream omniORBfile( omniORBcfg.c_str() ) ; - char ORBInitRef[11] ; - char egal[3] ; - char nameservice[132] ; - omniORBfile >> ORBInitRef ; - fileStream << "ORBInitRef "; - omniORBfile >> egal ; - omniORBfile >> nameservice ; - omniORBfile.close() ; - char * bsn = strchr( nameservice , '\n' ) ; - if ( bsn ) { - bsn[ 0 ] = '\0' ; + { + string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ; + ifstream omniORBfile( omniORBcfg.c_str() ) ; + char ORBInitRef[11] ; + char egal[3] ; + char nameservice[132] ; + omniORBfile >> ORBInitRef ; + fileStream << "ORBInitRef "; + omniORBfile >> egal ; + omniORBfile >> nameservice ; + omniORBfile.close() ; + char * bsn = strchr( nameservice , '\n' ) ; + + if ( bsn ) + { + bsn[ 0 ] = '\0' ; + } + + fileStream << nameservice; } - fileStream << nameservice; -} + + +//============================================================================= +/*! + * generate a file name in /tmp directory + */ +//============================================================================= string SALOME_ResourcesManager::BuildTemporaryFileName() const -{ - //build more complex file name to support multiple salome session - char *temp=new char[19]; - strcpy(temp,"/tmp/command"); - strcat(temp,"XXXXXX"); + { + //build more complex file name to support multiple salome session + char *temp = new char[19]; + strcpy(temp, "/tmp/command"); + strcat(temp, "XXXXXX"); #ifndef WNT - mkstemp(temp); + + mkstemp(temp); #else - char aPID[80]; - itoa(getpid(), aPID, 10); - strcat(temp,aPID); + + char aPID[80]; + itoa(getpid(), aPID, 10); + strcat(temp, aPID); #endif - string command(temp); - delete [] temp; - command += ".sh"; - return command; -} + + string command(temp); + delete [] temp; + command += ".sh"; + return command; + } diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index b8dca196c..92c25367d 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -28,90 +28,93 @@ #endif #endif -//WARNING the call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done in a critical section to be sure to be clean. -//Only one thread should use the SALOME_ResourcesManager class in a SALOME session. +// --- WARNING --- +// The call of BuildTempFileToLaunchRemoteContainer and RmTmpFile must be done +// in a critical section to be sure to be clean. +// Only one thread should use the SALOME_ResourcesManager class in a SALOME +// session. class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager -{ -public: - //! standard constructor - SALOME_ResourcesManager(CORBA::ORB_ptr orb); + { - //!just for test - SALOME_ResourcesManager(CORBA::ORB_ptr orb,const char *xmlFilePath); - - //! standard destructor - ~SALOME_ResourcesManager(); + public: - //! method to get the list of name of ressources fitting for the specified module. - std::vector GetFittingResources(const Engines::MachineParameters& params,const char *moduleName) throw(SALOME_Exception); + SALOME_ResourcesManager(CORBA::ORB_ptr orb, const char *xmlFilePath); + SALOME_ResourcesManager(CORBA::ORB_ptr orb); - //! method to dynamically obtain the best machines - std::string FindBest(const Engines::MachineList& listOfMachines); + ~SALOME_ResourcesManager(); - //! method that builds in a temporary file the script to be launched - std::string BuildTempFileToLaunchRemoteContainer(const std::string& machine,const Engines::MachineParameters& params); + std::vector + GetFittingResources(const Engines::MachineParameters& params, + const char *moduleName) + throw(SALOME_Exception); - //! method that builds the command to be launched. - std::string BuildCommandToLaunchLocalContainer(const Engines::MachineParameters& params); + std::string FindBest(const Engines::MachineList& listOfMachines); - //! method that remove the generated temporary file in case of a remote launch. - void RmTmpFile(); + std::string BuildTempFileToLaunchRemoteContainer + (const std::string& machine, + const Engines::MachineParameters& params); - //! method that builds the script to be launched - std::string BuildCommand(const std::string& machine,const char *containerName); + std::string BuildCommandToLaunchLocalContainer + (const Engines::MachineParameters& params); - //! add an entry in the ressources catalog xml file. Return 1 if OK. Return 0 if the ressource with the same hostname already exists. - int AddResourceInCatalog(const Engines::MachineParameters& paramsOfNewResources, const std::map& modulesOnNewResources, - const char *environPathOfPrerequired, - const char *alias, const char *userName, AccessModeType mode, AccessProtocolType prot) throw(SALOME_Exception); - - //! delete a ressource from the Catalog. - void DeleteResourceInCatalog(const char *hostname); + void RmTmpFile(); - //! write the current data in memory in file. - void WriteInXmlFile(); + std::string BuildCommand(const std::string& machine, + const char *containerName); - //! method to parse the data type catalog - const MapOfParserResourcesType& ParseXmlFile(); + int AddResourceInCatalog + (const Engines::MachineParameters& paramsOfNewResources, + const std::map& modulesOnNewResources, + const char *environPathOfPrerequired, + const char *alias, + const char *userName, + AccessModeType mode, + AccessProtocolType prot) + throw(SALOME_Exception); - //! to consult the content of the list - const MapOfParserResourcesType& GetList() const; + void DeleteResourceInCatalog(const char *hostname); -private: - SALOME_NamingService *_NS; + void WriteInXmlFile(); - //! method to verify ressources catalog content - return true if verfication is OK - bool _verify_resources(MapOfParserResourcesType resourceslist); + const MapOfParserResourcesType& ParseXmlFile(); - //! method that fill hosts with only resources in xml files that are on the specified OS - void SelectOnlyResourcesWithOS(std::vector& hosts,const char *OS) const throw(SALOME_Exception); + const MapOfParserResourcesType& GetList() const; - //! method that keep from hosts only those having component of name moduleName. - void KeepOnlyResourcesWithModule(std::vector& hosts,const char *moduleName) const throw(SALOME_Exception); + private: + SALOME_NamingService *_NS; - //! methode that add to command all options relative to naming service. - void AddOmninamesParams(std::string& command) const; + bool _verify_resources(MapOfParserResourcesType resourceslist); - //! method that add to command all options relative to naming service. - void AddOmninamesParams(std::ofstream& fileStream) const; + void SelectOnlyResourcesWithOS(std::vector& hosts, + const char *OS) const + throw(SALOME_Exception); - //! method that generate a file name in /tmp directory - std::string BuildTemporaryFileName() const; + void KeepOnlyResourcesWithModule(std::vector& hosts, + const char *moduleName) const + throw(SALOME_Exception); - // will contain the path to the ressources catalog - QString _path_resources; + void AddOmninamesParams(std::string& command) const; - //! attribute that contains current tmp files generated - std::string _TmpFileName; + void AddOmninamesParams(std::ofstream& fileStream) const; - //! attribute that contains the rsh or ssh command to access directly to machine. Only used by this->RmTmpFile in case of a remote launch. - std::string _CommandForRemAccess; - - //will contain the informations on the data type catalog(after parsing) - MapOfParserResourcesType _resourcesList; + std::string BuildTemporaryFileName() const; - SALOME_LoadRateManager _dynamicResourcesSelecter; -}; + + //! will contain the path to the ressources catalog + QString _path_resources; + + //! attribute that contains current tmp files generated + std::string _TmpFileName; + + //! contains the rsh or ssh command to access directly to machine. + // Only used by this->RmTmpFile in case of a remote launch. + std::string _CommandForRemAccess; + + //! will contain the informations on the data type catalog(after parsing) + MapOfParserResourcesType _resourcesList; + + SALOME_LoadRateManager _dynamicResourcesSelecter; + }; #endif // RESSOURCESCATALOG_IMPL_H diff --git a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx index 1697ac576..087ef940c 100644 --- a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx +++ b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.cxx @@ -10,9 +10,6 @@ using namespace std; -// --- Registers the fixture into the 'registry' - -CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); // ============================================================================ /*! @@ -55,7 +52,7 @@ SALOMELocalTraceTest::testSingletonBufferPool() CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite ofstream traceFile; - traceFile.open(theFileName, ios::out | ios::trunc); + traceFile.open(theFileName, ios::out | ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); diff --git a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.hxx b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.hxx index a219689e6..660c097bb 100644 --- a/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.hxx +++ b/src/SALOMELocalTrace/Test/SALOMELocalTraceTest.hxx @@ -10,7 +10,6 @@ class SALOMELocalTraceTest : public CppUnit::TestFixture CPPUNIT_TEST( testSingletonBufferPool ); CPPUNIT_TEST( testLoadBufferPoolLocal ); CPPUNIT_TEST( testLoadBufferPoolFile ); - CPPUNIT_TEST( testLoadBufferPoolFile ); CPPUNIT_TEST_SUITE_END(); public: diff --git a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx index 0706565c7..3af9746b6 100644 --- a/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx +++ b/src/SALOMELocalTrace/Test/TestSALOMELocalTrace.cxx @@ -3,6 +3,10 @@ #include "SALOMELocalTraceTest.hxx" +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); + // --- generic Main program from Basic/Test #include "BasicMainTest.hxx" diff --git a/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx b/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx index 6aed2110b..2a84b4b41 100644 --- a/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx +++ b/src/SALOMETraceCollector/Test/SALOMETraceCollectorTest.cxx @@ -10,10 +10,6 @@ using namespace std; -// --- Registers the fixture into the 'registry' - -CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); - // ============================================================================ /*! * diff --git a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx index 1ce22b7c3..2be9c0c42 100644 --- a/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx +++ b/src/SALOMETraceCollector/Test/TestSALOMETraceCollector.cxx @@ -4,6 +4,11 @@ #include "SALOMELocalTraceTest.hxx" #include "SALOMETraceCollectorTest.hxx" +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); + // --- generic Main program from Basic/Test #include "BasicMainTest.hxx" diff --git a/src/UnitTests/Makefile.in b/src/UnitTests/Makefile.in index 212f9a0c4..0f69aafcb 100644 --- a/src/UnitTests/Makefile.in +++ b/src/UnitTests/Makefile.in @@ -47,6 +47,8 @@ LIB_SRC = BIN = UnitTests BIN_SRC = +BIN_CLIENT_IDL = SALOME_Component.idl SALOME_TestComponent.idl \ + SALOME_Exception.idl LIBS= @LIBS@ @@ -54,8 +56,10 @@ LDFLAGSFORBIN+= \ -lSALOMELocalTraceTest -lSALOMELocalTrace -lSALOMEBasics \ -lSALOMETraceCollectorTest \ -lUtilsTest -lOpUtil \ + -lSalomeNS -lSalomeContainer -lSalomeResourcesManager \ + -lRegistry -lSalomeNotification \ + -lLifeCycleCORBATest -lSalomeLifeCycleCORBA \ -lcppunit -# -lefence @CONCLUDE@ diff --git a/src/UnitTests/UnitTests.cxx b/src/UnitTests/UnitTests.cxx index ec77f4752..987e3049c 100644 --- a/src/UnitTests/UnitTests.cxx +++ b/src/UnitTests/UnitTests.cxx @@ -4,6 +4,14 @@ #include "SALOMELocalTraceTest.hxx" #include "SALOMETraceCollectorTest.hxx" #include "UtilsTest.hxx" +#include "LifeCycleCORBATest.hxx" + +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( LifeCycleCORBATest ); // --- generic Main program from Basic/Test diff --git a/src/UnitTests/UnitTests.py b/src/UnitTests/UnitTests.py index d34e6beb2..9731efcdb 100644 --- a/src/UnitTests/UnitTests.py +++ b/src/UnitTests/UnitTests.py @@ -9,6 +9,13 @@ import TestKiller args, modules_list, modules_root_dir = runSalome.get_config() runSalome.set_env(args, modules_list, modules_root_dir) +# set environment for trace in logger +# (with file, servers may be killed before the write to the file...) + +#os.environ["SALOME_trace"] = "file:/tmp/traceUnitTest.log" +#os.environ["SALOME_trace"] = "local" +os.environ["SALOME_trace"] = "with_logger" + # launch CORBA naming server clt=orbmodule.client() @@ -19,11 +26,42 @@ myServer=runSalome.LoggerServer(args) myServer.run() clt.waitLogger("Logger") +# launch notify server + +myServer=runSalome.NotifyServer(args,modules_root_dir) +myServer.run() + +# launch registry server + +myServer=runSalome.RegistryServer(args) +myServer.run() +clt.waitNS("/Registry") + +# launch module catalog server + +cataServer=runSalome.CatalogServer(args) +cataServer.setpath(modules_list,modules_root_dir) +cataServer.run() +clt.waitNS("/Kernel/ModulCatalog") + +# launch container manager server + +myCmServer = runSalome.ContainerManagerServer(args) +myCmServer.setpath(modules_list,modules_root_dir) +myCmServer.run() +clt.waitNS("/ContainerManager") + # execute Unit Test command = ['UnitTests'] ret = os.spawnvp(os.P_WAIT, command[0], command) +# kill containers created by the Container Manager + +import Engines +containerManager = clt.waitNS("/ContainerManager",Engines.ContainerManager) +containerManager.Shutdown() + # kill Test process TestKiller.killProcess(runSalome.process_id) diff --git a/src/Utils/Test/TestUtils.cxx b/src/Utils/Test/TestUtils.cxx index ec77f4752..117e41790 100644 --- a/src/Utils/Test/TestUtils.cxx +++ b/src/Utils/Test/TestUtils.cxx @@ -5,6 +5,12 @@ #include "SALOMETraceCollectorTest.hxx" #include "UtilsTest.hxx" +// --- Registers the fixture into the 'registry' + +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMELocalTraceTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( SALOMETraceCollectorTest ); +CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); + // --- generic Main program from Basic/Test #include "BasicMainTest.hxx" diff --git a/src/Utils/Test/UtilsTest.cxx b/src/Utils/Test/UtilsTest.cxx index fd6372791..a82e9d55e 100644 --- a/src/Utils/Test/UtilsTest.cxx +++ b/src/Utils/Test/UtilsTest.cxx @@ -10,10 +10,6 @@ using namespace std; -// --- Registers the fixture into the 'registry' - -CPPUNIT_TEST_SUITE_REGISTRATION( UtilsTest ); - #define TRACEFILE "/tmp/traceUnitTest.log" // ============================================================================ @@ -39,7 +35,7 @@ UtilsTest::setUp() CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite ofstream traceFile; - traceFile.open(theFileName, ios::out | ios::trunc); + traceFile.open(theFileName, ios::out | ios::app); CPPUNIT_ASSERT(traceFile); // file created empty, then closed traceFile.close(); diff --git a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx index 9d910a323..ff8c7e64a 100644 --- a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx +++ b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx @@ -79,7 +79,7 @@ public : if ( Make_ATEXIT && !ATEXIT_Done ) { //CCRT assert (DESTRUCTEUR_GENERIQUE_::Destructeurs==0); - cerr << "ATEXIT_::ATEXIT_ Construction ATEXIT" << endl;// message necessaire pour utiliser logger dans Nettoyage (cf.BUG KERNEL4561) + //cerr << "ATEXIT_::ATEXIT_ Construction ATEXIT" << endl;// message necessaire pour utiliser logger dans Nettoyage (cf.BUG KERNEL4561) DESTRUCTEUR_GENERIQUE_::Destructeurs = new std::list ; // Destructeur alloue dynamiquement (cf. ci-dessous) , // il est utilise puis detruit par la fonction Nettoyage @@ -91,7 +91,7 @@ public : ~ATEXIT_( ) { - cerr << "ATEXIT_::~ATEXIT_ Destruction ATEXIT" << endl; + //cerr << "ATEXIT_::~ATEXIT_ Destruction ATEXIT" << endl; } }; @@ -111,7 +111,7 @@ static ATEXIT_ nettoyage = ATEXIT_( false ); /* singleton statique */ void Nettoyage( void ) { - cerr << "Nettoyage()" << endl; + //cerr << "Nettoyage()" << endl; //if(MYDEBUG) BEGIN_OF("Nettoyage( void )") ; assert(DESTRUCTEUR_GENERIQUE_::Destructeurs) ; //if(MYDEBUG) SCRUTE( DESTRUCTEUR_GENERIQUE_::Destructeurs->size() ) ; diff --git a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx index 4f97236a6..68fb9ce6e 100644 --- a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx +++ b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx @@ -123,13 +123,13 @@ public : typedef PortableServer::ServantBase TServant; if(_PtrObjet){ if(TServant* aServant = dynamic_cast(_PtrObjet)){ - cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting ServantBase's _PtrObjet" << endl; + //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting ServantBase's _PtrObjet" << endl; PortableServer::POA_var aPOA = aServant->_default_POA(); PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant); aPOA->deactivate_object(anObjectId.in()); aServant->_remove_ref(); }else{ - cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl; + //cerr << "DESTRUCTEUR_GENERIQUE_::operator() deleting _PtrObjet" << endl; TYPE* aPtr = static_cast(_PtrObjet); delete aPtr; } diff --git a/src/Utils/Utils_ORB_INIT.cxx b/src/Utils/Utils_ORB_INIT.cxx index cb8874845..7c774711c 100644 --- a/src/Utils/Utils_ORB_INIT.cxx +++ b/src/Utils/Utils_ORB_INIT.cxx @@ -40,9 +40,9 @@ ORB_INIT::~ORB_INIT() { if ( ! CORBA::is_nil( _orb ) ) { - std::cerr << "appel _orb->destroy()" << std::endl; + //std::cerr << "appel _orb->destroy()" << std::endl; _orb->destroy() ; - std::cerr << "retour _orb->destroy()" << std::endl; + //std::cerr << "retour _orb->destroy()" << std::endl; } } -- 2.39.2