From 580b222b174d89439af17c7af1daf94c563c44f1 Mon Sep 17 00:00:00 2001 From: prascle Date: Mon, 10 Oct 2005 14:50:05 +0000 Subject: [PATCH] PR: resources manager with and without SALOME Appli --- bin/appliskel/runAppli | 1 + bin/appliskel/runRemote.sh | 2 + bin/appliskel/runTests | 1 + src/Container/SALOME_ContainerManager.cxx | 2 +- .../SALOME_ResourcesCatalog_Handler.cxx | 173 +++++--- .../SALOME_ResourcesCatalog_Handler.hxx | 44 +- .../SALOME_ResourcesCatalog_Parser.hxx | 1 + .../SALOME_ResourcesManager.cxx | 383 +++++++++++------- .../SALOME_ResourcesManager.hxx | 9 +- 9 files changed, 352 insertions(+), 264 deletions(-) diff --git a/bin/appliskel/runAppli b/bin/appliskel/runAppli index 590947e82..39083ff01 100755 --- a/bin/appliskel/runAppli +++ b/bin/appliskel/runAppli @@ -35,6 +35,7 @@ searchFreePort() { local myhost=`hostname` export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg export NSPORT + export NSHOST=${myhost} local initref="NameService=corbaname::"`hostname`":$NSPORT" #echo "ORBInitRef $initref" > $OMNIORB_CONFIG echo "InitRef = $initref" > $OMNIORB_CONFIG diff --git a/bin/appliskel/runRemote.sh b/bin/appliskel/runRemote.sh index 84a125765..d3297a6c5 100755 --- a/bin/appliskel/runRemote.sh +++ b/bin/appliskel/runRemote.sh @@ -44,6 +44,8 @@ export APPLI # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_$1_$2.cfg +export NSHOST=$1 +export NSPORT=$2 initref="NameService=corbaname::"$1":$2" echo "ORBInitRef $initref" > $OMNIORB_CONFIG diff --git a/bin/appliskel/runTests b/bin/appliskel/runTests index ac202508d..487b4a302 100755 --- a/bin/appliskel/runTests +++ b/bin/appliskel/runTests @@ -35,6 +35,7 @@ searchFreePort() { local myhost=`hostname` export OMNIORB_CONFIG=${HOME}/${APPLI}/.omniORB_${myhost}_${NSPORT}.cfg export NSPORT + export NSHOST=${myhost} local initref="NameService=corbaname::"`hostname`":$NSPORT" #echo "ORBInitRef $initref" > $OMNIORB_CONFIG echo "InitRef = $initref" > $OMNIORB_CONFIG diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index d25196395..de43d8696 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -137,7 +137,7 @@ FindOrStartContainer(const Engines::MachineParameters& params, } else command = - _ResManager->BuildTempFileToLaunchRemoteContainer(theMachine,params); + _ResManager->BuildCommandToLaunchRemoteContainer(theMachine,params); _ResManager->RmTmpFile(); int status=system(command.c_str()); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx index 8ccecdb3f..f635431c7 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.cxx @@ -34,10 +34,13 @@ using namespace std; -//---------------------------------------------------------------------- -//Function : SALOME_ResourcesCatalog_Handler -//Purpose: Constructor -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Constructor + * \param listOfResources: map of ParserResourcesType to fill when parsing + */ +//============================================================================= + SALOME_ResourcesCatalog_Handler:: SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): _resources_list(listOfResources) @@ -52,6 +55,7 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): test_protocol = "protocol"; test_mode = "mode"; test_user_name = "userName"; + test_appli_path = "appliPath"; test_modules = "modules"; test_module_name = "moduleName"; test_module_path = "modulePath"; @@ -63,41 +67,59 @@ SALOME_ResourcesCatalog_Handler(MapOfParserResourcesType& listOfResources): test_nb_of_proc_per_node = "nbOfProcPerNode"; } -//---------------------------------------------------------------------- -//Function : ~SALOME_ResourcesCatalog_Handler -//Purpose: Destructor -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + SALOME_ResourcesCatalog_Handler::~SALOME_ResourcesCatalog_Handler() { MESSAGE("SALOME_ResourcesCatalog_Handler destruction"); } -//---------------------------------------------------------------------- -//Function : GetResourcesAfterParsing -//Purpose: Retrieves DS after the file parse. -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Retrieves DS after the file parse. + */ +//============================================================================= + const MapOfParserResourcesType& SALOME_ResourcesCatalog_Handler::GetResourcesAfterParsing() const { return _resources_list; } -//---------------------------------------------------------------------- -//Function : startDocument -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function startDocument. + * Called before an xml file is parsed. + * Clears the list of resources. + * \return true (if no error detected...) + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler::startDocument() { MESSAGE("Begin parse document"); - // Empty private elements + + // --- Empty private elements + _resources_list.clear(); return true; } -//---------------------------------------------------------------------- -//Function : startElement -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function startElement. + * \param QString argument by reference (not used here ?) + * \param QString argument by reference (not used here ?) + * \param name (not used here ?) + * \param atts + * \return true if no error was detected + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler:: startElement( const QString&, @@ -159,6 +181,9 @@ startElement( const QString&, if ((qName.compare(QString(test_user_name)) == 0)) _resource.UserName = content; + if ((qName.compare(QString(test_appli_path)) == 0)) + _resource.AppliPath = content; + if ((qName.compare(QString(test_module_name)) == 0)) previous_module_name = content; @@ -187,10 +212,16 @@ startElement( const QString&, return true; } -//---------------------------------------------------------------------- -//Function : endElement -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function endElement. + * \param QString argument by reference (not used here ?) + * \param QString argument by reference (not used here ?) + * \param qName + * \return true (if no error detected ...) + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler:: endElement(const QString&, const QString&, @@ -205,56 +236,71 @@ endElement(const QString&, return true; } -//---------------------------------------------------------------------- -//Function : characters -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function characters. + * fills the private attribute string 'content'. + * \param chars + * \return true (if no error detected ...) + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler::characters(const QString& chars) { content = (const char *)chars ; return true; } -//---------------------------------------------------------------------- -//Function : endDocument -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function endDocument. + * Called after the document has been parsed. + * \return true (if no error detected ...) + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler::endDocument() { - //_resources_list - // for (unsigned int ind = 0; ind < _resources_list.size(); ind++) - // { - // MESSAGE("Resources name :"<<_resources_list[ind].Parsername); - // MESSAGE("OS :"<<_resources_list[ind].ParserOS); - // MESSAGE("OS version :"<<_resources_list[ind].ParserOS_version); - // for (unsigned int i = 0; i < _resources_list[ind].Parserprocs.size(); i++) - // { - // MESSAGE("Proc number :" << _resources_list[ind].Parserprocs[i].Parsernumber); - // MESSAGE("Model name :" << _resources_list[ind].Parserprocs[i].Parsermodel_name); - // MESSAGE("CPU(MHz) :" << _resources_list[ind].Parserprocs[i].Parsercpu_mhz); - // MESSAGE("Cache :" << _resources_list[ind].Parserprocs[i].Parsercache_size); - // } - // for (unsigned int j = 0; j < _resources_list[ind].Parsercontainertype.size(); j++) - // MESSAGE("Container Type :" << _resources_list[ind].Parsercontainertype[j]); - // } + for (map::const_iterator iter = + _resources_list.begin(); + iter != _resources_list.end(); + iter++) + { + SCRUTE((*iter).second.Alias); + SCRUTE((*iter).second.UserName); + SCRUTE((*iter).second.AppliPath); + SCRUTE((*iter).second.PreReqFilePath); + SCRUTE((*iter).second.OS); + SCRUTE((*iter).second.Protocol); + SCRUTE((*iter).second.Mode); + } + MESSAGE("This is the end of document"); return true; } -//---------------------------------------------------------------------- -//Function : errorProtocol -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function errorProtocol. + * \return the error message. + */ +//============================================================================= + QString SALOME_ResourcesCatalog_Handler::errorProtocol() { - INFOS(" ------------- error protocole !"); + INFOS(" ------------- error protocol !"); return errorProt; } -//---------------------------------------------------------------------- -//Function : fatalError -//Purpose: overload handler function -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Overload handler function fatalError. + * Fills the private string errorProt with details on error. + * \param exception from parser + * \return boolean (meaning ?) + */ +//============================================================================= + bool SALOME_ResourcesCatalog_Handler::fatalError (const QXmlParseException& exception) @@ -268,10 +314,13 @@ SALOME_ResourcesCatalog_Handler::fatalError return QXmlDefaultHandler::fatalError( exception ); } -//---------------------------------------------------------------------- -//Function : FillDocument -//Purpose: Fill the document tree in xml file, used to write in xml file. -//---------------------------------------------------------------------- +//============================================================================= +/*! + * Fill the document tree in xml file, used to write in an xml file. + * \param doc document to fill. + */ +//============================================================================= + void SALOME_ResourcesCatalog_Handler::PrepareDocToXmlFile(QDomDocument& doc) { QDomElement root = doc.createElement("resources"); diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx index f97191e22..c450cfce8 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Handler.hxx @@ -43,69 +43,28 @@ 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 QString errorProtocol(); virtual bool fatalError(const QXmlParseException& exception); - //! method to fill the document to be writen in a file void PrepareDocToXmlFile(QDomDocument& doc); private : @@ -125,6 +84,7 @@ class SALOME_ResourcesCatalog_Handler : public QXmlDefaultHandler const char *test_protocol; const char *test_mode; const char *test_user_name; + const char *test_appli_path; const char *test_modules; const char *test_module_name; const char *test_module_path; diff --git a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx index 212462ddd..d81c1d4f1 100755 --- a/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx +++ b/src/ResourcesManager/SALOME_ResourcesCatalog_Parser.hxx @@ -75,6 +75,7 @@ struct ParserResourcesType AccessProtocolType Protocol; AccessModeType Mode; std::string UserName; + std::string AppliPath; MapOfModulesPath ModulesPath; std::string PreReqFilePath; std::string OS; diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 7e1ed8f5b..88ff54e84 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -35,8 +35,8 @@ using namespace std; SALOME_ResourcesManager:: SALOME_ResourcesManager(CORBA::ORB_ptr orb, - const char *xmlFilePath) : - _path_resources(xmlFilePath) + const char *xmlFilePath) : + _path_resources(xmlFilePath) { _NS = new SALOME_NamingService(orb); } @@ -55,12 +55,22 @@ SALOME_ResourcesManager(CORBA::ORB_ptr orb, 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"; + _isAppliSalomeDefined = (getenv("APPLI") != 0); + + if (_isAppliSalomeDefined) + { + _path_resources = getenv("HOME"); + _path_resources += "/"; + _path_resources += getenv("APPLI"); + _path_resources += "/CatalogResources.xml"; + } + + else + { + _path_resources = getenv("KERNEL_ROOT_DIR"); + _path_resources += "/share/salome/resources/CatalogResources.xml"; + } + ParseXmlFile(); } @@ -86,7 +96,6 @@ SALOME_ResourcesManager::~SALOME_ResourcesManager() * - 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) - * */ //============================================================================= @@ -119,7 +128,7 @@ throw(SALOME_Exception) else if (_resourcesList.find(hostname) != _resourcesList.end()) { - // --- params.hostame is in the list of resources so return it. + // --- params.hostname is in the list of resources so return it. ret.push_back(hostname); } @@ -137,14 +146,19 @@ throw(SALOME_Exception) SelectOnlyResourcesWithOS(ret, params.OS); KeepOnlyResourcesWithModule(ret, moduleName); + if (ret.size() == 0) - SelectOnlyResourcesWithOS(ret, params.OS); + 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; @@ -171,9 +185,7 @@ 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. - * + * Return 0 if OK (KERNEL found in new resources modules) else throw exception */ //============================================================================= @@ -215,7 +227,6 @@ throw(SALOME_Exception) throw SALOME_Exception("KERNEL is not present in this resource"); } - //============================================================================= /*! * Deletes a resource from the catalog @@ -227,7 +238,6 @@ void SALOME_ResourcesManager::DeleteResourceInCatalog(const char *hostname) _resourcesList.erase(hostname); } - //============================================================================= /*! * write the current data in memory in file. @@ -241,10 +251,11 @@ void SALOME_ResourcesManager::WriteInXmlFile() new SALOME_ResourcesCatalog_Handler(_resourcesList); handler->PrepareDocToXmlFile(doc); delete handler; + QFile file( _path_resources ); if ( !file.open( IO_WriteOnly ) ) - cout << "WRITING ERROR !!!" << endl; + INFOS("WRITING ERROR !"); QTextStream ts( &file ); @@ -252,10 +263,9 @@ void SALOME_ResourcesManager::WriteInXmlFile() file.close(); - cout << "WRITING DONE!!!" << endl; + MESSAGE("WRITING DONE!"); } - //============================================================================= /*! * parse the data type catalog @@ -279,44 +289,6 @@ const MapOfParserResourcesType& SALOME_ResourcesManager::ParseXmlFile() return _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; - return true; -} - - //============================================================================= /*! * consult the content of the list @@ -363,128 +335,95 @@ bool isPythonContainer(const char* ContainerName) //============================================================================= /*! - * builds in a temporary file the script to be launched + * Builds the script to be launched + * + * If SALOME Application not defined ($APPLI), + * see BuildTempFileToLaunchRemoteContainer() + * + * Else rely on distant configuration. Command is under the form (example): + * ssh user@machine distantPath/runRemote.sh hostNS portNS \ + * SALOME_Container containerName &" + + * - where user is ommited if not specified in CatalogResources, + * - where distant path is always relative to user@machine $HOME, and + * equal to $APPLI if not specified in CatalogResources, + * - where hostNS is the hostname of CORBA naming server (set by scripts to + * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh) + * - where portNS is the port used by CORBA naming server (set by scripts to + * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh) */ //============================================================================= string -SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer +SALOME_ResourcesManager::BuildCommandToLaunchRemoteContainer (const string& machine, const Engines::MachineParameters& params) { - // _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); - //Build command string command; - if (resInfo.Protocol == rsh) - { - command = "rsh "; - // string commandRcp="rcp "; - // commandRcp+=_TmpFileName; - // commandRcp+=" "; - // commandRcp+=machine; - // commandRcp+=":"; - // commandRcp+=_TmpFileName; - // system(commandRcp.c_str()); - } + if ( ! _isAppliSalomeDefined ) + command = BuildTempFileToLaunchRemoteContainer(machine, params); - else if (resInfo.Protocol == ssh) - command = "ssh "; else - throw SALOME_Exception("Unknown protocol"); + { + const ParserResourcesType& resInfo = _resourcesList[machine]; - // 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; + if (params.isMPI) + { + 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; + } - command += machine; // on suppose le même user par defaut + // "ssh user@machine distantPath/runRemote.sh hostNS portNS \ + // SALOME_Container containerName &" - command += " "; + if (resInfo.Protocol == rsh) + command = "rsh "; + else if (resInfo.Protocol == ssh) + command = "ssh "; + else + throw SALOME_Exception("Unknown protocol"); - command += getenv("APPLI"); // chemin relatif a $HOME + if (resInfo.UserName != "") + { + command += resInfo.UserName; + command += "@"; + } - command += "/runRemote.sh "; + command += machine; + command += " "; - command += GetHostname(); // ********** A CHANGER, le naming service n'est pas obligatoirement ici + if (resInfo.AppliPath != "") + command += resInfo.AppliPath; // path relative to user@machine $HOME + else + { + ASSERT(getenv("APPLI")); + command += getenv("APPLI"); // path relative to user@machine $HOME + } - command += " "; + command += "/runRemote.sh "; - command += getenv("NSPORT"); + ASSERT(getenv("NSHOST")); + command += getenv("NSHOST"); // hostname of CORBA name server - command += " SALOME_Container "; + command += " "; + ASSERT(getenv("NSPORT")); + command += getenv("NSPORT"); // port of CORBA name server - command += _NS->ContainerName(params); + command += " SALOME_Container "; + command += _NS->ContainerName(params); + command += "&"; - command += "&"; - - MESSAGE("command =" << command); + MESSAGE("command =" << command); + } return command; } @@ -588,6 +527,7 @@ SALOME_ResourcesManager::BuildCommand // 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) @@ -767,5 +707,134 @@ string SALOME_ResourcesManager::BuildTemporaryFileName() const } +//============================================================================= +/*! + * Builds in a temporary file the script to be launched. + * + * Used if SALOME Application ($APPLI) is not defined. + * The command is build with data from CatalogResources, in which every path + * used on remote computer must be defined. + */ +//============================================================================= + +string +SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer +(const string& machine, + const Engines::MachineParameters& params) +{ + _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); + + // --- Build command + + string command; + + if (resInfo.Protocol == rsh) + { + command = "rsh "; + string commandRcp = "rcp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += machine; + commandRcp += ":"; + commandRcp += _TmpFileName; + system(commandRcp.c_str()); + } + + 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 &"; + SCRUTE(command); + + return command; + +} + + diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 92c25367d..029c9fa9e 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -51,7 +51,7 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager std::string FindBest(const Engines::MachineList& listOfMachines); - std::string BuildTempFileToLaunchRemoteContainer + std::string BuildCommandToLaunchRemoteContainer (const std::string& machine, const Engines::MachineParameters& params); @@ -84,7 +84,9 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager private: SALOME_NamingService *_NS; - bool _verify_resources(MapOfParserResourcesType resourceslist); + std::string BuildTempFileToLaunchRemoteContainer + (const std::string& machine, + const Engines::MachineParameters& params); void SelectOnlyResourcesWithOS(std::vector& hosts, const char *OS) const @@ -115,6 +117,9 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager MapOfParserResourcesType _resourcesList; SALOME_LoadRateManager _dynamicResourcesSelecter; + + //! different behaviour if $APPLI exists (SALOME Application) + bool _isAppliSalomeDefined; }; #endif // RESSOURCESCATALOG_IMPL_H -- 2.39.2