From c7322a67a33c799c93e04638945c085b94fce2bd Mon Sep 17 00:00:00 2001 From: barate Date: Mon, 21 Sep 2009 14:56:26 +0000 Subject: [PATCH] Refactored submission based on SH, RSH and SSH by grouping related commands in CommunicationProtocol classes. --- Batch_config.h.in | 30 ++- CMakeModules/FindLocal.cmake | 82 +++----- src/Core/Batch_BatchManager_eClient.cxx | 135 +++---------- src/Core/Batch_BatchManager_eClient.hxx | 5 +- src/Core/Batch_CommunicationProtocol.cxx | 143 +++++++++++++ src/Core/Batch_CommunicationProtocol.hxx | 84 ++++++++ src/Core/Batch_CommunicationProtocolRSH.cxx | 191 ++++++++++++++++++ src/Core/Batch_CommunicationProtocolRSH.hxx | 75 +++++++ src/Core/Batch_CommunicationProtocolSH.cxx | 88 ++++++++ src/Core/Batch_CommunicationProtocolSH.hxx | 64 ++++++ src/Core/Batch_CommunicationProtocolSSH.cxx | 93 +++++++++ src/Core/Batch_CommunicationProtocolSSH.hxx | 60 ++++++ src/Core/Batch_FactBatchManager_eClient.hxx | 16 +- src/Core/CMakeLists.txt | 19 ++ src/LSF/Batch_BatchManager_eLSF.cxx | 131 +++--------- src/LSF/Batch_BatchManager_eLSF.hxx | 28 +-- src/LSF/Batch_FactBatchManager_eLSF.cxx | 8 +- src/LSF/Batch_FactBatchManager_eLSF.hxx | 15 +- src/Local/Batch_BatchManager_Local.cxx | 148 +++++++------- src/Local/Batch_BatchManager_Local.hxx | 35 ++-- src/Local/Batch_BatchManager_Local_RSH.cxx | 177 ---------------- src/Local/Batch_BatchManager_Local_RSH.hxx | 85 -------- src/Local/Batch_BatchManager_Local_SH.cxx | 165 --------------- src/Local/Batch_BatchManager_Local_SH.hxx | 87 -------- src/Local/Batch_BatchManager_Local_SSH.cxx | 176 ---------------- src/Local/Batch_BatchManager_Local_SSH.hxx | 85 -------- src/Local/Batch_FactBatchManager_Local.cxx | 36 +++- src/Local/Batch_FactBatchManager_Local.hxx | 15 +- .../Batch_FactBatchManager_Local_RSH.cxx | 60 ------ .../Batch_FactBatchManager_Local_RSH.hxx | 57 ------ src/Local/Batch_FactBatchManager_Local_SH.cxx | 60 ------ src/Local/Batch_FactBatchManager_Local_SH.hxx | 57 ------ .../Batch_FactBatchManager_Local_SSH.cxx | 60 ------ .../Batch_FactBatchManager_Local_SSH.hxx | 57 ------ src/Local/CMakeLists.txt | 8 +- src/Local/Test/CMakeLists.txt | 54 ++--- src/Local/Test/Test_Local_RSH.cxx | 4 + src/Local/Test/Test_Local_SH.cxx | 4 + src/Local/Test/Test_Local_SSH.cxx | 4 + src/PBS/Batch_BatchManager_ePBS.cxx | 127 +++--------- src/PBS/Batch_BatchManager_ePBS.hxx | 27 +-- src/PBS/Batch_FactBatchManager_ePBS.cxx | 6 +- src/PBS/Batch_FactBatchManager_ePBS.hxx | 4 +- src/PBS/Test/CMakeLists.txt | 14 +- src/PBS/Test/Test_ePBS_RSH.cxx | 147 ++++++++++++++ .../Test/{Test_ePBS.cxx => Test_ePBS_SSH.cxx} | 6 +- src/Python/Batch_PyVersatile.cxx | 168 +++++++-------- src/Python/Test/CMakeLists.txt | 24 +-- src/SGE/Batch_BatchManager_eSGE.cxx | 123 +++-------- src/SGE/Batch_BatchManager_eSGE.hxx | 27 +-- src/SGE/Batch_FactBatchManager_eSGE.cxx | 8 +- src/SGE/Batch_FactBatchManager_eSGE.hxx | 6 +- 52 files changed, 1476 insertions(+), 1912 deletions(-) create mode 100644 src/Core/Batch_CommunicationProtocol.cxx create mode 100644 src/Core/Batch_CommunicationProtocol.hxx create mode 100644 src/Core/Batch_CommunicationProtocolRSH.cxx create mode 100644 src/Core/Batch_CommunicationProtocolRSH.hxx create mode 100644 src/Core/Batch_CommunicationProtocolSH.cxx create mode 100644 src/Core/Batch_CommunicationProtocolSH.hxx create mode 100644 src/Core/Batch_CommunicationProtocolSSH.cxx create mode 100644 src/Core/Batch_CommunicationProtocolSSH.hxx delete mode 100644 src/Local/Batch_BatchManager_Local_RSH.cxx delete mode 100644 src/Local/Batch_BatchManager_Local_RSH.hxx delete mode 100644 src/Local/Batch_BatchManager_Local_SH.cxx delete mode 100644 src/Local/Batch_BatchManager_Local_SH.hxx delete mode 100644 src/Local/Batch_BatchManager_Local_SSH.cxx delete mode 100644 src/Local/Batch_BatchManager_Local_SSH.hxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_RSH.cxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_RSH.hxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_SH.cxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_SH.hxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_SSH.cxx delete mode 100644 src/Local/Batch_FactBatchManager_Local_SSH.hxx create mode 100644 src/PBS/Test/Test_ePBS_RSH.cxx rename src/PBS/Test/{Test_ePBS.cxx => Test_ePBS_SSH.cxx} (96%) diff --git a/Batch_config.h.in b/Batch_config.h.in index 1901c20..5586752 100644 --- a/Batch_config.h.in +++ b/Batch_config.h.in @@ -27,26 +27,34 @@ #cmakedefine MSVC #cmakedefine MINGW -/* A path to a rcp-like command */ -#define RCP "@RCP@" +/* SH tools (sh, cp, rm) found on the system */ +#cmakedefine HAS_SH + +/* A path to a sh-like command */ +#cmakedefine SH_COMMAND "@SH_COMMAND@" /* A path to a rm-like command */ -#define RM "@RM@" +#cmakedefine RM_COMMAND "@RM_COMMAND@" /* A path to a cp-like command */ -#define CP "@CP@" +#cmakedefine CP_COMMAND "@CP_COMMAND@" + +/* RSH tools (rsh, rcp) found on the system */ +#cmakedefine HAS_RSH /* A path to a rsh-like command */ -#define RSH "@RSH@" +#cmakedefine RSH_COMMAND "@RSH_COMMAND@" -/* A path to a scp-like command */ -#define SCP "@SCP@" +/* A path to a rcp-like command */ +#cmakedefine RCP_COMMAND "@RCP_COMMAND@" -/* A path to a sh-like command */ -#define SH "@SH@" -#cmakedefine SH_COMMAND_IS_CMD +/* SSH tools (ssh, scp) found on the system */ +#cmakedefine HAS_SSH /* A path to a ssh-like command */ -#define SSH "@SSH@" +#cmakedefine SSH_COMMAND "@SSH_COMMAND@" + +/* A path to a scp-like command */ +#cmakedefine SCP_COMMAND "@SCP_COMMAND@" #endif diff --git a/CMakeModules/FindLocal.cmake b/CMakeModules/FindLocal.cmake index bddeb89..4fb8b4e 100644 --- a/CMakeModules/FindLocal.cmake +++ b/CMakeModules/FindLocal.cmake @@ -20,64 +20,46 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -MACRO(FIND_LOCAL_COMMAND VAR COMMAND) - FIND_PROGRAM(${VAR} NAMES ${COMMAND} ${ARGN}) +MACRO(FIND_LOCAL_COMMAND VAR UNIX_COMMAND WIN32_COMMAND) + IF (WIN32) + FIND_PROGRAM(${VAR} ${WIN32_COMMAND}) + ELSE (WIN32) + FIND_PROGRAM(${VAR} ${UNIX_COMMAND}) + ENDIF (WIN32) IF (${VAR}) - MESSAGE(STATUS "${COMMAND} found : ${${VAR}}") + MESSAGE(STATUS "${VAR} found : ${${VAR}}") ELSE (${VAR}) - MESSAGE(STATUS "${COMMAND} not found, local submission might not work properly") - SET(${VAR} /bin/false) + MESSAGE(STATUS "${VAR} not found, local submission might not work properly") ENDIF (${VAR}) - MARK_AS_ADVANCED(${VAR}) ENDMACRO(FIND_LOCAL_COMMAND) -MESSAGE(STATUS "Looking for commands needed for local submission...") - -FIND_PROGRAM(RM rm) -IF (RM) - MESSAGE(STATUS "rm found : ${RM}") -ELSE (RM) +MACRO(FIND_LOCAL_COMMAND_WIN32_DEF VAR UNIX_COMMAND WIN32_DEFAULT) IF (WIN32) - MESSAGE(STATUS "using 'del' as rm command") - SET(RM del) + SET(${VAR} ${WIN32_DEFAULT} CACHE STRING "${VAR}") + MESSAGE(STATUS "${VAR} found : using '${${VAR}}' (Windows default)") ELSE (WIN32) - MESSAGE(STATUS "rm not found, local submission might not work properly") - SET(RM /bin/false) + FIND_LOCAL_COMMAND(${VAR} ${UNIX_COMMAND} ${WIN32_DEFAULT}) ENDIF (WIN32) -ENDIF (RM) -MARK_AS_ADVANCED(RM) +ENDMACRO(FIND_LOCAL_COMMAND_WIN32_DEF) -FIND_PROGRAM(SH sh) -IF (SH) - MESSAGE(STATUS "sh found : ${SH}") -ELSE (SH) - FIND_PROGRAM(CMD cmd) - IF (CMD) - MESSAGE(STATUS "cmd found : ${CMD}") - SET(SH ${CMD}) - SET(SH_COMMAND_IS_CMD TRUE) - ELSE (CMD) - MESSAGE(STATUS "sh not found, local submission might not work properly") - SET(SH /bin/false) - ENDIF (CMD) -ENDIF (SH) -MARK_AS_ADVANCED(CMD SH SH_COMMAND_IS_CMD) +MACRO(EVAL VAR) + IF(${ARGN}) + SET(${VAR} TRUE) + ELSE(${ARGN}) + SET(${VAR} FALSE) + ENDIF(${ARGN}) +ENDMACRO(EVAL) -FIND_PROGRAM(CP cp) -IF (CP) - MESSAGE(STATUS "cp found : ${CP}") -ELSE (CP) - IF (WIN32) - MESSAGE(STATUS "using 'copy' as cp command") - SET(CP copy) - ELSE (WIN32) - MESSAGE(STATUS "cp not found, local submission might not work properly") - SET(CP /bin/false) - ENDIF (WIN32) -ENDIF (CP) -MARK_AS_ADVANCED(CP) +MESSAGE(STATUS "Looking for commands needed for local submission...") + +FIND_LOCAL_COMMAND_WIN32_DEF(RM_COMMAND rm del) +FIND_LOCAL_COMMAND(SH_COMMAND sh cmd.exe) +FIND_LOCAL_COMMAND_WIN32_DEF(CP_COMMAND cp copy) +FIND_LOCAL_COMMAND(RSH_COMMAND rsh rsh) +FIND_LOCAL_COMMAND(RCP_COMMAND rcp rcp) +FIND_LOCAL_COMMAND(SSH_COMMAND ssh plink) +FIND_LOCAL_COMMAND(SCP_COMMAND scp pscp) -FIND_LOCAL_COMMAND(RSH rsh) -FIND_LOCAL_COMMAND(RCP rcp) -FIND_LOCAL_COMMAND(SSH ssh plink) -FIND_LOCAL_COMMAND(SCP scp pscp) +EVAL (HAS_SH SH_COMMAND AND CP_COMMAND AND RM_COMMAND) +EVAL (HAS_RSH RSH_COMMAND AND RCP_COMMAND) +EVAL (HAS_SSH SSH_COMMAND AND SCP_COMMAND) diff --git a/src/Core/Batch_BatchManager_eClient.cxx b/src/Core/Batch_BatchManager_eClient.cxx index 1808274..fc3f473 100644 --- a/src/Core/Batch_BatchManager_eClient.cxx +++ b/src/Core/Batch_BatchManager_eClient.cxx @@ -29,9 +29,6 @@ * */ -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_RunTimeException.hxx" - #include #include #include @@ -42,7 +39,10 @@ #include #endif -#include "Batch_config.h" +#include + +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_RunTimeException.hxx" #ifdef MSVC #define EXISTS(path) _access_s(path, 0) == 0 @@ -56,8 +56,8 @@ using namespace std; namespace Batch { BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, - const char* protocol, const char* mpiImpl) - : BatchManager(parent, host), _protocol(protocol), _username("") + CommunicationProtocolType protocolType, const char* mpiImpl) + : BatchManager(parent, host), _protocol(CommunicationProtocol::getInstance(protocolType)), _username("") { // instanciation of mpi implementation needed to launch executable in batch script _mpiImpl = FactoryMpiImpl(mpiImpl); @@ -66,7 +66,6 @@ namespace Batch { // Destructeur BatchManager_eClient::~BatchManager_eClient() { - // Nothing to do delete _mpiImpl; } @@ -78,29 +77,8 @@ namespace Batch { Versatile::iterator Vit; _username = string(params[USER]); - string command = "\""; - string copy_command = "\""; - - // Test protocol - if( _protocol == "rsh" ) { - command += RSH; - copy_command += RCP; - } else if( _protocol == "ssh" ) { - command += SSH; - copy_command += SCP; - } else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - copy_command += "\" "; - - // First step : creating batch tmp files directory - if(_username != ""){ - command += _username + "@"; - } - command += _hostname; - command += " mkdir -p "; - command += string(params[TMPDIR]); + string subCommand = string("mkdir -p ") + string(params[TMPDIR]); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); cerr << command.c_str() << endl; status = system(command.c_str()); if(status) { @@ -114,19 +92,9 @@ namespace Batch { // Second step : copy fileToExecute into // batch tmp files directory 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 (executeFile.size() != 0) { + status = _protocol.copyFile(executeFile, "", "", + params[TMPDIR], _hostname, _username); if(status) { std::ostringstream oss; oss << status; @@ -136,23 +104,11 @@ namespace Batch { } #ifdef WIN32 - // On Windows, we make the remote file executable afterward because pscp does not preserve - // access permissions on files - command = "\""; - if( _protocol == "rsh" ) { - command += RSH; - } else if( _protocol == "ssh" ) { - command += SSH; - } else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - if(_username != ""){ - command += _username + "@"; - } - command += _hostname; - command += " chmod u+x "; - command += string(params[TMPDIR]) + "/" + string(params[EXECUTABLE]); + // On Windows, we make the remote file executable afterward because + // pscp does not preserve access permissions on files + subCommand = string("chmod u+x ") + string(params[TMPDIR]) + "/" + + string(params[EXECUTABLE]); + command = _protocol.getExecCommand(subCommand, _hostname, _username); cerr << command.c_str() << endl; status = system(command.c_str()); if(status) { @@ -170,18 +126,8 @@ namespace Batch { for(Vit=V.begin(); Vit!=V.end(); Vit++) { CoupleType cpt = *static_cast< CoupleType * >(*Vit); Couple inputFile = cpt; - command = copy_command; - command += inputFile.getLocal(); - command += " "; - if(_username != ""){ - command += _username; - command += "@"; - } - command += _hostname; - command += ":"; - command += inputFile.getRemote(); - cerr << command.c_str() << endl; - status = system(command.c_str()); + status = _protocol.copyFile(inputFile.getLocal(), "", "", + inputFile.getRemote(), _hostname, _username); if(status) { std::ostringstream oss; oss << status; @@ -195,8 +141,6 @@ namespace Batch { void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException) { - int status; - Parametre params = job.getParametre(); Versatile V = params[OUTFILE]; Versatile::iterator Vit; @@ -204,32 +148,9 @@ namespace Batch { for(Vit=V.begin(); Vit!=V.end(); Vit++) { CoupleType cpt = *static_cast< CoupleType * >(*Vit); Couple outputFile = cpt; - - string command = "\""; - - // Test protocol - if( _protocol == "rsh" ) { - command += RCP; - } else if( _protocol == "ssh" ) { - command += SCP; - } else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - - if (_username != ""){ - command += _username; - command += "@"; - } - command += _hostname; - command += ":"; - command += outputFile.getRemote(); - command += " "; - command += directory; - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) - { + int status = _protocol.copyFile(outputFile.getRemote(), _hostname, _username, + directory, "", ""); + if (status) { // Try to get what we can (logs files) // throw BatchException("Error of connection on remote host"); std::string mess("Copy command failed ! status is :"); @@ -309,14 +230,17 @@ namespace Batch { #else string fileName = getTmpDir() + "/" + prefix + "-XXXXXX"; - char buf[fileName.size()+1]; + char * buf = new char[fileName.size()+1]; fileName.copy(buf, fileName.size()); buf[fileName.size()] = '\0'; int fd = mkstemp(buf); - if (fd == -1) + if (fd == -1) { + delete[] buf; throw RunTimeException(string("Can't create temporary file ") + fileName); + } fileName = buf; + delete[] buf; outputStream.open(fileName.c_str()); close(fd); // Close the file descriptor so that the file is not opened twice @@ -369,12 +293,15 @@ namespace Batch { #else - char buf[baseName.size()+1]; + char * buf = new char[baseName.size() + 1]; baseName.copy(buf, baseName.size()); buf[baseName.size()] = '\0'; - if (mkdtemp(buf) == NULL) + if (mkdtemp(buf) == NULL) { + delete[] buf; throw RunTimeException(string("Can't create temporary directory ") + baseName); + } tmpDirName = buf; + delete[] buf; #endif diff --git a/src/Core/Batch_BatchManager_eClient.hxx b/src/Core/Batch_BatchManager_eClient.hxx index a225492..74e8cbc 100644 --- a/src/Core/Batch_BatchManager_eClient.hxx +++ b/src/Core/Batch_BatchManager_eClient.hxx @@ -36,6 +36,7 @@ #include "Batch_MpiImpl.hxx" #include "Batch_BatchManager.hxx" #include "Batch_EmulationException.hxx" +#include "Batch_CommunicationProtocol.hxx" #include @@ -48,12 +49,12 @@ namespace Batch { public: // Constructeur et destructeur BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host="localhost", - const char* protocol="ssh", const char* mpiImpl="mpich1"); + CommunicationProtocolType protocolType = SSH, const char* mpiImpl="mpich1"); virtual ~BatchManager_eClient(); void importOutputFiles( const Job & job, const std::string directory ) throw(EmulationException); protected: - std::string _protocol; // protocol to access _hostname + const CommunicationProtocol & _protocol; // protocol to access _hostname std::string _username; // username to access _hostname MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script diff --git a/src/Core/Batch_CommunicationProtocol.cxx b/src/Core/Batch_CommunicationProtocol.cxx new file mode 100644 index 0000000..656c9fd --- /dev/null +++ b/src/Core/Batch_CommunicationProtocol.cxx @@ -0,0 +1,143 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocol.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include + +#include "Batch_CommunicationProtocol.hxx" +#include "Batch_CommunicationProtocolRSH.hxx" +#include "Batch_CommunicationProtocolSH.hxx" +#include "Batch_CommunicationProtocolSSH.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_RunTimeException.hxx" + +using namespace std; + +namespace Batch { + + CommunicationProtocol::~CommunicationProtocol() + { + } + + const CommunicationProtocol & CommunicationProtocol::getInstance(CommunicationProtocolType protocolType) + { + if (protocolType == SH) { + #ifdef HAS_SH + static CommunicationProtocolSH instanceSH; + return instanceSH; + #else + throw RunTimeException("Can't use SH protocol (SH tools were " + "not found on the system at compile time)."); + #endif + } else if (protocolType == RSH) { +#ifdef HAS_RSH + static CommunicationProtocolRSH instanceRSH; + return instanceRSH; +#else + throw RunTimeException("Can't use RSH protocol (RSH tools were " + "not found on the system at compile time)."); +#endif + } else if (protocolType == SSH) { +#ifdef HAS_SSH + static CommunicationProtocolSSH instanceSSH; + return instanceSSH; +#else + throw RunTimeException("Can't use SSH protocol (SSH tools were " + "not found on the system at compile time)."); +#endif + } else + throw APIInternalFailureException("Unknown communication protocol."); + } + + string CommunicationProtocol::getExecCommand(const string & subCommand, + const string & host, + const string & user) const + { + return commandStringFromArgs(getExecCommandArgs(subCommand, host, user)); + } + + int CommunicationProtocol::copyFile(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const + { + string command = commandStringFromArgs(getCopyCommandArgs(sourcePath, sourceHost, sourceUser, + destinationPath, destinationHost, + destinationUser)); + cout << command.c_str() << endl; + int status = system(command.c_str()); + return status; + } + + string CommunicationProtocol::getRemoveSubCommand(const string & path) const + { + return string("rm ") + path; + } + + int CommunicationProtocol::removeFile(const std::string & path, + const std::string & host, + const std::string & user) const + { + string command = getExecCommand(getRemoveSubCommand(path), host, user); + cout << command.c_str() << endl; + int status = system(command.c_str()); + return status; + } + + string CommunicationProtocol::commandStringFromArgs(const vector & commandArgs) const + { + string commandStr; + + // On Windows we surround the whole command with quotes to avoid problems when + // we have several quoted arguments. +#ifdef WIN32 + commandStr += "\""; +#endif + + for (unsigned int i=0 ; i +#include + +#include "Batch_Defines.hxx" + +namespace Batch { + + enum CommunicationProtocolType {SH, SSH, RSH}; + + class BATCH_EXPORT CommunicationProtocol + { + public: + virtual ~CommunicationProtocol(); + + static const CommunicationProtocol & getInstance(CommunicationProtocolType protocolType); + + virtual std::string getExecCommand(const std::string & subCommand, + const std::string & host, + const std::string & user) const; + + virtual std::vector getExecCommandArgs(const std::string & subCommand, + const std::string & host, + const std::string & user) const=0; + + virtual int copyFile(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const; + + virtual int removeFile(const std::string & path, + const std::string & host, + const std::string & user) const; + + protected: + + virtual std::vector getCopyCommandArgs(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const=0; + + virtual std::string getRemoveSubCommand(const std::string & path) const; + + std::string commandStringFromArgs(const std::vector & args) const; + + }; + +} + +#endif diff --git a/src/Core/Batch_CommunicationProtocolRSH.cxx b/src/Core/Batch_CommunicationProtocolRSH.cxx new file mode 100644 index 0000000..5fabe63 --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolRSH.cxx @@ -0,0 +1,191 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolRSH.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifdef WIN32 +#include +#include + +#include +#endif + +#include + +#include "Batch_CommunicationProtocolRSH.hxx" + +using namespace std; + +namespace Batch { + + vector CommunicationProtocolRSH::getExecCommandArgs(const string & subCommand, + const string & host, + const string & user) const + { + vector cmd; + + cmd.push_back(RSH_COMMAND); + cmd.push_back(host); + + if (user.size() > 0) { + cmd.push_back("-l"); + cmd.push_back(user); + } + +#ifdef WIN32 + cmd.push_back("-n"); +#endif + + cmd.push_back(subCommand); + + return cmd; + } + + vector CommunicationProtocolRSH::getCopyCommandArgs(const string & sourcePath, + const string & sourceHost, + const string & sourceUser, + const string & destinationPath, + const string & destinationHost, + const string & destinationUser) const + { + vector cmd; + + string fullSource; + if (sourceHost.size() != 0) { + if (sourceUser.size() != 0) { +#ifdef WIN32 + fullSource += sourceHost + "." + sourceUser + ":"; +#else + fullSource += sourceUser + "@" + sourceHost + ":"; +#endif + } else { + fullSource += sourceHost + ":"; + } + } + fullSource += sourcePath; + + string fullDestination; + if (destinationHost.size() != 0) { + if (destinationUser.size() != 0) { +#ifdef WIN32 + fullDestination += destinationHost + "." + destinationUser + ":"; +#else + fullDestination += destinationUser + "@" + destinationHost + ":"; +#endif + } else { + fullDestination += destinationHost + ":"; + } + } + fullDestination += destinationPath; + + cmd.push_back(RCP_COMMAND); + cmd.push_back(fullSource); + cmd.push_back(fullDestination); + + return cmd; + } + +#ifdef WIN32 + int CommunicationProtocolRSH::copyFile(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const + { + // On Windows, we can't use drive letters in the paths of rcp command because they + // are confused with host names. So we must first change the working directory and + // then copy the file using its path without the drive letter. + + // Extract the drive letter from the source path + string sourcePathWithoutDrive; + char sourceDriveLetter = getDriveLetter(sourcePath, &sourcePathWithoutDrive); + // Error if we have a drive letter and it is a remote path + if (sourceDriveLetter != '\0' && sourceHost.size() != 0) + throw RunTimeException(string("Invalid path: ") + sourcePath + " for host " + sourceHost); + + // Extract the drive letter from the destination path + string destinationPathWithoutDrive; + char destinationDriveLetter = getDriveLetter(destinationPath, &destinationPathWithoutDrive); + // Error if we have a drive letter and it is a remote path + if (destinationDriveLetter != '\0' && destinationHost.size() != 0) + throw RunTimeException(string("Invalid path: ") + destinationPath + " for host " + destinationHost); + + // Error if we have two drive letters and they are different + if (sourceDriveLetter != '\0' && destinationDriveLetter != '\0' && + sourceDriveLetter != destinationDriveLetter) + throw RunTimeException(string("Can't use RCP to copy files between different drives: ") + + sourcePath + (", ") + destinationPath); + + // Now get the drive letter to use if there is one + char driveLetter = (sourceDriveLetter != '\0') ? sourceDriveLetter : destinationDriveLetter; + + // Get the drive of the current working directory + char cwd[_MAX_PATH]; + _getcwd(cwd, _MAX_PATH); + char currentDrive = getDriveLetter(cwd); + + // Change working directory if necessary + if (driveLetter != '\0' && driveLetter != currentDrive) { + char newdir[3]; + newdir[0] = driveLetter; + newdir[1] = ':'; + newdir[2] = '\0'; + cout << "Changing directory: " << newdir << endl; + _chdir(newdir); + } + + int status = CommunicationProtocol::copyFile(sourcePathWithoutDrive, sourceHost, sourceUser, + destinationPathWithoutDrive, destinationHost, destinationUser); + + // Go back to previous directory if necessary + if (driveLetter != '\0' && driveLetter != currentDrive) { + cout << "Changing directory: " << cwd << endl; + _chdir(cwd); + } + + return status; + } + + char CommunicationProtocolRSH::getDriveLetter(const string & path, string * pathWithoutDrive) const + { + if (path.find(':') != string::npos) { + // Error if the colon is not the second character + if (path.size() < 2 || path[1] != ':') + throw RunTimeException(string("Invalid path: ") + path); + else { + if (pathWithoutDrive != NULL) *pathWithoutDrive = path.substr(2); + return path[0]; + } + } else { + if (pathWithoutDrive != NULL) *pathWithoutDrive = path; + return '\0'; + } + } + +#endif + +} diff --git a/src/Core/Batch_CommunicationProtocolRSH.hxx b/src/Core/Batch_CommunicationProtocolRSH.hxx new file mode 100644 index 0000000..80f180c --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolRSH.hxx @@ -0,0 +1,75 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolRSH.hxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLRSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLRSH_H_ + +#include +#include + +#include "Batch_Defines.hxx" +#include "Batch_CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolRSH : public CommunicationProtocol + { + public: + std::vector getExecCommandArgs(const std::string & subCommand, + const std::string & host, + const std::string & user) const; + + std::vector getCopyCommandArgs(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const; + +#ifdef WIN32 + + // On Windows, we must reimplement copyFile because there are problems with absolute + // paths containing a colon. + int copyFile(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const; + + protected: + + char getDriveLetter(const std::string & path, std::string * pathWithoutDrive = NULL) const; + +#endif + + }; + +} + +#endif diff --git a/src/Core/Batch_CommunicationProtocolSH.cxx b/src/Core/Batch_CommunicationProtocolSH.cxx new file mode 100644 index 0000000..2c5bfd0 --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolSH.cxx @@ -0,0 +1,88 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolSH.cxx : + * + * Created on: 16 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "Batch_CommunicationProtocolSH.hxx" + +using namespace std; + +namespace Batch { + + // Simple method to fix path strings depending on the platform. On Windows, it will replace + // forward slashes '/' by backslashes '\'. On Unix, the path is just copied without change. + string CommunicationProtocolSH::fixPath(const string & path) const + { + string fixedPath = path; + #ifdef WIN32 + for (unsigned int i=0 ; i CommunicationProtocolSH::getExecCommandArgs(const string & subCommand, + const string & host, + const string & user) const + { + vector cmd; + + cmd.push_back(fixPath(SH_COMMAND)); + +#ifdef WIN32 + cmd.push_back("/c"); +#else + cmd.push_back("-c"); +#endif + + cmd.push_back(fixPath(subCommand)); + + return cmd; + } + + vector CommunicationProtocolSH::getCopyCommandArgs(const string & sourcePath, + const string & sourceHost, + const string & sourceUser, + const string & destinationPath, + const string & destinationHost, + const string & destinationUser) const + { + vector cmd; + cmd.push_back(CP_COMMAND); + cmd.push_back(fixPath(sourcePath)); + cmd.push_back(fixPath(destinationPath)); + return cmd; + } + + string CommunicationProtocolSH::getRemoveSubCommand(const string & path) const + { + return string(RM_COMMAND) + " " + path; + } + +} diff --git a/src/Core/Batch_CommunicationProtocolSH.hxx b/src/Core/Batch_CommunicationProtocolSH.hxx new file mode 100644 index 0000000..2b1d2f0 --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolSH.hxx @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolSH.hxx : + * + * Created on: 16 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLSH_H_ + +#include +#include + +#include "Batch_Defines.hxx" +#include "Batch_CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolSH : public CommunicationProtocol + { + public: + std::vector getExecCommandArgs(const std::string & subCommand, + const std::string & host, + const std::string & user) const; + + std::vector getCopyCommandArgs(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const; + + std::string getRemoveSubCommand(const std::string & path) const; + + protected: + + std::string fixPath(const std::string & path) const; + + }; + +} + +#endif diff --git a/src/Core/Batch_CommunicationProtocolSSH.cxx b/src/Core/Batch_CommunicationProtocolSSH.cxx new file mode 100644 index 0000000..a9c6590 --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolSSH.cxx @@ -0,0 +1,93 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolSSH.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "Batch_CommunicationProtocolSSH.hxx" + +using namespace std; + +namespace Batch { + + vector CommunicationProtocolSSH::getExecCommandArgs(const string & subCommand, + const string & host, + const string & user) const + { + vector cmd; + + cmd.push_back(SSH_COMMAND); + cmd.push_back(host); + + if (user.size() != 0) { + cmd.push_back("-l"); + cmd.push_back(user); + } + + cmd.push_back(subCommand); + + return cmd; + } + + vector CommunicationProtocolSSH::getCopyCommandArgs(const string & sourcePath, + const string & sourceHost, + const string & sourceUser, + const string & destinationPath, + const string & destinationHost, + const string & destinationUser) const + { + vector cmd; + + string fullSource; + if (sourceHost.size() != 0) { + if (sourceUser.size() != 0) { + fullSource += sourceUser + "@"; + } + fullSource += sourceHost + ":"; + } + fullSource += sourcePath; + + string fullDestination; + if (destinationHost.size() != 0) { + if (destinationUser.size() != 0) { + fullDestination += destinationUser + "@"; + } + fullDestination += destinationHost + ":"; + } + fullDestination += destinationPath; + + // Option -p is used to keep the same permissions for the destination file + // (particularly useful to keep scripts executable when copying them) + cmd.push_back(SCP_COMMAND); + cmd.push_back("-p"); + cmd.push_back(fullSource); + cmd.push_back(fullDestination); + + return cmd; + } + +} diff --git a/src/Core/Batch_CommunicationProtocolSSH.hxx b/src/Core/Batch_CommunicationProtocolSSH.hxx new file mode 100644 index 0000000..c02bcd2 --- /dev/null +++ b/src/Core/Batch_CommunicationProtocolSSH.hxx @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Batch_CommunicationProtocolSSH.hxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLSSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLSSH_H_ + +#include +#include + +#include "Batch_Defines.hxx" +#include "Batch_CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolSSH : public CommunicationProtocol + { + public: + std::vector getExecCommandArgs(const std::string & subCommand, + const std::string & host, + const std::string & user) const; + + std::vector getCopyCommandArgs(const std::string & sourcePath, + const std::string & sourceHost, + const std::string & sourceUser, + const std::string & destinationPath, + const std::string & destinationHost, + const std::string & destinationUser) const; + + protected: + + }; + +} + +#endif diff --git a/src/Core/Batch_FactBatchManager_eClient.hxx b/src/Core/Batch_FactBatchManager_eClient.hxx index 82192d7..d047f55 100644 --- a/src/Core/Batch_FactBatchManager_eClient.hxx +++ b/src/Core/Batch_FactBatchManager_eClient.hxx @@ -29,25 +29,27 @@ * */ -#ifndef _FACTBATCHMANAGER_eClient_H_ -#define _FACTBATCHMANAGER_eClient_H_ +#ifndef _FACTBATCHMANAGER_ECLIENT_H_ +#define _FACTBATCHMANAGER_ECLIENT_H_ #include -#include + #include "Batch_FactBatchManager.hxx" +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_CommunicationProtocol.hxx" namespace Batch { - - class BatchManager_eClient; - class FactBatchManager_eClient : public FactBatchManager + class BATCH_EXPORT FactBatchManager_eClient : public FactBatchManager { public: // Constructeur et destructeur FactBatchManager_eClient(const std::string & type); virtual ~FactBatchManager_eClient(); - virtual Batch::BatchManager_eClient * operator() (const char * hostname,const char * protocol, const char * mpi) const = 0; + virtual Batch::BatchManager_eClient * operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpi) const = 0; protected: diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index b3756ed..d45850d 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -26,6 +26,7 @@ SET(CLASS_LIST Core/Batch_APIInternalFailureException Core/Batch_BatchManagerCatalog Core/Batch_BoolType Core/Batch_CharType + Core/Batch_CommunicationProtocol Core/Batch_ConnexionFailureException Core/Batch_Couple Core/Batch_CoupleType @@ -55,6 +56,24 @@ SET(CLASS_LIST Core/Batch_APIInternalFailureException Core/Batch_Versatile ) +IF (HAS_SH) + SET(CLASS_LIST ${CLASS_LIST} + Core/Batch_CommunicationProtocolSH + ) +ENDIF (HAS_SH) + +IF (HAS_RSH) + SET(CLASS_LIST ${CLASS_LIST} + Core/Batch_CommunicationProtocolRSH + ) +ENDIF (HAS_RSH) + +IF (HAS_SSH) + SET(CLASS_LIST ${CLASS_LIST} + Core/Batch_CommunicationProtocolSSH + ) +ENDIF (HAS_SSH) + APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST}) APPEND_CLASSES_TO_HDR_FILES(Core/Batch_Defines) diff --git a/src/LSF/Batch_BatchManager_eLSF.cxx b/src/LSF/Batch_BatchManager_eLSF.cxx index 14b5a2b..2b7ea3c 100644 --- a/src/LSF/Batch_BatchManager_eLSF.cxx +++ b/src/LSF/Batch_BatchManager_eLSF.cxx @@ -32,23 +32,25 @@ #include #include #include +#include #include -#include -#include -#include "Batch_BatchManager_eLSF.hxx" #ifdef WIN32 -# include -# include +#include #else -# include +#include #endif +#include "Batch_BatchManager_eLSF.hxx" +#include "Batch_JobInfo_eLSF.hxx" + using namespace std; namespace Batch { - BatchManager_eLSF::BatchManager_eLSF(const FactBatchManager * parent, const char * host, const char * protocol, const char * mpiImpl) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_eClient(parent,host,protocol,mpiImpl) + BatchManager_eLSF::BatchManager_eLSF(const FactBatchManager * parent, const char * host, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl) { // Nothing to do } @@ -81,34 +83,14 @@ namespace Batch { // 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 name of log file (local) + string logFile = generateTemporaryFileName("LSF-submitlog"); // define command to submit batch - command = _protocol; - command += " "; - - if(_username != ""){ - command += _username; - command += "@"; - } - - command += _hostname; - command += " \"cd " ; - command += dirForTmpFiles ; - command += "; bsub < " ; - command += fileNameToExecute ; - command += "_Batch.sh\" > "; + string subCommand = string("cd ") + dirForTmpFiles + "; bsub < " + + fileNameToExecute + "_Batch.sh"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; command += logFile; cerr << command.c_str() << endl; status = system(command.c_str()); @@ -138,23 +120,12 @@ namespace Batch { istringstream iss(jobid.getReference()); iss >> ref; - // define command to submit batch - string command; - command = _protocol; - command += " "; - - if (_username != ""){ - command += _username; - command += "@"; - } - - command += _hostname; - command += " \"bkill " ; - command += iss.str(); - command += "\""; + // define command to delete batch + string subCommand = string("bkill ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); cerr << command.c_str() << endl; status = system(command.c_str()); - if(status) + if (status) throw EmulationException("Error of connection on remote host"); cerr << "jobId = " << ref << "killed" << endl; @@ -198,38 +169,17 @@ namespace Batch { istringstream iss(jobid.getReference()); iss >> id; - // 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"; + // define name of log file (local) + string logFile = generateTemporaryFileName(string("LSF-querylog-id") + jobid.getReference()); - string command; - int status; - - // define command to submit batch - command = _protocol; - command += " "; - - if (_username != ""){ - command += _username; - command += "@"; - } - - command += _hostname; - command += " \"bjobs " ; - command += iss.str(); - command += "\" > "; + // define command to query batch + string subCommand = string("bjobs ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; command += logFile; cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) + int status = system(command.c_str()); + if (status) throw EmulationException("Error of connection on remote host"); JobInfo_eLSF ji = JobInfo_eLSF(id,logFile); @@ -247,7 +197,6 @@ namespace Batch { void BatchManager_eLSF::buildBatchScript(const Job & job) { #ifndef WIN32 //TODO: need for porting on Windows - int status; Parametre params = job.getParametre(); Environnement env = job.getEnvironnement(); const int nbproc = params[NBPROC]; @@ -317,28 +266,10 @@ namespace Batch { 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) + int status = _protocol.copyFile(TmpFileName, "", "", + dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) throw EmulationException("Error of connection on remote host"); remove(TmpFileName.c_str()); diff --git a/src/LSF/Batch_BatchManager_eLSF.hxx b/src/LSF/Batch_BatchManager_eLSF.hxx index d09db3d..f4840d9 100644 --- a/src/LSF/Batch_BatchManager_eLSF.hxx +++ b/src/LSF/Batch_BatchManager_eLSF.hxx @@ -29,33 +29,23 @@ * */ -#ifndef _BATCHMANAGER_eLSF_H_ -#define _BATCHMANAGER_eLSF_H_ +#ifndef _BATCHMANAGER_ELSF_H_ +#define _BATCHMANAGER_ELSF_H_ -#include "Batch_Defines.hxx" - -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_eLSF.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" +#include +#include +#include +#include +#include namespace Batch { - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - class BATCH_EXPORT BatchManager_eLSF : public BatchManager_eClient { public: // Constructeur et destructeur - 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 + BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host virtual ~BatchManager_eLSF(); // Recupere le nom du serveur par defaut diff --git a/src/LSF/Batch_FactBatchManager_eLSF.cxx b/src/LSF/Batch_FactBatchManager_eLSF.cxx index e46b355..f799922 100644 --- a/src/LSF/Batch_FactBatchManager_eLSF.cxx +++ b/src/LSF/Batch_FactBatchManager_eLSF.cxx @@ -28,10 +28,8 @@ * */ -#include #include "Batch_BatchManager_eLSF.hxx" #include "Batch_FactBatchManager_eLSF.hxx" -//#include "utilities.h" namespace Batch { @@ -54,10 +52,12 @@ namespace Batch { return new BatchManager_eLSF(this, hostname); } - BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const + BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const { // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'"); - return new BatchManager_eLSF(this, hostname, protocol, mpiImpl); + return new BatchManager_eLSF(this, hostname, protocolType, mpiImpl); } } diff --git a/src/LSF/Batch_FactBatchManager_eLSF.hxx b/src/LSF/Batch_FactBatchManager_eLSF.hxx index d2dec68..dc6adbf 100644 --- a/src/LSF/Batch_FactBatchManager_eLSF.hxx +++ b/src/LSF/Batch_FactBatchManager_eLSF.hxx @@ -31,17 +31,12 @@ #ifndef _FACTBATCHMANAGER_eLSF_H_ #define _FACTBATCHMANAGER_eLSF_H_ -#include "Batch_Defines.hxx" - -#include -#include -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" +#include +#include +#include namespace Batch { - class BatchManager_eLSF; - class BATCH_EXPORT FactBatchManager_eLSF : public FactBatchManager_eClient { public: @@ -50,7 +45,9 @@ namespace Batch { virtual ~FactBatchManager_eLSF(); virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const; + virtual BatchManager_eClient * operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; protected: diff --git a/src/Local/Batch_BatchManager_Local.cxx b/src/Local/Batch_BatchManager_Local.cxx index 22e5fb8..1f95608 100644 --- a/src/Local/Batch_BatchManager_Local.cxx +++ b/src/Local/Batch_BatchManager_Local.cxx @@ -27,6 +27,9 @@ * Date : Thu Nov 6 10:17:22 2003 * Projet : Salome 2 * +* Refactored by Renaud Barate (EDF R&D) in September 2009 to use +* CommunicationProtocol classes and merge Local_SH, Local_RSH and Local_SSH batch +* managers. */ #include @@ -37,11 +40,11 @@ #include #ifdef WIN32 -# include +#include #include "Batch_RunTimeException.hxx" #else -# include -# include +#include +#include #endif #include #include @@ -57,10 +60,12 @@ namespace Batch { // Constructeur - BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host) + BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host, + CommunicationProtocolType protocolType) throw(InvalidArgumentException,ConnexionFailureException) - : BatchManager(parent, host), _connect(0), _threads_mutex(), _threads(), _thread_id_id_association_mutex(), - _thread_id_id_association_cond(), _thread_id_id_association() + : BatchManager(parent, host), _connect(0), _threads_mutex(), _threads(), + _protocol(CommunicationProtocol::getInstance(protocolType)), + _thread_id_id_association_mutex(), _thread_id_id_association_cond(), _thread_id_id_association() { pthread_mutex_init(&_threads_mutex, NULL); pthread_mutex_init(&_thread_id_id_association_mutex, NULL); @@ -75,6 +80,11 @@ namespace Batch { pthread_cond_destroy(&_thread_id_id_association_cond); } + const CommunicationProtocol & BatchManager_Local::getProtocol() const + { + return _protocol; + } + // Methode pour le controle des jobs : soumet un job au gestionnaire const JobId BatchManager_Local::submitJob(const Job & job) { @@ -253,6 +263,37 @@ namespace Batch { } + vector BatchManager_Local::exec_command(const Parametre & param) const + { + ostringstream exec_sub_cmd; + +#ifdef WIN32 + char drive[_MAX_DRIVE]; + _splitpath(string(param[WORKDIR]).c_str(), drive, NULL, NULL, NULL); + if (strlen(drive) > 0) exec_sub_cmd << drive << " && "; +#endif + + exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE]; + + if (param.find(ARGUMENTS) != param.end()) { + Versatile V = param[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + exec_sub_cmd << " " << arg; + } + } + + string user; + Parametre::const_iterator it = param.find(USER); + if (it != param.end()) { + user = string(it->second); + } + + return _protocol.getExecCommandArgs(exec_sub_cmd.str(), param[EXECUTIONHOST], user); + } + + // Fabrique un identifiant unique pour les threads puisque le thread_id n'est pas unique // au cours du temps (il peut etre reutilise lorsqu'un thread se termine) // ATTENTION : cette methode est uniquement protegee par la section critique de l'association @@ -403,14 +444,10 @@ namespace Batch { string local = cp.getLocal(); string remote = cp.getRemote(); - string copy_cmd = p_ta->getBatchManager().copy_command("", "", local, user, - executionhost, workdir + "/" + remote); - UNDER_LOCK( cout << "Copying : " << copy_cmd << endl ); -#ifdef WIN32 - copy_cmd = string("\"") + copy_cmd + string("\""); -#endif - - if (system(copy_cmd.c_str()) ) { + int status = p_ta->getBatchManager().getProtocol().copyFile(local, "", "", + workdir + "/" + remote, + executionhost, user); + if (status) { // Echec de la copie rc |= 1; } else { @@ -455,14 +492,10 @@ namespace Batch { string local = cp.getLocal(); string remote = cp.getRemote(); - string copy_cmd = p_ta->getBatchManager().copy_command(user, executionhost, workdir + "/" + remote, - "", "", local); - UNDER_LOCK( cout << "Copying : " << copy_cmd << endl ); -#ifdef WIN32 - copy_cmd = string("\"") + copy_cmd + string("\""); -#endif - - if (system(copy_cmd.c_str()) ) { + int status = p_ta->getBatchManager().getProtocol().copyFile(workdir + "/" + remote, + executionhost, user, + local, "", ""); + if (status) { // Echec de la copie rc |= 1; } else { @@ -478,12 +511,13 @@ namespace Batch { if ( (rc == 0) || (child < 0) ) { std::vector::const_iterator it; for(it=files_to_delete.begin(); it!=files_to_delete.end(); it++) { - string remove_cmd = p_ta->getBatchManager().remove_command(user, executionhost, *it); + p_ta->getBatchManager().getProtocol().removeFile(*it, executionhost, user); +/* string remove_cmd = p_ta->getBatchManager().remove_command(user, executionhost, *it); UNDER_LOCK( cout << "Removing : " << remove_cmd << endl ); #ifdef WIN32 remove_cmd = string("\"") + remove_cmd + string("\""); #endif - system(remove_cmd.c_str()); + system(remove_cmd.c_str());*/ } } @@ -710,45 +744,24 @@ namespace Batch { try { // EXECUTABLE is MANDATORY, if missing, we exit with failure notification - char * execpath = NULL; + vector command; if (param.find(EXECUTABLE) != param.end()) { - string executable = _bm.exec_command(param); - execpath = new char [executable.size() + 1]; - strncpy(execpath, executable.c_str(), executable.size() + 1); + command = _bm.exec_command(param); } else exit(1); - string debug_command = execpath; - - string name = (param.find(NAME) != param.end()) ? param[NAME] : param[EXECUTABLE]; - - char ** argv = NULL; - if (param.find(ARGUMENTS) != param.end()) { - Versatile V = param[ARGUMENTS]; - - argv = new char * [V.size() + 2]; // 1 pour name et 1 pour le NULL terminal - - argv[0] = new char [name.size() + 1]; - strncpy(argv[0], name.c_str(), name.size() + 1); - - debug_command += string(" # ") + argv[0]; - - int i = 1; - for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++, i++) { - StringType argt = * static_cast(*it); - string arg = argt; - argv[i] = new char [arg.size() + 1]; - strncpy(argv[i], arg.c_str(), arg.size() + 1); - debug_command += string(" # ") + argv[i]; - } - - // assert (i == V.size() + 1) - argv[i] = NULL; + // Build the argument array argv from the command + char ** argv = new char * [command.size() + 1]; + string comstr; + for (string::size_type i=0 ; i0) comstr += " # "; + comstr += command[i]; } + argv[command.size()] = NULL; - UNDER_LOCK( cout << "*** debug_command = " << debug_command << endl ); - - + UNDER_LOCK( cout << "*** debug_command = " << comstr << endl ); // Create the environment for the new process. Note (RB): Here we change the environment for // the process launched in local. It would seem more logical to set the environment for the @@ -815,7 +828,7 @@ namespace Batch { // On execute la commande du fils - execve(execpath, argv, envp); + execve(argv[0], argv, envp); // No need to deallocate since nothing happens after a successful exec @@ -842,24 +855,21 @@ namespace Batch { try { // EXECUTABLE is MANDATORY, if missing, we throw an exception - string exec_command; + vector exec_command; if (param.find(EXECUTABLE) != param.end()) { exec_command = _bm.exec_command(param); } else { throw RunTimeException("Parameter \"EXECUTABLE\" is mandatory for local batch submission"); } - if (param.find(ARGUMENTS) != param.end()) { - Versatile V = param[ARGUMENTS]; - - for(Versatile::const_iterator it=V.begin() ; it!=V.end() ; it++) { - StringType argt = * static_cast(*it); - exec_command += string(" ") + string(argt); - } + // Build the command string from the command argument vector + string comstr; + for (unsigned int i=0 ; i0) comstr += " "; + comstr += exec_command[i]; } - UNDER_LOCK( cout << "*** exec_command = " << exec_command << endl ); - + UNDER_LOCK( cout << "*** debug_command = " << comstr << endl ); // Create the environment for the new process. Note (RB): Here we change the environment for // the process launched in local. It would seem more logical to set the environment for the @@ -890,7 +900,7 @@ namespace Batch { ZeroMemory( &pi, sizeof(pi) ); // Copy the command to a non-const buffer - char * buffer = strdup(exec_command.c_str()); + char * buffer = strdup(comstr.c_str()); // launch the new process BOOL res = CreateProcess(NULL, buffer, NULL, NULL, FALSE, diff --git a/src/Local/Batch_BatchManager_Local.hxx b/src/Local/Batch_BatchManager_Local.hxx index 5fac3d8..c3c5e19 100644 --- a/src/Local/Batch_BatchManager_Local.hxx +++ b/src/Local/Batch_BatchManager_Local.hxx @@ -27,12 +27,17 @@ * Date : Thu Nov 6 10:17:22 2003 * Projet : Salome 2 * + * Refactored by Renaud Barate (EDF R&D) in September 2009 to use + * CommunicationProtocol classes and merge Local_SH, Local_RSH and Local_SSH batch + * managers. + * */ #ifndef _BATCHMANAGER_LOCAL_H_ #define _BATCHMANAGER_LOCAL_H_ -#include "Batch_Defines.hxx" +#include +#include #ifdef WIN32 #include @@ -119,12 +124,19 @@ namespace Batch { public: // Constructeur et destructeur - BatchManager_Local(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host + BatchManager_Local(const FactBatchManager * parent, + const char * host="localhost", + CommunicationProtocolType protocolType = SSH) + throw(InvalidArgumentException, + ConnexionFailureException); // connexion a la machine host virtual ~BatchManager_Local(); // Recupere le nom du serveur par defaut // static string BatchManager_Local::getDefaultServer(); + // Get the underlying communication protocol + const CommunicationProtocol & getProtocol() const; + // 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 @@ -145,21 +157,10 @@ namespace Batch { pthread_mutex_t _threads_mutex; std::map _threads; - // Methode abstraite qui renvoie la commande de copie du fichier source en destination - virtual std::string copy_command( const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const = 0; - - // Methode abstraite qui renvoie la commande a executer - virtual std::string exec_command(Parametre & param) const = 0; - - // Methode abstraite qui renvoie la commande d'effacement du fichier - virtual std::string remove_command( const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const = 0; + const CommunicationProtocol & _protocol; + + // Methode qui renvoie la commande a executer + std::vector exec_command(const Parametre & param) const; private: struct ThreadIdIdAssociation { diff --git a/src/Local/Batch_BatchManager_Local_RSH.cxx b/src/Local/Batch_BatchManager_Local_RSH.cxx deleted file mode 100644 index 74c3a6a..0000000 --- a/src/Local/Batch_BatchManager_Local_RSH.cxx +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_RSH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include -#include -#include -#ifndef WIN32 -#include -#include -#endif -#include -#include -#include -#include -#include - -#include "Batch_IOMutex.hxx" -#include "Batch_BatchManager_Local_RSH.hxx" - -#include "Batch_config.h" - -#ifndef RCP -#error "RCP undefined. You must set RCP to a valid path to a rcp-like command." -#endif - -#ifndef RSH -#error "RSH undefined. You must set RSH to a valid path to a rsh-like command." -#endif - -using namespace std; - -namespace Batch { - - - // Constructeur - BatchManager_Local_RSH::BatchManager_Local_RSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host) - { - } - - // Destructeur - BatchManager_Local_RSH::~BatchManager_Local_RSH() - { - } - - - // Methode abstraite qui renvoie la commande de copie du fichier source en destination - string BatchManager_Local_RSH::copy_command(const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const - { - ostringstream fullsource; - if (host_source.size() != 0) { - if (user_source.size() != 0) { -#ifdef WIN32 - fullsource << host_source << "." << user_source << ":"; -#else - fullsource << user_source << "@" << host_source << ":"; -#endif - } else { - fullsource << host_source << ":"; - } - } - fullsource << source; - - ostringstream fulldestination; - if (host_destination.size() != 0) { - if (user_destination.size() != 0) { -#ifdef WIN32 - fulldestination << host_destination << "." << user_destination << ":"; -#else - fulldestination << user_destination << "@" << host_destination << ":"; -#endif - } else { - fulldestination << host_destination << ":"; - } - } - fulldestination << destination; - - ostringstream copy_cmd; - copy_cmd << "\"" << RCP << "\" " << fullsource.str() << " " << fulldestination.str(); - return copy_cmd.str(); - } - - // Methode abstraite qui renvoie la commande a executer - string BatchManager_Local_RSH::exec_command(Parametre & param) const - { - ostringstream exec_sub_cmd; - exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE]; - - if (param.find(ARGUMENTS) != param.end()) { - Versatile V = param[ARGUMENTS]; - for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { - StringType argt = * static_cast(*it); - string arg = argt; - exec_sub_cmd << " " << arg; - } - } - - Versatile new_arguments; - new_arguments.setMaxSize(0); - new_arguments = string(param[EXECUTIONHOST]); - - - if (param.find(USER) != param.end()) { - new_arguments += "-l"; - new_arguments += string(param[USER]); - } - -#ifdef WIN32 - new_arguments += "-n"; -#endif - - new_arguments += exec_sub_cmd.str(); - - param[ARGUMENTS] = new_arguments; - - // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh - param[EXECUTABLE] = RSH; - param.erase(NAME); - - return RSH; - } - - // Methode qui renvoie la commande d'effacement du fichier - string BatchManager_Local_RSH::remove_command(const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const - { - string fulldestination = (host_destination.size()) ? host_destination : "localhost"; - if (user_destination.size() != 0) { - fulldestination += " -l " + user_destination; - } - - // We consider here that the remote system is UNIX-like and has a "rm" command. Using the - // RM macro would be pointless here since the remote system is different from the local one. - ostringstream remove_cmd; - remove_cmd << "\"" << RSH << "\" " << fulldestination; -#ifdef WIN32 - remove_cmd << " -n"; -#endif - remove_cmd << " rm " << destination; - return remove_cmd.str(); - } -} diff --git a/src/Local/Batch_BatchManager_Local_RSH.hxx b/src/Local/Batch_BatchManager_Local_RSH.hxx deleted file mode 100644 index 235e3d8..0000000 --- a/src/Local/Batch_BatchManager_Local_RSH.hxx +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_RSH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#ifndef _BATCHMANAGER_LOCAL_RSH_H_ -#define _BATCHMANAGER_LOCAL_RSH_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include -#include -#include -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_Local.hxx" -#include "Batch_Job_Local.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_ConnexionFailureException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_NotYetImplementedException.hxx" -#include "Batch_BatchManager_Local.hxx" - -namespace Batch { - - class FactBatchManager; - - class BATCH_EXPORT BatchManager_Local_RSH : public BatchManager_Local - { - public: - // Constructeur et destructeur - BatchManager_Local_RSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - virtual ~BatchManager_Local_RSH(); - - protected: - // Methode qui renvoie la commande de copie du fichier source en destination - virtual std::string copy_command( const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - // Methode qui renvoie la commande a executer - virtual std::string exec_command(Parametre & param) const; - - // Methode qui renvoie la commande d'effacement du fichier - virtual std::string remove_command( const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - }; - -} - -#endif diff --git a/src/Local/Batch_BatchManager_Local_SH.cxx b/src/Local/Batch_BatchManager_Local_SH.cxx deleted file mode 100644 index 10778e1..0000000 --- a/src/Local/Batch_BatchManager_Local_SH.cxx +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#ifndef WIN32 -#include -#include -#endif -#include -#include -#include -#include -#include -#include "Batch_IOMutex.hxx" -#include "Batch_BatchManager_Local_SH.hxx" - -#include "Batch_config.h" - -#ifndef RM -#error "RM undefined. You must set RM to a valid path to a rm-like command." -#endif - -#ifndef CP -#error "CP undefined. You must set CP to a valid path to a cp-like command." -#endif - -#ifndef SH -#error "SH undefined. You must set SH to a valid path to a sh-like command." -#endif - -using namespace std; - -namespace Batch { - - // Simple method to fix path strings depending on the platform. On Windows, it will replace - // forward slashes '/' by backslashes '\'. On Unix, the path is just copied without change. - string BatchManager_Local_SH::fixPath(const string & path) const - { - string fixedPath = path; -#ifdef WIN32 - for (int i=0 ; i 0) exec_sub_cmd << drive << " && "; - exec_sub_cmd << "cd " << fixPath(param[WORKDIR]) << " && " << fixPath(param[EXECUTABLE]); -#else - exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE]; -#endif - - if (param.find(ARGUMENTS) != param.end()) { - Versatile V = param[ARGUMENTS]; - for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { - StringType argt = * static_cast(*it); - string arg = argt; - exec_sub_cmd << " " << arg; - } - } -#ifdef WIN32 - exec_sub_cmd << "\""; -#endif - -#ifdef SH_COMMAND_IS_CMD - param[ARGUMENTS] = "/c"; -#else - param[ARGUMENTS] = "-c"; -#endif - param[ARGUMENTS] += exec_sub_cmd.str(); - - return fixPath(SH); - } - - // Methode qui renvoie la commande d'effacement du fichier - string BatchManager_Local_SH::remove_command(const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const - { - ostringstream remove_cmd; - if (strchr(RM, ' ') == NULL) - remove_cmd << RM; - else - remove_cmd << "\"" << RM << "\""; - - remove_cmd << " \"" << fixPath(destination) << "\""; - return remove_cmd.str(); - } - -} diff --git a/src/Local/Batch_BatchManager_Local_SH.hxx b/src/Local/Batch_BatchManager_Local_SH.hxx deleted file mode 100644 index aee78d0..0000000 --- a/src/Local/Batch_BatchManager_Local_SH.hxx +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#ifndef _BATCHMANAGER_LOCAL_SH_H_ -#define _BATCHMANAGER_LOCAL_SH_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include -#include -#include -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_Local.hxx" -#include "Batch_Job_Local.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_ConnexionFailureException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_NotYetImplementedException.hxx" -#include "Batch_BatchManager_Local.hxx" - -namespace Batch { - - class FactBatchManager; - - class BATCH_EXPORT BatchManager_Local_SH : public BatchManager_Local - { - public: - // Constructeur et destructeur - BatchManager_Local_SH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - virtual ~BatchManager_Local_SH(); - - protected: - std::string fixPath(const std::string & path) const; - - // Methode qui renvoie la commande de copie du fichier source en destination - virtual std::string copy_command( const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - // Methode qui renvoie la commande a executer - virtual std::string exec_command(Parametre & param) const; - - // Methode qui renvoie la commande d'effacement du fichier - virtual std::string remove_command( const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - }; - -} - -#endif diff --git a/src/Local/Batch_BatchManager_Local_SSH.cxx b/src/Local/Batch_BatchManager_Local_SSH.cxx deleted file mode 100644 index 76af411..0000000 --- a/src/Local/Batch_BatchManager_Local_SSH.cxx +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SSH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#ifndef WIN32 -#include -#include -#endif -#include - -#include -#include -#include -#include -#include "Batch_IOMutex.hxx" -#include "Batch_BatchManager_Local_SSH.hxx" - -#include "Batch_config.h" - -#ifndef RM -#error "RM undefined. You must set RM to a valid path to a rm-like command." -#endif - -#ifndef SCP -#error "SCP undefined. You must set SCP to a valid path to a scp-like command." -#endif - -#ifndef SSH -#error "SSH undefined. You must set SSH to a valid path to a ssh-like command." -#endif - -using namespace std; - -namespace Batch { - - - // Constructeur - BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host) - { - } - - // Destructeur - BatchManager_Local_SSH::~BatchManager_Local_SSH() - { - } - - - // Methode abstraite qui renvoie la commande de copie du fichier source en destination - string BatchManager_Local_SSH::copy_command(const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const - { - ostringstream fullsource; - if (host_source.size() != 0) { - if (user_source.size() != 0) { - fullsource << user_source << "@"; - } - fullsource << host_source << ":"; - } - fullsource << source; - - ostringstream fulldestination; - if (host_destination.size() != 0) { - if (user_destination.size() != 0) { - fulldestination << user_destination << "@"; - } - fulldestination << host_destination << ":"; - } - fulldestination << destination; - - ostringstream copy_cmd; - // Option -p is used to keep the same permissions for the destination file (particularly useful to keep scripts - // executable when copying them) - copy_cmd << "\"" << SCP << "\" -p " << fullsource.str() << " " << fulldestination.str(); - return copy_cmd.str(); - } - - // Methode abstraite qui renvoie la commande a executer - string BatchManager_Local_SSH::exec_command(Parametre & param) const - { - ostringstream exec_sub_cmd; -#ifdef WIN32 - exec_sub_cmd << "\""; -#endif - exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE]; - - if (param.find(ARGUMENTS) != param.end()) { - Versatile V = param[ARGUMENTS]; - for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { - StringType argt = * static_cast(*it); - string arg = argt; - exec_sub_cmd << " " << arg; - } - } -#ifdef WIN32 - exec_sub_cmd << "\""; -#endif - - - Versatile new_arguments; - new_arguments.setMaxSize(0); - new_arguments = string(param[EXECUTIONHOST]); - - - if (param.find(USER) != param.end()) { - new_arguments += "-l"; - new_arguments += string(param[USER]); - } - - new_arguments += exec_sub_cmd.str(); - - param[ARGUMENTS] = new_arguments; - - // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh - param[EXECUTABLE] = SSH; - param.erase(NAME); - - return SSH; - } - - // Methode qui renvoie la commande d'effacement du fichier - string BatchManager_Local_SSH::remove_command(const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const - { - string fulldestination = (host_destination.size()) ? host_destination : "localhost"; - if (user_destination.size() != 0) { - fulldestination += " -l " + user_destination; - } - - // We consider here that the remote system is UNIX-like and has a "rm" command. Using the - // RM macro would be pointless here since the remote system is different from the local one. - ostringstream remove_cmd; - remove_cmd << "\"" << SSH << "\" " << fulldestination << " \"rm " << destination << "\""; - return remove_cmd.str(); - } -} diff --git a/src/Local/Batch_BatchManager_Local_SSH.hxx b/src/Local/Batch_BatchManager_Local_SSH.hxx deleted file mode 100644 index c5afaae..0000000 --- a/src/Local/Batch_BatchManager_Local_SSH.hxx +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SSH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:17:22 2003 - * Projet : Salome 2 - * - */ - -#ifndef _BATCHMANAGER_LOCAL_SSH_H_ -#define _BATCHMANAGER_LOCAL_SSH_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include -#include -#include -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_Local.hxx" -#include "Batch_Job_Local.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_ConnexionFailureException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_NotYetImplementedException.hxx" -#include "Batch_BatchManager_Local.hxx" - -namespace Batch { - - class FactBatchManager; - - class BATCH_EXPORT BatchManager_Local_SSH : public BatchManager_Local - { - public: - // Constructeur et destructeur - BatchManager_Local_SSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - virtual ~BatchManager_Local_SSH(); - - protected: - // Methode qui renvoie la commande de copie du fichier source en destination - virtual std::string copy_command( const std::string & user_source, - const std::string & host_source, - const std::string & source, - const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - // Methode qui renvoie la commande a executer - virtual std::string exec_command(Parametre & param) const; - - // Methode qui renvoie la commande d'effacement du fichier - virtual std::string remove_command( const std::string & user_destination, - const std::string & host_destination, - const std::string & destination) const; - - }; - -} - -#endif diff --git a/src/Local/Batch_FactBatchManager_Local.cxx b/src/Local/Batch_FactBatchManager_Local.cxx index 46fb130..b6a28a5 100644 --- a/src/Local/Batch_FactBatchManager_Local.cxx +++ b/src/Local/Batch_FactBatchManager_Local.cxx @@ -26,19 +26,36 @@ * Date : Septembre 2004 * Projet : SALOME 2 * + * Refactored by Renaud Barate (EDF R&D) in September 2009 to use + * CommunicationProtocol classes and merge Local_SH, Local_RSH and Local_SSH batch + * managers. + * */ -#include +#include + #include "Batch_BatchManager_Local.hxx" #include "Batch_FactBatchManager_Local.hxx" -//#include "utilities.h" namespace Batch { -// static FactBatchManager_Local sFBM_Local; +#ifdef HAS_SH + static FactBatchManager_Local sFBM_Local_SH("SH", SH); +#endif + +#ifdef HAS_RSH + static FactBatchManager_Local sFBM_Local_RSH("RSH", RSH); +#endif + +#ifdef HAS_SSH + static FactBatchManager_Local sFBM_Local_SSH("SSH", SSH); +#endif // Constructeur - FactBatchManager_Local::FactBatchManager_Local() : FactBatchManager("Local") + FactBatchManager_Local::FactBatchManager_Local(const char * name, + CommunicationProtocolType protocolType) + : FactBatchManager(name), + _protocolType(protocolType) { // Nothing to do } @@ -50,11 +67,10 @@ namespace Batch { } // Functor -// BatchManager * FactBatchManager_Local::operator() (const char * hostname) const -// { -// // MESSAGE("Building new BatchManager_Local on host '" << hostname << "'"); -// return new BatchManager_Local(this, hostname); -// } - + BatchManager * FactBatchManager_Local::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_Local on host '" << hostname << "'"); + return new BatchManager_Local(this, hostname, _protocolType); + } } diff --git a/src/Local/Batch_FactBatchManager_Local.hxx b/src/Local/Batch_FactBatchManager_Local.hxx index 4b2f0d4..5b39d05 100644 --- a/src/Local/Batch_FactBatchManager_Local.hxx +++ b/src/Local/Batch_FactBatchManager_Local.hxx @@ -26,28 +26,33 @@ * Date : Septembre 2004 * Projet : SALOME 2 * + * Refactored by Renaud Barate (EDF R&D) in September 2009 to use + * CommunicationProtocol classes and merge Local_SH, Local_RSH and Local_SSH batch + * managers. + * */ #ifndef _FACTBATCHMANAGER_LOCAL_H_ #define _FACTBATCHMANAGER_LOCAL_H_ -#include "Batch_FactBatchManager.hxx" +#include +#include namespace Batch { - class BatchManager_Local; - class FactBatchManager_Local : public FactBatchManager { public: // Constructeur et destructeur - FactBatchManager_Local(); + FactBatchManager_Local(const char * name, CommunicationProtocolType protocolType); virtual ~FactBatchManager_Local(); - virtual BatchManager * operator() (const char * hostname) const = 0; + virtual BatchManager * operator() (const char * hostname) const; protected: + CommunicationProtocolType _protocolType; + private: }; diff --git a/src/Local/Batch_FactBatchManager_Local_RSH.cxx b/src/Local/Batch_FactBatchManager_Local_RSH.cxx deleted file mode 100644 index cd15bad..0000000 --- a/src/Local/Batch_FactBatchManager_Local_RSH.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_RSH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include -#include "Batch_BatchManager_Local_RSH.hxx" -#include "Batch_FactBatchManager_Local_RSH.hxx" -//#include "utilities.h" - -namespace Batch { - - static FactBatchManager_Local_RSH sFBM_Local_RSH; - - // Constructeur - FactBatchManager_Local_RSH::FactBatchManager_Local_RSH() : FactBatchManager("RSH") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_Local_RSH::~FactBatchManager_Local_RSH() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_Local_RSH::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_Local_RSH on host '" << hostname << "'"); - return new BatchManager_Local_RSH(this, hostname); - } - - -} diff --git a/src/Local/Batch_FactBatchManager_Local_RSH.hxx b/src/Local/Batch_FactBatchManager_Local_RSH.hxx deleted file mode 100644 index 8b11c5d..0000000 --- a/src/Local/Batch_FactBatchManager_Local_RSH.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_RSH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_LOCAL_RSH_H_ -#define _FACTBATCHMANAGER_LOCAL_RSH_H_ - -#include "Batch_FactBatchManager.hxx" - -namespace Batch { - - class BatchManager_Local_RSH; - - class FactBatchManager_Local_RSH : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_Local_RSH(); - virtual ~FactBatchManager_Local_RSH(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/Local/Batch_FactBatchManager_Local_SH.cxx b/src/Local/Batch_FactBatchManager_Local_SH.cxx deleted file mode 100644 index a317e3c..0000000 --- a/src/Local/Batch_FactBatchManager_Local_SH.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include -#include "Batch_BatchManager_Local_SH.hxx" -#include "Batch_FactBatchManager_Local_SH.hxx" -//#include "utilities.h" - -namespace Batch { - - static FactBatchManager_Local_SH sFBM_Local_SH; - - // Constructeur - FactBatchManager_Local_SH::FactBatchManager_Local_SH() : FactBatchManager("SH") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_Local_SH::~FactBatchManager_Local_SH() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_Local_SH::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_Local_SH on host '" << hostname << "'"); - return new BatchManager_Local_SH(this, hostname); - } - - -} diff --git a/src/Local/Batch_FactBatchManager_Local_SH.hxx b/src/Local/Batch_FactBatchManager_Local_SH.hxx deleted file mode 100644 index 499eafe..0000000 --- a/src/Local/Batch_FactBatchManager_Local_SH.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_LOCAL_SH_H_ -#define _FACTBATCHMANAGER_LOCAL_SH_H_ - -#include "Batch_FactBatchManager.hxx" - -namespace Batch { - - class BatchManager_Local_SH; - - class FactBatchManager_Local_SH : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_Local_SH(); - virtual ~FactBatchManager_Local_SH(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/Local/Batch_FactBatchManager_Local_SSH.cxx b/src/Local/Batch_FactBatchManager_Local_SSH.cxx deleted file mode 100644 index d962374..0000000 --- a/src/Local/Batch_FactBatchManager_Local_SSH.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SSH.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include -#include "Batch_BatchManager_Local_SSH.hxx" -#include "Batch_FactBatchManager_Local_SSH.hxx" -//#include "utilities.h" - -namespace Batch { - - static FactBatchManager_Local_SSH sFBM_Local_SSH; - - // Constructeur - FactBatchManager_Local_SSH::FactBatchManager_Local_SSH() : FactBatchManager("SSH") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_Local_SSH::~FactBatchManager_Local_SSH() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_Local_SSH::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_Local_SSH on host '" << hostname << "'"); - return new BatchManager_Local_SSH(this, hostname); - } - - -} diff --git a/src/Local/Batch_FactBatchManager_Local_SSH.hxx b/src/Local/Batch_FactBatchManager_Local_SSH.hxx deleted file mode 100644 index 7f64f0e..0000000 --- a/src/Local/Batch_FactBatchManager_Local_SSH.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 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_Local_SSH.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_LOCAL_SSH_H_ -#define _FACTBATCHMANAGER_LOCAL_SSH_H_ - -#include "Batch_FactBatchManager.hxx" - -namespace Batch { - - class BatchManager_Local_SSH; - - class FactBatchManager_Local_SSH : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_Local_SSH(); - virtual ~FactBatchManager_Local_SSH(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/Local/CMakeLists.txt b/src/Local/CMakeLists.txt index c301ede..3c5a6f4 100644 --- a/src/Local/CMakeLists.txt +++ b/src/Local/CMakeLists.txt @@ -20,13 +20,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST Local/Batch_BatchManager_Local_RSH - Local/Batch_BatchManager_Local_SH - Local/Batch_BatchManager_Local_SSH - Local/Batch_BatchManager_Local - Local/Batch_FactBatchManager_Local_RSH - Local/Batch_FactBatchManager_Local_SH - Local/Batch_FactBatchManager_Local_SSH +SET(CLASS_LIST Local/Batch_BatchManager_Local Local/Batch_FactBatchManager_Local Local/Batch_IOMutex Local/Batch_Job_Local diff --git a/src/Local/Test/CMakeLists.txt b/src/Local/Test/CMakeLists.txt index dc9e770..7770a6a 100644 --- a/src/Local/Test/CMakeLists.txt +++ b/src/Local/Test/CMakeLists.txt @@ -20,16 +20,6 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# Build the executable to use for the local test program -add_executable(Exec_Test Exec_Test.cxx) -GET_TARGET_PROPERTY(EXEC_TEST_FULL_PATH_TEMP Exec_Test LOCATION) -GET_FILENAME_COMPONENT(EXEC_TEST_NAME_TEMP ${EXEC_TEST_FULL_PATH_TEMP} NAME) -SET(EXEC_TEST_FULL_PATH ${EXEC_TEST_FULL_PATH_TEMP} CACHE INTERNAL "") -SET(EXEC_TEST_NAME ${EXEC_TEST_NAME_TEMP} CACHE INTERNAL "") - -# Configure the config file for all the test scripts -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Local_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_Local_config.h) - # Just copy the test scripts to the binary dir CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY) @@ -40,17 +30,33 @@ include_directories(${CMAKE_SOURCE_DIR}/src/Core) include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -# Build the test programs -add_executable(Test_Local_SH Test_Local_SH.cxx) -target_link_libraries(Test_Local_SH Batch SimpleParser) - -add_executable(Test_Local_RSH Test_Local_RSH.cxx) -target_link_libraries(Test_Local_RSH Batch SimpleParser) - -add_executable(Test_Local_SSH Test_Local_SSH.cxx) -target_link_libraries(Test_Local_SSH Batch SimpleParser) - -# Add the tests themselves -ADD_TEST(Local_SH Test_Local_SH) -ADD_TEST(Local_RSH Test_Local_RSH) -ADD_TEST(Local_SSH Test_Local_SSH) +# Build the test programs and add the tests +IF (HAS_SH) + + # Build the executable to use for the local test program + add_executable(Exec_Test Exec_Test.cxx) + GET_TARGET_PROPERTY(EXEC_TEST_FULL_PATH_TEMP Exec_Test LOCATION) + GET_FILENAME_COMPONENT(EXEC_TEST_NAME_TEMP ${EXEC_TEST_FULL_PATH_TEMP} NAME) + SET(EXEC_TEST_FULL_PATH ${EXEC_TEST_FULL_PATH_TEMP} CACHE INTERNAL "") + SET(EXEC_TEST_NAME ${EXEC_TEST_NAME_TEMP} CACHE INTERNAL "") + + # Configure the config file for the test + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Local_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_Local_config.h) + + add_executable(Test_Local_SH Test_Local_SH.cxx) + target_link_libraries(Test_Local_SH Batch SimpleParser) + ADD_TEST(Local_SH Test_Local_SH) + +ENDIF (HAS_SH) + +IF (HAS_SSH) + add_executable(Test_Local_SSH Test_Local_SSH.cxx) + target_link_libraries(Test_Local_SSH Batch SimpleParser) + ADD_TEST(Local_SSH Test_Local_SSH) +ENDIF (HAS_SSH) + +IF (HAS_RSH) + add_executable(Test_Local_RSH Test_Local_RSH.cxx) + target_link_libraries(Test_Local_RSH Batch SimpleParser) + ADD_TEST(Local_RSH Test_Local_RSH) +ENDIF (HAS_RSH) diff --git a/src/Local/Test/Test_Local_RSH.cxx b/src/Local/Test/Test_Local_RSH.cxx index 51f9274..8e5dc12 100644 --- a/src/Local/Test/Test_Local_RSH.cxx +++ b/src/Local/Test/Test_Local_RSH.cxx @@ -90,6 +90,10 @@ int main(int argc, char** argv) // Create a BatchManager of type Local_RSH on localhost FactBatchManager * fbm = c("RSH"); + if (fbm == NULL) { + cerr << "Can't get RSH batch manager factory" << endl; + return 1; + } BatchManager * bm = (*fbm)("localhost"); // Submit the job to the BatchManager diff --git a/src/Local/Test/Test_Local_SH.cxx b/src/Local/Test/Test_Local_SH.cxx index 5eab791..e8e20b8 100644 --- a/src/Local/Test/Test_Local_SH.cxx +++ b/src/Local/Test/Test_Local_SH.cxx @@ -90,6 +90,10 @@ int main(int argc, char** argv) // Create a BatchManager of type Local_SH on localhost FactBatchManager * fbm = c("SH"); + if (fbm == NULL) { + cerr << "Can't get SH batch manager factory" << endl; + return 1; + } BatchManager * bm = (*fbm)("localhost"); // Submit the job to the BatchManager diff --git a/src/Local/Test/Test_Local_SSH.cxx b/src/Local/Test/Test_Local_SSH.cxx index 3876bb0..70bacb1 100644 --- a/src/Local/Test/Test_Local_SSH.cxx +++ b/src/Local/Test/Test_Local_SSH.cxx @@ -92,6 +92,10 @@ int main(int argc, char** argv) // Create a BatchManager of type Local_SSH on localhost FactBatchManager * fbm = c("SSH"); + if (fbm == NULL) { + cerr << "Can't get SSH batch manager factory" << endl; + return 1; + } BatchManager * bm = (*fbm)("localhost"); // Submit the job to the BatchManager diff --git a/src/PBS/Batch_BatchManager_ePBS.cxx b/src/PBS/Batch_BatchManager_ePBS.cxx index 096aad0..f2d5b79 100644 --- a/src/PBS/Batch_BatchManager_ePBS.cxx +++ b/src/PBS/Batch_BatchManager_ePBS.cxx @@ -34,7 +34,7 @@ #include #include -#include "Batch_config.h" +#include #ifdef MSVC #include @@ -43,14 +43,15 @@ #endif #include "Batch_BatchManager_ePBS.hxx" +#include "Batch_JobInfo_ePBS.hxx" using namespace std; namespace Batch { BatchManager_ePBS::BatchManager_ePBS(const FactBatchManager * parent, const char * host, - const char * protocol, const char * mpiImpl) - : BatchManager_eClient(parent, host, protocol, mpiImpl) + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl) { // Nothing to do } @@ -82,34 +83,9 @@ namespace Batch { string logFile = generateTemporaryFileName("PBS-submitlog"); // define command to submit batch - string command = "\""; - - // Test protocol - if( _protocol == "rsh" ) - command += RSH; - else if( _protocol == "ssh" ) - command += SSH; - else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - - if(_username != ""){ - command += _username + "@"; - } - - command += _hostname + " "; -#ifndef WIN32 - command += "\""; -#endif - command += "cd " ; - command += dirForTmpFiles ; - command += "; qsub " ; - command += fileNameToExecute ; - command += "_Batch.sh"; -#ifndef WIN32 - command += "\""; -#endif + string subCommand = string("cd ") + dirForTmpFiles + "; qsub " + + fileNameToExecute + "_Batch.sh"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); command += " > "; command += logFile; cerr << command.c_str() << endl; @@ -118,12 +94,13 @@ namespace Batch { 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); + ifstream idfile(logFile.c_str()); + string sline; + idfile >> sline; + idfile.close(); + if (sline.size() == 0) + throw EmulationException("Error in the submission of the job on the remote host"); - string sline(line); size_t pos = sline.find("."); string strjob; if(pos == string::npos) @@ -143,23 +120,12 @@ namespace Batch { 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 += "\""; + // define command to delete batch + string subCommand = string("qdel ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); cerr << command.c_str() << endl; status = system(command.c_str()); - if(status) + if (status) throw EmulationException("Error of connection on remote host"); cerr << "jobId = " << ref << "killed" << endl; @@ -207,31 +173,8 @@ namespace Batch { string logFile = generateTemporaryFileName(string("PBS-querylog-id") + jobid.getReference()); // define command to query batch - string command = "\""; - - // Test protocol - if( _protocol == "rsh" ) - command += RSH; - else if( _protocol == "ssh" ) - command += SSH; - else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - - if (_username != ""){ - command += _username + "@"; - } - - command += _hostname + " "; -#ifndef WIN32 - command += "\""; -#endif - command += "qstat -f " ; - command += iss.str(); -#ifndef WIN32 - command += "\""; -#endif + string subCommand = string("qstat -f ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); command += " > "; command += logFile; cerr << command.c_str() << endl; @@ -251,7 +194,6 @@ namespace Batch { void BatchManager_ePBS::buildBatchScript(const Job & job) { - int status; Parametre params = job.getParametre(); Environnement env = job.getEnvironnement(); const long nbproc = params[NBPROC]; @@ -330,33 +272,10 @@ namespace Batch { TmpFileName.c_str(), 0x1ED); cerr << TmpFileName.c_str() << endl; - string command = "\""; - - // Test protocol - if( _protocol == "rsh" ) { - command += RCP; - } else if( _protocol == "ssh" ) { - command += SCP; - } else - throw EmulationException("Unknown protocol : only rsh and ssh are known !"); - - command += "\" "; - - 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) + int status = _protocol.copyFile(TmpFileName, "", "", + dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) throw EmulationException("Error of connection on remote host"); remove(TmpFileName.c_str()); diff --git a/src/PBS/Batch_BatchManager_ePBS.hxx b/src/PBS/Batch_BatchManager_ePBS.hxx index 094b796..c9dfc6f 100644 --- a/src/PBS/Batch_BatchManager_ePBS.hxx +++ b/src/PBS/Batch_BatchManager_ePBS.hxx @@ -29,34 +29,23 @@ * */ -#ifndef _BATCHMANAGER_eLSF_H_ -#define _BATCHMANAGER_eLSF_H_ +#ifndef _BATCHMANAGER_EPBS_H_ +#define _BATCHMANAGER_EPBS_H_ -#include "Batch_Defines.hxx" - -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_ePBS.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" +#include +#include +#include +#include +#include namespace Batch { - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - class BATCH_EXPORT BatchManager_ePBS : public BatchManager_eClient { public: // Constructeur et destructeur BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost", - const char * protocol="ssh", const char * mpiImpl="nompi"); // connexion a la machine host + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host virtual ~BatchManager_ePBS(); // Recupere le nom du serveur par defaut diff --git a/src/PBS/Batch_FactBatchManager_ePBS.cxx b/src/PBS/Batch_FactBatchManager_ePBS.cxx index f7516ec..2984a3c 100644 --- a/src/PBS/Batch_FactBatchManager_ePBS.cxx +++ b/src/PBS/Batch_FactBatchManager_ePBS.cxx @@ -56,10 +56,12 @@ namespace Batch { return new BatchManager_ePBS(this, hostname); } - BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const + BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const { // MESSAGE("Building new BatchManager_PBS on host '" << hostname << "'"); - return new BatchManager_ePBS(this, hostname, protocol, mpiImpl); + return new BatchManager_ePBS(this, hostname, protocolType, mpiImpl); } diff --git a/src/PBS/Batch_FactBatchManager_ePBS.hxx b/src/PBS/Batch_FactBatchManager_ePBS.hxx index 027e9ed..930552d 100644 --- a/src/PBS/Batch_FactBatchManager_ePBS.hxx +++ b/src/PBS/Batch_FactBatchManager_ePBS.hxx @@ -50,7 +50,9 @@ namespace Batch { virtual ~FactBatchManager_ePBS(); virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const; + virtual BatchManager_eClient * operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; protected: diff --git a/src/PBS/Test/CMakeLists.txt b/src/PBS/Test/CMakeLists.txt index 0ac39cd..f584265 100644 --- a/src/PBS/Test/CMakeLists.txt +++ b/src/PBS/Test/CMakeLists.txt @@ -32,9 +32,17 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) include_directories(${CMAKE_CURRENT_BINARY_DIR}) # Build the test programs and add the tests -add_executable(Test_ePBS Test_ePBS.cxx) -target_link_libraries(Test_ePBS Batch SimpleParser) -ADD_TEST(ePBS Test_ePBS) +IF (HAS_SSH) + add_executable(Test_ePBS_SSH Test_ePBS_SSH.cxx) + target_link_libraries(Test_ePBS_SSH Batch SimpleParser) + ADD_TEST(ePBS_SSH Test_ePBS_SSH) +ENDIF (HAS_SSH) + +IF (HAS_RSH) + add_executable(Test_ePBS_RSH Test_ePBS_RSH.cxx) + target_link_libraries(Test_ePBS_RSH Batch SimpleParser) + ADD_TEST(ePBS_RSH Test_ePBS_RSH) +ENDIF (HAS_RSH) IF (BUILD_PBS_INTERFACE AND PBS_FOUND) add_executable(Test_PBS Test_PBS.cxx) diff --git a/src/PBS/Test/Test_ePBS_RSH.cxx b/src/PBS/Test/Test_ePBS_RSH.cxx new file mode 100644 index 0000000..daafecb --- /dev/null +++ b/src/PBS/Test/Test_ePBS_RSH.cxx @@ -0,0 +1,147 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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 +// +/* + * Test_ePBS.cxx : + * + * Author : Renaud BARATE - EDF R&D + * Date : April 2009 + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#ifdef WIN32 +#include +#define sleep(seconds) Sleep((seconds)*1000) +#define usleep(useconds) Sleep((useconds)/1000) +#endif + +using namespace std; +using namespace Batch; + +int main(int argc, char** argv) +{ + cout << "*******************************************************************************************" << endl; + cout << "This program tests the batch submission based on PBS emulation with RSH. Passwordless RSH" << endl; + cout << "authentication must be used for this test to pass (this can be configured with the .rhosts" << endl; + cout << "file). You also need to create a directory \"tmp/Batch\" in your home directory on the PBS" << endl; + cout << "server before running this test." << endl; + cout << "*******************************************************************************************" << endl; + + // eventually remove any previous result + remove("result.txt"); + + try { + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR"); + const string & host = parser.getValue("TEST_EPBS_HOST"); + const string & user = parser.getValue("TEST_EPBS_USER"); + const string & queue = parser.getValue("TEST_EPBS_QUEUE"); + int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT"); + + // Define the job... + Job job; + // ... and its parameters ... + Parametre p; + p["EXECUTABLE"] = "./test-script.sh"; + p["NAME"] = "Test_ePBS_RSH"; + p["WORKDIR"] = homedir + "/tmp/Batch"; + p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh"); + p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh"); + p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt"); + p["TMPDIR"] = "tmp/Batch/"; + p["USER"] = user; + p["NBPROC"] = 1; + p["MAXWALLTIME"] = 1; + p["MAXRAMSIZE"] = 4; + p["HOMEDIR"] = homedir; + p["QUEUE"] = queue; + job.setParametre(p); + // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication) + Environnement e; + const char * sshAuthSock = getenv("SSH_AUTH_SOCK"); + if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock; + job.setEnvironnement(e); + cout << job << endl; + + // Get the catalog + BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); + + // Create a BatchManager of type ePBS on localhost + FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS")); + BatchManager_eClient * bm = (*fbm)(host.c_str(), RSH, "lam"); + + // Submit the job to the BatchManager + JobId jobid = bm->submitJob(job); + cout << jobid.__repr__() << endl; + + // Wait for the end of the job + string state = "Undefined"; + for (int i=0 ; iimportOutputFiles(job, "."); + } else { + cerr << "Timeout while executing job" << endl; + return 1; + } + + } catch (GenericException e) { + cerr << "Error: " << e << endl; + return 1; + } catch (ParserException e) { + cerr << "Parser error: " << e.what() << endl; + return 1; + } + + // test the result file + string exp = "c = 12"; + string res; + ifstream f("result.txt"); + getline(f, res); + f.close(); + + cout << "result found : " << res << ", expected : " << exp << endl; + + if (res == exp) + return 0; + else + return 1; +} diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS_SSH.cxx similarity index 96% rename from src/PBS/Test/Test_ePBS.cxx rename to src/PBS/Test/Test_ePBS_SSH.cxx index d75d96a..42e98c3 100644 --- a/src/PBS/Test/Test_ePBS.cxx +++ b/src/PBS/Test/Test_ePBS_SSH.cxx @@ -51,7 +51,7 @@ using namespace Batch; int main(int argc, char** argv) { cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on PBS emulation. Passwordless SSH" << endl; + cout << "This program tests the batch submission based on PBS emulation with SSH. Passwordless SSH" << endl; cout << "authentication must be used for this test to pass (this can be configured with ssh-agent" << endl; cout << "for instance). You also need to create a directory \"tmp/Batch\" in your home directory on" << endl; cout << "the PBS server before running this test." << endl; @@ -75,7 +75,7 @@ int main(int argc, char** argv) // ... and its parameters ... Parametre p; p["EXECUTABLE"] = "./test-script.sh"; - p["NAME"] = "Test_ePBS"; + p["NAME"] = "Test_ePBS_SSH"; p["WORKDIR"] = homedir + "/tmp/Batch"; p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh"); p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh"); @@ -100,7 +100,7 @@ int main(int argc, char** argv) // Create a BatchManager of type ePBS on localhost FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), "ssh", "lam"); + BatchManager_eClient * bm = (*fbm)(host.c_str(), SSH, "lam"); // Submit the job to the BatchManager JobId jobid = bm->submitJob(job); diff --git a/src/Python/Batch_PyVersatile.cxx b/src/Python/Batch_PyVersatile.cxx index 620cf5e..8eb58c2 100644 --- a/src/Python/Batch_PyVersatile.cxx +++ b/src/Python/Batch_PyVersatile.cxx @@ -56,29 +56,29 @@ namespace Batch { if (PyList_Check(_PyO)) { // c'est une liste _maxsize = PyList_Size(_PyO); - for(int i=0; i<_maxsize; i++) { - PyObject * val = PyList_GetItem(_PyO, i); - if (PyString_Check(val)) { - *this += PyString_AsString(val); - - } else if (PyTuple_Check(val) && - (PyTuple_Size(val) == 2) && - PyString_Check( PyTuple_GetItem(val,0) ) && - PyString_Check( PyTuple_GetItem(val,1) ) ) { - *this += Couple( PyString_AsString( PyTuple_GetItem(val,0) ), - PyString_AsString( PyTuple_GetItem(val,1) ) - ); - - } else { - PyErr_SetString(PyExc_RuntimeWarning, "PyVersatile::PyVersatile(const PyObject * PyO) : invalid PyObject"); - } + for (size_type i=0; i<_maxsize; i++) { + PyObject * val = PyList_GetItem(_PyO, i); + if (PyString_Check(val)) { + *this += PyString_AsString(val); + + } else if (PyTuple_Check(val) && + (PyTuple_Size(val) == 2) && + PyString_Check( PyTuple_GetItem(val,0) ) && + PyString_Check( PyTuple_GetItem(val,1) ) ) { + *this += Couple( PyString_AsString( PyTuple_GetItem(val,0) ), + PyString_AsString( PyTuple_GetItem(val,1) ) + ); + + } else { + PyErr_SetString(PyExc_RuntimeWarning, "PyVersatile::PyVersatile(const PyObject * PyO) : invalid PyObject"); + } } } else if (PyString_Check(_PyO)) { // c'est une string const char * s = PyString_AsString(_PyO); Versatile V = string(s); *this = V; - + } else if (PyInt_Check(_PyO)) { // c'est un int *this = PyInt_AsLong(_PyO); @@ -97,90 +97,90 @@ namespace Batch { if (_maxsize != 1) { // une liste obj = PyList_New(0); for(Versatile::const_iterator it=begin(); it!=end(); it++) { -// char ch[2] = {0, 0}; - string st; - Couple cp; -// PyObject * tuple; - switch (_discriminator) { - // case BOOL: - // PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); - // break; - - // case CHAR: - // *ch = * static_cast(*it); - // PyList_Append(obj, PyString_FromString(ch)); - // break; - - // case INT: - // PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); - // break; - - case LONG: - PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); - break; - - case STRING: - st = * static_cast(*it); - PyList_Append(obj, PyString_FromString(st.c_str())); - break; - - case COUPLE: - cp = * static_cast(*it); -// tuple = PyTuple_New(2); -// PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) ); -// PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) ); -// PyList_Append(obj, tuple); - PyList_Append(obj, Py_BuildValue("(ss)", cp.getLocal().c_str(), cp.getRemote().c_str() )); - break; - - case UNDEFINED: - PyList_Append(obj, Py_None); - break; - } + // char ch[2] = {0, 0}; + string st; + Couple cp; + // PyObject * tuple; + switch (_discriminator) { + // case BOOL: + // PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); + // break; + + // case CHAR: + // *ch = * static_cast(*it); + // PyList_Append(obj, PyString_FromString(ch)); + // break; + + // case INT: + // PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); + // break; + + case LONG: + PyList_Append(obj, PyInt_FromLong(* static_cast(*it))); + break; + + case STRING: + st = * static_cast(*it); + PyList_Append(obj, PyString_FromString(st.c_str())); + break; + + case COUPLE: + cp = * static_cast(*it); + // tuple = PyTuple_New(2); + // PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) ); + // PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) ); + // PyList_Append(obj, tuple); + PyList_Append(obj, Py_BuildValue("(ss)", cp.getLocal().c_str(), cp.getRemote().c_str() )); + break; + + case UNDEFINED: + PyList_Append(obj, Py_None); + break; + } } } else { // un scalaire -// char ch[2] = {0, 0}; + // char ch[2] = {0, 0}; string st; Couple cp; -// PyObject * tuple; + // PyObject * tuple; switch (_discriminator) { - // case BOOL: - // obj = PyInt_FromLong(* static_cast(front())); - // break; + // case BOOL: + // obj = PyInt_FromLong(* static_cast(front())); + // break; - // case CHAR: - // *ch = * static_cast(front()); - // obj = PyString_FromString(ch); - // break; + // case CHAR: + // *ch = * static_cast(front()); + // obj = PyString_FromString(ch); + // break; - // case INT: - // obj = PyInt_FromLong(* static_cast(front())); - // break; + // case INT: + // obj = PyInt_FromLong(* static_cast(front())); + // break; case LONG: - obj = PyInt_FromLong(* static_cast(front())); - break; + obj = PyInt_FromLong(* static_cast(front())); + break; case STRING: - st = * static_cast(front()); - obj = PyString_FromString(st.c_str()); - break; + st = * static_cast(front()); + obj = PyString_FromString(st.c_str()); + break; case COUPLE: - cp = * static_cast(front()); -// tuple = PyTuple_New(2); -// PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) ); -// PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) ); -// obj = PyList_New(0); -// PyList_Append(obj, tuple); - obj = Py_BuildValue("[(ss)]", cp.getLocal().c_str(), cp.getRemote().c_str() ); - break; + cp = * static_cast(front()); + // tuple = PyTuple_New(2); + // PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) ); + // PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) ); + // obj = PyList_New(0); + // PyList_Append(obj, tuple); + obj = Py_BuildValue("[(ss)]", cp.getLocal().c_str(), cp.getRemote().c_str() ); + break; case UNDEFINED: - obj = Py_None; - break; + obj = Py_None; + break; } } diff --git a/src/Python/Test/CMakeLists.txt b/src/Python/Test/CMakeLists.txt index af36dd4..4252d36 100644 --- a/src/Python/Test/CMakeLists.txt +++ b/src/Python/Test/CMakeLists.txt @@ -20,16 +20,16 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# Configure the config file for all the test scripts -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py) - -# Just copy the test scripts to the binary dir -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Python_Local_SH.py - ${CMAKE_CURRENT_BINARY_DIR}/Test_Python_Local_SH.py COPYONLY) - -# Add the test -IF (BUILD_LOCAL_SUBMISSION) +IF (BUILD_LOCAL_SUBMISSION AND HAS_SH) + # Configure the config file for the test script + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py) + + # Just copy the test scripts to the binary dir + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Python_Local_SH.py + ${CMAKE_CURRENT_BINARY_DIR}/Test_Python_Local_SH.py COPYONLY) + + # Add the test ADD_TEST(Python_Local_SH ${PYTHON_EXECUTABLE} Test_Python_Local_SH.py) -ENDIF (BUILD_LOCAL_SUBMISSION) +ENDIF (BUILD_LOCAL_SUBMISSION AND HAS_SH) diff --git a/src/SGE/Batch_BatchManager_eSGE.cxx b/src/SGE/Batch_BatchManager_eSGE.cxx index 1e1634d..9a39df2 100644 --- a/src/SGE/Batch_BatchManager_eSGE.cxx +++ b/src/SGE/Batch_BatchManager_eSGE.cxx @@ -33,20 +33,22 @@ #include #include #include -#include "Batch_BatchManager_eSGE.hxx" -#include #ifdef WIN32 -# include -# include +#include #else #include #endif +#include "Batch_BatchManager_eSGE.hxx" +#include "Batch_JobInfo_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) + BatchManager_eSGE::BatchManager_eSGE(const FactBatchManager * parent, const char * host, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl) { // Nothing to do } @@ -74,34 +76,14 @@ namespace Batch { // 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 name of log file (local) + string logFile = generateTemporaryFileName("SGE-submitlog"); // 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\" > "; + string subCommand = string("cd ") + dirForTmpFiles + "; qsub " + + fileNameToExecute + "_Batch.sh"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; command += logFile; cerr << command.c_str() << endl; status = system(command.c_str()); @@ -130,20 +112,9 @@ namespace Batch { 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 += "\""; + // define command to delete batch + string subCommand = string("qdel ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); cerr << command.c_str() << endl; status = system(command.c_str()); if(status) @@ -190,36 +161,17 @@ namespace Batch { 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"; + // define name of log file (local) + string logFile = generateTemporaryFileName(string("SGE-querylog-id") + jobid.getReference()); - 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 += "\" > "; + // define command to query batch + string subCommand = string("qstat | grep ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; command += logFile; cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status && status != 256) + int status = system(command.c_str()); + if (status && status != 256) throw EmulationException("Error of connection on remote host"); JobInfo_eSGE ji = JobInfo_eSGE(id,logFile); @@ -236,7 +188,6 @@ namespace Batch { { #ifndef WIN32 //TODO porting on Win32 platform - int status; Parametre params = job.getParametre(); Environnement env = job.getEnvironnement(); const long nbproc = params[NBPROC]; @@ -299,28 +250,10 @@ namespace Batch { 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) + int status = _protocol.copyFile(TmpFileName, "", "", + dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) throw EmulationException("Error of connection on remote host"); remove(TmpFileName.c_str()); diff --git a/src/SGE/Batch_BatchManager_eSGE.hxx b/src/SGE/Batch_BatchManager_eSGE.hxx index 4f7ca96..2273a18 100644 --- a/src/SGE/Batch_BatchManager_eSGE.hxx +++ b/src/SGE/Batch_BatchManager_eSGE.hxx @@ -29,32 +29,23 @@ * */ -#ifndef _BATCHMANAGER_eLSF_H_ -#define _BATCHMANAGER_eLSF_H_ +#ifndef _BATCHMANAGER_ESGE_H_ +#define _BATCHMANAGER_ESGE_H_ -#include "Batch_Defines.hxx" -#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" +#include +#include +#include +#include +#include namespace Batch { - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - class BATCH_EXPORT 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 + BatchManager_eSGE(const FactBatchManager * parent, const char * host="localhost", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host virtual ~BatchManager_eSGE(); // Recupere le nom du serveur par defaut diff --git a/src/SGE/Batch_FactBatchManager_eSGE.cxx b/src/SGE/Batch_FactBatchManager_eSGE.cxx index c7a6c9f..7bc44c0 100644 --- a/src/SGE/Batch_FactBatchManager_eSGE.cxx +++ b/src/SGE/Batch_FactBatchManager_eSGE.cxx @@ -28,10 +28,8 @@ * */ -#include #include "Batch_BatchManager_eSGE.hxx" #include "Batch_FactBatchManager_eSGE.hxx" -//#include "utilities.h" namespace Batch { @@ -56,10 +54,12 @@ namespace Batch { return new BatchManager_eSGE(this, hostname); } - BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const + BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const { // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'"); - return new BatchManager_eSGE(this, hostname, protocol, mpiImpl); + return new BatchManager_eSGE(this, hostname, protocolType, mpiImpl); } diff --git a/src/SGE/Batch_FactBatchManager_eSGE.hxx b/src/SGE/Batch_FactBatchManager_eSGE.hxx index 44f7f6c..6dae360 100644 --- a/src/SGE/Batch_FactBatchManager_eSGE.hxx +++ b/src/SGE/Batch_FactBatchManager_eSGE.hxx @@ -38,8 +38,6 @@ namespace Batch { - class BatchManager_eSGE; - class BATCH_EXPORT FactBatchManager_eSGE : public FactBatchManager_eClient { public: @@ -48,7 +46,9 @@ namespace Batch { virtual ~FactBatchManager_eSGE(); virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const; + virtual BatchManager_eClient * operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; protected: -- 2.39.2