Salome HOME
[bos #32518][EDF] (2022-T3)
authorMargarita KARPUNINA <margarita.karpunina@opencascade.com>
Mon, 21 Nov 2022 13:09:20 +0000 (16:09 +0300)
committerMargarita KARPUNINA <margarita.karpunina@opencascade.com>
Mon, 21 Nov 2022 13:09:20 +0000 (16:09 +0300)
Parametrize commands in LIBBATCH
Debug, Windows porting/testing, info about overloaded or not commands

12 files changed:
CMakeLists.txt
CMakeModules/libbatchMacros.cmake
libbatch_config.h.in
src/Core/CMakeLists.txt
src/Core/CommandsOverloader.cxx
src/Core/CommandsOverloader.hxx
src/Core/CommunicationProtocol.cxx
src/LSF/CMakeLists.txt
src/Local/CMakeLists.txt
src/Python/Test/CMakeLists.txt
src/Slurm/CMakeLists.txt
src/Vishnu/CMakeLists.txt

index 63750e5d519d74ffb4386569468b704788a114c2..62ed7b7507ed3b79379f0fccba207ea4366dc513 100644 (file)
@@ -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()
index 999b8bfe5ee54a71d113944b3ec0730b39b3392a..a8daa4f2eeab5faf93ab73e8472277ca994dd309 100644 (file)
@@ -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")
index 57eee6bb309657fba0a74d30ac05a78be05dbf04..37f8a3dd135d01ff0e3941a3e0795c257898ca14 100644 (file)
@@ -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@"
 
 /* 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@"
 
index 54ea889f925f59ebdc5b0ad92e3fcdad48b08aa7..fa15d1ed6da3be36d3759ea4a9c2836428c539c6 100644 (file)
@@ -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)
index 7ee23c35a3f2f5d8410444309a8a827f31ea57e4..06f70576d1165628db2f615090bcdfd73fff5573 100644 (file)
@@ -30,6 +30,7 @@
 #include <fstream>
 #include <set>
 #include <sstream>
+#include <iostream>
 
 #include <libbatch_config.h>
 
@@ -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<string,string>::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;
+        }
       }
     }
 
index ca1cf768a93ba43057a5bd66bf09f6473a2172ab..4a34c834acaf14749344bf2a1289c5d167771d99 100644 (file)
@@ -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;
index c670ffd0546688d86ba585276f46aa7ea58d571d..ccb5b2fbd8a9a3d33901f7bcbe3a37deaa5f1e72 100644 (file)
 #include <libbatch_config.h>
 
 #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.");
   }
index 72f087f820032da5d969cce6be1d96687b161909..3a70d24ea96a2bea30cb436560d556b5ce0a7967 100644 (file)
@@ -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)
index f70c7ada13ddc1afac37d7eb25f67eed3c2b6d2c..bfabee7d52e029bdcadcad5f462e4386081db907 100644 (file)
@@ -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)
 
index e304a3975e6a3abed58fc3a010e0c43b172ca422..e89c4b04e5732f8cd032efc6bb66d73680c30d05 100644 (file)
@@ -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)
     
index b95e91bcf2bc18da83d0008c2512bb7856ad80cd..8869fd65c8513fb2a0e711cdc3eaab6cb84be469 100644 (file)
@@ -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)
index df976c480e1ea3e7cc85e6304e601d160a11d4f6..3ca057dcf5cbb0ac30d02d1d4cab7456e95c2b2a 100644 (file)
@@ -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)