From eda6d4900319aeca3570118060b8ed15a41e2e59 Mon Sep 17 00:00:00 2001 From: prascle Date: Fri, 24 Oct 2008 06:01:36 +0000 Subject: [PATCH] merge from branch BR41_BS tag after_merge_V4_1_0_maintainance_20080908 --- Makefile.am | 6 +- bin/appli_clean.sh | 2 +- configure.ac | 95 +++-- idl/SALOME_ContainerManager.idl | 8 +- resources/Makefile.am | 7 +- src/Batch/Batch_BatchManager_eClient.cxx | 41 ++- src/Batch/Batch_BatchManager_eClient.hxx | 2 +- src/Batch/Batch_BatchManager_eLSF.cxx | 58 ++- src/Batch/Batch_BatchManager_eLSF.hxx | 2 +- src/Batch/Batch_BatchManager_ePBS.cxx | 46 ++- src/Batch/Batch_BatchManager_ePBS.hxx | 2 +- src/Batch/Batch_BatchManager_eSGE.cxx | 330 ++++++++++++++++++ src/Batch/Batch_BatchManager_eSGE.hxx | 92 +++++ src/Batch/Batch_FactBatchManager.cxx | 4 +- src/Batch/Batch_FactBatchManager_eSGE.cxx | 64 ++++ src/Batch/Batch_FactBatchManager_eSGE.hxx | 60 ++++ src/Batch/Batch_JobInfo_eSGE.cxx | 111 ++++++ src/Batch/Batch_JobInfo_eSGE.hxx | 69 ++++ src/Batch/Makefile.am | 23 +- src/Batch/MpiImpl.cxx | 4 +- src/Launcher/BatchTest.cxx | 25 +- src/Launcher/Launcher.cxx | 320 +++++++++++++---- src/Launcher/Launcher.hxx | 18 +- src/Launcher/Makefile.am | 28 +- src/Launcher/SALOME_Launcher.cxx | 50 ++- src/Launcher/SALOME_Launcher.hxx | 6 + src/Launcher/SALOME_Launcher_Handler.cxx | 168 +++++++++ src/Launcher/SALOME_Launcher_Handler.hxx | 69 ++++ src/Launcher/SALOME_Launcher_Parser.cxx | 77 ++++ src/Launcher/SALOME_Launcher_Parser.hxx | 58 +++ src/Makefile.am | 7 +- src/ResourcesManager/Makefile.am | 6 +- src/ResourcesManager/ResourcesManager.cxx | 38 +- src/ResourcesManager/ResourcesManager.hxx | 2 +- .../SALOME_ResourcesCatalog_Handler.cxx | 18 +- .../SALOME_ResourcesCatalog_Parser.cxx | 2 +- .../SALOME_ResourcesCatalog_Parser.hxx | 4 +- .../SALOME_ResourcesManager.cxx | 10 +- 38 files changed, 1713 insertions(+), 219 deletions(-) create mode 100644 src/Batch/Batch_BatchManager_eSGE.cxx create mode 100644 src/Batch/Batch_BatchManager_eSGE.hxx create mode 100644 src/Batch/Batch_FactBatchManager_eSGE.cxx create mode 100644 src/Batch/Batch_FactBatchManager_eSGE.hxx create mode 100644 src/Batch/Batch_JobInfo_eSGE.cxx create mode 100644 src/Batch/Batch_JobInfo_eSGE.hxx create mode 100755 src/Launcher/SALOME_Launcher_Handler.cxx create mode 100755 src/Launcher/SALOME_Launcher_Handler.hxx create mode 100644 src/Launcher/SALOME_Launcher_Parser.cxx create mode 100755 src/Launcher/SALOME_Launcher_Parser.hxx diff --git a/Makefile.am b/Makefile.am index 54cd716fe..a49a0cc21 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,11 @@ endif ACLOCAL_AMFLAGS = -I salome_adm/unix/config_files -SUBDIRS = salome_adm $(IDLDIR) src doc bin resources +if WITHONLYLAUNCHER + SUBDIRS = src resources +else + SUBDIRS = salome_adm $(IDLDIR) src doc bin resources +endif DIST_SUBDIRS= salome_adm idl src doc bin resources diff --git a/bin/appli_clean.sh b/bin/appli_clean.sh index 169a56622..16abf0758 100644 --- a/bin/appli_clean.sh +++ b/bin/appli_clean.sh @@ -20,4 +20,4 @@ # #clean appli -rm -rf bin lib share doc env.d envd getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml *.pyc *~ .bashrc +rm -rf bin lib share doc idl env.d envd getAppliPath.py searchFreePort.sh runAppli runConsole runSession runRemote.sh runTests SalomeApp.xml *.pyc *~ .bashrc diff --git a/configure.ac b/configure.ac index ce460dfa2..46c0db90a 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,12 @@ AC_ARG_ENABLE(corba_gen, esac],[corba_gen=true]) AM_CONDITIONAL(CORBA_GEN, test x$corba_gen = xtrue) +# ---- option to build only launcher, resources manager and batch classes +AC_ARG_WITH(onlylauncher, + --with-onlylauncher, + WITHONLYLAUNCHER="yes",WITHONLYLAUNCHER="no") +AM_CONDITIONAL(WITHONLYLAUNCHER, test x$WITHONLYLAUNCHER = xyes) + # ---------------------------------------------------------------------------- echo @@ -172,6 +178,15 @@ dnl _CS_gbo We should use here a variable given from the CHECK_PYTHON AM_PATH_PYTHON(2.3) CHECK_SWIG +echo +echo --------------------------------------------- +echo Testing libxml2 +echo --------------------------------------------- +echo + +CHECK_LIBXML + +if test x$WITHONLYLAUNCHER = xno; then echo echo --------------------------------------------- echo testing HDF5 @@ -236,18 +251,14 @@ echo CHECK_BOOST -echo -echo --------------------------------------------- -echo Testing libxml2 -echo --------------------------------------------- -echo - -CHECK_LIBXML - fi # --- end test corba # ---------------------------------------------------------------------------- +fi +# --- end test ONLYLAUNCHER +# ---------------------------------------------------------------------------- + echo echo ============================================================ echo testing parallel products @@ -408,10 +419,14 @@ function check_fatal_error { # -------------------------------------- -if test x$corba_gen = xtrue; then - basic_mandatory_products="cc_ok threads_ok python_ok swig_ok hdf5_ok" +if test x$WITHONLYLAUNCHER = xno; then + if test x$corba_gen = xtrue; then + basic_mandatory_products="cc_ok threads_ok python_ok swig_ok hdf5_ok libxml_ok" + else + basic_mandatory_products="cc_ok threads_ok hdf5_ok libxml_ok" + fi else - basic_mandatory_products="cc_ok threads_ok hdf5_ok" + basic_mandatory_products="cc_ok threads_ok libxml_ok" fi echo --- General mandatory products - Light configuration: @@ -419,19 +434,21 @@ summary $basic_mandatory_products check_fatal_error $basic_mandatory_products echo -corba_mandatory_products="omniORB_ok omniORBpy_ok boost_ok libxml_ok" -if test x$corba_gen = xtrue; then - echo --- CORBA mandatory products - default configuration: - summary $corba_mandatory_products - check_fatal_error $corba_mandatory_products -else - echo --- CORBA products not required - option --disable-corba-gen - if test x"$WITH_BATCH" = xyes; then - echo --- BATCH mode mandatory products - default configuration: - summary "python_ok" - check_fatal_error "python_ok" - else +if test x$WITHONLYLAUNCHER = xno; then + corba_mandatory_products="omniORB_ok omniORBpy_ok boost_ok" + if test x$corba_gen = xtrue; then + echo --- CORBA mandatory products - default configuration: + summary $corba_mandatory_products + check_fatal_error $corba_mandatory_products + else + echo --- CORBA products not required - option --disable-corba-gen + if test x"$WITH_BATCH" = xyes; then + echo --- BATCH mode mandatory products - default configuration: + summary "python_ok" + check_fatal_error "python_ok" + else echo --- Python not required - option --enable-batch=no + fi fi fi echo @@ -454,9 +471,11 @@ echo --- Html documentation products: only required for doc production summary $htmldoc_products echo +if test x$WITHONLYLAUNCHER = xno; then echo echo "Default ORB : $DEFAULT_ORB" echo +fi dnl generals files which could be included in every makefile @@ -475,6 +494,35 @@ else AC_SUBST(SETX) SETX="set -x" fi +if test x$WITHONLYLAUNCHER = xno; then +echo +echo --------------------------------------------- +echo copying resource files, shell scripts, and +echo xml files +echo --------------------------------------------- +echo + + +mkdir -p bin/salome +cd bin/salome +for i in `find $ROOT_SRCDIR/bin` +do + local_bin=`echo $i | sed -e "s,$ROOT_SRCDIR/bin,.,"` + case "$local_bin" in + *.in | *~) ;; + . | */CVS | */CVS/* | ./salome) ;; + ./appliskel |./appliskel/env.d) $INSTALL -d $local_bin ; echo $local_bin ;; + *) $INSTALL $i $local_bin; echo $local_bin ;; + esac +done +cd $ROOT_BUILDDIR + +AC_OUTPUT_COMMANDS([ \ + chmod +x ./bin/*; \ + chmod +x ./bin/salome/* \ +]) +fi + echo echo --------------------------------------------- echo generating Makefiles and configure files @@ -561,4 +609,3 @@ AC_OUTPUT([ \ ./src/Utils/Makefile \ ./src/Utils/Test/Makefile \ ]) - diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index d4623c160..01942e44a 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -89,14 +89,16 @@ struct BatchParameters */ interface SalomeLauncher { + long submitJob( in string xmlExecuteFile, + in string clusterName ) raises (SALOME::SALOME_Exception); long submitSalomeJob( in string fileToExecute, in FilesList filesToExport, in FilesList filesToImport, in BatchParameters batch_params, in MachineParameters params ) raises (SALOME::SALOME_Exception); - string querySalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void deleteSalomeJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); - void getResultSalomeJob( in string directory, in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + string queryJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + void deleteJob( in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); + void getResultsJob( in string directory, in long jobId, in MachineParameters params ) raises (SALOME::SALOME_Exception); boolean testBatch(in MachineParameters params) raises (SALOME::SALOME_Exception); diff --git a/resources/Makefile.am b/resources/Makefile.am index 687202153..76ad823d8 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -33,10 +33,15 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am DEPRECATED_FILES= -dist_salomeres_DATA=\ +if WITHONLYLAUNCHER + dist_salomeres_DATA=\ + CatalogResources.xml +else + dist_salomeres_DATA=\ CatalogResources.xml \ config \ channel.cfg \ KERNELCatalog.xml \ SALOMEDS_Resources \ $(DEPRECATED_FILES) +endif diff --git a/src/Batch/Batch_BatchManager_eClient.cxx b/src/Batch/Batch_BatchManager_eClient.cxx index f8684f26a..17355739c 100644 --- a/src/Batch/Batch_BatchManager_eClient.cxx +++ b/src/Batch/Batch_BatchManager_eClient.cxx @@ -96,24 +96,27 @@ namespace Batch { // Second step : copy fileToExecute into // batch tmp files directory - command = copy_command; - command += string(params[EXECUTABLE]); - command += " "; - if(_username != ""){ - command += _username; - command += "@"; - } - command += _hostname; - command += ":"; - command += string(params[TMPDIR]); - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) { - std::ostringstream oss; - oss << status; - std::string ex_mess("Error of connection on remote host ! status = "); - ex_mess += oss.str(); - throw EmulationException(ex_mess.c_str()); + string executeFile = params[EXECUTABLE]; + if( executeFile.size() > 0 ){ + command = copy_command; + command += string(params[EXECUTABLE]); + command += " "; + if(_username != ""){ + command += _username; + command += "@"; + } + command += _hostname; + command += ":"; + command += string(params[TMPDIR]); + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status) { + std::ostringstream oss; + oss << status; + std::string ex_mess("Error of connection on remote host ! status = "); + ex_mess += oss.str(); + throw EmulationException(ex_mess.c_str()); + } } // Third step : copy filesToExportList into @@ -200,6 +203,8 @@ namespace Batch { return new MpiImpl_OPENMPI(); else if(mpiImpl == "slurm") return new MpiImpl_SLURM(); + else if(mpiImpl == "nompi") + throw EmulationException("you must specified an mpi implementation for batch manager"); else{ ostringstream oss; oss << mpiImpl << " : not yet implemented"; diff --git a/src/Batch/Batch_BatchManager_eClient.hxx b/src/Batch/Batch_BatchManager_eClient.hxx index f3d27c406..2deb3cc5c 100644 --- a/src/Batch/Batch_BatchManager_eClient.hxx +++ b/src/Batch/Batch_BatchManager_eClient.hxx @@ -53,7 +53,7 @@ namespace Batch { { public: // Constructeur et destructeur - BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host="localhost", const char* protocol="ssh", const char* mpiImpl="indif"); + BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host="localhost", const char* protocol="ssh", const char* mpiImpl="mpich1"); virtual ~BatchManager_eClient(); void importOutputFiles( const Job & job, const std::string directory ) throw(EmulationException); diff --git a/src/Batch/Batch_BatchManager_eLSF.cxx b/src/Batch/Batch_BatchManager_eLSF.cxx index 406466192..0b359eae2 100644 --- a/src/Batch/Batch_BatchManager_eLSF.cxx +++ b/src/Batch/Batch_BatchManager_eLSF.cxx @@ -62,9 +62,14 @@ namespace Batch { Parametre params = job.getParametre(); const std::string dirForTmpFiles = params[TMPDIR]; const string fileToExecute = params[EXECUTABLE]; - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + std::string fileNameToExecute; + if( fileToExecute.size() > 0 ){ + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + } + else + fileNameToExecute = "command"; // export input files on cluster exportInputFiles(job); @@ -240,19 +245,29 @@ namespace Batch { #ifndef WIN32 //TODO: need for porting on Windows int status; Parametre params = job.getParametre(); + Environnement env = job.getEnvironnement(); const int nbproc = params[NBPROC]; const long edt = params[MAXWALLTIME]; const long mem = params[MAXRAMSIZE]; const string workDir = params[WORKDIR]; const std::string dirForTmpFiles = params[TMPDIR]; const string fileToExecute = params[EXECUTABLE]; - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - std::string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - std::string fileNameToExecute = "~/" + dirForTmpFiles + "/" + string(basename(fileToExecute.c_str())); - - int idx = dirForTmpFiles.find("Batch/"); - std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + const string home = params[HOMEDIR]; + std::string rootNameToExecute; + std::string fileNameToExecute; + std::string filelogtemp; + if( fileToExecute.size() > 0 ){ + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + fileNameToExecute = "~/" + dirForTmpFiles + "/" + string(basename(fileToExecute.c_str())); + + int idx = dirForTmpFiles.find("Batch/"); + filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + } + else{ + rootNameToExecute = "command"; + } std::string TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; @@ -264,13 +279,26 @@ namespace Batch { if( mem > 0 ) tempOutputFile << "#BSUB -M " << mem*1024 << endl ; tempOutputFile << "#BSUB -n " << nbproc << endl ; - tempOutputFile << "#BSUB -o runSalome.output.log." << filelogtemp << endl ; - tempOutputFile << "#BSUB -e runSalome.error.log." << filelogtemp << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << "#BSUB -o " << home << "/" << dirForTmpFiles << "/output.log." << filelogtemp << endl ; + tempOutputFile << "#BSUB -e " << home << "/" << dirForTmpFiles << "/error.log." << filelogtemp << endl ; + } + else{ + tempOutputFile << "#BSUB -o " << dirForTmpFiles << "/" << env["LOGFILE"] << ".output.log" << endl ; + tempOutputFile << "#BSUB -e " << dirForTmpFiles << "/" << env["LOGFILE"] << ".error.log" << endl ; + } if( workDir.size() > 0 ) tempOutputFile << "cd " << workDir << endl ; - tempOutputFile << _mpiImpl->boot("",nbproc); - tempOutputFile << _mpiImpl->run("",nbproc,fileNameToExecute); - tempOutputFile << _mpiImpl->halt(); + if( fileToExecute.size() > 0 ){ + tempOutputFile << _mpiImpl->boot("",nbproc); + tempOutputFile << _mpiImpl->run("",nbproc,fileNameToExecute); + tempOutputFile << _mpiImpl->halt(); + } + else{ + tempOutputFile << "source " << env["SOURCEFILE"] << endl ; + tempOutputFile << env["COMMAND"]; + } + tempOutputFile.flush(); tempOutputFile.close(); #ifdef WIN32 diff --git a/src/Batch/Batch_BatchManager_eLSF.hxx b/src/Batch/Batch_BatchManager_eLSF.hxx index 9673d1a1e..851deda76 100644 --- a/src/Batch/Batch_BatchManager_eLSF.hxx +++ b/src/Batch/Batch_BatchManager_eLSF.hxx @@ -53,7 +53,7 @@ namespace Batch { { public: // Constructeur et destructeur - BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="indif") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="nompi") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host virtual ~BatchManager_eLSF(); // Recupere le nom du serveur par defaut diff --git a/src/Batch/Batch_BatchManager_ePBS.cxx b/src/Batch/Batch_BatchManager_ePBS.cxx index 8ac732099..2f3bf1824 100644 --- a/src/Batch/Batch_BatchManager_ePBS.cxx +++ b/src/Batch/Batch_BatchManager_ePBS.cxx @@ -239,6 +239,7 @@ namespace Batch { #ifndef WIN32 //TODO: need for porting on Windows int status; Parametre params = job.getParametre(); + Environnement env = job.getEnvironnement(); const long nbproc = params[NBPROC]; const long edt = params[MAXWALLTIME]; const long mem = params[MAXRAMSIZE]; @@ -246,13 +247,21 @@ namespace Batch { const std::string dirForTmpFiles = params[TMPDIR]; const string fileToExecute = params[EXECUTABLE]; const string home = params[HOMEDIR]; - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - std::string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - std::string fileNameToExecute = "~/" + dirForTmpFiles + "/" + string(basename(fileToExecute.c_str())); - - int idx = dirForTmpFiles.find("Batch/"); - std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + std::string rootNameToExecute; + std::string fileNameToExecute; + std::string filelogtemp; + if( fileToExecute.size() > 0 ){ + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + fileNameToExecute = "~/" + dirForTmpFiles + "/" + string(basename(fileToExecute.c_str())); + + int idx = dirForTmpFiles.find("Batch/"); + filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + } + else{ + rootNameToExecute = "command"; + } std::string TmpFileName = BuildTemporaryFileName(); ofstream tempOutputFile; @@ -263,13 +272,26 @@ namespace Batch { tempOutputFile << "#PBS -l walltime=" << edt*60 << endl ; if( mem > 0 ) tempOutputFile << "#PBS -l mem=" << mem << "mb" << endl ; - tempOutputFile << "#PBS -o " << home << "/" << dirForTmpFiles << "/runSalome.output.log." << filelogtemp << endl ; - tempOutputFile << "#PBS -e " << home << "/" << dirForTmpFiles << "/runSalome.error.log." << filelogtemp << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << "#PBS -o " << home << "/" << dirForTmpFiles << "/output.log." << filelogtemp << endl ; + tempOutputFile << "#PBS -e " << home << "/" << dirForTmpFiles << "/error.log." << filelogtemp << endl ; + } + else{ + tempOutputFile << "#PBS -o " << dirForTmpFiles << "/" << env["LOGFILE"] << ".output.log" << endl ; + tempOutputFile << "#PBS -e " << dirForTmpFiles << "/" << env["LOGFILE"] << ".error.log" << endl ; + } if( workDir.size() > 0 ) tempOutputFile << "cd " << workDir << endl ; - tempOutputFile << _mpiImpl->boot("${PBS_NODEFILE}",nbproc); - tempOutputFile << _mpiImpl->run("${PBS_NODEFILE}",nbproc,fileNameToExecute); - tempOutputFile << _mpiImpl->halt(); + if( fileToExecute.size() > 0 ){ + tempOutputFile << _mpiImpl->boot("${PBS_NODEFILE}",nbproc); + tempOutputFile << _mpiImpl->run("${PBS_NODEFILE}",nbproc,fileNameToExecute); + tempOutputFile << _mpiImpl->halt(); + } + else{ + tempOutputFile << "source " << env["SOURCEFILE"] << endl ; + tempOutputFile << env["COMMAND"]; + } + tempOutputFile.flush(); tempOutputFile.close(); #ifdef WIN32 diff --git a/src/Batch/Batch_BatchManager_ePBS.hxx b/src/Batch/Batch_BatchManager_ePBS.hxx index 2bfa60a1a..6f835fced 100644 --- a/src/Batch/Batch_BatchManager_ePBS.hxx +++ b/src/Batch/Batch_BatchManager_ePBS.hxx @@ -53,7 +53,7 @@ namespace Batch { { public: // Constructeur et destructeur - BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="indif") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="nompi") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host virtual ~BatchManager_ePBS(); // Recupere le nom du serveur par defaut diff --git a/src/Batch/Batch_BatchManager_eSGE.cxx b/src/Batch/Batch_BatchManager_eSGE.cxx new file mode 100644 index 000000000..429f3c13d --- /dev/null +++ b/src/Batch/Batch_BatchManager_eSGE.cxx @@ -0,0 +1,330 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * BatchManager_eSGE.cxx : emulation of SGE client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include +#include +#include +#include "Batch_BatchManager_eSGE.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_eSGE::BatchManager_eSGE(const FactBatchManager * parent, const char * host, const char * protocol, const char * mpiImpl) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_eClient(parent,host,protocol,mpiImpl) + { + // Nothing to do + } + + // Destructeur + BatchManager_eSGE::~BatchManager_eSGE() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_eSGE::submitJob(const Job & job) + { + int status; + Parametre params = job.getParametre(); + const std::string dirForTmpFiles = params[TMPDIR]; + const string fileToExecute = params[EXECUTABLE]; + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + + // export input files on cluster + exportInputFiles(job); + + // build batch script for job + buildBatchScript(job); + + // define name of log file + string logFile="/tmp/logs/"; + logFile += getenv("USER"); + logFile += "/batchSalome_"; + srand ( time(NULL) ); + int ir = rand(); + ostringstream oss; + oss << ir; + logFile += oss.str(); + logFile += ".log"; + + string command; + + // define command to submit batch + command = _protocol; + command += " "; + + if(_username != ""){ + command += _username; + command += "@"; + } + + command += _hostname; + command += " \"cd " ; + command += dirForTmpFiles ; + command += "; qsub " ; + command += fileNameToExecute ; + command += "_Batch.sh\" > "; + command += logFile; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status) + throw EmulationException("Error of connection on remote host"); + + // read id of submitted job in log file + char line[128]; + FILE *fp = fopen(logFile.c_str(),"r"); + fgets( line, 128, fp); + fclose(fp); + + string strjob; + istringstream iss(line); + iss >> strjob >> strjob >> strjob; + + JobId id(this, strjob); + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_eSGE::deleteJob(const JobId & jobid) + { + int status; + int ref; + istringstream iss(jobid.getReference()); + iss >> ref; + + // define command to submit batch + string command; + command = _protocol; + command += " "; + + if (_username != ""){ + command += _username; + command += "@"; + } + + command += _hostname; + command += " \"qdel " ; + command += iss.str(); + command += "\""; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status) + throw EmulationException("Error of connection on remote host"); + + cerr << "jobId = " << ref << "killed" << endl; + } + + // Methode pour le controle des jobs : suspend un job en file d'attente + void BatchManager_eSGE::holdJob(const JobId & jobid) + { + throw EmulationException("Not yet implemented"); + } + + // Methode pour le controle des jobs : relache un job suspendu + void BatchManager_eSGE::releaseJob(const JobId & jobid) + { + throw EmulationException("Not yet implemented"); + } + + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSGE::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + throw EmulationException("Not yet implemented"); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSGE::alterJob(const JobId & jobid, const Parametre & param) + { + alterJob(jobid, param, Environnement()); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSGE::alterJob(const JobId & jobid, const Environnement & env) + { + alterJob(jobid, Parametre(), env); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_eSGE::queryJob(const JobId & jobid) + { + int id; + istringstream iss(jobid.getReference()); + iss >> id; + + // define name of log file + string logFile="/tmp/logs/"; + logFile += getenv("USER"); + logFile += "/batchSalome_"; + + ostringstream oss; + oss << this << "_" << id; + logFile += oss.str(); + logFile += ".log"; + + string command; + int status; + + // define command to submit batch + command = _protocol; + command += " "; + + if (_username != ""){ + command += _username; + command += "@"; + } + + command += _hostname; + command += " \"qstat | grep " ; + command += iss.str(); + command += "\" > "; + command += logFile; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status && status != 256) + throw EmulationException("Error of connection on remote host"); + + JobInfo_eSGE ji = JobInfo_eSGE(id,logFile); + return ji; + } + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_eSGE::isRunning(const JobId & jobid) + { + throw EmulationException("Not yet implemented"); + } + + void BatchManager_eSGE::buildBatchScript(const Job & job) throw(EmulationException) + { + int status; + Parametre params = job.getParametre(); + Environnement env = job.getEnvironnement(); + const long nbproc = params[NBPROC]; + const long edt = params[MAXWALLTIME]; + const long mem = params[MAXRAMSIZE]; + const string workDir = params[WORKDIR]; + const std::string dirForTmpFiles = params[TMPDIR]; + const string fileToExecute = params[EXECUTABLE]; + const string home = params[HOMEDIR]; + std::string rootNameToExecute; + std::string fileNameToExecute; + std::string filelogtemp; + if( fileToExecute.size() > 0 ){ + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + fileNameToExecute = "~/" + dirForTmpFiles + "/" + string(basename(fileToExecute.c_str())); + + int idx = dirForTmpFiles.find("Batch/"); + filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + } + else{ + rootNameToExecute = "command"; + } + + std::string TmpFileName = BuildTemporaryFileName(); + ofstream tempOutputFile; + tempOutputFile.open(TmpFileName.c_str(), ofstream::out ); + + tempOutputFile << "#! /bin/sh -f" << endl; + tempOutputFile << "#$ -pe mpich " << nbproc << endl; + if( edt > 0 ) + tempOutputFile << "#$ -l h_rt=" << getWallTime(edt) << endl ; + if( mem > 0 ) + tempOutputFile << "#$ -l h_vmem=" << mem << "M" << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << "#$ -o " << home << "/" << dirForTmpFiles << "/output.log." << filelogtemp << endl ; + tempOutputFile << "#$ -e " << home << "/" << dirForTmpFiles << "/error.log." << filelogtemp << endl ; + } + else{ + tempOutputFile << "#$ -o " << dirForTmpFiles << "/" << env["LOGFILE"] << ".output.log" << endl ; + tempOutputFile << "#$ -e " << dirForTmpFiles << "/" << env["LOGFILE"] << ".error.log" << endl ; + } + if( workDir.size() > 0 ) + tempOutputFile << "cd " << workDir << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << _mpiImpl->boot("",nbproc); + tempOutputFile << _mpiImpl->run("${TMPDIR}/machines",nbproc,fileNameToExecute); + tempOutputFile << _mpiImpl->halt(); + } + else{ + tempOutputFile << "source " << env["SOURCEFILE"] << endl ; + tempOutputFile << env["COMMAND"]; + } + + tempOutputFile.flush(); + tempOutputFile.close(); + chmod(TmpFileName.c_str(), 0x1ED); + cerr << TmpFileName.c_str() << endl; + + string command; + if( _protocol == "rsh" ) + command = "rcp "; + else if( _protocol == "ssh" ) + command = "scp "; + else + throw EmulationException("Unknown protocol"); + command += TmpFileName; + command += " "; + if(_username != ""){ + command += _username; + command += "@"; + } + command += _hostname; + command += ":"; + command += dirForTmpFiles ; + command += "/" ; + command += rootNameToExecute ; + command += "_Batch.sh" ; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status) + throw EmulationException("Error of connection on remote host"); + + RmTmpFile(TmpFileName); + + } + + std::string BatchManager_eSGE::getWallTime(const long edt) + { + long h, m; + h = edt / 60; + m = edt - h*60; + ostringstream oss; + if( m >= 10 ) + oss << h << ":" << m; + else + oss << h << ":0" << m; + return oss.str(); + } + +} diff --git a/src/Batch/Batch_BatchManager_eSGE.hxx b/src/Batch/Batch_BatchManager_eSGE.hxx new file mode 100644 index 000000000..253ab5d42 --- /dev/null +++ b/src/Batch/Batch_BatchManager_eSGE.hxx @@ -0,0 +1,92 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * BatchManager_eSGE.hxx : emulation of SGE client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#ifndef _BATCHMANAGER_eLSF_H_ +#define _BATCHMANAGER_eLSF_H_ + +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_JobInfo_eSGE.hxx" +#include "Batch_InvalidArgumentException.hxx" +#include "Batch_ConnexionFailureException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_NotYetImplementedException.hxx" +#include "Batch_BatchManager.hxx" +#include "Batch_BatchManager_eClient.hxx" + +namespace Batch { + + class Job; + class JobId; + class JobInfo; + class FactBatchManager; + + class BatchManager_eSGE : public BatchManager_eClient + { + public: + // Constructeur et destructeur + BatchManager_eSGE(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="nompi") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + virtual ~BatchManager_eSGE(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente + virtual void releaseJob(const JobId & jobid); // relache un job suspendu + virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + + protected: + void buildBatchScript(const Job & job) throw(EmulationException); + std::string getWallTime(const long edt); + + private: + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/Batch/Batch_FactBatchManager.cxx b/src/Batch/Batch_FactBatchManager.cxx index 27b7f1c1f..514a8dd2d 100644 --- a/src/Batch/Batch_FactBatchManager.cxx +++ b/src/Batch/Batch_FactBatchManager.cxx @@ -28,9 +28,9 @@ #include #include +#include #include "Batch_BatchManagerCatalog.hxx" #include "Batch_FactBatchManager.hxx" -#include "utilities.h" using namespace std; namespace Batch { @@ -47,7 +47,7 @@ namespace Batch { */ ostringstream msg; msg << "FactBatchManager of type '" << type << "' inserted into catalog"; - MESSAGE(msg.str().c_str()); + cerr << msg.str().c_str() << endl; //#endif } diff --git a/src/Batch/Batch_FactBatchManager_eSGE.cxx b/src/Batch/Batch_FactBatchManager_eSGE.cxx new file mode 100644 index 000000000..9007e1270 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_eSGE.cxx @@ -0,0 +1,64 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * FactBatchManager_eSGE.cxx : + * + * Auteur : Bernard SECHER - CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#include +#include "Batch_BatchManager_eSGE.hxx" +#include "Batch_FactBatchManager_eSGE.hxx" +//#include "utilities.h" + +namespace Batch { + + static FactBatchManager_eSGE sFBM_eSGE; + + // Constructeur + FactBatchManager_eSGE::FactBatchManager_eSGE() : FactBatchManager_eClient("eSGE") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_eSGE::~FactBatchManager_eSGE() + { + // Nothing to do + } + + // Functor + BatchManager * FactBatchManager_eSGE::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'"); + return new BatchManager_eSGE(this, hostname); + } + + BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const + { + // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'"); + return new BatchManager_eSGE(this, hostname, protocol, mpiImpl); + } + + +} diff --git a/src/Batch/Batch_FactBatchManager_eSGE.hxx b/src/Batch/Batch_FactBatchManager_eSGE.hxx new file mode 100644 index 000000000..212511752 --- /dev/null +++ b/src/Batch/Batch_FactBatchManager_eSGE.hxx @@ -0,0 +1,60 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * FactBatchManager_eSGE.hxx : + * + * Auteur : Bernard SECHER : CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#ifndef _FACTBATCHMANAGER_eSGE_H_ +#define _FACTBATCHMANAGER_eSGE_H_ + +using namespace std; +#include +#include +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_FactBatchManager_eClient.hxx" + +namespace Batch { + + class BatchManager_eSGE; + + class FactBatchManager_eSGE : public FactBatchManager_eClient + { + public: + // Constructeur et destructeur + FactBatchManager_eSGE(); + virtual ~FactBatchManager_eSGE(); + + virtual BatchManager * operator() (const char * hostname) const; + virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const; + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Batch/Batch_JobInfo_eSGE.cxx b/src/Batch/Batch_JobInfo_eSGE.cxx new file mode 100644 index 000000000..cba97a4ef --- /dev/null +++ b/src/Batch/Batch_JobInfo_eSGE.cxx @@ -0,0 +1,111 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * JobInfo_eSGE.cxx : emulation of SGE client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include +#include +#include +#include "Batch_Parametre.hxx" +#include "Batch_Environnement.hxx" +#include "Batch_RunTimeException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_JobInfo_eSGE.hxx" + +using namespace std; + +namespace Batch { + + + + // Constructeurs + JobInfo_eSGE::JobInfo_eSGE(int id, string logFile) : JobInfo() + { + // On remplit les membres _param et _env + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + + // read of log file + char line[128]; + ifstream fp(logFile.c_str(),ios::in); + + string status; + string sline; + fp.getline(line,80,'\n'); + sline = string(line); + + if( sline.length() > 0 ){ + istringstream iss(sline); + iss >> status >> status >> status >> status >> status; + } + else + status = "e"; + + _param[STATE] = status; + + if( status.find("r") != string::npos) + _running = true; + + } + + // Teste si un job est present en machine + bool JobInfo_eSGE::isRunning() const + { + return _running; + } + + + // Destructeur + JobInfo_eSGE::~JobInfo_eSGE() + { + // Nothing to do + } + + // Convertit une date HH:MM:SS en secondes + long JobInfo_eSGE::HMStoLong(const string & s) + { + long hour, min, sec; + + sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); + return ( ( ( hour * 60L ) + min ) * 60L ) + sec; + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_eSGE::__str__() const + { + ostringstream sst; + sst << " #include #include @@ -47,7 +49,7 @@ using namespace std; Launcher_cpp::Launcher_cpp() { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Launcher_cpp constructor" << endl; + cout << "Launcher_cpp constructor" << endl; #endif } @@ -60,7 +62,7 @@ Launcher_cpp::Launcher_cpp() Launcher_cpp::~Launcher_cpp() { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Launcher_cpp destructor" << endl; + cout << "Launcher_cpp destructor" << endl; #endif std::map < string, Batch::BatchManager_eClient * >::const_iterator it1; for(it1=_batchmap.begin();it1!=_batchmap.end();it1++) @@ -70,6 +72,114 @@ Launcher_cpp::~Launcher_cpp() delete it2->second; } +//============================================================================= +/*! CORBA Method: + * Submit a batch job on a cluster and returns the JobId + * \param xmlExecuteFile : to define the execution on the batch cluster + * \param clusterName : name of the batch cluster + */ +//============================================================================= +long Launcher_cpp::submitJob( const std::string xmlExecuteFile, + const std::string clusterName) throw(LauncherException) +{ +#if defined(_DEBUG_) || defined(_DEBUG) + cout << "BEGIN OF Launcher_cpp::submitJob" << endl; +#endif + long jobId; + vector aMachineList; + + if(!_ResManager) + throw LauncherException("You must set Resources Manager to Launcher!!"); + + // verify if cluster is in resources catalog + machineParams params; + params.hostname = clusterName; + vector aCompoList ; + try{ + aMachineList = _ResManager->GetFittingResources(params, aCompoList); + } + catch(const ResourcesException &ex){ + throw LauncherException(ex.msg.c_str()); + } + if (aMachineList.size() == 0) + throw LauncherException("This cluster is not in resources catalog"); + + // Parsing xml file + ParseXmlFile(xmlExecuteFile); + + // verify if clustername is in xml file + map::const_iterator it1 = _launch.MachinesList.find(clusterName); + if(it1 == _launch.MachinesList.end()) + throw LauncherException("This cluster is not in xml file"); + + ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); + string cname(p.Alias); +#if defined(_DEBUG_) || defined(_DEBUG) + cout << "Choose cluster: " << cname << endl; +#endif + + // search batch manager for that cluster in map or instanciate one + map < string, Batch::BatchManager_eClient * >::const_iterator it2 = _batchmap.find(cname); + if(it2 == _batchmap.end()) + { + _batchmap[cname] = FactoryBatchManager(p); + // TODO: Add a test for the cluster ! + } + + try{ + + // directory on cluster to put files to execute + string remotedir = _launch.MachinesList[clusterName].WorkDirectory; + // local directory to get files to execute and to put results + string localdir = _launch.RefDirectory; + + int idx1 = xmlExecuteFile.find_last_of("/"); + if(idx1 == string::npos) idx1 = -1; + int idx2 = xmlExecuteFile.find(".xml"); + string logfile = xmlExecuteFile.substr(idx1+1,idx2-idx1-1); + string ologfile = logfile + ".output.log"; + string elogfile = logfile + ".error.log"; + + // create and submit job on cluster + Batch::Parametre param; + param[USER] = p.UserName; + param[EXECUTABLE] = ""; + for(int i=0; i<_launch.InputFile.size();i++) + param[INFILE] += Batch::Couple( localdir + "/" + _launch.InputFile[i], remotedir + "/" + _launch.InputFile[i] ); + for(int i=0; i<_launch.OutputFile.size();i++) + param[OUTFILE] += Batch::Couple( localdir + "/" + _launch.OutputFile[i], remotedir + "/" + _launch.OutputFile[i] ); + param[OUTFILE] += Batch::Couple( localdir + "/" + ologfile, remotedir + "/" + ologfile ); + param[OUTFILE] += Batch::Couple( localdir + "/" + elogfile, remotedir + "/" + elogfile ); + param[NBPROC] = _launch.NbOfProcesses; + param[WORKDIR] = remotedir; + param[TMPDIR] = remotedir; + param[MAXWALLTIME] = getWallTime(""); + param[MAXRAMSIZE] = getRamSize(""); + param[HOMEDIR] = ""; + + Batch::Environnement env; + env["COMMAND"] = _launch.Command; + env["SOURCEFILE"] = _launch.MachinesList[clusterName].EnvFile; + env["LOGFILE"] = logfile; + + Batch::Job* job = new Batch::Job(param,env); + + // submit job on cluster + Batch::JobId jid = _batchmap[cname]->submitJob(*job); + + // get job id in long + istringstream iss(jid.getReference()); + iss >> jobId; + + _jobmap[ pair(cname,jobId) ] = job; + } + catch(const Batch::EmulationException &ex){ + throw LauncherException(ex.msg.c_str()); + } + + return jobId; +} + //============================================================================= /*! CORBA Method: * Submit a batch job on a cluster and returns the JobId @@ -86,11 +196,14 @@ long Launcher_cpp::submitSalomeJob( const string fileToExecute , const machineParams& params) throw(LauncherException) { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "BEGIN OF Launcher_cpp::submitSalomeJob" << endl; + cout << "BEGIN OF Launcher_cpp::submitSalomeJob" << endl; #endif long jobId; vector aMachineList; + if(!_ResManager) + throw LauncherException("You must set Resources Manager to Launcher!!"); + // check batch params if ( !check(batch_params) ) throw LauncherException("Batch parameters are bad (see informations above)"); @@ -109,7 +222,7 @@ long Launcher_cpp::submitSalomeJob( const string fileToExecute , ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); string clustername(p.Alias); #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Choose cluster: " << clustername << endl; + cout << "Choose cluster: " << clustername << endl; #endif // search batch manager for that cluster in map or instanciate one @@ -132,11 +245,10 @@ long Launcher_cpp::submitSalomeJob( const string fileToExecute , for(int i=0;i aCompoList ; vector aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; @@ -194,15 +309,30 @@ string Launcher_cpp::querySalomeJob( long id, if(it == _batchmap.end()) throw LauncherException("no batchmanager for that cluster"); - ostringstream oss; - oss << id; - Batch::JobId jobId( _batchmap[clustername], oss.str() ); + Batch::Parametre par; + try{ + ostringstream oss; + oss << id; + Batch::JobId jobId( _batchmap[clustername], oss.str() ); + + Batch::JobInfo jinfo = jobId.queryJob(); + par = jinfo.getParametre(); + } + catch(const Batch::EmulationException &ex){ + throw LauncherException(ex.msg.c_str()); + } - Batch::JobInfo jinfo = jobId.queryJob(); - Batch::Parametre par = jinfo.getParametre(); return par[STATE]; } +string Launcher_cpp::queryJob( long id, + const std::string clusterName) +{ + machineParams params; + params.hostname = clusterName; + return queryJob(id,params); +} + //============================================================================= /*! CORBA Method: * Delete a batch job on a cluster @@ -210,9 +340,12 @@ string Launcher_cpp::querySalomeJob( long id, * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -void Launcher_cpp::deleteSalomeJob( const long id, - const machineParams& params) throw(LauncherException) +void Launcher_cpp::deleteJob( const long id, + const machineParams& params) throw(LauncherException) { + if(!_ResManager) + throw LauncherException("You must set Resources Manager to Launcher!!"); + // find a cluster matching params structure vector aCompoList ; vector aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; @@ -231,6 +364,14 @@ void Launcher_cpp::deleteSalomeJob( const long id, jobId.deleteJob(); } +void Launcher_cpp::deleteJob( long id, + const std::string clusterName) +{ + machineParams params; + params.hostname = clusterName; + deleteJob(id,params); +} + //============================================================================= /*! CORBA Method: * Get result files of job on a cluster @@ -238,10 +379,13 @@ void Launcher_cpp::deleteSalomeJob( const long id, * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -void Launcher_cpp::getResultSalomeJob( const string directory, - const long id, - const machineParams& params) throw(LauncherException) +void Launcher_cpp::getResultsJob( const string directory, + const long id, + const machineParams& params) throw(LauncherException) { + if(!_ResManager) + throw LauncherException("You must set Resources Manager to Launcher!!"); + vector aCompoList ; vector aMachineList = _ResManager->GetFittingResources( params , aCompoList ) ; ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]); @@ -257,6 +401,15 @@ void Launcher_cpp::getResultSalomeJob( const string directory, _batchmap[clustername]->importOutputFiles( *job, directory ); } +void Launcher_cpp::getResultsJob( const std::string directory, + long id, + const std::string clusterName) +{ + machineParams params; + params.hostname = clusterName; + getResultsJob(directory,id,params); +} + //============================================================================= /*! * Factory to instanciate the good batch manager for choosen cluster. @@ -297,29 +450,38 @@ Batch::BatchManager_eClient *Launcher_cpp::FactoryBatchManager( const ParserReso case slurm: mpi = "slurm"; break; + case nompi: + throw LauncherException("you must specified an mpi implementation for batch manager"); + break; default: - mpi = "indif"; + throw LauncherException("unknown mpi implementation"); break; } #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instanciation of batch manager" << endl; + cout << "Instanciation of batch manager" << endl; #endif switch( params.Batch ){ case pbs: #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instantiation of PBS batch manager" << endl; + cout << "Instantiation of PBS batch manager" << endl; #endif fact = new Batch::FactBatchManager_ePBS; break; case lsf: #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Instantiation of LSF batch manager" << endl; + cout << "Instantiation of LSF batch manager" << endl; #endif fact = new Batch::FactBatchManager_eLSF; break; + case sge: +#if defined(_DEBUG_) || defined(_DEBUG) + cout << "Instantiation of SGE batch manager" << endl; +#endif + fact = new Batch::FactBatchManager_eSGE; + break; default: #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "BATCH = " << params.Batch << endl; + cout << "BATCH = " << params.Batch << endl; #endif throw LauncherException("no batchmanager for that cluster"); } @@ -432,7 +594,7 @@ string Launcher_cpp::buildSalomeCouplingScript(const string fileToExecute, const tempOutputFile.close(); chmod(TmpFileName.c_str(), 0x1ED); #if defined(_DEBUG_) || defined(_DEBUG) - cerr << TmpFileName.c_str() << endl; + cout << TmpFileName.c_str() << endl; #endif delete mpiImpl; @@ -457,8 +619,9 @@ MpiImpl *Launcher_cpp::FactoryMpiImpl(MpiImplType mpi) throw(LauncherException) return new MpiImpl_OPENMPI(); case slurm: return new MpiImpl_SLURM(); - case indif: - throw LauncherException("you must specify a mpi implementation in CatalogResources.xml file"); + case nompi: + throw LauncherException("you must specified an mpi implementation for batch manager"); + break; default: ostringstream oss; oss << mpi << " : not yet implemented"; @@ -501,8 +664,8 @@ bool Launcher_cpp::check(const batchParams& batch_params) { bool rtn = true; #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Job parameters are :" << endl; - cerr << "Directory : $HOME/Batch/$date" << endl; + cout << "Job parameters are :" << endl; + cout << "Directory : $HOME/Batch/$date" << endl; #endif // check expected_during_time (check the format) @@ -541,7 +704,7 @@ bool Launcher_cpp::check(const batchParams& batch_params) edt_info = "No value given"; } #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Expected during time : " << edt_info << endl;; + cout << "Expected during time : " << edt_info << endl;; #endif // check memory (check the format) @@ -569,7 +732,7 @@ bool Launcher_cpp::check(const batchParams& batch_params) mem_info = "No value given"; } #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Memory : " << mem_info << endl; + cout << "Memory : " << mem_info << endl; #endif // check nb_proc @@ -585,7 +748,7 @@ bool Launcher_cpp::check(const batchParams& batch_params) nb_proc_info = nb_proc_value.str(); } #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Nb of processors : " << nb_proc_info << endl; + cout << "Nb of processors : " << nb_proc_info << endl; #endif return rtn; @@ -632,37 +795,70 @@ long Launcher_cpp::getRamSize(std::string mem) return 0; } -std::string -Launcher_cpp::getHomeDir(const ParserResourcesType& p, const std::string& tmpdir) +void Launcher_cpp::ParseXmlFile(string xmlExecuteFile) { - std::string home; - std::string command; - int idx = tmpdir.find("Batch/"); - std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length()); - filelogtemp = "/tmp/logs" + filelogtemp + "_home"; - - if( p.Protocol == rsh ) - command = "rsh "; - else if( p.Protocol == ssh ) - command = "ssh "; - else - throw LauncherException("Unknown protocol"); - if (p.UserName != ""){ - command += p.UserName; - command += "@"; + SALOME_Launcher_Handler* handler = new SALOME_Launcher_Handler(_launch); + + const char* aFilePath = xmlExecuteFile.c_str(); + FILE* aFile = fopen(aFilePath, "r"); + + if (aFile != NULL) + { + xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0); + + if (aDoc != NULL) + handler->ProcessXmlDocument(aDoc); + else{ +#if defined(_DEBUG_) || defined(_DEBUG) + cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl; +#endif + } + + // Free the document + xmlFreeDoc(aDoc); + + fclose(aFile); } - command += p.Alias; - command += " 'echo $HOME' > "; - command += filelogtemp; + else{ #if defined(_DEBUG_) || defined(_DEBUG) - std::cerr << command.c_str() << std::endl; + cout << "Launcher_cpp: file "< #include "ResourcesManager.hxx" +#include "SALOME_Launcher_Parser.hxx" #include #include @@ -65,15 +66,21 @@ public: Launcher_cpp(); ~Launcher_cpp(); + long submitJob(const std::string xmlExecuteFile, + const std::string clusterName) throw(LauncherException); + long submitSalomeJob(const std::string fileToExecute , const std::vector& filesToExport , const std::vector& filesToImport , const batchParams& batch_params, const machineParams& params) throw(LauncherException); - std::string querySalomeJob( const long jobId, const machineParams& params) throw(LauncherException); - void deleteSalomeJob( const long jobId, const machineParams& params) throw(LauncherException); - void getResultSalomeJob( const std::string directory, const long jobId, const machineParams& params ) throw(LauncherException); + std::string queryJob( const long jobId, const machineParams& params) throw(LauncherException); + std::string queryJob( const long jobId, const std::string clusterName); + void deleteJob( const long jobId, const machineParams& params) throw(LauncherException); + void deleteJob( const long jobId, const std::string clusterName); + void getResultsJob( const std::string directory, const long jobId, const machineParams& params ) throw(LauncherException); + void getResultsJob( const std::string directory, const long jobId, const std::string clusterName ); void SetResourcesManager( ResourcesManager_cpp* rm ) { _ResManager = rm; } @@ -92,6 +99,11 @@ protected: bool check(const batchParams& batch_params); long getWallTime(std::string edt); long getRamSize(std::string mem); + void ParseXmlFile(std::string xmlExecuteFile); + + //! will contain the informations on the data type catalog(after parsing) + ParserLauncherType _launch; + }; #endif diff --git a/src/Launcher/Makefile.am b/src/Launcher/Makefile.am index 9211ed82d..df1fb8c63 100644 --- a/src/Launcher/Makefile.am +++ b/src/Launcher/Makefile.am @@ -36,10 +36,12 @@ include $(top_srcdir)/salome_adm/unix/make_common_starter.am # # header files salomeinclude_HEADERS = \ - BatchTest.hxx \ - SALOME_Launcher.hxx \ - SALOME_Launcher_defs.hxx \ - Launcher.hxx + SALOME_Launcher_Parser.hxx \ + SALOME_Launcher_Handler.hxx \ + BatchTest.hxx \ + SALOME_Launcher_defs.hxx \ + SALOME_Launcher.hxx \ + Launcher.hxx # Scripts to be installed dist_salomescript_DATA = @@ -93,10 +95,14 @@ COMMON_LIBS =\ # Libraries targets # =============================================================== # -lib_LTLIBRARIES = libLauncher.la libSalomeLauncher.la +if WITHONLYLAUNCHER + lib_LTLIBRARIES = libLauncher.la +else + lib_LTLIBRARIES = libLauncher.la libSalomeLauncher.la +endif libSalomeLauncher_la_SOURCES=\ - BatchTest.cxx \ - SALOME_Launcher.cxx + BatchTest.cxx \ + SALOME_Launcher.cxx libSalomeLauncher_la_CPPFLAGS =\ $(COMMON_CPPFLAGS) @@ -109,10 +115,12 @@ libSalomeLauncher_la_LIBADD =\ $(COMMON_LIBS) libLauncher.la libLauncher_la_SOURCES=\ + SALOME_Launcher_Parser.cxx \ + SALOME_Launcher_Handler.cxx \ Launcher.cxx libLauncher_la_CPPFLAGS =\ - $(COMMON_CPPFLAGS) \ + -I$(srcdir)/../Batch \ -I$(srcdir)/../ResourcesManager \ @MPI_INCLUDES@ \ @LIBXML_INCLUDES@ @@ -130,7 +138,9 @@ libLauncher_la_LIBADD =\ # Executables targets # =============================================================== # -bin_PROGRAMS = SALOME_LauncherServer +if !WITHONLYLAUNCHER + bin_PROGRAMS = SALOME_LauncherServer +endif SALOME_LauncherServer_SOURCES =\ SALOME_LauncherServer.cxx diff --git a/src/Launcher/SALOME_Launcher.cxx b/src/Launcher/SALOME_Launcher.cxx index a053c8cc5..80f1da063 100644 --- a/src/Launcher/SALOME_Launcher.cxx +++ b/src/Launcher/SALOME_Launcher.cxx @@ -111,6 +111,28 @@ CORBA::Long SALOME_Launcher::getPID() } +//============================================================================= +/*! CORBA Method: + * Submit a batch job on a cluster and returns the JobId + * \param xmlExecuteFile : .xml to parse to execute on the batch cluster + * \param clusterName : cluster name + */ +//============================================================================= +CORBA::Long SALOME_Launcher::submitJob(const char * xmlExecuteFile, + const char * clusterName) +{ + CORBA::Long jobId; + + try{ + jobId = _l.submitJob(xmlExecuteFile,clusterName); + } + catch(const LauncherException &ex){ + INFOS(ex.msg.c_str()); + THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR); + } + return jobId; +} + //============================================================================= /*! CORBA Method: * Submit a batch job on a cluster and returns the JobId @@ -190,9 +212,9 @@ SALOME_Launcher::testBatch(const Engines::MachineParameters& params) rtn = true; } } - catch(const SALOME_Exception &ex){ - INFOS(ex.what()); - THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR); + catch(const LauncherException &ex){ + INFOS(ex.msg.c_str()); + THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::INTERNAL_ERROR); } return rtn; } @@ -204,8 +226,8 @@ SALOME_Launcher::testBatch(const Engines::MachineParameters& params) * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -char* SALOME_Launcher::querySalomeJob( const CORBA::Long jobId, - const Engines::MachineParameters& params) +char* SALOME_Launcher::queryJob( const CORBA::Long jobId, + const Engines::MachineParameters& params) { string status; machineParams p; @@ -217,10 +239,10 @@ char* SALOME_Launcher::querySalomeJob( const CORBA::Long jobId, p.mem_mb = params.mem_mb; try{ - status = _l.querySalomeJob(jobId,p); + status = _l.queryJob(jobId,p); } catch(const LauncherException &ex){ - INFOS("Caught exception."); + INFOS(ex.msg.c_str()); THROW_SALOME_CORBA_EXCEPTION(ex.msg.c_str(),SALOME::BAD_PARAM); } return CORBA::string_dup(status.c_str()); @@ -233,8 +255,8 @@ char* SALOME_Launcher::querySalomeJob( const CORBA::Long jobId, * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, - const Engines::MachineParameters& params) +void SALOME_Launcher::deleteJob( const CORBA::Long jobId, + const Engines::MachineParameters& params) { machineParams p; p.hostname = params.hostname; @@ -245,7 +267,7 @@ void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, p.mem_mb = params.mem_mb; try{ - _l.deleteSalomeJob(jobId,p); + _l.deleteJob(jobId,p); } catch(const LauncherException &ex){ INFOS("Caught exception."); @@ -260,9 +282,9 @@ void SALOME_Launcher::deleteSalomeJob( const CORBA::Long jobId, * \param params : Constraints for the choice of the batch cluster */ //============================================================================= -void SALOME_Launcher::getResultSalomeJob( const char *directory, - const CORBA::Long jobId, - const Engines::MachineParameters& params) +void SALOME_Launcher::getResultsJob( const char *directory, + const CORBA::Long jobId, + const Engines::MachineParameters& params) { machineParams p; p.hostname = params.hostname; @@ -273,7 +295,7 @@ void SALOME_Launcher::getResultSalomeJob( const char *directory, p.mem_mb = params.mem_mb; try{ - _l.getResultSalomeJob( directory, jobId, p ); + _l.getResultsJob( directory, jobId, p ); } catch(const LauncherException &ex){ INFOS("Caught exception."); diff --git a/src/Launcher/SALOME_Launcher.hxx b/src/Launcher/SALOME_Launcher.hxx index 8d59dd53f..239ce2c23 100644 --- a/src/Launcher/SALOME_Launcher.hxx +++ b/src/Launcher/SALOME_Launcher.hxx @@ -41,6 +41,9 @@ public: SALOME_Launcher(CORBA::ORB_ptr orb, PortableServer::POA_var poa); ~SALOME_Launcher(); + CORBA::Long submitJob(const char * xmlExecuteFile, + const char * clusterName); + CORBA::Long submitSalomeJob(const char * fileToExecute , const Engines::FilesList& filesToExport , const Engines::FilesList& filesToImport , @@ -50,6 +53,9 @@ public: char* querySalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); void deleteSalomeJob( CORBA::Long jobId, const Engines::MachineParameters& params); void getResultSalomeJob( const char * directory, CORBA::Long jobId, const Engines::MachineParameters& params ); + char* queryJob( const CORBA::Long jobId, const Engines::MachineParameters& params); + void deleteJob( const CORBA::Long jobId, const Engines::MachineParameters& params); + void getResultsJob( const char * directory, const CORBA::Long jobId, const Engines::MachineParameters& params ); CORBA::Boolean testBatch(const Engines::MachineParameters& params); diff --git a/src/Launcher/SALOME_Launcher_Handler.cxx b/src/Launcher/SALOME_Launcher_Handler.cxx new file mode 100755 index 000000000..3b21622e1 --- /dev/null +++ b/src/Launcher/SALOME_Launcher_Handler.cxx @@ -0,0 +1,168 @@ +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SALOME_Laucher_Handler.cxx +// Author : Bernard Secher +// Module : SALOME +//$Header$ + +#include "SALOME_Launcher_Handler.hxx" +#include +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +//============================================================================= +/*! + * Constructor + * \param listOfResources: map of ParserResourcesType to fill when parsing + */ +//============================================================================= + +SALOME_Launcher_Handler::SALOME_Launcher_Handler(ParserLauncherType& launch): + _launch(launch) +{ + //XML tags initialisation + test_machine_list = "machine-list"; + test_main = "main"; + + test_machine = "machine"; + test_env_file = "env-file"; + test_work_directory = "work-directory"; + test_ref_directory = "ref-directory"; + test_nb_processes = "nb-processes"; + test_input_file = "input-file"; + test_output_file = "output-file"; + test_command = "command"; + +} + +//============================================================================= +/*! + * Destructor + */ +//============================================================================= + +SALOME_Launcher_Handler::~SALOME_Launcher_Handler() +{ + // cout << "SALOME_Launcher_Handler destruction") << endl; +} + +//============================================================================= +/*! + * Retrieves DS after the file parse. + */ +//============================================================================= + +const ParserLauncherType& +SALOME_Launcher_Handler::GetLauncherAfterParsing() const +{ + return _launch; +} + +//============================================================================= +/*! + * Processes XML document and fills the list of resources + */ +//============================================================================= + +void SALOME_Launcher_Handler::ProcessXmlDocument(xmlDocPtr theDoc) +{ +// if (MYDEBUG) cout << "Begin parse document" << endl; + + // Empty private elements + _launch.Clear(); + + // Get the document root node + xmlNodePtr aCurNode = xmlDocGetRootElement(theDoc); + + aCurNode = aCurNode->xmlChildrenNode; + + // Processing the document nodes + while(aCurNode != NULL){ + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_machine_list) ){ + xmlNodePtr aCurNode2 = aCurNode->xmlChildrenNode; + while(aCurNode2 != NULL){ + if ( !xmlStrcmp(aCurNode2->name,(const xmlChar*)test_machine) ){ + _machp.Clear(); + xmlChar* name = xmlNodeGetContent(aCurNode2); + string clusterName = (const char*)name; + xmlFree(name); + + if (xmlHasProp(aCurNode2, (const xmlChar*)test_env_file)){ + xmlChar* envfile = xmlGetProp(aCurNode2, (const xmlChar*)test_env_file); + _machp.EnvFile = (const char*)envfile; + xmlFree(envfile); + } + + if (xmlHasProp(aCurNode2, (const xmlChar*)test_work_directory)){ + xmlChar* workdirectory = xmlGetProp(aCurNode2, (const xmlChar*)test_work_directory); + _machp.WorkDirectory = (const char*)workdirectory; + xmlFree(workdirectory); + } + _launch.MachinesList[clusterName]=_machp ; + } + aCurNode2 = aCurNode2->next; + } + } + + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_ref_directory) ){ + xmlChar* refdirectory = xmlNodeGetContent(aCurNode); + _launch.RefDirectory = (const char*)refdirectory; + xmlFree(refdirectory); + } + + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_nb_processes) ){ + xmlChar* nbofprocesses = xmlNodeGetContent(aCurNode); + _launch.NbOfProcesses = atoi((const char*)nbofprocesses); + xmlFree(nbofprocesses); + } + + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_input_file) ){ + xmlChar* inputfile = xmlNodeGetContent(aCurNode); + _launch.InputFile.push_back((const char*)inputfile); + xmlFree(inputfile); + } + + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_output_file) ){ + xmlChar* outputfile = xmlNodeGetContent(aCurNode); + _launch.OutputFile.push_back((const char*)outputfile); + xmlFree(outputfile); + } + + if ( !xmlStrcmp(aCurNode->name,(const xmlChar*)test_command) ){ + xmlChar* command = xmlNodeGetContent(aCurNode); + _launch.Command = (const char*)command; + xmlFree(command); + } + + aCurNode = aCurNode->next; + } + +} diff --git a/src/Launcher/SALOME_Launcher_Handler.hxx b/src/Launcher/SALOME_Launcher_Handler.hxx new file mode 100755 index 000000000..e58495854 --- /dev/null +++ b/src/Launcher/SALOME_Launcher_Handler.hxx @@ -0,0 +1,69 @@ +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SALOME_Launcher_Handler.hxx +// Author : Bernard SECHER +// Module : SALOME +//$Header$ + +#ifndef SALOME_LAUNCHER_HANDLER +#define SALOME_LAUNCHER_HANDLER + +#include "SALOME_Launcher_Parser.hxx" + +#include +#include + +#include + +class SALOME_Launcher_Handler +{ + +public : + SALOME_Launcher_Handler(ParserLauncherType& launch); + + virtual ~SALOME_Launcher_Handler(); + + const ParserLauncherType& GetLauncherAfterParsing() const; + + void ProcessXmlDocument(xmlDocPtr theDoc); + +private : + ParserLauncherType& _launch; + MachineParameters _machp; + + const char *test_machine_list; + const char *test_main; + + const char *test_machine; + const char *test_env_file; + const char *test_work_directory; + const char *test_ref_directory; + const char *test_nb_processes; + const char *test_input_file; + const char *test_output_file; + const char *test_command; + +}; + +#endif // SALOME_LAUNCHER_HANDLER diff --git a/src/Launcher/SALOME_Launcher_Parser.cxx b/src/Launcher/SALOME_Launcher_Parser.cxx new file mode 100644 index 000000000..f08514c49 --- /dev/null +++ b/src/Launcher/SALOME_Launcher_Parser.cxx @@ -0,0 +1,77 @@ +// Copyright (C) 2005 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +#include "SALOME_Launcher_Parser.hxx" +#include +#include + +#define NULL_VALUE 0 + +using namespace std; + +void MachineParameters::Clear() +{ + EnvFile = ""; + WorkDirectory = ""; +} + +void MachineParameters::Print() const +{ + ostringstream oss; + oss << " EnvFile: " << EnvFile + << " WorkDirectory: " << WorkDirectory << endl; + + cout << oss.str(); +} + +void ParserLauncherType::Print() const +{ + ostringstream oss; + oss << endl << + "RefDirectory: " << RefDirectory << endl << + "NbOfProcesses: " << NbOfProcesses << endl << + "InputFile: "; + for(int i=0; i ::const_iterator it; + for(it=MachinesList.begin();it!=MachinesList.end();it++){ + cout << " " << it->first; + it->second.Print(); + } + +} + +void ParserLauncherType::Clear() +{ + MachinesList.clear(); + RefDirectory = ""; + NbOfProcesses = 1; + InputFile.clear(); + OutputFile.clear(); + Command = ""; +} diff --git a/src/Launcher/SALOME_Launcher_Parser.hxx b/src/Launcher/SALOME_Launcher_Parser.hxx new file mode 100755 index 000000000..3a29818e1 --- /dev/null +++ b/src/Launcher/SALOME_Launcher_Parser.hxx @@ -0,0 +1,58 @@ +// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// +// File : SALOME_Launcher_Parser.hxx +// Author : Bernard Secher +// Module : SALOME +//$Header$ + +#ifndef SALOME_LAUNCHER_PARSER +#define SALOME_LAUNCHER_PARSER + +#include +#include +#include +#include + +struct MachineParameters + { + std::string EnvFile; + std::string WorkDirectory; + void Print() const; + void Clear(); + }; + +struct ParserLauncherType + { + std::map MachinesList; + std::string RefDirectory; + long NbOfProcesses; + std::vector InputFile; + std::vector OutputFile; + std::string Command; + + void Print() const; + void Clear(); + }; + +#endif //SALOME_LAUNCHER_PARSER diff --git a/src/Makefile.am b/src/Makefile.am index 368f6c0ee..2fb8d7ef6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -100,6 +100,10 @@ DIST_SUBDIRS = \ # check_cppunit for example with CPPUNIT_IS_OK. # +if WITHONLYLAUNCHER + SUBDIRS = Batch Batch_SWIG ResourcesManager Launcher +else + SUBDIRS = $(SUBDIR_BASE) if WITH_BATCH @@ -127,7 +131,8 @@ else endif endif if WITH_PACO_PARALLEL -SUBDIRS += $(SUBDIR_PARALLEL) + SUBDIRS += $(SUBDIR_PARALLEL) endif +endif EXTRA_DIST = win32pm diff --git a/src/ResourcesManager/Makefile.am b/src/ResourcesManager/Makefile.am index 7eef30ae1..d444c5b7c 100755 --- a/src/ResourcesManager/Makefile.am +++ b/src/ResourcesManager/Makefile.am @@ -73,7 +73,11 @@ COMMON_LIBS =\ # Libraries targets # =============================================================== # -lib_LTLIBRARIES = libResourcesManager.la libSalomeResourcesManager.la +if WITHONLYLAUNCHER + lib_LTLIBRARIES = libResourcesManager.la +else + lib_LTLIBRARIES = libResourcesManager.la libSalomeResourcesManager.la +endif libSalomeResourcesManager_la_SOURCES =\ SALOME_ResourcesManager.cxx diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index 94de9d4e0..e09207f5f 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -47,7 +47,7 @@ ResourcesManager_cpp(const char *xmlFilePath) : _path_resources(xmlFilePath) { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "ResourcesManager_cpp constructor" << endl; + cout << "ResourcesManager_cpp constructor" << endl; #endif } @@ -62,12 +62,14 @@ ResourcesManager_cpp(const char *xmlFilePath) : */ //============================================================================= -ResourcesManager_cpp::ResourcesManager_cpp() +ResourcesManager_cpp::ResourcesManager_cpp() throw(ResourcesException) { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "ResourcesManager_cpp constructor" << endl; + cout << "ResourcesManager_cpp constructor" << endl; #endif _isAppliSalomeDefined = (getenv("APPLI") != 0); + if(!getenv("KERNEL_ROOT_DIR")) + throw ResourcesException("you must define KERNEL_ROOT_DIR environment variable!!"); if (_isAppliSalomeDefined) { @@ -85,7 +87,7 @@ ResourcesManager_cpp::ResourcesManager_cpp() ParseXmlFile(); #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "ResourcesManager_cpp constructor end"; + cout << "ResourcesManager_cpp constructor end"; #endif } @@ -98,7 +100,7 @@ ResourcesManager_cpp::ResourcesManager_cpp() ResourcesManager_cpp::~ResourcesManager_cpp() { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "ResourcesManager_cpp destructor" << endl; + cout << "ResourcesManager_cpp destructor" << endl; #endif } @@ -120,9 +122,6 @@ std::vector ResourcesManager_cpp::GetFittingResources(const machineParams& params, const std::vector& componentList) throw(ResourcesException) { -//#if defined(_DEBUG_) || defined(_DEBUG) -// cerr << "ResourcesManager_cpp::GetFittingResources" << endl; -//#endif vector vec; ParseXmlFile(); @@ -133,9 +132,6 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params, #endif if (hostname[0] != '\0'){ -//#if defined(_DEBUG_) || defined(_DEBUG) -// cerr << "ResourcesManager_cpp::GetFittingResources : hostname specified" << endl; -//#endif if ( strcmp(hostname, "localhost") == 0 || strcmp(hostname, Kernel_Utils::GetHostname().c_str()) == 0 ) @@ -154,11 +150,13 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params, // --- params.hostname is in the list of resources so return it. vec.push_back(hostname); } + else if (_resourcesBatchList.find(hostname) != _resourcesBatchList.end()) { // --- params.hostname is in the list of resources so return it. vec.push_back(hostname); } + else { // Cas d'un cluster: nombre de noeuds > 1 @@ -167,10 +165,6 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params, if( (*iter).second.DataForSort._nbOfNodes > 1 ){ if( strncmp(hostname,(*iter).first.c_str(),strlen(hostname)) == 0 ){ vec.push_back((*iter).first.c_str()); -//#if defined(_DEBUG_) || defined(_DEBUG) -// cerr << "SALOME_ResourcesManager_cpp::GetFittingResources vector[" -// << cpt << "] = " << (*iter).first.c_str() << endl ; -//#endif cpt++; } } @@ -178,7 +172,7 @@ ResourcesManager_cpp::GetFittingResources(const machineParams& params, if(cpt==0){ // --- user specified an unknown hostame so notify him. #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "ResourcesManager_cpp::GetFittingResources : SALOME_Exception" << endl; + cout << "ResourcesManager_cpp::GetFittingResources : SALOME_Exception" << endl; #endif throw ResourcesException("unknown host"); } @@ -296,7 +290,7 @@ void ResourcesManager_cpp::WriteInXmlFile() if (aFile == NULL) { #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "Error opening file !" << endl; + cout << "Error opening file !" << endl; #endif return; } @@ -322,7 +316,7 @@ void ResourcesManager_cpp::WriteInXmlFile() fclose(aFile); #if defined(_DEBUG_) || defined(_DEBUG) - cerr << "WRITING DONE!" << endl; + cout << "WRITING DONE!" << endl; #endif } @@ -346,9 +340,9 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile() if (aDoc != NULL) handler->ProcessXmlDocument(aDoc); -#if defined(_DEBUG_) || defined(_DEBUG) else - cerr << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl; +#if defined(_DEBUG_) || defined(_DEBUG) + cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl; #endif // Free the document @@ -356,9 +350,9 @@ const MapOfParserResourcesType& ResourcesManager_cpp::ParseXmlFile() fclose(aFile); } -#if defined(_DEBUG_) || defined(_DEBUG) else - cerr << "ResourcesManager_cpp: file "<nb_proc_per_node = resource.DataForSort._nbOfProcPerNode; p_ptr->nb_node = resource.DataForSort._nbOfNodes; - if( resource.mpi == indif ) - p_ptr->mpiImpl = "indif"; - else if( resource.mpi == lam ) + if( resource.mpi == lam ) p_ptr->mpiImpl = "lam"; else if( resource.mpi == mpich1 ) p_ptr->mpiImpl = "mpich1"; @@ -222,14 +220,12 @@ Engines::MachineParameters* SALOME_ResourcesManager::GetMachineParameters(const else if( resource.mpi == slurm ) p_ptr->mpiImpl = "slurm"; - p_ptr->isMPI=false; - if(resource.mpi != indif ) - p_ptr->isMPI=true; - if( resource.Batch == pbs ) p_ptr->batch = "pbs"; else if( resource.Batch == lsf ) p_ptr->batch = "lsf"; + else if( resource.Batch == sge ) + p_ptr->batch = "sge"; p_ptr->nb_component_nodes=1; -- 2.39.2