From: Margarita KARPUNINA Date: Mon, 21 Nov 2022 13:09:20 +0000 (+0300) Subject: [bos #32518][EDF] (2022-T3) X-Git-Tag: V2_5_0~3 X-Git-Url: http://git.salome-platform.org/gitweb/?p=tools%2Flibbatch.git;a=commitdiff_plain;h=e1793d845a991264965eb3c0c84407fd9fa624ec [bos #32518][EDF] (2022-T3) Parametrize commands in LIBBATCH Debug, Windows porting/testing, info about overloaded or not commands --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 63750e5..62ed7b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ SET(INSTALL_INCLUDE_DIR include) SET(LIBBATCH_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission") SET(LIBBATCH_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping") -SET(LIBBATCH_BUILD_TESTS TRUE CACHE BOOL "Enable testing") +SET(LIBBATCH_BUILD_TESTS FALSE CACHE BOOL "Enable testing") IF(LIBBATCH_BUILD_TESTS) ENABLE_TESTING() diff --git a/CMakeModules/libbatchMacros.cmake b/CMakeModules/libbatchMacros.cmake index 999b8bf..a8daa4f 100644 --- a/CMakeModules/libbatchMacros.cmake +++ b/CMakeModules/libbatchMacros.cmake @@ -67,11 +67,6 @@ MACRO(LIBBATCH_FIND_ALL_LOCAL_COMMANDS) FIND_LOCAL_COMMAND(LIBBATCH_SCP_COMMAND scp pscp) FIND_LOCAL_COMMAND(LIBBATCH_RSYNC_COMMAND rsync pscp) - EVAL (HAS_SH LIBBATCH_SH_COMMAND AND LIBBATCH_CP_COMMAND AND LIBBATCH_RM_COMMAND AND LIBBATCH_MKDIR_COMMAND) - EVAL (HAS_RSH LIBBATCH_RSH_COMMAND AND LIBBATCH_RCP_COMMAND) - EVAL (HAS_SSH LIBBATCH_SSH_COMMAND AND LIBBATCH_SCP_COMMAND) - EVAL (HAS_RSYNC LIBBATCH_SSH_COMMAND AND LIBBATCH_RSYNC_COMMAND) - # Mark shell commands as advanced options # and assign the names without the LIBBATCH_ in front: SET (_cmds "RM;SH;CP;MKDIR;RSH;RCP;SSH;SCP;RSYNC") diff --git a/libbatch_config.h.in b/libbatch_config.h.in index 57eee6b..37f8a3d 100644 --- a/libbatch_config.h.in +++ b/libbatch_config.h.in @@ -23,9 +23,6 @@ #ifndef BATCH_CONFIG_H #define BATCH_CONFIG_H -/* SH tools (sh, cp, rm, mkdir) found on the system */ -#cmakedefine HAS_SH - /* A path to a sh-like command */ #cmakedefine SH_COMMAND "@SH_COMMAND@" @@ -38,21 +35,12 @@ /* A path to a mkdir-like command */ #cmakedefine MKDIR_COMMAND "@MKDIR_COMMAND@" -/* RSH tools (rsh, rcp) found on the system */ -#cmakedefine HAS_RSH - /* A path to a rsh-like command */ #cmakedefine RSH_COMMAND "@RSH_COMMAND@" /* A path to a rcp-like command */ #cmakedefine RCP_COMMAND "@RCP_COMMAND@" -/* SSH tools (ssh, scp) found on the system */ -#cmakedefine HAS_SSH - -/* SSH tools and rsync found */ -#cmakedefine HAS_RSYNC - /* A path to a ssh-like command */ #cmakedefine SSH_COMMAND "@SSH_COMMAND@" diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 54ea889..fa15d1e 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -56,22 +56,10 @@ APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST} APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST}) APPEND_CLASSES_TO_HDR_FILES(Core/Defines) -IF (HAS_SH) - APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSH) -ENDIF (HAS_SH) - -IF (HAS_RSH) - APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolRSH) -ENDIF (HAS_RSH) - -IF (HAS_SSH) - APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSSH) -ENDIF (HAS_SSH) - -IF (HAS_RSYNC) - APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolRsync) -ENDIF (HAS_RSYNC) - +APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSH) +APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolRSH) +APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSSH) +APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolRsync) IF (LIBBATCH_BUILD_TESTS) ADD_SUBDIRECTORY(Test) diff --git a/src/Core/CommandsOverloader.cxx b/src/Core/CommandsOverloader.cxx index 7ee23c3..06f7057 100644 --- a/src/Core/CommandsOverloader.cxx +++ b/src/Core/CommandsOverloader.cxx @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -48,7 +49,14 @@ namespace Batch { * Constructor. */ CommandsOverloader::CommandsOverloader() - { + { + bool isFileDefined; + isCmdFileDefined(isFileDefined); + if (!isFileDefined && isCheckCmdsDefined()) { + cout << "================================================================" << endl; + cout << "Commands found on the system at compile time are used." << endl; + cout << "================================================================" << endl; + } } /*! @@ -71,7 +79,18 @@ namespace Batch { */ string CommandsOverloader::RM_Command() { string cmd = CMD_Command("RM"); - return (cmd.empty() ? RM_COMMAND : cmd); + if (cmd.empty()) { +#ifdef RM_COMMAND + return RM_COMMAND; +#else + throw RunTimeException("Can't use SH protocol (RM command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -79,7 +98,18 @@ namespace Batch { */ string CommandsOverloader::SH_Command() { string cmd = CMD_Command("SH"); - return (cmd.empty() ? SH_COMMAND : cmd); + if (cmd.empty()) { +#ifdef SH_COMMAND + return SH_COMMAND; +#else + throw RunTimeException("Can't use SH protocol (SH command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -87,7 +117,18 @@ namespace Batch { */ string CommandsOverloader::CP_Command() { string cmd = CMD_Command("CP"); - return (cmd.empty() ? CP_COMMAND : cmd); + if (cmd.empty()) { +#ifdef CP_COMMAND + return CP_COMMAND; +#else + throw RunTimeException("Can't use SH protocol (CP command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -95,7 +136,18 @@ namespace Batch { */ string CommandsOverloader::MKDIR_Command() { string cmd = CMD_Command("MKDIR"); - return (cmd.empty() ? MKDIR_COMMAND : cmd); + if (cmd.empty()) { +#ifdef MKDIR_COMMAND + return MKDIR_COMMAND; +#else + throw RunTimeException("Can't use SH protocol (MKDIR command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -103,7 +155,18 @@ namespace Batch { */ string CommandsOverloader::RSH_Command() { string cmd = CMD_Command("RSH"); - return (cmd.empty() ? RSH_COMMAND : cmd); + if (cmd.empty()) { +#ifdef RSH_COMMAND + return RSH_COMMAND; +#else + throw RunTimeException("Can't use RSH protocol (RSH command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -111,7 +174,18 @@ namespace Batch { */ string CommandsOverloader::RCP_Command() { string cmd = CMD_Command("RCP"); - return (cmd.empty() ? RCP_COMMAND : cmd); + if (cmd.empty()) { +#ifdef RCP_COMMAND + return RCP_COMMAND; +#else + throw RunTimeException("Can't use RSH protocol (RCP command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -119,7 +193,18 @@ namespace Batch { */ string CommandsOverloader::SSH_Command() { string cmd = CMD_Command("SSH"); - return (cmd.empty() ? SSH_COMMAND : cmd); + if (cmd.empty()) { +#ifdef SSH_COMMAND + return SSH_COMMAND; +#else + throw RunTimeException("Can't use SSH protocol (SSH command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -127,7 +212,18 @@ namespace Batch { */ string CommandsOverloader::SCP_Command() { string cmd = CMD_Command("SCP"); - return (cmd.empty() ? SCP_COMMAND : cmd); + if (cmd.empty()) { +#ifdef SCP_COMMAND + return SCP_COMMAND; +#else + throw RunTimeException("Can't use SSH protocol (SCP command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -135,7 +231,18 @@ namespace Batch { */ string CommandsOverloader::RSYNC_Command() { string cmd = CMD_Command("RSYNC"); - return (cmd.empty() ? RSYNC_COMMAND : cmd); + if (cmd.empty()) { +#ifdef RSYNC_COMMAND + return RSYNC_COMMAND; +#else + throw RunTimeException("Can't use RSYNC protocol (RSYNC command was " + "not found neither in the file pointed by " + "LIBBATCH_OVERRIDE_CMDS environment variable " + "nor on the system at compile time)."); +#endif + } else { + return cmd; + } } /*! @@ -151,10 +258,12 @@ namespace Batch { throw RunTimeException(errMsg.str()); } string line; + bool empty = true; int lineNumber = 1; while (getline(fileStream, line)) { string str = line; if (!str.empty()) { + empty = false; // Find ' ' symbol and split the line size_t pos = str.find_first_of(' '); if (pos == string::npos) { @@ -198,6 +307,11 @@ namespace Batch { } ++lineNumber; } + if (empty) { + stringstream errMsg; + errMsg << "Wrong format of " << theFilename << " file: Empty file."; + throw RunTimeException(errMsg.str()); + } fileStream.close(); } @@ -214,6 +328,33 @@ namespace Batch { return theStr.substr(beg, end-beg+1); } + /*! + * Check, if file with overloaded commands is defined by + * LIBBATCH_OVERRIDE_CMDS environment variable. + * \param theIsDefined in/out parameter; true, if file is defined; false - otherwise + * \return the name of file with overloaded commands + */ + const char * CommandsOverloader::isCmdFileDefined(bool & theIsDefined) const + { + const char * filename = getenv("LIBBATCH_OVERRIDE_CMDS"); + theIsDefined = (filename != NULL && !string(filename).empty()); + return filename; + } + + /*! + * Check, if it is needed to show information about overloaded or not + * commands are used. It can be switched ON via the environment + * variable LIBBATCH_CHECK_CMDS=1. + * \return true, if it is needed to show information; false - otherwise + */ + bool CommandsOverloader::isCheckCmdsDefined() const + { + char * check_cmds_env = getenv("LIBBATCH_CHECK_CMDS"); + if (check_cmds_env && atoi(check_cmds_env) == 1) + return true; + return false; + } + /*! * Return an overridden definition of the given command. * \param theKey command name @@ -221,13 +362,34 @@ namespace Batch { */ string CommandsOverloader::CMD_Command(const std::string & theKey) { if (_cmdmap.empty()) { - const char * filename = getenv("LIBBATCH_OVERRIDE_CMDS"); - if (filename != NULL) { + bool isFileDefined; + const char * filename = isCmdFileDefined(isFileDefined); + if (isFileDefined) { // Environment variable LIBBATCH_OVERRIDE_CMDS is defined. // Parse text file pointed by LIBBATCH_OVERRIDE_CMDS environment variable. parse(filename); // Note: If environment variable LIBBATCH_OVERRIDE_CMDS is not defined, // use command configuration established at compile time. + + // Showing information about overloaded or not commands are used is disabled by default. + // It can be switched ON via the environment variable: LIBBATCH_CHECK_CMDS=1 + if (isCheckCmdsDefined()) { + cout << "================================================================" << endl; + if (_cmdmap.empty()) { + cout << "Commands found on the system at compile time are used." << endl; + } else if (_cmdmap.size() == supportedCmds.size()) { + cout << "Overloaded commands are used." << endl; + } else { + cout << "Command(s)" << endl; + map::const_iterator iter; + for (iter = _cmdmap.begin() ; iter != _cmdmap.end() ; ++iter) { + cout << "\t" << iter->first << endl; + } + cout << "is(are) overloaded." << endl; + cout << "The rest command(s) is(are) found on the system at compile time." << endl; + } + cout << "================================================================" << endl; + } } } diff --git a/src/Core/CommandsOverloader.hxx b/src/Core/CommandsOverloader.hxx index ca1cf76..4a34c83 100644 --- a/src/Core/CommandsOverloader.hxx +++ b/src/Core/CommandsOverloader.hxx @@ -63,6 +63,9 @@ namespace Batch { void parse(const std::string & theFilename); std::string trim(const std::string & theStr) const noexcept; + const char * isCmdFileDefined(bool & theIsDefined) const; + bool isCheckCmdsDefined() const; + std::string CMD_Command(const std::string & theKey); bool hasKey(const std::string & theKey) const; diff --git a/src/Core/CommunicationProtocol.cxx b/src/Core/CommunicationProtocol.cxx index c670ffd..ccb5b2f 100644 --- a/src/Core/CommunicationProtocol.cxx +++ b/src/Core/CommunicationProtocol.cxx @@ -31,18 +31,10 @@ #include #include "CommunicationProtocol.hxx" -#ifdef HAS_RSH - #include "CommunicationProtocolRSH.hxx" -#endif -#ifdef HAS_SH - #include "CommunicationProtocolSH.hxx" -#endif -#ifdef HAS_SSH - #include "CommunicationProtocolSSH.hxx" -#endif -#ifdef HAS_RSYNC - #include "CommunicationProtocolRsync.hxx" -#endif +#include "CommunicationProtocolRSH.hxx" +#include "CommunicationProtocolSH.hxx" +#include "CommunicationProtocolSSH.hxx" +#include "CommunicationProtocolRsync.hxx" #include "APIInternalFailureException.hxx" #include "RunTimeException.hxx" #include "Log.hxx" @@ -64,37 +56,17 @@ namespace Batch { 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 if (protocolType == RSYNC) { -#ifdef HAS_RSYNC static CommunicationProtocolRsync instanceRsync; return instanceRsync; -#else - throw RunTimeException("Can't use RSYNC protocol (RSYNC tools were " - "not found on the system at compile time)."); -#endif } else throw APIInternalFailureException("Unknown communication protocol."); } diff --git a/src/LSF/CMakeLists.txt b/src/LSF/CMakeLists.txt index 72f087f..3a70d24 100644 --- a/src/LSF/CMakeLists.txt +++ b/src/LSF/CMakeLists.txt @@ -27,6 +27,4 @@ SET(CLASS_LIST LSF/BatchManager_LSF APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (HAS_SSH) - ADD_TEST(LSF_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LSF SSH) -ENDIF () +ADD_TEST(LSF_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LSF SSH) diff --git a/src/Local/CMakeLists.txt b/src/Local/CMakeLists.txt index f70c7ad..bfabee7 100644 --- a/src/Local/CMakeLists.txt +++ b/src/Local/CMakeLists.txt @@ -29,15 +29,9 @@ SET(CLASS_LIST Local/BatchManager_Local APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (HAS_SH) - ADD_TEST(LOCAL_SH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SH) -ENDIF () +ADD_TEST(LOCAL_SH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SH) -IF (HAS_SSH) - ADD_TEST(LOCAL_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SSH) -ENDIF () +ADD_TEST(LOCAL_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SSH) -IF (HAS_RSH) - ADD_TEST(LOCAL_RSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL RSH) -ENDIF () +ADD_TEST(LOCAL_RSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL RSH) diff --git a/src/Python/Test/CMakeLists.txt b/src/Python/Test/CMakeLists.txt index e304a39..e89c4b0 100644 --- a/src/Python/Test/CMakeLists.txt +++ b/src/Python/Test/CMakeLists.txt @@ -20,7 +20,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -IF (LIBBATCH_LOCAL_SUBMISSION AND HAS_SH) +IF (LIBBATCH_LOCAL_SUBMISSION) # Configure the config file for the test script CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py) diff --git a/src/Slurm/CMakeLists.txt b/src/Slurm/CMakeLists.txt index b95e91b..8869fd6 100644 --- a/src/Slurm/CMakeLists.txt +++ b/src/Slurm/CMakeLists.txt @@ -27,6 +27,4 @@ SET(CLASS_LIST Slurm/BatchManager_Slurm APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (HAS_SSH) - ADD_TEST(SLURM_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager SLURM SSH) -ENDIF () +ADD_TEST(SLURM_SSH ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager SLURM SSH) diff --git a/src/Vishnu/CMakeLists.txt b/src/Vishnu/CMakeLists.txt index df976c4..3ca057d 100644 --- a/src/Vishnu/CMakeLists.txt +++ b/src/Vishnu/CMakeLists.txt @@ -27,6 +27,4 @@ SET(CLASS_LIST Vishnu/BatchManager_Vishnu APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (HAS_SSH) - ADD_TEST(VISHNU ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager VISHNU SH) -ENDIF () +ADD_TEST(VISHNU ${PROJECT_BINARY_DIR}/src/Core/Test/Test_BatchManager VISHNU SH)