From: barate Date: Fri, 15 Feb 2013 12:49:52 +0000 (+0000) Subject: Merge from BR_LIBBATCH_2_0 X-Git-Tag: V2_0_0a1~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=81d83ed5bb4d235c5688dcec0e9458015e760e26;p=tools%2Flibbatch.git Merge from BR_LIBBATCH_2_0 --- diff --git a/Batch_config.h.in b/Batch_config.h.in deleted file mode 100644 index 83fdacf..0000000 --- a/Batch_config.h.in +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2007-2012 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 -// - -#ifndef BATCH_CONFIG_H -#define BATCH_CONFIG_H - -/* Defines the compiler used on Windows */ -#cmakedefine MSVC -#cmakedefine MINGW - -/* 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 rm-like command */ -#cmakedefine RM_COMMAND "@RM_COMMAND@" - -/* A path to a cp-like command */ -#cmakedefine CP_COMMAND "@CP_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 - -/* A path to a ssh-like command */ -#cmakedefine SSH_COMMAND "@SSH_COMMAND@" - -/* A path to a scp-like command */ -#cmakedefine SCP_COMMAND "@SCP_COMMAND@" - -#endif diff --git a/CMakeLists.txt b/CMakeLists.txt index 41ec665..f671fce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,16 +20,13 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -project (libBatch) +project (libbatch) -cmake_minimum_required (VERSION 2.4) +cmake_minimum_required (VERSION 2.8) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/) find_package (PThread REQUIRED) -find_package (Makeinfo) -SET (BUILD_LSF_INTERFACE TRUE CACHE BOOL "Build interface for LSF batch system") -SET (BUILD_PBS_INTERFACE TRUE CACHE BOOL "Build interface for PBS batch system") SET (BUILD_LOCAL_SUBMISSION TRUE CACHE BOOL "Build classes for local submission") SET (BUILD_PYTHON_WRAPPING TRUE CACHE BOOL "Generate Python wrapping") SET (TEST_ENABLED FALSE CACHE BOOL "Enable testing") @@ -38,39 +35,30 @@ IF (TEST_ENABLED) ENABLE_TESTING() ENDIF (TEST_ENABLED) -IF (BUILD_LSF_INTERFACE) - find_package (LSF) -ENDIF (BUILD_LSF_INTERFACE) -IF (BUILD_PBS_INTERFACE) - find_package (PBS) -ENDIF (BUILD_PBS_INTERFACE) IF (BUILD_LOCAL_SUBMISSION) find_package (Local) ENDIF (BUILD_LOCAL_SUBMISSION) IF (BUILD_PYTHON_WRAPPING) - FIND_PACKAGE(Python) + FIND_PACKAGE(PythonInterp) + SET(PythonLibs_FIND_VERSION ${PYTHON_VERSION_STRING}) + FIND_PACKAGE(PythonLibs) FIND_PACKAGE(SWIG) ENDIF (BUILD_PYTHON_WRAPPING) SET(CPACK_GENERATOR TGZ) SET(CPACK_SOURCE_GENERATOR TGZ ZIP) -SET(CPACK_PACKAGE_VERSION_MAJOR 1) -SET(CPACK_PACKAGE_VERSION_MINOR 6) +SET(CPACK_PACKAGE_VERSION_MAJOR 2) +SET(CPACK_PACKAGE_VERSION_MINOR 0) SET(CPACK_PACKAGE_VERSION_PATCH 0) SET(CPACK_SOURCE_IGNORE_FILES /\\\\.;/CVS/;~) SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) -configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Batch_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Batch_config.h) +configure_file (${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) INCLUDE(Summary) add_subdirectory (src) - -IF (Makeinfo_FOUND) - add_subdirectory (doc) -ENDIF (Makeinfo_FOUND) - add_subdirectory (misc) INCLUDE(CPack) diff --git a/CMakeModules/FindLSF.cmake b/CMakeModules/FindLSF.cmake deleted file mode 100644 index 1f07877..0000000 --- a/CMakeModules/FindLSF.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -IF (NOT LSF_FIND_QUIETLY) - MESSAGE(STATUS "Looking for LSF...") -ENDIF (NOT LSF_FIND_QUIETLY) - -FIND_PATH(LSF_INCLUDE_DIR lsf/lsbatch.h) -FIND_LIBRARY(LSF_LIBRARY lsf) -FIND_LIBRARY(LSF_BAT_LIBRARY bat) - -IF (LSF_INCLUDE_DIR AND LSF_LIBRARY AND LSF_BAT_LIBRARY) - SET(LSF_FOUND True) -ENDIF (LSF_INCLUDE_DIR AND LSF_LIBRARY AND LSF_BAT_LIBRARY) - -IF (LSF_FOUND) - - IF (NOT LSF_FIND_QUIETLY) - MESSAGE(STATUS "Found LSF: ${LSF_LIBRARY}") - ENDIF (NOT LSF_FIND_QUIETLY) - -ELSE (LSF_FOUND) - - IF (LSF_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "LSF not found") - ELSE (LSF_FIND_REQUIRED) - IF (NOT LSF_FIND_QUIETLY) - MESSAGE(STATUS "LSF not found") - ENDIF (NOT LSF_FIND_QUIETLY) - ENDIF (LSF_FIND_REQUIRED) - -ENDIF (LSF_FOUND) diff --git a/CMakeModules/FindMakeinfo.cmake b/CMakeModules/FindMakeinfo.cmake deleted file mode 100644 index 4b51d1a..0000000 --- a/CMakeModules/FindMakeinfo.cmake +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -IF (NOT Makeinfo_FIND_QUIETLY) - MESSAGE(STATUS "Looking for Makeinfo...") -ENDIF (NOT Makeinfo_FIND_QUIETLY) - -FIND_PROGRAM(MAKEINFO_EXECUTABLE makeinfo DOC "Makeinfo executable") - -SET(Makeinfo_FOUND ${MAKEINFO_EXECUTABLE}) - -IF (Makeinfo_FOUND) - - IF (NOT Makeinfo_FIND_QUIETLY) - MESSAGE(STATUS "Found Makeinfo: ${MAKEINFO_EXECUTABLE}") - ENDIF (NOT Makeinfo_FIND_QUIETLY) - -ELSE (Makeinfo_FOUND) - - IF (Makeinfo_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Makeinfo not found") - ELSE (Makeinfo_FIND_REQUIRED) - IF (NOT Makeinfo_FIND_QUIETLY) - MESSAGE(STATUS "Makeinfo not found") - ENDIF (NOT Makeinfo_FIND_QUIETLY) - ENDIF (Makeinfo_FIND_REQUIRED) - -ENDIF (Makeinfo_FOUND) diff --git a/CMakeModules/FindPBS.cmake b/CMakeModules/FindPBS.cmake deleted file mode 100644 index 5f54a49..0000000 --- a/CMakeModules/FindPBS.cmake +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -IF (NOT PBS_FIND_QUIETLY) - MESSAGE(STATUS "Looking for PBS...") -ENDIF (NOT PBS_FIND_QUIETLY) - -FIND_PATH(PBS_INCLUDE_DIR pbs_ifl.h) -FIND_LIBRARY(PBS_LIBRARY NAMES pbs torque) - -IF (PBS_INCLUDE_DIR AND PBS_LIBRARY) - SET(PBS_FOUND True) -ENDIF (PBS_INCLUDE_DIR AND PBS_LIBRARY) - -IF (PBS_FOUND) - - IF (NOT PBS_FIND_QUIETLY) - MESSAGE(STATUS "Found PBS: ${PBS_LIBRARY}") - ENDIF (NOT PBS_FIND_QUIETLY) - -ELSE (PBS_FOUND) - - IF (PBS_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "PBS not found") - ELSE (PBS_FIND_REQUIRED) - IF (NOT PBS_FIND_QUIETLY) - MESSAGE(STATUS "PBS not found") - ENDIF (NOT PBS_FIND_QUIETLY) - ENDIF (PBS_FIND_REQUIRED) - -ENDIF (PBS_FOUND) diff --git a/CMakeModules/FindPython.cmake b/CMakeModules/FindPython.cmake deleted file mode 100644 index a6a3c82..0000000 --- a/CMakeModules/FindPython.cmake +++ /dev/null @@ -1,136 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# We use a custom FindPYTHON.cmake because the one shipped with cmake doesn't search -# properly for the version number. - -IF (NOT Python_FIND_QUIETLY) - MESSAGE(STATUS "Looking for Python...") -ENDIF (NOT Python_FIND_QUIETLY) - -IF(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL Release) - FIND_PROGRAM(PYTHON_DEBUG python_d) - mark_as_advanced(PYTHON_DEBUG) -ENDIF(WIN32 AND NOT CMAKE_BUILD_TYPE STREQUAL Release) - -IF (PYTHON_DEBUG) - SET(PYTHON_EXECUTABLE ${PYTHON_DEBUG} CACHE STRING "Python interpreter") -ELSE (PYTHON_DEBUG) - IF(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release) - MESSAGE(STATUS "Warning! Python debug executable not found. To build Swig module, you will need to install it or compile in Release mode") - ELSE(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release) - FIND_PROGRAM(PYTHON_EXECUTABLE python DOC "Python interpreter") - ENDIF(MSVC AND NOT CMAKE_BUILD_TYPE STREQUAL Release) -ENDIF (PYTHON_DEBUG) - -IF (PYTHON_EXECUTABLE) - IF (NOT Python_FIND_QUIETLY) - MESSAGE(STATUS "Python executable: ${PYTHON_EXECUTABLE}") - ENDIF (NOT Python_FIND_QUIETLY) - - EXECUTE_PROCESS( - COMMAND ${PYTHON_EXECUTABLE} -c "import sys; sys.stdout.write(sys.version[:3])" - OUTPUT_VARIABLE PYTHON_VERSION - ) - - IF (NOT Python_FIND_QUIETLY) - MESSAGE(STATUS "Python version: ${PYTHON_VERSION}") - ENDIF (NOT Python_FIND_QUIETLY) - - EXECUTE_PROCESS( - COMMAND ${PYTHON_EXECUTABLE} -c "import sys; import distutils.sysconfig; sys.stdout.write(distutils.sysconfig.get_python_inc())" - OUTPUT_VARIABLE PYTHON_DETECTED_INCLUDE_DIR - ) - - SET(PYTHON_HEADER Python.h) - FIND_PATH(PYTHON_INCLUDE_DIRS ${PYTHON_HEADER} - PATHS ${PYTHON_DETECTED_INCLUDE_DIR} - DOC "Python include directories") - - IF (NOT Python_FIND_QUIETLY) - IF (PYTHON_INCLUDE_DIRS) - MESSAGE(STATUS "Python include directories: ${PYTHON_INCLUDE_DIRS}") - ELSE (PYTHON_INCLUDE_DIRS) - MESSAGE(STATUS "Could not find Python include directories (looked for file ${PYTHON_HEADER} in directory ${PYTHON_DETECTED_INCLUDE_DIR})") - ENDIF (PYTHON_INCLUDE_DIRS) - ENDIF (NOT Python_FIND_QUIETLY) - - FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/findpythonlib.py - "import sys\n" - "import os\n" - "import distutils.sysconfig\n" - "libdir = distutils.sysconfig.get_config_var('LIBDIR')\n" - "if libdir is None:\n" - " prefix = distutils.sysconfig.get_config_var('prefix')\n" - " libdir = prefix + ';' + os.path.join(prefix, 'lib') + ';' + os.path.join(prefix, 'libs')\n" - "sys.stdout.write(libdir)" - ) - - EXECUTE_PROCESS( - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/findpythonlib.py - OUTPUT_VARIABLE PYTHON_DETECTED_LIB_DIRS - ) - - IF(WIN32) - STRING(REPLACE "." "" PYTHON_VERSION_WITHOUT_DOT ${PYTHON_VERSION}) - IF(PYTHON_DEBUG) - SET(LIB_NAME python${PYTHON_VERSION_WITHOUT_DOT}_d) - ELSE(PYTHON_DEBUG) - SET(LIB_NAME python${PYTHON_VERSION_WITHOUT_DOT}) - ENDIF(PYTHON_DEBUG) - ELSE(WIN32) - SET(LIB_NAME python${PYTHON_VERSION}) - ENDIF(WIN32) - - FIND_LIBRARY(PYTHON_LIBRARIES ${LIB_NAME} ${PYTHON_DETECTED_LIB_DIRS} DOC "Python libraries") - - IF (NOT Python_FIND_QUIETLY) - IF (PYTHON_LIBRARIES) - MESSAGE(STATUS "Python libraries: ${PYTHON_LIBRARIES}") - ELSE (PYTHON_LIBRARIES) - MESSAGE(STATUS "Could not find Python libraries (looked for library ${LIB_NAME} in directory ${PYTHON_DETECTED_LIB_DIRS})") - ENDIF (PYTHON_LIBRARIES) - ENDIF (NOT Python_FIND_QUIETLY) - -ENDIF (PYTHON_EXECUTABLE) - -IF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS) - SET(Python_FOUND True) -ENDIF(PYTHON_EXECUTABLE AND PYTHON_LIBRARIES AND PYTHON_INCLUDE_DIRS) - -IF (Python_FOUND) - - IF (NOT Python_FIND_QUIETLY) - MESSAGE(STATUS "OK, working Python installation found") - ENDIF (NOT Python_FIND_QUIETLY) - -ELSE (Python_FOUND) - - IF (Python_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "No working Python installation found") - ELSE (Python_FIND_REQUIRED) - IF (NOT Python_FIND_QUIETLY) - MESSAGE(STATUS "No working Python installation found") - ENDIF (NOT Python_FIND_QUIETLY) - ENDIF (Python_FIND_REQUIRED) - -ENDIF (Python_FOUND) diff --git a/CMakeModules/FindSWIG.cmake b/CMakeModules/FindSWIG.cmake deleted file mode 100644 index 87d95a8..0000000 --- a/CMakeModules/FindSWIG.cmake +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# We use a custom FindSWIG.cmake because the one shipped with cmake doesn't search -# properly in the $PATH env var. - -IF (NOT SWIG_FIND_QUIETLY) - MESSAGE(STATUS "Looking for SWIG...") -ENDIF (NOT SWIG_FIND_QUIETLY) - -FIND_PROGRAM(SWIG_EXECUTABLE NAMES swig swig-1.3 DOC "SWIG executable") - -SET(SWIG_FOUND ${SWIG_EXECUTABLE}) - -IF (SWIG_FOUND) - - IF (NOT SWIG_FIND_QUIETLY) - MESSAGE(STATUS "Found SWIG: ${SWIG_EXECUTABLE}") - ENDIF (NOT SWIG_FIND_QUIETLY) - -ELSE (SWIG_FOUND) - - IF (SWIG_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "SWIG not found") - ELSE (SWIG_FIND_REQUIRED) - IF (NOT SWIG_FIND_QUIETLY) - MESSAGE(STATUS "SWIG not found") - ENDIF (NOT SWIG_FIND_QUIETLY) - ENDIF (SWIG_FIND_REQUIRED) - -ENDIF (SWIG_FOUND) diff --git a/CMakeModules/Summary.cmake b/CMakeModules/Summary.cmake index 83e9843..8d713b4 100644 --- a/CMakeModules/Summary.cmake +++ b/CMakeModules/Summary.cmake @@ -23,26 +23,6 @@ MESSAGE(STATUS "") MESSAGE(STATUS "**************** Summary ****************") MESSAGE(STATUS "") -IF (BUILD_LSF_INTERFACE) - IF (LSF_FOUND) - MESSAGE(STATUS "LSF ................................. Yes") - ELSE (LSF_FOUND) - MESSAGE(STATUS "LSF ........................... Not found") - ENDIF (LSF_FOUND) -ELSE (BUILD_LSF_INTERFACE) - MESSAGE(STATUS "LSF ....................... Not requested") -ENDIF (BUILD_LSF_INTERFACE) - -IF (BUILD_PBS_INTERFACE) - IF (PBS_FOUND) - MESSAGE(STATUS "PBS ................................. Yes") - ELSE (PBS_FOUND) - MESSAGE(STATUS "PBS ........................... Not found") - ENDIF (PBS_FOUND) -ELSE (BUILD_PBS_INTERFACE) - MESSAGE(STATUS "PBS ....................... Not requested") -ENDIF (BUILD_PBS_INTERFACE) - IF (BUILD_LOCAL_SUBMISSION) MESSAGE(STATUS "Local submission .................... Yes") ELSE (BUILD_LOCAL_SUBMISSION) @@ -50,21 +30,15 @@ ELSE (BUILD_LOCAL_SUBMISSION) ENDIF (BUILD_LOCAL_SUBMISSION) IF (BUILD_PYTHON_WRAPPING) - IF (Python_FOUND AND SWIG_FOUND) + IF (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) MESSAGE(STATUS "Python wrapping ..................... Yes") - ELSE (Python_FOUND AND SWIG_FOUND) + ELSE (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) MESSAGE(STATUS "Python wrapping ............... Not found") - ENDIF (Python_FOUND AND SWIG_FOUND) + ENDIF (PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) ELSE (BUILD_PYTHON_WRAPPING) MESSAGE(STATUS "Python wrapping ........... Not requested") ENDIF (BUILD_PYTHON_WRAPPING) -IF (Makeinfo_FOUND) - MESSAGE(STATUS "Makeinfo ............................ Yes") -ELSE (Makeinfo_FOUND) - MESSAGE(STATUS "Makeinfo ...................... Not found") -ENDIF (Makeinfo_FOUND) - MESSAGE(STATUS "") MESSAGE(STATUS "************** End Summary **************") MESSAGE(STATUS "") diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..83fdacf --- /dev/null +++ b/config.h.in @@ -0,0 +1,63 @@ +// Copyright (C) 2007-2012 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 +// + +#ifndef BATCH_CONFIG_H +#define BATCH_CONFIG_H + +/* Defines the compiler used on Windows */ +#cmakedefine MSVC +#cmakedefine MINGW + +/* 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 rm-like command */ +#cmakedefine RM_COMMAND "@RM_COMMAND@" + +/* A path to a cp-like command */ +#cmakedefine CP_COMMAND "@CP_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 + +/* A path to a ssh-like command */ +#cmakedefine SSH_COMMAND "@SSH_COMMAND@" + +/* A path to a scp-like command */ +#cmakedefine SCP_COMMAND "@SCP_COMMAND@" + +#endif diff --git a/doc/Batch.texi b/doc/Batch.texi deleted file mode 100644 index d8bc55c..0000000 --- a/doc/Batch.texi +++ /dev/null @@ -1,4892 +0,0 @@ -\input texinfo @c -*-texinfo-*- -@c %**start of header -@setfilename Batch.info -@settitle Documentation de Batch -@setchapternewpage odd -@iftex -@afourpaper -@end iftex - -@include version.texi - -@dircategory Bibliotheque de classes Batch -@direntry -* Batch: (Batch); Documentation de la bibliotheque de classes Batch. -@end direntry - -@c %**end of header - - - -@titlepage -@sp 10 -@comment The title is printed in a large font. -@title Bibliotheque de classes Batch -@subtitle Documentation - version @value{VERSION} -@subtitle @value{UPDATED} -@author Ivan DUTKA-MALEN - EDF R&D - -@c The following two commands start the copyright page. -@page -@vskip 0pt plus 1filll -Copyright @copyright{} 2003-2004 EDF R&D sous licence GPL -@end titlepage - -@contents - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Top, Description, Index , (dir) -@comment node-name, next, previous, up -@ifinfo -Copyright @copyright{} 2003-2004 EDF R&D sous licence GPL -@end ifinfo - -@unnumbered Introduction - -Ceci est la documentation de la bibliotheque de classes Batch version -@value{VERSION}. - -Ce manuel est normalement disponible sous la forme de fichiers -@file{.info}, PostScript @file{.ps}, PDF @file{.pdf} et HTML -@file{.html}. Merci a Texinfo. - - -@menu -* Description:: Le batch, c'est quoi ? Ca sert a quoi ? -* Classes:: Une description des classes internes. -* Utilisation:: Comment on s'en sert ? Quelques exemples. -* Installation de la bibliotheque:: Comment ca s'installe ? -* Divers:: D'autres petits details. -* Index:: Index generaux. -@end menu - - - - - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Description, Classes, Top, Top -@comment node-name, next, previous, up -@chapter Description Generale -@cindex description - -Dans le domaine du batch, nombreux sont les gestionnaires qui sont -apparus et se sont popularises en fonction des plates-formes et des -constructeurs. On peut notamment citer NQS, le premier de tous, LSF, -LoadLeveler, PBS (et ses derives OpenPBS et PBS Pro), etc. qui se -prevalent tous d'une compatibilite avec NQS. - -Si l'ensemble de ces produits offrent les fonctionnalites de base de -NQS, a savoir soumission, controle, destruction, modification, etc. de -travaux batch, ils se distinguent tous par leur incompatibilite mutuelle -et par les syntaxes de fichiers et les appels de fonction specifiques -qu'ils ont developpes. - -Or il est interessant de pouvoir acceder d'une facon homogene et -generique aux fonctionnalites de ces gestionnaires quitte a se -restreindre a un sous-ensemble minimal mais essentiel de leurs -possibilites. - -La bibliotheque de classes Batch fournit ce moyen de soumettre et -controler des travaux batch depuis une machine cliente sans s'occuper du -type de gestionnaire present sur le serveur sur lequel se deroule -l'execution du travail. Seul doit etre precise le nom du serveur sur -lequel sera soumis le travail batch et le type de gestionnaire qui s'y -trouve. Tout le reste est generique et ne depend plus de l'implementation. - - - - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes, Terminologie, Description, Top -@comment node-name, next, previous, up -@chapter Classes Internes -@cindex classe - -Les classes de la bibliotheque reposent sur des concepts issus du monde -de la gestion de batch, qui meritent d'etre reprecises pour ne pas -introduire d'ambiguite semantique dans le discours. - -@menu -* Terminologie:: Description des termes employes. -* Classes generiques:: Les classes communes a tous les gestionnaires. -* Classes specifiques:: Les classes d'implementation. -@end menu - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Terminologie, Batch, Classes, Classes -@comment node-name, next, previous, up -@section Terminologie -@cindex terminologie - -Pour les non-inities aux mysteres de la gestion de batch, un petit -glossaire des termes employes dans cette documentation, assaisonne a la -sauce de la bibliotheque de classes Batch. - -@menu -* Batch:: Gestion par lots, execution differee. -* BatchManager:: Gestionnaire de batch. -* Job:: Travail. -* Parametre:: Configuration de l'execution. -* Environnement:: Environnement d'execution. -* JobId:: Identifiant de travail. -* JobInfo:: Informations sur le travail. -@end menu - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Batch, BatchManager, Terminologie, Terminologie -@comment node-name, next, previous, up -@subsection Batch -@cindex batch - -Le traitement batch (batch processing en anglais), ou traitement par -lot, fait reference au mode de sequencage et d'utilisation des -ressources d'un calculateur tel qu'il a ete premierement employe dans -les debuts de l'ere informatique. Mais il faut preciser que cette -anteriorite ne condamne pas le traitement batch aux oubliettes au motif -d'une quelconque obsolescence. Si le traitement par lot a vu le jour et -existe encore aujourd'hui, c'est parce qu'il repond de maniere -satisfaisante a une certaine utilisation des ressources d'un -calculateur, et que cette utilisation est encore d'actualite. Present -depuis plus de quarante ans, le batch est encore largement utilise sur -les grands serveurs, et le sera vraisemblablement pour quelques annees -encore. - -Le traitement par lot se distingue de l'execution interactive par le -fait que les travaux a effectuer sont places dans une file d'attente -avec une indication pour chaque lot des ressources dont il doit disposer -pour aboutir correctement. Une fois les travaux inscrits dans la file, -c'est au systeme de traitement batch (@xref{BatchManager}.) de veiller a -leur bonne execution en leur fournissant les ressources demandees. Tout -travail qui ne disposerait pas des ressources adequates ne peut pas etre -active. - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node BatchManager, Job, Batch, Terminologie -@comment node-name, next, previous, up -@subsection Batch Manager -@cindex batch manager -@cindex gestionnaire - -Le role du gestionnaire de batch, ou batch manager en anglais, est -d'executer et eventuellement d'ordonner les travaux places en file -d'attente en leur allouant exclusivement les ressources necessaires a -leur execution. Son objectif est d'optimiser les ressources du systeme -dont il a la charge de maniere a ecouler le maximum de travaux en un -minimum de temps et un minimum de ressources materielles. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Job, Parametre, BatchManager, Terminologie -@comment node-name, next, previous, up -@subsection Job -@cindex Job -@cindex travail - -Le travail, ou job en anglais, est l'unite elementaire de traitement qui -peut etre soumis au gestionnaire de batch. Il peut s'agir d'une simple -commande systeme, comme d'une application ou bien meme de l'enchainement -complexe mais indivisible de plusieurs applications ou commandes. - -Pour s'executer correctement, c'est-a-dire sans erreur, le job doit -disposer de certaines ressources --- de la memoire, du temps, de -l'espace disque @dots{} --- pendant toute la duree de son -execution. C'est au gestionnaire de batch (@xref{BatchManager}.) de -garantir au job la presence et la persistence de ces ressources pendant -l'execution du job. - -Par contre c'est a l'utilisateur qui soumet le job d'informer le -gestionnaire de batch des ressources necessaires au job. Pour des -raisons evidentes de bonne gestion des ressources, le job ne peut -consommer plus de ressources que celles qu'il a demande et obtenu du -gestionnaire de batch sans etre arrete ou reclasse. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Parametre, Environnement, Job, Terminologie -@comment node-name, next, previous, up -@subsection Parametre -@cindex parametre - -Le premier type de ressource necessaire a un job concerne les elements -materiels ou temporels, en un mot, physiques. Parmi ces ressources, on -trouve le temps de calcul, le temps de presence en machine, l'espace -disque, la quantite de memoire vive, l'architecture du calculateur, etc. - -Dans la terminologie de la bibliotheque de classes Batch, tous ces -elements ont ete regroupes sous le terme de @emph{Parametre}. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Environnement, JobId, Parametre, Terminologie -@comment node-name, next, previous, up -@subsection Environnement -@cindex environnement - -Le second type de ressource necessaire a un job concerne les elements -logiciels. Cela se traduit le plus souvent, et particulierement, dans -les systemes Unix par la notion de variable d'environnement. Lorsque le -job s'execute, il doit pouvoir trouver l'ensemble des commandes et des -applications auquel il souhaite faire appel. Les variables -d'environnement decrivent donc les localisations des ces -programmes. Elles peuvent egalement contenir des informations influant -sur le comportement des programmes. - -Dans la terminologie de la bibliotheque de classes Batch, tous ces -elements on ete regroupes sous le terme de @emph{Environnement}. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node JobId, JobInfo, Environnement, Terminologie -@comment node-name, next, previous, up -@subsection JobId -@cindex jobid -@cindex identifier - -Si un job (@xref{Job}.) decrit les actions qui doivent etre effectues -par le systeme sous le controle du gestionnaire de batch, il est clair -qu'il est possible de soumettre plusieurs fois de suite le meme job, et -par la-meme d'executer plusieurs fois (et parfois simultanement) ces -memes actions. On a donc plusieurs instances du meme job qui sont -presentes en machine. Chaque instance peut etre distinguee des autres -par un identifiant unique qui lui est propre : c'est le @emph{jobId}. - -Le JobId est determine par le gestionnaire de batch au moment de la -soumission. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node JobInfo, Classes generiques, JobId, Terminologie -@comment node-name, next, previous, up -@subsection JobInfo -@cindex jobinfo - - -Des qu'un job (@xref{Job}.) est soumis donc des qu'il dispose d'un -JobId (@xref{JobId}.), il est possible d'interroger le gestionnaire de -batch pour etre informe de son comportement, de son evolution au sein du -systeme pendant son execution. - -On peut ainsi connaitre les parametres reellement consommes par rapport -aux parametres alloues, ainsi que l'environnement d'execution du job. - -Le JobInfo est une structure qui collecte ses informations sur l'etat du -job. - - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes generiques, Namespace, JobInfo, Classes -@comment node-name, next, previous, up -@section Classes generiques -@cindex classes generiques - -Schematiquement, les classes composant la bibliotheque sont regroupees -en trois categories. Celles appartenant au groupe @emph{Types de base} -ne servent que de support au fonctionnement des classes de plus haut -niveau, egalement appellees @emph{Classes utilisateur}. Seules ces -dernieres sont vraiment interessantes pour l'utilisateur de la -bibliotheque. Les exceptions sont regroupees dans une categorie qui leur -est propre. - -@menu -* Namespace:: Espace de noms pour la bibliotheque. -* Types de base:: Les classes elementaires. -* Classes utilisateur:: Les classes de haut-niveau. -* Exceptions:: Les exceptions de la bibliotheque. -@end menu - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Namespace, Types de base, Classes generiques, Classes generiques -@comment node-name, next, previous, up -@subsection Namespace -@cindex namespace - -Toutes les classes de la bibliotheque sont regroupees dans un unique -namespace nomme @emph{Batch} afin de ne pas introduire de conflit avec -d'autres classes de meme nom. - -Ainsi lorsque par exemple on cite la classe @emph{BatchManager}, il -faudra declarer un objet @emph{Batch::BatchManager} ou bien faire appel -au namespace @emph{Batch} en C++. En Python, les objets sont regroupes -dans un module nomme @emph{libBatch_Swig}. - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Types de base, Classe Couple, Namespace, Classes generiques -@comment node-name, next, previous, up -@subsection Types de base -@cindex types de base - -Les classes decrites ici sont toutes utilisees ou utilisables par les -classes utilisateur de la bibliotheque, et en particulier par la classe -Versatile. @xref{Classe Versatile}. - -Ces classes implementent sous forme d'objet les types de base du langage -C++. Ainsi la classe @emph{Booltype} implemente le type de base -@emph{bool}. Certains types de base n'existant pas dans le langage ont -ete crees et encapsules dans une classe : c'est le cas notamment du type -de base @emph{Date} et de la classe @emph{DateType}, et du type de base -@emph{Couple} et de la classe @emph{CoupleType}. - -Tous les classes heritent de la classe generique @emph{GenericType}. - -@menu --- Types de base -- - -* Classe Couple:: Association de fichiers. -* Classe Date:: Type elementaire de date. - --- Classes d'implementation des types de base -- - -* Classe GenericType:: Classe-mere de tous les types. -* Classe BoolType:: Encapsulation du type bool. -* Classe CharType:: Encapsulation du type char. -* Classe CoupleType:: Encapsulation du type Couple. -* Classe DateType:: Encapsulation du type Date. -* Classe IntType:: Encapsulation du type int. -* Classe LongType:: Encapsulation du type long. -* Classe StringType:: Encapsulation du type string. - -@end menu - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Couple, Classe Date, Types de base, Types de base -@comment node-name, next, previous, up -@page -@subsubsection Couple -@findex Couple - -La classe @emph{Couple} implemente le comportement d'un couple de deux -chaines de type @emph{string} qui sont respectivement nommees -@emph{local} et @emph{remote}. - -Cette classe est utilisee essentiellement pour la designation des -fichiers a transferer lors des soumissions de travaux, d'ou les noms -employes. - -@cartouche -Il faut toutefois faire attention a designer correctement ce qui est -local ou distant. Ainsi dans la bibliotheque de classes Batch, on a -adopte la convention qu'un fichier dit @emph{local} est celui present -sur la machine qui execute la bibliotheque de classes Batch, alors qu'un -fichier dit @emph{remote} (ou distant) est celui present sur le serveur -du gestionnaire de batch. -L'approche est donc clairement orientee utilisateur plutot que serveur. -@end cartouche - -@itemize @bullet{} -@item Entete - -@example -class Couple -@{ - public: - // Constructeur standard - Couple(const string & local, const string & remote); - - // Constructeur par recopie - Couple(const Couple & C); - - // Operateur pour l'affichage sur un stream - friend ostream & operator << (ostream & os, const Couple & cp); - - // Operateur d'affectation - virtual Couple & operator =(const Couple &); - - // Conversion en chaine - virtual string str() const; - - // Accesseurs - virtual string getLocal() const; - virtual string getRemote() const; - - protected: - string _local; // chemin d'acces au fichier local - string _remote; // chemin d'acees au fichier distant - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Date, Classe GenericType, Classe Couple, Types de base -@comment node-name, next, previous, up -@page -@subsubsection Date -@findex Date - -La classe @emph{Date} sert a stocker n'importe quelle information de -temps et peut la representer sous une forme plus lisible a l'utilisateur -que le traditionnel appel a la fonction @emph{ctime}. @xref{(*manpages*)ctime}. - -@itemize @bullet{} -@item Entete - -@example -class Date -@{ - public: - // Constructeur standard (a partir d'une valeur epoch) - Date(const long l=0); - - // Constructeur a partir d'une chaine hh:mm:ss - Date(const string s); - - // Operateurs portant sur les Dates - virtual Date & operator =(long l); - virtual Date & operator +(long l); - virtual Date & operator -(long l); - virtual Date & operator +=(long l); - virtual Date & operator -=(long l); - virtual Date & operator =(const string & s); - - // Conversions en types standards - virtual string str() const; - virtual long epoch() const; - - protected: - int _day, _month, _year; - int _hour, _min, _sec; - - private: - -@}; -@end example -@end itemize - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe GenericType, Classe BoolType, Classe Date, Types de base -@comment node-name, next, previous, up -@page -@subsubsection GenericType -@findex GenericType - -La classe @emph{GenericType} est la classe-mere de toutes les classes -utilisees par la classe @emph{Versatile}. @xref{Classe Versatile}. - -Elle definit une interface que @emph{Versatile} utilise pour controler -les objets : constructeur simple et destructeur, operateur sur -@emph{ostream}, conversion en chaine et surtout methode @emph{clone}. - -La methode @emph{clone} permet de recuperer un nouvel objet identique au -premier qui sera automatiquement alloue sur le tas par un appel a -@emph{new}. Il est important de noter ici que le nouvel objet @strong{DEVRA} -etre desalloue par un appel a @emph{delete}. Cette desallocation est a -la charge de l'utilisateur de l'objet sans quoi une fuite memoire en -resultera. - -@itemize @bullet{} -@item Entete - -@example -class GenericType -@{ - public: - // Constructeur et destructeur - GenericType(); - virtual ~GenericType(); - - // Operateur pour l'affichage sur un stream - friend ostream & operator << (ostream & os, - const GenericType & obj); - - // Conversion en chaine - virtual string affiche() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - // Retourne le nombre d'objets GenericType et al. - static int getNb(); - - protected: - - private: - static int _nb; // nombre total d'objets GenericType et al. - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe BoolType, Classe CharType, Classe GenericType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection BoolType -@findex BoolType - -Cette classe encapsule le type C++ @emph{bool} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - -@itemize @bullet{} -@item Entete - -@example -class BoolType : public GenericType -@{ - public: - // Constructeur - BoolType(const bool b=false); - - // Conversion en chaine - virtual string affiche() const; - - // Operateur d'affectation - virtual BoolType & operator =(bool); - - // Conversion en bool - virtual operator bool() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - bool _data; - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe CharType, Classe CoupleType, Classe BoolType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection CharType -@findex CharType - -Cette classe encapsule le type C++ @emph{char} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - - -@itemize @bullet{} -@item Entete - -@example -class CharType : public GenericType -@{ - public: - // Constructeur - CharType(const char c=0); - - // Conversion en chaine - virtual string affiche() const; - - // Operateur d'affectation - virtual CharType & operator =(char); - - // Conversion en char - virtual operator char() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - char _data; - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe CoupleType, Classe DateType, Classe CharType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection CoupleType -@findex CoupleType - -Cette classe encapsule le type interne @emph{Couple} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - - -@itemize @bullet{} -@item Entete - -@example -class CoupleType : public GenericType -@{ - public: - // Constructeur - CoupleType(const Couple & C); - - // Conversion en chaine - virtual string affiche() const; - virtual operator string() const; - - // Operateur d'affectation - virtual CoupleType & operator =(const Couple & C); - - // Conversion en char - virtual operator Couple() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - Couple _data; - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe DateType, Classe IntType, Classe CoupleType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection DateType -@findex DateType - -Cette classe encapsule le type interne @emph{Date} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - - -@itemize @bullet{} -@item Entete - -@example -class DateType : public GenericType -@{ - public: - // Constructeur - DateType(const Date & d); - - // Conversion en chaine - virtual string affiche() const; - - // Operateur d'affectation - virtual DateType & operator =(const Date &); - - // Conversion en Date - virtual operator Date() const; - - // Conversion en long - virtual operator long() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - Date _data; - - private: -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe IntType, Classe LongType, Classe DateType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection IntType -@findex IntType - -Cette classe encapsule le type C++ @emph{int} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - - -@itemize @bullet{} -@item Entete - -@example -class IntType : public GenericType -@{ - public: - // Constructeur - IntType(const int i=0); - - // Conversion en chaine - virtual string affiche() const; - - // Operateur d'affectation - virtual IntType & operator =(int); - - // Conversion en int - virtual operator int() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - int _data; - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe LongType, Classe StringType, Classe IntType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection LongType -@findex LongType - -Cette classe encapsule le type C++ @emph{long} dans un objet herite de -@emph{GenericType} de maniere a pouvoir le stocker aisement dans un -objet de classe @emph{Versatile}. - -@itemize @bullet{} -@item Entete - -@example -class LongType : public GenericType -@{ - public: - // Constructeur - LongType(const long l=0L); - - // Conversion en chaine - virtual string affiche() const; - - // Operateur d'affectation - virtual LongType & operator =(long); - - // Conversion en long - virtual operator long() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - long _data; - - private: - -@}; -@end example -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe StringType, Classes utilisateur, Classe LongType, Types de base -@comment node-name, next, previous, up -@page -@subsubsection StringType -@findex StringType - -Cette classe encapsule le type C++ @emph{string} de la STL dans un objet -herite de @emph{GenericType} de maniere a pouvoir le stocker aisement -dans un objet de classe @emph{Versatile}. - -@itemize @bullet{} -@item Entete - -@example -class StringType : public GenericType -@{ - public: - // Constructeur - StringType(const string & s=""); - - // Conversion en chaine - virtual string affiche() const; - virtual operator string() const; - - // Operateur d'affectation - virtual StringType & operator =(string); - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - string _data; - - private: - -@}; -@end example -@end itemize - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes utilisateur, Exemple, Classe StringType, Classes generiques -@comment node-name, next, previous, up -@page -@subsection Classes utilisateur -@cindex classes utilisateur - -Les classes dites classes utilisateur sont en realite les classes de -plus haut niveau de la biliotheque de classes Batch. Ces classes -remplissent les unes avec les autres l'ensemble des fonctionnalites -proposees par la bibliotheque. L'utilisateur trouvera donc dans cette -section la description des possibilites de la bibliotheque et le moyen -de les mettre en oeuvre. - -La premiere section montre un exemple complet de soumission et de -controle d'un job soumis a travers les classes de la biliotheque. Les -sections suivantes reprennent les elements de l'exemple pour le -detailler et le completer. - -@menu -* Exemple:: Exemple simple mais complet d'utilisation. -* Classe BatchManagerCatalog:: Description de la classe BatchManagerCatalog. -* Classe FactBatchManager:: Description de la classe FactBatchManager. -* Classe BatchManager:: Description de la classe BatchManager. -* Classe Environnement:: Description de la classe Environnement. -* Classe Job:: Description de la classe Job. -* Classe JobId:: Description de la classe JobId. -* Classe JobInfo:: Description de la classe JobInfo. -* Classe Parametre:: Description de la classe Parametre. -* Classe Versatile:: Description de la classe Versatile. -@end menu - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Exemple, Classe BatchManagerCatalog, Classes utilisateur, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection Exemple -@cindex exemple - -Cet exemple decrit le processus type de creation et de soumission d'un -job a travers les classes de la bibliotheque. - -Il faut toutefois penser que les appels aux methodes peuvent lever des -exceptions qu'il faudra intercepter et gerer. @xref{Exceptions}. - -@example - @dots{} - - // On recupere l'instance du catalogue de gestionnaires de batch - Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - - // On cree un BatchManager qui se connecte au veritable gestionnaire - // de batch - Batch::BatchManager & bm = (* cata("PBS"))("monserver.mondomaine.fr"); - - // Pour fabriquer un Job, on doit d'abord creer un objet Parametre et - // un objet Environnement qui contiennent respectivement la liste des - // parametres du job au sein du gestionnaire de batch et la liste des - // variables d'environnement necessaires au fonctionnement du job - Batch::Parametre param; - - param[EXECUTABLE] = "/home/user/mon_application/executable"; - param[NAME] = "MonJob"; - param[ACCOUNT] = "MonProjet"; // code d'imputation/facturation - param[MAXCPUTIME] = 360L; // 6min - param[MAXWALLTIME] = 480L; // 8min - param[INFILE] = Batch::Couple("/tmp/infich1", rempath+"/infich1"); - param[OUTFILE] = Batch::Couple("/tmp/outfich1", rempath+"/outfich1"); - param[OUTFILE] += Batch::Couple("stderr", path + "/STDERR"); - param[OUTFILE] += Batch::Couple("stdout", path + "/STDOUT"); - param[MAIL] = "user@@domaine.fr"; - param[USER] = "user"; - - Batch::Environnement env; - env["DEBUG"] = "3"; // un niveau de debug exige par l'application - env["MYAPP_FILE"] = "/home/user/mon_application/data/mydatafile"; - - // Creation du job - Batch::Job job(param, env); - - // On soumet le Job au BatchManager qui le relaie jusqu'au veritable - // gestionnaire de batch sur le serveur. En retour on obtient un - // identifiant unique de notre job (JobId). - const Batch::JobId jobid = bm.submitJob(job); - - // On interroge le BatchManager pour connaitre l'etat du Job - const Batch::JobInfo jinfo = jobid.queryJob(); - cout << jinfo << endl; - - // On detruit l'objet BatchManager - delete &bm; - - @dots{} -@end example - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe BatchManagerCatalog, Classe FactBatchManager, Exemple, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection BatchManagerCatalog -@findex BatchManagerCatalog - -La classe @emph{BatchManagerCatalog} definit une interface d'acces au -catalogue de fabriques de BatchManager. @xref{Classe FactBatchManager}. - -Pourquoi utiliser une fabrique et ne pas instancier directement un objet -@emph{BatchManager} en fonction de sa classe ? C'est l'option qui avait ete -choisie dans la premiere version de la bibliotheque de classes -Batch. Cette facon de proceder est simple, aussi bien pour le -developpeur de la classe que pour l'utilisateur, mais elle se revele a -terme penalisante dans la souplesse d'utilisation des classes. Elle -permet aussi moins facilement de mettre en place une strategie de -singleton pour les objets @emph{BatchManager}, ce qui peut se reveler utile non -pas en termes de performance mais plutot en termes de genericite et -toujours de souplesse. - -En resume, l'utilisation de fabiques permet d'acceder a la genericite, -qui rappelons-le est l'objet de cette biliotheque, a la souplesse et a -la performance au prix d'une legere complication pour le developpeur -mais pas pour l'utilisateur. - -Le catalogue de fabriques est une @emph{map}, ou tableau associatif, -auquel on passe le nom d'une fabrique et qui retourne un pointeur sur -une instance de cette fabrique. - -Le catalogue est renseigne statiquement par les fabriques declarees -elles-memes statiquement dans la biliotheque. Il est donc precharge avec -les fabriques correspondant a chacune des API disponibles. Comme le -catalogue n'est pas declare constant, il est possible de rajouter ou de -supprimer des fabriques dans le catalogue dynamiquement. - -@itemize @bullet{} -@item Entete - -@example -class BatchManagerCatalog -@{ -public: - // Methode permettant de recuperer l'instance unique de catalogue - static BatchManagerCatalog& getInstance(); - - // Accesseurs - void addFactBatchManager(const char * type, Batch::FactBatchManager * pFBM); - Batch::FactBatchManager * operator() (const char * type); - - // Wrapping Python - virtual std::map * dict(); - virtual std::string __repr__() const; - -protected: - // Constructeur - BatchManagerCatalog(); - // Destructeur - virtual ~BatchManagerCatalog(); - - // Le catalogue proprement dit - std::map _catalog; - // Mutex permettant d'assurer des acces "thread-safe" au catalogue - pthread_mutex_t _mutex; - -private: - // On interdit la copie de l'instance unique du catalogue (singleton) - BatchManagerCatalog(const BatchManagerCatalog & orig); - BatchManagerCatalog& operator=(const BatchManagerCatalog & orig); - -@}; -@end example - -@item Exemple - -@example -@dots{} - -// On recupere l'instance du catalogue de gestionnaires de batch -Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{static BatchManagerCatalog& getInstance()} - -Cette methode retourne l'instance unique du catalogue qui peut ensuite -etre utilisee pour ajouter ou recuperer des fabriques. - -@item -@b{void addFactBatchManager(const char * type, FactBatchManager * pFBM)} - -Cet accesseur enregistre dans le catalogue un pointeur sur un objet de type -@emph{FactBatchManager} sous le nom (le type) passe en argument. - -@item -@b{FactBatchManager * operator() (const char * type)} - -Cet accesseur retourne un pointeur sur un objet de type -@emph{FactBatchManager} en fonction du nom (le type) sous lequel il -s'est enregistre dans le catalogue. - -@item -@b{map * dict()} - -Cette methode utilisable depuis Python permet de recuperer un -dictionnaire decrivant le contenu du catalogue. - -@item -@b{string __repr__() const} - -Cette methode utilisable depuis Python retourne une description de -l'objet @emph{BatchManagerCatalog}. - -@item -@b{BatchManagerCatalog()} - -Le constructeur par defaut est declare "protected" et ne peut donc pas -etre utilise pour creer une nouvelle instance de @emph{BatchManagerCatalog}. -En effet, le catalogue est un singleton, ce qui signifie qu'une seule -instance du catalogue existe. Pour recuperer cette instance, il faut -utiliser la methode @emph{BatchManagerCatalog::getInstance()}. - -@item -@b{~BatchManagerCatalog()} - -De la meme maniere, le destructeur est declare "protected" et ne peut pas -etre utilise pour detruire l'instance de catalogue. Le singleton est detruit -automatiquement a la fin du programme. - -@end itemize - - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe FactBatchManager, Classe BatchManager, Classe BatchManagerCatalog, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection FactBatchManager -@findex FactBatchManager - -La classe @emph{FactBatchManager} est abstraite. Elle definit une interface -qui doit etre implementee par des classes specialisees en fonction du -gestionnaire de batch et de son API de communication. @xref{Classes specifiques}. - -Les objets repondant a l'interface de @emph{FactBatchManager} sont -automatiquement inseres dans le catalogue des fabriques de -@emph{BatchManager} a la construction de l'objet. Il est ainsi possible -de definir statiquement des objets de ce type qui enrichiront le -catalogue des la compilation. @xref{Classe -BatchManagerCatalog}. @xref{Classe BatchManager}. - -Les objets de la classe @emph{FactBatchManager} ou de ses derivees sont -des functors et renvoient au moment de l'appel un pointeur sur un objet -gestionnaire de batch @emph{BatchManager} associe a un -serveur. L'allocation de l'objet est faite sur le tas et celui-ci doit -donc etre desalloue manuellement par l'utilisateur de la bibliotheque au -moment opportun. - -@itemize @bullet{} -@item Entete - -@example -class FactBatchManager -@{ -public: - // Constructeur - FactBatchManager(const string & type); - - // Destructeur - virtual ~FactBatchManager(); - - // Functor - virtual BatchManager * operator() (const char * hostname) const = 0; - - // Accesseur au type interne - string getType() const; - - // Wrapping Python - string __repr__() const; - -protected: - string type; // Le type interne - -private: - -@}; -@end example - -@item Exemple - -@example -@dots{} - -// On recupere l'instance du catalogue de gestionnaires de batch -Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - -// On cree une fabrique de BatchManager de type PBS -Batch::FactBatchManager & fbm = * cata("PBS"); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} - -@item -@b{FactBatchManager(const string & type)} - -Le constructeur de la classe prend un type qui doit identifer de maniere -unique la fabrique au sein du catalogue de fabrique. Ce type sert de cle au -catalogue. @xref{Classe BatchManagerCatalog}. - -@item -@b{~FactBatchManager()} - -Le destructeur de la classe n'a pas d'action particuliere. - -@item -@b{BatchManager * operator() (const char * hostname) const} - -Cette methode est virtuelle pure. Elle doit etre surchargee dans les -classes derivees et doit retourner un pointeur sur un objet de type -@emph{BatchManager} correpondant au type de la classe et oeuvrant sur la -machine passee en argument. Le @emph{hostname} est soit alphabetique -soit numerique et doit etre soit un nom de machine valide soit une -adresse IP valide. Aucun controle n'est a priori realise et cet argument -est passe tel quel a l'API du gestionnaire de batch. - -Cet objet agit comme @emph{parent} vis-a-vis de l'objet -@emph{BatchManager} qu'il retourne. - -@item -@b{string getType() const} - -Cette methode renvoie le type interne de l'objet, c'est-a-dire la cle -sous lequel il est enregistre dans le catalogue. - -@item -@b{string __repr__() const} - -Cette methode utilisable depuis Python retourne une description de -l'objet @emph{FactBatchManager}. - -@end itemize - - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe BatchManager, Classe Environnement, Classe FactBatchManager, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection BatchManager -@findex BatchManager - -La classe @emph{BatchManager} est abstraite. Elle definit une interface -qui doit etre implementee par des classes specialisees en fonction du -gestionnaire de batch et de son API de communication. @xref{Classes -specifiques}. - -Toute action a destination du gestionnaire de batch doit etre precedee -de l'instanciation d'un objet derivant de la classe @emph{BatchManager} -puisque c'est a travers cet objet que l'on aura acces a l'interface du -gestionnaire. - -Cette instanciation est realisee par une fabrique de gestionnaire de -batch, instance elle-meme derivee de la classe abstraite -FactBatchManager. @xref{Classe FactBatchManager}. - -@itemize @bullet{} -@item Entete - -@example -class BatchManager -@{ - public: - // Constructeur et destructeur - BatchManager(const FactBatchManager * parent, - const char * host="localhost") - throw(InvalidArgumentException); - virtual ~BatchManager(); - - // Recupere l'identifiant d'un job deja soumis au BatchManager - virtual const JobId getJobIdByReference(const string & ref); - - // Methodes pour le controle des jobs : virtuelles pures - // soumet un job au gestionnaire - virtual const JobId submitJob(const Job & job) = 0; - - // retire un job du gestionnaire - virtual void deleteJob(const JobId & jobid) = 0; - - // suspend un job en file d'attente - virtual void holdJob(const JobId & jobid) = 0; - - // relache un job suspendu - virtual void releaseJob(const JobId & jobid) = 0; - - // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, - const Parametre & param, - const Environnement & env) = 0; - virtual void alterJob(const JobId & jobid, - const Parametre & param) = 0; - virtual void alterJob(const JobId & jobid, - const Environnement & env) = 0; - - // renvoie l'etat du job - virtual JobInfo queryJob(const JobId & jobid) = 0; - - // wrapping Python - virtual string __repr__() const; - - protected: - string _hostname; // serveur ou tourne le BatchManager - const FactBatchManager * _parent; // fabrique qui a produit l'instance - - private: - -@}; -@end example - -@item Exemple - -@example -@dots{} - -// On recupere l'instance du catalogue de gestionnaires de batch -Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - -// On cree un BatchManager qui se connecte au veritable gestionnaire -// de batch -Batch::BatchManager & bm = (* cata("PBS"))("monserver.mondomaine.fr"); - -// Maintenant, on peut utiliser toutes les fonctionnalites du -// gestionnaire de batch a travers le variable myBM - -// On detruit l'objet BatchManager -delete &bm; - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{BatchManager(const FactBatchManager * parent,$* -const char * host="localhost") throw(InvalidArgumentException)} - -Excepte un pointeur sur la fabrique qui a produit l'objet, @xref{Classe FactBatchManager}, - le constructeur accepte zero ou un argument de type -@emph{string} decrivant soit le nom de domaine completement qualifie -(FQDN, @i{fully qualified domain name}) du serveur de batch, soit son -adresse IP dans un format decimal "aaa.bbb.ccc.ddd". - -Une resolution du nom ou de l'adresse peut etre realisee en fonction des -capacites de la plate-forme pour s'assurer que le serveur est connu et -joignable. En cas d'echec, une exception InvalidArgumentException est -levee. @xref{Classe InvalidArgumentException}. A priori, aucune -verification n'est faite par defaut. - -Ceci fait, une connexion est etablie avec le gestionnaire de batch qui -est maintenue jusqu'a destruction de l'objet, si le gestionnaire le permet. - -@item -@b{~BatchManager()} - -Le destructeur supprime la connexion precedemment etablie par le -constructeur lorsque celle-ci a reussi. - -@item -@b{const JobId submitJob(const Job & job)} - -Cette methode soumet le job passe en argument au gestionnaire de -batch. Etant donne que le job ne peut pas etre envoye tel quel puisqu'il -a un format generique au sein de la bibliotheque de classes Batch, cette -methode est chargee de le convertir dans un format adapte au -gestionnaire de batch sous-jacent. - -Ce n'est que lorsque cette conversion est realisee que le job est soumis -au gestionnaire a travers son API. L'identifiant propose par le -gestionnaire est alors renvoye a l'appelant. Si la soumission echoue -pour une raison ou une autre, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{void deleteJob(const JobId & jobid)} - -Cette methode retire le job dont l'identifiant est passe en argument de -la file d'attente du gestionnaire, ou bien l'arrete s'il est en cours -d'execution. Cette methode est inoperante sur des travaux deja termines, -auquel cas une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{void holdJob(const JobId & jobid)} - -Cette methode suspend le job dont l'identifiant est passe en argument au -sein de la file d'attente du gestionnaire. Cette methode est inoperante -sur des travaux en cours d'execution ou deja termines, ainsi que sur des -travaux deja suspendus. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{void releaseJob(const JobId & jobid)} - -Cette methode relache un job precedemment suspendu en file -d'attente dont l'identifiant est passe en argument. Elle est inoperante -sur des travaux deja relaches, en cours d'execution ou termines. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)@* -void alterJob(const JobId & jobid, const Parametre & param)@* -void alterJob(const JobId & jobid, const Environnement & env)} - -Ces methodes permettent de modifier les parametres d'execution et -d'environnement d'un job dont l'identifiant est passe en -argument. @xref{Classe Parametre}. @xref{Classe Environnement}. Il -est important de noter que le job doit etre encore place en file -d'attente sinon la methode est inoperante. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{JobInfo queryJob(const JobId & jobid)} - -Cette methode permet de recuperer les informations concernant le job -dont l'identifiant est passe en argument dans un objet de classe -@emph{JobInfo}. @xref{Classe JobInfo}. On y retrouve les parametres -d'execution et d'environnement du job tels qu'ils ont ete passes au -gestionnaire au moment de la soumission, ainsi que des informations -concernant l'execution du job comme par exemple la machine d'execution, -le temps consomme, la memoire consommee, etc. - -Il n'est pas toujours possible d'interroger un job deja termine. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{const JobId getJobIdByReference(const string & ref)} - -Cette methode permet de recuperer au sein de la classe un identifiant de -job a partir d'une chaine de caracteres obtenue par un biais -externe. Cet identifiant pourra etre utilise par la suite au sein de la -biliotheque de classes pour controler le job comme s'il avait ete cree -et soumis depuis la biliotheque-meme. - -@end itemize - - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Environnement, Classe Job, Classe BatchManager, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection Environnement -@findex Environnement - -La classe @emph{Environnement} permet de definir les variables -d'environnement necessaires a l'execution d'un job. Ces variables seront -creees automatiquement dans l'environnement du job lorsque celui-ci -debutera son execution sur la machine. - -Une variable d'environnement est traditionnellement composee d'un nom et -d'une valeur qui peut etre vide ou absente. L'ensemble des variables -d'environnement peut ainsi etre represente sous la forme d'une table -associative dans laquelle le nom de la variable correspond a la clef de la -table, et la valeur de la variable correspond a la valeur de la table -pour la clef donnee. - -Chaque objet de la classe @emph{Environnement} se comporte comme une -table associative telle que decrite auparavant. - -@itemize @bullet{} -@item Entete - -@example -typedef map < string, string > Environnement; -@end example - - -@item Exemple -@example -@dots{} - -Environnement env; -env["MYAPP_ROOTDIR"] = "/home/user/myapplication"; -env["MYAPP_LICENSEFILE"] = env["MYAPP_ROOTDIR"] + "/license.dat"; -env["CXX"] = "g++"; -env["CXXFLAGS"] = "-g -O2"; - -@dots{} -@end example - -@item Methodes - -Compte tenu de la definition actuelle de la classe @emph{Environnement} -en tant que map STL, elle beneficie de toutes les fonctionnalites -classiques des maps STL. - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Job, Classe JobId, Classe Environnement, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection Job -@findex Job - -La classe @emph{Job} represente la notion de travail, ou job, dans la -bibliotheque de classes Batch. Elle se comporte essentiellement comme -une collection de parametres et de variables necessaires a la -description des actions qui doivent etre realisees dans des conditions -precisees. - -Elle se repose sur deux autres classes qui distinguent la notion de -parametre d'execution et celle de variable d'environnement : les classes -@emph{Parametre} et @emph{Environnement}. @xref{Classe -Parametre}. @xref{Classe Environnement}. - -Son role est de preparer la soumission qui aura lieu et qui concretisera -l'incarnation du job dans le gestionnaire de batch. Tant que le job n'a -pas ete soumis, on ne peut pas vraiment considerer son existence et de -fait les interactions qu'on peut avoir avec l'objet sont tres limitees. - -@itemize @bullet{} -@item Entete - -@example -class Job -@{ - public: - // Constructeurs et destructeur - Job(); - Job(Parametre param); - Job(Environnement env); - Job(Parametre param, Environnement env); - virtual ~Job(); - - // Operateur pour l'affichage sur un stream - friend ostream & operator <<(ostream & os, const Job & job); - - // Accesseurs - Parametre getParametre() const; - void setParametre(const Parametre &); - - // Accesseurs - Environnement getEnvironnement() const; - void setEnvironnement(const Environnement &); - - // Methodes pour l'interfacage avec Python (SWIG) - string __repr__() const; - - protected: - Parametre _param; // table des parametres batch du job - Environnement _env; // table des variables d'environnement - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} - -@dots{} (ici on cree un BatchManager bm) -Parametre param; -Environnement env; - -@dots{} (ici on cree les parametres du job) - -Job job(param, env); -JobId jobid = bm.sumbitJob(job); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} - -@item -@b{Job()$* -Job(Parametre param)$* -Job(Environnement env)$* -Job(Parametre param, Environnement env)} - -Le constructeur, en plus de creer l'objet, peut faire des verifications -sur la coherence des objets passes en argument s'il y en a. - -@item -@b{~Job()} - -Le destructeur libere simplement les espaces alloues. - -@item -@b{ostream & operator <<(ostream & os, const Job & job)} - -Cette methode permet a l'utilisateur d'afficher sur un stream le contenu -d'un objet de classe @emph{Job}. - -@item -@b{Parametre getParametre() const} - -Un accesseur pour recuperer l'objet Parametre passe en argument du -constructeur. - -@item -@b{void setParametre(const Parametre &)} - -Cette methode permet de positionner @i{a posteriori} l'objet -@emph{Parametre}. Des tests complementaires peuvent etre faits pour -verifier la coherence de l'objet. - -@item -@b{Environnement getEnvironnement() const} - -Un accesseur pour recuperer l'objet Environnement passe en argument du constructeur. - -@item -@b{void setEnvironnement(const Environnement &)} - -Cette methode permet de positionner @i{a posteriori} l'objet -@emph{Environnement}. Des tests complementaires peuvent etre faits pour -verifier la coherence de l'objet. - -@item -@b{string __repr__() const} - -Cette methode sert dans l'interfacage Python de l'objet et permet d'en -realiser l'affichage a travers l'interpreteur Python. - -@end itemize -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe JobId, Classe JobInfo, Classe Job, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection JobId -@findex JobId - -La classe @emph{JobId} represente l'incarnation d'un objet de classe -@emph{Job} une fois soumis au travers du gestionnaire de batch. A chaque -objet @emph{JobId} correspond une et une seule soumission d'un objet -@emph{Job}. Ainsi un meme objet @emph{Job} peut etre soumis plusieurs -fois de suite a un ou plusieurs gestionnaires de batch et produira -autant d'objets @emph{JobId}. - -L'objet @emph{JobId} assure le controle et la gestion du job au travers -du gestionnaire de batch. Chaque objet @emph{JobId} est associe a un -gestionnaire particulier aupres duquel il relaie les actions qu'on lui -soumet. - - -@itemize @bullet{} -@item Entete - -@example -class JobId -@{ - friend class BatchManager; - - public: - // Constructeur standard et destructeur - JobId(); - virtual ~JobId(); - - // Constructeur avec le pointeur sur le BatchManager associe - // et avec une reference - JobId(BatchManager *, string ref); - - // Operateur d'affectation entre objets - virtual JobId & operator =(const JobId &); - - // Constructeur par recopie - JobId(const JobId &); - - // Accesseur pour la reference interne - virtual string getReference() const; - - // Methodes pour le controle du job - // retire un job du gestionnaire - virtual void deleteJob() const; - - // suspend un job en file d'attente - virtual void holdJob() const; - - // relache un job suspendu - virtual void releaseJob() const; - - // modifie un job en file d'attente - virtual void alterJob(const Parametre & param, - const Environnement & env) const; - virtual void alterJob(const Parametre & param) const; - virtual void alterJob(const Environnement & env) const; - - // modifie un job en file d'attente - virtual void setParametre(const Parametre & param); - virtual void setEnvironnement(const Environnement & env); - - // renvoie l'etat du job - virtual Batch::JobInfo queryJob() const; - - // Methodes pour l'interfacage avec Python (SWIG) - string __str__() const; // SWIG : affichage en Python - string __repr__() const; // SWIG : affichage en Python - - protected: - BatchManager * _p_batchmanager; // pointeur sur le BatchManager - // qui controle le job - string _reference; // reference du job au sein du BatchManager - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} (ici on cree un BatchManager bm et un Job job) - -// On soumet le job et on recupere un identifiant -JobId jobid = bm.submitJob(job); - -// Ce qui permet d'interroger l'etat du job en cours -JobInfo jinfo = jobid.queryJob(); - -@dots{} -@end example - -@item Methodes - -@itemize @minus{} -@item -@b{JobId()@* -JobId(BatchManager *, string ref)} - -Le constructeur par defaut cree un @emph{JobId} qui devra etre complete -par la suite. Ceci n'est pas directement realisable par l'utilisateur -mais sert pour certaines classes amies de la classe @emph{JobId}. - -D'un point de vue utilisateur la construction d'un objet @emph{JobId} -necessite un pointeur sur un gestionnaire de batch existant et une -chaine de caractere representant une reference au sein de ce -gestionnaire de batch. - -Ces parametres sont en general issus de la -communication avec l'API du gestionnaire de batch et ne peuvent etre -aisement deduits. C'est pourquoi il est recommande de passer par une -classe d'implementation pour fabriquer un objet @emph{JobId}. - - -@item -@b{~JobId()} - -Le destructeur libere l'espace occupe par l'objet. - -@item -@b{JobId & operator =(const JobId &)} - -L'affectation d'un objet @emph{JobId} duplique les donnees internes de -l'objet passe en argument. Les deux objets sont totalement independants -a l'issue de l'affectation et designent chacun la meme instance du job -dans le meme gestionnaire de batch. Le controle du job peut etre realise -avec l'un ou l'autre des objets. - -@item -@b{JobId(const JobId &)} - -De meme que l'affectation le constructeur par recopie produit un objet -@emph{JobId} totalement independant de l'objet passe en argument et qui -designe le meme job dans le meme gestionnaire de batch. Le controle du -job peut etre realise avec l'un ou l'autre des objets. - -@item -@b{string getReference() const} - -Cet accesseur retourne la reference du job pour le gestionnaire de batch -qui a produit l'objet. - -@item -@b{void deleteJob() const} - -Cette methode relaie aupres au gestionnaire de batch qui a produit -l'objet la demande d'arret du job. - -@item -@b{void holdJob() const} - -Cette methode relaie aupres au gestionnaire de batch qui a produit -l'objet la demande de suspension du job. - -@item -@b{void releaseJob() const} - -Cette methode relaie aupres au gestionnaire de batch qui a produit -l'objet la demande de liberation du job. - -@item -@b{void alterJob(const Parametre & param, const Environnement & env) const@* -void alterJob(const Parametre & param) const@* -void alterJob(const Environnement & env) const} - -Ces methodes relaient aupres du gestionnaire de batch qui a produit -l'objet la demande de modification des parametres et/ou des variables -d'environnement du job. - -@item -@b{void setParametre(const Parametre & param)} - -Cette methode n'est utile que pour l'interfacage avec Python, car Python -ne sait pas gerer la surcharge de methode, et de fait leve des -exceptions lors d'appels a de telles methodes. - -Elle est equivalente a la methode @samp{void alterJob(const Parametre & param) const}. - - -@item -@b{void setEnvironnement(const Environnement & env)} - -Cette methode n'est utile que pour l'interfacage avec Python, car Python -ne sait pas gerer la surcharge de methode, et de fait leve des -exceptions lors d'appels a de telles methodes. - -Elle est equivalente a la methode @samp{void alterJob(const Environnement & env) const}. - -@item -@b{Batch::JobInfo queryJob() const} - -Cette methode relaie aupres du gestionnaire de batch qui a produit -l'objet la demande d'interrogation de l'etat du job. - -@item -@b{string __str__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobId}. - -@item -@b{string __repr__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobId}. - -@end itemize -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe JobInfo, Classe Parametre, Classe JobId, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection JobInfo -@findex JobInfo - -Un objet de classe @emph{JobInfo} represente l'ensemble des informations -disponibles sur un travail actif, c'est-a-dire soumis au gestionnaire de -batch, a un instant donne. - -Cet objet reprend des informations issues du job tel qu'il a ete soumis, -@xref{Classe Job}, mais aussi des informations produites par le -gestionnaire de batch a partir de la soumission et du transit du job en -son sein : nom de la queue dans laquelle le job est inscrit, duree -d'execution, date de soumission, etc. - -Ces informations sont disponibles aupres de l'utilisateur de la classe a -travers les objets @emph{Parametre} et @emph{Environnement} que l'objet -@emph{JobInfo} peut fournir. - -@itemize @bullet{} -@item Entete - -@example -class JobInfo -@{ - public: - // Constructeur standard et destructeur - JobInfo(); - virtual ~JobInfo(); - - // Constructeur par recopie - JobInfo(const JobInfo & jinfo); - - // Operateur pour l'affichage sur un stream - friend ostream & operator <<(ostream & os, const JobInfo & ji); - - // Accesseurs - virtual Parametre getParametre() const; - virtual Environnement getEnvironnement() const; - - // Methodes pour l'interfacage avec Python (SWIG) - string __str__() const; // SWIG : affichage en Python - string __repr__() const; // SWIG : affichage en Python - - protected: - Parametre _param; // parametres du job - Environnement _env; // variables d'environnement du job - - private: -@}; -@end example - - -@item Exemple -@example -@dots{} (ici on cree un BatchManager bm et un Job job) - -// On soumet le job et on recupere un identifiant -JobId jobid = bm.submitJob(job); - -// Ce qui permet d'interroger l'etat du job en cours -JobInfo jinfo = jobid.queryJob(); - -// On recupere l'objet Parametre interne modifie -// par le gestionnaire de batch -Parametre param = jinfo.getParametre(); - -// On recupere l'objet Environnement interne modifie -// par le gestionnaire de batch -Environnement env = jinfo.getEnvironnement(); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{JobInfo()} - -Ce constructeur cree un objet @emph{JobInfo} vide. - -@item -@b{~JobInfo()} - -Le destructeur libere l'espace memoire alloue par l'objet. - -@item -@b{JobInfo(const JobInfo & jinfo)} - -Le constructeur par recopie produit un objet identique a celui passe en -argument. Les deux objets sont totalement independants l'un de l'autre. - -@item -@b{ostream & operator <<(ostream & os, const JobInfo & ji)} - -Cet operateur permet de voir le contenu de l'objet sur un flot de sortie. - -@item -@b{Parametre getParametre() const} - -Cet accesseur retourne l'objet interne @emph{Parametre} modifie par le -gestionnaire de batch. En particulier on y retrouve toutes les clefs et -les valeurs correspondant aux informations produites dynamiquement par -le gestionnaire (duree d'execution, machine d'execution, etc.). -Il n'est pas garanti que les valeurs passees au moment de la soumission -soient inchangees car des modifications ont pu etre apportees a ces -valeurs pendant le traitement du job par le gestionnaire. - -@item -@b{Environnement getEnvironnement() const} - -Cet accesseur retourne l'objet interne @emph{Environnement} modifie par le -gestionnaire de batch. En particulier on y retrouve toutes les clefs et -les valeurs correspondant aux informations produites dynamiquement par -le gestionnaire (chemin d'acces, variables d'environnement specifiques a -la machine d'execution, etc.). -Il n'est pas garanti que les valeurs passees au moment de la soumission -soient inchangees car des modifications ont pu etre apportees a ces -valeurs pendant le traitement du job par le gestionnaire. - -@item -@b{string __str__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobInfo}. - -@item -@b{string __repr__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobInfo}. - -@end itemize - -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Parametre, Classe Versatile, Classe JobInfo, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection Parametre -@findex Parametre - -Les objets de la classe @emph{Parametre} se comportent comme des maps -STL, dont ils ont les fonctionnalites, decrivant les parametres -d'execution du job. - -Contrairement aux variables d'environnement qui sont decrites par les -objets de la classe @emph{Environnement}, les parametres d'execution -servent a preciser les contraintes qui pesent sur le job, comme par -exemple la duree maximale d'execution autorisee, la quantite maximale de -memoire utilisable ou la queue de soumission, ou bien a renseigner le -job avec des informations specifiques a l'utilisateur, comme son -username, son adresse email, le code d'imputation du job, etc. - -En raison du caractere tres specifique et precis des informations qui -doivent etre fournies au gestionnaire de batch, une nomenclature est -proposee par la classe @emph{Parametre} qu'il est vivement conseille de -suivre. De plus tout a ete fait pour rendre cette ecriture naturelle et -facile, donc il ne devrait pas y avoir de probleme pour l'utiliser. - -Ainsi, a titre d'exemple, pour preciser le temps maximal autorise pour -un job, il faut creer une clef de nom @var{maxcputime} dans un objet de -classe @emph{Parametre} qui sera ensuite passe au job. Et pour preciser -le code d'imputation du job, il faut creer une clef de nom @var{account}. - -Mais cet exemple simple montre que la valeur associee a la clef -@var{maxcputime} est semantiquement une duree, et que la valeur associee a -la clef @var{account} est semantiquement un nom. On a donc un probleme de -type puisque dans la definition d'une map STL le type de la valeur doit -etre le meme, et ce meme si les valeurs doivent par la suite avoir des -types semantiques differents. C'est pourquoi on a definit une classe -@emph{Versatile} qui encapsule des types differents. @xref{Classe -Versatile}. - -Quoiqu'il en soit toute la mecanique est cachee et seul importe pour -l'utilisateur de savoir que les valeurs associees aux clefs sont typees -et que ces types sont definis dans l'enumeration @emph{DiscriminatorType}. -@xref{Classe Versatile}. - - -@itemize @bullet{} -@item Entete - -@example -class Parametre : public map< string, Versatile > -@{ - public: - // Constructeur standard - Parametre(); - - // Constructeur par recopie - Parametre(const Parametre & PM); - - // Operateur de recherche dans la map - Versatile & operator [] (const string &); - const Versatile & operator [] (const string &) const; - - // Operateur d'affectation - Parametre & operator =(const Parametre & PM); - - // Declarations statique des clefs de la map - static const string ACCOUNT; - static const string CHECKPOINT; - static const string CKPTINTERVAL; - static const string CREATIONTIME; - static const string EGROUP; - static const string ELIGIBLETIME; - static const string EUSER; - static const string EXECUTABLE; - static const string EXECUTIONHOST; - static const string HOLD; - static const string ID; - static const string INFILE; - static const string MAIL; - static const string MAXCPUTIME; - static const string MAXDISKSIZE; - static const string MAXRAMSIZE; - static const string MAXWALLTIME; - static const string MODIFICATIONTIME; - static const string NAME; - static const string OUTFILE; - static const string PID; - static const string QUEUE; - static const string QUEUEDTIME; - static const string SERVER; - static const string STARTDATE; - static const string STATE; - static const string TEXT; - static const string TMPDIR; - static const string USEDCPUTIME; - static const string USEDDISKSIZE; - static const string USEDRAMSIZE; - static const string USEDWALLTIME; - static const string USER; - - protected: - // map interne servant a controler le type - // de la valeur associee a chaque clef - map< string, TypeParam > TypeMap; - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} - -Parametre param; - -param[EXECUTABLE] = "/home/user/mon_application/executable"; -param[NAME] = "MonJob"; -param[ACCOUNT] = "MonProjet"; // code d'imputation/facturation -param[MAXCPUTIME] = 360L; // 6min -param[MAXWALLTIME] = 480L; // 8min -param[INFILE] = Couple("/tmp/infich1", rempath + "/infich1"); -param[OUTFILE] = Couple("/tmp/outfich1", rempath + "/outfich1"); -param[OUTFILE] += Couple("stderr", path + "/STDERR"); -param[OUTFILE] += Couple("stdout", path + "/STDOUT"); -param[MAIL] = "user@@domaine.fr"; -param[USER] = "user"; - -@dots{} -@end example - -@item Methodes -@itemize @minus{} - -@item -@b{Parametre()} - -Le constructeur par defaut initialise l'objet @emph{Parametre} et cree -la table des types internes. Par contre l'objet ne contient aucune valeur. - -@item -@b{Parametre(const Parametre & PM)} - -Le constructeur par recopie cree un objet @emph{Parametre} a l'image de -celui qui lui est passe en argument. La table des types internes est -dupliquee ainsi que tous les objets correspondant a chacune des clefs. - -@item -@b{Versatile & operator [] (const string &)} - -Cet operateur permet de recuperer la valeur designee par la clef passee -en argument. Cette valeur est de classe @emph{Versatile} qui encapsule -tous les types de base utilisables dans la bibliotheque en tant que -parametre. @xref{Classe Versatile}. - - -@item -@b{const Versatile & operator [] (const string &) const} - -A l'image de l'operateur precedent, cet operateur permet de recuperer la -valeur designee par la clef passee en argument mais uniquement pour des -objets constants. - -@item -@b{Parametre & operator =(const Parametre & PM)} - -L'operateur d'affectation remplace l'ensemble du contenu de l'objet -@emph{Parametre} par le contenu de l'objet passe en argument. Les -valeurs sont dupliquees par rapport a l'objet @var{pm}. - -@end itemize - -@item Description des clefs - -Selon les gestionnaires de batch utilises, certaines clefs sont actives -ou inactives. Une definition superflue ne pose pas de probleme et se -trouve ignoree au moment de la soumission. Par contre l'absence d'un -clef peut empecher la soumission d'aboutir et lever une exception. - -@itemize @minus{} -@item ACCOUNT : type STRING - -Le code de facturation sur lequel le job doit s'imputer. - -@item CHECKPOINT : type LONG - -Une valeur non nulle indique au gestionnaire de batch que le job est -@dfn{checkpointable}, c'est-a-dire interruptible pour une reprise -ulterieure. - -@item CKPTINTERVAL : type LONG - -En liaison avec la clef @var{CHECKPOINT}, la clef @var{CKPTINTERVAL} -indique l'intervalle en secondes entre deux interruptions du code -(@dfn{checkpoint}). - -@item CREATIONTIME : type LONG - -La date a laquelle le job a ete cree (soumis) dans le gestionnaire de batch. - -@item EGROUP : type STRING - -Le groupe effectif au sens Unix du terme dans lequel le job s'execute. - -@item ELIGIBLETIME : type LONG - -La date a laquelle le job a pu disposer des ressources necessaires a son -execution. - -@item EUSER : type STRING - -L'utilisateur effectif au sens Unix du terme pour lequel le job s'execute. - -@item EXECUTABLE : type STRING - -Le chemin d'acces absolu a l'executable sur la machine qui soumet le job. - -@item EXECUTIONHOST : type STRING - -Le nom de la machine qui execute le job. - -@item HOLD : type LONG - -Une valeur non nulle indique au gestionnaire de batch que le job doit -etre place dans l'etat suspendu. Une valeur nulle libere le job. - -@item ID : type STRING - -L'identifiant unique du job pour le gestionnaire de batch. - -@item INFILE : type liste de COUPLE - -La clef @var{infile} liste les fichiers qui seront envoyes au job avant -son execution. Chaque fichier peut avoir un nom different sur la machine -cliente --- qui soumet le job --- et sur le serveur. C'est pourquoi -chaque fichier a envoyer est represente par un couple dont le nom @var{local} -est le chemin absolu du fichier sur la machine cliente et le nom -@var{remote} est le chemin absolu du fichier sur le -serveur. @xref{Classe Couple}. - -Si le nom @var{remote} vaut @samp{stdin}, alors le contenu du fichier -designe par le nom @var{local} est envoye sur l'entree standard du job -au moment de son execution. - -@item MAIL : type STRING - -L'adresse email de l'utilisateur ou lui seront envoyes les eventuels -messages d'information et d'alerte du gestionnaire de batch. - -@item MAXCPUTIME : type LONG - -Le temps de calcul (@i{CPU time}) en secondes que ne devra pas depasser le job. - -@item MAXDISKSIZE : type LONG - -L'espace disque en octets que ne devra pas depasser le job. - -@item MAXRAMSIZE : type LONG - -La quantite de memoire vive en octets que ne devra pas depasser le job. - -@item MAXWALLTIME : type LONG - -Le temps reel (@i{elapsed time}) en secondes que ne devra pas depasser le job. - -@item MODIFICATIONTIME : type LONG - -La date a laquelle le job a ete modifie pour la derniere fois dans le -gestionnaire de batch. Cette date correspond le plus souvent a la -derniere operation realisee par le gestionnaire dans la gestion du job : -routage au sein des files, suspension ou reprise, etc. - -@item NAME : type STRING - -Le nom du job tel qu'il apparait a l'utilisateur dans son dialogue avec -le gestionnaire de batch. Ce nom n'a pas besoin d'etre unique et ne -remplace pas l'identifiant (ID). Il n'est la que pour informer -l'utilisateur de la nature de son job. - -@item OUTFILE : type liste de COUPLE - -La clef @var{outfile} liste les fichiers qui sont produits par le job et -qui seront recuperes sur la machine locale de l'utilisateur apres -son execution. Chaque fichier peut avoir un nom different sur la machine -cliente --- qui soumet le job --- et sur le serveur. C'est pourquoi -chaque fichier a recuperer est represente par un couple dont le nom @var{local} -est le chemin absolu du fichier sur la machine cliente et le nom -@var{remote} est le chemin absolu du fichier sur le -serveur. @xref{Classe Couple}. - -Si le nom @var{local} vaut @samp{stdout}, alors le contenu du fichier -designe par le nom @var{local} contient la sortie standard du job -au moment de son execution. - -Si le nom @var{local} vaut @samp{stderr}, alors le contenu du fichier -designe par le nom @var{local} contient la sortie d'erreur du job -au moment de son execution. - -@item PID : type LONG - -La valeur du PID (@i{process identifier}) du job sur la machine sur -lqsuelle il s'execute. - -@item QUEUE : type STRING - -Le nom de la queue, aussi appelee classe ou file suivant les -terminologies, qui accueille le job. - -@item QUEUEDTIME : type LONG - -La date depuis laquelle le job a ete place en queue dans le gestionnaire -de batch. - -@item SERVER : type STRING - -Le nom complet du serveur qui recoit les soumissions de job. - -@item STARTDATE : type LONG - -La date a partir de laquelle l'utilisateur desire que le job soit -execute. L'execution ne demarrera qu'au dela de cette date et a -condition que toutes les conditions de ressources soient remplies. - -@item STATE : type STRING - -L'etat actuel du job. - -ATTENTION : Ces valeurs ne sont pas encore normalisees. - -@item TEXT : type STRING - -Un texte d'information que le gestionnaire peut emettre a destination de -l'utilisateur lorsque l'ensemble des parametres n'est pas suffisant pour -traduire l'etat reel du job. Par exemple, ce message peut informer -l'utilisateur de la raison qui maintient un job dans un etat suspendu ou -qui l'empeche de s'executer. - -@item TMPDIR : type STRING - -Un chemin d'acces absolu a un repertoire qui sera cree au demarrage du -job et qui isolera le job des autres travaux en cours d'execution sur la -meme machine. - -@item USEDCPUTIME : type LONG - -Le temps de calcul (@i{CPU time}) en secondes reellement consomme par le job. - -@item USEDDISKSIZE : type LONG - -L'espace disque en octets reellement consomme par le job. - -@item USEDRAMSIZE : type LONG - -L'espace disque en octets reellement consommee par le job. - -@item USEDWALLTIME : type LONG - -Le temps reel (@i{elapsed time}) en secondes reellement consomme par le job. - -@item USER : type STRING - -Le nom de l'utilisateur (@i{username}) sous lequel le job devra tourner -sur la machine d'execution. Ce parametre est utile lorsque l'utilisateur -possede des comptes differents sur les machines sur lequel il soumet et calcule. - -@end itemize - - -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe Versatile, Exceptions, Classe Parametre, Classes utilisateur -@comment node-name, next, previous, up -@page -@subsubsection Versatile -@findex Versatile - -Cette classe est normalement invisible en tant que telle a l'utilsateur -de la bibliotheque de classes Batch. Mais il est tout de meme utile de -la presenter car son action est visible, notamment dans son interaction -fine avec la classe @emph{Parametre}. @xref{Classe Parametre}. - -Comme il a ete precise dans la descrption de la classe @emph{Parametre}, -la classe @emph{Versatile} a ete concue pour encapsuler les valeurs de -la map @emph{Parametre} qui peuvent etre de types effectifs differents. - -Ces types, decrits par l'enumeration @emph{DiscriminatorType}, sont -actuellement au nombre de trois : @var{long}, @var{string} et -@var{couple}. Ces types correpondent au types de base du langage C++ ou -de la biliotheque de classes Batch. @xref{Types de base}. - -Le type special @var{undefined} ne sert que pour l'objet -@emph{Versatile} juste cree mais non encore affecte d'une valeur et donc -d'un type. La premiere affection d'une valeur a un objet -@emph{Versatile} non encore affecte lui donne automatiquement le type de -la valeur. - -Les objets de classe @emph{Versatile} peuvent se comporter soit comme -des variables scalaires, c'est-a-dire ne contenant qu'une valeur unique, -soit comme des listes, auquel cas elles utilisent l'interface des -@emph{list} de la STL. Toutefois afin de faciliter l'ecriture pour -l'utilisateur basique de la classe @emph{Versatile} --- et de la classe -@emph{Parametre} ---, des operateurs de concatenation @samp{+=} et -@samp{,} ont ete ajoutes. - - -@itemize @bullet{} -@item Entete - -@example -// Les types autorises -enum DiscriminatorType @{ UNDEFINED, LONG, STRING, COUPLE @}; - -typedef struct @{ - DiscriminatorType type; // le type de l'element interne - int maxelem; // le nombre d'elements autorises -@} TypeParam; - -class Versatile : public list< GenericType * > -@{ - public: - // Constructeur standard et destructeur - Versatile(); - virtual ~Versatile(); - - // Constructeur par recopie - Versatile(const Versatile & V); - - // Constructeur depuis le type de "base" - Versatile(long l); - Versatile(const string & s); - Versatile(const Couple & c); - - // Operateur d'affectation et de concatenation - // a partir d'un type de "base" - Versatile & operator = (const long l) - throw(TypeMismatchException); - Versatile & operator = (const string & ch) - throw(TypeMismatchException); - Versatile & operator +=(const string & ch) - throw(TypeMismatchException,ListIsFullException); - Versatile & operator , (const string & ch) - throw(TypeMismatchException,ListIsFullException); - Versatile & operator = (const Couple & cp) - throw(TypeMismatchException); - Versatile & operator +=(const Couple & cp) - throw(TypeMismatchException,ListIsFullException); - Versatile & operator , (const Couple & cp) - throw(TypeMismatchException,ListIsFullException); - - // Operateur d'affectation entre objets - Versatile & operator = (const Versatile & V) - throw(TypeMismatchException); - - // Conversion de type vers un type de "base" - operator long() const throw(TypeMismatchException); - operator string() const throw(TypeMismatchException); - operator Couple() const throw(TypeMismatchException); - string str() const throw(TypeMismatchException); - - // Operateur pour l'affichage sur un stream - friend ostream & operator << (ostream & os, const Versatile & ); - - // Positionnement et recuperation du type de l'element interne - void setType(DiscriminatorType) throw(TypeMismatchException); - DiscriminatorType getType() const; - - // Positionnement et recuperation du nombre d'elements internes - void setMaxSize(int i); - int getMaxSize() const; - - // Positionnement et recuperation du nom de l'objet - string getName() const; - void setName(const string & name); - - protected: - // Efface tous les elements internes de l'objet - virtual void eraseAll(); - - DiscriminatorType _discriminator; // type de l'element interne - int _maxsize; // nombre max d'elements internes - string _name; // nom de l'objet (sert pour les exceptions) - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} - -// On cree un objet Versatile non encore affecte (scalaire) -Versatile Vlong; - -// L'affectation d'un long lui donne le type LONG -Vlong = 1024L * 1024L * 1024L; -cout << "Versatile long (must be 1073741824) : " << Vlong << endl; - -// On cree un objet Versatile non encore affecte (scalaire) -Versatile Vstring; - -// L'affectation d'une string (const char * promu en string) -// lui donne le type STRING -Vstring = "UneChaine"; -cout << "Versatile string (must be UneChaine) : " << Vstring << endl; - -try - @{ - // L'affectation d'un autre type leve une exception. - // Il n'y a pas de retypage dynamique. - Vlong = ""; - cout << "ERR : No TypeMismatchException catched for Versatile long" - << endl; - @} -catch (TypeMismatchException & ex) - @{ - cout << "OK : TypeMismatchException catched for Versatile long" - << endl; - @} - -// Reaffectation avec le meme type -Vlong = 1024L * 1024L; -cout << "Versatile long (must be 1048576) : " << Vlong << endl; - -// On cree un objet Versatile non encore affecte (scalaire) ... -Versatile Vcat1; - -// ... que l'on transforme en liste (non limitee) -Vcat1.setMaxSize(0); - -// On affecte la premiere valeur ... -Vcat1 = "A"; - -// ... puis les suivantes par concatenation -Vcat1 += "B"; -Vcat1 += "C"; -Vcat1 += "D"; -Vcat1 += "E"; -cout << "Versatile string concatenation (must be A B C D E) : " - << Vcat1 << endl; - -// Idem que pour Vcat1, mais avec une limite a 5 elements dans la liste -Versatile Vcat2; -Vcat2.setMaxSize(5); -Vcat2 = "a", "b", "c", "d", "e"; -cout << "Versatile string concatenation (must be a b c d e) : " - << Vcat2 << endl; - -// On tronque les 2 derniers elements de la liste (il en reste 3) -Vcat2.setMaxSize(3); -cout << "Versatile string concatenation (must be a b c) : " - << Vcat2 << endl; - - -Versatile Vcopy2(Vcat2); -cout << "Versatile copy (must be a b c) : " << Vcopy2 << endl; - -Versatile Vaffect; -Vaffect = Vcat1; -cout << "Versatile affect (must be A B C D E) : " << Vaffect << endl; -Vaffect = Vcat2; -cout << "Versatile affect (must be a b c) : " << Vaffect << endl; - -try - @{ - // Retypage dynamique interdit - Vaffect = Vlong; - cout << "ERR : No TypeMismatchException catched for Versatile" - << endl; - @} -catch (TypeMismatchException & ex) - @{ - cout << "OK : TypeMismatchException catched for Versatile string" - << endl; - @} - -try - @{ - // Concatenation au dela de la limite interdit - Vcat2 += "En trop"; - cout << "ERR : No ListIsFullException catched for Versatile string" - << endl; - @} -catch (ListIsFullException & ex) - @{ - cout << "OK : ListIsFullException catched for Versatile string" - << endl; - @} - -// Les objets Versatile se comportent (presque) comme des objets -// standards du langage -long L = Vlong; -cout << "Long value of Versatile long (must be 1048576) : " - << L << endl; - -string S = Vstring; -cout << "String value of Versatile (must be EncoreUneAutreChaine):" - << S << endl; - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{Versatile()} - -Le constructeur par defaut fabrique un objet scalaire de type -@var{undefined} et de nom @samp{undefined}. - -@item -@b{~Versatile()} - -Le destructeur efface tout le contenu de l'objet si celui-ci avait ete affecte. - -@item -@b{Versatile(const Versatile & V)} - -Le constructeur par recopie duplique l'objet passe en argument ainsi que -les valeurs qu'il contient. Le nouvel objet est totalement independant -de son geniteur. - -@item -@b{Versatile(long l)@* -Versatile(const string & s)@* -Versatile(const Couple & c)} - -Ces constructeurs fabriquent des objets scalaires @emph{Versatile} a partir des -types de base passes en argument. Chaque objet acquerera definitivement -le type correspondant au type de base : @var{long} pour @samp{long}, -@var{string} pour @samp{string} et @var{couple} pour @samp{Couple}. - -@item -@b{Versatile & operator = (const long l) throw(TypeMismatchException)@* -Versatile & operator = (const string & ch) throw(TypeMismatchException)@* -Versatile & operator = (const Couple & cp) throw(TypeMismatchException)} - -Ces operateurs affectent ou reaffectent la valeur passee en argument a -l'objet. Le type de la valeur doit correspondre au type de l'objet si -celui-ci a deja ete affecte, sinon une exception @emph{TypeMismatchException} est -levee. @xref{Classe TypeMismatchException}. - -L'ancienne valeur de l'objet est perdue. - -@item -@b{Versatile & operator += (const string & ch) - throw(TypeMismatchException, ListIsFullException)@* -Versatile & operator , (const string & ch) - throw(TypeMismatchException, ListIsFullException)@* -Versatile & operator += (const Couple & cp) - throw(TypeMismatchException, ListIsFullException)@* -Versatile & operator , (const Couple & cp) - throw(TypeMismatchException, ListIsFullException)} - -Ces operateurs concatenent la valeur passee en argument a l'objet. Le -type de la valeur doit correspondre au type interne de l'objet si -celui-ci a deja ete affecte, sinon une exception @emph{TypeMismatchException} est -levee. @xref{Classe TypeMismatchException}. - -Si la taille maximale de la liste est depasse, une exception @emph{ListIsFullException} est -levee. @xref{Classe ListIsFullException}. - -@item -@b{Versatile & operator = (const Versatile & V) throw(TypeMismatchException)} - -L'operateur d'affectation duplique l'objet passe en argument dans -l'objet. Toutes les valeurs internes sont dupliquees de maniere a avoir -une independance totale entre les deux objets a l'issue de -l'affectation. - -Il est a noter qu'il est possible d'affecter a un objet un objet -possedant un type different, auquel cas l'objet courant change de type -pour acquerir celui de l'objet passe en argument. C'est le seul cas de -changement de type autorise pour un objet. - -@item -@b{operator long() const throw(TypeMismatchException)@* -operator string() const throw(TypeMismatchException)@* -operator Couple() const throw(TypeMismatchException)@* -string str() const throw(TypeMismatchException)} - -Ces operateur de conversion dans les types de base permettent de -recuperer la valeur interne de l'objet. Lorsque le type interne est -incompatible avec la conversion une exception @emph{TypeMismatchException} est -levee. @xref{Classe TypeMismatchException}. - -@item -@b{ostream & operator << (ostream & os, const Versatile & )} - -Cet operateur permet de voir le contenu de l'objet sur un flot de sortie. - -@item -@b{void setType(DiscriminatorType) throw(TypeMismatchException)} - -Cette methode change le type interne de l'objet en celui passe en -argument. Ceci n'est possible que pour un objet non encore affecte. Si -le nouveau type est different du type actuel une exception @emph{TypeMismatchException} est -levee. @xref{Classe TypeMismatchException}. - -@item -@b{DiscriminatorType getType() const} - -Cet accesseur renvoie le type interne de l'objet. - -@item -@b{void setMaxSize(int i)} - -Cette methode permet de changer le nombre d'elements que l'objet est -capable de stocker. Par defaut ce nombre est 1 a la construction de -l'objet, signifiant qu'il ne peut contenir qu'une seule valeur a la fois -(scalaire). - -Si ce nombre est superieur a 1 alors il represente une -limite qui ne pourra etre depassee par l'objet sans lever d'exception -@emph{ListIsFullException}. @xref{Classe ListIsFullException}. - -Si ce nombre vaut 0 (zero) alors il n'y a aucune limite superieure au -nombre d'element dans l'objet. - -@item -@b{int getMaxSize() const} - -Cet accesseur renvoie la taille maximale admise par l'objet. - -@item -@b{void setName(const string & name)} - -Cette methode permet de positionner le nom de l'objet. Par defaut ce nom -vaut @samp{undefined} a la construction de l'objet. - -Il est interessant de positionner le nom a une valeur significative -comme par exemple le nom de la variable contenant l'objet car lorsqu'une -exception est levee ce nom apparait en clair et aide au debugging. - -@item -@b{string getName() const} - -Cet accesseur renvoie le nom interne de l'objet. - -@end itemize - -@end itemize - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Exceptions, Classe APIInternalFailureException, Classe Versatile, Classes generiques -@comment node-name, next, previous, up -@page -@subsection Exceptions -@cindex exceptions - -La bibliotheque de classes Batch definit un certain nombre d'exceptions -qui sont levees par les classes lors d'evenements qui traduisent un -comportement anormal de la bibliotheque. - -@menu -* Classe APIInternalFailureException:: Erreur d'utilisation de l'API. -* Classe ConnexionFailureException:: Probleme de connexion de l'API. -* Classe GenericException:: Classe-mere de toutes les exceptions. -* Classe InvalidArgumentException:: Parametre errone d'une methode. -* Classe InvalidKeyException:: Clef erronee d'une map. -* Classe ListIsFullException:: Debordement de taille d'une liste. -* Classe NotYetImplementedException:: Methodes non encore implementee. -* Classe RunTimeException:: Erreur d'execution imprevue. -* Classe TypeMismatchException:: Probleme de conversion de type. -@end menu - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe APIInternalFailureException, Classe ConnexionFailureException, Exceptions, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection APIInternalFailureException -@findex APIInternalFailureException - -Cette exception est levee par les classes d'implementation de la -bibliotheque lorsqu'une erreur est detectee au moment de la -communication avec l'API du gestionnaire de batch. En general l'erreur -renvoyee par l'API est incluse dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class APIInternalFailureException : public GenericException -@{ - public: - // Constructeur - APIInternalFailureException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{APIInternalFailureException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{APIInternalFailureException}. - -@end itemize - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe ConnexionFailureException, Classe GenericException, Classe APIInternalFailureException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection ConnexionFailureException -@findex ConnexionFailureException - -Cette exception est levee par les classes d'implementation de la -bibliotheque lorsqu'une erreur est detectee au moment de la -connexion au gestionnaire de batch. En general l'erreur -renvoyee par l'API de connexion est incluse dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class ConnexionFailureException : public GenericException -@{ - public: - // Constructeur - ConnexionFailureException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{ConnexionFailureException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{ConnexionFailureException}. - -@end itemize - -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe GenericException, Classe InvalidArgumentException, Classe ConnexionFailureException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection GenericException -@findex GenericException - -Cette classe est generique comme son nom l'indique et definit une -interface commune pour toutes les exceptions de la -bibliotheque. - -Cette exception definit uniquement un constructeur et deux membres -publics constants : @emph{type} et @emph{message}. @xref{Classe -GenericException}. - - -@itemize @bullet{} -@item Entete - -@example -class GenericException -@{ - public: - const string type; // la nature de l'exception - const string message; // la raison de l'exception - - // Constructeur - GenericException(const string tp = "GenericException", - const string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{GenericException(const string tp = "GenericException", const string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le parametre -@emph{tp} qui contient generalement le nom de la classe. - -@end itemize - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe InvalidArgumentException, Classe InvalidKeyException, Classe GenericException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection InvalidArgumentException -@findex InvalidArgumentException - -Cette exception est levee par les classes de la bibliotheque lorsqu'un -parametre erronne est passe en argument a une methode. En general -le nom de l'arguement erronne est inclus dans le message de -l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class InvalidArgumentException : public GenericException -@{ - public: - // Constructeur - InvalidArgumentException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{InvalidArgumentException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{InvalidArgumentException}. - -@end itemize - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe InvalidKeyException, Classe ListIsFullException, Classe InvalidArgumentException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection InvalidKeyException -@findex InvalidKeyException - - -Cette exception est levee par les methodes de la classe @emph{Parametre} -lorsqu'une clef erronnee est utilisee. En general le nom de la clef -erronnee est inclus dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class InvalidKeyException : public GenericException -@{ - public: - // Constructeur - InvalidKeyException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{InvalidKeyException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{InvalidKeyException}. - -@end itemize - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe ListIsFullException, Classe NotYetImplementedException, Classe InvalidKeyException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection ListIsFullException -@findex ListIsFullException - -Cette exception est levee par les methodes de la classe @emph{Versatile} -lorsque la taille maximale de la liste interne est depasse. En general -le nom de l'objet en erreur est inclus dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class ListIsFullException : public GenericException -@{ - public: - // Constructeur - ListIsFullException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{ListIsFullException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{ListIsFullException}. - -@end itemize - -@end itemize - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe NotYetImplementedException, Classe RunTimeException, Classe ListIsFullException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection NotYetImplementedException -@findex NotYetImplementedException - -Cette exception est levee par les classes de la bibliotheque lorsqu'une -methode declaree mais non encore implementee est utilisee. En general -le nom de l'objet en erreur est inclus dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class NotYetImplementedException : public GenericException -@{ - public: - // Constructeur - NotYetImplementedException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{NotYetImplementedException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{NotYetImplementedException}. - -@end itemize - -@end itemize - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe RunTimeException, Classe TypeMismatchException, Classe NotYetImplementedException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection RunTimeException -@findex RunTimeException - -Cette exception est levee par les classes de la bibliotheque lorsqu'une -erreur inconnue et imprevue apparait. Cette exception est le -comportement par defaut que doit gerer le gestionnaire d'exception en ce -qui concerne les classes de la bibliotheque. En general le nom de -l'objet en erreur est inclus dans le message de l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class RunTimeException : public GenericException -@{ - public: - // Constructeur - RunTimeException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{RunTimeException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{RunTimeException}. - -@end itemize - -@end itemize - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe TypeMismatchException, Classes specifiques, Classe RunTimeException, Exceptions -@comment node-name, next, previous, up -@page -@subsubsection TypeMismatchException -@findex TypeMismatchException - -Cette exception est levee par les methodes de la classe @emph{Versatile} -lorsque qu'une erreur de type est rencontree dans un objet. Ce genre -d'erreur survient lorsqu'on essaie d'affecter une valeur d'un type -different du type interne de l'objet @emph{Versatile} a ce meme objet, -ou bien lorsqu'on ajoute une valeur d'un type different a une liste. En -general le nom de l'objet en erreur est inclus dans le message de -l'exception. - -Cette exception herite de la classe @emph{GenericException} qui definit -uniquement un constructeur et deux membres publics constants : @emph{type} et -@emph{message}. @xref{Classe GenericException}. - -@itemize @bullet{} -@item Entete - -@example -class TypeMismatchException : public GenericException -@{ - public: - // Constructeur - TypeMismatchException(string msg = "undefined"); -@}; -@end example - - -@item Methodes -@itemize @minus{} -@item -@b{TypeMismatchException(string msg = "undefined")} - -Ce contructeur prend la chaine @emph{msg} comme message d'erreur a -renvoyer au gestionnaire d'exception. Cette valeur est stockee dans le -membre public constant @emph{message}. - -Le membre public constant @emph{type} est initialise avec le nom de la -classe, soit @emph{TypeMismatchException}. - -@end itemize - -@end itemize - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes specifiques, Classes PBS, Classe TypeMismatchException, Classes -@comment node-name, next, previous, up -@page -@section Classes specifiques -@cindex classes specifiques - -Afin de pouvoir se connecter aux gestionnaires de batch reels a travers -leurs API, les classes generiques ont ete derivees pour offrir une -implementation correspondant a l'interface qu'elles definissent. - -Pour traduire a la fois le fait que les nouvelles classes derivent d'une -classe generique et qu'elles sont une implementation d'une API -particuliere, on adopte la convention de nom suivante : la classe se -nomme comme sa classe generique mais est suffixee par le nom de l'API du -gestionnaire de batch, les deux termes etant separes par un caractere -@kbd{_} (souligne). - -Actuellement, seul le gestionnaire de batch OpenPBS, @xref{Prerequis}, est -supporte. Mais ce catalogue devrait s'enrichir par la suite. - -Les classes de la bibliotheque sont egalement accessibles a travers un -interpreteur Python, ce qui a necessite la creation de certaines classes -d'interface avec l'interpreteur. - -@menu -* Classes PBS:: Classes d'implementation pour OpenPBS -* Classes Python:: Classes d'interfacage avec Python. -@end menu - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes PBS, Classe FactBatchManager_PBS, Classes specifiques, Classes specifiques -@comment node-name, next, previous, up -@page -@subsection Classes PBS -@cindex classes PBS - -Actuellement seules les classes @emph{BatchManager}, @emph{JobInfo} et -@emph{Job} ont besoin d'etre derivees pour implementer la communication -et l'interfacage avec l'API du gestionnaire de batch OpenPBS. - - -@menu -* Classe FactBatchManager_PBS:: Description de la classe FactBatchManager_PBS. -* Classe BatchManager_PBS:: Description de la classe BatchManager_PBS. -* Classe JobInfo_PBS:: Description de la classe JobInfo_PBS. -* Classe Job_PBS:: Description de la classe Job_PBS. -@end menu - - -@node Classe FactBatchManager_PBS, Classe BatchManager_PBS, Classes PBS, Classes PBS -@comment node-name, next, previous, up -@subsubsection FactBatchManager_PBS -@cindex FactBatchManager_PBS - -Cette classe derive de la classe generique @emph{FactBatchManager}, -@xref{Classe FactBatchManager}. - -Les objets de la classe @emph{BatchManager_PBS} realisent l'interface de -la bibliotheque avec l'API du gestionnaire de batch OpenPBS. - -@itemize @bullet{} -@item Entete - -@example -class FactBatchManager_PBS : public FactBatchManager -@{ -public: - // Constructeur et destructeur - FactBatchManager_PBS(); - virtual ~FactBatchManager_PBS(); - - virtual BatchManager_PBS * operator() (const char * hostname) const; - -protected: - -private: - -@}; -@end example - -@item Exemple - -@example -@dots{} - -// On recupere l'instance du catalogue de gestionnaires de batch -Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - -// On cree une fabrique de BatchManager de type PBS -Batch::FactBatchManager & fbm = * cata("PBS"); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{FactBatchManager_PBS()} - -Ce constructeur instancie un objet de la classe -@emph{FactBatchManager_PBS} et l'enregistre automatiquement aupres du -catalogue de fabrique. @xref{Classe BatchManagerCatalog}. - -Le type est positionne a la valeur PBS. - -@item -@b{~FactBatchManager_PBS()} - -Le destructeur ne fait rien de particulier. - -@item -@b{BatchManager_PBS * operator() (const char * hostname) const} - -Cet operateur renvoie un objet nouvellement cree de type -@emph{BatchManager_PBS} derivant de @emph{BatchManager} et oeuvrant sur -la machine @emph{hostname}. La destruction de l'objet est a la charge de -l'appelant. - -@end itemize - -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classe BatchManager_PBS, Classe JobInfo_PBS, Classe FactBatchManager_PBS, Classes PBS -@comment node-name, next, previous, up -@page -@subsubsection BatchManager_PBS -@cindex BatchManager_PBS - -Cette classe derive de la classe generique @emph{BatchManager}, -@xref{Classe BatchManager}. - -Les objets de la classe @emph{BatchManager_PBS} realisent l'interface de -la bibliotheque avec l'API du gestionnaire de batch OpenPBS. - -@itemize @bullet{} -@item Entete - -@example -class BatchManager_PBS : public BatchManager -@{ - public: - // Constructeur et destructeur - BatchManager_PBS(FactBatchManager * parent, - const char * host) throw(InvalidArgumentException); - virtual ~BatchManager_PBS(); - - // Recupere le nom du serveur par defaut - static string getDefaultServer(); - - // Recupere le l'identifiant d'un job deja soumis au BatchManager - virtual const JobId getJobIdByReference(const string & ref); - - // Methodes pour le controle des jobs : virtuelles pures - // soumet un job au gestionnaire - virtual const JobId submitJob(const Job & job); - - // retire un job du gestionnaire - virtual void deleteJob(const JobId & jobid); - - // suspend un job en file d'attente - virtual void holdJob(const JobId & jobid); - - // relache un job suspendu - virtual void releaseJob(const JobId & jobid); - - // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, - const Parametre & param, - const Environnement & env); - virtual void alterJob(const JobId & jobid, - const Parametre & param); - virtual void alterJob(const JobId & jobid, - const Environnement & env); - - // renvoie l'etat du job - virtual JobInfo queryJob(const JobId & jobid); - - // modifie un job en file d'attente - virtual void setParametre(const JobId & jobid, - const Parametre & param); - virtual void setEnvironnement(const JobId & jobid, - const Environnement & env); - - protected: - string _hostname; // serveur ou tourne le BatchManager - - private: - -@}; -@end example - -@item Exemple - -@example -@dots{} - -// On recupere l'instance du catalogue de gestionnaires de batch -Batch::BatchManagerCatalog cata = Batch::BatchManagerCatalog::getInstance(); - -// On cree une fabrique de BatchManager de type PBS -Batch::BatchManager & myBM = (* cata("PBS"))("serveur.domaine.fr") - -// Maintenant, on peut utiliser toutes les fonctionnalites du -// gestionnaire de batch a travers le variable myBM - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{BatchManager_PBS(FactBatchManager * parent, -const char * host) throw(InvalidArgumentException)} - -Excepte un pointeur sur la fabrique qui a produit l'objet, le -constructeur accepte zero ou un argument de type @emph{string} decrivant -soit le nom de domaine completement qualifie (FQDN, @i{fully qualified -domain name}) du serveur de batch, soit son adresse IP dans un format -decimal "aaa.bbb.ccc.ddd". - -Si aucun parametre n'est passe au constructeur, celui-ci prend le -serveur par defaut tel que renvoye par la methode @emph{getDefaultServer}. - -Une resolution du nom ou de l'adresse peut etre realisee en fonction des -capacites de la plate-forme pour s'assurer que le serveur est connu et -joignable. En cas d'echec, une exception InvalidArgumentException est -levee. @xref{Classe InvalidArgumentException}. - -Ceci fait, une connexion est etablie avec le gestionnaire de batch qui -est maintenue jusqu'a destruction de l'objet. - -@item -@b{~BatchManager()} - -Le destructeur supprime la connexion precedemment etablie par le -constructeur lorsque celle-ci a reussi. - -@item -@b{const JobId submitJob(const Job & job)} - -Cette methode soumet le job passe en argument au gestionnaire de -batch. Etant donne que le job ne peut pas etre envoye tel quel puisqu'il -a un format generique au sein de la bibliotheque de classes Batch, cette -methode est chargee de le convertir dans un format adapte au -gestionnaire de batch sous-jacent. - -La methode opere ici une conversion du job de la classe @emph{Job} en @emph{Job_PBS}. - -Ce n'est que lorsque cette conversion est realisee que le job est soumis -au gestionnaire a travers son API. L'identifiant propose par le -gestionnaire est alors renvoye a l'appelant. Si la soumission echoue -pour une raison ou une autre, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{void deleteJob(const JobId & jobid)} - -Cette methode retire le job dont l'identifiant est passe en argument de -la file d'attente du gestionnaire, ou bien l'arrete en cours -d'execution. Cette methode est inoperante sur des travaux deja termines, -auquel cas une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{void holdJob(const JobId & jobid)} - -Cette methode suspend le job dont l'identifiant est passe en argument au -sein de la file d'attente du gestionnaire. Cette methode est inoperante -sur des travaux en cours d'execution ou deja termines, ainsi que sur des -travaux deja suspendus. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{void releaseJob(const JobId & jobid)} - -Cette methode relache un job precedemment suspendu en file -d'attente dont l'identifiant est passe en argument. Elle est inoperante -sur des travaux deja reclaches, en cours d'execution ou termines. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)@* -void alterJob(const JobId & jobid, const Parametre & param)@* -void alterJob(const JobId & jobid, const Environnement & env)} - -Ces methodes permettent de modifier les parametres d'execution et -d'environnement d'un job dont l'identifiant est passe en -argument. @xref{Classe Parametre}. @xref{Classe Environnement}. Il -est important de noter que le job doit etre encore place en file -d'attente sinon la methode est inoperante. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - -@item -@b{JobInfo queryJob(const JobId & jobid)} - -Cette methode permet de recuperer les informations concernant le job -dont l'identifiant est passe en argument dans un objet de classe -@emph{JobInfo}. @xref{Classe JobInfo}. On y retrouve les parametres -d'execution et d'environnement du job tels qu'ils ont ete passes au -gestionnaire au moment de la soumission, ainsi que des informations -concernant l'execution du job comme par exemple la machine d'execution, -le temps consomme, la memoire consommee, etc. - -Il n'est pas toujours possible d'interroger un job deja termine. -En cas de probleme, une exception APIInternalFailureException est -levee. @xref{Classe APIInternalFailureException}. - - -@item -@b{const JobId getJobIdByReference(const string & ref)} - -Cette methode permet de recuperer au sein de la classe un identifiant de -job a partir d'une chaine de caracteres obtenue par un biais -externe. Cet identifiant pourra etre utilise par la suite au sein de la -biliotheque de classes pour controler le job comme s'il avait ete cree -et soumis depuis la biliotheque-meme. - -@item -@b{void setParametre(const JobId & jobid, const Parametre & param)} - -Cette methode n'est utile que pour l'interfacage avec Python, car Python -ne sait pas gerer la surcharge de methode, et de fait leve des -exceptions lors d'appels a de telles methodes. - -Elle est equivalente a la methode @samp{void alterJob(const JobId & jobid, const Parametre & param)}. - -@item -@b{void setEnvironnement(const JobId & jobid, const Environnement & env)} - -Cette methode n'est utile que pour l'interfacage avec Python, car Python -ne sait pas gerer la surcharge de methode, et de fait leve des -exceptions lors d'appels a de telles methodes. - -Elle est equivalente a la methode @samp{void alterJob(const JobId & jobid, const Environnement & env)}. - -@end itemize - - -@end itemize - -@c ---------------------- -@c ---------------------- -@c ---------------------- - - -@node Classe JobInfo_PBS, Classe Job_PBS, Classe BatchManager_PBS, Classes PBS -@comment node-name, next, previous, up -@page -@subsubsection JobInfo_PBS -@cindex JobInfo_PBS - -Un objet de classe @emph{JobInfo} represente l'ensemble des informations -disponibles sur un travail actif, c'est-a-dire soumis au gestionnaire de -batch, a un instant donne. - -Cet objet reprend des informations issues du job tel qu'il a ete soumis, -@xref{Classe Job}, mais aussi des informations produites par le -gestionnaire de batch a partir de la soumission et du transit du job en -son sein : nom de la queue dans laquelle le job est inscrit, duree -d'execution, date de soumission, etc. - -Ces informations sont disponibles aupres de l'utilisateur de la classe a -travers les objets @emph{Parametre} et @emph{Environnement} que l'objet -@emph{JobInfo} peut fournir. - -@itemize @bullet{} -@item Entete - -@example -class JobInfo_PBS : public JobInfo -@{ - public: - // Constructeur standard et destructeur - JobInfo_PBS(); - JobInfo_PBS(struct batch_status * stat_list, - bool tobedeleted = false); - virtual ~JobInfo_PBS(); - - // Constructeur par recopie - JobInfo_PBS(const JobInfo_PBS & jinfo); - - // Methodes pour l'interfacage avec Python (SWIG) - string __str__() const; // SWIG : affichage en Python - string __repr__() const; // SWIG : affichage en Python - - protected: - Parametre _param; // parametres du job - Environnement _env; // variables d'environnement du job - - private: -@}; -@end example - - -@item Exemple -@example -@dots{} (ici on cree un BatchManager bm et un Job job) - -// On soumet le job et on recupere un identifiant -JobId jobid = bm.submitJob(job); - -// Ce qui permet d'interroger l'etat du job en cours -// Nota : l'objet retourne est un JobInfo_PBS -JobInfo jinfo = jobid.queryJob(); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} -@item -@b{JobInfo_PBS()} - -Ce constructeur cree un objet @emph{JobInfo_PBS} vide. - -@item -@b{~JobInfo_PBS()} - -Le destructeur libere l'espace memoire alloue pour l'objet si la -desollacation n'a pas eu deja lieu dans le constructeur. - -@item -@b{JobInfo_PBS(const JobInfo_PBS & jinfo)} - -Le constructeur par recopie produit un objet identique a celui passe en -argument. Les deux objets sont totalement independants l'un de l'autre. - -@item -@b{JobInfo_PBS(struct batch_status * stat_list, bool tobedeleted = false)} - -Ce constructeur recupere une liste chainee du type interne OpenPBS -@emph{struct batch_status *}, la parcoure et l'analyse pour en extraire -les informations utilisables par la bibliotheque de classes et les -stocker dans deux objets internes @emph{Parametre} et -@emph{Environnement}. - -Si le parametre @emph{tobedeleted} vaut @emph{true} alors la liste -chainee @emph{stat_list} sera desallouee a la fin du constructeur. Sinon -elle sera desalloue dans le destructeur au plus tard. - -@item -@b{string __str__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobInfo}. - -@item -@b{string __repr__() const} - -Cette methode n'est utile que pour l'interfacage avec Python. Elle -permet d'afficher l'etat de l'objet @emph{JobInfo}. - -@end itemize - -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - - -@node Classe Job_PBS, Classes Python, Classe JobInfo_PBS, Classes PBS -@comment node-name, next, previous, up -@page -@subsubsection Job_PBS -@cindex Job_PBS - -Un objet de classe @emph{Job} possede une structure generique -potentiellement utilisable par tout gestionnaire de batch mais pas en -l'etat. Une conversion dans un format lisible par le gestionnaire doit -etre realisee. - -Ceci se fait en produisant a partir des donnees generiques de la classe -@emph{Job} des structures de donnees specifiques qui peuvent etre -directement passees a l'API du gestionnaire. - -La classe @emph{Job_PBS} se distingue donc de la classe @emph{Job} par son -constructeur et par des accesseurs specifiques qui produisent des -donnees lisibles par OpenPBS. - -Etant donnee la specificite de cette classe, elle ne devrait concerner -que les developpeurs de la bibliotheque de classes Batch. - -@itemize @bullet{} -@item Entete - -@example -class Job_PBS -@{ - public: - // Constructeurs et destructeur - Job_PBS(const Job & job); - virtual ~Job_PBS(); - - // Accesseurs - struct attropl * getAttributesOP(); - struct attrl * getAttributes(); - char * getScript(); - char * getDestination(); - - protected: - struct attropl * _p_attropl; // liste d'attributs + operateur - struct attrl * _p_attrl; // liste d'attributs - char * _script; // chemin d'acces au script du job - char * _destination; // queue dans laquelle le job est soumis - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} - -Parametre param; -Environnement env; - -@dots{} (ici on cree les parametres du job) - -Job job(param, env); - -// On fabrique un job specifique a OpenPBS a partir du job generique -// Ceci ne concerne en general pas l'utilisateur de la bibliotheque -Job_PBS jobpbs(job); - -@dots{} -@end example - -@item Methodes -@itemize @minus{} - -@item -@b{Job_PBS(const Job & job)} - -Le constructeur convertit les objets internes @emph{Parametre} et -@emph{Environnement} de l'objet passe en argument en un ensemble de -quatre structures C @emph{AttributesOP}, @emph{Attributes}, -@emph{Script} et @emph{Destination} directement utilisable par l'API de -OpenPBS. - -@item -@b{~Job_PBS()} - -Le destructeur libere simplement les espaces alloues pour les structures -@emph{AttributesOP}, @emph{Attributes}, @emph{Script} et -@emph{Destination}. - -@item -@b{struct attropl * getAttributesOP()} - -Cet accesseur retourne un pointeur sur la structure interne -@emph{AttributesOP} de l'objet. Cette structure n'est pas protogee -contre les modifications accidentelles de l'utilisateur. Par consequent -il est recommande d'eviter d'y apporter toute alteration sous peine de -dysfonctionnement. - -Pour la definition de la structure @emph{AttributesOP}, voir la -documentation OpenPBS. - -@item -@b{struct attrl * getAttributes()} - -Cet accesseur retourne un pointeur sur la structure interne -@emph{Attributes} de l'objet. Cette structure n'est pas protogee -contre les modifications accidentelles de l'utilisateur. Par consequent -il est recommande d'eviter d'y apporter toute alteration sous peine de -dysfonctionnement. - -Pour la definition de la structure @emph{Attributes}, voir la -documentation OpenPBS. - -@item -@b{char * getScript()} - -Cet accesseur retourne un parametre @emph{Script} qui est une chaine de -caracteres C contenant le chemin absolu (sur la machine d'execution) -du script a soumettre au gestionnaire de batch. - -Cette chaine n'est pas protegee contre les modifications accidentelles -de l'utilisateur. Il est donc recommande de ne pas y apporter de modification. - -@item -@b{char * getDestination()} - -Cet accesseur retourne un parametre @emph{Destination} qui est une chaine de -caracteres C contenant le nom de la queue, ou classe ou file selon les terminologies, -du gestionnaire de batch dans laquelle le job doit etre soumis. - -Cette chaine n'est pas protegee contre les modifications accidentelles -de l'utilisateur. Il est donc recommande de ne pas y apporter de modification. - - -@end itemize -@end itemize - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Classes Python, Classe PyVersatile, Classe Job_PBS, Classes specifiques -@comment node-name, next, previous, up -@page -@subsection Classes Python -@cindex classes Python - -L'integration de la bibliotheque de classes Batch dans l'interpreteur -Python a beaucoup progresse depuis la precedente version et se trouve -etre quasiment iso-fonctionelle avec le C++. - -Actuellement, l'interface avec Python s'appuie a la fois sur les -fonctionnalites de l'utilitaire SWIG, et sur la definition d'une classe -specifique qui permet de voir en Python la classe @emph{Versatile}. - -Certaines classes ont de plus des methodes specifiques pour le wrapping -Python qui simplifient grandement le developpement des classes -d'interface au detriment, il est vrai, d'une bonne independance entre -les langages. Ce choix n'est pas definitif et pourra etre revu si -l'occasion s'en presente. - -Quoi qu'il en soit toutes les classes de haut niveau sont interfacees en -Python sous le meme nom et proposent les memes methodes (sauf celles -surchargees en C++ qui sot parfois renommees pour lever -l'ambiguite). Pour ne pas refaire un expose detaille et fastidieux des -fonctionnalites Python de la bibliotheque de classes, il est propose de -retrouver les noms et la syntaxe de ces classe dans la partie -Utilisation de ce document. @xref{Utilisation}. - -@menu -* Classe PyVersatile:: Description de la classe PyVersatile. -@end menu - -@c ---------------------- -@c ---------------------- -@c ---------------------- - - -@node Classe PyVersatile, Utilisation, Classes Python, Classes Python -@comment node-name, next, previous, up -@page -@subsubsection PyVersatile -@cindex PyVersatile - - -La classe @emph{PyVersatile} derive de la classe @emph{Versatile} et -offre la possibilite de convertir un tel objet en objet Python et -@i{vice versa}. - - -@itemize @bullet{} -@item Entete - -@example -class PyVersatile : public Versatile -@{ - public: - // Constructeur a partir d'un objet Versatile - PyVersatile(const Versatile &); - - // Constructeur a partir d'un PyObject - PyVersatile(const PyObject *) throw(TypeMismatchException, - ListIsFullException, - InvalidArgumentException); - - // Conversion de type vers un PyObject - operator PyObject *() const; - - // Operateur d'affectation a partir d'un objet Versatile - PyVersatile & operator =(const Versatile &); - - protected: - - private: - -@}; -@end example - - -@item Exemple -@example -@dots{} - -// On cree un objet Versatile contenant -// une liste de chaine de caracteres -Versatile V; -V = "a", "b", "c"; - -// On convertit cet objet Versatile en PyVersatile -PyVersatile PyV(V); - -// De la on produit un objet Python -// qui est une liste de chaine de caracteres -PyObject * PyO = PyV; - -@dots{} -@end example - -@item Methodes -@itemize @minus{} - -@item -@b{PyVersatile(const Versatile &)} - -Ce constructeur convertit un objet @emph{Versatile} en objet @emph{PyVersatile}. - -@item -@b{PyVersatile(const PyObject *) throw(TypeMismatchException, ListIsFullException, InvalidArgumentException)} - -Ce constructeur convertit un objet Python passe en argument en un objet -@emph{PyVersatile}. - -Seuls certains objets Python peuvent etre convertis : les @emph{string} -et les @emph{long}, ainsi que les listes homogenes de ces types, ce qui -est coherent avec la nature de l'objet @emph{Versatile}. Si tel n'est -pas le cas, une exception Python est renvoyee a l'interpreteur. - - -@item -@b{operator PyObject *() const} - -Cet operateur convertit l'objet en objet Python. Selon le cas, l'objet -retourne est soit un scalaire soit une liste. L'objet retourne est -alloue dynamiquement et doit donc etre pris en charge par l'interpreteur. - -@item -@b{PyVersatile & operator =(const Versatile &)} - -L'affectation d'un objet @emph{Versatile} passe en argument est -similaire a l'affectation entre objets @emph{Versatile}. Les structures -de donnees internes initiales de l'objet sont effacees et remplacees par -une copie des donnees internes de l'objet passe en argument. Les deux -objets restent independants l'un de l'autre a l'issue de l'affectation. - -@end itemize -@end itemize - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Utilisation, Connexion, Classe PyVersatile, Top -@comment node-name, next, previous, up -@page -@chapter Utilisation -@cindex utilisation - -Ce chapitre presente les differentes actions qu'il est possible de -realiser avec les classes de la bilbiotheque. - -On presente un cas hypothetique ou un utilisateur voudrait soumettre et -controler un job depuis un code C++. Les sections suivantes decrivent -les operations a faire ainsi que leur action sur le travail soumis. - -@menu -* Connexion:: Creation d'un gestionnaire de batch. -* Creation:: Declaration d'un job (travail). -* Soumission:: Demande d'execution du job. -* Interrogation:: Recuperation des informations sur le job. -* Destruction:: Arret du job en cours. -* Suspension:: Suspension du job en file d'attente. -* Reprise:: Liberation du job en file d'attente. -* Modification:: Modification d'un job en file d'attente. -@end menu - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Connexion, Creation, Utilisation, Utilisation -@comment node-name, next, previous, up -@section Connexion -@cindex connexion -@cindex deconnexion - -La premiere etape avant toute utilisation pratique des classes de la -bibliotheque consiste a se connecter a un gestionnaire de batch. - -Ce concept de connexion est purement interne a la bibliotheque car il -est tout a fait possible d'imaginer le controle de jobs a travers l'API -d'un gestionnaire sans jamais etablir ni maintenir une quelconque -connexion avec celui-ci. D'autres par contre reclament l'etablissement -d'une connexion. - -Quoiqu'il en soit ceci n'est pas genant et l'etablissement et le -maintien de la connexion avec le gestionnaire de batch se fait par la -creation d'un objet de classe @emph{BatchManager} ou d'une classe -derivee. - -En pratique, la classe @emph{BatchManager} se comporte comme une -interface et seules les classes d'implementation derivee doivent etre -instanciees. - -Si l'on prend le cas d'un serveur @samp{serveur.domaine.fr} supportant -un gestionnaire de batch OpenPBS, on peut s'y connecter de la maniere -suivante : - -@itemize @bullet{} -@item Exemple C++ : - -@example -BatchManagerCatalog cata = BatchManagerCatalog::getInstance(); -BatchManager_PBS & bm = * (* cata('PBS'))("serveur.domaine.fr"); -@end example - -@item Exemple Python: - -@example -cata = BatchManagerCatalog.getInstance() -bm = cata('PBS')('serveur.domaine.fr') -@end example - -@end itemize - -Tant que l'objet @emph{bm} sera present --- tant que son destructeur -n'aura pas ete appele --- la connexion sera maintenue. La deconnexion -aura lieu a la destruction de l'objet. - -@xref{Classe BatchManager}. -@xref{Classe BatchManager_PBS}. - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Creation, Soumission, Connexion, Utilisation -@comment node-name, next, previous, up -@section Creation -@cindex creation - -La creation du job est l'etape qui precede toute soumission. Elle -necessite de decrire d'un maniere ou d'un autre ce que l'on va demander -a la machine d'executer. - -Pour cela on passe par deux objets intermediaires qui sont l'objet -@emph{Parametre} et l'objet @emph{Environnement}. - -Le minimum a preciser est en general le chemin absolu d'acces a -l'executable, quoique ceci depende fortement de la configuration du -gestionnaire auquel on se connecte. Celui-ci peut reclamer des -parametres supplementaires. - -Pour connaitre l'ensemble des parametres disponibles : @xref{Classe -Parametre}. - -On supposera dans cet exemple que l'application en question sait -reconnaitre une variable d'environnement @var{myapp_loglevel} qui prend -une valeur numerique correspondant au niveau d'information affiche en -sortie. - -Cette application imaginaire utilise egalement trois fichiers : - -@itemize @bullet{} -@item -un fichier d'entree nomme @file{Cas1.data} sur la machine locale qu'il -faudra renommer @file{fort.9} pour que l'application puisse le lire -(notre application imaginaire est ecrite en FORTRAN et attend un fichier -d'entree sur son descripteur 9); - -@item -un fichier de sortie standard que l'on voudra recuperer sous le nom -@file{Cas1.out}; - -@item -un fichier d'erreur standard que l'on voudra recuperer sous le nom -@file{Cas1.err}. - -@end itemize - -Le job est ensuite cree simplement a l'aide des deux objets precedents. - -@itemize @bullet{} -@item Exemple C++ : - -@example -Parametre param; -param[EXECUTABLE] = "/home/user/my_app/bin/exec_app.sh"; -param[INFILE] = Couple("/home/user/my_app/data/Cas1.data","fort.9"); -param[OUTFILE] = Couple("/home/user/my_app/data/Cas1.out", "stdout"), - Couple("/home/user/my_app/data/Cas1.err", "stderr"); - -Environnement env; -env["MYAPP_LOGLEVEL"] = "3"; - -Job job(param, env); -@end example - -@item Exemple Python: - -@example -param = @{@} -param["EXECUTABLE"] = "/home/user/my_app/bin/exec_app.sh" -param["INFILE"] = [ ("/home/user/my_app/data/Cas1.data","fort.9") ] -param["OUTFILE"] = [ ("/home/user/my_app/data/Cas1.out", "stdout"), - ("/home/user/my_app/data/Cas1.err", "stderr") ] - -env = @{@} -env["MYAPP_LOGLEVEL"] = "3" - -job = Job() -job.setParametre(param) -job.setEnvironnement(env) -@end example - -@end itemize - - -@xref{Classe Parametre}. -@xref{Classe Environnement}. -@xref{Classe Job}. - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Soumission, Interrogation, Creation, Utilisation -@comment node-name, next, previous, up -@section Soumission -@cindex soumission -@findex submitJob - -Une fois le job cree, il est alors tres simple de le soumettre au -gestionnaire de batch en passant par l'intermediaire de l'objet -@emph{BatchManager} cree precedemment. - -Cette soumission produira un objet @emph{JobId} qui servira a controler -le job par la suite. - -Cependant des exceptions peuvent etre levees au moment de la soumission -et il convient de fournir un gestionnaire d'exception pour gerer -proprement ces incidents. - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - const JobId jobid = bm.submitJob(job); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -try : - jobid = bm.submitJob(job) -except : - @dots{} -@end example - -@end itemize - - -@xref{Classe Job}. -@xref{Classe JobId}. -@xref{Exceptions}. - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Interrogation, Destruction, Soumission, Utilisation -@comment node-name, next, previous, up -@section Interrogation -@cindex interrogation -@findex queryJob - -La fourniture d'un objet @emph{JobId} permet d'avoir tout controle sur -le job en cours. En particulier il est possible de l'interroger : -ceci generera un objet @emph{JobInfo} qui donnera l'ensemble des -informations disponibles sur l'etat du job aupres du gestionnaire de -batch. - -Ces informations sont disponibles a travers deux objets internes de -classes @emph{Parametre} et @emph{Environnement}, les memes que pour la -classe @emph{Job}, mais modifies et completes avec les donnees les plus -a jour du gestionnaire de batch. - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - const JobInfo jinfo = jobid.queryJob(); - - Parametre newparam = jinfo.getParametre(); - Environnement newenv = jinfo.getEnvironnement(); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -try : - jobinfo = jobid.queryJob() - - newparam = jinfo.getParametre() - newenv = jinfo.getEnvironnement() -except : - @dots{} -@end example - -@end itemize - - -@xref{Classe JobId}. -@xref{Classe JobInfo}. -@xref{Exceptions}. - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Destruction, Suspension, Interrogation, Utilisation -@comment node-name, next, previous, up -@section Destruction -@cindex destruction -@cindex suppression -@findex deleteJob - - -Il est possible de detruire un job que celui-ci soit encore en file -d'attente ou bien que son execution ait deja commence, auquel cas elle -serait immediatement interrompue. - - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - jobid.deleteJob(); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -try : - jobid.deleteJob() - -except : - @dots{} -@end example - -@end itemize - - -@xref{Classe JobId}. -@xref{Exceptions}. - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Suspension, Reprise, Destruction, Utilisation -@comment node-name, next, previous, up -@section Suspension -@cindex suspension -@findex holdJob - -La suspension consiste a figer en file d'attente un job qui n'aurait pas -encore commence son execution. Il n'est pas possible de suspendre un job -qui s'execute. - -Il y a deux manieres de suspendre un job en file d'attente : -@itemize @bullet{} -@item en utilisant la methode @samp{holdJob}; -@item en modifiant les parametres du job a l'aide de la methode @samp{alterJob}. -@end itemize - -Exemple 1 : - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - jobid.holdJob(); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -try : - jobid.holdJob() - -except : - @dots{} -@end example - -@end itemize - -Exemple 2 : - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - Parametre altparam; - altparam[HOLD] = 1; - jobid.alterJob(altparam); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -// Compte tenu de la surcharge d'operateur, cet exemple peut ne pas -// fonctionner encore -try : - altparam = @{@} - altparam["HOLD"] = 1 - jobid.alterJob(altparam) - -except : - @dots{} -@end example - -@end itemize - - - -@xref{Classe JobId}. -@xref{Exceptions}. -@xref{Reprise}. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Reprise, Modification, Suspension, Utilisation -@comment node-name, next, previous, up -@section Reprise -@cindex reprise -@findex releaseJob - -La reprise est l'operation inverse de la suspension en ceci qu'elle -libere un job precedemment suspendu en file d'attente. Le job continuera -alors son cheminement normal au sein du gestionnaire de batch. - -Il y a deux manieres de suspendre un job en file d'attente : -@itemize @bullet{} -@item en utilisant la methode @samp{releaseJob}; -@item en modifiant les parametres du job a l'aide de la methode @samp{alterJob}. -@end itemize - -Exemple 1 : - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - jobid.releaseJob(); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -try : - jobid.releaseJob() - -except : - @dots{} -@end example - -@end itemize - -Exemple 2 : - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - Parametre altparam; - altparam[HOLD] = 0; - jobid.alterJob(altparam); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -// Compte tenu de la surcharge d'operateur, cet exemple peut ne pas -// fonctionner encore -try : - altparam = @{@} - altparam["HOLD"] = 0 - jobid.alterJob(altparam) - -except : - @dots{} -@end example - -@end itemize - - -@xref{Classe JobId}. -@xref{Exceptions}. -@xref{Suspension}. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Modification, Installation de la bibliotheque, Reprise, Utilisation -@comment node-name, next, previous, up -@section Modification -@cindex modification -@findex alterJob - -Il est possible de modifier tout ou partie des parametres et des -variables d'un job a condition que celui-ci soit encore en file -d'attente. Un job dont l'execution a deja debute devient inalterable, -sauf a l'arreter definitvement. - -La modification se fait en declarant un objet @emph{Parametre} et/ou un -objet @emph{Environnement} contenant l'ensemble des alterations a -apporter a la description du job. Ces alterations peuvent porter sur des -parametres ou des variables deja definies ou non. - -En reprenant le cas du job imaginaire utilise jusqu'ici, on peut -souhaiter changer le script qui tient lieu d'executable car le precedent -etait incomplet, modifier le niveau d'affichage de la log et ajouter une -variable nommee @var{myapp_debug} qui indique au code de passer en mode -debug. Ceci pourrait se faire de la maniere suivante : - -@itemize @bullet{} -@item Exemple C++ : - -@example -try @{ - Parametre altparam; - altparam[EXECUTABLE] = "/home/user/my_app/bin/exec_app.sh"; - - Environnement altenv; - altenv["MYAPP_LOGLEVEL"] = "4"; - altenv["MYAPP_DEBUG"] = "1"; - jobid.alterJob(altparam, altenv); - -@} catch (GenericException & ex) @{ - @dots{} -@} -@end example - -@item Exemple Python: - -@example -// Compte tenu de la surcharge d'operateur, cet exemple peut ne pas -// fonctionner encore -try : - altparam = @{@} - altparam["EXECUTABLE"] = "/home/user/my_app/bin/exec_app.sh" - - altenv = @{@} - altenv["MYAPP_LOGLEVEL"] = "4"; - altenv["MYAPP_DEBUG"] = "1"; - - jobid.alterJob(altparam, altenv) - -except : - @dots{} -@end example - -@end itemize - - -@xref{Classe JobId}. -@xref{Exceptions}. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Installation de la bibliotheque, Prerequis, Modification, Top -@comment node-name, next, previous, up -@chapter Installation -@cindex installation - -Cette section montre comment installer l'ensemble de la bibliotheque de -classes Batch sur une machine Unix. - -@menu -* Prerequis:: -* Installation rapide:: -* Configuration:: -* Compilation:: -* Compilation de la documentation:: -* Tests:: -* Installation:: -@end menu - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Prerequis, Installation rapide, Installation de la bibliotheque, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Prerequis -@cindex prerequis - -@unnumberedsubsubsec CMake -@cindex CMake - -La bibliotheque de classes Batch utilise CMake pour la configuration et -la generation des Makefiles (voir le site officiel -@uref{http://www.cmake.org/}). La version minimum requise est la 2.4. - -@unnumberedsubsec GCC/G++ - -A l'heure actuelle, la bibliotheque de classes Batch est developpee en -C++ et necessite de fait un compilateur pour ce langage. GCC/G++ -version 2.95.3 ou une version ulterieure est un choix judicieux. - -@unnumberedsubsec Gestionnaires de batch - -Comme la bibliotheque utilise les fonctionnalites de certains -gestionnaires de batch, il est indispensable de pouvoir acceder aux -bibliotheques et aux fichiers d'entete de ces produits, ou du moins des -produits dont on se servira par la suite, ceci pour pouvoir communiquer -a travers l'API qu'ils ont developpe. - -Le cas le plus simple est d'avoir le produit directement installe sur la -machine sur laquelle sera compilee la bibliotheque de classes Batch. - -@unnumberedsubsubsec OpenPBS -@cindex OpenPBS -@cindex PBS - -A ce jour, seul le gestionnaire de batch PBS (OpenPBS et PBS Pro) est -supporte (voir le site officiel @uref{http://www.openpbs.org}). Il doit -avoir une version au moins egale a 2.3.16. - -@unnumberedsubsubsec LSF -@cindex LSF - -Il est prevu d'avoir un support de LSF dans les mois qui viennent. - -@unnumberedsubsubsec LoadLeveler -@cindex LoadLeveler - -Il est prevu d'avoir un support de LoadLeveler mais dans un futur plus -lointain en fonction de la disponibilite du produit mais surtout d'une -machine sur lequel il serait installe. - -@unnumberedsubsubsec Sun Grid Engine - -Ce choix-la est beaucoup plus hypothetique, et risque bien de ne jamais -etre mene a bien. - -@unnumberedsubsubsec Rsh/Ssh - -Il est prevu de simuler le fonctionnement d'un gestionnaire de batch a -l'aide de commandes Unix Rsh et Ssh dans la mesure de leurs capacites -lorsque qu'il n'est pas possible d'avoir un gestionnaire de batch sur -certaines machines ou de s'y connecter (par exemple lorsqu'on traverse -un coupe-feu). - -@unnumberedsubsec Python -@cindex Python - -Les classes de haut-niveau de la bibliotheque de classes Batch disposent -d'une interface en Python qui leur permet d'etre utilisables dans ce -langage. L'usage de cette fonctionnalite necessite d'avoir a disposition -une version de Python (voir le site officiel -@uref{http://www.python.org}) au moins egale a 2.2. - -@unnumberedsubsec SWIG -@cindex SWIG - -De plus l'interfacage avec Python est automatise a l'aide de -l'utilitaire SWIG (voir le site officiel @uref{http://www.swig.org}) qui -transcrit les definitions des classes C++ en classes Python. Il faut -pour cela disposer de la version 1.3.17 ou ulterieure. - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Installation rapide, Configuration, Prerequis, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Installation rapide -@cindex installation rapide - -Il faut commencer par decompresser le fichier @file{.tar.gz} ou -@file{.tgz} et descendre dans le repertoire qu'il a cree : - -@example -$ tar -xzvf libBatch-@value{VERSION}.tar.gz -$ cd libBatch-@value{VERSION} -@end example - -Pour ceux qui sont vraiment presses, le minimum requis est : - -@example -$ cmake -$ make -$ make install -@end example - -Pour ceux qui ont le temps de lire la suite, les sections suivantes -decrivent plus en detail ces etapes et les differents tests que l'on -peut mener. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Configuration, Compilation, Installation rapide, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Configuration -@cindex configuration - -La phase de configuration, tres classique dans le domaine des logiciels -libres, est basee sur CMake (voir @uref{http://www.cmake.org/}). - -La configuration est faite en appelant @file{cmake} avec en parametre -le repertoire racine de la bibliotheque de classes -Batch. Ce programme analyse l'ensemble des elements du systeme sur -lequel se deroulera la compilation pour determiner les parametres -optimaux et la presence de tous les produits necessaires a la -compilation. - -On n'oubliera pas de se referer a la documentation de @file{cmake} -notamment pour determiner l'emplacement definitif de l'installation. Le -fichier @file{INSTALL} situe a la racine de la bibliotheque de classes -Batch pourra egalement donner des indications d'utilisation. - -C'est aussi au cours de cette phase de configuration qu'il est -indispensable de preciser avec quelles options la bibliotheque doit etre -generee. En particulier il est necessaire d'indiquer avec quel(s) -gestionnaire(s) de batch doit se faire la compilation de maniere a avoir -acces a l'API. L'utilitaire @file{ccmake}, qui prend en parametre -le repertoire racine de la bibliotheque de classes Batch, permet de -preciser cette configuration. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Compilation, Compilation de la documentation, Configuration, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Compilation -@cindex compilation - -La compilation proprement dite n'appelle pas de remarque particuliere : - -@example -$ make -@end example - -On n'oubliera pas d'utiliser les fonctionnalites de chaque @file{make}, -comme par exemple la compilation parallele pour reduire les temps de -compilation (voir @inforef{Top, ,make}). - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Compilation de la documentation, Tests, Compilation, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Compilation de la documentation -@cindex compilation de la documentation - -Normalement la documentation est automatiquement compilee lors de la -compilation de la bibliotheque, mais uniquement sous forme HTML. -Il est egalement possible d'obtenir un fichier @file{.info} ou un fichier -@file{.dvi} qui permettra de generer d'autres formats comme le -PostScript (fichier @file{.ps}) ou le PDF (fichier @file{.pdf}). -Cependant les cibles permettant de generer ces autres formats n'ont pas -ete creees a l'heure actuelle. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Tests, Installation, Compilation de la documentation, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Tests -@cindex tests - -@unnumberedsubsec Tests de pre-installation - -La bibliotheque de classes Batch dispose d'un ensemble de tests -permettant de verifier le fonctionnement des differents systemes de -batch. Les tests sont executes de la maniere suivante : - -@example -$ make test -@end example - -A la fin des tests, un compte rendu est fait qui avertit l'utilisateur -des tests reussis et des echecs rencontres. Chaque test peut etre rejoue -individuellement grace a l'utilitaire @file{ctest} et en precisant le -nom du test. Par exemple : - -@example -$ ctest -R Local_SSH -@end example - -@unnumberedsubsec Tests de post-installation - -Aucun test de post-installation n'est actuellement possible sur la -bibliotheque de classes Batch. - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Installation, Divers, Tests, Installation de la bibliotheque -@comment node-name, next, previous, up -@section Installation -@cindex installation - -L'installation est la mise a disposition definitive dans le systeme de -la bibliotheque de classes Batch. C'est la derniere etape de la -procedure apres la configuration et la compilation. - -On l'execute de la maniere suivante : - -@example -$ make install -@end example - -La bibliotheque, les fichiers d'entete, la documentation et eventuellement -le module Python sont installes dans le repertoire definitif. - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Divers, Index, Installation, Top -@comment node-name, next, previous, up -@chapter Divers -@cindex divers - - - - - -@c ---------------------- -@c ---------------------- -@c ---------------------- - -@node Index, Top , Divers, Top -@comment node-name, next, previous, up -@unnumbered Index - -@heading Index des concepts -@printindex cp - -@heading Index des fonctions et des methodes -@printindex fn - -@bye - diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt deleted file mode 100644 index c85a28a..0000000 --- a/doc/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.texi.in ${CMAKE_CURRENT_BINARY_DIR}/version.texi) - -SET (TEXI_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Batch.texi) - -ADD_CUSTOM_TARGET(doc ALL ${MAKEINFO_EXECUTABLE} --html ${TEXI_FILE}) - -FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Batch) - -INSTALL(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Batch/ DESTINATION share/Batch/doc) diff --git a/doc/version.texi.in b/doc/version.texi.in deleted file mode 100644 index ea149e8..0000000 --- a/doc/version.texi.in +++ /dev/null @@ -1,2 +0,0 @@ -@set UPDATED 23 April 2010 -@set VERSION @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@ diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index c0ec92b..3266b56 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -21,12 +21,12 @@ # email : webmaster.salome@opencascade.com INSTALL(FILES check_libbatch.m4 - DESTINATION share/Batch/misc) + DESTINATION share/libbatch/misc) -GET_TARGET_PROPERTY(LIBBATCH_ABS_PATH Batch LOCATION) +GET_TARGET_PROPERTY(LIBBATCH_ABS_PATH batch LOCATION) GET_FILENAME_COMPONENT(LIBBATCH_REAL_NAME ${LIBBATCH_ABS_PATH} NAME) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libBatchConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/libBatchConfig.cmake @ONLY) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libbatchConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libbatchConfig.cmake @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libBatchConfig.cmake +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbatchConfig.cmake DESTINATION lib) diff --git a/misc/check_libbatch.m4 b/misc/check_libbatch.m4 index 9fb0f1b..bd2dd2b 100644 --- a/misc/check_libbatch.m4 +++ b/misc/check_libbatch.m4 @@ -1,35 +1,35 @@ -dnl Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +dnl Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE dnl -dnl Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +dnl Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +dnl CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS dnl -dnl This library is free software; you can redistribute it and/or -dnl modify it under the terms of the GNU Lesser General Public -dnl License as published by the Free Software Foundation; either -dnl version 2.1 of the License. +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License. dnl -dnl This library is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -dnl Lesser General Public License for more details. +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. dnl -dnl You should have received a copy of the GNU Lesser General Public -dnl License along with this library; if not, write to the Free Software -dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library; if not, write to the Free Software +dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA dnl -dnl See http://www.salome-platform.org/ or -dnl email : webmaster.salome@opencascade.com +dnl See http://www.salome-platform.org/ or +dnl email : webmaster.salome@opencascade.com dnl # CHECK_LIBBATCH -# This macro can be used to find libBatch and set the associated variables in +# This macro can be used to find libbatch and set the associated variables in # a project based on autoconf. You can copy this file in your own project and # eventually modify it according to your own needs. # ---------------------------------------------------------------------------- AC_DEFUN([CHECK_LIBBATCH],[ -AC_MSG_NOTICE(Checking for libBatch library) +AC_MSG_NOTICE(Checking for libbatch library) AC_SUBST(LIBBATCH_INCLUDES) AC_SUBST(LIBBATCH_LIBS) @@ -59,27 +59,27 @@ LOCAL_LIBS="" if test "x$LIBBATCH_DIR" != "x" ; then LOCAL_INCLUDES="-I$LIBBATCH_DIR/include" if test "x$LIBBATCH_DIR" = "x/usr" ; then - LOCAL_LIBS="-lBatch" + LOCAL_LIBS="-lbatch" else - LOCAL_LIBS="-L$LIBBATCH_DIR/lib -lBatch" + LOCAL_LIBS="-L$LIBBATCH_DIR/lib -lbatch" fi else LOCAL_INCLUDES="-I/usr/include" - LOCAL_LIBS="-lBatch" + LOCAL_LIBS="-lbatch" fi -# libBatch headers +# libbatch headers CPPFLAGS_old="$CPPFLAGS" CPPFLAGS="$CPPFLAGS $LOCAL_INCLUDES" -AC_CHECK_HEADER(Batch/Batch_BatchManager.hxx, +AC_CHECK_HEADER(libbatch/BatchManager.hxx, libbatch_ok="yes", libbatch_ok="no") CPPFLAGS="$CPPFLAGS_old" if test "x$libbatch_ok" = "xyes" ; then - # libBatch library + # libbatch library LIBS_old=$LIBS LIBS="$LIBS $LOCAL_LIBS" @@ -110,6 +110,6 @@ if test "x$libbatch_ok" = "xyes" ; then LIBBATCH_LIBS="$LOCAL_LIBS" fi -AC_MSG_RESULT(for libBatch: $libbatch_ok) +AC_MSG_RESULT(for libbatch: $libbatch_ok) ]) diff --git a/misc/libBatchConfig.cmake.in b/misc/libBatchConfig.cmake.in deleted file mode 100644 index 5e457c1..0000000 --- a/misc/libBatchConfig.cmake.in +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (C) 2007-2012 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 - -get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -get_filename_component(LIBBATCH_ROOT_DIR "${SELF_DIR}/.." ABSOLUTE) -set(LIBBATCH_INCLUDE_DIRS "${LIBBATCH_ROOT_DIR}/include/Batch") -set(LIBBATCH_LIBRARIES "${LIBBATCH_ROOT_DIR}/lib/@LIBBATCH_REAL_NAME@") -set(LIBBATCH_RUNTIME_LIBRARY_DIRS "${LIBBATCH_ROOT_DIR}/lib") -set(LIBBATCH_PYTHONPATH "${LIBBATCH_ROOT_DIR}/lib/python@PYTHON_VERSION@/site-packages") diff --git a/misc/libbatchConfig.cmake.in b/misc/libbatchConfig.cmake.in new file mode 100644 index 0000000..3d1345a --- /dev/null +++ b/misc/libbatchConfig.cmake.in @@ -0,0 +1,28 @@ +# Copyright (C) 2007-2012 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 + +get_filename_component(SELF_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(LIBBATCH_ROOT_DIR "${SELF_DIR}/.." ABSOLUTE) +set(LIBBATCH_INCLUDE_DIRS "${LIBBATCH_ROOT_DIR}/include/libbatch") +set(LIBBATCH_LIBRARIES "${LIBBATCH_ROOT_DIR}/lib/@LIBBATCH_REAL_NAME@") +set(LIBBATCH_RUNTIME_LIBRARY_DIRS "${LIBBATCH_ROOT_DIR}/lib") +set(LIBBATCH_PYTHONPATH "${LIBBATCH_ROOT_DIR}/lib/python@PYTHON_VERSION@/site-packages") diff --git a/src/CCC/BatchManager_CCC.cxx b/src/CCC/BatchManager_CCC.cxx new file mode 100644 index 0000000..e24c171 --- /dev/null +++ b/src/CCC/BatchManager_CCC.cxx @@ -0,0 +1,292 @@ +// Copyright (C) 2007-2012 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_CCC.cxx : emulation of CCC client for CCRT machines + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2010 + * Projet : PAL Salome + * + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +#include +#include +#include + +#include "BatchManager_CCC.hxx" +#include "JobInfo_CCC.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_CCC::BatchManager_CCC(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + // Destructeur + BatchManager_CCC::~BatchManager_CCC() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_CCC::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const std::string workDir = params[WORKDIR]; + const string fileToExecute = params[EXECUTABLE]; + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + + // export input files on cluster + LOG("Export des fichiers en entree"); + exportInputFiles(job); + + // build batch script for job + LOG("Construction du script de batch"); + buildBatchScript(job); + LOG("Script envoye"); + + // define command to submit batch + string subCommand = string("bash -l -c \\\"cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh\\\""; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // find id of submitted job in output + istringstream idfile(output); + string sidj; + idfile >> sidj; + idfile >> sidj; + idfile >> sidj; + idfile >> sidj; + if (sidj.size() == 0) + throw RunTimeException("Error in the submission of the job on the remote host"); + + JobId id(this, sidj); + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_CCC::deleteJob(const JobId & jobid) + { + int status; + int ref; + istringstream iss(jobid.getReference()); + iss >> ref; + + // define command to delete batch + string subCommand = string("bash -l -c \\\"ccc_mdel ") + iss.str() + string("\\\""); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + status = system(command.c_str()); + if (status) + throw RunTimeException("Error of connection on remote host"); + + LOG("jobId = " << ref << "killed"); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_CCC::queryJob(const JobId & jobid) + { + int id; + istringstream iss(jobid.getReference()); + iss >> id; + + // define command to query batch + string subCommand = string("bash -l -c \\\"bjobs ") + iss.str() + string("\\\""); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + if (status) + throw RunTimeException("Error of connection on remote host"); + + JobInfo_CCC ji = JobInfo_CCC(id, output); + return ji; + } + + + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_CCC::isRunning(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_CCC::isRunning"); + } + + void BatchManager_CCC::buildBatchScript(const Job & job) + { +#ifndef WIN32 //TODO: need for porting on Windows + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + int nbproc = 0; + int edt = 0; + int mem = 0; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); + + // Optional parameters + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + if (params.find(MAXWALLTIME) != params.end()) + edt = (long)params[MAXWALLTIME] * 60; + if (params.find(MAXRAMSIZE) != params.end()) + mem = params[MAXRAMSIZE]; + if (params.find(QUEUE) != params.end()) + queue = params[QUEUE].str(); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + std::string TmpFileName = Utils::createAndOpenTemporaryFile("LSF-script", tempOutputFile); + + tempOutputFile << "#!/bin/bash" << endl ; + if (queue != "") + tempOutputFile << "#MSUB -q " << queue << endl; + if( edt > 0 ) + tempOutputFile << "#MSUB -T " << edt << endl ; + if( mem > 0 ) + tempOutputFile << "#MSUB -M " << mem << endl ; + tempOutputFile << "#MSUB -n " << nbproc << endl ; + size_t pos = workDir.find("$HOME"); + string baseDir; + if( pos != string::npos ) + baseDir = getHomeDir(workDir) + workDir.substr(pos+5,workDir.length()-5); + else{ + pos = workDir.find("~"); + if( pos != string::npos ) + baseDir = getHomeDir(workDir) + workDir.substr(pos+1,workDir.length()-1); + else + baseDir = workDir; + } + tempOutputFile << "#MSUB -o " << baseDir << "/logs/output.log." << rootNameToExecute << endl ; + tempOutputFile << "#MSUB -e " << baseDir << "/logs/error.log." << rootNameToExecute << endl ; + + tempOutputFile << "cd " << workDir << endl ; + + // generate nodes file + tempOutputFile << "bool=0" << endl; + tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl; + tempOutputFile << " if test $bool = 0; then" << endl; + tempOutputFile << " n=$i" << endl; + tempOutputFile << " bool=1" << endl; + tempOutputFile << " else" << endl; + tempOutputFile << " for ((j=0;j<$i;j++)); do" << endl; + tempOutputFile << " echo $n >> nodesFile." << rootNameToExecute << endl; + tempOutputFile << " done" << endl; + tempOutputFile << " bool=0" << endl; + tempOutputFile << " fi" << endl; + tempOutputFile << "done" << endl; + + // Abstraction of PBS_NODEFILE - TODO + tempOutputFile << "export LIBBATCH_NODEFILE=nodesFile." << rootNameToExecute << endl; + + // Allow resource sharing in CCRT nodes + tempOutputFile << "export OMPI_MCA_orte_process_binding=none" << endl; + + // Launch the executable + tempOutputFile << "./" + fileNameToExecute << endl; + tempOutputFile.flush(); + tempOutputFile.close(); + + Utils::chmod(TmpFileName.c_str(), 0x1ED); + LOG("Batch script file generated is: " << TmpFileName.c_str()); + + int status = _protocol.copyFile(TmpFileName, "", "", + workDir + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) + throw RunTimeException("Error of connection on remote host"); + +#endif + + } + + std::string BatchManager_CCC::getHomeDir(std::string tmpdir) + { + std::string home; + + string subCommand = string("echo "); + subCommand += tmpdir; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + + if (status) + throw RunTimeException("Error of launching home command on remote host"); + + std::istringstream file_home(output); + std::getline(file_home, home); + return home; + } + +} diff --git a/src/CCC/BatchManager_CCC.hxx b/src/CCC/BatchManager_CCC.hxx new file mode 100644 index 0000000..67a5228 --- /dev/null +++ b/src/CCC/BatchManager_CCC.hxx @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2012 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_CCC.hxx : emulation of CCC client for CCRT machines + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2010 + * Projet : PAL Salome + * + */ + +#ifndef _BATCHMANAGER_ECCC_H_ +#define _BATCHMANAGER_ECCC_H_ + +#include "Defines.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_CCC : public BatchManager + { + public: + // Constructeur et destructeur + BatchManager_CCC(const FactBatchManager * parent, const char * host="localhost", + const char * username="", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host + virtual ~BatchManager_CCC(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + protected: + void buildBatchScript(const Job & job); + std::string getWallTime(const long edt); + + private: + + std::string getHomeDir(std::string tmpdir); + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/CCC/Batch_BatchManager_eCCC.cxx b/src/CCC/Batch_BatchManager_eCCC.cxx deleted file mode 100644 index 83443ee..0000000 --- a/src/CCC/Batch_BatchManager_eCCC.cxx +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright (C) 2007-2012 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_eCCC.cxx : emulation of CCC client for CCRT machines - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2010 - * Projet : PAL Salome - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#ifdef WIN32 -#include -#else -#include -#endif - -#include "Batch_Constants.hxx" -#include "Batch_BatchManager_eCCC.hxx" -#include "Batch_JobInfo_eCCC.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_eCCC::BatchManager_eCCC(const FactBatchManager * parent, const char * host, - const char * username, - CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl) - { - // Nothing to do - } - - // Destructeur - BatchManager_eCCC::~BatchManager_eCCC() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_eCCC::submitJob(const Job & job) - { - int status; - Parametre params = job.getParametre(); - const std::string workDir = params[WORKDIR]; - const string fileToExecute = params[EXECUTABLE]; - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - - // export input files on cluster - cerr << "Export des fichiers en entree" << endl; - exportInputFiles(job); - - // build batch script for job - cerr << "Construction du script de batch" << endl; - buildBatchScript(job); - cerr << "Script envoye" << endl; - - // define name of log file (local) - string logFile = generateTemporaryFileName("CCC-submitlog"); - - // define command to submit batch - string subCommand = string("bash -l -c \\\"cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh\\\""; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - command += " 2>&1"; - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) - { - ifstream error_message(logFile.c_str()); - std::string mess; - std::string temp; - while(std::getline(error_message, temp)) - mess += temp; - error_message.close(); - throw EmulationException("Error of connection on remote host, error was: " + mess); - } - - // read id of submitted job in log file - ifstream idfile(logFile.c_str()); - string sidj; - idfile >> sidj; - idfile >> sidj; - idfile >> sidj; - idfile >> sidj; - idfile.close(); - if (sidj.size() == 0) - throw EmulationException("Error in the submission of the job on the remote host"); - - JobId id(this, sidj); - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_eCCC::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_eCCC::deleteJob(const JobId & jobid) - { - int status; - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - - // define command to delete batch - string subCommand = string("bash -l -c \\\"ccc_mdel ") + iss.str() + string("\\\""); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - status = system(command.c_str()); - if (status) - throw EmulationException("Error of connection on remote host"); - - cerr << "jobId = " << ref << "killed" << endl; - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_eCCC::holdJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_eCCC::releaseJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eCCC::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eCCC::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eCCC::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_eCCC::queryJob(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - // define name of log file (local) - string logFile = generateTemporaryFileName(string("CCC-querylog-id") + jobid.getReference()); - - // define command to query batch - string subCommand = string("bash -l -c \\\"bjobs ") + iss.str() + string("\\\""); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - cerr << command.c_str() << endl; - int status = system(command.c_str()); - if (status) - throw EmulationException("Error of connection on remote host"); - - JobInfo_eCCC ji = JobInfo_eCCC(id,logFile); - return ji; - } - - - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_eCCC::isRunning(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - void BatchManager_eCCC::buildBatchScript(const Job & job) - { -#ifndef WIN32 //TODO: need for porting on Windows - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - int nbproc = 0; - int edt = 0; - int mem = 0; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); - - // Optional parameters - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - if (params.find(MAXWALLTIME) != params.end()) - edt = (long)params[MAXWALLTIME] * 60; - if (params.find(MAXRAMSIZE) != params.end()) - mem = params[MAXRAMSIZE]; - if (params.find(QUEUE) != params.end()) - queue = params[QUEUE].str(); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - std::string TmpFileName = createAndOpenTemporaryFile("LSF-script", tempOutputFile); - - tempOutputFile << "#!/bin/bash" << endl ; - if (queue != "") - tempOutputFile << "#MSUB -q " << queue << endl; - if( edt > 0 ) - tempOutputFile << "#MSUB -T " << edt << endl ; - if( mem > 0 ) - tempOutputFile << "#MSUB -M " << mem << endl ; - tempOutputFile << "#MSUB -n " << nbproc << endl ; - size_t pos = workDir.find("$HOME"); - string baseDir; - if( pos != string::npos ) - baseDir = getHomeDir(workDir) + workDir.substr(pos+5,workDir.length()-5); - else{ - pos = workDir.find("~"); - if( pos != string::npos ) - baseDir = getHomeDir(workDir) + workDir.substr(pos+1,workDir.length()-1); - else - baseDir = workDir; - } - tempOutputFile << "#MSUB -o " << baseDir << "/logs/output.log." << rootNameToExecute << endl ; - tempOutputFile << "#MSUB -e " << baseDir << "/logs/error.log." << rootNameToExecute << endl ; - - tempOutputFile << "cd " << workDir << endl ; - - // generate nodes file - tempOutputFile << "bool=0" << endl; - tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl; - tempOutputFile << " if test $bool = 0; then" << endl; - tempOutputFile << " n=$i" << endl; - tempOutputFile << " bool=1" << endl; - tempOutputFile << " else" << endl; - tempOutputFile << " for ((j=0;j<$i;j++)); do" << endl; - tempOutputFile << " echo $n >> nodesFile." << rootNameToExecute << endl; - tempOutputFile << " done" << endl; - tempOutputFile << " bool=0" << endl; - tempOutputFile << " fi" << endl; - tempOutputFile << "done" << endl; - - // Abstraction of PBS_NODEFILE - TODO - tempOutputFile << "export LIBBATCH_NODEFILE=nodesFile." << rootNameToExecute << endl; - - // Allow resource sharing in CCRT nodes - tempOutputFile << "export OMPI_MCA_orte_process_binding=none" << endl; - - // Launch the executable - tempOutputFile << "./" + fileNameToExecute << endl; - tempOutputFile.flush(); - tempOutputFile.close(); - - BATCH_CHMOD(TmpFileName.c_str(), 0x1ED); - cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl; - - int status = _protocol.copyFile(TmpFileName, "", "", - workDir + "/" + rootNameToExecute + "_Batch.sh", - _hostname, _username); - if (status) - throw EmulationException("Error of connection on remote host"); - -#endif - - } - - std::string BatchManager_eCCC::getHomeDir(std::string tmpdir) - { - std::string home; - std::string filelogtemp = generateTemporaryFileName("gethomedir"); - - string subCommand = string("echo "); - subCommand += tmpdir; - string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp; - cerr << command.c_str() << endl; - int status = system(command.c_str()); - if (status) - throw EmulationException("Error of launching home command on remote host"); - - std::ifstream file_home(filelogtemp.c_str()); - std::getline(file_home, home); - file_home.close(); - return home; - } - -} diff --git a/src/CCC/Batch_BatchManager_eCCC.hxx b/src/CCC/Batch_BatchManager_eCCC.hxx deleted file mode 100644 index de93827..0000000 --- a/src/CCC/Batch_BatchManager_eCCC.hxx +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2007-2012 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_eCCC.hxx : emulation of CCC client for CCRT machines - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2010 - * Projet : PAL Salome - * - */ - -#ifndef _BATCHMANAGER_ECCC_H_ -#define _BATCHMANAGER_ECCC_H_ - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_eCCC : public BatchManager_eClient - { - public: - // Constructeur et destructeur - BatchManager_eCCC(const FactBatchManager * parent, const char * host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host - virtual ~BatchManager_eCCC(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - void buildBatchScript(const Job & job); - std::string getWallTime(const long edt); - - private: - - std::string getHomeDir(std::string tmpdir); - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/CCC/Batch_FactBatchManager_eCCC.cxx b/src/CCC/Batch_FactBatchManager_eCCC.cxx deleted file mode 100644 index 080d89f..0000000 --- a/src/CCC/Batch_FactBatchManager_eCCC.cxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2012 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_eCCC.cxx : - * - * Auteur : Bernard SECHER - CEA DEN - * Date : Avril 2010 - * Projet : PAL Salome - * - */ - -#include "Batch_BatchManager_eCCC.hxx" -#include "Batch_FactBatchManager_eCCC.hxx" - -namespace Batch { - - static FactBatchManager_eCCC sFBM_eCCC; - - // Constructeur - FactBatchManager_eCCC::FactBatchManager_eCCC() : FactBatchManager_eClient("eCCC") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_eCCC::~FactBatchManager_eCCC() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_eCCC::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_CCC on host '" << hostname << "'"); - return new BatchManager_eCCC(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eCCC::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_CCC on host '" << hostname << "'"); - return new BatchManager_eCCC(this, hostname, username, protocolType, mpiImpl); - } - -} diff --git a/src/CCC/Batch_FactBatchManager_eCCC.hxx b/src/CCC/Batch_FactBatchManager_eCCC.hxx deleted file mode 100644 index 9070abe..0000000 --- a/src/CCC/Batch_FactBatchManager_eCCC.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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_eCCC.hxx : - * - * Auteur : Bernard SECHER : CEA DEN - * Date : Avril 2010 - * Projet : PAL Salome - * - */ - -#ifndef _FACTBATCHMANAGER_eCCC_H_ -#define _FACTBATCHMANAGER_eCCC_H_ - -#include "Batch_Defines.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT FactBatchManager_eCCC : public FactBatchManager_eClient - { - public: - // Constructeur et destructeur - FactBatchManager_eCCC(); - virtual ~FactBatchManager_eCCC(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/CCC/Batch_JobInfo_eCCC.cxx b/src/CCC/Batch_JobInfo_eCCC.cxx deleted file mode 100644 index ff56a35..0000000 --- a/src/CCC/Batch_JobInfo_eCCC.cxx +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_eCCC.cxx : emulation of CCC client for CCRT machines - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2010 - * Projet : PAL Salome - * - */ - -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_JobInfo_eCCC.hxx" - -using namespace std; - -namespace Batch { - - - - // Constructeurs - JobInfo_eCCC::JobInfo_eCCC(int id, string logFile) : JobInfo() - { - // On remplit les membres _param et _env - ostringstream oss; - oss << id; - _param[ID] = oss.str(); - - // read status of job in log file - char line[128]; - ifstream fp(logFile.c_str(),ios::in); - fp.getline(line,80,'\n'); - - string sjobid, username, status; - fp >> sjobid; - fp >> username; - fp >> status; - - if (status == "PEND") { // Pending - _param[STATE] = QUEUED; - } else if (status == "PSUSP") { // Suspended while pending - _param[STATE] = PAUSED; - } else if (status == "RUN") { // Running - _param[STATE] = RUNNING; - } else if (status == "USUSP") { // Suspended while running - _param[STATE] = PAUSED; - } else if (status == "SSUSP") { // Suspended by CCC - _param[STATE] = PAUSED; - } else if (status == "DONE") { // Finished successfully - _param[STATE] = FINISHED; - } else if (status == "EXIT") { // Finished successfully - _param[STATE] = FINISHED; - } else if (status == "UNKWN") { // Lost contact - _param[STATE] = FAILED; - } else if (status == "ZOMBI") { // Zombie - _param[STATE] = FAILED; - } else { - cerr << "Unknown job state code: " << status << endl; - } - - if( status.find("RUN") != string::npos) - _running = true; - - } - - // Teste si un job est present en machine - bool JobInfo_eCCC::isRunning() const - { - return _running; - } - - - // Destructeur - JobInfo_eCCC::~JobInfo_eCCC() - { - // Nothing to do - } - - // Convertit une date HH:MM:SS en secondes - long JobInfo_eCCC::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_eCCC::__str__() const - { - ostringstream sst; - sst << " - -namespace Batch { - - class JobInfo_eCCC : public JobInfo - { - public: - // Constructeurs et destructeur - JobInfo_eCCC() : _running(false) {}; - JobInfo_eCCC(int id,std::string logFile); - virtual ~JobInfo_eCCC(); - - // Constructeur par recopie - JobInfo_eCCC(const JobInfo_eCCC & jinfo) : JobInfo(jinfo) {}; - - // Teste si un job est present en machine - virtual bool isRunning() const; - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - bool _running; // etat du job en machine - - private: - // Convertit une date HH:MM:SS en secondes - long HMStoLong(const std::string &); - - }; - -} - -#endif diff --git a/src/CCC/CMakeLists.txt b/src/CCC/CMakeLists.txt index 272eadb..55c1e27 100644 --- a/src/CCC/CMakeLists.txt +++ b/src/CCC/CMakeLists.txt @@ -20,9 +20,9 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST CCC/Batch_BatchManager_eCCC - CCC/Batch_FactBatchManager_eCCC - CCC/Batch_JobInfo_eCCC +SET(CLASS_LIST CCC/BatchManager_CCC + CCC/FactBatchManager_CCC + CCC/JobInfo_CCC ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) diff --git a/src/CCC/FactBatchManager_CCC.cxx b/src/CCC/FactBatchManager_CCC.cxx new file mode 100644 index 0000000..a065daa --- /dev/null +++ b/src/CCC/FactBatchManager_CCC.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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_CCC.cxx : + * + * Auteur : Bernard SECHER - CEA DEN + * Date : Avril 2010 + * Projet : PAL Salome + * + */ + +#include "BatchManager_CCC.hxx" +#include "FactBatchManager_CCC.hxx" + +namespace Batch { + + static FactBatchManager_CCC sFBM_CCC; + + // Constructeur + FactBatchManager_CCC::FactBatchManager_CCC() : FactBatchManager("CCC") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_CCC::~FactBatchManager_CCC() + { + // Nothing to do + } + + BatchManager * FactBatchManager_CCC::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + // MESSAGE("Building new BatchManager_CCC on host '" << hostname << "'"); + return new BatchManager_CCC(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/CCC/FactBatchManager_CCC.hxx b/src/CCC/FactBatchManager_CCC.hxx new file mode 100644 index 0000000..dafabae --- /dev/null +++ b/src/CCC/FactBatchManager_CCC.hxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2012 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_CCC.hxx : + * + * Auteur : Bernard SECHER : CEA DEN + * Date : Avril 2010 + * Projet : PAL Salome + * + */ + +#ifndef _FACTBATCHMANAGER_CCC_H_ +#define _FACTBATCHMANAGER_CCC_H_ + +#include "Defines.hxx" +#include "BatchManager.hxx" +#include "FactBatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT FactBatchManager_CCC : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_CCC(); + virtual ~FactBatchManager_CCC(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + }; + +} + +#endif diff --git a/src/CCC/JobInfo_CCC.cxx b/src/CCC/JobInfo_CCC.cxx new file mode 100644 index 0000000..510d967 --- /dev/null +++ b/src/CCC/JobInfo_CCC.cxx @@ -0,0 +1,127 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_CCC.cxx : emulation of CCC client for CCRT machines + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2010 + * Projet : PAL Salome + * + */ + +#include +#include +#include + +#include "Constants.hxx" +#include "Parametre.hxx" +#include "Environnement.hxx" +#include "JobInfo_CCC.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + + + // Constructeurs + JobInfo_CCC::JobInfo_CCC(int id, string output) : JobInfo() + { + // On remplit les membres _param et _nv + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + + // read status of job in log file + char line[128]; + istringstream fp(output); + fp.getline(line,80,'\n'); + + string sjobid, username, status; + fp >> sjobid; + fp >> username; + fp >> status; + + if (status == "PEND") { // Pending + _param[STATE] = QUEUED; + } else if (status == "PSUSP") { // Suspended while pending + _param[STATE] = PAUSED; + } else if (status == "RUN") { // Running + _param[STATE] = RUNNING; + } else if (status == "USUSP") { // Suspended while running + _param[STATE] = PAUSED; + } else if (status == "SSUSP") { // Suspended by CCC + _param[STATE] = PAUSED; + } else if (status == "DONE") { // Finished successfully + _param[STATE] = FINISHED; + } else if (status == "EXIT") { // Finished successfully + _param[STATE] = FINISHED; + } else if (status == "UNKWN") { // Lost contact + _param[STATE] = FAILED; + } else if (status == "ZOMBI") { // Zombie + _param[STATE] = FAILED; + } else { + LOG("Unknown job state code: " << status); + } + + if( status.find("RUN") != string::npos) + _running = true; + + } + + // Teste si un job est present en machine + bool JobInfo_CCC::isRunning() const + { + return _running; + } + + + // Destructeur + JobInfo_CCC::~JobInfo_CCC() + { + // Nothing to do + } + + // Convertit une date HH:MM:SS en secondes + long JobInfo_CCC::HMStoLong(const string & s) + { + long hour, min, sec; + + sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); + return ( ( ( hour * 60L ) + min ) * 60L ) + sec; + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_CCC::__str__() const + { + ostringstream sst; + sst << " + +namespace Batch { + + class JobInfo_CCC : public JobInfo + { + public: + // Constructeurs et destructeur + JobInfo_CCC() : _running(false) {}; + JobInfo_CCC(int id,std::string output); + virtual ~JobInfo_CCC(); + + // Constructeur par recopie + JobInfo_CCC(const JobInfo_CCC & jinfo) : JobInfo(jinfo) {}; + + // Teste si un job est present en machine + virtual bool isRunning() const; + + // Methodes pour l'interfacage avec Python (SWIG) + // TODO : supprimer ces methodes et transferer leur definitions dans SWIG + std::string __str__() const; // SWIG : affichage en Python + std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + + protected: + bool _running; // etat du job en machine + + private: + // Convertit une date HH:MM:SS en secondes + long HMStoLong(const std::string &); + + }; + +} + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e88e974..69ccb0e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,22 +20,18 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -# These macros are used to create the lists of source files and header files in global variables. -# If we move to cmake 2.6, this can be done more cleanly with the PARENT_SCOPE option. -MACRO(APPEND_TO_GLOBAL_VAR VAR) - SET(${VAR} ${${VAR}} ${ARGN} CACHE INTERNAL "") -ENDMACRO(APPEND_TO_GLOBAL_VAR) - MACRO(APPEND_CLASSES_TO_SRC_FILES) FOREACH(CLASS ${ARGV}) - APPEND_TO_GLOBAL_VAR(SRC_FILES_BUILD ${CLASS}.cxx) + LIST(APPEND SRC_FILES ${CLASS}.cxx) ENDFOREACH(CLASS ${ARGV}) + SET(SRC_FILES ${SRC_FILES} PARENT_SCOPE) ENDMACRO(APPEND_CLASSES_TO_SRC_FILES) MACRO(APPEND_CLASSES_TO_HDR_FILES) FOREACH(CLASS ${ARGV}) - APPEND_TO_GLOBAL_VAR(HDR_FILES_BUILD ${CLASS}.hxx) + LIST(APPEND HDR_FILES ${CLASS}.hxx) ENDFOREACH(CLASS ${ARGV}) + SET(HDR_FILES ${HDR_FILES} PARENT_SCOPE) ENDMACRO(APPEND_CLASSES_TO_HDR_FILES) IF (MSVC) @@ -54,7 +50,6 @@ add_subdirectory (CCC) add_subdirectory (LSF) add_subdirectory (PBS) add_subdirectory (SGE) -add_subdirectory (SSH) add_subdirectory (LoadLeveler) add_subdirectory (Slurm) @@ -63,40 +58,22 @@ IF (NOT WIN32) add_subdirectory (Vishnu) ENDIF (NOT WIN32) -# Make a copy of the built value and clear the built value for the next run of cmake -SET(SRC_FILES ${SRC_FILES_BUILD} CACHE INTERNAL "") -SET(SRC_FILES_BUILD CACHE INTERNAL "") - -SET(HDR_FILES ${HDR_FILES_BUILD} CACHE INTERNAL "") -SET(HDR_FILES_BUILD CACHE INTERNAL "") - - -add_library (Batch SHARED ${SRC_FILES}) +add_library(batch SHARED ${SRC_FILES}) include_directories(${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Core) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Local) -target_link_libraries(Batch ${PTHREAD_LIBRARY}) +target_link_libraries(batch ${PTHREAD_LIBRARY}) IF (WIN32) - target_link_libraries(Batch ws2_32) + target_link_libraries(batch ws2_32) ENDIF (WIN32) # If necessary, activate all warnings (useful for debugging and code cleaning) # add_definitions(-Wall -Werror -ansi -pedantic) -IF (BUILD_LSF_INTERFACE AND LSF_FOUND) - include_directories(${LSF_INCLUDE_DIR}) - target_link_libraries(Batch ${LSF_LIBRARY} ${LSF_BAT_LIBRARY}) -ENDIF (BUILD_LSF_INTERFACE AND LSF_FOUND) - -IF (BUILD_PBS_INTERFACE AND PBS_FOUND) - include_directories(${PBS_INCLUDE_DIR}) - target_link_libraries(Batch ${PBS_LIBRARY}) -ENDIF (BUILD_PBS_INTERFACE AND PBS_FOUND) - -INSTALL(TARGETS Batch DESTINATION lib) -INSTALL(FILES ${HDR_FILES} DESTINATION include/Batch) +INSTALL(TARGETS batch DESTINATION lib) +INSTALL(FILES ${HDR_FILES} DESTINATION include/libbatch) -IF (BUILD_PYTHON_WRAPPING AND Python_FOUND AND SWIG_FOUND) +IF (BUILD_PYTHON_WRAPPING AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) add_subdirectory (Python) -ENDIF (BUILD_PYTHON_WRAPPING AND Python_FOUND AND SWIG_FOUND) +ENDIF (BUILD_PYTHON_WRAPPING AND PYTHONINTERP_FOUND AND PYTHONLIBS_FOUND AND SWIG_FOUND) diff --git a/src/Core/APIInternalFailureException.cxx b/src/Core/APIInternalFailureException.cxx new file mode 100644 index 0000000..5170a7c --- /dev/null +++ b/src/Core/APIInternalFailureException.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2012 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 +// +/* + * APIInternalFailureException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 20 15:15:42 2003 + * Projet : Salome 2 + * + */ + +#include "APIInternalFailureException.hxx" +using namespace std; + +namespace Batch { + +} diff --git a/src/Core/APIInternalFailureException.hxx b/src/Core/APIInternalFailureException.hxx new file mode 100644 index 0000000..2e1a6d8 --- /dev/null +++ b/src/Core/APIInternalFailureException.hxx @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2012 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 +// +/* + * APIInternalFailureException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 20 15:15:41 2003 + * Projet : Salome 2 + * + */ + +#ifndef _APIINTERNALFAILUREEXCEPTION_H_ +#define _APIINTERNALFAILUREEXCEPTION_H_ + +#include "Defines.hxx" + +#include "GenericException.hxx" +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT APIInternalFailureException : public GenericException + { + public: + // Constructeur + APIInternalFailureException(std::string ch = "undefined") : GenericException("APIInternalFailureException", ch) {} + }; + +} + +#endif diff --git a/src/Core/BatchManager.cxx b/src/Core/BatchManager.cxx new file mode 100644 index 0000000..7ee7a56 --- /dev/null +++ b/src/Core/BatchManager.cxx @@ -0,0 +1,326 @@ +// Copyright (C) 2007-2012 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.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include +#include +#include + +#include "Constants.hxx" +#include "Job.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" +#include "Utils.hxx" +#include "NotYetImplementedException.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager::BatchManager(const Batch::FactBatchManager * parent, const char* host, + const char * username, + CommunicationProtocolType protocolType, const char* mpiImpl) + : _hostname(host), jobid_map(), _type(parent->getType()), + _protocol(CommunicationProtocol::getInstance(protocolType)), + _username(username), _mpiImpl(FactoryMpiImpl(mpiImpl)) + { + } + + + // Destructeur + BatchManager::~BatchManager() + { + delete _mpiImpl; + } + + string BatchManager::__repr__() const + { + ostringstream oss; + oss << ""; + return oss.str(); + } + + // Recupere le l'identifiant d'un job deja soumis au BatchManager + const JobId BatchManager::getJobIdByReference(const char * ref) + { + return JobId(this, ref); + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager::submitJob(const Job & job) + { + throw NotYetImplementedException("Method submitJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager::deleteJob(const JobId & jobid) + { + throw NotYetImplementedException("Method deleteJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : suspend un job en file d'attente + void BatchManager::holdJob(const JobId & jobid) + { + throw NotYetImplementedException("Method holdJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : relache un job suspendu + void BatchManager::releaseJob(const JobId & jobid) + { + throw NotYetImplementedException("Method releaseJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + throw NotYetImplementedException("Method alterJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager::alterJob(const JobId & jobid, const Parametre & param) + { + throw NotYetImplementedException("Method alterJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager::alterJob(const JobId & jobid, const Environnement & env) + { + throw NotYetImplementedException("Method alterJob not implemented by Batch Manager \"" + _type + "\""); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager::queryJob(const JobId & jobid) + { + throw NotYetImplementedException("Method queryJob not implemented by Batch Manager \"" + _type + "\""); + } + + const JobId BatchManager::addJob(const Job & job, const string & reference) + { + return JobId(this, reference); + } + + //! Wait for the end of a job + /*! + * This method is a simple way to wait for a job to end. It will query the job state at + * increasing intervals and return when the job is finished (whether successfully or not) or + * when the timeout is reached. This method is not intended to be generic. In many cases you + * will have to write your own loop to wait for the end of a job. + * \param jobid ID of the job to wait for. + * \param timeout Maximum time to wait in seconds. If -1 (default), wait indefinitely. + * \param initSleepTime Initial time in seconds between two queries for the job state (default is 1). + * \param maxSleepTime Maximum time in seconds between two queries for the job state (default is 600). + * \return The job state as returned by the last query. + */ + string BatchManager::waitForJobEnd(const JobId & jobid, long timeout, + long initSleepTime, long maxSleepTime) + { + int time = 0; + int sleeptime = initSleepTime; + bool testTimeout = (timeout > -1); + bool timeoutReached = (testTimeout && time >= timeout); + JobInfo jinfo = jobid.queryJob(); + string state = jinfo.getParametre()[STATE].str(); + while (!timeoutReached && state != FINISHED && state != FAILED) { + LOG("State is \"" << state << "\"" << ", sleeping " << sleeptime << "s..."); + Utils::sleep(sleeptime); + time += sleeptime; + timeoutReached = (testTimeout && time >= timeout); + sleeptime *= 2; + if (testTimeout && sleeptime > timeout - time) + sleeptime = timeout - time; + if (sleeptime > maxSleepTime) + sleeptime = maxSleepTime; + jinfo = jobid.queryJob(); + state = jinfo.getParametre()[STATE].str(); + } + LOG("State is \"" << state << "\""); + return state; + } + + + void BatchManager::exportInputFiles(const Job& job) + { + int status; + Parametre params = job.getParametre(); + const Versatile & V = params[INFILE]; + Versatile::const_iterator Vit; + + // Create remote directories + string logdir = string(params[WORKDIR]) + "/logs"; + status = _protocol.makeDirectory(logdir, _hostname, _username); + if (status) { + std::ostringstream oss; + oss << "Cannot create directory " << logdir << " on host " << _hostname; + oss << ". Return status is " << status; + throw RunTimeException(oss.str()); + } + + // Copy the file to execute into the remote working directory + string executeFile = params[EXECUTABLE]; + if (executeFile.size() != 0) { + status = _protocol.copyFile(executeFile, "", "", + params[WORKDIR], _hostname, _username); + if (status) { + std::ostringstream oss; + oss << "Cannot copy file " << executeFile << " on host " << _hostname; + oss << ". Return status is " << status; + throw RunTimeException(oss.str()); + } + +#ifdef WIN32 + if (_protocol.getType() != SH) { + // On Windows, we make the remote file executable afterward because + // pscp does not preserve access permissions on files + + string remoteExec = string(params[EXECUTABLE]); + remoteExec = remoteExec.substr(remoteExec.rfind("/") + 1, remoteExec.length()); + remoteExec = string(params[WORKDIR]) + "/" + remoteExec; + + string subCommand = string("chmod u+x ") + remoteExec; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + status = system(command.c_str()); + if (status) { + std::ostringstream oss; + oss << "Cannot change permissions of file " << remoteExec << " on host " << _hostname; + oss << ". Return status is " << status; + throw RunTimeException(oss.str()); + } + } +#endif + } + + // Copy input files into the remote working directory + for (Vit=V.begin() ; Vit!=V.end() ; Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple inputFile = cpt; + string remotePath = inputFile.getRemote(); + if (!Utils::isAbsolutePath(remotePath)) { + remotePath = params[WORKDIR].str() + "/" + remotePath; + } + status = _protocol.copyFile(inputFile.getLocal(), "", "", + remotePath, _hostname, _username); + if (status) { + std::ostringstream oss; + oss << "Cannot copy file " << inputFile.getLocal() << " on host " << _hostname; + oss << ". Return status is " << status; + throw RunTimeException(oss.str()); + } + } + + } + + void BatchManager::importOutputFiles( const Job & job, const string directory ) + { + Parametre params = job.getParametre(); + const Versatile & V = params[OUTFILE]; + Versatile::const_iterator Vit; + + // Create local result directory + int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", ""); + if (status) + LOG("Directory creation failed. Status is: " << status); + + for(Vit=V.begin(); Vit!=V.end(); Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple outputFile = cpt; + string remotePath = outputFile.getRemote(); + if (!Utils::isAbsolutePath(remotePath)) { + remotePath = params[WORKDIR].str() + "/" + remotePath; + } + string localPath = outputFile.getLocal(); + if (!Utils::isAbsolutePath(localPath)) { + localPath = directory + "/" + localPath; + } + status = _protocol.copyFile(remotePath, _hostname, _username, + localPath, "", ""); + if (status) + LOG("Copy command failed. Status is: " << status); + } + + // Copy logs + status = _protocol.copyFile(string(params[WORKDIR]) + string("/logs"), _hostname, _username, + directory, "", ""); + if (status) + LOG("Copy logs directory failed. Status is: " << status); + } + + bool BatchManager::importDumpStateFile( const Job & job, const string directory ) + { + Parametre params = job.getParametre(); + + // Create local result directory + int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", ""); + if (status) + LOG("Directory creation failed. Status is: " << status); + + bool ret = true; + status = _protocol.copyFile(string(params[WORKDIR]) + string("/dumpState*.xml"), _hostname, _username, + directory, "", ""); + if (status) { + LOG("Copy command failed. Status is: " << status); + ret = false; + } + return ret; + } + + MpiImpl *BatchManager::FactoryMpiImpl(string mpiImpl) + { + if(mpiImpl == "lam") + return new MpiImpl_LAM(); + else if(mpiImpl == "mpich1") + return new MpiImpl_MPICH1(); + else if(mpiImpl == "mpich2") + return new MpiImpl_MPICH2(); + else if(mpiImpl == "openmpi") + return new MpiImpl_OPENMPI(); + else if(mpiImpl == "ompi") + return new MpiImpl_OMPI(); + else if(mpiImpl == "slurm") + return new MpiImpl_SLURM(); + else if(mpiImpl == "prun") + return new MpiImpl_PRUN(); + else if(mpiImpl == "nompi") + return NULL; + else{ + ostringstream oss; + oss << mpiImpl << " : not yet implemented"; + throw RunTimeException(oss.str().c_str()); + } + } + + const CommunicationProtocol & BatchManager::getProtocol() const + { + return _protocol; + } + +} diff --git a/src/Core/BatchManager.hxx b/src/Core/BatchManager.hxx new file mode 100644 index 0000000..c5ad00d --- /dev/null +++ b/src/Core/BatchManager.hxx @@ -0,0 +1,102 @@ +// Copyright (C) 2007-2012 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.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _BATCHMANAGER_H_ +#define _BATCHMANAGER_H_ + +#include "Defines.hxx" + +#include +#include +#include "Job.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "InvalidArgumentException.hxx" +#include "CommunicationProtocol.hxx" +#include "MpiImpl.hxx" + +namespace Batch { + + class Job; + class JobId; + class JobInfo; + class FactBatchManager; + + class BATCH_EXPORT BatchManager + { + public: + // Constructeur et destructeur + BatchManager(const Batch::FactBatchManager * parent, const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi"); + virtual ~BatchManager(); + virtual std::string __repr__() const; + + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const std::string & ref); + virtual const Batch::JobId getJobIdByReference(const char * ref); + + // Methodes pour le controle des jobs : doivent etre implementees dans les classes filles + virtual const Batch::JobId submitJob(const Batch::Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const Batch::JobId & jobid); // retire un job du gestionnaire + virtual void holdJob(const Batch::JobId & jobid); // suspend un job en file d'attente + virtual void releaseJob(const Batch::JobId & jobid); // relache un job suspendu + virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param, const Batch::Environnement & env); // modifie un job en file d'attente + virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param); // modifie un job en file d'attente + virtual void alterJob(const Batch::JobId & jobid, const Batch::Environnement & env); // modifie un job en file d'attente + virtual Batch::JobInfo queryJob(const Batch::JobId & jobid); // renvoie l'etat du job + virtual const Batch::JobId addJob(const Batch::Job & job, const std::string & reference); // ajoute un nouveau job sans le soumettre + virtual std::string waitForJobEnd(const Batch::JobId & jobid, long timeout = -1, + long initSleepTime = 1, long maxSleepTime = 600); + virtual void importOutputFiles( const Job & job, const std::string directory ); + bool importDumpStateFile( const Job & job, const std::string directory ); + + // Get the underlying communication protocol + const CommunicationProtocol & getProtocol() const; + + protected: + std::string _hostname; // serveur ou tourne le BatchManager + // std::map< const std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis + std::map< std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis + const std::string & _type; + const CommunicationProtocol & _protocol; // protocol to access _hostname + const std::string _username; // username to access _hostname + MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script + + MpiImpl* FactoryMpiImpl(std::string mpiImpl); + void exportInputFiles(const Job & job); + + private: + + }; + +} + +#endif diff --git a/src/Core/BatchManagerCatalog.cxx b/src/Core/BatchManagerCatalog.cxx new file mode 100644 index 0000000..44d2844 --- /dev/null +++ b/src/Core/BatchManagerCatalog.cxx @@ -0,0 +1,108 @@ +// Copyright (C) 2007-2012 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 +// +/* + * BatchManagerCatalog.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * Modified by Renaud Barate, April 2009 + * + */ + +#include +#include +#include +#include "BatchManagerCatalog.hxx" +#include "FactBatchManager.hxx" +using namespace std; + +namespace Batch { + + // Constructeur + BatchManagerCatalog::BatchManagerCatalog() + { + pthread_mutex_init(&_mutex, NULL); + } + + // Destructeur + BatchManagerCatalog::~BatchManagerCatalog() + { + pthread_mutex_destroy(&_mutex); + } + + /** + * Returns the catalog singleton. + * We use the construct-on-first-use idiom here because otherwise there could be a problem with + * the initialization order between the factory singletons and this catalog. Note that since the + * destructors do not depend on the other objects, the order is not important for destruction. + */ + BatchManagerCatalog& BatchManagerCatalog::getInstance () { + static BatchManagerCatalog instance; + return instance; + } + + void BatchManagerCatalog::addFactBatchManager(const char * type, FactBatchManager * pFBM) + { + if (pFBM) { // *** section critique *** + pthread_mutex_lock(&_mutex); + _catalog[type] = pFBM; + pthread_mutex_unlock(&_mutex); + } + } + + bool BatchManagerCatalog::hasFactBatchManager(const char * type) + { + pthread_mutex_lock(&_mutex); + bool result = (_catalog.find(type) != _catalog.end()); + pthread_mutex_unlock(&_mutex); + return result; + } + + // Functor + FactBatchManager * BatchManagerCatalog::operator() (const char * type) + { + FactBatchManager * result = NULL; + pthread_mutex_lock(&_mutex); + if (_catalog.find(type) != _catalog.end()) result = _catalog[type]; + pthread_mutex_unlock(&_mutex); + return result; + } + + std::map * BatchManagerCatalog::dict() + { + return &_catalog; + } + + string BatchManagerCatalog::__repr__() const + { + ostringstream oss; + oss << "::const_iterator it = _catalog.begin(); it != _catalog.end(); it++, sep=", ") { + oss << sep << "'" << (*it).first << "' : '" << (*it).second->__repr__() << "'"; + } + oss << "}>"; + return oss.str(); + } + +} diff --git a/src/Core/BatchManagerCatalog.hxx b/src/Core/BatchManagerCatalog.hxx new file mode 100644 index 0000000..a26a64e --- /dev/null +++ b/src/Core/BatchManagerCatalog.hxx @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2012 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 +// +/* + * BatchManagerCatalog.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * Modified by Renaud Barate, April 2009 + * + */ + +#ifndef _CATALOG_H_ +#define _CATALOG_H_ + +#include "Defines.hxx" + +#include +#include +#include + +namespace Batch { + + class FactBatchManager; + + class BATCH_EXPORT BatchManagerCatalog + { + public: + static BatchManagerCatalog& getInstance(); + + void addFactBatchManager(const char * type, Batch::FactBatchManager * pFBM); + bool hasFactBatchManager(const char * type); + Batch::FactBatchManager * operator() (const char * type); + + virtual std::map * dict(); + virtual std::string __repr__() const; + + protected: + // Constructeur + BatchManagerCatalog(); + // Destructeur + virtual ~BatchManagerCatalog(); + + std::map _catalog; + pthread_mutex_t _mutex; + + private: + + // Forbid the use of copy constructor and assignment operator + BatchManagerCatalog(const BatchManagerCatalog & orig) {} + void operator=(const BatchManagerCatalog & orig) {} + + }; + +} + +#endif diff --git a/src/Core/Batch_APIInternalFailureException.cxx b/src/Core/Batch_APIInternalFailureException.cxx deleted file mode 100644 index 515b554..0000000 --- a/src/Core/Batch_APIInternalFailureException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * APIInternalFailureException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 20 15:15:42 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_APIInternalFailureException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_APIInternalFailureException.hxx b/src/Core/Batch_APIInternalFailureException.hxx deleted file mode 100644 index c1a7dd6..0000000 --- a/src/Core/Batch_APIInternalFailureException.hxx +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * APIInternalFailureException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 20 15:15:41 2003 - * Projet : Salome 2 - * - */ - -#ifndef _APIINTERNALFAILUREEXCEPTION_H_ -#define _APIINTERNALFAILUREEXCEPTION_H_ - -#include "Batch_Defines.hxx" - -#include "Batch_GenericException.hxx" -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT APIInternalFailureException : public GenericException - { - public: - // Constructeur - APIInternalFailureException(std::string ch = "undefined") : GenericException("APIInternalFailureException", ch) {} - }; - -} - -#endif diff --git a/src/Core/Batch_BatchManager.cxx b/src/Core/Batch_BatchManager.cxx deleted file mode 100644 index 3d0b8d9..0000000 --- a/src/Core/Batch_BatchManager.cxx +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright (C) 2007-2012 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.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include -#include -#include -#ifdef WIN32 -# include -#else -#include -# include -#endif - -#include "Batch_Constants.hxx" -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager.hxx" - -#ifdef WIN32 -#define sleep(seconds) Sleep((seconds)*1000) -#endif - -using namespace std; - -namespace Batch { - - // Constructeur -// BatchManager::BatchManager(string host) throw(InvalidArgumentException) : _hostname(host), jobid_map() -// { -// // On verifie que le hostname est correct -// if (!gethostbyname(_hostname.c_str())) { // hostname unknown from network -// string msg = "hostname \""; -// msg += _hostname; -// msg += "\" unknown from the network"; -// throw InvalidArgumentException(msg.c_str()); -// } -// } - BatchManager::BatchManager(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException) : _hostname(host), jobid_map(), _parent(parent) - { - /* -#ifdef WIN32 - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 2), &wsaData); // Initialize Winsock -#endif - - // On verifie que le hostname est correct - struct hostent* res = gethostbyname(_hostname.c_str()); - -#ifdef WIN32 - WSACleanup(); // Finalize Winsock -#endif - - if (!res) { // hostname unknown from network - string msg = "hostname \""; - msg += _hostname; - msg += "\" unknown from the network"; - throw InvalidArgumentException(msg.c_str()); - } - */ - } - - // Destructeur - BatchManager::~BatchManager() - { - // Nothing to do - } - - string BatchManager::__repr__() const - { - ostringstream oss; - oss << "getType() : "unknown (no factory)") << "' connected to server '" << _hostname << "'>"; - return oss.str(); - } - - // Recupere le l'identifiant d'un job deja soumis au BatchManager -// const JobId BatchManager::getJobIdByReference(const string & ref) -// { -// return JobId(this, ref); -// } - const JobId BatchManager::getJobIdByReference(const char * ref) - { - return JobId(this, ref); - } - -// // Methode pour le controle des jobs : soumet un job au gestionnaire -// const JobId BatchManager::submitJob(const Job & job) -// { -// static int idx = 0; -// //MEDMEM::STRING sst; -// ostringstream sst; -// sst << "Jobid_" << idx++; -// JobId id(this, sst.str()); -// return id; -// } - -// // Methode pour le controle des jobs : retire un job du gestionnaire -// void BatchManager::deleteJob(const JobId & jobid) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : suspend un job en file d'attente -// void BatchManager::holdJob(const JobId & jobid) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : relache un job suspendu -// void BatchManager::releaseJob(const JobId & jobid) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : modifie un job en file d'attente -// void BatchManager::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : modifie un job en file d'attente -// void BatchManager::alterJob(const JobId & jobid, const Parametre & param) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : modifie un job en file d'attente -// void BatchManager::alterJob(const JobId & jobid, const Environnement & env) -// { -// // Nothing to do -// } - -// // Methode pour le controle des jobs : renvoie l'etat du job -// JobInfo BatchManager::queryJob(const JobId & jobid) -// { -// return JobInfo(); -// } - - //! Wait for the end of a job - /*! - * This method is a simple way to wait for a job to end. It will query the job state at - * increasing intervals and return when the job is finished (whether successfully or not) or - * when the timeout is reached. This method is not intended to be generic. In many cases you - * will have to write your own loop to wait for the end of a job. - * \param jobid ID of the job to wait for. - * \param timeout Maximum time to wait in seconds. If -1 (default), wait indefinitely. - * \param initSleepTime Initial time in seconds between two queries for the job state (default is 1). - * \param maxSleepTime Maximum time in seconds between two queries for the job state (default is 600). - * \return The job state as returned by the last query. - */ - string BatchManager::waitForJobEnd(const JobId & jobid, long timeout, - long initSleepTime, long maxSleepTime) - { - int time = 0; - int sleeptime = initSleepTime; - bool testTimeout = (timeout > -1); - bool timeoutReached = (testTimeout && time >= timeout); - JobInfo jinfo = jobid.queryJob(); - string state = jinfo.getParametre()[STATE].str(); - cout << "State is \"" << state << "\""; - while (!timeoutReached && state != FINISHED && state != FAILED) { - cout << ", sleeping " << sleeptime << "s..." << endl; - sleep(sleeptime); - time += sleeptime; - timeoutReached = (testTimeout && time >= timeout); - sleeptime *= 2; - if (testTimeout && sleeptime > timeout - time) - sleeptime = timeout - time; - if (sleeptime > maxSleepTime) - sleeptime = maxSleepTime; - jinfo = jobid.queryJob(); - state = jinfo.getParametre()[STATE].str(); - cout << "State is \"" << state << "\""; - } - cout << endl; - return state; - } - -} diff --git a/src/Core/Batch_BatchManager.hxx b/src/Core/Batch_BatchManager.hxx deleted file mode 100644 index 1deb9ff..0000000 --- a/src/Core/Batch_BatchManager.hxx +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2007-2012 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.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _BATCHMANAGER_H_ -#define _BATCHMANAGER_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_InvalidArgumentException.hxx" - -namespace Batch { - - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - - class BATCH_EXPORT BatchManager - { - public: - // Constructeur et destructeur - //BatchManager(std::string host="localhost") throw(InvalidArgumentException); // connexion a la machine host - BatchManager(const Batch::FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException); // connexion a la machine host - virtual ~BatchManager(); - virtual std::string __repr__() const; - - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const std::string & ref); - virtual const Batch::JobId getJobIdByReference(const char * ref); - - // Methodes pour le controle des jobs : virtuelles pures - virtual const Batch::JobId submitJob(const Batch::Job & job) = 0; // soumet un job au gestionnaire - virtual void deleteJob(const Batch::JobId & jobid) = 0; // retire un job du gestionnaire - virtual void holdJob(const Batch::JobId & jobid) = 0; // suspend un job en file d'attente - virtual void releaseJob(const Batch::JobId & jobid) = 0; // relache un job suspendu - virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param, const Batch::Environnement & env) = 0; // modifie un job en file d'attente - virtual void alterJob(const Batch::JobId & jobid, const Batch::Parametre & param) = 0; // modifie un job en file d'attente - virtual void alterJob(const Batch::JobId & jobid, const Batch::Environnement & env) = 0; // modifie un job en file d'attente - virtual Batch::JobInfo queryJob(const Batch::JobId & jobid) = 0; // renvoie l'etat du job - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference) = 0; // ajoute un nouveau job sans le soumettre - virtual std::string waitForJobEnd(const Batch::JobId & jobid, long timeout = -1, - long initSleepTime = 1, long maxSleepTime = 600); - - protected: - std::string _hostname; // serveur ou tourne le BatchManager - // std::map< const std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis - std::map< std::string, const Batch::JobId * > jobid_map; // table des jobs deja soumis - const Batch::FactBatchManager * _parent; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_BatchManagerCatalog.cxx b/src/Core/Batch_BatchManagerCatalog.cxx deleted file mode 100644 index 8597688..0000000 --- a/src/Core/Batch_BatchManagerCatalog.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * BatchManagerCatalog.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * Modified by Renaud Barate, April 2009 - * - */ - -#include -#include -#include -#include "Batch_BatchManagerCatalog.hxx" -#include "Batch_FactBatchManager.hxx" -using namespace std; - -namespace Batch { - - // Constructeur - BatchManagerCatalog::BatchManagerCatalog() - { - pthread_mutex_init(&_mutex, NULL); - } - - // Destructeur - BatchManagerCatalog::~BatchManagerCatalog() - { - pthread_mutex_destroy(&_mutex); - } - - /** - * Returns the catalog singleton. - * We use the construct-on-first-use idiom here because otherwise there could be a problem with - * the initialization order between the factory singletons and this catalog. Note that since the - * destructors do not depend on the other objects, the order is not important for destruction. - */ - BatchManagerCatalog& BatchManagerCatalog::getInstance () { - static BatchManagerCatalog instance; - return instance; - } - - void BatchManagerCatalog::addFactBatchManager(const char * type, FactBatchManager * pFBM) - { - if (pFBM) { // *** section critique *** - pthread_mutex_lock(&_mutex); - _catalog[type] = pFBM; - pthread_mutex_unlock(&_mutex); - } - } - - bool BatchManagerCatalog::hasFactBatchManager(const char * type) - { - pthread_mutex_lock(&_mutex); - bool result = (_catalog.find(type) != _catalog.end()); - pthread_mutex_unlock(&_mutex); - return result; - } - - // Functor - FactBatchManager * BatchManagerCatalog::operator() (const char * type) - { - FactBatchManager * result = NULL; - pthread_mutex_lock(&_mutex); - if (_catalog.find(type) != _catalog.end()) result = _catalog[type]; - pthread_mutex_unlock(&_mutex); - return result; - } - - std::map * BatchManagerCatalog::dict() - { - return &_catalog; - } - - string BatchManagerCatalog::__repr__() const - { - ostringstream oss; - oss << "::const_iterator it = _catalog.begin(); it != _catalog.end(); it++, sep=", ") { - oss << sep << "'" << (*it).first << "' : '" << (*it).second->__repr__() << "'"; - } - oss << "}>"; - return oss.str(); - } - -} diff --git a/src/Core/Batch_BatchManagerCatalog.hxx b/src/Core/Batch_BatchManagerCatalog.hxx deleted file mode 100644 index dad4388..0000000 --- a/src/Core/Batch_BatchManagerCatalog.hxx +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * BatchManagerCatalog.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * Modified by Renaud Barate, April 2009 - * - */ - -#ifndef _CATALOG_H_ -#define _CATALOG_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include - -namespace Batch { - - class FactBatchManager; - - class BATCH_EXPORT BatchManagerCatalog - { - public: - static BatchManagerCatalog& getInstance(); - - void addFactBatchManager(const char * type, Batch::FactBatchManager * pFBM); - bool hasFactBatchManager(const char * type); - Batch::FactBatchManager * operator() (const char * type); - - virtual std::map * dict(); - virtual std::string __repr__() const; - - protected: - // Constructeur - BatchManagerCatalog(); - // Destructeur - virtual ~BatchManagerCatalog(); - - std::map _catalog; - pthread_mutex_t _mutex; - - private: - - // Forbid the use of copy constructor and assignment operator - BatchManagerCatalog(const BatchManagerCatalog & orig) {} - void operator=(const BatchManagerCatalog & orig) {} - - }; - -} - -#endif diff --git a/src/Core/Batch_BatchManager_eClient.cxx b/src/Core/Batch_BatchManager_eClient.cxx deleted file mode 100644 index 92162b2..0000000 --- a/src/Core/Batch_BatchManager_eClient.cxx +++ /dev/null @@ -1,380 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.cxx : emulation of LSF client -* -* Auteur : Bernard SECHER - CEA DEN -* Mail : mailto:bernard.secher@cea.fr -* Date : Thu Apr 24 10:17:22 2008 -* Projet : PAL Salome -* -*/ - -#include -#include - -#include -#include -#include -#include - -#ifdef WIN32 -#include -#include -#else -#include -#endif - -#include - -#include "Batch_Constants.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_Utils.hxx" - -#ifdef MSVC -#define EXISTS(path) _access_s(path, 0) == 0 -#else -#define EXISTS(path) access(path, F_OK) == 0 -#endif - -using namespace std; - - -namespace Batch { - - BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host, - const char * username, - CommunicationProtocolType protocolType, const char* mpiImpl) - : BatchManager(parent, host), _protocol(CommunicationProtocol::getInstance(protocolType)), - _username(username) - { - // instanciation of mpi implementation needed to launch executable in batch script - _mpiImpl = FactoryMpiImpl(mpiImpl); - } - - // Destructeur - BatchManager_eClient::~BatchManager_eClient() - { - if (_mpiImpl) - delete _mpiImpl; - } - - void BatchManager_eClient::exportInputFiles(const Job& job) - { - int status; - Parametre params = job.getParametre(); - const Versatile & V = params[INFILE]; - Versatile::const_iterator Vit; - - status = _protocol.makeDirectory(string(params[TMPDIR]) + "/logs", _hostname, _username); - if(status) { - std::ostringstream oss; - oss << status; - std::string ex_mess("Error of connection on remote host ! status = "); - ex_mess += oss.str(); - throw EmulationException(ex_mess.c_str()); - } - - // Second step : copy fileToExecute into - // batch tmp files directory - string executeFile = params[EXECUTABLE]; - if (executeFile.size() != 0) { - status = _protocol.copyFile(executeFile, "", "", - params[TMPDIR], _hostname, _username); - if(status) { - std::ostringstream oss; - oss << status; - std::string ex_mess("Error of connection on remote host ! status = "); - ex_mess += oss.str(); - throw EmulationException(ex_mess.c_str()); - } - -#ifdef WIN32 - // On Windows, we make the remote file executable afterward because - // pscp does not preserve access permissions on files - - string executable = string(params[EXECUTABLE]); - executable = executable.substr(executable.rfind("\\") + 1,executable.length()); - - string subCommand = string("chmod u+x ") + string(params[TMPDIR]) + "/" + executable; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) { - std::ostringstream oss; - oss << status; - std::string ex_mess("Error of connection on remote host ! status = "); - ex_mess += oss.str(); - throw EmulationException(ex_mess.c_str()); - } -#endif - } - - // Third step : copy filesToExportList into - // batch tmp files directory - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple inputFile = cpt; - status = _protocol.copyFile(inputFile.getLocal(), "", "", - inputFile.getRemote(), _hostname, _username); - if(status) { - std::ostringstream oss; - oss << status; - std::string ex_mess("Error of connection on remote host ! status = "); - ex_mess += oss.str(); - throw EmulationException(ex_mess.c_str()); - } - } - - } - - void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) - { - Parametre params = job.getParametre(); - const Versatile & V = params[OUTFILE]; - Versatile::const_iterator Vit; - - // Create local result directory - int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", ""); - if (status) { - string mess("Directory creation failed. Status is :"); - ostringstream status_str; - status_str << status; - mess += status_str.str(); - cerr << mess << endl; - } - - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple outputFile = cpt; - string localPath = outputFile.getLocal(); - if (!Utils::isAbsolutePath(localPath)) { - localPath = directory + "/" + localPath; - } - status = _protocol.copyFile(outputFile.getRemote(), _hostname, _username, - localPath, "", ""); - 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 :"); - ostringstream status_str; - status_str << status; - mess += status_str.str(); - cerr << mess << endl; - } - } - - // Copy logs - status = _protocol.copyFile(string(params[TMPDIR]) + string("/logs"), _hostname, _username, - directory, "", ""); - if (status) { - std::string mess("Copy logs directory failed ! status is :"); - ostringstream status_str; - status_str << status; - mess += status_str.str(); - cerr << mess << endl; - } - - } - - bool BatchManager_eClient::importDumpStateFile( const Job & job, const string directory ) - { - Parametre params = job.getParametre(); - - // Create local result directory - int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", ""); - if (status) { - string mess("Directory creation failed. Status is :"); - ostringstream status_str; - status_str << status; - mess += status_str.str(); - cerr << mess << endl; - } - - bool ret = true; - status = _protocol.copyFile(string(params[TMPDIR]) + string("/dumpState*.xml"), _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 :"); - ostringstream status_str; - status_str << status; - mess += status_str.str(); - cerr << mess << endl; - ret = false; - } - return ret; - } - - MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) - { - if(mpiImpl == "lam") - return new MpiImpl_LAM(); - else if(mpiImpl == "mpich1") - return new MpiImpl_MPICH1(); - else if(mpiImpl == "mpich2") - return new MpiImpl_MPICH2(); - else if(mpiImpl == "openmpi") - return new MpiImpl_OPENMPI(); - else if(mpiImpl == "ompi") - return new MpiImpl_OMPI(); - else if(mpiImpl == "slurm") - return new MpiImpl_SLURM(); - else if(mpiImpl == "prun") - return new MpiImpl_PRUN(); - else if(mpiImpl == "nompi") - return NULL; - else{ - ostringstream oss; - oss << mpiImpl << " : not yet implemented"; - throw EmulationException(oss.str().c_str()); - } - } - - /** - * This method generates a temporary file name with the pattern "/-XXXXXX" where - * is the directory for temporary files (see BatchManager_eClient::getTmpDir()) and the - * X's are replaced by random characters. Note that this method is less secure than - * BatchManager_eClient::createAndOpenTemporaryFile, so use the latter whenever possible. - * \param prefix the prefix to use for the temporary file. - * \return a name usable for a temporary file. - */ - string BatchManager_eClient::generateTemporaryFileName(const string & prefix) - { - string fileName = getTmpDir() + "/" + prefix + "-XXXXXX"; - char randstr[7]; - - do { - sprintf(randstr, "%06d", rand() % 1000000); - fileName.replace(fileName.size()-6, 6, randstr); - } while (EXISTS(fileName.c_str())); - - return fileName; - } - - /** - * This method creates a temporary file and opens an output stream to write into this file. - * The file is created with the pattern "/-XXXXXX" where is the directory - * for temporary files (see BatchManager_eClient::getTmpDir()) and the X's are replaced by random - * characters. The caller is responsible for closing and deleting the file when it is no more used. - * \param prefix the prefix to use for the temporary file. - * \param outputStream an output stream that will be opened for writing in the temporary file. If - * the stream is already open, it will be closed first. - * \return the name of the created file. - */ - string BatchManager_eClient::createAndOpenTemporaryFile(const string & prefix, ofstream & outputStream) - { - if (outputStream.is_open()) - outputStream.close(); - -#ifdef WIN32 - - string fileName = generateTemporaryFileName(prefix); - // Open the file as binary to avoid problems with Windows newlines - outputStream.open(fileName.c_str(), ios_base::binary | ios_base::out); - -#else - - string fileName = getTmpDir() + "/" + prefix + "-XXXXXX"; - char * buf = new char[fileName.size()+1]; - fileName.copy(buf, fileName.size()); - buf[fileName.size()] = '\0'; - - int fd = mkstemp(buf); - 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 - -#endif - - if (outputStream.fail()) - throw RunTimeException(string("Can't open temporary file ") + fileName); - - return fileName; - } - - /** - * This method finds the name of the directory to use for temporary files in libBatch. This name - * is /libBatch--XXXXXX. is found by looking for environment - * variables TEMP, TMP, TEMPDIR, TMPDIR, and defaults to "/tmp" if none of them is defined. - * is found by looking for environment variables USER and USERNAME, and defaults to - * "unknown". XXXXXX represents random characters. The directory name is generated only once for - * each BatchManager_eClient instance, and the directory is created at this moment. Subsequent - * calls will always return the same path and the existence of the directory will not be - * rechecked. - * \return the name of the directory to use for temporary files. - */ - const std::string & BatchManager_eClient::getTmpDir() - { - if (tmpDirName.empty()) { - const char * baseDir = getenv("TEMP"); - if (baseDir == NULL) baseDir = getenv("TMP"); - if (baseDir == NULL) baseDir = getenv("TEMPDIR"); - if (baseDir == NULL) baseDir = getenv("TMPDIR"); - if (baseDir == NULL) baseDir = "/tmp"; - - const char * userName = getenv("USER"); - if (userName == NULL) userName = getenv("USERNAME"); - if (userName == NULL) userName = "unknown"; - - string baseName = string(baseDir) + "/libBatch-" + userName + "-XXXXXX"; - srand(time(NULL)); - -#ifdef WIN32 - - char randstr[7]; - do { - sprintf(randstr, "%06d", rand() % 1000000); - baseName.replace(baseName.size()-6, 6, randstr); - } while (EXISTS(baseName.c_str())); - if (_mkdir(baseName.c_str()) != 0) - throw RunTimeException(string("Can't create temporary directory ") + baseName); - tmpDirName = baseName; - -#else - - char * buf = new char[baseName.size() + 1]; - baseName.copy(buf, baseName.size()); - buf[baseName.size()] = '\0'; - if (mkdtemp(buf) == NULL) { - delete[] buf; - throw RunTimeException(string("Can't create temporary directory ") + baseName); - } - tmpDirName = buf; - delete[] buf; - -#endif - - } - - return tmpDirName; - } - -} diff --git a/src/Core/Batch_BatchManager_eClient.hxx b/src/Core/Batch_BatchManager_eClient.hxx deleted file mode 100644 index bc4396b..0000000 --- a/src/Core/Batch_BatchManager_eClient.hxx +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.hxx : emulation of client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#ifndef _BATCHMANAGER_eClient_H_ -#define _BATCHMANAGER_eClient_H_ - -#include "Batch_Defines.hxx" -#include "Batch_MpiImpl.hxx" -#include "Batch_BatchManager.hxx" -#include "Batch_EmulationException.hxx" -#include "Batch_CommunicationProtocol.hxx" - -#include - -namespace Batch { - - class Job; - - class BATCH_EXPORT BatchManager_eClient : virtual public BatchManager - { - public: - // Constructeur et destructeur - BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char* mpiImpl="mpich1"); - virtual ~BatchManager_eClient(); - virtual void importOutputFiles( const Job & job, const std::string directory ); - bool importDumpStateFile( const Job & job, const std::string directory ); - - protected: - const CommunicationProtocol & _protocol; // protocol to access _hostname - const std::string _username; // username to access _hostname - MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script - - std::string generateTemporaryFileName(const std::string & prefix); - std::string createAndOpenTemporaryFile(const std::string & prefix, std::ofstream & outputStream); - MpiImpl* FactoryMpiImpl(std::string mpiImpl); - void exportInputFiles(const Job & job); - const std::string & getTmpDir(); - - private: - std::string tmpDirName; // Path to the directory for temporary files - - }; - -} - -#endif diff --git a/src/Core/Batch_BoolType.cxx b/src/Core/Batch_BoolType.cxx deleted file mode 100644 index a5dec46..0000000 --- a/src/Core/Batch_BoolType.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * BoolType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include -#include -#include "Batch_BoolType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string BoolType::affiche() const - { - return _data ? string("true") : string("false"); - } - - // Operateur d'affectation - BoolType & BoolType::operator =(bool b) - { - _data = b; - return *this; - } - - // Conversion en bool - BoolType::operator bool() const - { - return this->_data; - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * BoolType::clone() const - { - BoolType * pB = new BoolType(this->_data); - assert(pB != 0); - return pB; - } - -} diff --git a/src/Core/Batch_BoolType.hxx b/src/Core/Batch_BoolType.hxx deleted file mode 100644 index 7695320..0000000 --- a/src/Core/Batch_BoolType.hxx +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * BoolType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _BOOLTYPE_H_ -#define _BOOLTYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" - -namespace Batch { - - class BATCH_EXPORT BoolType : public GenericType - { - public: - // Constructeur - BoolType(const bool b=false) : _data(b) {} - - // Conversion en chaine - virtual std::string affiche() const; - - // Operateur d'affectation - virtual BoolType & operator =(bool); - - // Conversion en bool - virtual operator bool() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - bool _data; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_CharType.cxx b/src/Core/Batch_CharType.cxx deleted file mode 100644 index f4e5da1..0000000 --- a/src/Core/Batch_CharType.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * CharType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include -#include -#include "Batch_CharType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string CharType::affiche() const - { - return string(1, _data); - } - - // Operateur d'affectation - CharType & CharType::operator =(char c) - { - _data = c; - return *this; - } - - // Conversion en char - CharType::operator char() const - { - return this->_data; - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * CharType::clone() const - { - CharType * pC = new CharType(this->_data); - assert(pC != 0); - return pC; - } - -} diff --git a/src/Core/Batch_CharType.hxx b/src/Core/Batch_CharType.hxx deleted file mode 100644 index 864e181..0000000 --- a/src/Core/Batch_CharType.hxx +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * CharType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _CHARTYPE_H_ -#define _CHARTYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" - -namespace Batch { - - class BATCH_EXPORT CharType : public GenericType - { - public: - // Constructeur - CharType(const char c=0) : _data(c) {} - - // Conversion en chaine - virtual std::string affiche() const; - - // Operateur d'affectation - virtual CharType & operator =(char); - - // Conversion en char - virtual operator char() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - char _data; - - private: - - }; - -} - -#endif - diff --git a/src/Core/Batch_CommunicationProtocol.cxx b/src/Core/Batch_CommunicationProtocol.cxx deleted file mode 100644 index 8a3ef6a..0000000 --- a/src/Core/Batch_CommunicationProtocol.cxx +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2007-2012 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 - -#include - -#include "Batch_CommunicationProtocol.hxx" -#ifdef HAS_RSH - #include "Batch_CommunicationProtocolRSH.hxx" -#endif -#ifdef HAS_SH - #include "Batch_CommunicationProtocolSH.hxx" -#endif -#ifdef HAS_SSH - #include "Batch_CommunicationProtocolSSH.hxx" -#endif -#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; - } - - string CommunicationProtocol::getMakeDirectorySubCommand(const string & path) const - { - return string("mkdir -p ") + 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; - } - - int CommunicationProtocol::makeDirectory(const std::string & path, - const std::string & host, - const std::string & user) const - { - string command = getExecCommand(getMakeDirectorySubCommand(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; - - virtual int makeDirectory(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; - - virtual std::string getMakeDirectorySubCommand(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 deleted file mode 100644 index 99f28ba..0000000 --- a/src/Core/Batch_CommunicationProtocolRSH.cxx +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright (C) 2007-2012 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("-r"); - 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 deleted file mode 100644 index e2a475d..0000000 --- a/src/Core/Batch_CommunicationProtocolRSH.hxx +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2007-2012 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 deleted file mode 100644 index 3ef7180..0000000 --- a/src/Core/Batch_CommunicationProtocolSH.cxx +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (C) 2007-2012 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); -#ifndef WIN32 - cmd.push_back("-r"); -#endif - cmd.push_back(fixPath(sourcePath)); - cmd.push_back(fixPath(destinationPath)); - return cmd; - } - - string CommunicationProtocolSH::getRemoveSubCommand(const string & path) const - { - return string(RM_COMMAND) + " " + fixPath(path); - } - - string CommunicationProtocolSH::getMakeDirectorySubCommand(const string & path) const - { - string subCommand = MKDIR_COMMAND; -#ifndef WIN32 - subCommand += " -p"; -#endif - subCommand += " " + fixPath(path); - return subCommand; - } - -} diff --git a/src/Core/Batch_CommunicationProtocolSH.hxx b/src/Core/Batch_CommunicationProtocolSH.hxx deleted file mode 100644 index 46e0d8c..0000000 --- a/src/Core/Batch_CommunicationProtocolSH.hxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2012 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; - - protected: - - std::string getRemoveSubCommand(const std::string & path) const; - - std::string getMakeDirectorySubCommand(const std::string & path) const; - - std::string fixPath(const std::string & path) const; - - }; - -} - -#endif diff --git a/src/Core/Batch_CommunicationProtocolSSH.cxx b/src/Core/Batch_CommunicationProtocolSSH.cxx deleted file mode 100644 index deac559..0000000 --- a/src/Core/Batch_CommunicationProtocolSSH.cxx +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (C) 2007-2012 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 + ":"; - } -#ifndef WIN32 - fullSource += "'"; -#endif - fullSource += sourcePath; -#ifndef WIN32 - fullSource += "'"; -#endif - - string fullDestination; - if (destinationHost.size() != 0) { - if (destinationUser.size() != 0) { - fullDestination += destinationUser + "@"; - } - fullDestination += destinationHost + ":"; - } -#ifndef WIN32 - fullDestination += "'"; -#endif - fullDestination += destinationPath; -#ifndef WIN32 - fullDestination += "'"; -#endif - - // 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("-r"); - cmd.push_back(fullSource); - cmd.push_back(fullDestination); - - return cmd; - } - -} diff --git a/src/Core/Batch_CommunicationProtocolSSH.hxx b/src/Core/Batch_CommunicationProtocolSSH.hxx deleted file mode 100644 index 24743ff..0000000 --- a/src/Core/Batch_CommunicationProtocolSSH.hxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2012 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_ConnexionFailureException.cxx b/src/Core/Batch_ConnexionFailureException.cxx deleted file mode 100644 index 0c6b97c..0000000 --- a/src/Core/Batch_ConnexionFailureException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * ConnexionFailureException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 13 11:24:31 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_ConnexionFailureException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_ConnexionFailureException.hxx b/src/Core/Batch_ConnexionFailureException.hxx deleted file mode 100644 index d36dd33..0000000 --- a/src/Core/Batch_ConnexionFailureException.hxx +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * ConnexionFailureException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 13 11:24:31 2003 - * Projet : Salome 2 - * - */ - -#ifndef _CONNEXIONFAILUREEXCEPTION_H_ -#define _CONNEXIONFAILUREEXCEPTION_H_ - -#include "Batch_Defines.hxx" - - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT ConnexionFailureException : public GenericException - { - public: - // Constructeur - ConnexionFailureException(std::string ch = "undefined") : GenericException("ConnexionFailureException", ch) {} - - }; - -} - -#endif - diff --git a/src/Core/Batch_Constants.cxx b/src/Core/Batch_Constants.cxx deleted file mode 100644 index 778a3c7..0000000 --- a/src/Core/Batch_Constants.cxx +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2007-2012 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_Constants.cxx : - * - * Auteur : Renaud BARATE - EDF R&D - * Date : January 2010 - * - */ - -#include "Batch_Constants.hxx" - -namespace Batch { - - // Definition of the string constants (keys for the parameter map) - def_Constant(ACCOUNT); - def_Constant(ARGUMENTS); - def_Constant(CHECKPOINT); - def_Constant(CKPTINTERVAL); - def_Constant(CREATIONTIME); - def_Constant(EGROUP); - def_Constant(ELIGIBLETIME); - def_Constant(ENDTIME); - def_Constant(EUSER); - def_Constant(EXECUTABLE); - def_Constant(EXECUTIONHOST); - def_Constant(EXITCODE); - def_Constant(HOLD); - def_Constant(ID); - def_Constant(INFILE); - def_Constant(MAIL); - def_Constant(MAXCPUTIME); - def_Constant(MAXDISKSIZE); - def_Constant(MAXRAMSIZE); - def_Constant(MAXWALLTIME); - def_Constant(MODIFICATIONTIME); - def_Constant(NAME); - def_Constant(NBPROC); - def_Constant(OUTFILE); - def_Constant(PID); - def_Constant(QUEUE); - def_Constant(QUEUEDTIME); - def_Constant(SERVER); - def_Constant(STARTTIME); - def_Constant(STATE); - def_Constant(TEXT); - def_Constant(TMPDIR); - def_Constant(USEDCPUTIME); - def_Constant(USEDDISKSIZE); - def_Constant(USEDRAMSIZE); - def_Constant(USEDWALLTIME); - def_Constant(USER); - def_Constant(WORKDIR); - def_Constant(HOMEDIR); - def_Constant(EXCLUSIVE); - - // These constants define the status of a job (parameter STATE); - def_Constant(CREATED); - def_Constant(IN_PROCESS); - def_Constant(QUEUED); - def_Constant(RUNNING); - def_Constant(PAUSED); - def_Constant(FINISHED); - def_Constant(FAILED); - -} diff --git a/src/Core/Batch_Constants.hxx b/src/Core/Batch_Constants.hxx deleted file mode 100644 index 332a163..0000000 --- a/src/Core/Batch_Constants.hxx +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2007-2012 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_Constants.hxx : - * - * Auteur : Renaud BARATE - EDF R&D - * Date : January 2010 - * - */ - -#ifndef _CONSTANTS_H_ -#define _CONSTANTS_H_ - -#include - -#include "Batch_Defines.hxx" - -// These macros simplify the creation of new string constants for keys and -// values in parameters map. -// TODO: replace those static declarations by an external description file (XML for instance) -#define decl_extern_Constant(constant) extern BATCH_EXPORT const std::string constant -#define def_Constant(constant) const std::string constant = #constant - -namespace Batch { - - // Declaration of the keys for the parameter map - decl_extern_Constant(ACCOUNT); - decl_extern_Constant(ARGUMENTS); - decl_extern_Constant(CHECKPOINT); - decl_extern_Constant(CKPTINTERVAL); - decl_extern_Constant(CREATIONTIME); - decl_extern_Constant(EGROUP); - decl_extern_Constant(ELIGIBLETIME); - decl_extern_Constant(ENDTIME); - decl_extern_Constant(EUSER); - decl_extern_Constant(EXECUTABLE); - decl_extern_Constant(EXECUTIONHOST); - decl_extern_Constant(EXITCODE); - decl_extern_Constant(HOLD); - decl_extern_Constant(ID); - decl_extern_Constant(INFILE); - decl_extern_Constant(MAIL); - decl_extern_Constant(MAXCPUTIME); - decl_extern_Constant(MAXDISKSIZE); - decl_extern_Constant(MAXRAMSIZE); - decl_extern_Constant(MAXWALLTIME); - decl_extern_Constant(MODIFICATIONTIME); - decl_extern_Constant(NAME); - decl_extern_Constant(NBPROC); - decl_extern_Constant(OUTFILE); - decl_extern_Constant(PID); - decl_extern_Constant(QUEUE); - decl_extern_Constant(QUEUEDTIME); - decl_extern_Constant(SERVER); - decl_extern_Constant(STARTTIME); - decl_extern_Constant(STATE); - decl_extern_Constant(TEXT); - decl_extern_Constant(TMPDIR); - decl_extern_Constant(USEDCPUTIME); - decl_extern_Constant(USEDDISKSIZE); - decl_extern_Constant(USEDRAMSIZE); - decl_extern_Constant(USEDWALLTIME); - decl_extern_Constant(USER); - decl_extern_Constant(WORKDIR); - decl_extern_Constant(HOMEDIR); - decl_extern_Constant(EXCLUSIVE); - - // These constants define the status of a job (parameter STATE) - decl_extern_Constant(CREATED); - decl_extern_Constant(IN_PROCESS); - decl_extern_Constant(QUEUED); - decl_extern_Constant(RUNNING); - decl_extern_Constant(PAUSED); - decl_extern_Constant(FINISHED); - decl_extern_Constant(FAILED); - -} - -#endif diff --git a/src/Core/Batch_Couple.cxx b/src/Core/Batch_Couple.cxx deleted file mode 100644 index d1e49f3..0000000 --- a/src/Core/Batch_Couple.cxx +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Couple.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Dec 9 15:00:35 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_Couple.hxx" -using namespace std; - -namespace Batch { - - // Operateur d'affectation - Couple & Couple::operator =(const Couple & C) - { - _local = C._local; - _remote = C._remote; - return *this; - } - - // Conversion en chaine - string Couple::str() const - { - string res; - res = "Couple(local : "; - res += _local; - res += ", remote : "; - res += _remote; - res += ")"; - return res; - } - - // Operateur pour l'affichage sur un stream - ostream & operator << (ostream & os, const Couple & cp) - { - return os << cp.str(); - } - -} diff --git a/src/Core/Batch_Couple.hxx b/src/Core/Batch_Couple.hxx deleted file mode 100644 index ec7238f..0000000 --- a/src/Core/Batch_Couple.hxx +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Couple.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Dec 9 15:00:35 2003 - * Projet : Salome 2 - * - */ - -#ifndef _COUPLE_H_ -#define _COUPLE_H_ - -#include "Batch_Defines.hxx" - -#include - -namespace Batch { - - class BATCH_EXPORT Couple - { - public: - // Constructeur standard - Couple(const std::string & local="", const std::string & remote="") : _local(local), _remote(remote) {} - - // Constructeur par recopie - Couple(const Couple & C) : _local(C._local), _remote(C._remote) {} - - // Destructeur - virtual ~Couple() {} - - // Operateur pour l'affichage sur un stream - BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Couple & cp); - - // Operateur d'affectation - virtual Couple & operator =(const Couple &); - - // Conversion en chaine - virtual std::string str() const; - - // Accesseurs - virtual std::string getLocal() const { return _local; } - virtual std::string getRemote() const { return _remote; } - - protected: - std::string _local; // chemin d'acces au fichier local - std::string _remote; // chemin d'acees au fichier distant - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_CoupleType.cxx b/src/Core/Batch_CoupleType.cxx deleted file mode 100644 index 20f1852..0000000 --- a/src/Core/Batch_CoupleType.cxx +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * CoupleType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Dec 9 14:51:53 2003 - * Projet : Salome 2 - * - */ - -#include -#include "Batch_CoupleType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string CoupleType::affiche() const - { - return _data.str(); - } - - // Operateur d'affectation - CoupleType & CoupleType::operator =(const Couple & C) - { - _data = C; - return *this; - } - - // Conversion en char - CoupleType::operator Couple() const - { - return _data; - } - - // Conversion en chaine - CoupleType::operator string() const - { - return _data.str(); - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * CoupleType::clone() const - { - CoupleType * pC = new CoupleType(this->_data); - assert(pC != 0); - return pC; - } - -} - diff --git a/src/Core/Batch_CoupleType.hxx b/src/Core/Batch_CoupleType.hxx deleted file mode 100644 index 9b66562..0000000 --- a/src/Core/Batch_CoupleType.hxx +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * CoupleType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Dec 9 14:51:53 2003 - * Projet : Salome 2 - * - */ - -#ifndef _COUPLETYPE_H_ -#define _COUPLETYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" -#include "Batch_Couple.hxx" - -namespace Batch { - - class BATCH_EXPORT CoupleType : public GenericType - { - public: - // Constructeur - CoupleType(const Couple & C) : _data(C) {} - - // Conversion en chaine - virtual std::string affiche() const; - virtual operator std::string() const; - - // Operateur d'affectation - virtual CoupleType & operator =(const Couple & C); - - // Conversion en char - virtual operator Couple() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - Couple _data; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_Date.cxx b/src/Core/Batch_Date.cxx deleted file mode 100644 index a81bc87..0000000 --- a/src/Core/Batch_Date.cxx +++ /dev/null @@ -1,195 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Date.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 14:11:42 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include "Batch_Date.hxx" -using namespace std; - -namespace Batch { - - Date::Date(const long l) - { - time_t l_t = l; - struct tm * p_tm = localtime(&l_t); - _day = p_tm->tm_mday; - _month = p_tm->tm_mon + 1; - _year = p_tm->tm_year + 1900; - _hour = p_tm->tm_hour; - _min = p_tm->tm_min; - _sec = p_tm->tm_sec; - } - - Date::Date(const string s) - { - if ((s == "now") || (s == "Now") || (s == "NOW")) { - long l = time(0); - time_t l_t = l; - struct tm * p_tm = localtime(&l_t); - _day = p_tm->tm_mday; - _month = p_tm->tm_mon + 1; - _year = p_tm->tm_year + 1900; - _hour = p_tm->tm_hour; - _min = p_tm->tm_min; - _sec = p_tm->tm_sec; - - } else { -// char c; -// istringstream ist(s); -// ist >> _day >> c -// >> _month >> c -// >> _year >> c -// >> _hour >> c -// >> _min >> c -// >> _sec; - sscanf(s.c_str(), "%d/%d/%d-%d:%d:%d", &_day, &_month, &_year, &_hour, &_min, &_sec); - } - } - - Date & Date::operator =(long l) - { - time_t l_t = l; - struct tm * p_tm = localtime(&l_t); - _day = p_tm->tm_mday; - _month = p_tm->tm_mon + 1; - _year = p_tm->tm_year + 1900; - _hour = p_tm->tm_hour; - _min = p_tm->tm_min; - _sec = p_tm->tm_sec; - - return *this; - } - - Date & Date::operator +(long l) - { - *this = epoch() + l; - return *this; - } - - Date & Date::operator -(long l) - { - *this = epoch() - l; - return *this; - } - - Date & Date::operator +=(long l) - { - *this = epoch() + l; - return *this; - } - - Date & Date::operator -=(long l) - { - *this = epoch() - l; - return *this; - } - - Date & Date::operator =(const string & s) - { - if ((s == "now") || (s == "Now") || (s == "NOW")) { - long l = time(0); - time_t l_t = l; - struct tm * p_tm = localtime(&l_t); - _day = p_tm->tm_mday; - _month = p_tm->tm_mon + 1; - _year = p_tm->tm_year + 1900; - _hour = p_tm->tm_hour; - _min = p_tm->tm_min; - _sec = p_tm->tm_sec; - - } else { -// char c; -// istringstream ist(s); -// ist >> _day >> c -// >> _month >> c -// >> _year >> c -// >> _hour >> c -// >> _min >> c -// >> _sec; - sscanf(s.c_str(), "%d/%d/%d-%d:%d:%d", &_day, &_month, &_year, &_hour, &_min, &_sec); - } - - return *this; - } - - string Date::str() const - { - char buf[64]; - string datestr; - - // _day to char * - sprintf(buf, "%02d", _day); - datestr += buf; - datestr += "/"; - - // _month to char * - sprintf(buf, "%02d", _month); - datestr += buf; - datestr += "/"; - - // _year to char * - sprintf(buf, "%04d", _year); - datestr += buf; - datestr += "-"; - - // _hour to char * - sprintf(buf, "%02d", _hour); - datestr += buf; - datestr += ":"; - - // _min to char * - sprintf(buf, "%02d", _min); - datestr += buf; - datestr += ":"; - - // _sec to char * - sprintf(buf, "%02d", _sec); - datestr += buf; - - return datestr; - } - - long Date::epoch() const - { - struct tm T; - T.tm_mday = _day; - T.tm_mon = _month - 1; - T.tm_year = _year - 1900; - T.tm_hour = _hour; - T.tm_min = _min; - T.tm_sec = _sec; - return mktime(&T); - } - -} - - -// COMMENTS diff --git a/src/Core/Batch_Date.hxx b/src/Core/Batch_Date.hxx deleted file mode 100644 index 0a38a91..0000000 --- a/src/Core/Batch_Date.hxx +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Date.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 14:11:42 2003 - * Projet : Salome 2 - * - */ - -#ifndef _DATE_H_ -#define _DATE_H_ - -#include "Batch_Defines.hxx" - -#include - -namespace Batch { - - class BATCH_EXPORT Date - { - public: - Date(const long l=0); - Date(const std::string s); - virtual ~Date() {} - virtual Date & operator =(long l); - virtual Date & operator +(long l); - virtual Date & operator -(long l); - virtual Date & operator +=(long l); - virtual Date & operator -=(long l); - virtual Date & operator =(const std::string & s); - virtual std::string str() const; - virtual long epoch() const; - - protected: - int _day, _month, _year; - int _hour, _min, _sec; - - private: - - }; - -} - -#endif - -// COMMENTS diff --git a/src/Core/Batch_DateType.cxx b/src/Core/Batch_DateType.cxx deleted file mode 100644 index c94b3fd..0000000 --- a/src/Core/Batch_DateType.cxx +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * DateType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 11:15:34 2003 - * Projet : Salome 2 - * - */ -extern "C" { -#include -} -#include -#include "Batch_DateType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string DateType::affiche() const - { - return _data.str(); - } - - // Operateur d'affectation - DateType & DateType::operator =(const Date & d) - { - _data = d; - return *this; - } - - // Conversion en Date - DateType::operator Date() const - { - return _data; - } - - // Conversion en long - DateType::operator long() const - { - return _data.epoch(); - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * DateType::clone() const - { - DateType * pD = new DateType(this->_data); - assert(pD != 0); - return pD; - } - -} diff --git a/src/Core/Batch_DateType.hxx b/src/Core/Batch_DateType.hxx deleted file mode 100644 index 24723df..0000000 --- a/src/Core/Batch_DateType.hxx +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * DateType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 11:15:34 2003 - * Projet : Salome 2 - * - */ - -#ifndef _DATETYPE_H_ -#define _DATETYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" -#include "Batch_Date.hxx" - -namespace Batch { - - class BATCH_EXPORT DateType : public GenericType - { - public: - // Constructeur - DateType(const Date & d) : _data(d) {}; - - // Conversion en chaine - virtual std::string affiche() const; - - // Operateur d'affectation - virtual DateType & operator =(const Date &); - - // Conversion en Date - virtual operator Date() const; - - // Conversion en long - virtual operator long() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - Date _data; - - private: - }; - -} - -#endif - diff --git a/src/Core/Batch_Defines.hxx b/src/Core/Batch_Defines.hxx deleted file mode 100644 index d53cfdb..0000000 --- a/src/Core/Batch_Defines.hxx +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -// File : Batch_Defines.hxx -// Author : Alexander A. BORODIN -// Module : SALOME -// -#ifndef _BATCH_Defines_HXX_ -#define _BATCH_Defines_HXX_ - -#ifdef WIN32 -# if defined Batch_EXPORTS -# define BATCH_EXPORT __declspec( dllexport ) -# else -# define BATCH_EXPORT __declspec( dllimport ) -# endif -#else -# define BATCH_EXPORT -#endif - -#ifdef WIN32 -#define BATCH_CHMOD(name, mode) _chmod(name, mode) -#else -#define BATCH_CHMOD(name, mode) chmod(name, mode) -#endif - -#endif diff --git a/src/Core/Batch_EmulationException.cxx b/src/Core/Batch_EmulationException.cxx deleted file mode 100644 index 627655c..0000000 --- a/src/Core/Batch_EmulationException.cxx +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * EmulationException.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : April 2009 - * - */ - -#include "Batch_EmulationException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_EmulationException.hxx b/src/Core/Batch_EmulationException.hxx deleted file mode 100644 index a34e82b..0000000 --- a/src/Core/Batch_EmulationException.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * EmulationException.hxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : April 2009 - * - */ - -#ifndef _EMULATIONEXCEPTION_H_ -#define _EMULATIONEXCEPTION_H_ - -#include "Batch_Defines.hxx" -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT EmulationException : public GenericException - { - public: - // Constructor - EmulationException(const std::string & ch = "undefined") - : GenericException("EmulationException", ch) {} - }; - -} - -#endif diff --git a/src/Core/Batch_Environnement.cxx b/src/Core/Batch_Environnement.cxx deleted file mode 100644 index 0f4dcdc..0000000 --- a/src/Core/Batch_Environnement.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Environnement.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Oct 16 11:37:47 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_Environnement.hxx" -using namespace std; - -namespace Batch { - - -} diff --git a/src/Core/Batch_Environnement.hxx b/src/Core/Batch_Environnement.hxx deleted file mode 100644 index e99fc7f..0000000 --- a/src/Core/Batch_Environnement.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Environnement.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Oct 16 11:37:47 2003 - * Projet : Salome 2 - * - */ - -#ifndef _ENVIRONNEMENT_H_ -#define _ENVIRONNEMENT_H_ - -#include "Batch_Defines.hxx" - - -#include -#include - -namespace Batch { - - typedef std::map < std::string, std::string > Environnement; - -} - -#endif - diff --git a/src/Core/Batch_FactBatchManager.cxx b/src/Core/Batch_FactBatchManager.cxx deleted file mode 100644 index df74a91..0000000 --- a/src/Core/Batch_FactBatchManager.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2007-2012 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.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include -#include -#include -#include "Batch_BatchManagerCatalog.hxx" -#include "Batch_FactBatchManager.hxx" -using namespace std; - -namespace Batch { - - // Constructeur - FactBatchManager::FactBatchManager(const string & _t) : type(_t) - { - BatchManagerCatalog::getInstance().addFactBatchManager(type.c_str(), this); - - /* - ostringstream msg; - msg << "FactBatchManager of type '" << type << "' inserted into catalog"; - cerr << msg.str().c_str() << endl; - */ - } - - // Destructeur - FactBatchManager::~FactBatchManager() - { - // Nothing to do - } - - // Accesseur - string FactBatchManager::getType() const - { - return type; - } - - string FactBatchManager::__repr__() const - { - ostringstream oss; - oss << ""; - return oss.str(); - } - -} diff --git a/src/Core/Batch_FactBatchManager.hxx b/src/Core/Batch_FactBatchManager.hxx deleted file mode 100644 index a51a596..0000000 --- a/src/Core/Batch_FactBatchManager.hxx +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2007-2012 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.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_H_ -#define _FACTBATCHMANAGER_H_ - -#include "Batch_Defines.hxx" - -#include -#include - -namespace Batch { - - class BatchManager; - - class BATCH_EXPORT FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager(const std::string & type); - virtual ~FactBatchManager(); - - virtual Batch::BatchManager * operator() (const char * hostname) const = 0; - std::string getType() const; - std::string __repr__() const; - - protected: - std::string type; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_FactBatchManager_eClient.cxx b/src/Core/Batch_FactBatchManager_eClient.cxx deleted file mode 100644 index 69a571c..0000000 --- a/src/Core/Batch_FactBatchManager_eClient.cxx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2007-2012 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_eClient.cxx : emulation of client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include -#include "Batch_FactBatchManager_eClient.hxx" -using namespace std; - -namespace Batch { - - // Constructeur - FactBatchManager_eClient::FactBatchManager_eClient(const string & _t) : FactBatchManager(_t) - { - } - - // Destructeur - FactBatchManager_eClient::~FactBatchManager_eClient() - { - // Nothing to do - } - -} diff --git a/src/Core/Batch_FactBatchManager_eClient.hxx b/src/Core/Batch_FactBatchManager_eClient.hxx deleted file mode 100644 index e475929..0000000 --- a/src/Core/Batch_FactBatchManager_eClient.hxx +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2007-2012 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_eClient.hxx : emulation of client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#ifndef _FACTBATCHMANAGER_ECLIENT_H_ -#define _FACTBATCHMANAGER_ECLIENT_H_ - -#include - -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_CommunicationProtocol.hxx" - -namespace Batch { - - 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 * username, - CommunicationProtocolType protocolType, - const char * mpi = "nompi", - int nb_proc_per_node = 1) const = 0; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_GenericException.cxx b/src/Core/Batch_GenericException.cxx deleted file mode 100644 index 67b29c1..0000000 --- a/src/Core/Batch_GenericException.cxx +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * GenericException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 10:15:57 2003 - * Projet : Salome 2 - * - */ - -#include -#include "Batch_GenericException.hxx" - -using namespace std; - -namespace Batch { - -// Operator for writing on a stream -ostream & operator <<(ostream & os, const GenericException & e) -{ - return os << e.type << ": " << e.message; -} - -} diff --git a/src/Core/Batch_GenericException.hxx b/src/Core/Batch_GenericException.hxx deleted file mode 100644 index 435911b..0000000 --- a/src/Core/Batch_GenericException.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * GenericException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Nov 26 10:15:56 2003 - * Projet : Salome 2 - * - */ - -#ifndef _GENERICEXCEPTION_H_ -#define _GENERICEXCEPTION_H_ - -#include "Batch_Defines.hxx" - - -#include - -namespace Batch { - - class BATCH_EXPORT GenericException - { - public: - const std::string type; // la nature de l'exception - const std::string message; // la raison de l'exception - - // Constructeur - GenericException(const std::string & tp = "GenericException", - const std::string & ch = "undefined") : type(tp), message(ch) {} - }; - - // Operator for writing on a stream - BATCH_EXPORT std::ostream & operator <<(std::ostream & os, const GenericException & e); - -} - -#endif diff --git a/src/Core/Batch_GenericType.cxx b/src/Core/Batch_GenericType.cxx deleted file mode 100644 index 810d837..0000000 --- a/src/Core/Batch_GenericType.cxx +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * GenericType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - - -#include -#include -#include -#include "Batch_GenericType.hxx" -using namespace std; - -namespace Batch { - - // nombre total d'objet GenericType et al. - int GenericType::_nb = 0; - - // Operateur pour l'affichage sur un stream - ostream & operator << (ostream & os, const GenericType & obj) - { - return os << obj.affiche(); - } - - // Conversion en chaine - string GenericType::affiche() const - { - return string("(GenericType : si ce message apparait, vous devez avoir un probleme)"); - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * GenericType::clone() const - { - GenericType * pG = new GenericType; - assert(pG != 0); - return pG; - } - -} - diff --git a/src/Core/Batch_GenericType.hxx b/src/Core/Batch_GenericType.hxx deleted file mode 100644 index a2520d6..0000000 --- a/src/Core/Batch_GenericType.hxx +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * GenericType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _GENERICTYPE_H_ -#define _GENERICTYPE_H_ - -#include "Batch_Defines.hxx" - - -#include -#include - -namespace Batch { - - class BATCH_EXPORT GenericType - { - public: - // Constructeur et destructeur - GenericType() { _nb++; } - virtual ~GenericType() { _nb--; } - - // Operateur pour l'affichage sur un stream - BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const GenericType & obj); - - // Conversion en chaine - virtual std::string affiche() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - // Retourne le nombre d'objets GenericType et al. - static int getNb() { return _nb; } - - protected: - - private: - static int _nb; // nombre total d'objets GenericType et al. - - }; - -} - -#endif - diff --git a/src/Core/Batch_InvalidArgumentException.cxx b/src/Core/Batch_InvalidArgumentException.cxx deleted file mode 100644 index a027307..0000000 --- a/src/Core/Batch_InvalidArgumentException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * InvalidArgumentException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Oct 16 16:18:00 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_InvalidArgumentException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_InvalidArgumentException.hxx b/src/Core/Batch_InvalidArgumentException.hxx deleted file mode 100644 index fbd55b6..0000000 --- a/src/Core/Batch_InvalidArgumentException.hxx +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * InvalidArgumentException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Oct 16 16:18:00 2003 - * Projet : Salome 2 - * - */ - -#ifndef _INVALIDARGUMENTEXCEPTION_H_ -#define _INVALIDARGUMENTEXCEPTION_H_ - - -#include "Batch_Defines.hxx" - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT InvalidArgumentException : public GenericException - { - public: - // Constructeur - InvalidArgumentException(const std::string & ch = "undefined") - : GenericException("InvalidArgumentException", ch) {} - }; - -} - -#endif - diff --git a/src/Core/Batch_InvalidKeyException.cxx b/src/Core/Batch_InvalidKeyException.cxx deleted file mode 100644 index 3f0b173..0000000 --- a/src/Core/Batch_InvalidKeyException.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * InvalidKeyException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Oct 15 10:39:51 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_InvalidKeyException.hxx" -using namespace std; - -namespace Batch { - -} - diff --git a/src/Core/Batch_InvalidKeyException.hxx b/src/Core/Batch_InvalidKeyException.hxx deleted file mode 100644 index ff9dddc..0000000 --- a/src/Core/Batch_InvalidKeyException.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * InvalidKeyException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Wed Oct 15 10:39:51 2003 - * Projet : Salome 2 - * - */ - -#ifndef _INVALIDKEYEXCEPTION_H_ -#define _INVALIDKEYEXCEPTION_H_ - -#include "Batch_Defines.hxx" - - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT InvalidKeyException : public GenericException - { - public: - // Constructeur - InvalidKeyException(std::string ch = "undefined") : GenericException("InvalidKeyException", ch) {} - - protected: - - private: - - }; - -} - -#endif - diff --git a/src/Core/Batch_Job.cxx b/src/Core/Batch_Job.cxx deleted file mode 100644 index 9c93a3b..0000000 --- a/src/Core/Batch_Job.cxx +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include "Batch_Job.hxx" -#include "Batch_Parametre.hxx" -#include -//#include "MEDMEM_STRING.hxx" -using namespace std; - -namespace Batch { - - // Constructeur - Job::Job() : _param(), _env() - { - // Nothing to do - } - - - // Constructeur - Job::Job(Parametre param) : _param(param), _env() - { - // Nothing to do - } - - - // Constructeur - Job::Job(Environnement env) : _param(), _env(env) - { - // Nothing to do - } - - - // Constructeur - Job::Job(Parametre param, Environnement env) : _param(param), _env(env) - { - // Nothing to do - } - - // Operateur pour l'affichage sur un stream - ostream & operator <<(ostream & os, const Job & job) - { - return os << job.__str__(); - } - - // Accesseur - Batch::Parametre Job::getParametre() const - { - return _param; - } - - // Accesseur - void Job::setParametre(const Batch::Parametre & param) - { - _param = param; - } - - // Accesseur - Environnement Job::getEnvironnement() const - { - return _env; - } - - // Accesseur - void Job::setEnvironnement(const Environnement & env) - { - _env = env; - } - - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string Job::__str__() const { - //MEDMEM::STRING str; - ostringstream str; - str << ""; - return str.str(); - } - - -} diff --git a/src/Core/Batch_Job.hxx b/src/Core/Batch_Job.hxx deleted file mode 100644 index e3045c7..0000000 --- a/src/Core/Batch_Job.hxx +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _JOB_H_ -#define _JOB_H_ - -#include "Batch_Defines.hxx" - - -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" - -namespace Batch { - - class BATCH_EXPORT Job - { - public: - // Constructeurs et destructeur - Job(); - Job(Batch::Parametre param); - Job(Batch::Environnement env); - Job(Batch::Parametre param, Batch::Environnement env); - virtual ~Job() {} - - // Operateur pour l'affichage sur un stream - BATCH_EXPORT friend std::ostream & operator <<(std::ostream & os, const Job & job); - - // Accesseurs - Batch::Parametre getParametre() const; - void setParametre(const Batch::Parametre &); - - // Accesseurs - Batch::Environnement getEnvironnement() const; - void setEnvironnement(const Batch::Environnement &); - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - Batch::Parametre _param; // table des parametres batch du job - Batch::Environnement _env; // table des variables d'environnement - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_JobId.cxx b/src/Core/Batch_JobId.cxx deleted file mode 100644 index 048ef27..0000000 --- a/src/Core/Batch_JobId.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobId.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include "Batch_JobId.hxx" -#include "Batch_BatchManager.hxx" -#include -#include -//#include "MEDMEM_STRING.hxx" -using namespace std; - -namespace Batch { - - // Constructeur standard - JobId::JobId() : _p_batchmanager(), _reference("undefined") - { - // Nothing to do - } - - // Constructeur avec le pointeur sur le BatchManager associe et avec une reference - JobId::JobId(BatchManager * _p_bm, string ref) : _p_batchmanager(_p_bm), _reference(ref) - { - // Nothing to do - } - - // Destructeur - JobId::~JobId() - { - // Nothing to do - } - - // Operateur d'affectation entre objets - JobId & JobId::operator =(const JobId & jobid) - { - _p_batchmanager = jobid._p_batchmanager; - _reference = jobid._reference; - - return *this; - } - - // Constructeur par recopie - JobId::JobId(const JobId & jobid) : _p_batchmanager(jobid._p_batchmanager), _reference(jobid._reference) - { - // Nothing to do - } - - // Accesseur pour la reference interne - string JobId::getReference() const - { - return _reference; - } - - // Permet de recharger un job depuis un fichier - void JobId::setReference(const std::string & new_reference) - { - _reference = new_reference; - } - - // Methode pour le controle du job : retire le job du gestionnaire - void JobId::deleteJob() const - { - assert(_p_batchmanager != 0); - _p_batchmanager->deleteJob(*this); - } - - // Methode pour le controle du job : suspend le job en file d'attente - void JobId::holdJob() const - { - assert(_p_batchmanager != 0); - _p_batchmanager->holdJob(*this); - } - - // Methode pour le controle du job : relache le job suspendu - void JobId::releaseJob() const - { - assert(_p_batchmanager != 0); - _p_batchmanager->releaseJob(*this); - } - - // Methode pour le controle du job : modifie le job en file d'attente - void JobId::alterJob(const Parametre & param, const Environnement & env) const - { - assert(_p_batchmanager != 0); - _p_batchmanager->alterJob(*this, param, env); - } - - // Methode pour le controle du job : modifie le job en file d'attente - void JobId::alterJob(const Parametre & param) const - { - assert(_p_batchmanager != 0); - _p_batchmanager->alterJob(*this, param); - } - - // Methode pour le controle du job : modifie le job en file d'attente - void JobId::alterJob(const Environnement & env) const - { - assert(_p_batchmanager != 0); - _p_batchmanager->alterJob(*this, env); - } - - // Methode pour le controle du job : renvoie l'etat du job - JobInfo JobId::queryJob() const - { - assert(_p_batchmanager != 0); - return _p_batchmanager->queryJob(*this); - } - - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobId::__str__() const { - //MEDMEM::STRING str; - ostringstream str; - str << ""; - return str.str(); - } - -} diff --git a/src/Core/Batch_JobId.hxx b/src/Core/Batch_JobId.hxx deleted file mode 100644 index 831c5cf..0000000 --- a/src/Core/Batch_JobId.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobId.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _JOBID_H_ -#define _JOBID_H_ - - -#include "Batch_Defines.hxx" - -#include "Batch_JobInfo.hxx" -#include "Batch_BatchManager.hxx" - -namespace Batch { - - class BatchManager; - - class BATCH_EXPORT JobId - { - friend class BatchManager; - - public: - // Constructeur standard et destructeur - JobId(); - virtual ~JobId(); - - // Constructeur avec le pointeur sur le BatchManager associe et avec une reference - JobId(Batch::BatchManager *, std::string ref); - - // Operateur d'affectation entre objets - virtual JobId & operator =(const Batch::JobId &); - - // Constructeur par recopie - JobId(const Batch::JobId &); - - // Accesseur pour la reference interne - virtual std::string getReference() const; - - // Permet de recharger un job depuis un fichier - virtual void setReference(const std::string & new_reference); - - // Methodes pour le controle du job - virtual void deleteJob() const; // retire un job du gestionnaire - virtual void holdJob() const; // suspend un job en file d'attente - virtual void releaseJob() const; // relache un job suspendu - virtual void alterJob(const Batch::Parametre & param, const Batch::Environnement & env) const; // modifie un job en file d'attente - virtual void alterJob(const Batch::Parametre & param) const; // modifie un job en file d'attente - virtual void alterJob(const Batch::Environnement & env) const; // modifie un job en file d'attente - virtual void setParametre(const Batch::Parametre & param) { return alterJob(param); } // modifie un job en file d'attente - virtual void setEnvironnement(const Batch::Environnement & env) { return alterJob(env); } // modifie un job en file d'attente - virtual Batch::JobInfo queryJob() const; // renvoie l'etat du job - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - Batch::BatchManager * _p_batchmanager; // pointeur sur le BatchManager qui controle le job - std::string _reference; // reference du job au sein du BatchManager - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_JobInfo.cxx b/src/Core/Batch_JobInfo.cxx deleted file mode 100644 index 6f50309..0000000 --- a/src/Core/Batch_JobInfo.cxx +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:05:30 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_JobInfo.hxx" - -using namespace std; - -namespace Batch { - - // Destructeur - JobInfo::~JobInfo() - { - // Nothing to do - } - - - // Operateur pour l'affichage sur un stream - ostream & operator <<(ostream & os, const JobInfo & ji) - { - return os << ji.__str__(); - } - - - // Methodes pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo::__str__() const - { - //MEDMEM::STRING sst; - ostringstream sst; - sst << ""; - - return sst.str(); - } - - // Accesseur - Parametre JobInfo::getParametre() const - { - return _param; - } - - // Accesseur - Environnement JobInfo::getEnvironnement() const - { - return _env; - } - - -} diff --git a/src/Core/Batch_JobInfo.hxx b/src/Core/Batch_JobInfo.hxx deleted file mode 100644 index 7e09a18..0000000 --- a/src/Core/Batch_JobInfo.hxx +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Thu Nov 6 10:05:30 2003 - * Projet : Salome 2 - * - */ - -#ifndef _JOBINFO_H_ -#define _JOBINFO_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" - -namespace Batch { - - class BATCH_EXPORT JobInfo - { - public: - // Constructeur standard et destructeur - JobInfo() : _param(), _env() {}; - virtual ~JobInfo(); - - // Constructeur par recopie - JobInfo(const JobInfo & jinfo) : _param(jinfo._param), _env(jinfo._env) {}; - - // Operateur pour l'affichage sur un stream - BATCH_EXPORT friend std::ostream & operator <<(std::ostream & os, const JobInfo & ji); - - // Accesseurs - // _CS_gbo Ajout explicite du namespace pour les besoins de swig (mauvaise gestion - // des namespace par swig. - virtual Batch::Parametre getParametre() const; - virtual Batch::Environnement getEnvironnement() const; - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - Parametre _param; // parametres du job - Environnement _env; // variables d'environnement du job - JobInfo(const Parametre & param, const Environnement & env) : _param(param), _env(env) {}; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_ListIsFullException.cxx b/src/Core/Batch_ListIsFullException.cxx deleted file mode 100644 index 3a46ebc..0000000 --- a/src/Core/Batch_ListIsFullException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * ListIsFullException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include "Batch_ListIsFullException.hxx" -using namespace std; - - -namespace Batch { - -} diff --git a/src/Core/Batch_ListIsFullException.hxx b/src/Core/Batch_ListIsFullException.hxx deleted file mode 100644 index 4020927..0000000 --- a/src/Core/Batch_ListIsFullException.hxx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * ListIsFullException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _LISTISFULLEXCEPTION_H_ -#define _LISTISFULLEXCEPTION_H_ - -#include "Batch_Defines.hxx" - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT ListIsFullException : public GenericException - { - public: - // Constructeur - ListIsFullException(std::string ch = "undefined") : GenericException("ListIsFullException", ch) {} - }; - -} - -#endif - diff --git a/src/Core/Batch_LongType.cxx b/src/Core/Batch_LongType.cxx deleted file mode 100644 index 48a9b86..0000000 --- a/src/Core/Batch_LongType.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * LongType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include -#include -#include -//#include "MEDMEM_STRING.hxx" -#include "Batch_LongType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string LongType::affiche() const - { - //MEDMEM::STRING sst; - ostringstream sst; - sst << _data; - return sst.str(); - } - - // Operateur d'affectation - LongType & LongType::operator =(long l) - { - _data = l; - return *this; - } - - // Conversion en long - LongType::operator long() const - { - return this->_data; - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * LongType::clone() const - { - LongType * pL = new LongType(this->_data); - assert(pL != 0); - return pL; - } - -} diff --git a/src/Core/Batch_LongType.hxx b/src/Core/Batch_LongType.hxx deleted file mode 100644 index 8e9f3ba..0000000 --- a/src/Core/Batch_LongType.hxx +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * LongType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _LONGTYPE_H_ -#define _LONGTYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" - -namespace Batch { - - class BATCH_EXPORT LongType : public GenericType - { - public: - // Constructeur - LongType(const long l=0L) : _data(l) {} - - // Conversion en chaine - virtual std::string affiche() const; - - // Operateur d'affectation - virtual LongType & operator =(long); - - // Conversion en long - virtual operator long() const; - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - long _data; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_MpiImpl.cxx b/src/Core/Batch_MpiImpl.cxx deleted file mode 100644 index dcd68b0..0000000 --- a/src/Core/Batch_MpiImpl.cxx +++ /dev/null @@ -1,350 +0,0 @@ -// Copyright (C) 2007-2012 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 -// - -#include -#include -#include -#include "Batch_MpiImpl.hxx" - -using namespace std; - -// Constructor -MpiImpl::MpiImpl() -{ -} - -// Destructor -MpiImpl::~MpiImpl() -{ -} - -// lam implementation -// Constructor -MpiImpl_LAM::MpiImpl_LAM() : MpiImpl() -{ -} - -// Destructor -MpiImpl_LAM::~MpiImpl_LAM() -{ -} - -string MpiImpl_LAM::size() -{ - return "${LAMWORLD}"; -} - -string MpiImpl_LAM::rank() -{ - return "${LAMRANK}"; -} - -string MpiImpl_LAM::boot(const string machinefile, const unsigned int nbnodes) -{ - ostringstream oss; - oss << "lamboot " << machinefile << endl; - return oss.str(); -} - -string MpiImpl_LAM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_LAM::halt() -{ - ostringstream oss; - oss << "lamhalt" << endl; - return oss.str(); -} - -string MpiImpl_LAM::name() -{ - return "lam"; -} - -// mpich1 implementation -// Constructor -MpiImpl_MPICH1::MpiImpl_MPICH1() : MpiImpl() -{ -} - -// Destructor -MpiImpl_MPICH1::~MpiImpl_MPICH1() -{ -} - -string MpiImpl_MPICH1::size() -{ - return "${MPIRUN_NPROCS}"; -} - -string MpiImpl_MPICH1::rank() -{ - return "${MPIRUN_RANK}"; -} - -string MpiImpl_MPICH1::boot(const string machinefile, const unsigned int nbnodes) -{ - return ""; -} - -string MpiImpl_MPICH1::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "mpirun -machinefile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_MPICH1::halt() -{ - return ""; -} - -string MpiImpl_MPICH1::name() -{ - return "mpich"; -} - -// mpich2 implementation -// Constructor -MpiImpl_MPICH2::MpiImpl_MPICH2() : MpiImpl() -{ -} - -// Destructor -MpiImpl_MPICH2::~MpiImpl_MPICH2() -{ -} - -string MpiImpl_MPICH2::size() -{ - return "${PMI_SIZE}"; -} - -string MpiImpl_MPICH2::rank() -{ - return "${PMI_RANK}"; -} - -string MpiImpl_MPICH2::boot(const string machinefile, const unsigned int nbnodes) -{ - ostringstream oss; - oss << "mpdboot" << " -n " << nbnodes; - if (machinefile!="") - oss << " -f " << machinefile; - oss << endl; - return oss.str(); -} - -string MpiImpl_MPICH2::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_MPICH2::halt() -{ - ostringstream oss; - oss << "mpdallexit" << endl; - return oss.str(); -} - -string MpiImpl_MPICH2::name() -{ - return "mpich"; -} - -// openmpi implementation -// Constructor -MpiImpl_OPENMPI::MpiImpl_OPENMPI() : MpiImpl() -{ -} - -// Destructor -MpiImpl_OPENMPI::~MpiImpl_OPENMPI() -{ -} - -string MpiImpl_OPENMPI::size() -{ - return "${OMPI_MCA_ns_nds_num_procs}"; -} - -string MpiImpl_OPENMPI::rank() -{ - return "${OMPI_MCA_ns_nds_vpid}"; -} - -string MpiImpl_OPENMPI::boot(const string machinefile, const unsigned int nbnodes) -{ - return ""; -} - -string MpiImpl_OPENMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_OPENMPI::halt() -{ - return ""; -} - -string MpiImpl_OPENMPI::name() -{ - return "openmpi"; -} - -// ompi implementation -// Constructor -MpiImpl_OMPI::MpiImpl_OMPI() : MpiImpl() -{ -} - -// Destructor -MpiImpl_OMPI::~MpiImpl_OMPI() -{ -} - -string MpiImpl_OMPI::size() -{ - return "${OMPI_MCA_ns_nds_num_procs}"; -} - -string MpiImpl_OMPI::rank() -{ - return "${OMPI_MCA_ns_nds_vpid}"; -} - -string MpiImpl_OMPI::boot(const string machinefile, const unsigned int nbnodes) -{ - return ""; -} - -string MpiImpl_OMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_OMPI::halt() -{ - return ""; -} - -string MpiImpl_OMPI::name() -{ - return "ompi"; -} - -// slurm implementation -// Constructor -MpiImpl_SLURM::MpiImpl_SLURM() : MpiImpl() -{ -} - -// Destructor -MpiImpl_SLURM::~MpiImpl_SLURM() -{ -} - -string MpiImpl_SLURM::size() -{ - return "${SLURM_NPROCS}"; -} - -string MpiImpl_SLURM::rank() -{ - return "${SLURM_PROCID}"; -} - -string MpiImpl_SLURM::boot(const string machinefile, const unsigned int nbnodes) -{ - return ""; -} - -string MpiImpl_SLURM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "srun " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_SLURM::halt() -{ - return ""; -} - -string MpiImpl_SLURM::name() -{ - return "slurm"; -} - -// prun implementation -// Constructor -MpiImpl_PRUN::MpiImpl_PRUN() : MpiImpl() -{ -} - -// Destructor -MpiImpl_PRUN::~MpiImpl_PRUN() -{ -} - -string MpiImpl_PRUN::size() -{ - return "${RMS_NPROCS}"; -} - -string MpiImpl_PRUN::rank() -{ - return "${RMS_RANK}"; -} - -string MpiImpl_PRUN::boot(const string machinefile, const unsigned int nbnodes) -{ - return ""; -} - -string MpiImpl_PRUN::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) -{ - ostringstream oss; - oss << "prun -n " << nbproc << " " << "-p mpi " << fileNameToExecute << endl; - return oss.str(); -} - -string MpiImpl_PRUN::halt() -{ - return ""; -} - -string MpiImpl_PRUN::name() -{ - return "prun"; -} diff --git a/src/Core/Batch_MpiImpl.hxx b/src/Core/Batch_MpiImpl.hxx deleted file mode 100644 index 9bc323f..0000000 --- a/src/Core/Batch_MpiImpl.hxx +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright (C) 2007-2012 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 -// - -#ifndef _BL_MPIIMPL_H_ -#define _BL_MPIIMPL_H_ - -#include "Batch_Defines.hxx" -#include - -class BATCH_EXPORT MpiImplException -{ -public: - const std::string msg; - - MpiImplException(const std::string m) : msg(m) {} -}; - -class BATCH_EXPORT MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl(); // constrcuctor - virtual ~MpiImpl(); //Destructor - - virtual std::string size() = 0; // get number of process of current job - virtual std::string rank() = 0; // get process number of current job - virtual std::string boot(const std::string machinefile, const unsigned int nbnodes) = 0; // get boot command - virtual std::string run(const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute) = 0; // get run command - virtual std::string halt() = 0; // get stop command - virtual std::string name() = 0; // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_LAM : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_LAM(); // constructor - virtual ~MpiImpl_LAM(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_MPICH1 : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_MPICH1(); // constructor - virtual ~MpiImpl_MPICH1(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_MPICH2 : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_MPICH2(); // constructor - virtual ~MpiImpl_MPICH2(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_OPENMPI : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_OPENMPI(); // constructor - virtual ~MpiImpl_OPENMPI(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_OMPI : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_OMPI(); // constructor - virtual ~MpiImpl_OMPI(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_SLURM : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_SLURM(); // constructor - virtual ~MpiImpl_SLURM(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -class BATCH_EXPORT MpiImpl_PRUN : public MpiImpl -{ -public: - // Constructeur et destructeur - MpiImpl_PRUN(); // constructor - virtual ~MpiImpl_PRUN(); //Destructor - - std::string size(); // get number of process of current job - std::string rank(); // get process number of current job - std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command - std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command - std::string halt(); // get stop command - std::string name(); // name of mpi implementation - -protected: - -private: - -}; - -#endif diff --git a/src/Core/Batch_NotYetImplementedException.cxx b/src/Core/Batch_NotYetImplementedException.cxx deleted file mode 100644 index 40df58b..0000000 --- a/src/Core/Batch_NotYetImplementedException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * NotYetImplementedException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Nov 25 11:35:07 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_NotYetImplementedException.hxx" - -namespace Batch { - -} - diff --git a/src/Core/Batch_NotYetImplementedException.hxx b/src/Core/Batch_NotYetImplementedException.hxx deleted file mode 100644 index 8e5ee7e..0000000 --- a/src/Core/Batch_NotYetImplementedException.hxx +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * NotYetImplementedException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Nov 25 11:35:07 2003 - * Projet : Salome 2 - * - */ - -#ifndef _NOTYETIMPLEMENTEDEXCEPTION_H_ -#define _NOTYETIMPLEMENTEDEXCEPTION_H_ - -#include "Batch_Defines.hxx" -#include "Batch_GenericException.hxx" - -#include - -namespace Batch { - - class BATCH_EXPORT NotYetImplementedException : public GenericException - { - public: - // Constructeur - NotYetImplementedException(std::string ch = "undefined") : GenericException("NotYetImplementedException", ch) {} - }; - -} - -#endif - diff --git a/src/Core/Batch_ParameterTypeMap.cxx b/src/Core/Batch_ParameterTypeMap.cxx deleted file mode 100644 index dcda3bb..0000000 --- a/src/Core/Batch_ParameterTypeMap.cxx +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright (C) 2007-2012 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_ParameterTypeMap.cxx : - * - * Auteur : Renaud Barate - EDF R&D - * Date : Mars 2011 - * - */ - -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_InvalidKeyException.hxx" -#include "Batch_ParameterTypeMap.hxx" - -using namespace std; - -namespace Batch { - - /*! - * The values of this type map contain the type of the parameters and the maximum - * number of items in the corresponding Versatile object (0 means any number). - */ - ParameterTypeMap::ParameterTypeMap() - { - // Don't use the string constants in this constructor because they might be uninitialized - addParameter("ACCOUNT", STRING, 1); - addParameter("ARGUMENTS", STRING, 0); - addParameter("CHECKPOINT", LONG, 1); - addParameter("CKPTINTERVAL", LONG, 1); - addParameter("CREATIONTIME", LONG, 1); - addParameter("EGROUP", STRING, 1); - addParameter("ELIGIBLETIME", LONG, 1); - addParameter("ENDTIME", LONG, 1); - addParameter("EUSER", STRING, 1); - addParameter("EXECUTABLE", STRING, 1); - addParameter("EXECUTIONHOST", STRING, 0); - addParameter("EXITCODE", LONG, 1); - addParameter("HOLD", LONG, 1); - addParameter("ID", STRING, 1); - addParameter("INFILE", COUPLE, 0); - addParameter("MAIL", STRING, 1); - addParameter("MAXCPUTIME", LONG, 1); - addParameter("MAXDISKSIZE", LONG, 1); - addParameter("MAXRAMSIZE", LONG, 1); - addParameter("MAXWALLTIME", LONG, 1); - addParameter("MODIFICATIONTIME", LONG, 1); - addParameter("NAME", STRING, 1); - addParameter("NBPROC", LONG, 1); - addParameter("OUTFILE", COUPLE, 0); - addParameter("PID", LONG, 1); - addParameter("QUEUE", STRING, 1); - addParameter("QUEUEDTIME", LONG, 1); - addParameter("SERVER", STRING, 1); - addParameter("STARTTIME", LONG, 1); - addParameter("STATE", STRING, 1); - addParameter("TEXT", STRING, 1); - addParameter("TMPDIR", STRING, 1); - addParameter("USEDCPUTIME", LONG, 1); - addParameter("USEDDISKSIZE", LONG, 1); - addParameter("USEDRAMSIZE", LONG, 1); - addParameter("USEDWALLTIME", LONG, 1); - addParameter("USER", STRING, 1); - addParameter("WORKDIR", STRING, 1); - addParameter("HOMEDIR", STRING, 1); - addParameter("EXCLUSIVE", BOOL, 1); - } - - ParameterTypeMap::~ParameterTypeMap() - { - } - - /*! - * Returns the ParameterTypeMap singleton. - * We use the construct-on-first-use idiom here because otherwise there could be a problem with - * the initialization order between the factory singletons and this type map. Note that since the - * destructors do not depend on the other objects, the order is not important for destruction. - */ - ParameterTypeMap& ParameterTypeMap::getInstance () { - static ParameterTypeMap instance; - return instance; - } - - bool ParameterTypeMap::hasKey(const string & key) const - { - return (_map.find(key) != _map.end()); - } - - void ParameterTypeMap::addParameter(const std::string & key, DiscriminatorType type, int maxelem) - { - if (hasKey(key)) throw InvalidKeyException(key + " is already present in type map"); - _map[key].type = type; - _map[key].maxelem = maxelem; - } - - Versatile ParameterTypeMap::createVersatile(const std::string & parameterName) - { - map::const_iterator it = _map.find(parameterName); - if (it == _map.end()) throw InvalidKeyException(parameterName); - return Versatile(it->second.type, it->second.maxelem, parameterName); - } - -} diff --git a/src/Core/Batch_ParameterTypeMap.hxx b/src/Core/Batch_ParameterTypeMap.hxx deleted file mode 100644 index b565552..0000000 --- a/src/Core/Batch_ParameterTypeMap.hxx +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2007-2012 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_ParameterTypeMap.hxx : - * - * Auteur : Renaud Barate - EDF R&D - * Date : Mars 2011 - * - */ - -#ifndef _PARAMETERTYPEMAP_H_ -#define _PARAMETERTYPEMAP_H_ - -#include "Batch_Defines.hxx" -#include "Batch_Versatile.hxx" - -#include -#include - -namespace Batch { - - typedef struct { - DiscriminatorType type; - int maxelem; - } ParameterType; - - - /*! - * This class is used to control the type of the values associated with a parameter. - * It's a singleton that can be get only through the static method getInstance(). - */ - class BATCH_EXPORT ParameterTypeMap - { - public: - static ParameterTypeMap& getInstance(); - - bool hasKey(const std::string & key) const; - void addParameter(const std::string & key, DiscriminatorType type, int maxelem); - Versatile createVersatile(const std::string & parameterName); - - protected: - - ParameterTypeMap(); - virtual ~ParameterTypeMap(); - - std::map _map; - - private: - - // Forbid the use of copy constructor and assignment operator - ParameterTypeMap(const ParameterTypeMap & orig) {} - void operator=(const ParameterTypeMap & orig) {} - - }; - -} - -#endif diff --git a/src/Core/Batch_Parametre.cxx b/src/Core/Batch_Parametre.cxx deleted file mode 100644 index 70ffadd..0000000 --- a/src/Core/Batch_Parametre.cxx +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Parametre.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include "Batch_Versatile.hxx" -#include "Batch_InvalidKeyException.hxx" -#include "Batch_ParameterTypeMap.hxx" -#include "Batch_Parametre.hxx" - -using namespace std; - -namespace Batch { - - // Constructeur standard - Parametre::Parametre() : map< string, Versatile >() - { - } - - // Operateur de recherche dans la map - // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de - // la valeur associée à la clef car il retourne une reference non constante - Versatile & Parametre::operator [] (const string & mk) - { - // On controle que la clef est valide - if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk); - - Parametre::iterator it = find(mk); - if (it != end()) { - return it->second; - } else { - Versatile V = ParameterTypeMap::getInstance().createVersatile(mk); - pair result = insert(make_pair(mk, V)); - return result.first->second; - } - } - - // Operateur de recherche dans la map - // Cet operateur agit sur les objets CONSTANTS - const Versatile & Parametre::operator [] (const string & mk) const - { - // On controle que la clef est valide - if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk); - - // On recherche la valeur associee - Parametre::const_iterator it = find(mk); - if (it == end()) throw InvalidKeyException(mk); - const Versatile & V = (*it).second; - - return V; - } - - // Operateur d'affectation - Parametre & Parametre::operator =(const Parametre & PM) - { - // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie - if (this == &PM) return *this; - - // On efface toute la map - erase(begin(), end()); - - // On recree la structure interne de la map avec les valeurs de celle passee en argument - Parametre::const_iterator it; - for(it=PM.begin(); it!=PM.end(); it++) - insert(make_pair((*it).first, Versatile((*it).second))); - - return *this; - } - - // Constructeur par recopie - Parametre::Parametre(const Parametre & PM) : map< string, Versatile >() - { - // On cree la structure interne de la map avec les valeurs de celle passee en argument - Parametre::const_iterator it; - for(it=PM.begin(); it!=PM.end(); it++) - insert(make_pair((*it).first, Versatile((*it).second))); - } - -} diff --git a/src/Core/Batch_Parametre.hxx b/src/Core/Batch_Parametre.hxx deleted file mode 100644 index 7312c0f..0000000 --- a/src/Core/Batch_Parametre.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Parametre.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _PARAMETRE_H_ -#define _PARAMETRE_H_ - -#include -#include - -#include "Batch_Defines.hxx" -#include "Batch_Versatile.hxx" - -namespace Batch { - - class BATCH_EXPORT Parametre : public std::map< std::string, Versatile > - { - public: - // Constructeur standard - Parametre(); - - // Constructeur par recopie - Parametre(const Parametre & PM); - - // Operateur de recherche dans la map - Versatile & operator [] (const std::string &); - const Versatile & operator [] (const std::string &) const; - - // Operateur d'affectation - Parametre & operator =(const Parametre & PM); - - }; - -} - -#endif diff --git a/src/Core/Batch_RunTimeException.cxx b/src/Core/Batch_RunTimeException.cxx deleted file mode 100644 index a983e24..0000000 --- a/src/Core/Batch_RunTimeException.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * RunTimeException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Nov 25 14:04:13 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_RunTimeException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_RunTimeException.hxx b/src/Core/Batch_RunTimeException.hxx deleted file mode 100644 index 87878bf..0000000 --- a/src/Core/Batch_RunTimeException.hxx +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * RunTimeException.hxx : - * - * Auteur : %author% - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Tue Nov 25 14:04:13 2003 - * Projet : Salome 2 - * - */ - -#ifndef _RUNTIMEEXCEPTION_H_ -#define _RUNTIMEEXCEPTION_H_ - -#include "Batch_Defines.hxx" - - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT RunTimeException : public GenericException - { - public: - // Constructeur - RunTimeException(std::string ch = "undefined") : GenericException("RunTimeException", ch) {} - }; - -} - -#endif diff --git a/src/Core/Batch_StringType.cxx b/src/Core/Batch_StringType.cxx deleted file mode 100644 index d7d418f..0000000 --- a/src/Core/Batch_StringType.cxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * StringType.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include -#include -#include "Batch_StringType.hxx" -using namespace std; - -namespace Batch { - - // Conversion en chaine - string StringType::affiche() const - { - return _data; - } - - // Operateur d'affectation - StringType & StringType::operator =(string s) - { - _data = s; - return *this; - } - - // Conversion en chaine - StringType::operator string() const - { - return this->_data; - } - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - GenericType * StringType::clone() const - { - StringType * pS = new StringType(this->_data); - assert(pS != 0); - return pS; - } - -} diff --git a/src/Core/Batch_StringType.hxx b/src/Core/Batch_StringType.hxx deleted file mode 100644 index ab7246c..0000000 --- a/src/Core/Batch_StringType.hxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * StringType.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _STRINGTYPE_H_ -#define _STRINGTYPE_H_ - -#include "Batch_Defines.hxx" - -#include -#include "Batch_GenericType.hxx" - -namespace Batch { - - class BATCH_EXPORT StringType : public GenericType - { - public: - // Constructeur - StringType(const std::string & s="") : _data(s) {} - - // Conversion en chaine - virtual std::string affiche() const; - virtual operator std::string() const; - - // Operateur d'affectation - virtual StringType & operator =(std::string); - - // Clone duplique l'objet et en fabrique un nouveau a l'aide de new - // qu'il faudra detruire ensuite manuellement - virtual GenericType * clone() const; - - protected: - std::string _data; - - private: - - }; - -} - -#endif diff --git a/src/Core/Batch_TypeMismatchException.cxx b/src/Core/Batch_TypeMismatchException.cxx deleted file mode 100644 index 48884ae..0000000 --- a/src/Core/Batch_TypeMismatchException.cxx +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * TypeMismatchException.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#include "Batch_TypeMismatchException.hxx" -using namespace std; - -namespace Batch { - -} diff --git a/src/Core/Batch_TypeMismatchException.hxx b/src/Core/Batch_TypeMismatchException.hxx deleted file mode 100644 index cd24cc5..0000000 --- a/src/Core/Batch_TypeMismatchException.hxx +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * TypeMismatchException.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2003 - * Projet : SALOME 2 - * - */ - -#ifndef _TYPEMISMATCHEXCEPTION_H_ -#define _TYPEMISMATCHEXCEPTION_H_ - -#include "Batch_Defines.hxx" - - -#include "Batch_GenericException.hxx" - -namespace Batch { - - class BATCH_EXPORT TypeMismatchException : public GenericException - { - public: - // Constructeur - TypeMismatchException(std::string ch = "undefined") : GenericException("TypeMismatchException", ch) {} - }; - -} - -#endif - diff --git a/src/Core/Batch_Utils.cxx b/src/Core/Batch_Utils.cxx deleted file mode 100644 index e3c864a..0000000 --- a/src/Core/Batch_Utils.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2007-2012 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_Utils.cxx - * - * Created on: 30 jan. 2012 - * Author : Renaud BARATE - EDF R&D - */ - -#include - -#include -#include "Batch_Utils.hxx" - -#ifdef MSVC -#define popen _popen -#define pclose _pclose -#endif - -using namespace std; -namespace Batch { - -int Utils::getCommandOutput(const string & command, string & output) -{ - // Reinitialize output - output = ""; - - // Call command - FILE * fp = popen(command.c_str(), "r"); - if (fp == NULL) { - return -1; - } - - // Read the output and store it - char buf[1024]; - while (fgets(buf, sizeof(buf), fp) != NULL) { - output += buf; - } - - // close and get status - int status = pclose(fp); - return status; -} - -bool Utils::isAbsolutePath(const string & path) -{ - if (path.size() == 0) - return false; - return path[0] == '/'; -} - -} diff --git a/src/Core/Batch_Utils.hxx b/src/Core/Batch_Utils.hxx deleted file mode 100644 index c14273b..0000000 --- a/src/Core/Batch_Utils.hxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2012 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_Utils.hxx - * - * Created on: 30 jan. 2012 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef BATCH_UTILS_HXX_ -#define BATCH_UTILS_HXX_ - -#include - -namespace Batch { - -class Utils { -public: - - /** - * Call a command with the system shell and stores its output in parameter "output". - * Returns the return code of the command. - */ - static int getCommandOutput(const std::string & command, std::string & output); - - /** - * Test if the path in parameter is an absolute path (does not test the existence of - * a file or directory at this path). - */ - static bool isAbsolutePath(const std::string & path); - -private: - - // No instanciation possible as this class provides only static methods - Utils() { } - -}; - -} - -#endif /* BATCH_UTILS_HXX_ */ diff --git a/src/Core/Batch_Versatile.cxx b/src/Core/Batch_Versatile.cxx deleted file mode 100644 index 834caff..0000000 --- a/src/Core/Batch_Versatile.cxx +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Versatile.cxx : - * - * Author : Ivan DUTKA-MALEN - EDF R&D - * Date : September 2003 - * - */ - -#include -#include -#include -#include - -#include "Batch_GenericType.hxx" -#include "Batch_BoolType.hxx" -#include "Batch_CharType.hxx" -#include "Batch_LongType.hxx" -#include "Batch_StringType.hxx" -#include "Batch_Versatile.hxx" -#include "Batch_TypeMismatchException.hxx" -#include "Batch_ListIsFullException.hxx" - -using namespace std; - -namespace Batch { - - Versatile::Versatile(DiscriminatorType discriminator, size_type maxsize, std::string name) - : _discriminator(discriminator), - _maxsize(maxsize), - _name(name) - { - } - - Versatile::Versatile(const Versatile & V) - : _discriminator(V._discriminator), - _maxsize(V._maxsize), - _name(V._name) - { - Versatile::const_iterator it; - for(it=V.begin(); it!=V.end(); it++) - push_back( (*it)->clone() ); - } - - Versatile::~Versatile() - { - eraseAll(); - } - - Versatile & Versatile::operator = (const long l) throw(TypeMismatchException) - { - checkType(LONG); - eraseAll(); - push_back(new LongType(l)); - return *this; - } - - Versatile & Versatile::operator = (const string & ch) throw(TypeMismatchException) - { - checkType(STRING); - eraseAll(); - push_back(new StringType(ch)); - return *this; - } - - Versatile & Versatile::operator +=(const string & ch) throw(TypeMismatchException,ListIsFullException) - { - checkType(STRING); - - // If max size is reached, throw a ListIsFullException - if (_maxsize == 0 || size() < _maxsize) - push_back(new StringType(ch)); - else { - ostringstream msg; - msg << "Maximum size for \"" << _name << "\" is reached: " << _maxsize; - throw(ListIsFullException(msg.str())); - } - return *this; - } - - Versatile & Versatile::operator , (const string & ch) throw(TypeMismatchException,ListIsFullException) - { - *this += ch; - return *this; - } - - Versatile & Versatile::operator = (const char * ch) throw(TypeMismatchException) - { - return operator=(string(ch)); - } - - Versatile & Versatile::operator +=(const char * ch) throw(TypeMismatchException,ListIsFullException) - { - return operator+=(string(ch)); - } - - Versatile & Versatile::operator , (const char * ch) throw(TypeMismatchException,ListIsFullException) - { - return operator,(string(ch)); - } - - Versatile & Versatile::operator = (const Couple & cp) throw(TypeMismatchException) - { - checkType(COUPLE); - eraseAll(); - push_back(new CoupleType(cp)); - return *this; - } - - Versatile & Versatile::operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException) - { - checkType(COUPLE); - // If max size is reached, throw a ListIsFullException - if (_maxsize == 0 || size() < _maxsize) - push_back(new CoupleType(cp)); - else { - ostringstream msg; - msg << "Maximum size for \"" << _name << "\" is reached: " << _maxsize; - throw(ListIsFullException(msg.str())); - } - return *this; - } - - Versatile & Versatile::operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException) - { - *this += cp; - return *this; - } - - ostream & operator << (ostream & os, const Versatile & V) - { - Versatile::const_iterator it; - const char * sep = ""; - - for(it=V.begin(); it!=V.end(); it++, sep=" ") { - string s = (*it)->affiche(); - os << sep << s; - } - return os; - } - - Versatile & Versatile::operator = (const int i) throw(TypeMismatchException) - { - checkType(LONG); - eraseAll(); - push_back(new LongType((long)i)); - return *this; - } - - Versatile & Versatile::operator = (const bool b) throw(TypeMismatchException) - { - checkType(BOOL); - eraseAll(); - push_back(new BoolType(b)); - return *this; - } - - void Versatile::checkType(DiscriminatorType t) const throw(TypeMismatchException) - { - if (_discriminator != t) - throw (TypeMismatchException("Trying to change type of Versatile object \"" + _name + "\"")); - } - - Versatile::operator long() const throw(TypeMismatchException) - { - // If the type does not correspond or if the list has more than one element, - // throw a TypeMismatchException - if ( _maxsize != 1 || _discriminator != LONG || size() == 0 ) { - ostringstream sst; - sst << "Cannot cast Versatile object \"" << _name << "\" to long"; - throw (TypeMismatchException(sst.str())); - } - return *( static_cast(this->front()) ); - } - - Versatile::operator bool() const throw(TypeMismatchException) - { - // If the type does not correspond or if the list has more than one element, - // throw a TypeMismatchException - if ( _maxsize != 1 || _discriminator != BOOL || size() == 0 ) { - ostringstream sst; - sst << "Cannot cast Versatile object \"" << _name << "\" to bool"; - throw(TypeMismatchException(sst.str())); - } - return *( static_cast(this->front()) ); - } - - Versatile::operator int() const throw(TypeMismatchException) - { - return operator long(); - } - - Versatile::operator Couple() const throw(TypeMismatchException) - { - // If the type does not correspond or if the list has more than one element, - // throw a TypeMismatchException - if ( _maxsize != 1 || _discriminator != COUPLE || size() == 0 ) { - ostringstream sst; - sst << "Cannot cast Versatile object \"" << _name << "\" to Couple"; - throw(TypeMismatchException(sst.str())); - } - return *( static_cast(this->front()) ); - } - - string Versatile::str() const throw(TypeMismatchException) - { - // If the type does not correspond, throw a TypeMismatchException - if ( _discriminator != STRING || size() == 0 ) { - ostringstream sst; - sst << "Cannot cast Versatile object \"" << _name << "\" to string"; - throw(TypeMismatchException(sst.str())); - } - - // The returned string is the concatenation of internal strings - string s; - Versatile::const_iterator it; - const char * sep = ""; - for(it=begin(); it!=end(); it++, s+=sep, sep=" ") - s += *( static_cast(*it)); - - return s; - } - - Versatile::operator string () const throw(TypeMismatchException) - { - return str(); - } - - void Versatile::eraseAll() - { - while(!empty()) { - delete back(); - pop_back(); - } - } - - DiscriminatorType Versatile::getType() const - { - return _discriminator; - } - - Versatile::size_type Versatile::getMaxSize() const - { - return _maxsize; - } - - const string & Versatile::getName() const - { - return _name; - } - -} diff --git a/src/Core/Batch_Versatile.hxx b/src/Core/Batch_Versatile.hxx deleted file mode 100644 index 2f909b6..0000000 --- a/src/Core/Batch_Versatile.hxx +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Versatile.hxx : - * - * Author : Ivan DUTKA-MALEN - EDF R&D - * Date : September 2003 - * - */ - -#ifndef _VERSATILE_H_ -#define _VERSATILE_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include -#include "Batch_GenericType.hxx" -#include "Batch_BoolType.hxx" -#include "Batch_CharType.hxx" -#include "Batch_LongType.hxx" -#include "Batch_StringType.hxx" -#include "Batch_CoupleType.hxx" -#include "Batch_TypeMismatchException.hxx" -#include "Batch_ListIsFullException.hxx" -#include "Batch_RunTimeException.hxx" - -namespace Batch { - - // Authorized types - enum DiscriminatorType { BOOL, LONG, STRING, COUPLE }; - - class BATCH_EXPORT Versatile : public std::list< GenericType * > - { - public: - - // Constructors - Versatile(DiscriminatorType discriminator, size_type maxsize, std::string name); - Versatile(const Versatile & V); - - // Use of default constructor is forbidden but we cannot declare it private because - // compilation fails with VC8 on Windows - Versatile() { throw RunTimeException("Forbidden constructor"); } - - // Destructor - virtual ~Versatile(); - - // Affectation and concatenation operators from base types - Versatile & operator = (const long l) throw(TypeMismatchException); - Versatile & operator = (const std::string & ch) throw(TypeMismatchException); - Versatile & operator +=(const std::string & ch) throw(TypeMismatchException,ListIsFullException); - Versatile & operator , (const std::string & ch) throw(TypeMismatchException,ListIsFullException); - Versatile & operator = (const char * ch) throw(TypeMismatchException); - Versatile & operator +=(const char * ch) throw(TypeMismatchException,ListIsFullException); - Versatile & operator , (const char * ch) throw(TypeMismatchException,ListIsFullException); - Versatile & operator = (const Couple & cp) throw(TypeMismatchException); - Versatile & operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException); - Versatile & operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException); - Versatile & operator = (const int i) throw(TypeMismatchException); - Versatile & operator = (const bool b) throw(TypeMismatchException); - - // Type conversion to base types - operator long() const throw(TypeMismatchException); - operator std::string() const throw(TypeMismatchException); - operator Couple() const throw(TypeMismatchException); - std::string str() const throw(TypeMismatchException); - operator bool() const throw(TypeMismatchException); - operator int() const throw(TypeMismatchException); - - // Display on a stream - BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & ); - - // Check the type - void checkType(DiscriminatorType t) const throw (TypeMismatchException); - - // Getter methods - DiscriminatorType getType() const; - size_type getMaxSize() const; - const std::string & getName() const; - - // Erase all internal elements - void eraseAll(); - - protected: - - DiscriminatorType _discriminator; // Internal element type - size_type _maxsize; // Maximum number of internal elements - std::string _name; // Object name (used for exceptions) - - private: - - // Forbid the use of affectation operator - void operator= (const Versatile & V) {} - - }; - -} - -#endif diff --git a/src/Core/BoolType.cxx b/src/Core/BoolType.cxx new file mode 100644 index 0000000..66b4f07 --- /dev/null +++ b/src/Core/BoolType.cxx @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2012 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 +// +/* + * BoolType.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include +#include +#include "BoolType.hxx" +using namespace std; + +namespace Batch { + + // Conversion en chaine + string BoolType::affiche() const + { + return _data ? string("true") : string("false"); + } + + // Operateur d'affectation + BoolType & BoolType::operator =(bool b) + { + _data = b; + return *this; + } + + // Conversion en bool + BoolType::operator bool() const + { + return this->_data; + } + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + GenericType * BoolType::clone() const + { + BoolType * pB = new BoolType(this->_data); + assert(pB != 0); + return pB; + } + +} diff --git a/src/Core/BoolType.hxx b/src/Core/BoolType.hxx new file mode 100644 index 0000000..e7a27c3 --- /dev/null +++ b/src/Core/BoolType.hxx @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2012 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 +// +/* + * BoolType.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _BOOLTYPE_H_ +#define _BOOLTYPE_H_ + +#include "Defines.hxx" + +#include +#include "GenericType.hxx" + +namespace Batch { + + class BATCH_EXPORT BoolType : public GenericType + { + public: + // Constructeur + BoolType(const bool b=false) : _data(b) {} + + // Conversion en chaine + virtual std::string affiche() const; + + // Operateur d'affectation + virtual BoolType & operator =(bool); + + // Conversion en bool + virtual operator bool() const; + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + virtual GenericType * clone() const; + + protected: + bool _data; + + private: + + }; + +} + +#endif diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 8b0136a..0e53214 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -20,57 +20,51 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST Core/Batch_APIInternalFailureException - Core/Batch_BatchManager_eClient - Core/Batch_BatchManager - Core/Batch_BatchManagerCatalog - Core/Batch_BoolType - Core/Batch_CharType - Core/Batch_CommunicationProtocol - Core/Batch_ConnexionFailureException - Core/Batch_Constants - Core/Batch_Couple - Core/Batch_CoupleType - Core/Batch_Date - Core/Batch_DateType - Core/Batch_EmulationException - Core/Batch_Environnement - Core/Batch_FactBatchManager_eClient - Core/Batch_FactBatchManager - Core/Batch_GenericException - Core/Batch_GenericType - Core/Batch_InvalidArgumentException - Core/Batch_InvalidKeyException - Core/Batch_Job - Core/Batch_JobId - Core/Batch_JobInfo - Core/Batch_ListIsFullException - Core/Batch_LongType - Core/Batch_MpiImpl - Core/Batch_NotYetImplementedException - Core/Batch_ParameterTypeMap - Core/Batch_Parametre - Core/Batch_RunTimeException - Core/Batch_StringType - Core/Batch_TypeMismatchException - Core/Batch_Versatile - Core/Batch_Utils +SET(CLASS_LIST Core/APIInternalFailureException + Core/BatchManager + Core/BatchManagerCatalog + Core/BoolType + Core/CommunicationProtocol + Core/Constants + Core/Couple + Core/CoupleType + Core/Environnement + Core/FactBatchManager + Core/GenericException + Core/GenericType + Core/InvalidArgumentException + Core/InvalidKeyException + Core/Job + Core/JobId + Core/JobInfo + Core/ListIsFullException + Core/LongType + Core/MpiImpl + Core/NotYetImplementedException + Core/ParameterTypeMap + Core/Parametre + Core/RunTimeException + Core/StringType + Core/TypeMismatchException + Core/Versatile ) -APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) +APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST} + Core/Utils + Core/Log) APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST}) -APPEND_CLASSES_TO_HDR_FILES(Core/Batch_Defines) +APPEND_CLASSES_TO_HDR_FILES(Core/Defines) IF (HAS_SH) - APPEND_CLASSES_TO_SRC_FILES(Core/Batch_CommunicationProtocolSH) + APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSH) ENDIF (HAS_SH) IF (HAS_RSH) - APPEND_CLASSES_TO_SRC_FILES(Core/Batch_CommunicationProtocolRSH) + APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolRSH) ENDIF (HAS_RSH) IF (HAS_SSH) - APPEND_CLASSES_TO_SRC_FILES(Core/Batch_CommunicationProtocolSSH) + APPEND_CLASSES_TO_SRC_FILES(Core/CommunicationProtocolSSH) ENDIF (HAS_SSH) diff --git a/src/Core/CommunicationProtocol.cxx b/src/Core/CommunicationProtocol.cxx new file mode 100644 index 0000000..371ba8d --- /dev/null +++ b/src/Core/CommunicationProtocol.cxx @@ -0,0 +1,176 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocol.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#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 +#include "APIInternalFailureException.hxx" +#include "RunTimeException.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + CommunicationProtocol::CommunicationProtocol(CommunicationProtocolType type) + : _type(type) + { + } + + 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)); + LOG(command); + int status = system(command.c_str()); + return status; + } + + string CommunicationProtocol::getRemoveSubCommand(const string & path) const + { + return string("rm ") + path; + } + + string CommunicationProtocol::getMakeDirectorySubCommand(const string & path) const + { + return string("mkdir -p ") + path; + } + + int CommunicationProtocol::removeFile(const std::string & path, + const std::string & host, + const std::string & user) const + { + string command = getExecCommand(getRemoveSubCommand(path), host, user); + LOG(command); + int status = system(command.c_str()); + return status; + } + + int CommunicationProtocol::makeDirectory(const std::string & path, + const std::string & host, + const std::string & user) const + { + string command = getExecCommand(getMakeDirectorySubCommand(path), host, user); + LOG(command); + 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 "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; + + virtual int makeDirectory(const std::string & path, + const std::string & host, + const std::string & user) const; + + CommunicationProtocolType getType() const; + + protected: + + CommunicationProtocol(CommunicationProtocolType type = SH); + + 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; + + virtual std::string getMakeDirectorySubCommand(const std::string & path) const; + + std::string commandStringFromArgs(const std::vector & args) const; + + CommunicationProtocolType _type; + + }; + +} + +#endif diff --git a/src/Core/CommunicationProtocolRSH.cxx b/src/Core/CommunicationProtocolRSH.cxx new file mode 100644 index 0000000..7c69d15 --- /dev/null +++ b/src/Core/CommunicationProtocolRSH.cxx @@ -0,0 +1,198 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolRSH.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifdef WIN32 +#include +#include + +#include +#endif + +#include + +#include "CommunicationProtocolRSH.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + CommunicationProtocolRSH::CommunicationProtocolRSH() + : CommunicationProtocol(RSH) + { + } + + 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("-r"); + 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'; + LOG("Changing directory: " << newdir); + _chdir(newdir); + } + + int status = CommunicationProtocol::copyFile(sourcePathWithoutDrive, sourceHost, sourceUser, + destinationPathWithoutDrive, destinationHost, destinationUser); + + // Go back to previous directory if necessary + if (driveLetter != '\0' && driveLetter != currentDrive) { + LOG("Changing directory: " << cwd); + _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/CommunicationProtocolRSH.hxx b/src/Core/CommunicationProtocolRSH.hxx new file mode 100644 index 0000000..c62fc9a --- /dev/null +++ b/src/Core/CommunicationProtocolRSH.hxx @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolRSH.hxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLRSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLRSH_H_ + +#include +#include + +#include "Defines.hxx" +#include "CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolRSH : public CommunicationProtocol + { + friend class 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; + +#endif + + protected: + +#ifdef WIN32 + + char getDriveLetter(const std::string & path, std::string * pathWithoutDrive = NULL) const; + +#endif + + CommunicationProtocolRSH(); + + }; + +} + +#endif diff --git a/src/Core/CommunicationProtocolSH.cxx b/src/Core/CommunicationProtocolSH.cxx new file mode 100644 index 0000000..89968d9 --- /dev/null +++ b/src/Core/CommunicationProtocolSH.cxx @@ -0,0 +1,94 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolSH.cxx : + * + * Created on: 16 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "CommunicationProtocolSH.hxx" +#include "Utils.hxx" + +using namespace std; + +namespace Batch { + + CommunicationProtocolSH::CommunicationProtocolSH() + : CommunicationProtocol(SH) + { + } + + vector CommunicationProtocolSH::getExecCommandArgs(const string & subCommand, + const string & host, + const string & user) const + { + vector cmd; + + cmd.push_back(Utils::fixPath(SH_COMMAND)); + +#ifdef WIN32 + cmd.push_back("/c"); +#else + cmd.push_back("-c"); +#endif + + cmd.push_back(Utils::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); +#ifndef WIN32 + cmd.push_back("-r"); +#endif + cmd.push_back(Utils::fixPath(sourcePath)); + cmd.push_back(Utils::fixPath(destinationPath)); + return cmd; + } + + string CommunicationProtocolSH::getRemoveSubCommand(const string & path) const + { + return string(RM_COMMAND) + " " + Utils::fixPath(path); + } + + string CommunicationProtocolSH::getMakeDirectorySubCommand(const string & path) const + { + string subCommand = MKDIR_COMMAND; +#ifndef WIN32 + subCommand += " -p"; +#endif + subCommand += " " + Utils::fixPath(path); + return subCommand; + } + +} diff --git a/src/Core/CommunicationProtocolSH.hxx b/src/Core/CommunicationProtocolSH.hxx new file mode 100644 index 0000000..b6b9a78 --- /dev/null +++ b/src/Core/CommunicationProtocolSH.hxx @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolSH.hxx : + * + * Created on: 16 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLSH_H_ + +#include +#include + +#include "Defines.hxx" +#include "CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolSH : public CommunicationProtocol + { + friend class 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: + + CommunicationProtocolSH(); + + std::string getRemoveSubCommand(const std::string & path) const; + + std::string getMakeDirectorySubCommand(const std::string & path) const; + + }; + +} + +#endif diff --git a/src/Core/CommunicationProtocolSSH.cxx b/src/Core/CommunicationProtocolSSH.cxx new file mode 100644 index 0000000..b6883a4 --- /dev/null +++ b/src/Core/CommunicationProtocolSSH.cxx @@ -0,0 +1,111 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolSSH.cxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "CommunicationProtocolSSH.hxx" + +using namespace std; + +namespace Batch { + + CommunicationProtocolSSH::CommunicationProtocolSSH() + : CommunicationProtocol(SSH) + { + } + + 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 + ":"; + } +#ifndef WIN32 + fullSource += "'"; +#endif + fullSource += sourcePath; +#ifndef WIN32 + fullSource += "'"; +#endif + + string fullDestination; + if (destinationHost.size() != 0) { + if (destinationUser.size() != 0) { + fullDestination += destinationUser + "@"; + } + fullDestination += destinationHost + ":"; + } +#ifndef WIN32 + fullDestination += "'"; +#endif + fullDestination += destinationPath; +#ifndef WIN32 + fullDestination += "'"; +#endif + + // 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("-r"); + cmd.push_back(fullSource); + cmd.push_back(fullDestination); + + return cmd; + } + +} diff --git a/src/Core/CommunicationProtocolSSH.hxx b/src/Core/CommunicationProtocolSSH.hxx new file mode 100644 index 0000000..3aadcce --- /dev/null +++ b/src/Core/CommunicationProtocolSSH.hxx @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CommunicationProtocolSSH.hxx : + * + * Created on: 14 sept. 2009 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHCOMMUNICATIONPROTOCOLSSH_H_ +#define _BATCHCOMMUNICATIONPROTOCOLSSH_H_ + +#include +#include + +#include "Defines.hxx" +#include "CommunicationProtocol.hxx" + +namespace Batch { + + class BATCH_EXPORT CommunicationProtocolSSH : public CommunicationProtocol + { + friend class 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: + + CommunicationProtocolSSH(); + + }; + +} + +#endif diff --git a/src/Core/Constants.cxx b/src/Core/Constants.cxx new file mode 100644 index 0000000..c6df750 --- /dev/null +++ b/src/Core/Constants.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Constants.cxx : + * + * Auteur : Renaud BARATE - EDF R&D + * Date : January 2010 + * + */ + +#include "Constants.hxx" + +namespace Batch { + + // Definition of the string constants (keys for the parameter map) + def_Constant(ARGUMENTS); + def_Constant(EXECUTABLE); + def_Constant(ID); + def_Constant(INFILE); + def_Constant(MAXCPUTIME); + def_Constant(MAXDISKSIZE); + def_Constant(MAXRAMSIZE); + def_Constant(MAXWALLTIME); + def_Constant(NAME); + def_Constant(NBPROC); + def_Constant(NBPROCPERNODE); + def_Constant(OUTFILE); + def_Constant(QUEUE); + def_Constant(STATE); + def_Constant(WORKDIR); + def_Constant(EXCLUSIVE); + + // These constants define the status of a job (parameter STATE); + def_Constant(CREATED); + def_Constant(IN_PROCESS); + def_Constant(QUEUED); + def_Constant(RUNNING); + def_Constant(PAUSED); + def_Constant(FINISHED); + def_Constant(FAILED); + +} diff --git a/src/Core/Constants.hxx b/src/Core/Constants.hxx new file mode 100644 index 0000000..46cbaf1 --- /dev/null +++ b/src/Core/Constants.hxx @@ -0,0 +1,74 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Constants.hxx : + * + * Auteur : Renaud BARATE - EDF R&D + * Date : January 2010 + * + */ + +#ifndef _CONSTANTS_H_ +#define _CONSTANTS_H_ + +#include + +#include "Defines.hxx" + +// These macros simplify the creation of new string constants for keys and +// values in parameters map. +// TODO: replace those static declarations by an external description file (XML for instance) +#define decl_extern_Constant(constant) extern BATCH_EXPORT const std::string constant +#define def_Constant(constant) const std::string constant = #constant + +namespace Batch { + + // Declaration of the keys for the parameter map + decl_extern_Constant(ARGUMENTS); + decl_extern_Constant(EXECUTABLE); + decl_extern_Constant(ID); + decl_extern_Constant(INFILE); + decl_extern_Constant(MAXCPUTIME); + decl_extern_Constant(MAXDISKSIZE); + decl_extern_Constant(MAXRAMSIZE); + decl_extern_Constant(MAXWALLTIME); + decl_extern_Constant(NAME); + decl_extern_Constant(NBPROC); + decl_extern_Constant(NBPROCPERNODE); + decl_extern_Constant(OUTFILE); + decl_extern_Constant(QUEUE); + decl_extern_Constant(STATE); + decl_extern_Constant(WORKDIR); + decl_extern_Constant(EXCLUSIVE); + + // These constants define the status of a job (parameter STATE) + decl_extern_Constant(CREATED); + decl_extern_Constant(IN_PROCESS); + decl_extern_Constant(QUEUED); + decl_extern_Constant(RUNNING); + decl_extern_Constant(PAUSED); + decl_extern_Constant(FINISHED); + decl_extern_Constant(FAILED); + +} + +#endif diff --git a/src/Core/Couple.cxx b/src/Core/Couple.cxx new file mode 100644 index 0000000..4782efb --- /dev/null +++ b/src/Core/Couple.cxx @@ -0,0 +1,63 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Couple.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Dec 9 15:00:35 2003 + * Projet : Salome 2 + * + */ + +#include "Couple.hxx" +using namespace std; + +namespace Batch { + + // Operateur d'affectation + Couple & Couple::operator =(const Couple & C) + { + _local = C._local; + _remote = C._remote; + return *this; + } + + // Conversion en chaine + string Couple::str() const + { + string res; + res = "Couple(local : "; + res += _local; + res += ", remote : "; + res += _remote; + res += ")"; + return res; + } + + // Operateur pour l'affichage sur un stream + ostream & operator << (ostream & os, const Couple & cp) + { + return os << cp.str(); + } + +} diff --git a/src/Core/Couple.hxx b/src/Core/Couple.hxx new file mode 100644 index 0000000..fe41fbc --- /dev/null +++ b/src/Core/Couple.hxx @@ -0,0 +1,76 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Couple.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Dec 9 15:00:35 2003 + * Projet : Salome 2 + * + */ + +#ifndef _COUPLE_H_ +#define _COUPLE_H_ + +#include "Defines.hxx" + +#include + +namespace Batch { + + class BATCH_EXPORT Couple + { + public: + // Constructeur standard + Couple(const std::string & local="", const std::string & remote="") : _local(local), _remote(remote) {} + + // Constructeur par recopie + Couple(const Couple & C) : _local(C._local), _remote(C._remote) {} + + // Destructeur + virtual ~Couple() {} + + // Operateur pour l'affichage sur un stream + BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Couple & cp); + + // Operateur d'affectation + virtual Couple & operator =(const Couple &); + + // Conversion en chaine + virtual std::string str() const; + + // Accesseurs + virtual std::string getLocal() const { return _local; } + virtual std::string getRemote() const { return _remote; } + + protected: + std::string _local; // chemin d'acces au fichier local + std::string _remote; // chemin d'acees au fichier distant + + private: + + }; + +} + +#endif diff --git a/src/Core/CoupleType.cxx b/src/Core/CoupleType.cxx new file mode 100644 index 0000000..0b7144b --- /dev/null +++ b/src/Core/CoupleType.cxx @@ -0,0 +1,73 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CoupleType.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Dec 9 14:51:53 2003 + * Projet : Salome 2 + * + */ + +#include +#include "CoupleType.hxx" +using namespace std; + +namespace Batch { + + // Conversion en chaine + string CoupleType::affiche() const + { + return _data.str(); + } + + // Operateur d'affectation + CoupleType & CoupleType::operator =(const Couple & C) + { + _data = C; + return *this; + } + + // Conversion en char + CoupleType::operator Couple() const + { + return _data; + } + + // Conversion en chaine + CoupleType::operator string() const + { + return _data.str(); + } + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + GenericType * CoupleType::clone() const + { + CoupleType * pC = new CoupleType(this->_data); + assert(pC != 0); + return pC; + } + +} + diff --git a/src/Core/CoupleType.hxx b/src/Core/CoupleType.hxx new file mode 100644 index 0000000..b6fcf7a --- /dev/null +++ b/src/Core/CoupleType.hxx @@ -0,0 +1,72 @@ +// Copyright (C) 2007-2012 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 +// +/* + * CoupleType.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Dec 9 14:51:53 2003 + * Projet : Salome 2 + * + */ + +#ifndef _COUPLETYPE_H_ +#define _COUPLETYPE_H_ + +#include "Defines.hxx" + +#include +#include "GenericType.hxx" +#include "Couple.hxx" + +namespace Batch { + + class BATCH_EXPORT CoupleType : public GenericType + { + public: + // Constructeur + CoupleType(const Couple & C) : _data(C) {} + + // Conversion en chaine + virtual std::string affiche() const; + virtual operator std::string() const; + + // Operateur d'affectation + virtual CoupleType & operator =(const Couple & C); + + // Conversion en char + virtual operator Couple() const; + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + virtual GenericType * clone() const; + + protected: + Couple _data; + + private: + + }; + +} + +#endif diff --git a/src/Core/Defines.hxx b/src/Core/Defines.hxx new file mode 100644 index 0000000..0cecc1a --- /dev/null +++ b/src/Core/Defines.hxx @@ -0,0 +1,39 @@ +// Copyright (C) 2007-2012 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 +// +// File : Defines.hxx +// Author : Alexander A. BORODIN +// Module : SALOME +// +#ifndef _BATCH_Defines_HXX_ +#define _BATCH_Defines_HXX_ + +#ifdef WIN32 +# if defined batch_EXPORTS +# define BATCH_EXPORT __declspec( dllexport ) +# else +# define BATCH_EXPORT __declspec( dllimport ) +# endif +#else +# define BATCH_EXPORT +#endif + +#endif diff --git a/src/Core/Environnement.cxx b/src/Core/Environnement.cxx new file mode 100644 index 0000000..db85263 --- /dev/null +++ b/src/Core/Environnement.cxx @@ -0,0 +1,38 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Environnement.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Oct 16 11:37:47 2003 + * Projet : Salome 2 + * + */ + +#include "Environnement.hxx" +using namespace std; + +namespace Batch { + + +} diff --git a/src/Core/Environnement.hxx b/src/Core/Environnement.hxx new file mode 100644 index 0000000..75eb7a7 --- /dev/null +++ b/src/Core/Environnement.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Environnement.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Oct 16 11:37:47 2003 + * Projet : Salome 2 + * + */ + +#ifndef _ENVIRONNEMENT_H_ +#define _ENVIRONNEMENT_H_ + +#include "Defines.hxx" + + +#include +#include + +namespace Batch { + + typedef std::map < std::string, std::string > Environnement; + +} + +#endif + diff --git a/src/Core/FactBatchManager.cxx b/src/Core/FactBatchManager.cxx new file mode 100644 index 0000000..dae5f12 --- /dev/null +++ b/src/Core/FactBatchManager.cxx @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2012 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.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#include +#include +#include +#include "BatchManagerCatalog.hxx" +#include "FactBatchManager.hxx" +using namespace std; + +namespace Batch { + + // Constructeur + FactBatchManager::FactBatchManager(const string & _t) : type(_t) + { + BatchManagerCatalog::getInstance().addFactBatchManager(type.c_str(), this); + } + + // Destructeur + FactBatchManager::~FactBatchManager() + { + // Nothing to do + } + + // Accesseur + const string & FactBatchManager::getType() const + { + return type; + } + + string FactBatchManager::__repr__() const + { + ostringstream oss; + oss << ""; + return oss.str(); + } + +} diff --git a/src/Core/FactBatchManager.hxx b/src/Core/FactBatchManager.hxx new file mode 100644 index 0000000..9b4fd73 --- /dev/null +++ b/src/Core/FactBatchManager.hxx @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2012 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.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2004 + * Projet : SALOME 2 + * + */ + +#ifndef _FACTBATCHMANAGER_H_ +#define _FACTBATCHMANAGER_H_ + +#include + +#include "Defines.hxx" +#include "CommunicationProtocol.hxx" + +namespace Batch { + + class BatchManager; + + class BATCH_EXPORT FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager(const std::string & type); + virtual ~FactBatchManager(); + + virtual Batch::BatchManager * operator() (const char * hostname, + const char * username = "", + CommunicationProtocolType protocolType = SSH, + const char * mpi = "nompi") const = 0; + const std::string & getType() const; + std::string __repr__() const; + + protected: + std::string type; + + }; + +} + +#endif diff --git a/src/Core/GenericException.cxx b/src/Core/GenericException.cxx new file mode 100644 index 0000000..5636488 --- /dev/null +++ b/src/Core/GenericException.cxx @@ -0,0 +1,45 @@ +// Copyright (C) 2007-2012 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 +// +/* + * GenericException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Wed Nov 26 10:15:57 2003 + * Projet : Salome 2 + * + */ + +#include +#include "GenericException.hxx" + +using namespace std; + +namespace Batch { + +// Operator for writing on a stream +ostream & operator <<(ostream & os, const GenericException & e) +{ + return os << e.type << ": " << e.message; +} + +} diff --git a/src/Core/GenericException.hxx b/src/Core/GenericException.hxx new file mode 100644 index 0000000..cbeaa93 --- /dev/null +++ b/src/Core/GenericException.hxx @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2012 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 +// +/* + * GenericException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Wed Nov 26 10:15:56 2003 + * Projet : Salome 2 + * + */ + +#ifndef _GENERICEXCEPTION_H_ +#define _GENERICEXCEPTION_H_ + +#include "Defines.hxx" + + +#include + +namespace Batch { + + class BATCH_EXPORT GenericException + { + public: + const std::string type; // la nature de l'exception + const std::string message; // la raison de l'exception + + // Constructeur + GenericException(const std::string & tp = "GenericException", + const std::string & ch = "undefined") : type(tp), message(ch) {} + }; + + // Operator for writing on a stream + BATCH_EXPORT std::ostream & operator <<(std::ostream & os, const GenericException & e); + +} + +#endif diff --git a/src/Core/GenericType.cxx b/src/Core/GenericType.cxx new file mode 100644 index 0000000..b8aa499 --- /dev/null +++ b/src/Core/GenericType.cxx @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2012 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 +// +/* + * GenericType.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + + +#include +#include +#include +#include "GenericType.hxx" +using namespace std; + +namespace Batch { + + // nombre total d'objet GenericType et al. + int GenericType::_nb = 0; + + // Operateur pour l'affichage sur un stream + ostream & operator << (ostream & os, const GenericType & obj) + { + return os << obj.affiche(); + } + + // Conversion en chaine + string GenericType::affiche() const + { + return string("(GenericType : si ce message apparait, vous devez avoir un probleme)"); + } + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + GenericType * GenericType::clone() const + { + GenericType * pG = new GenericType; + assert(pG != 0); + return pG; + } + +} + diff --git a/src/Core/GenericType.hxx b/src/Core/GenericType.hxx new file mode 100644 index 0000000..2b3ede3 --- /dev/null +++ b/src/Core/GenericType.hxx @@ -0,0 +1,72 @@ +// Copyright (C) 2007-2012 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 +// +/* + * GenericType.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _GENERICTYPE_H_ +#define _GENERICTYPE_H_ + +#include "Defines.hxx" + + +#include +#include + +namespace Batch { + + class BATCH_EXPORT GenericType + { + public: + // Constructeur et destructeur + GenericType() { _nb++; } + virtual ~GenericType() { _nb--; } + + // Operateur pour l'affichage sur un stream + BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const GenericType & obj); + + // Conversion en chaine + virtual std::string affiche() const; + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + virtual GenericType * clone() const; + + // Retourne le nombre d'objets GenericType et al. + static int getNb() { return _nb; } + + protected: + + private: + static int _nb; // nombre total d'objets GenericType et al. + + }; + +} + +#endif + diff --git a/src/Core/InvalidArgumentException.cxx b/src/Core/InvalidArgumentException.cxx new file mode 100644 index 0000000..9e7534d --- /dev/null +++ b/src/Core/InvalidArgumentException.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2012 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 +// +/* + * InvalidArgumentException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Oct 16 16:18:00 2003 + * Projet : Salome 2 + * + */ + +#include "InvalidArgumentException.hxx" +using namespace std; + +namespace Batch { + +} diff --git a/src/Core/InvalidArgumentException.hxx b/src/Core/InvalidArgumentException.hxx new file mode 100644 index 0000000..fd7d77c --- /dev/null +++ b/src/Core/InvalidArgumentException.hxx @@ -0,0 +1,53 @@ +// Copyright (C) 2007-2012 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 +// +/* + * InvalidArgumentException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Oct 16 16:18:00 2003 + * Projet : Salome 2 + * + */ + +#ifndef _INVALIDARGUMENTEXCEPTION_H_ +#define _INVALIDARGUMENTEXCEPTION_H_ + + +#include "Defines.hxx" + +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT InvalidArgumentException : public GenericException + { + public: + // Constructeur + InvalidArgumentException(const std::string & ch = "undefined") + : GenericException("InvalidArgumentException", ch) {} + }; + +} + +#endif + diff --git a/src/Core/InvalidKeyException.cxx b/src/Core/InvalidKeyException.cxx new file mode 100644 index 0000000..7e6f49a --- /dev/null +++ b/src/Core/InvalidKeyException.cxx @@ -0,0 +1,38 @@ +// Copyright (C) 2007-2012 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 +// +/* + * InvalidKeyException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Wed Oct 15 10:39:51 2003 + * Projet : Salome 2 + * + */ + +#include "InvalidKeyException.hxx" +using namespace std; + +namespace Batch { + +} + diff --git a/src/Core/InvalidKeyException.hxx b/src/Core/InvalidKeyException.hxx new file mode 100644 index 0000000..d70466a --- /dev/null +++ b/src/Core/InvalidKeyException.hxx @@ -0,0 +1,57 @@ +// Copyright (C) 2007-2012 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 +// +/* + * InvalidKeyException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Wed Oct 15 10:39:51 2003 + * Projet : Salome 2 + * + */ + +#ifndef _INVALIDKEYEXCEPTION_H_ +#define _INVALIDKEYEXCEPTION_H_ + +#include "Defines.hxx" + + +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT InvalidKeyException : public GenericException + { + public: + // Constructeur + InvalidKeyException(std::string ch = "undefined") : GenericException("InvalidKeyException", ch) {} + + protected: + + private: + + }; + +} + +#endif + diff --git a/src/Core/Job.cxx b/src/Core/Job.cxx new file mode 100644 index 0000000..f87a905 --- /dev/null +++ b/src/Core/Job.cxx @@ -0,0 +1,117 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Job.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include "Job.hxx" +#include "Parametre.hxx" +#include +//#include "MEDMEM_STRING.hxx" +using namespace std; + +namespace Batch { + + // Constructeur + Job::Job() : _param(), _env() + { + // Nothing to do + } + + + // Constructeur + Job::Job(Parametre param) : _param(param), _env() + { + // Nothing to do + } + + + // Constructeur + Job::Job(Environnement env) : _param(), _env(env) + { + // Nothing to do + } + + + // Constructeur + Job::Job(Parametre param, Environnement env) : _param(param), _env(env) + { + // Nothing to do + } + + // Operateur pour l'affichage sur un stream + ostream & operator <<(ostream & os, const Job & job) + { + return os << job.__str__(); + } + + // Accesseur + Batch::Parametre Job::getParametre() const + { + return _param; + } + + // Accesseur + void Job::setParametre(const Batch::Parametre & param) + { + _param = param; + } + + // Accesseur + Environnement Job::getEnvironnement() const + { + return _env; + } + + // Accesseur + void Job::setEnvironnement(const Environnement & env) + { + _env = env; + } + + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string Job::__str__() const { + //MEDMEM::STRING str; + ostringstream str; + str << ""; + return str.str(); + } + + +} diff --git a/src/Core/Job.hxx b/src/Core/Job.hxx new file mode 100644 index 0000000..5433fdd --- /dev/null +++ b/src/Core/Job.hxx @@ -0,0 +1,78 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Job.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _JOB_H_ +#define _JOB_H_ + +#include "Defines.hxx" + + +#include "Parametre.hxx" +#include "Environnement.hxx" + +namespace Batch { + + class BATCH_EXPORT Job + { + public: + // Constructeurs et destructeur + Job(); + Job(Batch::Parametre param); + Job(Batch::Environnement env); + Job(Batch::Parametre param, Batch::Environnement env); + virtual ~Job() {} + + // Operateur pour l'affichage sur un stream + BATCH_EXPORT friend std::ostream & operator <<(std::ostream & os, const Job & job); + + // Accesseurs + Batch::Parametre getParametre() const; + void setParametre(const Batch::Parametre &); + + // Accesseurs + Batch::Environnement getEnvironnement() const; + void setEnvironnement(const Batch::Environnement &); + + // Methodes pour l'interfacage avec Python (SWIG) + // TODO : supprimer ces methodes et transferer leur definitions dans SWIG + std::string __str__() const; // SWIG : affichage en Python + std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + + protected: + Batch::Parametre _param; // table des parametres batch du job + Batch::Environnement _env; // table des variables d'environnement + + private: + + }; + +} + +#endif diff --git a/src/Core/JobId.cxx b/src/Core/JobId.cxx new file mode 100644 index 0000000..1ff3c58 --- /dev/null +++ b/src/Core/JobId.cxx @@ -0,0 +1,143 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobId.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include "JobId.hxx" +#include "BatchManager.hxx" +#include +#include +//#include "MEDMEM_STRING.hxx" +using namespace std; + +namespace Batch { + + // Constructeur standard + JobId::JobId() : _p_batchmanager(), _reference("undefined") + { + // Nothing to do + } + + // Constructeur avec le pointeur sur le BatchManager associe et avec une reference + JobId::JobId(BatchManager * _p_bm, const string & ref) : _p_batchmanager(_p_bm), _reference(ref) + { + // Nothing to do + } + + // Destructeur + JobId::~JobId() + { + // Nothing to do + } + + // Operateur d'affectation entre objets + JobId & JobId::operator =(const JobId & jobid) + { + _p_batchmanager = jobid._p_batchmanager; + _reference = jobid._reference; + + return *this; + } + + // Constructeur par recopie + JobId::JobId(const JobId & jobid) : _p_batchmanager(jobid._p_batchmanager), _reference(jobid._reference) + { + // Nothing to do + } + + // Accesseur pour la reference interne + string JobId::getReference() const + { + return _reference; + } + + // Permet de recharger un job depuis un fichier + void JobId::setReference(const std::string & new_reference) + { + _reference = new_reference; + } + + // Methode pour le controle du job : retire le job du gestionnaire + void JobId::deleteJob() const + { + assert(_p_batchmanager != 0); + _p_batchmanager->deleteJob(*this); + } + + // Methode pour le controle du job : suspend le job en file d'attente + void JobId::holdJob() const + { + assert(_p_batchmanager != 0); + _p_batchmanager->holdJob(*this); + } + + // Methode pour le controle du job : relache le job suspendu + void JobId::releaseJob() const + { + assert(_p_batchmanager != 0); + _p_batchmanager->releaseJob(*this); + } + + // Methode pour le controle du job : modifie le job en file d'attente + void JobId::alterJob(const Parametre & param, const Environnement & env) const + { + assert(_p_batchmanager != 0); + _p_batchmanager->alterJob(*this, param, env); + } + + // Methode pour le controle du job : modifie le job en file d'attente + void JobId::alterJob(const Parametre & param) const + { + assert(_p_batchmanager != 0); + _p_batchmanager->alterJob(*this, param); + } + + // Methode pour le controle du job : modifie le job en file d'attente + void JobId::alterJob(const Environnement & env) const + { + assert(_p_batchmanager != 0); + _p_batchmanager->alterJob(*this, env); + } + + // Methode pour le controle du job : renvoie l'etat du job + JobInfo JobId::queryJob() const + { + assert(_p_batchmanager != 0); + return _p_batchmanager->queryJob(*this); + } + + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobId::__str__() const { + //MEDMEM::STRING str; + ostringstream str; + str << ""; + return str.str(); + } + +} diff --git a/src/Core/JobId.hxx b/src/Core/JobId.hxx new file mode 100644 index 0000000..48a3c02 --- /dev/null +++ b/src/Core/JobId.hxx @@ -0,0 +1,94 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobId.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _JOBID_H_ +#define _JOBID_H_ + + +#include "Defines.hxx" + +#include "JobInfo.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BatchManager; + + class BATCH_EXPORT JobId + { + friend class BatchManager; + + public: + // Constructeur standard et destructeur + JobId(); + virtual ~JobId(); + + // Constructeur avec le pointeur sur le BatchManager associe et avec une reference + JobId(Batch::BatchManager *, const std::string & ref); + + // Operateur d'affectation entre objets + virtual JobId & operator =(const Batch::JobId &); + + // Constructeur par recopie + JobId(const Batch::JobId &); + + // Accesseur pour la reference interne + virtual std::string getReference() const; + + // Permet de recharger un job depuis un fichier + virtual void setReference(const std::string & new_reference); + + // Methodes pour le controle du job + virtual void deleteJob() const; // retire un job du gestionnaire + virtual void holdJob() const; // suspend un job en file d'attente + virtual void releaseJob() const; // relache un job suspendu + virtual void alterJob(const Batch::Parametre & param, const Batch::Environnement & env) const; // modifie un job en file d'attente + virtual void alterJob(const Batch::Parametre & param) const; // modifie un job en file d'attente + virtual void alterJob(const Batch::Environnement & env) const; // modifie un job en file d'attente + virtual void setParametre(const Batch::Parametre & param) { return alterJob(param); } // modifie un job en file d'attente + virtual void setEnvironnement(const Batch::Environnement & env) { return alterJob(env); } // modifie un job en file d'attente + virtual Batch::JobInfo queryJob() const; // renvoie l'etat du job + + // Methodes pour l'interfacage avec Python (SWIG) + // TODO : supprimer ces methodes et transferer leur definitions dans SWIG + std::string __str__() const; // SWIG : affichage en Python + std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + + protected: + Batch::BatchManager * _p_batchmanager; // pointeur sur le BatchManager qui controle le job + std::string _reference; // reference du job au sein du BatchManager + + private: + + }; + +} + +#endif diff --git a/src/Core/JobInfo.cxx b/src/Core/JobInfo.cxx new file mode 100644 index 0000000..8353ecd --- /dev/null +++ b/src/Core/JobInfo.cxx @@ -0,0 +1,97 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:05:30 2003 + * Projet : Salome 2 + * + */ + +#include +#include +#include + +#include "Constants.hxx" +#include "JobInfo.hxx" + +using namespace std; + +namespace Batch { + + // Destructeur + JobInfo::~JobInfo() + { + // Nothing to do + } + + + // Operateur pour l'affichage sur un stream + ostream & operator <<(ostream & os, const JobInfo & ji) + { + return os << ji.__str__(); + } + + + // Methodes pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo::__str__() const + { + //MEDMEM::STRING sst; + ostringstream sst; + sst << ""; + + return sst.str(); + } + + // Accesseur + Parametre JobInfo::getParametre() const + { + return _param; + } + + // Accesseur + Environnement JobInfo::getEnvironnement() const + { + return _env; + } + + +} diff --git a/src/Core/JobInfo.hxx b/src/Core/JobInfo.hxx new file mode 100644 index 0000000..817c60e --- /dev/null +++ b/src/Core/JobInfo.hxx @@ -0,0 +1,79 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Thu Nov 6 10:05:30 2003 + * Projet : Salome 2 + * + */ + +#ifndef _JOBINFO_H_ +#define _JOBINFO_H_ + +#include "Defines.hxx" + +#include +#include +#include "Parametre.hxx" +#include "Environnement.hxx" + +namespace Batch { + + class BATCH_EXPORT JobInfo + { + public: + // Constructeur standard et destructeur + JobInfo() : _param(), _env() {}; + virtual ~JobInfo(); + + // Constructeur par recopie + JobInfo(const JobInfo & jinfo) : _param(jinfo._param), _env(jinfo._env) {}; + + // Operateur pour l'affichage sur un stream + BATCH_EXPORT friend std::ostream & operator <<(std::ostream & os, const JobInfo & ji); + + // Accesseurs + // _CS_gbo Ajout explicite du namespace pour les besoins de swig (mauvaise gestion + // des namespace par swig. + virtual Batch::Parametre getParametre() const; + virtual Batch::Environnement getEnvironnement() const; + + // Methodes pour l'interfacage avec Python (SWIG) + // TODO : supprimer ces methodes et transferer leur definitions dans SWIG + std::string __str__() const; // SWIG : affichage en Python + std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + + protected: + Parametre _param; // parametres du job + Environnement _env; // variables d'environnement du job + JobInfo(const Parametre & param, const Environnement & env) : _param(param), _env(env) {}; + + private: + + }; + +} + +#endif diff --git a/src/Core/ListIsFullException.cxx b/src/Core/ListIsFullException.cxx new file mode 100644 index 0000000..2b0cd56 --- /dev/null +++ b/src/Core/ListIsFullException.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2012 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 +// +/* + * ListIsFullException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include "ListIsFullException.hxx" +using namespace std; + + +namespace Batch { + +} diff --git a/src/Core/ListIsFullException.hxx b/src/Core/ListIsFullException.hxx new file mode 100644 index 0000000..e1df097 --- /dev/null +++ b/src/Core/ListIsFullException.hxx @@ -0,0 +1,50 @@ +// Copyright (C) 2007-2012 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 +// +/* + * ListIsFullException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _LISTISFULLEXCEPTION_H_ +#define _LISTISFULLEXCEPTION_H_ + +#include "Defines.hxx" + +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT ListIsFullException : public GenericException + { + public: + // Constructeur + ListIsFullException(std::string ch = "undefined") : GenericException("ListIsFullException", ch) {} + }; + +} + +#endif + diff --git a/src/Core/Log.cxx b/src/Core/Log.cxx new file mode 100644 index 0000000..7d4f359 --- /dev/null +++ b/src/Core/Log.cxx @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Log.cxx : + * + * Created on: 28 jan. 2013 + * Author : Renaud BARATE - EDF R&D + */ + +#include "Utils.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + Log::Log() + { + const size_t BUFSIZE = 32; + char date[BUFSIZE]; + time_t curtime = time(NULL); + strftime(date, BUFSIZE, "%Y-%m-%d_%H-%M-%S", localtime(&curtime)); + string prefix = string("log-") + date; + Utils::createAndOpenTemporaryFile(prefix, _stream); + } + + Log::~Log() + { + _stream.close(); + } + + void Log::log(const string & msg) + { + const size_t BUFSIZE = 32; + char timestamp[BUFSIZE]; + time_t curtime = time(NULL); + strftime(timestamp, BUFSIZE, "%Y-%m-%d_%H-%M-%S", localtime(&curtime)); + getInstance()._stream << timestamp << ": " << msg << endl; + } + + Log & Log::getInstance() + { + static Log instance; + return instance; + } + +} diff --git a/src/Core/Log.hxx b/src/Core/Log.hxx new file mode 100644 index 0000000..6647d95 --- /dev/null +++ b/src/Core/Log.hxx @@ -0,0 +1,65 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Log.hxx : + * + * Created on: 28 jan. 2013 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _LOG_H_ +#define _LOG_H_ + +#include +#include +#include + +#include "Defines.hxx" + +#define LOG(msg) {std::ostringstream sstream; sstream << msg; Log::log(sstream.str());} + +namespace Batch { + + class BATCH_EXPORT Log + { + public: + virtual ~Log(); + + static void log(const std::string & msg); + + private: + + Log(); + + static Log & getInstance(); + + // Forbid the use of copy constructor and assignment operator + Log(const Log & orig) {} + void operator=(const Log & orig) {} + + std::ofstream _stream; + + }; + +} + +#endif diff --git a/src/Core/LongType.cxx b/src/Core/LongType.cxx new file mode 100644 index 0000000..f600081 --- /dev/null +++ b/src/Core/LongType.cxx @@ -0,0 +1,71 @@ +// Copyright (C) 2007-2012 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 +// +/* + * LongType.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include +#include +#include +//#include "MEDMEM_STRING.hxx" +#include "LongType.hxx" +using namespace std; + +namespace Batch { + + // Conversion en chaine + string LongType::affiche() const + { + //MEDMEM::STRING sst; + ostringstream sst; + sst << _data; + return sst.str(); + } + + // Operateur d'affectation + LongType & LongType::operator =(long l) + { + _data = l; + return *this; + } + + // Conversion en long + LongType::operator long() const + { + return this->_data; + } + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + GenericType * LongType::clone() const + { + LongType * pL = new LongType(this->_data); + assert(pL != 0); + return pL; + } + +} diff --git a/src/Core/LongType.hxx b/src/Core/LongType.hxx new file mode 100644 index 0000000..dfdeccb --- /dev/null +++ b/src/Core/LongType.hxx @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2012 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 +// +/* + * LongType.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _LONGTYPE_H_ +#define _LONGTYPE_H_ + +#include "Defines.hxx" + +#include +#include "GenericType.hxx" + +namespace Batch { + + class BATCH_EXPORT LongType : public GenericType + { + public: + // Constructeur + LongType(const long l=0L) : _data(l) {} + + // Conversion en chaine + virtual std::string affiche() const; + + // Operateur d'affectation + virtual LongType & operator =(long); + + // Conversion en long + virtual operator long() const; + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + virtual GenericType * clone() const; + + protected: + long _data; + + private: + + }; + +} + +#endif diff --git a/src/Core/MpiImpl.cxx b/src/Core/MpiImpl.cxx new file mode 100644 index 0000000..a319861 --- /dev/null +++ b/src/Core/MpiImpl.cxx @@ -0,0 +1,350 @@ +// Copyright (C) 2007-2012 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 +// + +#include +#include +#include +#include "MpiImpl.hxx" + +using namespace std; + +// Constructor +MpiImpl::MpiImpl() +{ +} + +// Destructor +MpiImpl::~MpiImpl() +{ +} + +// lam implementation +// Constructor +MpiImpl_LAM::MpiImpl_LAM() : MpiImpl() +{ +} + +// Destructor +MpiImpl_LAM::~MpiImpl_LAM() +{ +} + +string MpiImpl_LAM::size() +{ + return "${LAMWORLD}"; +} + +string MpiImpl_LAM::rank() +{ + return "${LAMRANK}"; +} + +string MpiImpl_LAM::boot(const string machinefile, const unsigned int nbnodes) +{ + ostringstream oss; + oss << "lamboot " << machinefile << endl; + return oss.str(); +} + +string MpiImpl_LAM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_LAM::halt() +{ + ostringstream oss; + oss << "lamhalt" << endl; + return oss.str(); +} + +string MpiImpl_LAM::name() +{ + return "lam"; +} + +// mpich1 implementation +// Constructor +MpiImpl_MPICH1::MpiImpl_MPICH1() : MpiImpl() +{ +} + +// Destructor +MpiImpl_MPICH1::~MpiImpl_MPICH1() +{ +} + +string MpiImpl_MPICH1::size() +{ + return "${MPIRUN_NPROCS}"; +} + +string MpiImpl_MPICH1::rank() +{ + return "${MPIRUN_RANK}"; +} + +string MpiImpl_MPICH1::boot(const string machinefile, const unsigned int nbnodes) +{ + return ""; +} + +string MpiImpl_MPICH1::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "mpirun -machinefile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_MPICH1::halt() +{ + return ""; +} + +string MpiImpl_MPICH1::name() +{ + return "mpich"; +} + +// mpich2 implementation +// Constructor +MpiImpl_MPICH2::MpiImpl_MPICH2() : MpiImpl() +{ +} + +// Destructor +MpiImpl_MPICH2::~MpiImpl_MPICH2() +{ +} + +string MpiImpl_MPICH2::size() +{ + return "${PMI_SIZE}"; +} + +string MpiImpl_MPICH2::rank() +{ + return "${PMI_RANK}"; +} + +string MpiImpl_MPICH2::boot(const string machinefile, const unsigned int nbnodes) +{ + ostringstream oss; + oss << "mpdboot" << " -n " << nbnodes; + if (machinefile!="") + oss << " -f " << machinefile; + oss << endl; + return oss.str(); +} + +string MpiImpl_MPICH2::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_MPICH2::halt() +{ + ostringstream oss; + oss << "mpdallexit" << endl; + return oss.str(); +} + +string MpiImpl_MPICH2::name() +{ + return "mpich"; +} + +// openmpi implementation +// Constructor +MpiImpl_OPENMPI::MpiImpl_OPENMPI() : MpiImpl() +{ +} + +// Destructor +MpiImpl_OPENMPI::~MpiImpl_OPENMPI() +{ +} + +string MpiImpl_OPENMPI::size() +{ + return "${OMPI_MCA_ns_nds_num_procs}"; +} + +string MpiImpl_OPENMPI::rank() +{ + return "${OMPI_MCA_ns_nds_vpid}"; +} + +string MpiImpl_OPENMPI::boot(const string machinefile, const unsigned int nbnodes) +{ + return ""; +} + +string MpiImpl_OPENMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_OPENMPI::halt() +{ + return ""; +} + +string MpiImpl_OPENMPI::name() +{ + return "openmpi"; +} + +// ompi implementation +// Constructor +MpiImpl_OMPI::MpiImpl_OMPI() : MpiImpl() +{ +} + +// Destructor +MpiImpl_OMPI::~MpiImpl_OMPI() +{ +} + +string MpiImpl_OMPI::size() +{ + return "${OMPI_MCA_ns_nds_num_procs}"; +} + +string MpiImpl_OMPI::rank() +{ + return "${OMPI_MCA_ns_nds_vpid}"; +} + +string MpiImpl_OMPI::boot(const string machinefile, const unsigned int nbnodes) +{ + return ""; +} + +string MpiImpl_OMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_OMPI::halt() +{ + return ""; +} + +string MpiImpl_OMPI::name() +{ + return "ompi"; +} + +// slurm implementation +// Constructor +MpiImpl_SLURM::MpiImpl_SLURM() : MpiImpl() +{ +} + +// Destructor +MpiImpl_SLURM::~MpiImpl_SLURM() +{ +} + +string MpiImpl_SLURM::size() +{ + return "${SLURM_NPROCS}"; +} + +string MpiImpl_SLURM::rank() +{ + return "${SLURM_PROCID}"; +} + +string MpiImpl_SLURM::boot(const string machinefile, const unsigned int nbnodes) +{ + return ""; +} + +string MpiImpl_SLURM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "srun " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_SLURM::halt() +{ + return ""; +} + +string MpiImpl_SLURM::name() +{ + return "slurm"; +} + +// prun implementation +// Constructor +MpiImpl_PRUN::MpiImpl_PRUN() : MpiImpl() +{ +} + +// Destructor +MpiImpl_PRUN::~MpiImpl_PRUN() +{ +} + +string MpiImpl_PRUN::size() +{ + return "${RMS_NPROCS}"; +} + +string MpiImpl_PRUN::rank() +{ + return "${RMS_RANK}"; +} + +string MpiImpl_PRUN::boot(const string machinefile, const unsigned int nbnodes) +{ + return ""; +} + +string MpiImpl_PRUN::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute) +{ + ostringstream oss; + oss << "prun -n " << nbproc << " " << "-p mpi " << fileNameToExecute << endl; + return oss.str(); +} + +string MpiImpl_PRUN::halt() +{ + return ""; +} + +string MpiImpl_PRUN::name() +{ + return "prun"; +} diff --git a/src/Core/MpiImpl.hxx b/src/Core/MpiImpl.hxx new file mode 100644 index 0000000..a1345d8 --- /dev/null +++ b/src/Core/MpiImpl.hxx @@ -0,0 +1,197 @@ +// Copyright (C) 2007-2012 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 +// + +#ifndef _BL_MPIIMPL_H_ +#define _BL_MPIIMPL_H_ + +#include "Defines.hxx" +#include + +class BATCH_EXPORT MpiImplException +{ +public: + const std::string msg; + + MpiImplException(const std::string m) : msg(m) {} +}; + +class BATCH_EXPORT MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl(); // constrcuctor + virtual ~MpiImpl(); //Destructor + + virtual std::string size() = 0; // get number of process of current job + virtual std::string rank() = 0; // get process number of current job + virtual std::string boot(const std::string machinefile, const unsigned int nbnodes) = 0; // get boot command + virtual std::string run(const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute) = 0; // get run command + virtual std::string halt() = 0; // get stop command + virtual std::string name() = 0; // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_LAM : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_LAM(); // constructor + virtual ~MpiImpl_LAM(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_MPICH1 : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_MPICH1(); // constructor + virtual ~MpiImpl_MPICH1(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_MPICH2 : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_MPICH2(); // constructor + virtual ~MpiImpl_MPICH2(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_OPENMPI : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_OPENMPI(); // constructor + virtual ~MpiImpl_OPENMPI(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_OMPI : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_OMPI(); // constructor + virtual ~MpiImpl_OMPI(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_SLURM : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_SLURM(); // constructor + virtual ~MpiImpl_SLURM(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +class BATCH_EXPORT MpiImpl_PRUN : public MpiImpl +{ +public: + // Constructeur et destructeur + MpiImpl_PRUN(); // constructor + virtual ~MpiImpl_PRUN(); //Destructor + + std::string size(); // get number of process of current job + std::string rank(); // get process number of current job + std::string boot( const std::string machinefile, const unsigned int nbnodes); // get boot command + std::string run( const std::string machinefile, const unsigned int nbproc, const std::string fileNameToExecute); // get run command + std::string halt(); // get stop command + std::string name(); // name of mpi implementation + +protected: + +private: + +}; + +#endif diff --git a/src/Core/NotYetImplementedException.cxx b/src/Core/NotYetImplementedException.cxx new file mode 100644 index 0000000..a4e38c9 --- /dev/null +++ b/src/Core/NotYetImplementedException.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2012 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 +// +/* + * NotYetImplementedException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Nov 25 11:35:07 2003 + * Projet : Salome 2 + * + */ + +#include "NotYetImplementedException.hxx" + +namespace Batch { + +} + diff --git a/src/Core/NotYetImplementedException.hxx b/src/Core/NotYetImplementedException.hxx new file mode 100644 index 0000000..42001da --- /dev/null +++ b/src/Core/NotYetImplementedException.hxx @@ -0,0 +1,52 @@ +// Copyright (C) 2007-2012 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 +// +/* + * NotYetImplementedException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Nov 25 11:35:07 2003 + * Projet : Salome 2 + * + */ + +#ifndef _NOTYETIMPLEMENTEDEXCEPTION_H_ +#define _NOTYETIMPLEMENTEDEXCEPTION_H_ + +#include "Defines.hxx" +#include "GenericException.hxx" + +#include + +namespace Batch { + + class BATCH_EXPORT NotYetImplementedException : public GenericException + { + public: + // Constructeur + NotYetImplementedException(std::string ch = "undefined") : GenericException("NotYetImplementedException", ch) {} + }; + +} + +#endif + diff --git a/src/Core/ParameterTypeMap.cxx b/src/Core/ParameterTypeMap.cxx new file mode 100644 index 0000000..0e5973d --- /dev/null +++ b/src/Core/ParameterTypeMap.cxx @@ -0,0 +1,100 @@ +// Copyright (C) 2007-2012 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 +// +/* + * ParameterTypeMap.cxx : + * + * Auteur : Renaud Barate - EDF R&D + * Date : Mars 2011 + * + */ + +#include +#include + +#include "Constants.hxx" +#include "InvalidKeyException.hxx" +#include "ParameterTypeMap.hxx" + +using namespace std; + +namespace Batch { + + /*! + * The values of this type map contain the type of the parameters and the maximum + * number of items in the corresponding Versatile object (0 means any number). + */ + ParameterTypeMap::ParameterTypeMap() + { + // Don't use the string constants in this constructor because they might be uninitialized + addParameter("ARGUMENTS", STRING, 0); + addParameter("EXECUTABLE", STRING, 1); + addParameter("ID", STRING, 1); + addParameter("INFILE", COUPLE, 0); + addParameter("MAXCPUTIME", LONG, 1); + addParameter("MAXDISKSIZE", LONG, 1); + addParameter("MAXRAMSIZE", LONG, 1); + addParameter("MAXWALLTIME", LONG, 1); + addParameter("NAME", STRING, 1); + addParameter("NBPROC", LONG, 1); + addParameter("NBPROCPERNODE", LONG, 1); + addParameter("OUTFILE", COUPLE, 0); + addParameter("QUEUE", STRING, 1); + addParameter("STATE", STRING, 1); + addParameter("WORKDIR", STRING, 1); + addParameter("EXCLUSIVE", BOOL, 1); + } + + ParameterTypeMap::~ParameterTypeMap() + { + } + + /*! + * Returns the ParameterTypeMap singleton. + * We use the construct-on-first-use idiom here because otherwise there could be a problem with + * the initialization order between the factory singletons and this type map. Note that since the + * destructors do not depend on the other objects, the order is not important for destruction. + */ + ParameterTypeMap& ParameterTypeMap::getInstance () { + static ParameterTypeMap instance; + return instance; + } + + bool ParameterTypeMap::hasKey(const string & key) const + { + return (_map.find(key) != _map.end()); + } + + void ParameterTypeMap::addParameter(const std::string & key, DiscriminatorType type, int maxelem) + { + if (hasKey(key)) throw InvalidKeyException(key + " is already present in type map"); + _map[key].type = type; + _map[key].maxelem = maxelem; + } + + Versatile ParameterTypeMap::createVersatile(const std::string & parameterName) + { + map::const_iterator it = _map.find(parameterName); + if (it == _map.end()) throw InvalidKeyException(parameterName); + return Versatile(it->second.type, it->second.maxelem, parameterName); + } + +} diff --git a/src/Core/ParameterTypeMap.hxx b/src/Core/ParameterTypeMap.hxx new file mode 100644 index 0000000..5854741 --- /dev/null +++ b/src/Core/ParameterTypeMap.hxx @@ -0,0 +1,77 @@ +// Copyright (C) 2007-2012 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 +// +/* + * ParameterTypeMap.hxx : + * + * Auteur : Renaud Barate - EDF R&D + * Date : Mars 2011 + * + */ + +#ifndef _PARAMETERTYPEMAP_H_ +#define _PARAMETERTYPEMAP_H_ + +#include "Defines.hxx" +#include "Versatile.hxx" + +#include +#include + +namespace Batch { + + typedef struct { + DiscriminatorType type; + int maxelem; + } ParameterType; + + + /*! + * This class is used to control the type of the values associated with a parameter. + * It's a singleton that can be get only through the static method getInstance(). + */ + class BATCH_EXPORT ParameterTypeMap + { + public: + static ParameterTypeMap& getInstance(); + + bool hasKey(const std::string & key) const; + void addParameter(const std::string & key, DiscriminatorType type, int maxelem); + Versatile createVersatile(const std::string & parameterName); + + protected: + + ParameterTypeMap(); + virtual ~ParameterTypeMap(); + + std::map _map; + + private: + + // Forbid the use of copy constructor and assignment operator + ParameterTypeMap(const ParameterTypeMap & orig) {} + void operator=(const ParameterTypeMap & orig) {} + + }; + +} + +#endif diff --git a/src/Core/Parametre.cxx b/src/Core/Parametre.cxx new file mode 100644 index 0000000..5336981 --- /dev/null +++ b/src/Core/Parametre.cxx @@ -0,0 +1,104 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Parametre.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include "Versatile.hxx" +#include "InvalidKeyException.hxx" +#include "ParameterTypeMap.hxx" +#include "Parametre.hxx" + +using namespace std; + +namespace Batch { + + // Constructeur standard + Parametre::Parametre() : map< string, Versatile >() + { + } + + // Operateur de recherche dans la map + // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de + // la valeur associée à la clef car il retourne une reference non constante + Versatile & Parametre::operator [] (const string & mk) + { + // On controle que la clef est valide + if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk); + + Parametre::iterator it = find(mk); + if (it != end()) { + return it->second; + } else { + Versatile V = ParameterTypeMap::getInstance().createVersatile(mk); + pair result = insert(make_pair(mk, V)); + return result.first->second; + } + } + + // Operateur de recherche dans la map + // Cet operateur agit sur les objets CONSTANTS + const Versatile & Parametre::operator [] (const string & mk) const + { + // On controle que la clef est valide + if (!ParameterTypeMap::getInstance().hasKey(mk)) throw InvalidKeyException(mk); + + // On recherche la valeur associee + Parametre::const_iterator it = find(mk); + if (it == end()) throw InvalidKeyException(mk); + const Versatile & V = (*it).second; + + return V; + } + + // Operateur d'affectation + Parametre & Parametre::operator =(const Parametre & PM) + { + // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie + if (this == &PM) return *this; + + // On efface toute la map + erase(begin(), end()); + + // On recree la structure interne de la map avec les valeurs de celle passee en argument + Parametre::const_iterator it; + for(it=PM.begin(); it!=PM.end(); it++) + insert(make_pair((*it).first, Versatile((*it).second))); + + return *this; + } + + // Constructeur par recopie + Parametre::Parametre(const Parametre & PM) : map< string, Versatile >() + { + // On cree la structure interne de la map avec les valeurs de celle passee en argument + Parametre::const_iterator it; + for(it=PM.begin(); it!=PM.end(); it++) + insert(make_pair((*it).first, Versatile((*it).second))); + } + +} diff --git a/src/Core/Parametre.hxx b/src/Core/Parametre.hxx new file mode 100644 index 0000000..574d366 --- /dev/null +++ b/src/Core/Parametre.hxx @@ -0,0 +1,62 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Parametre.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _PARAMETRE_H_ +#define _PARAMETRE_H_ + +#include +#include + +#include "Defines.hxx" +#include "Versatile.hxx" + +namespace Batch { + + class BATCH_EXPORT Parametre : public std::map< std::string, Versatile > + { + public: + // Constructeur standard + Parametre(); + + // Constructeur par recopie + Parametre(const Parametre & PM); + + // Operateur de recherche dans la map + Versatile & operator [] (const std::string &); + const Versatile & operator [] (const std::string &) const; + + // Operateur d'affectation + Parametre & operator =(const Parametre & PM); + + }; + +} + +#endif diff --git a/src/Core/RunTimeException.cxx b/src/Core/RunTimeException.cxx new file mode 100644 index 0000000..22100e4 --- /dev/null +++ b/src/Core/RunTimeException.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2007-2012 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 +// +/* + * RunTimeException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Nov 25 14:04:13 2003 + * Projet : Salome 2 + * + */ + +#include "RunTimeException.hxx" +using namespace std; + +namespace Batch { + +} diff --git a/src/Core/RunTimeException.hxx b/src/Core/RunTimeException.hxx new file mode 100644 index 0000000..c792517 --- /dev/null +++ b/src/Core/RunTimeException.hxx @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2012 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 +// +/* + * RunTimeException.hxx : + * + * Auteur : %author% - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Tue Nov 25 14:04:13 2003 + * Projet : Salome 2 + * + */ + +#ifndef _RUNTIMEEXCEPTION_H_ +#define _RUNTIMEEXCEPTION_H_ + +#include "Defines.hxx" + + +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT RunTimeException : public GenericException + { + public: + // Constructeur + RunTimeException(std::string ch = "undefined") : GenericException("RunTimeException", ch) {} + }; + +} + +#endif diff --git a/src/Core/StringType.cxx b/src/Core/StringType.cxx new file mode 100644 index 0000000..e762037 --- /dev/null +++ b/src/Core/StringType.cxx @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2012 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 +// +/* + * StringType.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include +#include +#include "StringType.hxx" +using namespace std; + +namespace Batch { + + // Conversion en chaine + string StringType::affiche() const + { + return _data; + } + + // Operateur d'affectation + StringType & StringType::operator =(string s) + { + _data = s; + return *this; + } + + // Conversion en chaine + StringType::operator string() const + { + return this->_data; + } + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + GenericType * StringType::clone() const + { + StringType * pS = new StringType(this->_data); + assert(pS != 0); + return pS; + } + +} diff --git a/src/Core/StringType.hxx b/src/Core/StringType.hxx new file mode 100644 index 0000000..4e75778 --- /dev/null +++ b/src/Core/StringType.hxx @@ -0,0 +1,67 @@ +// Copyright (C) 2007-2012 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 +// +/* + * StringType.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _STRINGTYPE_H_ +#define _STRINGTYPE_H_ + +#include "Defines.hxx" + +#include +#include "GenericType.hxx" + +namespace Batch { + + class BATCH_EXPORT StringType : public GenericType + { + public: + // Constructeur + StringType(const std::string & s="") : _data(s) {} + + // Conversion en chaine + virtual std::string affiche() const; + virtual operator std::string() const; + + // Operateur d'affectation + virtual StringType & operator =(std::string); + + // Clone duplique l'objet et en fabrique un nouveau a l'aide de new + // qu'il faudra detruire ensuite manuellement + virtual GenericType * clone() const; + + protected: + std::string _data; + + private: + + }; + +} + +#endif diff --git a/src/Core/Test/CMakeLists.txt b/src/Core/Test/CMakeLists.txt index a2e81cc..b2244cb 100644 --- a/src/Core/Test/CMakeLists.txt +++ b/src/Core/Test/CMakeLists.txt @@ -29,13 +29,18 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_config.h.in ${CMAKE_CURRENT_BINA # Set the include directories include_directories(${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR}/src/Core) # Build SimpleParser library add_library (SimpleParser STATIC SimpleParser.cxx) -# Build the test program +# Build the test program for SimpleParser add_executable(Test_SimpleParser Test_SimpleParser.cxx) target_link_libraries(Test_SimpleParser SimpleParser) # Add the test itself ADD_TEST(SimpleParser Test_SimpleParser) + +# Build the test program for the batch managers +add_executable(Test_BatchManager Test_BatchManager.cxx) +target_link_libraries(Test_BatchManager batch SimpleParser) diff --git a/src/Core/Test/SimpleParser.cxx b/src/Core/Test/SimpleParser.cxx index f20eb27..e40a56b 100644 --- a/src/Core/Test/SimpleParser.cxx +++ b/src/Core/Test/SimpleParser.cxx @@ -128,6 +128,21 @@ const string & SimpleParser::getValue(const string & key) const throw(ParserExce return iter->second; } +const string & SimpleParser::getTestValue(const string & bmType, const string & protocolStr, + const string & key) const throw(ParserException) +{ + string fullkey = string("TEST_") + bmType + "_" + protocolStr + "_" + key; + try { + return getValue(fullkey); + } catch (const ParserException &) {} + fullkey = string("TEST_") + bmType + "_" + key; + try { + return getValue(fullkey); + } catch (const ParserException &) {} + fullkey = string("TEST_") + key; + return getValue(fullkey); +} + int SimpleParser::getValueAsInt(const string & key) const throw(ParserException) { const string & valueStr = getValue(key); @@ -140,6 +155,21 @@ int SimpleParser::getValueAsInt(const string & key) const throw(ParserException) return res; } +int SimpleParser::getTestValueAsInt(const string & bmType, const string & protocolStr, + const string & key) const throw(ParserException) +{ + string fullkey = string("TEST_") + bmType + "_" + protocolStr + "_" + key; + try { + return getValueAsInt(fullkey); + } catch (const ParserException &) {} + fullkey = string("TEST_") + bmType + "_" + key; + try { + return getValueAsInt(fullkey); + } catch (const ParserException &) {} + fullkey = string("TEST_") + key; + return getValueAsInt(fullkey); +} + ostream & operator <<(ostream & os, const SimpleParser & parser) throw() { if (parser._configmap.empty()) { diff --git a/src/Core/Test/SimpleParser.hxx b/src/Core/Test/SimpleParser.hxx index cccee1f..43e8ec8 100644 --- a/src/Core/Test/SimpleParser.hxx +++ b/src/Core/Test/SimpleParser.hxx @@ -54,7 +54,11 @@ public: void parse(const std::string & filename) throw(ParserException); void parseTestConfigFile() throw(ParserException); const std::string & getValue(const std::string & key) const throw(ParserException); + const std::string & getTestValue(const std::string & bmType, const std::string & protocolStr, + const std::string & key) const throw(ParserException); int getValueAsInt(const std::string & key) const throw(ParserException); + int getTestValueAsInt(const std::string & bmType, const std::string & protocolStr, + const std::string & key) const throw(ParserException); friend std::ostream & operator <<(std::ostream & os, const SimpleParser & parser) throw(); diff --git a/src/Core/Test/Test_BatchManager.cxx b/src/Core/Test/Test_BatchManager.cxx new file mode 100644 index 0000000..e1940cb --- /dev/null +++ b/src/Core/Test/Test_BatchManager.cxx @@ -0,0 +1,176 @@ +// Copyright (C) 2007-2012 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_BatchManager.cxx : + * + * Author : Renaud BARATE - EDF R&D + * Date : Jan 2013 + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "SimpleParser.hxx" + +#include + +using namespace std; +using namespace Batch; + +void print_usage() +{ + cout << "usage: Test_BatchManager BATCH_MANAGER PROTOCOL" << endl; + cout << " BATCH_MANAGER \"CCC\", \"LL\", \"LOCAL\", \"LSF\", \"PBS\", " << + "\"SGE\", \"SLURM\" or \"VISHNU\"" << endl; + cout << " PROTOCOL \"SH\", \"SSH\" or \"RSH\"" << endl; +} + +int main(int argc, char** argv) +{ + // Parse argument + if (argc != 3) { + print_usage(); + return 1; + } + const char * bmType = argv[1]; + const char * protocolStr = argv[2]; + CommunicationProtocolType protocol; + if (strcmp(protocolStr, "SSH") == 0) + protocol = SSH; + else if (strcmp(protocolStr, "RSH") == 0) + protocol = RSH; + else if (strcmp(protocolStr, "SH") == 0) + protocol = SH; + else { + print_usage(); + return 1; + } + + cout << "*******************************************************************************************" << endl; + cout << "This program tests the batch submission of a job using the batch manager \"" << bmType << "\"" << endl; + cout << "and the communication protocol \"" << protocolStr << "\"." << endl; + if (protocol == RSH || protocol == SSH) { + cout << "Passwordless authentication must be used for this test to pass." << endl; + if (protocol == SSH) { + cout << "This can be configured with ssh-agent for instance." << endl; + } else if (protocol == RSH) { + cout << "This can be configured with the .rhosts file." << endl; + } + } + cout << "*******************************************************************************************" << endl; + + // eventually remove any previous result + remove("resultdir/seconddirname/result.txt"); + + try { + // Get the catalog and the BatchManager factory + BatchManagerCatalog& cata = BatchManagerCatalog::getInstance(); + FactBatchManager * fbm = cata(bmType); + + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & workdir = parser.getTestValue(bmType, protocolStr, "WORKDIR"); + const string & host = parser.getTestValue(bmType, protocolStr, "HOST"); + const string & user = parser.getTestValue(bmType, protocolStr, "USER"); + int timeout = parser.getTestValueAsInt(bmType, protocolStr, "TIMEOUT"); + + // Define the job... + Job job; + // ... and its parameters ... + Parametre p; + p[EXECUTABLE] = string(CMAKE_CURRENT_SOURCE_DIR) + "/test_script.py"; + p[ARGUMENTS] = "copied_seta.py"; + p[ARGUMENTS] += "copied_setb.py"; + p[ARGUMENTS] += "orig_result.txt"; + p[NAME] = string("Test ") + bmType + " " + argv[2]; + p[WORKDIR] = workdir; + p[INFILE] = Couple(string(CMAKE_CURRENT_SOURCE_DIR) + "/seta.py", "copied_seta.py"); + p[INFILE] += Couple(string(CMAKE_CURRENT_SOURCE_DIR) + "/setb.py", "copied_setb.py"); + p[OUTFILE] = Couple("result.txt", "orig_result.txt"); + p[NBPROC] = 1; + p[MAXWALLTIME] = 1; + p[MAXRAMSIZE] = 50; + job.setParametre(p); + // ... and its environment + Environnement e; + e["MYENVVAR"] = "MYVALUE"; + job.setEnvironnement(e); + cout << job << endl; + + // Create the BatchManager + BatchManager * bm = (*fbm)(host.c_str(), user.c_str(), protocol); + + // Submit the job to the BatchManager + JobId jobid = bm->submitJob(job); + cout << jobid.__repr__() << endl; + + // Wait for the end of the job + string state = bm->waitForJobEnd(jobid, timeout); + + if (state == FINISHED) { + cout << "Job " << jobid.__repr__() << " is done" << endl; + bm->importOutputFiles(job, "resultdir/seconddirname"); + } else if (state == FAILED) { + cerr << "Job " << jobid.__repr__() << " finished in error" << endl; + bm->importOutputFiles(job, "resultdir/seconddirname"); + return 1; + } else { + cerr << "Timeout while executing job" << endl; + return 1; + } + + } catch (const GenericException & e) { + cerr << "Error: " << e << endl; + return 1; + } catch (const ParserException & e) { + cerr << "Parser error: " << e.what() << endl; + return 1; + } + + // test the result file + try { + SimpleParser resultParser; + resultParser.parse("resultdir/seconddirname/result.txt"); + cout << "Result:" << endl << resultParser; + const string & envvar = resultParser.getValue("MYENVVAR"); + int result = resultParser.getValueAsInt("c"); + if (envvar == "MYVALUE" && result == 12) { + cout << "OK, Expected result found." << endl; + return 0; + } else { + cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; + return 1; + } + } catch (const ParserException & e) { + cerr << "Parser error on result file: " << e.what() << endl; + return 1; + } +} diff --git a/src/Core/Test/Test_config.h.in b/src/Core/Test/Test_config.h.in index 8e5ab00..a116412 100644 --- a/src/Core/Test/Test_config.h.in +++ b/src/Core/Test/Test_config.h.in @@ -20,4 +20,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +/* Environment variable containing the path of the test configuration file */ #define TEST_CONFIG_FILE_ENV_VAR "${TEST_CONFIG_FILE_ENV_VAR}" + +/* Current source directory */ +#define CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf index 2d30ca9..f8cdcf3 100644 --- a/src/Core/Test/batchtest.conf +++ b/src/Core/Test/batchtest.conf @@ -5,46 +5,27 @@ # Note that BATCH_TEST_CONFIG_FILE is the default name for this environment variable. It can be # changed at compilation time by setting CMake option TEST_CONFIG_FILE_ENV_VAR. +TEST_LOCAL_SH_HOST = "localhost" # Not used +TEST_LOCAL_SH_USER = "me" # Not used TEST_LOCAL_SH_WORK_DIR = "/tmp" # Work directory for local SH Batch test TEST_LOCAL_SH_TIMEOUT = 2 # Execution timeout (in seconds) for local SH Batch test -TEST_LOCAL_SH_FINALIZATION_TIME = 2 # Finalization time (in seconds) for local SH Batch test -TEST_LOCAL_RSH_EXECUTION_HOST = "localhost" # Execution host for RSH Batch test -TEST_LOCAL_RSH_USER = "username" # User name on the execution host for RSH Batch test -TEST_LOCAL_RSH_WORK_DIR = "/tmp" # Work directory for RSH Batch test -TEST_LOCAL_RSH_TIMEOUT = 10 # Execution timeout (in seconds) for local RSH Batch test -TEST_LOCAL_RSH_FINALIZATION_TIME = 5 # Finalization time (in seconds) for local RSH Batch test - -TEST_LOCAL_SSH_EXECUTION_HOST = "localhost" # Execution host for SSH Batch test -TEST_LOCAL_SSH_USER = "username" # User name on the execution host for SSH Batch test -TEST_LOCAL_SSH_WORK_DIR = "/tmp" # Work directory for SSH Batch test -TEST_LOCAL_SSH_TIMEOUT = 10 # Execution timeout (in seconds) for local SSH Batch test -TEST_LOCAL_SSH_FINALIZATION_TIME = 5 # Finalization time (in seconds) for local SSH Batch test - -TEST_PBS_HOST = "localhost" # PBS server host -TEST_PBS_USER = "username" # Login for the PBS server -TEST_PBS_QUEUE = "queuename" # Queue to submit test job on PBS server -TEST_PBS_TIMEOUT = 120 # Execution timeout (in seconds) for PBS Batch test - -TEST_EPBS_HOST = "localhost" # PBS server host -TEST_EPBS_USER = "username" # Login for the PBS server -TEST_EPBS_HOMEDIR = "/home/username" # Home directory on PBS server -TEST_EPBS_QUEUE = "queuename" # Queue to submit test job on PBS server -TEST_EPBS_TIMEOUT = 120 # Execution timeout (in seconds) for PBS Batch test - -TEST_ELL_HOST = "localhost" # LoadLeveler server host -TEST_ELL_USER = "username" # Login for the LoadLeveler server -TEST_ELL_HOMEDIR = "/home/username" # Home directory on LoadLeveler server -TEST_ELL_QUEUE = "classname" # Class for the test job test job on LoadLeveler server -TEST_ELL_JOBTYPE = "serial" # Job type for LoadLeveler -TEST_ELL_TIMEOUT = 120 # Execution timeout (in seconds) for LoadLeveler Batch test - -TEST_ESLURM_HOST = "localhost" # Slurm server host -TEST_ESLURM_USER = "username" # Login for the Slurm server -TEST_ESLURM_HOMEDIR = "/home/username" # Home directory on Slurm server -TEST_ESLURM_TIMEOUT = 120 # Execution timeout (in seconds) for Slurm Batch test - -TEST_EVISHNU_HOST = "localhost" # Machine ID of the target cluster -TEST_EVISHNU_USER = "username" # Vishnu login (unused) -TEST_EVISHNU_HOMEDIR = "/home/username" # Home directory on the target cluster -TEST_EVISHNU_TIMEOUT = 120 # Execution timeout (in seconds) for Vishnu Batch test +TEST_LOCAL_HOST = "localhost" # Execution host for LOCAL Batch test +TEST_LOCAL_USER = "username" # User name on the execution host for LOCAL Batch test +TEST_LOCAL_WORKDIR = "/tmp" # Work directory for LOCAL Batch test +TEST_LOCAL_TIMEOUT = 10 # Execution timeout (in seconds) for LOCAL Batch test + +TEST_LSF_HOST = "localhost" # LSF server host +TEST_LSF_USER = "username" # Login for the LSF server +TEST_LSF_WORKDIR = "/home/username/wrk" # Work directory on LSF server +TEST_LSF_TIMEOUT = 120 # Execution timeout (in seconds) for LSF Batch test + +TEST_SLURM_HOST = "localhost" # Slurm server host +TEST_SLURM_USER = "username" # Login for the Slurm server +TEST_SLURM_WORKDIR = "/home/username/wrk" # Work directory on Slurm server +TEST_SLURM_TIMEOUT = 120 # Execution timeout (in seconds) for Slurm Batch test + +TEST_VISHNU_HOST = "localhost" # Machine ID of the target cluster +TEST_VISHNU_USER = "username" # Vishnu login (unused) +TEST_VISHNU_WORKDIR = "/home/username/wrk" # Work directory on the target cluster +TEST_VISHNU_TIMEOUT = 120 # Execution timeout (in seconds) for Vishnu Batch test diff --git a/src/Core/Test/seta.py b/src/Core/Test/seta.py new file mode 100644 index 0000000..da718ba --- /dev/null +++ b/src/Core/Test/seta.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +a=4 diff --git a/src/Core/Test/setb.py b/src/Core/Test/setb.py new file mode 100644 index 0000000..070121a --- /dev/null +++ b/src/Core/Test/setb.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +b=3 diff --git a/src/Core/Test/test_script.py b/src/Core/Test/test_script.py new file mode 100755 index 0000000..f4073ce --- /dev/null +++ b/src/Core/Test/test_script.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import sys +import os + +if len(sys.argv) != 4: + print "Usage: test-script.py seta.py setb.py result.txt" + +execfile(sys.argv[1]) +execfile(sys.argv[2]) + +c = a * b + +f = open(sys.argv[3], "w") +f.write('MYENVVAR = "%s"\n' % os.getenv("MYENVVAR")) +f.write("c = %d\n" % c) diff --git a/src/Core/TypeMismatchException.cxx b/src/Core/TypeMismatchException.cxx new file mode 100644 index 0000000..904fbc5 --- /dev/null +++ b/src/Core/TypeMismatchException.cxx @@ -0,0 +1,36 @@ +// Copyright (C) 2007-2012 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 +// +/* + * TypeMismatchException.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#include "TypeMismatchException.hxx" +using namespace std; + +namespace Batch { + +} diff --git a/src/Core/TypeMismatchException.hxx b/src/Core/TypeMismatchException.hxx new file mode 100644 index 0000000..de84fdb --- /dev/null +++ b/src/Core/TypeMismatchException.hxx @@ -0,0 +1,51 @@ +// Copyright (C) 2007-2012 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 +// +/* + * TypeMismatchException.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Date : Septembre 2003 + * Projet : SALOME 2 + * + */ + +#ifndef _TYPEMISMATCHEXCEPTION_H_ +#define _TYPEMISMATCHEXCEPTION_H_ + +#include "Defines.hxx" + + +#include "GenericException.hxx" + +namespace Batch { + + class BATCH_EXPORT TypeMismatchException : public GenericException + { + public: + // Constructeur + TypeMismatchException(std::string ch = "undefined") : GenericException("TypeMismatchException", ch) {} + }; + +} + +#endif + diff --git a/src/Core/Utils.cxx b/src/Core/Utils.cxx new file mode 100644 index 0000000..623bb60 --- /dev/null +++ b/src/Core/Utils.cxx @@ -0,0 +1,170 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Utils.cxx + * + * Created on: 30 jan. 2012 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include +#include +#include + +#ifdef WIN32 +#include +#include +#include +#else +#include +#include +#endif + +#include +#include "Utils.hxx" +#include "RunTimeException.hxx" + +#ifdef MSVC +#define popen _popen +#define pclose _pclose +#endif + +using namespace std; +namespace Batch { + +int Utils::getCommandOutput(const string & command, string & output) +{ + // Reinitialize output + output = ""; + + // Call command + FILE * fp = popen(command.c_str(), "r"); + if (fp == NULL) { + return -1; + } + + // Read the output and store it + char buf[1024]; + while (fgets(buf, sizeof(buf), fp) != NULL) { + output += buf; + } + + // close and get status + int status = pclose(fp); + return status; +} + +bool Utils::isAbsolutePath(const string & path) +{ + if (path.size() == 0) + return false; +#ifdef WIN32 + // On Windows, absolute paths may begin with something like "C:" + if (path[1] == ':') + return true; +#endif + return path[0] == '/'; +} + +string Utils::createAndOpenTemporaryFile(const string & prefix, ofstream & outputStream) +{ + if (outputStream.is_open()) + outputStream.close(); + + // Find directory for temporary files + const char * tmpDirName = getenv("TEMP"); + if (tmpDirName == NULL) tmpDirName = getenv("TMP"); + if (tmpDirName == NULL) tmpDirName = getenv("TEMPDIR"); + if (tmpDirName == NULL) tmpDirName = getenv("TMPDIR"); + if (tmpDirName == NULL) tmpDirName = "/tmp"; + + string fileName = (string)tmpDirName + "/libbatch-" + prefix + "-XXXXXX"; + +#ifdef WIN32 + + char randstr[7]; + srand(time(NULL)); + + do { + sprintf(randstr, "%06d", rand() % 1000000); + fileName.replace(fileName.size()-6, 6, randstr); + } while (_access_s(fileName.c_str(), 0) == 0); + + // Open the file as binary to avoid problems with Windows newlines + outputStream.open(fileName.c_str(), ios_base::binary | ios_base::out); + +#else + + char * buf = new char[fileName.size()+1]; + fileName.copy(buf, fileName.size()); + buf[fileName.size()] = '\0'; + + int fd = mkstemp(buf); + 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 + +#endif + + if (outputStream.fail()) + throw RunTimeException(string("Can't open temporary file ") + fileName); + + return fileName; +} + +int Utils::chmod(const char *path, int mode) +{ +#ifdef WIN32 + return _chmod(path, mode); +#else + return ::chmod(path, mode); +#endif +} + +void Utils::sleep(unsigned int seconds) +{ +#ifdef WIN32 + Sleep((seconds)*1000); +#else + ::sleep(seconds); +#endif +} + +string Utils::fixPath(const string & path) +{ + string fixedPath = path; +#ifdef WIN32 + for (unsigned int i=0 ; i + +namespace Batch { + +class Utils { +public: + + /** + * Call a command with the system shell and stores its output in parameter "output". + * Returns the return code of the command. + */ + static int getCommandOutput(const std::string & command, std::string & output); + + /** + * Test if the path in parameter is an absolute path (does not test the existence of + * a file or directory at this path). + */ + static bool isAbsolutePath(const std::string & path); + + /** + * Create a temporary file and open an output stream to write into this file. + * The file is created with the pattern "/libbatch--XXXXXX" where is the + * directory for temporary files and the X's are replaced by random characters. The caller is + * responsible for closing and deleting the file when it is no more used. + * is found by looking for environment variables TEMP, TMP, TEMPDIR, TMPDIR, and defaults + * to "/tmp" if none of them is defined. + * \param prefix the prefix to use for the temporary file. + * \param outputStream an output stream that will be opened for writing in the temporary file. If + * the stream is already open, it will be closed first. + * \return the name of the created file. + */ + static std::string createAndOpenTemporaryFile(const std::string & prefix, + std::ofstream & outputStream); + + /** + * Change permissions of a file + */ + static int chmod(const char *path, int mode); + + /** + * Sleep for the number of specified seconds + */ + static void sleep(unsigned int seconds); + + /** + * 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. + */ + static std::string fixPath(const std::string & path); + +private: + + // No instanciation possible as this class provides only static methods + Utils() { } + +}; + +} + +#endif /* BATCH_UTILS_HXX_ */ diff --git a/src/Core/Versatile.cxx b/src/Core/Versatile.cxx new file mode 100644 index 0000000..06bfbad --- /dev/null +++ b/src/Core/Versatile.cxx @@ -0,0 +1,271 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Versatile.cxx : + * + * Author : Ivan DUTKA-MALEN - EDF R&D + * Date : September 2003 + * + */ + +#include +#include +#include +#include + +#include "GenericType.hxx" +#include "BoolType.hxx" +#include "LongType.hxx" +#include "StringType.hxx" +#include "Versatile.hxx" +#include "TypeMismatchException.hxx" +#include "ListIsFullException.hxx" + +using namespace std; + +namespace Batch { + + Versatile::Versatile(DiscriminatorType discriminator, size_type maxsize, std::string name) + : _discriminator(discriminator), + _maxsize(maxsize), + _name(name) + { + } + + Versatile::Versatile(const Versatile & V) + : _discriminator(V._discriminator), + _maxsize(V._maxsize), + _name(V._name) + { + Versatile::const_iterator it; + for(it=V.begin(); it!=V.end(); it++) + push_back( (*it)->clone() ); + } + + Versatile::~Versatile() + { + eraseAll(); + } + + Versatile & Versatile::operator = (const long l) throw(TypeMismatchException) + { + checkType(LONG); + eraseAll(); + push_back(new LongType(l)); + return *this; + } + + Versatile & Versatile::operator = (const string & ch) throw(TypeMismatchException) + { + checkType(STRING); + eraseAll(); + push_back(new StringType(ch)); + return *this; + } + + Versatile & Versatile::operator +=(const string & ch) throw(TypeMismatchException,ListIsFullException) + { + checkType(STRING); + + // If max size is reached, throw a ListIsFullException + if (_maxsize == 0 || size() < _maxsize) + push_back(new StringType(ch)); + else { + ostringstream msg; + msg << "Maximum size for \"" << _name << "\" is reached: " << _maxsize; + throw(ListIsFullException(msg.str())); + } + return *this; + } + + Versatile & Versatile::operator , (const string & ch) throw(TypeMismatchException,ListIsFullException) + { + *this += ch; + return *this; + } + + Versatile & Versatile::operator = (const char * ch) throw(TypeMismatchException) + { + return operator=(string(ch)); + } + + Versatile & Versatile::operator +=(const char * ch) throw(TypeMismatchException,ListIsFullException) + { + return operator+=(string(ch)); + } + + Versatile & Versatile::operator , (const char * ch) throw(TypeMismatchException,ListIsFullException) + { + return operator,(string(ch)); + } + + Versatile & Versatile::operator = (const Couple & cp) throw(TypeMismatchException) + { + checkType(COUPLE); + eraseAll(); + push_back(new CoupleType(cp)); + return *this; + } + + Versatile & Versatile::operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException) + { + checkType(COUPLE); + // If max size is reached, throw a ListIsFullException + if (_maxsize == 0 || size() < _maxsize) + push_back(new CoupleType(cp)); + else { + ostringstream msg; + msg << "Maximum size for \"" << _name << "\" is reached: " << _maxsize; + throw(ListIsFullException(msg.str())); + } + return *this; + } + + Versatile & Versatile::operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException) + { + *this += cp; + return *this; + } + + ostream & operator << (ostream & os, const Versatile & V) + { + Versatile::const_iterator it; + const char * sep = ""; + + for(it=V.begin(); it!=V.end(); it++, sep=" ") { + string s = (*it)->affiche(); + os << sep << s; + } + return os; + } + + Versatile & Versatile::operator = (const int i) throw(TypeMismatchException) + { + checkType(LONG); + eraseAll(); + push_back(new LongType((long)i)); + return *this; + } + + Versatile & Versatile::operator = (const bool b) throw(TypeMismatchException) + { + checkType(BOOL); + eraseAll(); + push_back(new BoolType(b)); + return *this; + } + + void Versatile::checkType(DiscriminatorType t) const throw(TypeMismatchException) + { + if (_discriminator != t) + throw (TypeMismatchException("Trying to change type of Versatile object \"" + _name + "\"")); + } + + Versatile::operator long() const throw(TypeMismatchException) + { + // If the type does not correspond or if the list has more than one element, + // throw a TypeMismatchException + if ( _maxsize != 1 || _discriminator != LONG || size() == 0 ) { + ostringstream sst; + sst << "Cannot cast Versatile object \"" << _name << "\" to long"; + throw (TypeMismatchException(sst.str())); + } + return *( static_cast(this->front()) ); + } + + Versatile::operator bool() const throw(TypeMismatchException) + { + // If the type does not correspond or if the list has more than one element, + // throw a TypeMismatchException + if ( _maxsize != 1 || _discriminator != BOOL || size() == 0 ) { + ostringstream sst; + sst << "Cannot cast Versatile object \"" << _name << "\" to bool"; + throw(TypeMismatchException(sst.str())); + } + return *( static_cast(this->front()) ); + } + + Versatile::operator int() const throw(TypeMismatchException) + { + return operator long(); + } + + Versatile::operator Couple() const throw(TypeMismatchException) + { + // If the type does not correspond or if the list has more than one element, + // throw a TypeMismatchException + if ( _maxsize != 1 || _discriminator != COUPLE || size() == 0 ) { + ostringstream sst; + sst << "Cannot cast Versatile object \"" << _name << "\" to Couple"; + throw(TypeMismatchException(sst.str())); + } + return *( static_cast(this->front()) ); + } + + string Versatile::str() const throw(TypeMismatchException) + { + // If the type does not correspond, throw a TypeMismatchException + if ( _discriminator != STRING || size() == 0 ) { + ostringstream sst; + sst << "Cannot cast Versatile object \"" << _name << "\" to string"; + throw(TypeMismatchException(sst.str())); + } + + // The returned string is the concatenation of internal strings + string s; + Versatile::const_iterator it; + const char * sep = ""; + for(it=begin(); it!=end(); it++, s+=sep, sep=" ") + s += *( static_cast(*it)); + + return s; + } + + Versatile::operator string () const throw(TypeMismatchException) + { + return str(); + } + + void Versatile::eraseAll() + { + while(!empty()) { + delete back(); + pop_back(); + } + } + + DiscriminatorType Versatile::getType() const + { + return _discriminator; + } + + Versatile::size_type Versatile::getMaxSize() const + { + return _maxsize; + } + + const string & Versatile::getName() const + { + return _name; + } + +} diff --git a/src/Core/Versatile.hxx b/src/Core/Versatile.hxx new file mode 100644 index 0000000..b1e7462 --- /dev/null +++ b/src/Core/Versatile.hxx @@ -0,0 +1,118 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Versatile.hxx : + * + * Author : Ivan DUTKA-MALEN - EDF R&D + * Date : September 2003 + * + */ + +#ifndef _VERSATILE_H_ +#define _VERSATILE_H_ + +#include "Defines.hxx" + +#include +#include +#include +#include "GenericType.hxx" +#include "BoolType.hxx" +#include "LongType.hxx" +#include "StringType.hxx" +#include "CoupleType.hxx" +#include "TypeMismatchException.hxx" +#include "ListIsFullException.hxx" +#include "RunTimeException.hxx" + +namespace Batch { + + // Authorized types + enum DiscriminatorType { BOOL, LONG, STRING, COUPLE }; + + class BATCH_EXPORT Versatile : public std::list< GenericType * > + { + public: + + // Constructors + Versatile(DiscriminatorType discriminator, size_type maxsize, std::string name); + Versatile(const Versatile & V); + + // Use of default constructor is forbidden but we cannot declare it private because + // compilation fails with VC8 on Windows + Versatile() { throw RunTimeException("Forbidden constructor"); } + + // Destructor + virtual ~Versatile(); + + // Affectation and concatenation operators from base types + Versatile & operator = (const long l) throw(TypeMismatchException); + Versatile & operator = (const std::string & ch) throw(TypeMismatchException); + Versatile & operator +=(const std::string & ch) throw(TypeMismatchException,ListIsFullException); + Versatile & operator , (const std::string & ch) throw(TypeMismatchException,ListIsFullException); + Versatile & operator = (const char * ch) throw(TypeMismatchException); + Versatile & operator +=(const char * ch) throw(TypeMismatchException,ListIsFullException); + Versatile & operator , (const char * ch) throw(TypeMismatchException,ListIsFullException); + Versatile & operator = (const Couple & cp) throw(TypeMismatchException); + Versatile & operator +=(const Couple & cp) throw(TypeMismatchException,ListIsFullException); + Versatile & operator , (const Couple & cp) throw(TypeMismatchException,ListIsFullException); + Versatile & operator = (const int i) throw(TypeMismatchException); + Versatile & operator = (const bool b) throw(TypeMismatchException); + + // Type conversion to base types + operator long() const throw(TypeMismatchException); + operator std::string() const throw(TypeMismatchException); + operator Couple() const throw(TypeMismatchException); + std::string str() const throw(TypeMismatchException); + operator bool() const throw(TypeMismatchException); + operator int() const throw(TypeMismatchException); + + // Display on a stream + BATCH_EXPORT friend std::ostream & operator << (std::ostream & os, const Versatile & ); + + // Check the type + void checkType(DiscriminatorType t) const throw (TypeMismatchException); + + // Getter methods + DiscriminatorType getType() const; + size_type getMaxSize() const; + const std::string & getName() const; + + // Erase all internal elements + void eraseAll(); + + protected: + + DiscriminatorType _discriminator; // Internal element type + size_type _maxsize; // Maximum number of internal elements + std::string _name; // Object name (used for exceptions) + + private: + + // Forbid the use of affectation operator + void operator= (const Versatile & V) {} + + }; + +} + +#endif diff --git a/src/LSF/BatchManager_LSF.cxx b/src/LSF/BatchManager_LSF.cxx new file mode 100644 index 0000000..a1b0daf --- /dev/null +++ b/src/LSF/BatchManager_LSF.cxx @@ -0,0 +1,299 @@ +// Copyright (C) 2007-2012 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_LSF.cxx : emulation of LSF client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include +#include + +#include +#include +#include +#include "BatchManager_LSF.hxx" +#include "JobInfo_LSF.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + // Destructeur + BatchManager_LSF::~BatchManager_LSF() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_LSF::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const std::string workDir = params[WORKDIR]; + + // export input files on cluster + LOG("Export des fichiers en entree"); + exportInputFiles(job); + + // build batch script for job + LOG("Construction du script de batch"); + string scriptFile = buildSubmissionScript(job); + LOG("Script envoye"); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; bsub < " + scriptFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // read id of submitted job in output + int p10 = output.find("<"); + int p20 = output.find(">"); + string strjob = output.substr(p10+1,p20-p10-1); + + JobId id(this, strjob); + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_LSF::deleteJob(const JobId & jobid) + { + int status; + int ref; + istringstream iss(jobid.getReference()); + iss >> ref; + + // define command to delete batch + string subCommand = string("bkill ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + status = system(command.c_str()); + if (status) + throw RunTimeException("Error of connection on remote host"); + + LOG("jobId = " << ref << "killed"); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_LSF::queryJob(const JobId & jobid) + { + int id; + istringstream iss(jobid.getReference()); + iss >> id; + + // define command to query batch + string subCommand = string("bjobs ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + if (status) throw RunTimeException("Error of connection on remote host"); + + JobInfo_LSF ji = JobInfo_LSF(id, output); + return ji; + } + + + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_LSF::isRunning(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_LSF::isRunning"); + } + + std::string BatchManager_LSF::buildSubmissionScript(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + int nbproc = 0; + int edt = 0; + int mem = 0; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); + + // Optional parameters + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + if (params.find(MAXWALLTIME) != params.end()) + edt = params[MAXWALLTIME]; + if (params.find(MAXRAMSIZE) != params.end()) + mem = params[MAXRAMSIZE]; + if (params.find(QUEUE) != params.end()) + queue = params[QUEUE].str(); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + std::string TmpFileName = Utils::createAndOpenTemporaryFile("LSF-script", tempOutputFile); + + tempOutputFile << "#! /bin/sh -f" << endl ; + if (params.find(NAME) != params.end()) + tempOutputFile << "#BSUB -J " << params[NAME] << endl; + if (queue != "") + tempOutputFile << "#BSUB -q " << queue << endl; + if( edt > 0 ) + tempOutputFile << "#BSUB -W " << getWallTime(edt) << endl ; + if( mem > 0 ) + tempOutputFile << "#BSUB -M " << mem*1024 << endl ; + tempOutputFile << "#BSUB -n " << nbproc << endl ; + + if (params.find(EXCLUSIVE) != params.end() && params[EXCLUSIVE]) { + tempOutputFile << "#BSUB -x" << endl ; + } + + size_t pos = workDir.find("$HOME"); + string baseDir; + if( pos != string::npos ) + baseDir = getHomeDir(workDir) + workDir.substr(pos+5,workDir.length()-5); + else{ + pos = workDir.find("~"); + if( pos != string::npos ) + baseDir = getHomeDir(workDir) + workDir.substr(pos+1,workDir.length()-1); + else + baseDir = workDir; + } + tempOutputFile << "#BSUB -o " << baseDir << "/logs/output.log." << rootNameToExecute << endl ; + tempOutputFile << "#BSUB -e " << baseDir << "/logs/error.log." << rootNameToExecute << endl ; + + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "export " << iter->first << "=" << iter->second << endl; + } + + tempOutputFile << "cd " << workDir << endl ; + + // generate nodes file + tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl; + tempOutputFile << "bool=0" << endl; + tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl; + tempOutputFile << " if test $bool = 0; then" << endl; + tempOutputFile << " n=$i" << endl; + tempOutputFile << " bool=1" << endl; + tempOutputFile << " else" << endl; + tempOutputFile << " for ((j=0;j<$i;j++)); do" << endl; + tempOutputFile << " echo $n >> $LIBBATCH_NODEFILE" << endl; + tempOutputFile << " done" << endl; + tempOutputFile << " bool=0" << endl; + tempOutputFile << " fi" << endl; + tempOutputFile << "done" << endl; + tempOutputFile << "export LIBBATCH_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "./" + fileNameToExecute; + if (params.find(ARGUMENTS) != params.end()) { + Versatile V = params[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + tempOutputFile << " " << arg; + } + } + tempOutputFile << endl; + + // Remove the node file + tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << TmpFileName.c_str()); + + string remoteFileName = rootNameToExecute + "_Batch.sh"; + int status = _protocol.copyFile(TmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw RunTimeException("Error of connection on remote host"); + return remoteFileName; + } + + std::string BatchManager_LSF::getWallTime(const long edt) + { + long h, m; + h = edt / 60; + m = edt - h*60; + ostringstream oss; + if( m >= 10 ) + oss << h << ":" << m; + else + oss << h << ":0" << m; + return oss.str(); + } + + std::string BatchManager_LSF::getHomeDir(std::string tmpdir) + { + std::string home; + int idx = tmpdir.find("Batch/"); + std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length()); + filelogtemp = "/tmp/logs" + filelogtemp + "_home"; + + string subCommand = string("echo $HOME"); + string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp; + LOG(command); + int status = system(command.c_str()); + if (status) + throw RunTimeException("Error of launching home command on remote host"); + + std::ifstream file_home(filelogtemp.c_str()); + std::getline(file_home, home); + file_home.close(); + return home; + } + +} diff --git a/src/LSF/BatchManager_LSF.hxx b/src/LSF/BatchManager_LSF.hxx new file mode 100644 index 0000000..a794d91 --- /dev/null +++ b/src/LSF/BatchManager_LSF.hxx @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2012 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_LSF.hxx : emulation of LSF client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#ifndef _BATCHMANAGER_ELSF_H_ +#define _BATCHMANAGER_ELSF_H_ + +#include "Defines.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_LSF : public BatchManager + { + public: + // Constructeur et destructeur + BatchManager_LSF(const FactBatchManager * parent, const char * host="localhost", + const char * username="", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host + virtual ~BatchManager_LSF(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + protected: + std::string buildSubmissionScript(const Job & job); + std::string getWallTime(const long edt); + + private: + + std::string getHomeDir(std::string tmpdir); + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/LSF/Batch_BatchManager_LSF.cxx b/src/LSF/Batch_BatchManager_LSF.cxx deleted file mode 100644 index 19f9613..0000000 --- a/src/LSF/Batch_BatchManager_LSF.cxx +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright (C) 2007-2012 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_LSF.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 - * - */ - -extern "C" { -#include -#include -} -#include -#include -#include -#include -#include "Batch_BatchManager_LSF.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_LSF::BatchManager_LSF(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host) - { - // On se connecte au serveur LSF - _connect = lsb_init("Salome2 Batch library"); - if (_connect < 0) { // si erreur - char * errmsg = lsb_sysmsg(); - string msg = "LSF Server on host \""; - msg += _hostname; - msg += "\" : "; - msg += errmsg ? errmsg : "Reason unknown"; - throw ConnexionFailureException(msg.c_str()); - } - } - - // Destructeur - BatchManager_LSF::~BatchManager_LSF() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_LSF::submitJob(const Job & job) - { - Job_LSF joblsf = job; - struct submitReply reply; - int ref = lsb_submit(joblsf.getSubmitStruct(), - &reply); - if (ref < 0) { // si erreur - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("LSF submit error. Reason : ") + msg); - } - - ostringstream oss; - oss << ref; - JobId id(this, oss.str()); - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_LSF::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_LSF::deleteJob(const JobId & jobid) - { - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - int rc = lsb_deletejob(ref, 0, 0); - if (rc < 0) { // si erreur - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("LSF deljob error. Reason : ") + msg); - } - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_LSF::holdJob(const JobId & jobid) - { - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - int rc = lsb_signaljob(ref, SIGSTOP); - if (rc < 0) { // si erreur - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg); - } - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_LSF::releaseJob(const JobId & jobid) - { - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - int rc = lsb_signaljob(ref, SIGCONT); - if (rc < 0) { // si erreur - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("LSF signaljob error. Reason : ") + msg); - } - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - - Job_LSF joblsf = Job(param, env); - struct submitReply reply; - ref = lsb_modify(joblsf.getSubmitStruct(), - &reply, - ref); - if (ref < 0) { // si erreur - ostringstream msg_sst; - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - msg_sst << msg << endl; -// msg_sst << "BadJobId = " << (long) reply.badJobId << endl -// << "BadJobName = " << reply.badJobName << endl -// << "BadReqIndx = " << reply.badReqIndx << endl; - throw APIInternalFailureException(string("LSF modify error. Reason : ") + msg_sst.str()); - } - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_LSF::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_LSF::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_LSF::queryJob(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - JobInfo_LSF ji = JobInfo_LSF(id); - - return ji; - } - - - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_LSF::isRunning(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - JobInfo_LSF ji = JobInfo_LSF(id); - - return ji.isRunning(); - } - - - -} diff --git a/src/LSF/Batch_BatchManager_LSF.hxx b/src/LSF/Batch_BatchManager_LSF.hxx deleted file mode 100644 index d906b81..0000000 --- a/src/LSF/Batch_BatchManager_LSF.hxx +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2007-2012 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_LSF.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_LSF_H_ -#define _BATCHMANAGER_LSF_H_ - -#include "Batch_Defines.hxx" - -#include "Batch_Job.hxx" -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_LSF.hxx" -#include "Batch_Job_LSF.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_ConnexionFailureException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_NotYetImplementedException.hxx" -#include "Batch_BatchManager.hxx" - -namespace Batch { - - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - - class BATCH_EXPORT BatchManager_LSF : public BatchManager - { - public: - // Constructeur et destructeur - BatchManager_LSF(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - virtual ~BatchManager_LSF(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - int _connect; // LSF connect id - - private: - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/LSF/Batch_BatchManager_eLSF.cxx b/src/LSF/Batch_BatchManager_eLSF.cxx deleted file mode 100644 index 560b994..0000000 --- a/src/LSF/Batch_BatchManager_eLSF.cxx +++ /dev/null @@ -1,328 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.cxx : emulation of LSF client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include -#include - -#include -#include -#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 * username, - CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl) - - { - // Nothing to do - } - - // Destructeur - BatchManager_eLSF::~BatchManager_eLSF() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_eLSF::submitJob(const Job & job) - { - Parametre params = job.getParametre(); - const std::string workDir = params[WORKDIR]; - - // export input files on cluster - cerr << "Export des fichiers en entree" << endl; - exportInputFiles(job); - - // build batch script for job - cerr << "Construction du script de batch" << endl; - string scriptFile = buildSubmissionScript(job); - cerr << "Script envoye" << endl; - - // define command to submit batch - string subCommand = string("cd ") + workDir + "; bsub < " + scriptFile; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cerr << command.c_str() << endl; - - string output; - int status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) throw EmulationException("Can't submit job, error was: " + output); - - // read id of submitted job in output - int p10 = output.find("<"); - int p20 = output.find(">"); - string strjob = output.substr(p10+1,p20-p10-1); - - JobId id(this, strjob); - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_eLSF::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_eLSF::deleteJob(const JobId & jobid) - { - int status; - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - - // 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) - throw EmulationException("Error of connection on remote host"); - - cerr << "jobId = " << ref << "killed" << endl; - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_eLSF::holdJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_eLSF::releaseJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eLSF::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eLSF::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eLSF::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_eLSF::queryJob(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - // define command to query batch - string subCommand = string("bjobs ") + iss.str(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - string output; - int status = Utils::getCommandOutput(command, output); - if (status) throw EmulationException("Error of connection on remote host"); - - JobInfo_eLSF ji = JobInfo_eLSF(id, output); - return ji; - } - - - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_eLSF::isRunning(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - std::string BatchManager_eLSF::buildSubmissionScript(const Job & job) - { - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - int nbproc = 0; - int edt = 0; - int mem = 0; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); - - // Optional parameters - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - if (params.find(MAXWALLTIME) != params.end()) - edt = params[MAXWALLTIME]; - if (params.find(MAXRAMSIZE) != params.end()) - mem = params[MAXRAMSIZE]; - if (params.find(QUEUE) != params.end()) - queue = params[QUEUE].str(); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - std::string TmpFileName = createAndOpenTemporaryFile("LSF-script", tempOutputFile); - - tempOutputFile << "#! /bin/sh -f" << endl ; - if (params.find(NAME) != params.end()) - tempOutputFile << "#BSUB -J " << params[NAME] << endl; - if (queue != "") - tempOutputFile << "#BSUB -q " << queue << endl; - if( edt > 0 ) - tempOutputFile << "#BSUB -W " << getWallTime(edt) << endl ; - if( mem > 0 ) - tempOutputFile << "#BSUB -M " << mem*1024 << endl ; - tempOutputFile << "#BSUB -n " << nbproc << endl ; - - if (params.find(EXCLUSIVE) != params.end() && params[EXCLUSIVE]) { - tempOutputFile << "#BSUB -x" << endl ; - } - - size_t pos = workDir.find("$HOME"); - string baseDir; - if( pos != string::npos ) - baseDir = getHomeDir(workDir) + workDir.substr(pos+5,workDir.length()-5); - else{ - pos = workDir.find("~"); - if( pos != string::npos ) - baseDir = getHomeDir(workDir) + workDir.substr(pos+1,workDir.length()-1); - else - baseDir = workDir; - } - tempOutputFile << "#BSUB -o " << baseDir << "/logs/output.log." << rootNameToExecute << endl ; - tempOutputFile << "#BSUB -e " << baseDir << "/logs/error.log." << rootNameToExecute << endl ; - - // Define environment for the job - Environnement env = job.getEnvironnement(); - for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { - tempOutputFile << "export " << iter->first << "=" << iter->second << endl; - } - - tempOutputFile << "cd " << workDir << endl ; - - // generate nodes file - tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl; - tempOutputFile << "bool=0" << endl; - tempOutputFile << "for i in $LSB_MCPU_HOSTS; do" << endl; - tempOutputFile << " if test $bool = 0; then" << endl; - tempOutputFile << " n=$i" << endl; - tempOutputFile << " bool=1" << endl; - tempOutputFile << " else" << endl; - tempOutputFile << " for ((j=0;j<$i;j++)); do" << endl; - tempOutputFile << " echo $n >> $LIBBATCH_NODEFILE" << endl; - tempOutputFile << " done" << endl; - tempOutputFile << " bool=0" << endl; - tempOutputFile << " fi" << endl; - tempOutputFile << "done" << endl; - tempOutputFile << "export LIBBATCH_NODEFILE" << endl; - - // Launch the executable - tempOutputFile << "./" + fileNameToExecute << endl; - - // Remove the node file - tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; - - tempOutputFile.flush(); - tempOutputFile.close(); - - cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl; - - string remoteFileName = rootNameToExecute + "_Batch.sh"; - int status = _protocol.copyFile(TmpFileName, "", "", - workDir + "/" + remoteFileName, - _hostname, _username); - if (status) - throw EmulationException("Error of connection on remote host"); - return remoteFileName; - } - - std::string BatchManager_eLSF::getWallTime(const long edt) - { - long h, m; - h = edt / 60; - m = edt - h*60; - ostringstream oss; - if( m >= 10 ) - oss << h << ":" << m; - else - oss << h << ":0" << m; - return oss.str(); - } - - std::string BatchManager_eLSF::getHomeDir(std::string tmpdir) - { - std::string home; - int idx = tmpdir.find("Batch/"); - std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length()); - filelogtemp = "/tmp/logs" + filelogtemp + "_home"; - - string subCommand = string("echo $HOME"); - string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp; - cerr << command.c_str() << endl; - int status = system(command.c_str()); - if (status) - throw EmulationException("Error of launching home command on remote host"); - - std::ifstream file_home(filelogtemp.c_str()); - std::getline(file_home, home); - file_home.close(); - return home; - } - -} diff --git a/src/LSF/Batch_BatchManager_eLSF.hxx b/src/LSF/Batch_BatchManager_eLSF.hxx deleted file mode 100644 index 57fa621..0000000 --- a/src/LSF/Batch_BatchManager_eLSF.hxx +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.hxx : emulation of LSF client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#ifndef _BATCHMANAGER_ELSF_H_ -#define _BATCHMANAGER_ELSF_H_ - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_eLSF : public BatchManager_eClient - { - public: - // Constructeur et destructeur - BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host - virtual ~BatchManager_eLSF(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - std::string buildSubmissionScript(const Job & job); - std::string getWallTime(const long edt); - - private: - - std::string getHomeDir(std::string tmpdir); - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/LSF/Batch_FactBatchManager_LSF.cxx b/src/LSF/Batch_FactBatchManager_LSF.cxx deleted file mode 100644 index 93f5434..0000000 --- a/src/LSF/Batch_FactBatchManager_LSF.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2012 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_LSF.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include -#include "Batch_BatchManager_LSF.hxx" -#include "Batch_FactBatchManager_LSF.hxx" -//#include "utilities.h" - -namespace Batch { - - static FactBatchManager_LSF sFBM_LSF; - - // Constructeur - FactBatchManager_LSF::FactBatchManager_LSF() : FactBatchManager("LSF") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_LSF::~FactBatchManager_LSF() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_LSF::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'"); - return new BatchManager_LSF(this, hostname); - } - - -} diff --git a/src/LSF/Batch_FactBatchManager_LSF.hxx b/src/LSF/Batch_FactBatchManager_LSF.hxx deleted file mode 100644 index b6770ce..0000000 --- a/src/LSF/Batch_FactBatchManager_LSF.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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_LSF.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_LSF_H_ -#define _FACTBATCHMANAGER_LSF_H_ - -#include "Batch_FactBatchManager.hxx" - -namespace Batch { - - class BatchManager_LSF; - - class FactBatchManager_LSF : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_LSF(); - virtual ~FactBatchManager_LSF(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/LSF/Batch_FactBatchManager_eLSF.cxx b/src/LSF/Batch_FactBatchManager_eLSF.cxx deleted file mode 100644 index e5387bf..0000000 --- a/src/LSF/Batch_FactBatchManager_eLSF.cxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.cxx : - * - * Auteur : Bernard SECHER - CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#include "Batch_BatchManager_eLSF.hxx" -#include "Batch_FactBatchManager_eLSF.hxx" - -namespace Batch { - - static FactBatchManager_eLSF sFBM_eLSF; - - // Constructeur - FactBatchManager_eLSF::FactBatchManager_eLSF() : FactBatchManager_eClient("eLSF") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_eLSF::~FactBatchManager_eLSF() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_eLSF::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'"); - return new BatchManager_eLSF(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'"); - return new BatchManager_eLSF(this, hostname, username, protocolType, mpiImpl); - } - -} diff --git a/src/LSF/Batch_FactBatchManager_eLSF.hxx b/src/LSF/Batch_FactBatchManager_eLSF.hxx deleted file mode 100644 index 6668068..0000000 --- a/src/LSF/Batch_FactBatchManager_eLSF.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.hxx : - * - * Auteur : Bernard SECHER : CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#ifndef _FACTBATCHMANAGER_eLSF_H_ -#define _FACTBATCHMANAGER_eLSF_H_ - -#include "Batch_Defines.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT FactBatchManager_eLSF : public FactBatchManager_eClient - { - public: - // Constructeur et destructeur - FactBatchManager_eLSF(); - virtual ~FactBatchManager_eLSF(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/LSF/Batch_JobInfo_LSF.cxx b/src/LSF/Batch_JobInfo_LSF.cxx deleted file mode 100644 index 66b84cc..0000000 --- a/src/LSF/Batch_JobInfo_LSF.cxx +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_LSF.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 21 09:42:06 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_JobInfo_LSF.hxx" - -using namespace std; - -namespace Batch { - - - - // Constructeurs - JobInfo_LSF::JobInfo_LSF(int id) : JobInfo() - { - struct loadIndexLog * p_ld = new struct loadIndexLog; - struct jobInfoHead * p_jInfoHead = lsb_openjobinfo_a(id, NULL, NULL, NULL, NULL, ALL_JOB); - - int more = p_jInfoHead->numJobs; - if (more != 1) { - char * msg = lsb_sysmsg(); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("LSF lsb_openjobinfo error. Reason : ") + msg); - } - - // on remplit une structure contenant elements - struct jobInfoEnt & jobInfo = * lsb_readjobinfo(&more); - - - // On remplit les membres _param et _env - _param[ACCOUNT] = jobInfo.submit.projectName; - _param[CHECKPOINT] = jobInfo.submit.chkpntPeriod != 0; - _param[CKPTINTERVAL] = jobInfo.submit.chkpntPeriod; - _param[CREATIONTIME] = jobInfo.submitTime; - // _param[EGROUP] = jobInfo.; - _param[ELIGIBLETIME] = jobInfo.reserveTime; - _param[ENDTIME] = jobInfo.endTime; - _param[EUSER] = jobInfo.execUsername; - _param[EXECUTABLE] = jobInfo.submit.command; - _param[EXITCODE] = jobInfo.exitStatus; - _param[HOLD] = jobInfo.status & (JOB_STAT_PSUSP | JOB_STAT_SSUSP | JOB_STAT_USUSP); - _param[MAIL] = jobInfo.submit.mailUser; - _param[MAXCPUTIME] = jobInfo.submit.rLimits[LSF_RLIMIT_CPU]; - _param[MAXDISKSIZE] = jobInfo.submit.rLimits[LSF_RLIMIT_FSIZE]; - _param[MAXRAMSIZE] = jobInfo.submit.rLimits[LSF_RLIMIT_SWAP]; - _param[MAXWALLTIME] = jobInfo.submit.rLimits[LSF_RLIMIT_RUN]; - _param[MODIFICATIONTIME] = jobInfo.lastEvent; - _param[NAME] = jobInfo.jName; - _param[NBPROC] = jobInfo.submit.numProcessors; - _param[PID] = jobInfo.jobPid; - _param[QUEUE] = jobInfo.submit.queue; - _param[QUEUEDTIME] = jobInfo.submitTime; - // _param[SERVER] = jobInfo.; - _param[STARTTIME] = jobInfo.startTime; - _param[TEXT] = jobInfo.numReasons ? lsb_pendreason(jobInfo.numReasons, - jobInfo.reasonTb, - p_jInfoHead, - p_ld,0) : ""; - // _param[TMPDIR] = jobInfo.; - _param[USEDCPUTIME] = static_cast(jobInfo.cpuTime); - // _param[USEDDISKSIZE] = jobInfo.; - _param[USEDRAMSIZE] = jobInfo.runRusage.mem; - _param[USEDWALLTIME] = jobInfo.duration * 60L; - _param[USER] = jobInfo.user; - - - ostringstream oss; - int jobid = jobInfo.jobId; - oss << jobid; - _param[ID] = oss.str(); - - - string hosts, sep; - for(int i=0; i < jobInfo.numExHosts; i++, sep="+") { - hosts += jobInfo.exHosts[i]; - hosts += sep; - } - _param[EXECUTIONHOST] = hosts; - - ostringstream status; - - if (IS_PEND(jobInfo.status)) - status << " Job is pending;"; - if (IS_START(jobInfo.status)) - status << " Job is started;"; - if (IS_FINISH(jobInfo.status)) - status << " Job is finished;"; - if (IS_SUSP(jobInfo.status)) - status << " Job is suspended;"; - if (IS_POST_DONE(jobInfo.status)) - status << " Job is post-done;"; - if (IS_POST_ERR(jobInfo.status)) - status << " Job is post-error;"; - - // TODO: Use constants for STATE instead - _param[STATE] = status.str(); - _running = IS_FINISH(jobInfo.status) ? false : true; - - - if (strlen(jobInfo.submit.inFile)) - _param[INFILE] += Couple(jobInfo.submit.inFile, "stdin"); - if (strlen(jobInfo.submit.outFile)) - _param[OUTFILE] += Couple(jobInfo.submit.outFile, "stdout"); - if (strlen(jobInfo.submit.errFile)) - _param[OUTFILE] += Couple(jobInfo.submit.errFile, "stderr"); - - for(int i=0; i < jobInfo.submit.nxf; i++) { - switch (jobInfo.submit.xf[i].options) { - case XF_OP_SUB2EXEC: - _param[INFILE] += Couple(jobInfo.submit.xf[i].subFn, jobInfo.submit.xf[i].execFn); - break; - - case XF_OP_EXEC2SUB: - _param[OUTFILE] += Couple(jobInfo.submit.xf[i].subFn, jobInfo.submit.xf[i].execFn); - break; - - default: - break; - } - } - - - lsb_closejobinfo(); - delete p_ld; - } - - - - // Teste si un job est present en machine - bool JobInfo_LSF::isRunning() const - { - return _running; - } - - - // Destructeur - JobInfo_LSF::~JobInfo_LSF() - { - // Nothing to do - } - - - - // Convertit une date HH:MM:SS en secondes - long JobInfo_LSF::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_LSF::__str__() const - { - ostringstream sst; - sst << " -#include -} -#include -#include "Batch_RunTimeException.hxx" -#include "Batch_JobInfo.hxx" - -namespace Batch { - - class JobInfo_LSF : public JobInfo - { - public: - // Constructeurs et destructeur - JobInfo_LSF() : _running(false) {}; - JobInfo_LSF(int id); - virtual ~JobInfo_LSF(); - - // Constructeur par recopie - JobInfo_LSF(const JobInfo_LSF & jinfo) : JobInfo(jinfo) {}; - - // Teste si un job est present en machine - virtual bool isRunning() const; - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - bool _running; // etat du job en machine - - private: - // Convertit une date HH:MM:SS en secondes - long HMStoLong(const std::string &); - - }; - -} - -#endif diff --git a/src/LSF/Batch_JobInfo_eLSF.cxx b/src/LSF/Batch_JobInfo_eLSF.cxx deleted file mode 100644 index 3f7ddec..0000000 --- a/src/LSF/Batch_JobInfo_eLSF.cxx +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_eLSF.cxx : emulation of LSF client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include - -#include -#include "Batch_JobInfo_eLSF.hxx" - -using namespace std; - -namespace Batch { - - // Constructeurs - JobInfo_eLSF::JobInfo_eLSF(int id, const std::string & queryOutput) : JobInfo() - { - // Fill ID parameter - ostringstream oss; - oss << id; - _param[ID] = oss.str(); - - // read query output - string line; - istringstream fp(queryOutput); - getline(fp, line); - - // On some batch managers, the job is deleted soon after it is finished, - // so we have to consider that an unknown job (empty file) is a finished - // one, even if it is not always true. - if (fp.eof()) { - _param[STATE] = FINISHED; - } else { - string sjobid, username, status; - fp >> sjobid; - fp >> username; - fp >> status; - - if (status == "PEND") { // Pending - _param[STATE] = QUEUED; - } else if (status == "PSUSP") { // Suspended while pending - _param[STATE] = PAUSED; - } else if (status == "RUN") { // Running - _param[STATE] = RUNNING; - } else if (status == "USUSP") { // Suspended while running - _param[STATE] = PAUSED; - } else if (status == "SSUSP") { // Suspended by LSF - _param[STATE] = PAUSED; - } else if (status == "DONE") { // Finished successfully - _param[STATE] = FINISHED; - } else if (status == "EXIT") { // Finished in error - _param[STATE] = FAILED; - } else if (status == "UNKWN") { // Lost contact - _param[STATE] = FAILED; - } else if (status == "ZOMBI") { // Zombie - _param[STATE] = FAILED; - } else { - cerr << "Unknown job state code: " << status << endl; - } - - if( status.find("RUN") != string::npos) - _running = true; - } - } - - // Teste si un job est present en machine - bool JobInfo_eLSF::isRunning() const - { - return _running; - } - - - // Destructeur - JobInfo_eLSF::~JobInfo_eLSF() - { - // Nothing to do - } - - // Convertit une date HH:MM:SS en secondes - long JobInfo_eLSF::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_eLSF::__str__() const - { - ostringstream sst; - sst << " - -namespace Batch { - - class JobInfo_eLSF : public JobInfo - { - public: - // Constructeurs et destructeur - JobInfo_eLSF() : _running(false) {}; - JobInfo_eLSF(int id, const std::string & queryOutput); - virtual ~JobInfo_eLSF(); - - // Constructeur par recopie - JobInfo_eLSF(const JobInfo_eLSF & jinfo) : JobInfo(jinfo) {}; - - // Teste si un job est present en machine - virtual bool isRunning() const; - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - bool _running; // etat du job en machine - - private: - // Convertit une date HH:MM:SS en secondes - long HMStoLong(const std::string &); - - }; - -} - -#endif diff --git a/src/LSF/Batch_Job_LSF.cxx b/src/LSF/Batch_Job_LSF.cxx deleted file mode 100644 index 4a3cd9c..0000000 --- a/src/LSF/Batch_Job_LSF.cxx +++ /dev/null @@ -1,266 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job_LSF.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Job_LSF.hxx" - -using namespace std; - -namespace Batch { - - - // Constructeur - Job_LSF::Job_LSF(const Job & job) : _p_submit(0) - { - Parametre P = job.getParametre(); - _p_submit = ParametreToSubmitStruct(P); - } - - - // Destructeur - Job_LSF::~Job_LSF() - { - if (_p_submit) { - if (_p_submit->jobName) delete [] _p_submit->jobName; - if (_p_submit->queue) delete [] _p_submit->queue; - if (_p_submit->askedHosts) { - delete [] *(_p_submit->askedHosts); - delete [] _p_submit->askedHosts; - } - if (_p_submit->resReq) delete [] _p_submit->resReq; - if (_p_submit->hostSpec) delete [] _p_submit->hostSpec; - if (_p_submit->dependCond) delete [] _p_submit->dependCond; - if (_p_submit->timeEvent) delete [] _p_submit->timeEvent; - if (_p_submit->inFile) delete [] _p_submit->inFile; - if (_p_submit->outFile) delete [] _p_submit->outFile; - if (_p_submit->errFile) delete [] _p_submit->errFile; - if (_p_submit->command) delete [] _p_submit->command; - if (_p_submit->newCommand) delete [] _p_submit->newCommand; - if (_p_submit->chkpntDir) delete [] _p_submit->chkpntDir; - if (_p_submit->xf) delete [] _p_submit->xf; - if (_p_submit->preExecCmd) delete [] _p_submit->preExecCmd; - if (_p_submit->mailUser) delete [] _p_submit->mailUser; - if (_p_submit->projectName) delete [] _p_submit->projectName; - if (_p_submit->loginShell) delete [] _p_submit->loginShell; - if (_p_submit->exceptList) delete [] _p_submit->exceptList; - delete _p_submit; - } - } - - - // Accesseur - struct submit * Job_LSF::getSubmitStruct() - { - return _p_submit; - } - - - char * Job_LSF::string2char(const string & s) - { - char * ch = new char [s.size() + 1]; - memset(ch, 0, s.size() + 1); - strncat(ch, s.c_str(), s.size()); - return ch; - } - - - struct submit * Job_LSF::ParametreToSubmitStruct(const Parametre & P) - { - if (! _p_submit) _p_submit = new struct submit; - - memset( (void *) _p_submit, 0, sizeof(struct submit)); - - struct submit & sub = * _p_submit; - sub.options = 0; - sub.options2 = 0; - - sub.beginTime = 0; // job can run as soon as possible (default) - sub.termTime = 0; // job can run as long as it wishes (default) - - sub.numProcessors = 1; // job can run on one single processor (default) - sub.maxNumProcessors = 1; // job can run on one single processor (default) - - for(int i = 0; i< LSF_RLIM_NLIMITS; i++) sub.rLimits[i] = DEFAULT_RLIMIT; - - typedef std::vector< struct xFile > XFTAB; - XFTAB xf_tab; - - string st_second; - for(Parametre::const_iterator it = P.begin(); it != P.end(); it++) { - if ( (*it).first == ACCOUNT ) { - sub.options |= SUB_PROJECT_NAME; - st_second = (*it).second.str(); - sub.projectName = string2char(st_second); - - } else if ( (*it).first == CHECKPOINT ) { - if (static_cast< long >((*it).second)) - sub.options |= SUB_CHKPNT_PERIOD; - else - sub.options &= ~ SUB_CHKPNT_PERIOD; - - } else if ( (*it).first == CKPTINTERVAL ) { - sub.chkpntPeriod = static_cast< long >((*it).second); - - } else if ( (*it).first == EXECUTABLE ) { - st_second = (*it).second.str(); - sub.command = string2char(st_second); - - } else if ( (*it).first == EXECUTIONHOST ) { - sub.options |= SUB_HOST; - if (! sub.numAskedHosts) { - sub.numAskedHosts = 1; - sub.askedHosts = new char* [1]; - } - st_second = (*it).second.str(); - sub.askedHosts[0] = string2char(st_second); - - } else if ( (*it).first == HOLD ) { - if (static_cast< long >((*it).second)) - sub.options2 |= SUB2_HOLD; - else - sub.options2 &= ~ SUB2_HOLD; - - } else if ( (*it).first == INFILE ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur - if (remote == "stdin"){ - sub.options |= SUB_IN_FILE; - sub.inFile = string2char(local); - - } else { - struct xFile xf; - strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0; - strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0; - xf.options = XF_OP_SUB2EXEC; - xf_tab.push_back(xf); - } - } - - } else if ( (*it).first == MAIL ) { - sub.options |= SUB_MAIL_USER; - st_second = (*it).second.str(); - sub.mailUser = string2char(st_second); - - } else if ( (*it).first == MAXCPUTIME ) { - sub.rLimits[LSF_RLIMIT_CPU] = static_cast< long >((*it).second); - - } else if ( (*it).first == MAXDISKSIZE ) { - sub.rLimits[LSF_RLIMIT_FSIZE] = static_cast< long >((*it).second); - - } else if ( (*it).first == MAXRAMSIZE ) { - sub.rLimits[LSF_RLIMIT_SWAP] = static_cast< long >((*it).second); - - } else if ( (*it).first == MAXWALLTIME ) { - sub.rLimits[LSF_RLIMIT_RUN] = static_cast< long >((*it).second); - - } else if ( (*it).first == NAME ) { - sub.options |= SUB_JOB_NAME; - st_second = (*it).second.str(); - sub.jobName = string2char(st_second); - - } else if ( (*it).first == NBPROC ) { - sub.numProcessors = static_cast< long >((*it).second); - sub.maxNumProcessors = static_cast< long >((*it).second); - - } else if ( (*it).first == OUTFILE ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur - if (remote == "stdout"){ - sub.options |= SUB_OUT_FILE; - sub.outFile = string2char(local); - - } else if (remote == "stderr"){ - sub.options |= SUB_ERR_FILE; - sub.errFile = string2char(local); - - } else { - struct xFile xf; - strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0; - strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0; - xf.options = XF_OP_EXEC2SUB; - xf_tab.push_back(xf); - } - } - - - } else if ( (*it).first == QUEUE ) { - sub.options |= SUB_QUEUE; - st_second = (*it).second.str(); - sub.queue = string2char(st_second); - - } else if ( (*it).first == STARTTIME ) { - sub.beginTime = static_cast< long >((*it).second); - - } else if ( (*it).first == TMPDIR ) { - // TODO - - } else if ( (*it).first == USER ) { - // TODO - - } - } - - - // Transfert de fichiers en entree et sortie - sub.options |= SUB_OTHER_FILES; - sub.nxf = xf_tab.size(); - sub.xf = new struct xFile [sub.nxf]; - int ixf = 0; - for(XFTAB::const_iterator it_xf=xf_tab.begin(); it_xf != xf_tab.end(); it_xf++, ixf++) - sub.xf[ixf] = *it_xf; // *it_xf == xf_tab[ixf] - - - return _p_submit; - } - -} diff --git a/src/LSF/Batch_Job_LSF.hxx b/src/LSF/Batch_Job_LSF.hxx deleted file mode 100644 index ebaacdc..0000000 --- a/src/LSF/Batch_Job_LSF.hxx +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job_LSF.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#ifndef _JOB_LSF_H_ -#define _JOB_LSF_H_ - -extern "C" { - -#include -#include -} -#include -#include "Batch_Job.hxx" - -namespace Batch { - - class Job_LSF - { - public: - // Constructeur et destructeur - Job_LSF(const Job & job); - virtual ~Job_LSF(); - - // Accesseurs - struct submit * getSubmitStruct(); - - protected: - struct submit * _p_submit; // structure pour soumettre les jobs - - private: - struct submit * ParametreToSubmitStruct(const Parametre & P); - char * string2char(const std::string &); - }; - -} - -#endif diff --git a/src/LSF/CMakeLists.txt b/src/LSF/CMakeLists.txt index 53602e9..7268633 100644 --- a/src/LSF/CMakeLists.txt +++ b/src/LSF/CMakeLists.txt @@ -20,22 +20,13 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST LSF/Batch_BatchManager_eLSF - LSF/Batch_FactBatchManager_eLSF - LSF/Batch_JobInfo_eLSF +SET(CLASS_LIST LSF/BatchManager_LSF + LSF/FactBatchManager_LSF + LSF/JobInfo_LSF ) -IF (BUILD_LSF_INTERFACE AND LSF_FOUND) - SET(CLASS_LIST ${CLASS_LIST} - LSF/Batch_BatchManager_LSF - LSF/Batch_FactBatchManager_LSF - LSF/Batch_Job_LSF - LSF/Batch_JobInfo_LSF - ) -ENDIF (BUILD_LSF_INTERFACE AND LSF_FOUND) - APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) +IF (TEST_ENABLED AND HAS_SSH) + ADD_TEST(LSF_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LSF SSH) +ENDIF (TEST_ENABLED AND HAS_SSH) diff --git a/src/LSF/FactBatchManager_LSF.cxx b/src/LSF/FactBatchManager_LSF.cxx new file mode 100644 index 0000000..cb6990c --- /dev/null +++ b/src/LSF/FactBatchManager_LSF.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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_LSF.cxx : + * + * Auteur : Bernard SECHER - CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#include "BatchManager_LSF.hxx" +#include "FactBatchManager_LSF.hxx" + +namespace Batch { + + static FactBatchManager_LSF sFBM_LSF; + + // Constructeur + FactBatchManager_LSF::FactBatchManager_LSF() : FactBatchManager("LSF") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_LSF::~FactBatchManager_LSF() + { + // Nothing to do + } + + BatchManager * FactBatchManager_LSF::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'"); + return new BatchManager_LSF(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/LSF/FactBatchManager_LSF.hxx b/src/LSF/FactBatchManager_LSF.hxx new file mode 100644 index 0000000..fc191cb --- /dev/null +++ b/src/LSF/FactBatchManager_LSF.hxx @@ -0,0 +1,56 @@ +// Copyright (C) 2007-2012 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_LSF.hxx : + * + * Auteur : Bernard SECHER : CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#ifndef _FACTBATCHMANAGER_LSF_H_ +#define _FACTBATCHMANAGER_LSF_H_ + +#include "Defines.hxx" +#include "BatchManager.hxx" +#include "FactBatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT FactBatchManager_LSF : public FactBatchManager + { + public: + + FactBatchManager_LSF(); + virtual ~FactBatchManager_LSF(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + + }; + +} + +#endif diff --git a/src/LSF/JobInfo_LSF.cxx b/src/LSF/JobInfo_LSF.cxx new file mode 100644 index 0000000..2413b48 --- /dev/null +++ b/src/LSF/JobInfo_LSF.cxx @@ -0,0 +1,128 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_LSF.cxx : emulation of LSF client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include + +#include +#include "JobInfo_LSF.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + // Constructeurs + JobInfo_LSF::JobInfo_LSF(int id, const std::string & queryOutput) : JobInfo() + { + // Fill ID parameter + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + + // read query output + string line; + istringstream fp(queryOutput); + getline(fp, line); + + // On some batch managers, the job is deleted soon after it is finished, + // so we have to consider that an unknown job (empty file) is a finished + // one, even if it is not always true. + if (fp.eof()) { + _param[STATE] = FINISHED; + } else { + string sjobid, username, status; + fp >> sjobid; + fp >> username; + fp >> status; + + if (status == "PEND") { // Pending + _param[STATE] = QUEUED; + } else if (status == "PSUSP") { // Suspended while pending + _param[STATE] = PAUSED; + } else if (status == "RUN") { // Running + _param[STATE] = RUNNING; + } else if (status == "USUSP") { // Suspended while running + _param[STATE] = PAUSED; + } else if (status == "SSUSP") { // Suspended by LSF + _param[STATE] = PAUSED; + } else if (status == "DONE") { // Finished successfully + _param[STATE] = FINISHED; + } else if (status == "EXIT") { // Finished in error + _param[STATE] = FAILED; + } else if (status == "UNKWN") { // Lost contact + _param[STATE] = FAILED; + } else if (status == "ZOMBI") { // Zombie + _param[STATE] = FAILED; + } else { + LOG("Unknown job state code: " << status); + } + + if( status.find("RUN") != string::npos) + _running = true; + } + } + + // Teste si un job est present en machine + bool JobInfo_LSF::isRunning() const + { + return _running; + } + + + // Destructeur + JobInfo_LSF::~JobInfo_LSF() + { + // Nothing to do + } + + // Convertit une date HH:MM:SS en secondes + long JobInfo_LSF::HMStoLong(const string & s) + { + long hour, min, sec; + + sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); + return ( ( ( hour * 60L ) + min ) * 60L ) + sec; + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_LSF::__str__() const + { + ostringstream sst; + sst << " + +namespace Batch { + + class JobInfo_LSF : public JobInfo + { + public: + // Constructeurs et destructeur + JobInfo_LSF() : _running(false) {}; + JobInfo_LSF(int id, const std::string & queryOutput); + virtual ~JobInfo_LSF(); + + // Constructeur par recopie + JobInfo_LSF(const JobInfo_LSF & jinfo) : JobInfo(jinfo) {}; + + // Teste si un job est present en machine + virtual bool isRunning() const; + + // Methodes pour l'interfacage avec Python (SWIG) + // TODO : supprimer ces methodes et transferer leur definitions dans SWIG + std::string __str__() const; // SWIG : affichage en Python + std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python + + protected: + bool _running; // etat du job en machine + + private: + // Convertit une date HH:MM:SS en secondes + long HMStoLong(const std::string &); + + }; + +} + +#endif diff --git a/src/LSF/Test/CMakeLists.txt b/src/LSF/Test/CMakeLists.txt deleted file mode 100644 index de1db94..0000000 --- a/src/LSF/Test/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# 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-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) - -# set the include directories -include_directories(${CMAKE_SOURCE_DIR}/src/Core) -include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -# Build the test programs and add the tests -add_executable(Test_eLSF Test_eLSF.cxx) -target_link_libraries(Test_eLSF Batch SimpleParser) - -IF (HAS_SSH) - ADD_TEST(eLSF_SSH Test_eLSF SSH) -ENDIF (HAS_SSH) - -#IF (HAS_RSH) -# ADD_TEST(eLSF_RSH Test_eLSF RSH) -#ENDIF (HAS_RSH) diff --git a/src/LSF/Test/Test_eLSF.cxx b/src/LSF/Test/Test_eLSF.cxx deleted file mode 100644 index 420e1ad..0000000 --- a/src/LSF/Test/Test_eLSF.cxx +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2007-2012 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_eLSF.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : September 2011 - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -void print_usage() -{ - cout << "usage: Test_eLSF PROTOCOL" << endl; - cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; -} - -int main(int argc, char** argv) -{ - // Parse argument - if (argc != 2) { - print_usage(); - return 1; - } - CommunicationProtocolType protocol; - if (strcmp(argv[1], "SSH") == 0) - protocol = SSH; - else if (strcmp(argv[1], "RSH") == 0) - protocol = RSH; - else { - print_usage(); - return 1; - } - - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on LSF emulation. Passwordless" << endl; - cout << "authentication must be used for this test to pass. For SSH, this can be configured with" << endl; - cout << "ssh-agent for instance. For RSH, this can be configured with the .rhosts file." << 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_ELSF_HOMEDIR"); - const string & host = parser.getValue("TEST_ELSF_HOST"); - const string & user = parser.getValue("TEST_ELSF_USER"); - int timeout = parser.getValueAsInt("TEST_ELSF_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "./test-script.sh"; - p[NAME] = string("Test_eLSF_") + argv[1]; - 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[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 128; - p[HOMEDIR] = homedir; - p[EXCLUSIVE] = true; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - 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("eLSF")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - } else if (state == FAILED) { - cerr << "Job " << jobid.__repr__() << " finished in error" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - return 1; - } 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 - try { - SimpleParser resultParser; - resultParser.parse("resultdir/seconddirname/result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/LSF/Test/seta.sh b/src/LSF/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/LSF/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/LSF/Test/setb.sh b/src/LSF/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/LSF/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/LSF/Test/test-script.sh b/src/LSF/Test/test-script.sh deleted file mode 100755 index 1d56247..0000000 --- a/src/LSF/Test/test-script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -. ./seta.sh -. ./setb.sh - -c=`expr $a "*" $b` - -echo "MYENVVAR = $MYENVVAR" > result.txt -echo "c = $c" >> result.txt diff --git a/src/LoadLeveler/BatchManager_LL.cxx b/src/LoadLeveler/BatchManager_LL.cxx new file mode 100644 index 0000000..f62871e --- /dev/null +++ b/src/LoadLeveler/BatchManager_LL.cxx @@ -0,0 +1,244 @@ +// Copyright (C) 2007-2012 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_LL.cxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include +#include +#include + +#include +#include + +#include "FactBatchManager_LL.hxx" +#include "BatchManager_LL.hxx" +#include "JobInfo_LL.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_LL::BatchManager_LL(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + BatchManager_LL::~BatchManager_LL() + { + // Nothing to do + } + + // Method to submit a job to the batch manager + const JobId BatchManager_LL::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const string workDir = params[WORKDIR]; + + // export input files on cluster + exportInputFiles(job); + + // build command file to submit the job and copy it on the server + string cmdFile = buildCommandFile(job); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // find id of submitted job in output + string jobref; + istringstream idfile(output); + string line; + while (idfile && line.compare(0, 9, "llsubmit:") != 0) + getline(idfile, line); + if (line.compare(0, 9, "llsubmit:") == 0) + { + string::size_type p1 = line.find_first_of("\""); + string::size_type p2 = line.find_last_of("\""); + if (p1 != p2) + jobref = line.substr(p1 + 1, p2 - p1 - 1); + } + if (jobref.size() == 0) + throw RunTimeException("Error in the submission of the job on the remote host"); + + JobId id(this, jobref); + return id; + } + + /** + * Create LoadLeveler command file and copy it on the server. + * Return the name of the remote file. + */ + string BatchManager_LL::buildCommandFile(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + string tmpFileName = Utils::createAndOpenTemporaryFile("LL-script", tempOutputFile); + + tempOutputFile << "#!/bin/bash" << endl; + tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl; + + if (params.find(NAME) != params.end()) + tempOutputFile << "# @ job_name = " << params[NAME] << endl; + + // Optional parameters + int nbproc = 1; + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + int nbprocpernode = 1; + if (params.find(NBPROCPERNODE) != params.end()) + nbprocpernode = params[NBPROCPERNODE]; + + if (params.find(EXCLUSIVE) != params.end()) { + if (params[EXCLUSIVE]) + tempOutputFile << "# @ node_usage = not_shared" << endl; + else + tempOutputFile << "# @ node_usage = shared" << endl; + } + + // If job type is not specified, try to guess it from number of procs + string job_type; + if (params.find(LL_JOBTYPE) != params.end()) + job_type = params[LL_JOBTYPE].str(); + else if (nbproc == 1) + job_type = "serial"; + else + job_type = "mpich"; + + tempOutputFile << "# @ job_type = " << job_type << endl; + + if (job_type == "mpich") { + int nodes_requested = (nbproc + nbprocpernode -1) / nbprocpernode; + tempOutputFile << "# @ node = " << nodes_requested << endl; + tempOutputFile << "# @ total_tasks = " << nbproc << endl; + } + + if (params.find(MAXWALLTIME) != params.end()) + tempOutputFile << "# @ wall_clock_limit = " << params[MAXWALLTIME] << ":00" << endl; + if (params.find(MAXRAMSIZE) != params.end()) + tempOutputFile << "# @ as_limit = " << params[MAXRAMSIZE] << "mb" << endl; + if (params.find(QUEUE) != params.end()) + tempOutputFile << "# @ class = " << params[QUEUE] << endl; + + // Define environment for the job + Environnement env = job.getEnvironnement(); + if (!env.empty()) { + tempOutputFile << "# @ environment = "; + Environnement::const_iterator iter; + for (iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << iter->first << "=" << iter->second << "; "; + } + tempOutputFile << endl; + } + + tempOutputFile << "# @ queue" << endl; + + // generate nodes file + tempOutputFile << "export LIBBATCH_NODEFILE=$LOADL_HOSTFILE" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl; + tempOutputFile << "./" + fileNameToExecute << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << tmpFileName); + + string remoteFileName = rootNameToExecute + "_LL.cmd"; + int status = _protocol.copyFile(tmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw RunTimeException("Cannot copy command file on host " + _hostname); + + return remoteFileName; + } + + void BatchManager_LL::deleteJob(const JobId & jobid) + { + // define command to delete job + string subCommand = "llcancel " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + int status = system(command.c_str()); + if (status) + throw RunTimeException("Can't delete job " + jobid.getReference()); + + LOG("job " << jobid.getReference() << " killed"); + } + + JobInfo BatchManager_LL::queryJob(const JobId & jobid) + { + // define command to query batch + string subCommand = "llq -f %st " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + string output; + int status = Utils::getCommandOutput(command, output); + if (status != 0) + throw RunTimeException("Can't query job " + jobid.getReference()); + + JobInfo_LL jobinfo = JobInfo_LL(jobid.getReference(), output); + return jobinfo; + } + +} diff --git a/src/LoadLeveler/BatchManager_LL.hxx b/src/LoadLeveler/BatchManager_LL.hxx new file mode 100644 index 0000000..6bfd342 --- /dev/null +++ b/src/LoadLeveler/BatchManager_LL.hxx @@ -0,0 +1,62 @@ +// Copyright (C) 2007-2012 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_LL.hxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHMANAGER_ELL_H_ +#define _BATCHMANAGER_ELL_H_ + +#include + +#include "Defines.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_LL : public BatchManager + { + public: + BatchManager_LL(const FactBatchManager * parent, const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi"); + virtual ~BatchManager_LL(); + + // Methods to control jobs + virtual const JobId submitJob(const Job & job); + virtual void deleteJob(const JobId & jobid); + virtual JobInfo queryJob(const JobId & jobid); + + protected: + std::string buildCommandFile(const Job & job); + + }; + +} + +#endif diff --git a/src/LoadLeveler/Batch_BatchManager_eLL.cxx b/src/LoadLeveler/Batch_BatchManager_eLL.cxx deleted file mode 100644 index 91ba2ca..0000000 --- a/src/LoadLeveler/Batch_BatchManager_eLL.cxx +++ /dev/null @@ -1,288 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eLL.cxx : - * - * Created on: 25 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#include -#include -#include - -#include -#include - -#include "Batch_FactBatchManager_eLL.hxx" -#include "Batch_BatchManager_eLL.hxx" -#include "Batch_JobInfo_eLL.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_eLL::BatchManager_eLL(const FactBatchManager * parent, const char * host, - const char * username, - CommunicationProtocolType protocolType, const char * mpiImpl, - int nb_proc_per_node) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl), - _nb_proc_per_node(nb_proc_per_node) - { - // Nothing to do - } - - BatchManager_eLL::~BatchManager_eLL() - { - // Nothing to do - } - - // Method to submit a job to the batch manager - const JobId BatchManager_eLL::submitJob(const Job & job) - { - int status; - Parametre params = job.getParametre(); - const string workDir = params[WORKDIR]; - - // export input files on cluster - exportInputFiles(job); - - // build command file to submit the job and copy it on the server - string cmdFile = buildCommandFile(job); - - // define name of log file (local) - string logFile = generateTemporaryFileName("LL-submitlog"); - - // define command to submit batch - string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - cerr << command.c_str() << endl; - status = system(command.c_str()); - if (status) - { - ifstream error_message(logFile.c_str()); - string mess; - string temp; - while(getline(error_message, temp)) - mess += temp; - error_message.close(); - throw EmulationException("Error of connection on remote host, error was: " + mess); - } - - // read id of submitted job in log file - string jobref; - ifstream idfile(logFile.c_str()); - string line; - while (idfile && line.compare(0, 9, "llsubmit:") != 0) - getline(idfile, line); - idfile.close(); - if (line.compare(0, 9, "llsubmit:") == 0) - { - string::size_type p1 = line.find_first_of("\""); - string::size_type p2 = line.find_last_of("\""); - if (p1 != p2) - jobref = line.substr(p1 + 1, p2 - p1 - 1); - } - if (jobref.size() == 0) - throw EmulationException("Error in the submission of the job on the remote host"); - - JobId id(this, jobref); - return id; - } - - /** - * Create LoadLeveler command file and copy it on the server. - * Return the name of the remote file. - */ - string BatchManager_eLL::buildCommandFile(const Job & job) - { - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile); - - tempOutputFile << "#!/bin/bash" << endl; - tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl; - tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl; - - if (params.find(NAME) != params.end()) - tempOutputFile << "# @ job_name = " << params[NAME] << endl; - - // Optional parameters - int nbproc = 1; - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - - if (params.find(EXCLUSIVE) != params.end()) { - if (params[EXCLUSIVE]) - tempOutputFile << "# @ node_usage = not_shared" << endl; - else - tempOutputFile << "# @ node_usage = shared" << endl; - } - - // If job type is not specified, try to guess it from number of procs - string job_type; - if (params.find(LL_JOBTYPE) != params.end()) - job_type = params[LL_JOBTYPE].str(); - else if (nbproc == 1) - job_type = "serial"; - else - job_type = "mpich"; - - tempOutputFile << "# @ job_type = " << job_type << endl; - - if (job_type == "mpich") { - int nodes_requested = (nbproc + _nb_proc_per_node -1) / _nb_proc_per_node; - tempOutputFile << "# @ node = " << nodes_requested << endl; - tempOutputFile << "# @ total_tasks = " << nbproc << endl; - } - - if (params.find(MAXWALLTIME) != params.end()) - tempOutputFile << "# @ wall_clock_limit = " << params[MAXWALLTIME] << ":00" << endl; - if (params.find(MAXRAMSIZE) != params.end()) - tempOutputFile << "# @ as_limit = " << params[MAXRAMSIZE] << "mb" << endl; - if (params.find(QUEUE) != params.end()) - tempOutputFile << "# @ class = " << params[QUEUE] << endl; - - // Define environment for the job - Environnement env = job.getEnvironnement(); - if (!env.empty()) { - tempOutputFile << "# @ environment = "; - Environnement::const_iterator iter; - for (iter = env.begin() ; iter != env.end() ; ++iter) { - tempOutputFile << iter->first << "=" << iter->second << "; "; - } - tempOutputFile << endl; - } - - tempOutputFile << "# @ queue" << endl; - - // generate nodes file - tempOutputFile << "export LIBBATCH_NODEFILE=$LOADL_HOSTFILE" << endl; - - // Launch the executable - tempOutputFile << "cd " << workDir << endl; - tempOutputFile << "./" + fileNameToExecute << endl; - - tempOutputFile.flush(); - tempOutputFile.close(); - - cerr << "Batch script file generated is: " << tmpFileName << endl; - - string remoteFileName = rootNameToExecute + "_LL.cmd"; - int status = _protocol.copyFile(tmpFileName, "", "", - workDir + "/" + remoteFileName, - _hostname, _username); - if (status) - throw EmulationException("Cannot copy command file on host " + _hostname); - - return remoteFileName; - } - - void BatchManager_eLL::deleteJob(const JobId & jobid) - { - // define command to delete job - string subCommand = "llcancel " + jobid.getReference(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - int status = system(command.c_str()); - if (status) - throw EmulationException("Can't delete job " + jobid.getReference()); - - cerr << "job " << jobid.getReference() << " killed" << endl; - } - - void BatchManager_eLL::holdJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eLL::holdJob"); - } - - void BatchManager_eLL::releaseJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eLL::releaseJob"); - } - - void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eLL::alterJob"); - } - - void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param) - { - throw NotYetImplementedException("BatchManager_eLL::alterJob"); - } - - void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eLL::alterJob"); - } - - JobInfo BatchManager_eLL::queryJob(const JobId & jobid) - { - // define name of log file (local) - string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference()); - - // define command to query batch - string subCommand = "llq -f %st " + jobid.getReference(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - cerr << command.c_str() << endl; - int status = system(command.c_str()); - if (status != 0) - throw EmulationException("Can't query job " + jobid.getReference()); - - JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile); - return jobinfo; - } - - const JobId BatchManager_eLL::addJob(const Job & job, const string reference) - { - return JobId(this, reference); - } - -} diff --git a/src/LoadLeveler/Batch_BatchManager_eLL.hxx b/src/LoadLeveler/Batch_BatchManager_eLL.hxx deleted file mode 100644 index 6516c28..0000000 --- a/src/LoadLeveler/Batch_BatchManager_eLL.hxx +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eLL.hxx : - * - * Created on: 25 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _BATCHMANAGER_ELL_H_ -#define _BATCHMANAGER_ELL_H_ - -#include - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_eLL : public BatchManager_eClient - { - public: - BatchManager_eLL(const FactBatchManager * parent, const char * host = "localhost", - const char * username = "", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi", - int nb_proc_per_node=1); - virtual ~BatchManager_eLL(); - - // Methods to control jobs - virtual const JobId submitJob(const Job & job); - virtual void deleteJob(const JobId & jobid); - virtual void holdJob(const JobId & jobid); - virtual void releaseJob(const JobId & jobid); - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); - virtual void alterJob(const JobId & jobid, const Parametre & param); - virtual void alterJob(const JobId & jobid, const Environnement & env); - virtual JobInfo queryJob(const JobId & jobid); - virtual const JobId addJob(const Job & job, const std::string reference); - - protected: - std::string buildCommandFile(const Job & job); - - int _nb_proc_per_node; - - }; - -} - -#endif diff --git a/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx b/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx deleted file mode 100644 index c983f82..0000000 --- a/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eLL.cxx : - * - * Created on: 25 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#include "Batch_ParameterTypeMap.hxx" -#include "Batch_BatchManager_eLL.hxx" -#include "Batch_FactBatchManager_eLL.hxx" - -namespace Batch { - - def_Constant(LL_JOBTYPE); - - static FactBatchManager_eLL sFBM_eLL; - - FactBatchManager_eLL::FactBatchManager_eLL() : FactBatchManager_eClient("eLL") - { - // Add specific parameters - ParameterTypeMap::getInstance().addParameter(LL_JOBTYPE, STRING, 1); - } - - FactBatchManager_eLL::~FactBatchManager_eLL() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_eLL::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_eLL on host '" << hostname << "'"); - return new BatchManager_eLL(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eLL::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_eLL on host '" << hostname << "'"); - return new BatchManager_eLL(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); - } - -} diff --git a/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx b/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx deleted file mode 100644 index a37cb6e..0000000 --- a/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eLL.hxx : - * - * Created on: 25 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _FACTBATCHMANAGER_ELL_H_ -#define _FACTBATCHMANAGER_ELL_H_ - -#include -#include - -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - decl_extern_Constant(LL_JOBTYPE); - - class BatchManager_eLL; - - class BATCH_EXPORT FactBatchManager_eLL : public FactBatchManager_eClient - { - public: - // Constructeur et destructeur - FactBatchManager_eLL(); - virtual ~FactBatchManager_eLL(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - }; - -} - -#endif diff --git a/src/LoadLeveler/Batch_JobInfo_eLL.cxx b/src/LoadLeveler/Batch_JobInfo_eLL.cxx deleted file mode 100644 index 13ab39c..0000000 --- a/src/LoadLeveler/Batch_JobInfo_eLL.cxx +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eLL.cxx : - * - * Created on: 30 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#include -#include -#include - -#include -#include - -#include "Batch_JobInfo_eLL.hxx" - -using namespace std; - -namespace Batch { - - JobInfo_eLL::JobInfo_eLL(const std::string & id, const std::string & logFile) - : JobInfo() - { - _param[ID] = id; - - // read log file - ifstream log(logFile.c_str()); - string line; - - // status should be on the third line - for (int i=0 ; i<3 ; i++) - getline(log, line); - log.close(); - string status; - istringstream iss(line); - iss >> status; - - if (status.size() == 0) { - // On some batch managers, the job is deleted as soon as it is finished, - // so we have to consider that an unknown job is a finished one, even if - // it is not always true. - _param[STATE] = FINISHED; - } else if (status == "C") { // Completed - _param[STATE] = FINISHED; - } else if (status == "R") { // Running - _param[STATE] = RUNNING; - } else if (status == "I") { // Idle - _param[STATE] = QUEUED; - } else if (status == "CA") { // Canceled - _param[STATE] = FAILED; - } else if (status == "CK") { // Checkpointing - _param[STATE] = RUNNING; - } else if (status == "CP") { // Complete Pending - _param[STATE] = RUNNING; - } else if (status == "D") { // Deferred - _param[STATE] = QUEUED; - } else if (status == "NQ") { // Not Queued - _param[STATE] = QUEUED; - } else if (status == "NR") { // Not Run - _param[STATE] = FAILED; - } else if (status == "P") { // Pending - _param[STATE] = RUNNING; - } else if (status == "E") { // Preempted - _param[STATE] = RUNNING; - } else if (status == "EP") { // Preempt Pending - _param[STATE] = RUNNING; - } else if (status == "X") { // Rejected - _param[STATE] = FAILED; - } else if (status == "XP") { // Reject Pending - _param[STATE] = QUEUED; - } else if (status == "RM") { // Removed - _param[STATE] = FAILED; - } else if (status == "RP") { // Remove Pending - _param[STATE] = FAILED; - } else if (status == "MP") { // Resume Pending - _param[STATE] = RUNNING; - } else if (status == "ST") { // Starting - _param[STATE] = RUNNING; - } else if (status == "S") { // System Hold - _param[STATE] = PAUSED; - } else if (status == "TX") { // Terminated - _param[STATE] = FAILED; - } else if (status == "HS") { // User & System Hold - _param[STATE] = PAUSED; - } else if (status == "H") { // User Hold - _param[STATE] = PAUSED; - } else if (status == "V") { // Vacated - _param[STATE] = FAILED; - } else if (status == "VP") { // Vacate Pending - _param[STATE] = FAILED; - } else { - throw RunTimeException("Unknown job state code: \"" + status + "\""); - } - } - - JobInfo_eLL::~JobInfo_eLL() - { - // Nothing to do - } - -} diff --git a/src/LoadLeveler/Batch_JobInfo_eLL.hxx b/src/LoadLeveler/Batch_JobInfo_eLL.hxx deleted file mode 100644 index a4ec9f1..0000000 --- a/src/LoadLeveler/Batch_JobInfo_eLL.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eLL.hxx : - * - * Created on: 30 nov. 2010 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _JOBINFO_ELL_H_ -#define _JOBINFO_ELL_H_ - -#include - -#include - -namespace Batch { - - class JobInfo_eLL : public JobInfo - { - public: - JobInfo_eLL(const std::string & id, const std::string & logFile); - virtual ~JobInfo_eLL(); - - }; - -} - -#endif diff --git a/src/LoadLeveler/CMakeLists.txt b/src/LoadLeveler/CMakeLists.txt index aa8445f..a063420 100644 --- a/src/LoadLeveler/CMakeLists.txt +++ b/src/LoadLeveler/CMakeLists.txt @@ -20,13 +20,9 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST LoadLeveler/Batch_BatchManager_eLL - LoadLeveler/Batch_FactBatchManager_eLL - LoadLeveler/Batch_JobInfo_eLL +SET(CLASS_LIST LoadLeveler/BatchManager_LL + LoadLeveler/FactBatchManager_LL + LoadLeveler/JobInfo_LL ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) - -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) diff --git a/src/LoadLeveler/FactBatchManager_LL.cxx b/src/LoadLeveler/FactBatchManager_LL.cxx new file mode 100644 index 0000000..501118d --- /dev/null +++ b/src/LoadLeveler/FactBatchManager_LL.cxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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_LL.cxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include "ParameterTypeMap.hxx" +#include "BatchManager_LL.hxx" +#include "FactBatchManager_LL.hxx" + +namespace Batch { + + def_Constant(LL_JOBTYPE); + + static FactBatchManager_LL sFBM_LL; + + FactBatchManager_LL::FactBatchManager_LL() : FactBatchManager("LL") + { + // Add specific parameters + ParameterTypeMap::getInstance().addParameter(LL_JOBTYPE, STRING, 1); + } + + FactBatchManager_LL::~FactBatchManager_LL() + { + // Nothing to do + } + + BatchManager * FactBatchManager_LL::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + // MESSAGE("Building new BatchManager_LL on host '" << hostname << "'"); + return new BatchManager_LL(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/LoadLeveler/FactBatchManager_LL.hxx b/src/LoadLeveler/FactBatchManager_LL.hxx new file mode 100644 index 0000000..de5e242 --- /dev/null +++ b/src/LoadLeveler/FactBatchManager_LL.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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_LL.hxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _FACTBATCHMANAGER_ELL_H_ +#define _FACTBATCHMANAGER_ELL_H_ + +#include +#include + +#include "BatchManager.hxx" +#include "FactBatchManager.hxx" + +namespace Batch { + + decl_extern_Constant(LL_JOBTYPE); + + class BatchManager_LL; + + class BATCH_EXPORT FactBatchManager_LL : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_LL(); + virtual ~FactBatchManager_LL(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + }; + +} + +#endif diff --git a/src/LoadLeveler/JobInfo_LL.cxx b/src/LoadLeveler/JobInfo_LL.cxx new file mode 100644 index 0000000..188f6b8 --- /dev/null +++ b/src/LoadLeveler/JobInfo_LL.cxx @@ -0,0 +1,120 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_LL.cxx : + * + * Created on: 30 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include + +#include +#include + +#include "JobInfo_LL.hxx" + +using namespace std; + +namespace Batch { + + JobInfo_LL::JobInfo_LL(const std::string & id, const std::string & output) + : JobInfo() + { + _param[ID] = id; + + // read log file + istringstream log(output); + string line; + + // status should be on the third line + for (int i=0 ; i<3 ; i++) + getline(log, line); + string status; + istringstream iss(line); + iss >> status; + + if (status.size() == 0) { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } else if (status == "C") { // Completed + _param[STATE] = FINISHED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "I") { // Idle + _param[STATE] = QUEUED; + } else if (status == "CA") { // Canceled + _param[STATE] = FAILED; + } else if (status == "CK") { // Checkpointing + _param[STATE] = RUNNING; + } else if (status == "CP") { // Complete Pending + _param[STATE] = RUNNING; + } else if (status == "D") { // Deferred + _param[STATE] = QUEUED; + } else if (status == "NQ") { // Not Queued + _param[STATE] = QUEUED; + } else if (status == "NR") { // Not Run + _param[STATE] = FAILED; + } else if (status == "P") { // Pending + _param[STATE] = RUNNING; + } else if (status == "E") { // Preempted + _param[STATE] = RUNNING; + } else if (status == "EP") { // Preempt Pending + _param[STATE] = RUNNING; + } else if (status == "X") { // Rejected + _param[STATE] = FAILED; + } else if (status == "XP") { // Reject Pending + _param[STATE] = QUEUED; + } else if (status == "RM") { // Removed + _param[STATE] = FAILED; + } else if (status == "RP") { // Remove Pending + _param[STATE] = FAILED; + } else if (status == "MP") { // Resume Pending + _param[STATE] = RUNNING; + } else if (status == "ST") { // Starting + _param[STATE] = RUNNING; + } else if (status == "S") { // System Hold + _param[STATE] = PAUSED; + } else if (status == "TX") { // Terminated + _param[STATE] = FAILED; + } else if (status == "HS") { // User & System Hold + _param[STATE] = PAUSED; + } else if (status == "H") { // User Hold + _param[STATE] = PAUSED; + } else if (status == "V") { // Vacated + _param[STATE] = FAILED; + } else if (status == "VP") { // Vacate Pending + _param[STATE] = FAILED; + } else { + throw RunTimeException("Unknown job state code: \"" + status + "\""); + } + } + + JobInfo_LL::~JobInfo_LL() + { + // Nothing to do + } + +} diff --git a/src/LoadLeveler/JobInfo_LL.hxx b/src/LoadLeveler/JobInfo_LL.hxx new file mode 100644 index 0000000..770bc5c --- /dev/null +++ b/src/LoadLeveler/JobInfo_LL.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_LL.hxx : + * + * Created on: 30 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _JOBINFO_ELL_H_ +#define _JOBINFO_ELL_H_ + +#include + +#include + +namespace Batch { + + class JobInfo_LL : public JobInfo + { + public: + JobInfo_LL(const std::string & id, const std::string & output); + virtual ~JobInfo_LL(); + + }; + +} + +#endif diff --git a/src/LoadLeveler/Test/CMakeLists.txt b/src/LoadLeveler/Test/CMakeLists.txt deleted file mode 100644 index 293c8ff..0000000 --- a/src/LoadLeveler/Test/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# 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-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) - -# set the include directories -include_directories(${CMAKE_SOURCE_DIR}/src/Core) -include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -# Build the test programs and add the tests -add_executable(Test_eLL Test_eLL.cxx) -target_link_libraries(Test_eLL Batch SimpleParser) - -IF (HAS_SSH) - ADD_TEST(eLL_SSH Test_eLL SSH) -ENDIF (HAS_SSH) - -#IF (HAS_RSH) -# ADD_TEST(eLL_RSH Test_eLL RSH) -#ENDIF (HAS_RSH) diff --git a/src/LoadLeveler/Test/Test_eLL.cxx b/src/LoadLeveler/Test/Test_eLL.cxx deleted file mode 100644 index 62156d7..0000000 --- a/src/LoadLeveler/Test/Test_eLL.cxx +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (C) 2007-2012 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 -#include -#include - -#include - -using namespace std; -using namespace Batch; - -void print_usage() -{ - cout << "usage: Test_eLL PROTOCOL" << endl; - cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; -} - -int main(int argc, char** argv) -{ - // Parse argument - if (argc != 2) { - print_usage(); - return 1; - } - CommunicationProtocolType protocol; - if (strcmp(argv[1], "SSH") == 0) - protocol = SSH; - else if (strcmp(argv[1], "RSH") == 0) - protocol = RSH; - else { - print_usage(); - return 1; - } - - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on LoadLeveler emulation. Passwordless" << endl; - cout << "authentication must be used for this test to pass. For SSH, this can be configured with" << endl; - cout << "ssh-agent for instance. For RSH, this can be configured with the .rhosts file." << 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_ELL_HOMEDIR"); - const string & host = parser.getValue("TEST_ELL_HOST"); - const string & user = parser.getValue("TEST_ELL_USER"); - const string & queue = parser.getValue("TEST_ELL_QUEUE"); - const string & jobType = parser.getValue("TEST_ELL_JOBTYPE"); - int timeout = parser.getValueAsInt("TEST_ELL_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "./test-script.sh"; - p[NAME] = string("Test_eLL_") + argv[1]; - 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[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 50; - p[HOMEDIR] = homedir; - p[QUEUE] = queue; - p[LL_JOBTYPE] = jobType; - p[EXCLUSIVE] = false; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - 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("eLL")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - } else if (state == FAILED) { - cerr << "Job " << jobid.__repr__() << " finished in error" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - return 1; - } 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 - try { - SimpleParser resultParser; - resultParser.parse("resultdir/seconddirname/result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/LoadLeveler/Test/seta.sh b/src/LoadLeveler/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/LoadLeveler/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/LoadLeveler/Test/setb.sh b/src/LoadLeveler/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/LoadLeveler/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/LoadLeveler/Test/test-script.sh b/src/LoadLeveler/Test/test-script.sh deleted file mode 100755 index ae952c8..0000000 --- a/src/LoadLeveler/Test/test-script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -source seta.sh -source setb.sh - -c=`expr $a "*" $b` - -echo "MYENVVAR = $MYENVVAR" > result.txt -echo "c = $c" >> result.txt diff --git a/src/Local/BatchManager_Local.cxx b/src/Local/BatchManager_Local.cxx new file mode 100644 index 0000000..6d1ae1a --- /dev/null +++ b/src/Local/BatchManager_Local.cxx @@ -0,0 +1,813 @@ +// Copyright (C) 2007-2012 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.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 +* +* 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 +#include +#include + +#include +#ifdef WIN32 +#include +#else +#include +#include +#endif +#include +#include +#include +#include +#include + +#include "Constants.hxx" +#include "IOMutex.hxx" +#include "BatchManager_Local.hxx" +#include "RunTimeException.hxx" +#include "Utils.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + + // Constructeur + BatchManager_Local::BatchManager_Local(const Batch::FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl), _connect(0), + _idCounter(0) + { + pthread_mutex_init(&_threads_mutex, NULL); + pthread_cond_init(&_threadSyncCondition, NULL); + } + + // Destructeur + BatchManager_Local::~BatchManager_Local() + { + for (map::iterator iter = _threads.begin() ; iter != _threads.end() ; iter++) { + pthread_mutex_lock(&_threads_mutex); + string state = iter->second.param[STATE]; + if (state != FINISHED && state != FAILED) { + UNDER_LOCK( LOG("Warning: Job " << iter->first << + " is not finished, it will now be canceled.")); + pthread_cancel(iter->second.thread_id); + pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); + } + pthread_mutex_unlock(&_threads_mutex); + } + pthread_mutex_destroy(&_threads_mutex); + pthread_cond_destroy(&_threadSyncCondition); + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_Local::submitJob(const Job & job) + { + // export input files in the working directory of the execution host + exportInputFiles(job); + + Job_Local jobLocal = job; + Id id = _idCounter++; + ThreadAdapter * p_ta = new ThreadAdapter(*this, job, id); + + // Les attributs du thread a sa creation + pthread_attr_t thread_attr; + pthread_attr_init(&thread_attr); + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); + + // Creation du thread qui va executer la commande systeme qu'on lui passe + pthread_t thread_id; + pthread_mutex_lock(&_threads_mutex); + int rc = pthread_create(&thread_id, + &thread_attr, + &ThreadAdapter::run, + static_cast(p_ta)); + + // Liberation des zones memoire maintenant inutiles occupees par les attributs du thread + pthread_attr_destroy(&thread_attr); + + if (rc != 0) { + pthread_mutex_unlock(&_threads_mutex); + throw RunTimeException("Can't create new thread in BatchManager_Local"); + } + + pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); + pthread_mutex_unlock(&_threads_mutex); + + ostringstream id_sst; + id_sst << id; + return JobId(this, id_sst.str()); + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_Local::deleteJob(const JobId & jobid) + { + Id id; + + istringstream iss(jobid.getReference()); + iss >> id; + + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + bool idFound = (_threads.find(id) != _threads.end()); + if (idFound) { + string state = _threads[id].param[STATE]; + if (state != FINISHED && state != FAILED) { + pthread_cancel(_threads[id].thread_id); + pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); + } else { + LOG("Cannot delete job " << jobid.getReference() << ". Job is already finished."); + } + } + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + if (!idFound) + throw RunTimeException(string("Job with id ") + jobid.getReference() + " does not exist"); + } + + // Methode pour le controle des jobs : suspend un job en file d'attente + void BatchManager_Local::holdJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + UNDER_LOCK( LOG("BatchManager is sending HOLD command to the thread " << id) ); + + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + if (_threads.find(id) != _threads.end()) + _threads[id].command_queue.push(HOLD); + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + + // Methode pour le controle des jobs : relache un job suspendu + void BatchManager_Local::releaseJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + UNDER_LOCK( LOG("BatchManager is sending RELEASE command to the thread " << id) ); + + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + if (_threads.find(id) != _threads.end()) + _threads[id].command_queue.push(RELEASE); + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_Local::queryJob(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + Parametre param; + Environnement env; + + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + std::map::iterator pos = _threads.find(id); + bool found = (pos != _threads.end()); + if (found) { + param = pos->second.param; + env = pos->second.env; + } + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); + + if (!found) throw InvalidArgumentException("Invalid JobId argument for queryJob"); + + JobInfo_Local ji(param, env); + return ji; + } + + + // Ce manager ne peut pas reprendre un job + // On force donc l'état du job à erreur - pour cela on ne donne pas d'Id + // au JobId + const Batch::JobId + BatchManager_Local::addJob(const Batch::Job & job, const std::string & reference) + { + return JobId(this, "undefined"); + } + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_Local::isRunning(const JobId & jobid) + { + Id id; + istringstream iss(jobid.getReference()); + iss >> id; + + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_threads_mutex); + bool running = (_threads[id].param[STATE].str() == RUNNING); + pthread_mutex_unlock(&_threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); + + return running; + } + + string BatchManager_Local::ThreadAdapter::buildCommandFile(const Job_Local & job) + { + Parametre param = job.getParametre(); + + // Mandatory parameters + string workDir = ""; + if (param.find(WORKDIR) != param.end()) + workDir = param[WORKDIR].str(); + else + throw RunTimeException("param[WORKDIR] is not defined. Please define it, cannot submit this job."); + string fileToExecute = ""; + if (param.find(EXECUTABLE) != param.end()) + fileToExecute = param[EXECUTABLE].str(); + else + throw RunTimeException("param[EXECUTABLE] is not defined. Please define it, cannot submit this job."); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + string remotePath = workDir + "/" + rootNameToExecute + "_launch_job"; + + // Create batch submit file + ofstream tempOutputFile; + string tmpFileName = Utils::createAndOpenTemporaryFile("launch-job", tempOutputFile); + +#ifdef WIN32 + if (_bm._protocol.getType() == SH) { + char drive[_MAX_DRIVE]; + _splitpath(workDir.c_str(), drive, NULL, NULL, NULL); + if (strlen(drive) > 0) tempOutputFile << drive << endl; + tempOutputFile << "cd " << Utils::fixPath(workDir) << endl; + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "set " << iter->first << "=" << iter->second << endl; + } + // Launch the executable + tempOutputFile << fileNameToExecute; + 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; + tempOutputFile << " " << arg; + } + } + remotePath += ".bat"; + } else { +#endif + + tempOutputFile << "#!/bin/sh" << endl; + tempOutputFile << "cd " << workDir << endl; + + // Optional parameters (system limits on the job process) + if (param.find(MAXCPUTIME) != param.end()) { + long maxcputime = (long)param[MAXCPUTIME] * 60; + tempOutputFile << "ulimit -H -t " << maxcputime << endl; + } + + if (param.find(MAXDISKSIZE) != param.end()) { + long maxdisksize = (long)param[MAXDISKSIZE] * 1024; + tempOutputFile << "ulimit -H -f " << maxdisksize << endl; + } + + if (param.find(MAXRAMSIZE) != param.end()) { + long maxramsize = (long)param[MAXRAMSIZE] * 1024; + tempOutputFile << "ulimit -H -v " << maxramsize << endl; + } + + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "export " << iter->first << "=" << iter->second << endl; + } + + // generate nodes file + tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; + tempOutputFile << "echo `hostname` > $LIBBATCH_NODEFILE" << endl; + tempOutputFile << "export LIBBATCH_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "./" + fileNameToExecute; + 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; + tempOutputFile << " " << arg; + } + } + + // Standard input and output + if (param.find(INFILE) != param.end()) { + Versatile V = param[INFILE]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + Couple cpl = * static_cast(*it); + string remote = cpl.getRemote(); + if (remote == "stdin") + tempOutputFile << " (*it); + string remote = cpl.getRemote(); + if (remote == "stdout") stdoutFile = "stdout"; + if (remote == "stderr") stderrFile = "stderr"; + } + } + tempOutputFile << " 1>" << stdoutFile << " 2>" << stderrFile << endl; + + // Remove the node file + tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; + +#ifdef WIN32 + } +#endif + + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << tmpFileName); + + Utils::chmod(tmpFileName.c_str(), 0x1ED); + int status = _bm._protocol.copyFile(tmpFileName, "", "", + remotePath, _bm._hostname, _bm._username); + if (status) + throw RunTimeException("Cannot copy command file on host " + _bm._hostname); + +#ifdef WIN32 + if (_bm._protocol.getType() != SH) { + // On Windows, we make the remote file executable afterward because + // pscp does not preserve access permissions on files + string subCommand = string("chmod u+x ") + remotePath; + string command = _bm._protocol.getExecCommand(subCommand, _bm._hostname, _bm._username); + LOG(command); + status = system(command.c_str()); + if (status) { + std::ostringstream oss; + oss << "Cannot change permissions of file " << remotePath << " on host " << _bm._hostname; + oss << ". Return status is " << status; + throw RunTimeException(oss.str()); + } + } +#endif + + return remotePath; + } + + + + // Constructeur de la classe ThreadAdapter + BatchManager_Local::ThreadAdapter::ThreadAdapter(BatchManager_Local & bm, const Job_Local & job, Id id) : + _bm(bm), _job(job), _id(id) + { + // Nothing to do + } + + + + // Methode d'execution du thread + void * BatchManager_Local::ThreadAdapter::run(void * arg) + { + ThreadAdapter * p_ta = static_cast(arg); + +#ifndef WIN32 + // On bloque tous les signaux pour ce thread + sigset_t setmask; + sigfillset(&setmask); + pthread_sigmask(SIG_BLOCK, &setmask, NULL); +#endif + + // On autorise la terminaison differee du thread + // (ces valeurs sont les valeurs par defaut mais on les force par precaution) + pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); + pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); + + // On enregistre la fonction de suppression du fils en cas d'arret du thread + // Cette fontion sera automatiquement appelee lorsqu'une demande d'annulation + // sera prise en compte par pthread_testcancel() + Process child; + pthread_cleanup_push(BatchManager_Local::delete_on_exit, arg); + pthread_cleanup_push(BatchManager_Local::setFailedOnCancel, arg); + pthread_cleanup_push(BatchManager_Local::kill_child_on_exit, static_cast (&child)); + + // On forke/exec un nouveau process pour pouvoir controler le fils + // (plus finement qu'avec un appel system) + // int rc = system(commande.c_str()); + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 10 && echo end", NULL}; + //execv("/usr/bin/ssh", parmList); +#ifdef WIN32 + child = p_ta->launchWin32ChildProcess(); + p_ta->pere(child); +#else + child = fork(); + if (child < 0) { // erreur + UNDER_LOCK( LOG("Fork impossible (rc=" << child << ")") ); + + } else if (child > 0) { // pere + p_ta->pere(child); + + } else { // fils + p_ta->fils(); + } +#endif + + pthread_mutex_lock(&p_ta->_bm._threads_mutex); + + // Set the job state to FINISHED or FAILED + p_ta->_bm._threads[p_ta->_id].param[STATE] = (p_ta->_bm._threads[p_ta->_id].hasFailed) ? FAILED : FINISHED; + + // On retire la fonction de nettoyage de la memoire + pthread_cleanup_pop(0); + + // On retire la fonction de suppression du fils + pthread_cleanup_pop(0); + + // remove setFailedOnCancel function from cancel stack + pthread_cleanup_pop(0); + + pthread_mutex_unlock(&p_ta->_bm._threads_mutex); + + // On invoque la fonction de nettoyage de la memoire + delete_on_exit(arg); + + UNDER_LOCK( LOG("Father is leaving") ); + pthread_exit(NULL); + return NULL; + } + + + + + void BatchManager_Local::ThreadAdapter::pere(Process child) + { + time_t child_starttime = time(NULL); + + // On enregistre le fils dans la table des threads + pthread_t thread_id = pthread_self(); + + Parametre param = _job.getParametre(); + Environnement env = _job.getEnvironnement(); + + ostringstream id_sst; + id_sst << _id; + param[ID] = id_sst.str(); + param[STATE] = Batch::RUNNING; + + _bm._threads[_id].thread_id = thread_id; +#ifndef WIN32 + _bm._threads[_id].pid = child; +#endif + _bm._threads[_id].hasFailed = false; + _bm._threads[_id].param = param; + _bm._threads[_id].env = env; + _bm._threads[_id].command_queue.push(NOP); + + // Unlock the master thread. From here, all shared variables must be protected + // from concurrent access + pthread_cond_signal(&_bm._threadSyncCondition); + + + // on boucle en attendant que le fils ait termine + while (1) { +#ifdef WIN32 + DWORD exitCode; + GetExitCodeProcess(child, &exitCode); + if (exitCode != STILL_ACTIVE) { + UNDER_LOCK( LOG("Father sees his child is DONE: exit code = " << exitCode) ); + break; + } +#else + int child_rc = 0; + pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */); + if (child_wait_rc > 0) { + UNDER_LOCK( LOG("Status is: " << WIFEXITED( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WEXITSTATUS( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WIFSIGNALED( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WTERMSIG( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WCOREDUMP( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WIFSTOPPED( child_rc)) ); + UNDER_LOCK( LOG("Status is: " << WSTOPSIG( child_rc)) ); +#ifdef WIFCONTINUED + UNDER_LOCK( LOG("Status is: " << WIFCONTINUED( child_rc)) ); // not compilable on sarge +#endif + if (WIFSTOPPED(child_rc)) { + // NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED + // soit positionne dans l'appel a waitpid ci-dessus. Ce flag est couramment + // desactive car s'il est possible de detecter l'arret d'un process, il est + // plus difficile de detecter sa reprise. + + // Le fils est simplement stoppe + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[_id].param[STATE] = Batch::PAUSED; + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + UNDER_LOCK( LOG("Father sees his child is STOPPED : " << child_wait_rc) ); + + } + else { + // Le fils est termine, on sort de la boucle et du if englobant + UNDER_LOCK( LOG("Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")") ); + break; + } + } + else if (child_wait_rc == -1) { + // Le fils a disparu ... + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + _bm._threads[_id].hasFailed = true; + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + UNDER_LOCK( LOG("Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")") ); + break; + } +#endif + + // On teste si le thread doit etre detruit + pthread_testcancel(); + + + + // On regarde si le fils n'a pas depasse son temps (wallclock time) + time_t child_currenttime = time(NULL); + long child_elapsedtime_minutes = (child_currenttime - child_starttime) / 60L; + if (param.find(MAXWALLTIME) != param.end()) { + long maxwalltime = param[MAXWALLTIME]; + // cout << "child_starttime = " << child_starttime << endl + // << "child_currenttime = " << child_currenttime << endl + // << "child_elapsedtime = " << child_elapsedtime << endl + // << "maxwalltime = " << maxwalltime << endl + // << "int(maxwalltime * 1.1) = " << int(maxwalltime * 1.1) << endl; + if (child_elapsedtime_minutes > long((float)maxwalltime * 1.1) ) { // On se donne 10% de marge avant le KILL + UNDER_LOCK( LOG("Father is sending KILL command to the thread " << _id) ); + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(_id) != _bm._threads.end()) + _bm._threads[_id].command_queue.push(KILL); + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + + } else if (child_elapsedtime_minutes > maxwalltime ) { + UNDER_LOCK( LOG("Father is sending TERM command to the thread " << _id) ); + // On introduit une commande dans la queue du thread + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(_id) != _bm._threads.end()) + _bm._threads[_id].command_queue.push(TERM); + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + } + } + + + + // On regarde s'il y a quelque chose a faire dans la queue de commande + // @@@ --------> SECTION CRITIQUE <-------- @@@ + pthread_mutex_lock(&_bm._threads_mutex); + if (_bm._threads.find(_id) != _bm._threads.end()) { + while (_bm._threads[_id].command_queue.size() > 0) { + Commande cmd = _bm._threads[_id].command_queue.front(); + _bm._threads[_id].command_queue.pop(); + + switch (cmd) { + case NOP: + UNDER_LOCK( LOG("Father does nothing to his child") ); + break; +#ifndef WIN32 + case HOLD: + UNDER_LOCK( LOG("Father is sending SIGSTOP signal to his child") ); + kill(child, SIGSTOP); + break; + + case RELEASE: + UNDER_LOCK( LOG("Father is sending SIGCONT signal to his child") ); + kill(child, SIGCONT); + break; + + case TERM: + UNDER_LOCK( LOG("Father is sending SIGTERM signal to his child") ); + kill(child, SIGTERM); + break; + + case KILL: + UNDER_LOCK( LOG("Father is sending SIGKILL signal to his child") ); + kill(child, SIGKILL); + break; +#endif + case ALTER: + break; + + default: + break; + } + } + + } + pthread_mutex_unlock(&_bm._threads_mutex); + // @@@ --------> SECTION CRITIQUE <-------- @@@ + + // On fait une petite pause pour ne pas surcharger inutilement le processeur +#ifdef WIN32 + Sleep(1000); +#else + sleep(1); +#endif + + } + + } + + + +#ifndef WIN32 + + void BatchManager_Local::ThreadAdapter::fils() + { + Parametre param = _job.getParametre(); + Parametre::iterator it; + + try { + + // build script file to launch the job and copy it on the server + string cmdFilePath = buildCommandFile(_job); + + // define command to submit the job + vector command = _bm._protocol.getExecCommandArgs(cmdFilePath, _bm._hostname, _bm._username); + + // Build the argument array argv from the command + char ** argv = new char * [command.size() + 1]; + string comstr; + for (string::size_type i=0 ; i command = _bm._protocol.getExecCommandArgs(cmdFilePath, _bm._hostname, _bm._username); + + // Build the command string from the command argument vector + string comstr; + for (unsigned int i=0 ; i0) comstr += " "; + comstr += command[i]; + } + + UNDER_LOCK( LOG("*** debug_command = " << comstr) ); + + STARTUPINFO si; + ZeroMemory( &si, sizeof(si) ); + si.cb = sizeof(si); + ZeroMemory( &pi, sizeof(pi) ); + + // Copy the command to a non-const buffer + char * buffer = strdup(comstr.c_str()); + + // launch the new process + bool res = CreateProcess(NULL, buffer, NULL, NULL, FALSE, + CREATE_NO_WINDOW, NULL, NULL, &si, &pi); + + if (buffer) free(buffer); + if (!res) throw RunTimeException("Error while creating new process"); + + CloseHandle(pi.hThread); + + } catch (GenericException & e) { + + LOG("Caught exception : " << e.type << " : " << e.message); + } + + return pi.hProcess; + } + +#endif + + + void BatchManager_Local::kill_child_on_exit(void * p_pid) + { +#ifndef WIN32 + //TODO: porting of following functionality + pid_t child = * static_cast(p_pid); + + // On tue le fils + kill(child, SIGTERM); + + // Nota : on pourrait aussi faire a la suite un kill(child, SIGKILL) + // mais cette option n'est pas implementee pour le moment, car il est + // preferable de laisser le process fils se terminer normalement et seul. +#endif + } + + void BatchManager_Local::delete_on_exit(void * arg) + { + ThreadAdapter * p_ta = static_cast(arg); + delete p_ta; + } + + void BatchManager_Local::setFailedOnCancel(void * arg) + { + ThreadAdapter * p_ta = static_cast(arg); + pthread_mutex_lock(&p_ta->getBatchManager()._threads_mutex); + p_ta->getBatchManager()._threads[p_ta->getId()].param[STATE] = FAILED; + pthread_mutex_unlock(&p_ta->getBatchManager()._threads_mutex); + + // Unlock the master thread. From here, the batch manager instance should not be used. + pthread_cond_signal(&p_ta->getBatchManager()._threadSyncCondition); + } + +} diff --git a/src/Local/BatchManager_Local.hxx b/src/Local/BatchManager_Local.hxx new file mode 100644 index 0000000..8058a3c --- /dev/null +++ b/src/Local/BatchManager_Local.hxx @@ -0,0 +1,170 @@ +// Copyright (C) 2007-2012 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.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 + * + * 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 "Defines.hxx" +#include "CommunicationProtocol.hxx" + +#ifdef WIN32 +#include +#endif + +#include +#include +#include +#include +#include "Job.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "JobInfo_Local.hxx" +#include "Job_Local.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class FactBatchManager; + + /*! + * This class defines a local pseudo batch manager that can launch jobs locally or on a remote + * machine with SSH or RSH. This class is NOT thread-safe. + */ + class BATCH_EXPORT BatchManager_Local : virtual public BatchManager + { + private: + typedef int Id; +#ifdef WIN32 + typedef HANDLE Process; +#else + typedef pid_t Process; +#endif + friend class ThreadAdapter; + class ThreadAdapter{ + public: + ThreadAdapter(BatchManager_Local & bm, const Job_Local & job, Id id); + static void * run(void * arg); + BatchManager_Local & getBatchManager() const { return _bm; }; + Id getId() const { return _id; }; + + protected: + BatchManager_Local & _bm; + const Job_Local _job; + Id _id; + + private: + void pere(Process child); +#ifndef WIN32 + void fils(); +#else + Process launchWin32ChildProcess(); +#endif + + /** + * Create script to launch the remote command and copy it on the server. + * Return the path of the remote script. + */ + std::string buildCommandFile(const Job_Local & job); + + }; + + enum Commande { + NOP = 0, + HOLD, + RELEASE, + TERM, + KILL, + ALTER + }; + + struct Child { + pthread_t thread_id; + std::queue > command_queue; + pid_t pid; + int exit_code; + bool hasFailed; + Parametre param; + Environnement env; + }; + + + + public: + + BatchManager_Local(const Batch::FactBatchManager * parent, const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi"); + virtual ~BatchManager_Local(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_Local::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente + virtual void releaseJob(const JobId & jobid); // relache un job suspendu + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + virtual const Batch::JobId addJob(const Batch::Job & job, const std::string & reference); // ajoute un nouveau job sans le soumettre + + protected: + int _connect; // Local connect id + pthread_mutex_t _threads_mutex; + std::map _threads; + + private: + static void kill_child_on_exit(void * p_pid); + static void delete_on_exit(void * arg); + static void setFailedOnCancel(void * arg); + pthread_cond_t _threadSyncCondition; + Id _idCounter; + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/Local/Batch_BatchManager_Local.cxx b/src/Local/Batch_BatchManager_Local.cxx deleted file mode 100644 index 2098e1c..0000000 --- a/src/Local/Batch_BatchManager_Local.cxx +++ /dev/null @@ -1,939 +0,0 @@ -// Copyright (C) 2007-2012 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.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 -* -* 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 -#include -#include - -#include -#ifdef WIN32 -#include -#else -#include -#include -#endif -#include -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_IOMutex.hxx" -#include "Batch_BatchManager_Local.hxx" -#include "Batch_RunTimeException.hxx" - -using namespace std; - -namespace Batch { - - - // Constructeur - BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host, - CommunicationProtocolType protocolType) - : BatchManager(parent, host), _connect(0), - _protocol(CommunicationProtocol::getInstance(protocolType)), - _idCounter(0) - { - pthread_mutex_init(&_threads_mutex, NULL); - pthread_cond_init(&_threadSyncCondition, NULL); - } - - // Destructeur - BatchManager_Local::~BatchManager_Local() - { - for (map::iterator iter = _threads.begin() ; iter != _threads.end() ; iter++) { - pthread_mutex_lock(&_threads_mutex); - string state = iter->second.param[STATE]; - if (state != FINISHED && state != FAILED) { - UNDER_LOCK( cout << "Warning: Job " << iter->first << - " is not finished, it will now be canceled." << endl ); - pthread_cancel(iter->second.thread_id); - pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); - } - pthread_mutex_unlock(&_threads_mutex); - } - pthread_mutex_destroy(&_threads_mutex); - pthread_cond_destroy(&_threadSyncCondition); - } - - 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) - { - Job_Local jobLocal = job; - Id id = _idCounter++; - ThreadAdapter * p_ta = new ThreadAdapter(*this, job, id); - - // Les attributs du thread a sa creation - pthread_attr_t thread_attr; - pthread_attr_init(&thread_attr); - pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); - - // Creation du thread qui va executer la commande systeme qu'on lui passe - pthread_t thread_id; - pthread_mutex_lock(&_threads_mutex); - int rc = pthread_create(&thread_id, - &thread_attr, - &ThreadAdapter::run, - static_cast(p_ta)); - - // Liberation des zones memoire maintenant inutiles occupees par les attributs du thread - pthread_attr_destroy(&thread_attr); - - if (rc != 0) { - pthread_mutex_unlock(&_threads_mutex); - throw RunTimeException("Can't create new thread in BatchManager_Local"); - } - - pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); - pthread_mutex_unlock(&_threads_mutex); - - ostringstream id_sst; - id_sst << id; - return JobId(this, id_sst.str()); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_Local::deleteJob(const JobId & jobid) - { - Id id; - - istringstream iss(jobid.getReference()); - iss >> id; - - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_threads_mutex); - bool idFound = (_threads.find(id) != _threads.end()); - if (idFound) { - string state = _threads[id].param[STATE]; - if (state != FINISHED && state != FAILED) { - pthread_cancel(_threads[id].thread_id); - pthread_cond_wait(&_threadSyncCondition, &_threads_mutex); - } else { - cout << "Cannot delete job " << jobid.getReference() << - ". Job is already finished." << endl; - } - } - pthread_mutex_unlock(&_threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - - if (!idFound) - throw RunTimeException(string("Job with id ") + jobid.getReference() + " does not exist"); - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_Local::holdJob(const JobId & jobid) - { - Id id; - istringstream iss(jobid.getReference()); - iss >> id; - - UNDER_LOCK( cout << "BatchManager is sending HOLD command to the thread " << id << endl ); - - // On introduit une commande dans la queue du thread - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_threads_mutex); - if (_threads.find(id) != _threads.end()) - _threads[id].command_queue.push(HOLD); - pthread_mutex_unlock(&_threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_Local::releaseJob(const JobId & jobid) - { - Id id; - istringstream iss(jobid.getReference()); - iss >> id; - - UNDER_LOCK( cout << "BatchManager is sending RELEASE command to the thread " << id << endl ); - - // On introduit une commande dans la queue du thread - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_threads_mutex); - if (_threads.find(id) != _threads.end()) - _threads[id].command_queue.push(RELEASE); - pthread_mutex_unlock(&_threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_Local::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_Local::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_Local::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_Local::queryJob(const JobId & jobid) - { - Id id; - istringstream iss(jobid.getReference()); - iss >> id; - - Parametre param; - Environnement env; - - //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_threads_mutex); - std::map::iterator pos = _threads.find(id); - bool found = (pos != _threads.end()); - if (found) { - param = pos->second.param; - env = pos->second.env; - } - pthread_mutex_unlock(&_threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); - - if (!found) throw InvalidArgumentException("Invalid JobId argument for queryJob"); - - JobInfo_Local ji(param, env); - return ji; - } - - - // Ce manager ne peut pas reprendre un job - // On force donc l'état du job à erreur - pour cela on ne donne pas d'Id - // au JobId - const Batch::JobId - BatchManager_Local::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, "undefined"); - } - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_Local::isRunning(const JobId & jobid) - { - Id id; - istringstream iss(jobid.getReference()); - iss >> id; - - //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : AVANT section critique" << endl ); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_threads_mutex); - bool running = (_threads[id].param[STATE].str() == RUNNING); - pthread_mutex_unlock(&_threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - //UNDER_LOCK( cout << "JobInfo BatchManager_Local::queryJob(const JobId & jobid) : APRES section critique" << endl ); - - return running; - } - - - 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; - } - } - - if (param.find(INFILE) != param.end()) { - Versatile V = param[INFILE]; - for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { - Couple cpl = * static_cast(*it); - string remote = cpl.getRemote(); - if (remote == "stdin") - exec_sub_cmd << " (*it); - string remote = cpl.getRemote(); - if (remote == "stdout") exec_sub_cmd << " 1>stdout"; - if (remote == "stderr") exec_sub_cmd << " 2>stderr"; - } - } - - 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); - } - - - - // Constructeur de la classe ThreadAdapter - BatchManager_Local::ThreadAdapter::ThreadAdapter(BatchManager_Local & bm, const Job_Local & job, Id id) : - _bm(bm), _job(job), _id(id) - { - // Nothing to do - } - - - - // Methode d'execution du thread - void * BatchManager_Local::ThreadAdapter::run(void * arg) - { - ThreadAdapter * p_ta = static_cast(arg); - -#ifndef WIN32 - // On bloque tous les signaux pour ce thread - sigset_t setmask; - sigfillset(&setmask); - pthread_sigmask(SIG_BLOCK, &setmask, NULL); -#endif - - // On autorise la terminaison differee du thread - // (ces valeurs sont les valeurs par defaut mais on les force par precaution) - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); - - // On enregistre la fonction de suppression du fils en cas d'arret du thread - // Cette fontion sera automatiquement appelee lorsqu'une demande d'annulation - // sera prise en compte par pthread_testcancel() - Process child; - pthread_cleanup_push(BatchManager_Local::delete_on_exit, arg); - pthread_cleanup_push(BatchManager_Local::setFailedOnCancel, arg); - pthread_cleanup_push(BatchManager_Local::kill_child_on_exit, static_cast (&child)); - - - // Le code retour cumule (ORed) de tous les appels - // Nul en cas de reussite de l'ensemble des operations - int rc = 0; - - // Cette table contient la liste des fichiers a detruire a la fin du processus - std::vector files_to_delete; - - - - // On copie les fichiers d'entree pour le fils - const Parametre param = p_ta->_job.getParametre(); - Parametre::const_iterator it; - - // On initialise la variable workdir a la valeur du Current Working Directory - char * cwd = -#ifdef WIN32 - _getcwd(NULL, 0); -#else - new char [PATH_MAX]; - getcwd(cwd, PATH_MAX); -#endif - string workdir = cwd; - delete [] cwd; - - if ( (it = param.find(WORKDIR)) != param.end() ) { - workdir = static_cast( (*it).second ); - } - - string executionhost = string(param[EXECUTIONHOST]); - string user; - if ( (it = param.find(USER)) != param.end() ) { - user = string(it->second); - } - - if ( (it = param.find(INFILE)) != param.end() ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - std::cerr << workdir << std::endl; - std::cerr << remote << std::endl; - - int status = p_ta->getBatchManager().getProtocol().copyFile(local, "", "", - workdir + "/" + remote, - executionhost, user); - if (status) { - // Echec de la copie - rc |= 1; - } else { - // On enregistre le fichier comme etant a detruire - files_to_delete.push_back(workdir + "/" + remote); - } - - } - } - - - - - // On forke/exec un nouveau process pour pouvoir controler le fils - // (plus finement qu'avec un appel system) - // int rc = system(commande.c_str()); - //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 10 && echo end", NULL}; - //execv("/usr/bin/ssh", parmList); -#ifdef WIN32 - child = p_ta->launchWin32ChildProcess(); - p_ta->pere(child); -#else - child = fork(); - if (child < 0) { // erreur - UNDER_LOCK( cerr << "Fork impossible (rc=" << child << ")" << endl ); - - } else if (child > 0) { // pere - p_ta->pere(child); - - } else { // fils - p_ta->fils(); - } -#endif - - - // On copie les fichiers de sortie du fils - if ( (it = param.find(OUTFILE)) != param.end() ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - for(Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - int status = p_ta->getBatchManager().getProtocol().copyFile(workdir + "/" + remote, - executionhost, user, - local, "", ""); - if (status) { - // Echec de la copie - rc |= 1; - } else { - // On enregistre le fichier comme etant a detruire - files_to_delete.push_back(workdir + "/" + remote); - } - - } - } - - // On efface les fichiers d'entree et de sortie du fils si les copies precedentes ont reussi - // ou si la creation du fils n'a pu avoir lieu - if ( (rc == 0) || (child < 0) ) { - std::vector::const_iterator it; - for(it=files_to_delete.begin(); it!=files_to_delete.end(); 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());*/ - } - } - - pthread_mutex_lock(&p_ta->_bm._threads_mutex); - - // Set the job state to FINISHED or FAILED - p_ta->_bm._threads[p_ta->_id].param[STATE] = (p_ta->_bm._threads[p_ta->_id].hasFailed) ? FAILED : FINISHED; - - // On retire la fonction de nettoyage de la memoire - pthread_cleanup_pop(0); - - // On retire la fonction de suppression du fils - pthread_cleanup_pop(0); - - // remove setFailedOnCancel function from cancel stack - pthread_cleanup_pop(0); - - pthread_mutex_unlock(&p_ta->_bm._threads_mutex); - - // On invoque la fonction de nettoyage de la memoire - delete_on_exit(arg); - - UNDER_LOCK( cout << "Father is leaving" << endl ); - pthread_exit(NULL); - return NULL; - } - - - - - void BatchManager_Local::ThreadAdapter::pere(Process child) - { - time_t child_starttime = time(NULL); - - // On enregistre le fils dans la table des threads - pthread_t thread_id = pthread_self(); - - Parametre param = _job.getParametre(); - Environnement env = _job.getEnvironnement(); - - ostringstream id_sst; - id_sst << _id; - param[ID] = id_sst.str(); - param[STATE] = Batch::RUNNING; -#ifndef WIN32 - param[PID] = child; -#endif - - _bm._threads[_id].thread_id = thread_id; -#ifndef WIN32 - _bm._threads[_id].pid = child; -#endif - _bm._threads[_id].hasFailed = false; - _bm._threads[_id].param = param; - _bm._threads[_id].env = env; - _bm._threads[_id].command_queue.push(NOP); - - // Unlock the master thread. From here, all shared variables must be protected - // from concurrent access - pthread_cond_signal(&_bm._threadSyncCondition); - - - // on boucle en attendant que le fils ait termine - while (1) { -#ifdef WIN32 - DWORD exitCode; - GetExitCodeProcess(child, &exitCode); - if (exitCode != STILL_ACTIVE) { - UNDER_LOCK( cout << "Father sees his child is DONE: exit code = " << exitCode << endl ); - break; - } -#else - int child_rc = 0; - pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */); - if (child_wait_rc > 0) { - UNDER_LOCK( cout << "Status is: " << WIFEXITED( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WEXITSTATUS( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WIFSIGNALED( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WTERMSIG( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WCOREDUMP( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WIFSTOPPED( child_rc) << endl); - UNDER_LOCK( cout << "Status is: " << WSTOPSIG( child_rc) << endl); -#ifdef WIFCONTINUED - UNDER_LOCK( cout << "Status is: " << WIFCONTINUED( child_rc) << endl); // not compilable on sarge -#endif - if (WIFSTOPPED(child_rc)) { - // NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED - // soit positionne dans l'appel a waitpid ci-dessus. Ce flag est couramment - // desactive car s'il est possible de detecter l'arret d'un process, il est - // plus difficile de detecter sa reprise. - - // Le fils est simplement stoppe - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_bm._threads_mutex); - _bm._threads[_id].param[STATE] = Batch::PAUSED; - pthread_mutex_unlock(&_bm._threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - UNDER_LOCK( cout << "Father sees his child is STOPPED : " << child_wait_rc << endl ); - - } - else { - // Le fils est termine, on sort de la boucle et du if englobant - UNDER_LOCK( cout << "Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")" << endl ); - break; - } - } - else if (child_wait_rc == -1) { - // Le fils a disparu ... - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_bm._threads_mutex); - _bm._threads[_id].hasFailed = true; - pthread_mutex_unlock(&_bm._threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - UNDER_LOCK( cout << "Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")" << endl ); - break; - } -#endif - - // On teste si le thread doit etre detruit - pthread_testcancel(); - - - - // On regarde si le fils n'a pas depasse son temps (wallclock time) - time_t child_currenttime = time(NULL); - long child_elapsedtime_minutes = (child_currenttime - child_starttime) / 60L; - if (param.find(MAXWALLTIME) != param.end()) { - long maxwalltime = param[MAXWALLTIME]; - // cout << "child_starttime = " << child_starttime << endl - // << "child_currenttime = " << child_currenttime << endl - // << "child_elapsedtime = " << child_elapsedtime << endl - // << "maxwalltime = " << maxwalltime << endl - // << "int(maxwalltime * 1.1) = " << int(maxwalltime * 1.1) << endl; - if (child_elapsedtime_minutes > long((float)maxwalltime * 1.1) ) { // On se donne 10% de marge avant le KILL - UNDER_LOCK( cout << "Father is sending KILL command to the thread " << _id << endl ); - // On introduit une commande dans la queue du thread - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_bm._threads_mutex); - if (_bm._threads.find(_id) != _bm._threads.end()) - _bm._threads[_id].command_queue.push(KILL); - pthread_mutex_unlock(&_bm._threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - - - } else if (child_elapsedtime_minutes > maxwalltime ) { - UNDER_LOCK( cout << "Father is sending TERM command to the thread " << _id << endl ); - // On introduit une commande dans la queue du thread - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_bm._threads_mutex); - if (_bm._threads.find(_id) != _bm._threads.end()) - _bm._threads[_id].command_queue.push(TERM); - pthread_mutex_unlock(&_bm._threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - } - } - - - - // On regarde s'il y a quelque chose a faire dans la queue de commande - // @@@ --------> SECTION CRITIQUE <-------- @@@ - pthread_mutex_lock(&_bm._threads_mutex); - if (_bm._threads.find(_id) != _bm._threads.end()) { - while (_bm._threads[_id].command_queue.size() > 0) { - Commande cmd = _bm._threads[_id].command_queue.front(); - _bm._threads[_id].command_queue.pop(); - - switch (cmd) { - case NOP: - UNDER_LOCK( cout << "Father does nothing to his child" << endl ); - break; -#ifndef WIN32 - case HOLD: - UNDER_LOCK( cout << "Father is sending SIGSTOP signal to his child" << endl ); - kill(child, SIGSTOP); - break; - - case RELEASE: - UNDER_LOCK( cout << "Father is sending SIGCONT signal to his child" << endl ); - kill(child, SIGCONT); - break; - - case TERM: - UNDER_LOCK( cout << "Father is sending SIGTERM signal to his child" << endl ); - kill(child, SIGTERM); - break; - - case KILL: - UNDER_LOCK( cout << "Father is sending SIGKILL signal to his child" << endl ); - kill(child, SIGKILL); - break; -#endif - case ALTER: - break; - - default: - break; - } - } - - } - pthread_mutex_unlock(&_bm._threads_mutex); - // @@@ --------> SECTION CRITIQUE <-------- @@@ - - // On fait une petite pause pour ne pas surcharger inutilement le processeur -#ifdef WIN32 - Sleep(1000); -#else - sleep(1); -#endif - - } - - } - - - -#ifndef WIN32 - - void BatchManager_Local::ThreadAdapter::fils() - { - Parametre param = _job.getParametre(); - Parametre::iterator it; - - //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; - //int result = execv("/usr/bin/ssh", parmList); - //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); - //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); - try { - - // EXECUTABLE is MANDATORY, if missing, we exit with failure notification - vector command; - if (param.find(EXECUTABLE) != param.end()) { - command = _bm.exec_command(param); - } else exit(1); - - // 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 = " << comstr << endl ); - UNDER_LOCK( cout << "*** debug_command = " << argv[0] << 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 - // remote process. - Environnement env = _job.getEnvironnement(); - - char ** envp = NULL; - if(env.size() > 0) { - envp = new char * [env.size() + 1]; // 1 pour le NULL terminal - int i = 0; - for(Environnement::const_iterator it=env.begin(); it!=env.end(); it++, i++) { - const string & key = (*it).first; - const string & value = (*it).second; - ostringstream oss; - oss << key << "=" << value; - envp[i] = new char [oss.str().size() + 1]; - strncpy(envp[i], oss.str().c_str(), oss.str().size() + 1); - } - - // assert (i == env.size()) - envp[i] = NULL; - } - - //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; - //int result = execv("/usr/bin/ssh", parmList); - //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); - //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); - - - - // On positionne les limites systeme imposees au fils - // This part is deactivated because those limits should be set on the job process, not on - // the ssh process. If it is done properly one day, beware of the types used (int is not enough) - /* - if (param.find(MAXCPUTIME) != param.end()) { - int maxcputime = param[MAXCPUTIME]; - struct rlimit limit; - limit.rlim_cur = maxcputime; - limit.rlim_max = int(maxcputime * 1.1); - setrlimit(RLIMIT_CPU, &limit); - } - - if (param.find(MAXDISKSIZE) != param.end()) { - int maxdisksize = param[MAXDISKSIZE]; - struct rlimit limit; - limit.rlim_cur = maxdisksize * 1024; - limit.rlim_max = int(maxdisksize * 1.1) * 1024; - setrlimit(RLIMIT_FSIZE, &limit); - } - - if (param.find(MAXRAMSIZE) != param.end()) { - int maxramsize = param[MAXRAMSIZE]; - struct rlimit limit; - limit.rlim_cur = maxramsize * 1024 * 1024; - limit.rlim_max = int(maxramsize * 1.1) * 1024 * 1024; - setrlimit(RLIMIT_AS, &limit); - } - */ - - - //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; - //int result = execv("/usr/bin/ssh", parmList); - //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); - //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); - - // On cree une session pour le fils de facon a ce qu'il ne soit pas - // detruit lorsque le shell se termine (le shell ouvre une session et - // tue tous les process appartenant a la session en quittant) - setsid(); - - - // On ferme les descripteurs de fichiers standards - //close(STDIN_FILENO); - //close(STDOUT_FILENO); - //close(STDERR_FILENO); - - - // On execute la commande du fils - execve(argv[0], argv, envp); - UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); - // No need to deallocate since nothing happens after a successful exec - - // Normalement on ne devrait jamais arriver ici - ofstream file_err("error.log"); - UNDER_LOCK( file_err << "Echec de l'appel a execve" << endl ); - - } catch (GenericException & e) { - - std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl; - } - - exit(99); - } - -#else - - BatchManager_Local::Process BatchManager_Local::ThreadAdapter::launchWin32ChildProcess() - { - Parametre param = _job.getParametre(); - Parametre::iterator it; - PROCESS_INFORMATION pi; - - try { - - // EXECUTABLE is MANDATORY, if missing, we throw an exception - 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"); - } - - // 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 << "*** 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 - // remote process. - // Note that if no environment is specified, we reuse the current environment. - Environnement env = _job.getEnvironnement(); - char * chNewEnv = NULL; - - if(env.size() > 0) { - chNewEnv = new char[4096]; - LPTSTR lpszCurrentVariable = chNewEnv; - for(Environnement::const_iterator it=env.begin() ; it!=env.end() ; it++) { - const string & key = (*it).first; - const string & value = (*it).second; - string envvar = key + "=" + value; - envvar.copy(lpszCurrentVariable, envvar.size()); - lpszCurrentVariable[envvar.size()] = '\0'; - lpszCurrentVariable += lstrlen(lpszCurrentVariable) + 1; - } - // Terminate the block with a NULL byte. - *lpszCurrentVariable = '\0'; - } - - - STARTUPINFO si; - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - // Copy the command to a non-const buffer - char * buffer = strdup(comstr.c_str()); - - // launch the new process - bool res = CreateProcess(NULL, buffer, NULL, NULL, FALSE, - CREATE_NO_WINDOW, chNewEnv, NULL, &si, &pi); - - if (buffer) free(buffer); - if (!res) throw RunTimeException("Error while creating new process"); - - CloseHandle(pi.hThread); - - } catch (GenericException & e) { - - std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl; - } - - return pi.hProcess; - } - -#endif - - - void BatchManager_Local::kill_child_on_exit(void * p_pid) - { -#ifndef WIN32 - //TODO: porting of following functionality - pid_t child = * static_cast(p_pid); - - // On tue le fils - kill(child, SIGTERM); - - // Nota : on pourrait aussi faire a la suite un kill(child, SIGKILL) - // mais cette option n'est pas implementee pour le moment, car il est - // preferable de laisser le process fils se terminer normalement et seul. -#endif - } - - void BatchManager_Local::delete_on_exit(void * arg) - { - ThreadAdapter * p_ta = static_cast(arg); - delete p_ta; - } - - void BatchManager_Local::setFailedOnCancel(void * arg) - { - ThreadAdapter * p_ta = static_cast(arg); - pthread_mutex_lock(&p_ta->getBatchManager()._threads_mutex); - p_ta->getBatchManager()._threads[p_ta->getId()].param[STATE] = FAILED; - pthread_mutex_unlock(&p_ta->getBatchManager()._threads_mutex); - - // Unlock the master thread. From here, the batch manager instance should not be used. - pthread_cond_signal(&p_ta->getBatchManager()._threadSyncCondition); - } - -} diff --git a/src/Local/Batch_BatchManager_Local.hxx b/src/Local/Batch_BatchManager_Local.hxx deleted file mode 100644 index fcc2f90..0000000 --- a/src/Local/Batch_BatchManager_Local.hxx +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright (C) 2007-2012 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.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 - * - * 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 "Batch_CommunicationProtocol.hxx" - -#ifdef WIN32 -#include -#endif - -#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_BatchManager.hxx" - -namespace Batch { - - class FactBatchManager; - - /*! - * This class defines a local pseudo batch manager that can launch jobs locally or on a remote - * machine with SSH or RSH. This class is NOT thread-safe. - */ - class BATCH_EXPORT BatchManager_Local : virtual public BatchManager - { - private: - typedef int Id; -#ifdef WIN32 - typedef HANDLE Process; -#else - typedef pid_t Process; -#endif - friend class ThreadAdapter; - class ThreadAdapter{ - public: - ThreadAdapter(BatchManager_Local & bm, const Job_Local & job, Id id); - static void * run(void * arg); - BatchManager_Local & getBatchManager() const { return _bm; }; - Id getId() const { return _id; }; - - protected: - BatchManager_Local & _bm; - const Job_Local _job; - Id _id; - - private: - void pere(Process child); -#ifndef WIN32 - void fils(); -#else - Process launchWin32ChildProcess(); -#endif - - }; - - enum Commande { - NOP = 0, - HOLD, - RELEASE, - TERM, - KILL, - ALTER - }; - - struct Child { - pthread_t thread_id; - std::queue > command_queue; - pid_t pid; - int exit_code; - bool hasFailed; - Parametre param; - Environnement env; - }; - - - - public: - // Constructeur et destructeur - BatchManager_Local(const FactBatchManager * parent, - const char * host="localhost", - CommunicationProtocolType protocolType = SSH); // 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 - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - int _connect; // Local connect id - pthread_mutex_t _threads_mutex; - std::map _threads; - - const CommunicationProtocol & _protocol; - - // Methode qui renvoie la commande a executer - std::vector exec_command(const Parametre & param) const; - - private: - static void kill_child_on_exit(void * p_pid); - static void delete_on_exit(void * arg); - static void setFailedOnCancel(void * arg); - pthread_cond_t _threadSyncCondition; - Id _idCounter; - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/Local/Batch_FactBatchManager_Local.cxx b/src/Local/Batch_FactBatchManager_Local.cxx deleted file mode 100644 index 16f6f47..0000000 --- a/src/Local/Batch_FactBatchManager_Local.cxx +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (C) 2007-2012 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.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * 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 "Batch_BatchManager_Local.hxx" -#include "Batch_FactBatchManager_Local.hxx" - -namespace Batch { - -#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(const char * name, - CommunicationProtocolType protocolType) - : FactBatchManager(name), - _protocolType(protocolType) - { - // Nothing to do - } - - // Destructeur - FactBatchManager_Local::~FactBatchManager_Local() - { - // Nothing to do - } - - // Functor - 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 deleted file mode 100644 index 4b01a4b..0000000 --- a/src/Local/Batch_FactBatchManager_Local.hxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * 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 "Batch_CommunicationProtocol.hxx" - -namespace Batch { - - class FactBatchManager_Local : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_Local(const char * name, CommunicationProtocolType protocolType); - virtual ~FactBatchManager_Local(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - CommunicationProtocolType _protocolType; - - private: - - }; - -} - -#endif diff --git a/src/Local/Batch_IOMutex.cxx b/src/Local/Batch_IOMutex.cxx deleted file mode 100644 index 37d9770..0000000 --- a/src/Local/Batch_IOMutex.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * IOMutex.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#include "Batch_IOMutex.hxx" - -namespace Batch { - - pthread_mutex_t IOMutex = PTHREAD_MUTEX_INITIALIZER; - -} diff --git a/src/Local/Batch_IOMutex.hxx b/src/Local/Batch_IOMutex.hxx deleted file mode 100644 index b7e34ce..0000000 --- a/src/Local/Batch_IOMutex.hxx +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * IOMutex.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#ifndef _IOMUTEX_H_ -#define _IOMUTEX_H_ - -#include - -#define LOCK_IO { pthread_mutex_lock(&Batch::IOMutex) ; } -#define UNLOCK_IO { pthread_mutex_unlock(&Batch::IOMutex) ; } -#define UNDER_LOCK(statement) { LOCK_IO ; { statement ; } ; UNLOCK_IO ; } - -namespace Batch { - - extern pthread_mutex_t IOMutex; - -} - -#endif diff --git a/src/Local/Batch_JobInfo_Local.cxx b/src/Local/Batch_JobInfo_Local.cxx deleted file mode 100644 index 3a742bb..0000000 --- a/src/Local/Batch_JobInfo_Local.cxx +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_Local.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 21 09:42:06 2003 - * Projet : Salome 2 - * - */ - -#include -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_JobInfo_Local.hxx" - -namespace Batch { - - // Constructeurs - JobInfo_Local::JobInfo_Local(const Parametre & param, const Environnement & env) : - JobInfo(param, env) - { - // Nothing to do - } - - - // Destructeur - JobInfo_Local::~JobInfo_Local() - { - // Nothing to do - } - - -} diff --git a/src/Local/Batch_JobInfo_Local.hxx b/src/Local/Batch_JobInfo_Local.hxx deleted file mode 100644 index f5f1160..0000000 --- a/src/Local/Batch_JobInfo_Local.hxx +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_Local.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 21 09:42:05 2003 - * Projet : Salome 2 - * - */ - -#ifndef _JOBINFO_LOCAL_H_ -#define _JOBINFO_LOCAL_H_ - -#include -#include "Batch_JobInfo.hxx" - -namespace Batch { - - class JobInfo_Local : public JobInfo - { - public: - // Constructeurs et destructeur - JobInfo_Local() {}; - JobInfo_Local(const Parametre & param, const Environnement & env); - virtual ~JobInfo_Local(); - - // Constructeur par recopie - JobInfo_Local(const JobInfo_Local & jinfo) : JobInfo(jinfo) {}; - - - protected: - - private: - - }; - -} - -#endif diff --git a/src/Local/Batch_Job_Local.cxx b/src/Local/Batch_Job_Local.cxx deleted file mode 100644 index 474c6df..0000000 --- a/src/Local/Batch_Job_Local.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job_Local.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#ifndef WIN32 -#include -#endif - -#include "Batch_Constants.hxx" -#include "Batch_Job_Local.hxx" - -using namespace std; - -namespace Batch { - - // Constructeur - Job_Local::Job_Local(const Job & job) : - _command(), _param(job.getParametre()), _env(job.getEnvironnement()) - { - // On positionne le nom du EXECUTIONHOST a "localhost" s'il n'est pas precise - if ( _param.find(EXECUTIONHOST) == _param.end() ) { - _param[EXECUTIONHOST] = "localhost"; - } - - // On convertit les objets Parametre et Environnement en liste chainee d'attributs + operateur - addEnvironnement( _env ); - addParametre ( _param ); - - } - - - // Destructeur - Job_Local::~Job_Local() - { - } - - - void Job_Local::addParametre(const Parametre & P) - { - // En dernier, on ajoute le chemin complet de la commande - _command += P[EXECUTABLE].str(); - } - - - void Job_Local::addEnvironnement(const Environnement & E) - { - for(Environnement::const_iterator it=E.begin(); it != E.end(); it++) { - string variable = (*it).first; - string value = (*it).second; - - // On remplace toutes les occurences de single-quote par backslash-single-quote - for(size_t pos=0; pos < value.size(); pos++) { - pos = value.find("'", pos); - if ( pos > value.size() ) break; - value.replace(pos, 1, "\'"); - } - _command += variable + "='" + value + "' "; - } - } - - string Job_Local::getCommand(void) const { - return _command; - } - - - // Retourne l'objet Parametre - Parametre Job_Local::getParametre() const - { - return _param; - } - - // Retourne l'objet Environnement - Environnement Job_Local::getEnvironnement() const - { - return _env; - } - - -} diff --git a/src/Local/Batch_Job_Local.hxx b/src/Local/Batch_Job_Local.hxx deleted file mode 100644 index a07f115..0000000 --- a/src/Local/Batch_Job_Local.hxx +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job_Local.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#ifndef _JOB_LOCAL_H_ -#define _JOB_LOCAL_H_ - -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_Job.hxx" - -namespace Batch { - - class Job_Local - { - public: - // Constructeur et destructeur - Job_Local(const Job & job); - virtual ~Job_Local(); - - // Retourne la commande _command - virtual std::string getCommand(void) const; - - // Retourne l'objet Parametre - virtual Parametre getParametre() const; - - // Retourne l'objet Environnement - virtual Environnement getEnvironnement() const; - - - protected: - std::string _command; - Parametre _param; - Environnement _env; - - private: - void addParametre(const Parametre & P); - void addEnvironnement(const Environnement & E); - - }; - -} - -#endif diff --git a/src/Local/CMakeLists.txt b/src/Local/CMakeLists.txt index 93f746c..7d4d023 100644 --- a/src/Local/CMakeLists.txt +++ b/src/Local/CMakeLists.txt @@ -20,15 +20,25 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST Local/Batch_BatchManager_Local - Local/Batch_FactBatchManager_Local - Local/Batch_IOMutex - Local/Batch_Job_Local - Local/Batch_JobInfo_Local +SET(CLASS_LIST Local/BatchManager_Local + Local/FactBatchManager_Local + Local/IOMutex + Local/Job_Local + Local/JobInfo_Local ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) IF (TEST_ENABLED) - add_subdirectory(Test) + IF (HAS_SH) + ADD_TEST(LOCAL_SH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SH) + ENDIF (HAS_SH) + + IF (HAS_SSH) + ADD_TEST(LOCAL_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL SSH) + ENDIF (HAS_SSH) + + IF (HAS_RSH) + ADD_TEST(LOCAL_RSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager LOCAL RSH) + ENDIF (HAS_RSH) ENDIF (TEST_ENABLED) diff --git a/src/Local/FactBatchManager_Local.cxx b/src/Local/FactBatchManager_Local.cxx new file mode 100644 index 0000000..935c2a9 --- /dev/null +++ b/src/Local/FactBatchManager_Local.cxx @@ -0,0 +1,61 @@ +// Copyright (C) 2007-2012 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.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * 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 "BatchManager_Local.hxx" +#include "FactBatchManager_Local.hxx" + +namespace Batch { + + static FactBatchManager_Local sFBM_Local; + + FactBatchManager_Local::FactBatchManager_Local() + : FactBatchManager("LOCAL") + { + } + + FactBatchManager_Local::~FactBatchManager_Local() + { + } + + BatchManager * FactBatchManager_Local::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpi) const + { + return new BatchManager_Local(this, hostname, username, protocolType, mpi); + } + +} diff --git a/src/Local/FactBatchManager_Local.hxx b/src/Local/FactBatchManager_Local.hxx new file mode 100644 index 0000000..09fffff --- /dev/null +++ b/src/Local/FactBatchManager_Local.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * 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 "FactBatchManager.hxx" +#include "CommunicationProtocol.hxx" + +namespace Batch { + + class FactBatchManager_Local : public FactBatchManager + { + public: + + FactBatchManager_Local(); + virtual ~FactBatchManager_Local(); + + virtual BatchManager * operator() (const char * hostname, + const char * username = "", + CommunicationProtocolType protocolType = SSH, + const char * mpi = "nompi") const; + + }; + +} + +#endif diff --git a/src/Local/IOMutex.cxx b/src/Local/IOMutex.cxx new file mode 100644 index 0000000..7991942 --- /dev/null +++ b/src/Local/IOMutex.cxx @@ -0,0 +1,38 @@ +// Copyright (C) 2007-2012 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 +// +/* + * IOMutex.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#include "IOMutex.hxx" + +namespace Batch { + + pthread_mutex_t IOMutex = PTHREAD_MUTEX_INITIALIZER; + +} diff --git a/src/Local/IOMutex.hxx b/src/Local/IOMutex.hxx new file mode 100644 index 0000000..b7e34ce --- /dev/null +++ b/src/Local/IOMutex.hxx @@ -0,0 +1,47 @@ +// Copyright (C) 2007-2012 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 +// +/* + * IOMutex.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#ifndef _IOMUTEX_H_ +#define _IOMUTEX_H_ + +#include + +#define LOCK_IO { pthread_mutex_lock(&Batch::IOMutex) ; } +#define UNLOCK_IO { pthread_mutex_unlock(&Batch::IOMutex) ; } +#define UNDER_LOCK(statement) { LOCK_IO ; { statement ; } ; UNLOCK_IO ; } + +namespace Batch { + + extern pthread_mutex_t IOMutex; + +} + +#endif diff --git a/src/Local/JobInfo_Local.cxx b/src/Local/JobInfo_Local.cxx new file mode 100644 index 0000000..988d6cd --- /dev/null +++ b/src/Local/JobInfo_Local.cxx @@ -0,0 +1,54 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 21 09:42:06 2003 + * Projet : Salome 2 + * + */ + +#include +#include "Parametre.hxx" +#include "Environnement.hxx" +#include "JobInfo_Local.hxx" + +namespace Batch { + + // Constructeurs + JobInfo_Local::JobInfo_Local(const Parametre & param, const Environnement & env) : + JobInfo(param, env) + { + // Nothing to do + } + + + // Destructeur + JobInfo_Local::~JobInfo_Local() + { + // Nothing to do + } + + +} diff --git a/src/Local/JobInfo_Local.hxx b/src/Local/JobInfo_Local.hxx new file mode 100644 index 0000000..4534b8f --- /dev/null +++ b/src/Local/JobInfo_Local.hxx @@ -0,0 +1,60 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 21 09:42:05 2003 + * Projet : Salome 2 + * + */ + +#ifndef _JOBINFO_LOCAL_H_ +#define _JOBINFO_LOCAL_H_ + +#include +#include "JobInfo.hxx" + +namespace Batch { + + class JobInfo_Local : public JobInfo + { + public: + // Constructeurs et destructeur + JobInfo_Local() {}; + JobInfo_Local(const Parametre & param, const Environnement & env); + virtual ~JobInfo_Local(); + + // Constructeur par recopie + JobInfo_Local(const JobInfo_Local & jinfo) : JobInfo(jinfo) {}; + + + protected: + + private: + + }; + +} + +#endif diff --git a/src/Local/Job_Local.cxx b/src/Local/Job_Local.cxx new file mode 100644 index 0000000..f7109a7 --- /dev/null +++ b/src/Local/Job_Local.cxx @@ -0,0 +1,102 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Job_Local.cxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#include +#include +#ifndef WIN32 +#include +#endif + +#include "Constants.hxx" +#include "Job_Local.hxx" + +using namespace std; + +namespace Batch { + + // Constructeur + Job_Local::Job_Local(const Job & job) : + _command(), _param(job.getParametre()), _env(job.getEnvironnement()) + { + // On convertit les objets Parametre et Environnement en liste chainee d'attributs + operateur + addEnvironnement( _env ); + addParametre ( _param ); + } + + + // Destructeur + Job_Local::~Job_Local() + { + } + + + void Job_Local::addParametre(const Parametre & P) + { + // En dernier, on ajoute le chemin complet de la commande + _command += P[EXECUTABLE].str(); + } + + + void Job_Local::addEnvironnement(const Environnement & E) + { + for(Environnement::const_iterator it=E.begin(); it != E.end(); it++) { + string variable = (*it).first; + string value = (*it).second; + + // On remplace toutes les occurences de single-quote par backslash-single-quote + for(size_t pos=0; pos < value.size(); pos++) { + pos = value.find("'", pos); + if ( pos > value.size() ) break; + value.replace(pos, 1, "\'"); + } + _command += variable + "='" + value + "' "; + } + } + + string Job_Local::getCommand(void) const { + return _command; + } + + + // Retourne l'objet Parametre + Parametre Job_Local::getParametre() const + { + return _param; + } + + // Retourne l'objet Environnement + Environnement Job_Local::getEnvironnement() const + { + return _env; + } + + +} diff --git a/src/Local/Job_Local.hxx b/src/Local/Job_Local.hxx new file mode 100644 index 0000000..d2c2e25 --- /dev/null +++ b/src/Local/Job_Local.hxx @@ -0,0 +1,71 @@ +// Copyright (C) 2007-2012 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 +// +/* + * Job_Local.hxx : + * + * Auteur : Ivan DUTKA-MALEN - EDF R&D + * Mail : mailto:ivan.dutka-malen@der.edf.fr + * Date : Fri Nov 14 11:00:39 2003 + * Projet : Salome 2 + * + */ + +#ifndef _JOB_LOCAL_H_ +#define _JOB_LOCAL_H_ + +#include "Parametre.hxx" +#include "Environnement.hxx" +#include "Job.hxx" + +namespace Batch { + + class Job_Local + { + public: + // Constructeur et destructeur + Job_Local(const Job & job); + virtual ~Job_Local(); + + // Retourne la commande _command + virtual std::string getCommand(void) const; + + // Retourne l'objet Parametre + virtual Parametre getParametre() const; + + // Retourne l'objet Environnement + virtual Environnement getEnvironnement() const; + + + protected: + std::string _command; + Parametre _param; + Environnement _env; + + private: + void addParametre(const Parametre & P); + void addEnvironnement(const Environnement & E); + + }; + +} + +#endif diff --git a/src/Local/Test/CMakeLists.txt b/src/Local/Test/CMakeLists.txt deleted file mode 100644 index 4ff10b4..0000000 --- a/src/Local/Test/CMakeLists.txt +++ /dev/null @@ -1,62 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# 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-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) - -# set the include directories -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 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/Exec_Test.cxx b/src/Local/Test/Exec_Test.cxx deleted file mode 100644 index 8ae8d65..0000000 --- a/src/Local/Test/Exec_Test.cxx +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Exec_Test.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : May 2009 - * - */ - -#include -#include -#include -#include - -using namespace std; - -int main(int argc, char** argv) -{ - if (argc != 4) { - cerr << "Exec_Test expects three parameters, usage: Exec_Test " << endl; - return 1; - } - - const char * scriptAFileName = argv[1]; - const char * scriptBFileName = argv[2]; - const char * resultFileName = argv[3]; - - ifstream scriptAStream(scriptAFileName); - std::string line; - int a = 0; - while (getline(scriptAStream, line)) { - if (line.compare(0, 2, string("a=")) == 0) { - a = strtol(line.substr(2).c_str(), NULL, 10); - } - } - scriptAStream.close(); - if (a == 0) { - cerr << "Exec_Test couldn't parse value \"a\" in " << scriptAFileName << endl; - return 1; - } - - ifstream scriptBStream(scriptBFileName); - int b = 0; - while (getline(scriptBStream, line)) { - if (line.compare(0, 2, string("b=")) == 0) { - b = strtol(line.substr(2).c_str(), NULL, 10); - } - } - scriptBStream.close(); - if (b == 0) { - cerr << "Exec_Test couldn't parse value \"b\" in " << scriptBFileName << endl; - return 1; - } - - int c = a * b; - ofstream resultStream(resultFileName); - resultStream << "c = " << c; - resultStream.close(); - return 0; -} diff --git a/src/Local/Test/Test_Local_RSH.cxx b/src/Local/Test/Test_Local_RSH.cxx deleted file mode 100644 index 83622c3..0000000 --- a/src/Local/Test/Test_Local_RSH.cxx +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2007-2012 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_Local_RSH.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : April 2009 - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -int main(int argc, char** argv) -{ - cout << "*******************************************************************************************" << endl; - cout << "This program tests the local batch submission based on RSH. Passwordless RSH authentication" << endl; - cout << "must be used for this test to pass (this can be configured with the .rhosts file)." << endl; - cout << "*******************************************************************************************" << endl; - - // eventually remove any previous result - remove("result.txt"); - - try { - // Parse the test configuration file - SimpleParser parser; - parser.parseTestConfigFile(); - const string & workdir = parser.getValue("TEST_LOCAL_RSH_WORK_DIR"); - const string & exechost = parser.getValue("TEST_LOCAL_RSH_EXECUTION_HOST"); - const string & user = parser.getValue("TEST_LOCAL_RSH_USER"); - int timeout = parser.getValueAsInt("TEST_LOCAL_RSH_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "source copied-test-script.sh"; - p[NAME] = "Test_Local_RSH"; - p[WORKDIR] = workdir; - p[INFILE] = Couple("seta.sh", "copied-seta.sh"); - p[INFILE] += Couple("setb.sh", "copied-setb.sh"); - p[INFILE] += Couple("test-script.sh", "copied-test-script.sh"); - p[OUTFILE] = Couple("result.txt", "orig-result.txt"); - p[EXECUTIONHOST] = exechost; - p[USER] = user; - job.setParametre(p); - // ... and its environment - Environnement e; - job.setEnvironnement(e); - cout << job << endl; - - // Get the catalog - BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); - - // 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 - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state != FINISHED && state != FAILED) { - cerr << "Error: Job not finished after timeout" << endl; - return 1; - } - - cout << "Job " << jobid.__repr__() << " is done" << endl; - - } 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/Local/Test/Test_Local_SH.cxx b/src/Local/Test/Test_Local_SH.cxx deleted file mode 100644 index 5c3c2e7..0000000 --- a/src/Local/Test/Test_Local_SH.cxx +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright (C) 2007-2012 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_Local_SH.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : April 2009 - * - */ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -using namespace std; -using namespace Batch; - -int main(int argc, char** argv) -{ - cout << "*******************************************************************************************" << endl; - cout << "This program tests the local batch submission based on SH. No specific configuration is" << endl; - cout << "needed for 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 & workdir = parser.getValue("TEST_LOCAL_SH_WORK_DIR"); - int timeout = parser.getValueAsInt("TEST_LOCAL_SH_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = string("./copied-") + EXEC_TEST_NAME; - p[ARGUMENTS] = "copied-seta.sh"; - p[ARGUMENTS] += "copied-setb.sh"; - p[ARGUMENTS] += "orig-result.txt"; - p[NAME] = "Test_Local_SH"; - p[WORKDIR] = workdir; - p[INFILE] = Couple("seta.sh", "copied-seta.sh"); - p[INFILE] += Couple("setb.sh", "copied-setb.sh"); - p[INFILE] += Couple(EXEC_TEST_NAME, string("copied-") + EXEC_TEST_NAME); - p[OUTFILE] = Couple("result.txt", "orig-result.txt"); - job.setParametre(p); - // ... and its environment - Environnement e; - job.setEnvironnement(e); - cout << job << endl; - - // Get the catalog - BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); - - // 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 - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state != FINISHED && state != FAILED) { - cerr << "Error: Job not finished after timeout" << endl; - return 1; - } - - cout << "Job " << jobid.__repr__() << " is done" << endl; - - } 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/Local/Test/Test_Local_SSH.cxx b/src/Local/Test/Test_Local_SSH.cxx deleted file mode 100644 index b82740e..0000000 --- a/src/Local/Test/Test_Local_SSH.cxx +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright (C) 2007-2012 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_Local_SSH.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : April 2009 - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -int main(int argc, char** argv) -{ - cout << "*******************************************************************************************" << endl; - cout << "This program tests the local batch submission based on SSH. Passwordless SSH authentication" << endl; - cout << "must be used for this test to pass (this can be configured with ssh-agent for instance)." << endl; - cout << "*******************************************************************************************" << endl; - - // eventually remove any previous result - remove("result.txt"); - - try { - // Parse the test configuration file - SimpleParser parser; - parser.parseTestConfigFile(); - const string & workdir = parser.getValue("TEST_LOCAL_SSH_WORK_DIR"); - const string & exechost = parser.getValue("TEST_LOCAL_SSH_EXECUTION_HOST"); - const string & user = parser.getValue("TEST_LOCAL_SSH_USER"); - int timeout = parser.getValueAsInt("TEST_LOCAL_SSH_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "source copied-test-script.sh"; - p[NAME] = "Test_Local_SSH"; - p[WORKDIR] = workdir; - p[INFILE] = Couple("seta.sh", "copied-seta.sh"); - p[INFILE] += Couple("setb.sh", "copied-setb.sh"); - p[INFILE] += Couple("test-script.sh", "copied-test-script.sh"); - p[OUTFILE] = Couple("result.txt", "orig-result.txt"); - p[EXECUTIONHOST] = exechost; - p[USER] = user; - 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 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 - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state != FINISHED && state != FAILED) { - cerr << "Error: Job not finished after timeout" << endl; - return 1; - } - - cout << "Job " << jobid.__repr__() << " is done" << endl; - - } 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/Local/Test/Test_Local_config.h.in b/src/Local/Test/Test_Local_config.h.in deleted file mode 100644 index 4b32fe6..0000000 --- a/src/Local/Test/Test_Local_config.h.in +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2007-2012 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 -// - -#define EXEC_TEST_NAME "${EXEC_TEST_NAME}" diff --git a/src/Local/Test/seta.sh b/src/Local/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/Local/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/Local/Test/setb.sh b/src/Local/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/Local/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/Local/Test/test-script.sh b/src/Local/Test/test-script.sh deleted file mode 100755 index afd53de..0000000 --- a/src/Local/Test/test-script.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -source copied-seta.sh -source copied-setb.sh - -c=`expr $a "*" $b` - -echo "c = $c" > orig-result.txt diff --git a/src/PBS/BatchManager_PBS.cxx b/src/PBS/BatchManager_PBS.cxx new file mode 100644 index 0000000..ae18c23 --- /dev/null +++ b/src/PBS/BatchManager_PBS.cxx @@ -0,0 +1,253 @@ +// Copyright (C) 2007-2012 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_PBS.cxx : emulation of PBS client + * + * Auteur : Bernard SECHER - CEA DEN, André RIBES - EDF R&D + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include +#include + +#include +#include +#include + +#include "BatchManager_PBS.hxx" +#include "JobInfo_PBS.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_PBS::BatchManager_PBS(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + // Destructeur + BatchManager_PBS::~BatchManager_PBS() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_PBS::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const std::string workDir = params[WORKDIR]; + + // export input files on cluster + exportInputFiles(job); + + // build batch script for job + string scriptFile = buildSubmissionScript(job); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; qsub " + scriptFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // normally output contains only id of submitted job, we just need to remove the final \n + string jobref = output.substr(0, output.size() - 1); + JobId id(this, jobref); + + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_PBS::deleteJob(const JobId & jobid) + { + int status; + int ref; + istringstream iss(jobid.getReference()); + iss >> ref; + + // define command to delete batch + string subCommand = string("qdel ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + status = system(command.c_str()); + if (status) + throw RunTimeException("Error of connection on remote host"); + + LOG("jobId = " << ref << "killed"); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_PBS::queryJob(const JobId & jobid) + { + int id; + istringstream iss(jobid.getReference()); + iss >> id; + + // define command to query batch + string subCommand = string("qstat -f ") + iss.str(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + if(status && status != 153 && status != 256*153) + throw RunTimeException("Error of connection on remote host"); + + JobInfo_PBS ji = JobInfo_PBS(id, output); + return ji; + } + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_PBS::isRunning(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_PBS::isRunning"); + } + + std::string BatchManager_PBS::buildSubmissionScript(const Job & job) + { + Parametre params = job.getParametre(); + Environnement env = job.getEnvironnement(); + + // Mandatory parameters + string workDir; + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); + string fileToExecute; + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); + + // Optional parameters + int nbproc = 1; + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + int nbprocpernode = 1; + if (params.find(NBPROCPERNODE) != params.end()) + nbprocpernode = params[NBPROCPERNODE]; + int edt = 0; + if (params.find(MAXWALLTIME) != params.end()) + edt = params[MAXWALLTIME]; + int mem = 0; + if (params.find(MAXRAMSIZE) != params.end()) + mem = params[MAXRAMSIZE]; + string queue = ""; + if (params.find(QUEUE) != params.end()) + queue = params[QUEUE].str(); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + std::string TmpFileName = Utils::createAndOpenTemporaryFile("PBS-script", tempOutputFile); + + tempOutputFile << "#! /bin/sh -f" << endl; + if (params.find(NAME) != params.end()) { + tempOutputFile << "#PBS -N " << params[NAME] << endl; + } + + if (nbproc > 0) + { + int nb_full_nodes = nbproc / nbprocpernode; + int nb_proc_on_last_node = nbproc % nbprocpernode; + + // In exclusive mode, we reserve all procs on the nodes + if (params.find(EXCLUSIVE) != params.end() && params[EXCLUSIVE] && nb_proc_on_last_node > 0) { + nb_full_nodes += 1; + nb_proc_on_last_node = 0; + } + + tempOutputFile << "#PBS -l nodes="; + + // Full nodes + if (nb_full_nodes > 0) { + tempOutputFile << nb_full_nodes << ":ppn=" << nbprocpernode; + if (nb_proc_on_last_node > 0) { + tempOutputFile << "+"; + } + } + + // Partly reserved node + if (nb_proc_on_last_node > 0) { + tempOutputFile << "1:ppn=" << nb_proc_on_last_node; + } + + tempOutputFile << endl; + } + if (queue != "") + tempOutputFile << "#PBS -q " << queue << endl; + if( edt > 0 ) + tempOutputFile << "#PBS -l walltime=" << edt*60 << endl; + if( mem > 0 ) + tempOutputFile << "#PBS -l mem=" << mem << "MB" << endl; + tempOutputFile << "#PBS -o " << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "#PBS -e " << workDir << "/logs/error.log." << rootNameToExecute << endl; + + // Define environment for the job + if (!env.empty()) { + tempOutputFile << "#PBS -v "; + Environnement::const_iterator iter; + for (iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << iter->first << "=" << iter->second << ","; + } + tempOutputFile << endl; + } + + // Define NODEFILE + tempOutputFile << "export LIBBATCH_NODEFILE=$PBS_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl; + tempOutputFile << "./" + fileNameToExecute << endl; + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << TmpFileName.c_str()); + + string remoteFileName = rootNameToExecute + "_Batch.sh"; + int status = _protocol.copyFile(TmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw RunTimeException("Error of connection on remote host, cannot copy batch submission file"); + return remoteFileName; + } +} diff --git a/src/PBS/BatchManager_PBS.hxx b/src/PBS/BatchManager_PBS.hxx new file mode 100644 index 0000000..d0e9c3f --- /dev/null +++ b/src/PBS/BatchManager_PBS.hxx @@ -0,0 +1,78 @@ +// Copyright (C) 2007-2012 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_PBS.hxx : emulation of PBS client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#ifndef _BATCHMANAGER_EPBS_H_ +#define _BATCHMANAGER_EPBS_H_ + +#include "Defines.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_PBS : public BatchManager + { + public: + // Constructeur et destructeur + BatchManager_PBS(const FactBatchManager * parent, const char * host="localhost", + const char * username="", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); + virtual ~BatchManager_PBS(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + protected: + std::string buildSubmissionScript(const Job & job); + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/PBS/Batch_BatchManager_PBS.cxx b/src/PBS/Batch_BatchManager_PBS.cxx deleted file mode 100644 index 2836571..0000000 --- a/src/PBS/Batch_BatchManager_PBS.cxx +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (C) 2007-2012 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_PBS.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 - * - */ - -extern "C" { -#include -#include -} -#include -#include -#include -#include -//#include "MEDMEM_STRING.hxx" -#include "Batch_BatchManager_PBS.hxx" -using namespace std; - -namespace Batch { - - // Recupere le nom du serveur par defaut -// string BatchManager_PBS::getDefaultServer() { -// string server_name = "localhost"; - -// const char * server_name_path = "@openpbsspooldir@/server_name"; -// ifstream server_name_file(server_name_path); -// if (server_name_file) { -// server_name_file >> server_name; -// server_name_file.close(); -// } - -// return server_name; -// } - - // Constructeur -// BatchManager_PBS::BatchManager_PBS() throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(BatchManager_PBS::getDefaultServer()) -// { -// // On se connecte au serveur PBS -// _connect = pbs_connect(const_cast< char * >(_hostname.c_str())); -// if (_connect < 0) { // si erreur -// char * errmsg = pbs_geterrmsg(_connect); -// string msg = "PBS Server on host \""; -// msg += _hostname; -// msg += "\" : "; -// msg += errmsg ? errmsg : "Reason unknown"; -// throw ConnexionFailureException(msg.c_str()); -// } -// } - - // Constructeur -// BatchManager_PBS::BatchManager_PBS(string host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(host) -// { -// // On se connecte au serveur PBS -// _connect = pbs_connect(const_cast< char * >(_hostname.c_str())); -// if (_connect < 0) { // si erreur -// char * errmsg = pbs_geterrmsg(_connect); -// string msg = "PBS Server on host \""; -// msg += _hostname; -// msg += "\" : "; -// msg += errmsg ? errmsg : "Reason unknown"; -// throw ConnexionFailureException(msg.c_str()); -// } -// } - BatchManager_PBS::BatchManager_PBS(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager(parent, host) - { - // On se connecte au serveur PBS - _connect = pbs_connect(const_cast< char * >(_hostname.c_str())); - if (_connect < 0) { // si erreur - throw ConnexionFailureException(getErrorMessage("connect").c_str()); - } - } - - // Destructeur - BatchManager_PBS::~BatchManager_PBS() - { - // On se deconnecte du serveur PBS - int rc = pbs_disconnect(_connect); - if (rc < 0) { // si erreur - throw ConnexionFailureException(getErrorMessage("disconnect").c_str()); - } - } - - string BatchManager_PBS::getErrorMessage(const char * operation) const - { - char * msg = pbs_geterrmsg(_connect); - stringstream sstr; - sstr << "PBS " << operation << " error (host \"" << _hostname << "\"): "; - if (msg != NULL) { - sstr << msg; - } else { - sstr << "code = " << pbs_errno << " (" << pbse_to_txt(pbs_errno) << ")"; - } - return sstr.str(); - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_PBS::submitJob(const Job & job) - { - Job_PBS jobpbs = job; - char * ref = pbs_submit(_connect, - jobpbs.getAttributesOP(), - jobpbs.getScript(), - jobpbs.getDestination(), - NULL); - if (!ref) { // si erreur - throw APIInternalFailureException(getErrorMessage("submit").c_str()); - } - - JobId id(this, string(ref)); - free(ref); - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_PBS::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_PBS::deleteJob(const JobId & jobid) - { - char * ref = const_cast< char * >(jobid.getReference().c_str()); - int rc = pbs_deljob(_connect, ref, 0); - if (rc) { // si erreur - throw APIInternalFailureException(getErrorMessage("deljob").c_str()); - } - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_PBS::holdJob(const JobId & jobid) - { - char * ref = const_cast< char * >(jobid.getReference().c_str()); - int rc = pbs_holdjob(_connect, ref, const_cast< char * >(USER_HOLD), 0); - if (rc) { // si erreur - throw APIInternalFailureException(getErrorMessage("holdjob").c_str()); - } - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_PBS::releaseJob(const JobId & jobid) - { - char * ref = const_cast< char * >(jobid.getReference().c_str()); - int rc = pbs_rlsjob(_connect, ref, const_cast< char * >(USER_HOLD), 0); - if (rc) { // si erreur - throw APIInternalFailureException(getErrorMessage("rlsjob").c_str()); - } - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - Job job(param, env); - Job_PBS jobpbs(job); - - char * ref = const_cast< char * >(jobid.getReference().c_str()); - int rc = pbs_alterjob(_connect, - ref, - jobpbs.getAttributes(), - NULL); - if (rc) { // si erreur - throw APIInternalFailureException(getErrorMessage("alterjob").c_str()); - } - - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_PBS::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_PBS::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_PBS::queryJob(const JobId & jobid) - { - char * id = const_cast< char * >(jobid.getReference().c_str()); - JobInfo_PBS ji = JobInfo_PBS(pbs_statjob(_connect, id, 0, 0), true); - return ji; - } - - - -} diff --git a/src/PBS/Batch_BatchManager_PBS.hxx b/src/PBS/Batch_BatchManager_PBS.hxx deleted file mode 100644 index 5419580..0000000 --- a/src/PBS/Batch_BatchManager_PBS.hxx +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2007-2012 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_PBS.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_PBS_H_ -#define _BATCHMANAGER_PBS_H_ - -#include "Batch_Defines.hxx" - -#include "Batch_Job.hxx" -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_JobInfo_PBS.hxx" -#include "Batch_Job_PBS.hxx" -#include "Batch_InvalidArgumentException.hxx" -#include "Batch_ConnexionFailureException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_NotYetImplementedException.hxx" -#include "Batch_BatchManager.hxx" - -namespace Batch { - - class Job; - class JobId; - class JobInfo; - class FactBatchManager; - - class BATCH_EXPORT BatchManager_PBS : public BatchManager - { - public: - // Constructeur et destructeur - //BatchManager_PBS() throw(InvalidArgumentException,ConnexionFailureException); // connexion au serveur par defaut - //BatchManager_PBS(std::string host) throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - BatchManager_PBS(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host - virtual ~BatchManager_PBS(); - - // Recupere le nom du serveur par defaut - // static std::string BatchManager_PBS::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - - protected: - std::string getErrorMessage(const char * operation) const; - - int _connect; // PBS connect id - - private: - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const std::string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/PBS/Batch_BatchManager_ePBS.cxx b/src/PBS/Batch_BatchManager_ePBS.cxx deleted file mode 100644 index 2fbfb9e..0000000 --- a/src/PBS/Batch_BatchManager_ePBS.cxx +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (C) 2007-2012 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_ePBS.cxx : emulation of PBS client - * - * Auteur : Bernard SECHER - CEA DEN, André RIBES - EDF R&D - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include -#include - -#include -#include - -#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 * username, - CommunicationProtocolType protocolType, const char * mpiImpl, - int nb_proc_per_node) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl), - _nb_proc_per_node(nb_proc_per_node) - { - // Nothing to do - } - - // Destructeur - BatchManager_ePBS::~BatchManager_ePBS() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_ePBS::submitJob(const Job & job) - { - Parametre params = job.getParametre(); - const std::string workDir = params[WORKDIR]; - - // export input files on cluster - exportInputFiles(job); - - // build batch script for job - string scriptFile = buildSubmissionScript(job); - - // define command to submit batch - string subCommand = string("cd ") + workDir + "; qsub " + scriptFile; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cerr << command.c_str() << endl; - - // submit job - string output; - int status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) throw EmulationException("Can't submit job, error was: " + output); - - // normally output contains only id of submitted job, we just need to remove the final \n - string jobref = output.substr(0, output.size() - 1); - JobId id(this, jobref); - - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_ePBS::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_ePBS::deleteJob(const JobId & jobid) - { - int status; - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - - // 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) - throw EmulationException("Error of connection on remote host"); - - cerr << "jobId = " << ref << "killed" << endl; - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_ePBS::holdJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_ePBS::releaseJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_ePBS::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_ePBS::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_ePBS::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_ePBS::queryJob(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - // define command to query batch - string subCommand = string("qstat -f ") + iss.str(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - string output; - int status = Utils::getCommandOutput(command, output); - if(status && status != 153 && status != 256*153) - throw EmulationException("Error of connection on remote host"); - - JobInfo_ePBS ji = JobInfo_ePBS(id, output); - return ji; - } - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_ePBS::isRunning(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - std::string BatchManager_ePBS::buildSubmissionScript(const Job & job) - { - Parametre params = job.getParametre(); - Environnement env = job.getEnvironnement(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - int nbproc = 0; - int edt = 0; - int mem = 0; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); - - // Optional parameters - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - if (params.find(MAXWALLTIME) != params.end()) - edt = params[MAXWALLTIME]; - if (params.find(MAXRAMSIZE) != params.end()) - mem = params[MAXRAMSIZE]; - if (params.find(QUEUE) != params.end()) - queue = params[QUEUE].str(); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - std::string TmpFileName = createAndOpenTemporaryFile("PBS-script", tempOutputFile); - - tempOutputFile << "#! /bin/sh -f" << endl; - if (params.find(NAME) != params.end()) { - tempOutputFile << "#PBS -N " << params[NAME] << endl; - } - - if (nbproc > 0) - { - int nb_full_nodes = nbproc / _nb_proc_per_node; - int nb_proc_on_last_node = nbproc % _nb_proc_per_node; - - // In exclusive mode, we reserve all procs on the nodes - if (params.find(EXCLUSIVE) != params.end() && params[EXCLUSIVE] && nb_proc_on_last_node > 0) { - nb_full_nodes += 1; - nb_proc_on_last_node = 0; - } - - tempOutputFile << "#PBS -l nodes="; - - // Full nodes - if (nb_full_nodes > 0) { - tempOutputFile << nb_full_nodes << ":ppn=" << _nb_proc_per_node; - if (nb_proc_on_last_node > 0) { - tempOutputFile << "+"; - } - } - - // Partly reserved node - if (nb_proc_on_last_node > 0) { - tempOutputFile << "1:ppn=" << nb_proc_on_last_node; - } - - tempOutputFile << endl; - } - if (queue != "") - tempOutputFile << "#PBS -q " << queue << endl; - if( edt > 0 ) - tempOutputFile << "#PBS -l walltime=" << edt*60 << endl; - if( mem > 0 ) - tempOutputFile << "#PBS -l mem=" << mem << "MB" << endl; - tempOutputFile << "#PBS -o " << workDir << "/logs/output.log." << rootNameToExecute << endl; - tempOutputFile << "#PBS -e " << workDir << "/logs/error.log." << rootNameToExecute << endl; - - // Define environment for the job - if (!env.empty()) { - tempOutputFile << "#PBS -v "; - Environnement::const_iterator iter; - for (iter = env.begin() ; iter != env.end() ; ++iter) { - tempOutputFile << iter->first << "=" << iter->second << ","; - } - tempOutputFile << endl; - } - - // Abstraction of PBS_NODEFILE - TODO - tempOutputFile << "export LIBBATCH_NODEFILE=$PBS_NODEFILE" << endl; - - // Launch the executable - tempOutputFile << "cd " << workDir << endl; - tempOutputFile << "./" + fileNameToExecute << endl; - tempOutputFile.flush(); - tempOutputFile.close(); - - cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl; - - string remoteFileName = rootNameToExecute + "_Batch.sh"; - int status = _protocol.copyFile(TmpFileName, "", "", - workDir + "/" + remoteFileName, - _hostname, _username); - if (status) - throw EmulationException("Error of connection on remote host, cannot copy batch submission file"); - return remoteFileName; - } -} diff --git a/src/PBS/Batch_BatchManager_ePBS.hxx b/src/PBS/Batch_BatchManager_ePBS.hxx deleted file mode 100644 index a32fcc2..0000000 --- a/src/PBS/Batch_BatchManager_ePBS.hxx +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2007-2012 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_ePBS.hxx : emulation of PBS client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#ifndef _BATCHMANAGER_EPBS_H_ -#define _BATCHMANAGER_EPBS_H_ - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_ePBS : public BatchManager_eClient - { - public: - // Constructeur et destructeur - BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi", - int nb_proc_per_node=1); // connexion a la machine host - virtual ~BatchManager_ePBS(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - std::string buildSubmissionScript(const Job & job); - - private: - int _nb_proc_per_node; - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/PBS/Batch_FactBatchManager_PBS.cxx b/src/PBS/Batch_FactBatchManager_PBS.cxx deleted file mode 100644 index 9a651c9..0000000 --- a/src/PBS/Batch_FactBatchManager_PBS.cxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2007-2012 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_PBS.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#include "Batch_BatchManager_PBS.hxx" -#include "Batch_FactBatchManager_PBS.hxx" -using namespace std; - -namespace Batch { - - static FactBatchManager_PBS sFBM_PBS; - - // Constructeur - FactBatchManager_PBS::FactBatchManager_PBS() : FactBatchManager("PBS") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_PBS::~FactBatchManager_PBS() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_PBS::operator() (const char * hostname) const - { - return new BatchManager_PBS(this, hostname); - } - - -} diff --git a/src/PBS/Batch_FactBatchManager_PBS.hxx b/src/PBS/Batch_FactBatchManager_PBS.hxx deleted file mode 100644 index fea48dc..0000000 --- a/src/PBS/Batch_FactBatchManager_PBS.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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_PBS.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Date : Septembre 2004 - * Projet : SALOME 2 - * - */ - -#ifndef _FACTBATCHMANAGER_PBS_H_ -#define _FACTBATCHMANAGER_PBS_H_ - -#include "Batch_FactBatchManager.hxx" - -namespace Batch { - - class BatchManager_PBS; - - class FactBatchManager_PBS : public FactBatchManager - { - public: - // Constructeur et destructeur - FactBatchManager_PBS(); - virtual ~FactBatchManager_PBS(); - - virtual BatchManager * operator() (const char * hostname) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/PBS/Batch_FactBatchManager_ePBS.cxx b/src/PBS/Batch_FactBatchManager_ePBS.cxx deleted file mode 100644 index 415ac58..0000000 --- a/src/PBS/Batch_FactBatchManager_ePBS.cxx +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (C) 2007-2012 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_ePBS.cxx : - * - * Auteur : Bernard SECHER - CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#include -#include "Batch_BatchManager_ePBS.hxx" -#include "Batch_FactBatchManager_ePBS.hxx" -//#include "utilities.h" - -namespace Batch { - - static FactBatchManager_ePBS sFBM_ePBS; - - // Constructeur - FactBatchManager_ePBS::FactBatchManager_ePBS() : FactBatchManager_eClient("ePBS") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_ePBS::~FactBatchManager_ePBS() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_ePBS::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_PBS on host '" << hostname << "'"); - return new BatchManager_ePBS(this, hostname); - } - - BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_PBS on host '" << hostname << "'"); - return new BatchManager_ePBS(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); - } - - -} diff --git a/src/PBS/Batch_FactBatchManager_ePBS.hxx b/src/PBS/Batch_FactBatchManager_ePBS.hxx deleted file mode 100644 index a379d5b..0000000 --- a/src/PBS/Batch_FactBatchManager_ePBS.hxx +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (C) 2007-2012 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_ePBS.hxx : - * - * Auteur : Bernard SECHER : CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#ifndef _FACTBATCHMANAGER_ePBS_H_ -#define _FACTBATCHMANAGER_ePBS_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - class BatchManager_ePBS; - - class BATCH_EXPORT FactBatchManager_ePBS : public FactBatchManager_eClient - { - public: - // Constructeur et destructeur - FactBatchManager_ePBS(); - virtual ~FactBatchManager_ePBS(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/PBS/Batch_JobInfo_PBS.cxx b/src/PBS/Batch_JobInfo_PBS.cxx deleted file mode 100644 index a7c19e1..0000000 --- a/src/PBS/Batch_JobInfo_PBS.cxx +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_PBS.cxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 21 09:42:06 2003 - * Projet : Salome 2 - * - */ - -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_JobInfo_PBS.hxx" -using namespace std; - -namespace Batch { - - // Constructeurs - JobInfo_PBS::JobInfo_PBS(struct batch_status * list, bool tobedeleted) : JobInfo() - { - // On ne considere que le premier element de la liste - // Si tout est OK, la liste ne devrait contenir qu'un element - // Sinon on leve une exception. - struct batch_status * p_job = list; - int i; - for(i=0; p_job; p_job = p_job->next) i++; - if (i == 0) throw RunTimeException("Liste vide (le job est absent de la file)"); - if (i > 1) { - ostringstream sst; - sst << "JobInfo_PBS::JobInfo_PBS(struct batch_status * list, bool tobedeleted) : la liste contient " - << i << " elements" << " (1 seul requis)" << endl; - throw RunTimeException(sst.str()); - } - p_job = list; - - // On remplit les membres _param et _env - - if (p_job->name && strlen(p_job->name)) _param[ID] = p_job->name; - if (p_job->text && strlen(p_job->text)) _param[TEXT] = p_job->text; - - for(struct attrl * p_attr = p_job->attribs; p_attr; p_attr = p_attr->next) { - - string name, res, value; - if (p_attr->name && strlen(p_attr->name)) name = p_attr->name; - if (p_attr->resource && strlen(p_attr->resource)) res = p_attr->resource; - if (p_attr->value && strlen(p_attr->value)) value = p_attr->value; - - if (name == ATTR_N) { - _param[NAME] = value; - - } else if (name == ATTR_owner) { - _param[USER] = value; - - } else if (name == ATTR_state) { - string status = value; - if (status == "C") { // Completed - _param[STATE] = FINISHED; - } else if (status == "E") { // Exiting - _param[STATE] = RUNNING; - } else if (status == "H") { // Held - _param[STATE] = PAUSED; - } else if (status == "Q") { // Queued - _param[STATE] = QUEUED; - } else if (status == "R") { // Running - _param[STATE] = RUNNING; - } else if (status == "S") { // Suspend - _param[STATE] = PAUSED; - } else if (status == "T") { // Transiting - _param[STATE] = IN_PROCESS; - } else if (status == "W") { // Waiting - _param[STATE] = PAUSED; - } else { - cerr << "Unknown job state code: " << status << endl; - } - - } else if (name == ATTR_queue) { - _param[QUEUE] = value; - - } else if (name == ATTR_A) { - _param[ACCOUNT] = value; - - } else if (name == ATTR_M) { - _param[MAIL] = value; - - } else if (name == ATTR_c) { - if (!strcmp(value.c_str(), CHECKPOINT_UNSPECIFIED)) _param[CHECKPOINT] = 1L; - else _param[CHECKPOINT] = 0L; - - } else if (name == ATTR_h) { - if (!strcmp(value.c_str(), NO_HOLD)) _param[HOLD] = 0L; - else _param[HOLD] = 1L; - - } else if (name == ATTR_ctime) { - _param[CREATIONTIME] = atol(value.c_str()); - - } else if (name == ATTR_etime) { - _param[ELIGIBLETIME] = atol(value.c_str()); - - } else if (name == ATTR_mtime) { - _param[MODIFICATIONTIME] = atol(value.c_str()); - - } else if (name == ATTR_qtime) { - _param[QUEUEDTIME] = atol(value.c_str()); - - } else if (name == ATTR_exechost) { - _param[EXECUTIONHOST] = value; - - } else if (name == ATTR_session) { - _param[PID] = atol(value.c_str()); - - } else if (name == ATTR_euser) { - _param[EUSER] = value; - - } else if (name == ATTR_egroup) { - _param[EGROUP] = value; - - } else if (name == ATTR_l) { - if (res == "cput") { - _param[MAXCPUTIME] = HMStoLong(value); - - } else if (res == "walltime") { - _param[MAXWALLTIME] = HMStoLong(value); - - } - - } else if (name == ATTR_used) { - if (res == "cput") { - _param[USEDCPUTIME] = HMStoLong(value); - - } else if (res == "walltime") { - _param[USEDWALLTIME] = HMStoLong(value); - - } - - } else if (name == ATTR_v) { - int deb = 0; - int pos = 0; - bool ok = true; - - while (ok) { - pos = value.find(",", deb); - string sub = value.substr(deb, pos-deb); - deb = pos + 1; - if (pos < 0) ok = false; - - int eq = sub.find("="); - _env[sub.substr(0, eq)] = sub.substr(eq+1); - } - - } - } - - - if (tobedeleted) pbs_statfree(list); - } - - // Destructeur - JobInfo_PBS::~JobInfo_PBS() - { - // Nothing to do - } - - // Convertit une date HH:MM:SS en secondes - long JobInfo_PBS::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_PBS::__str__() const - { - ostringstream sst; - sst << " -#include -} -#include -#include "Batch_RunTimeException.hxx" -#include "Batch_JobInfo.hxx" - -namespace Batch { - - class JobInfo_PBS : public JobInfo - { - public: - // Constructeurs et destructeur - JobInfo_PBS() : JobInfo() {}; - JobInfo_PBS(struct batch_status * stat_list, bool tobedeleted = false); - virtual ~JobInfo_PBS(); - - // Constructeur par recopie - JobInfo_PBS(const JobInfo_PBS & jinfo) : JobInfo(jinfo) {}; - - // Methodes pour l'interfacage avec Python (SWIG) - // TODO : supprimer ces methodes et transferer leur definitions dans SWIG - std::string __str__() const; // SWIG : affichage en Python - std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - - protected: - - private: - // Convertit une date HH:MM:SS en secondes - long HMStoLong(const std::string &); - - }; - -} - -#endif diff --git a/src/PBS/Batch_JobInfo_ePBS.cxx b/src/PBS/Batch_JobInfo_ePBS.cxx deleted file mode 100644 index 6211073..0000000 --- a/src/PBS/Batch_JobInfo_ePBS.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_ePBS.cxx : emulation of PBS client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include -#include - -#include -#include "Batch_JobInfo_ePBS.hxx" - -using namespace std; - -namespace Batch { - - // Constructeurs - JobInfo_ePBS::JobInfo_ePBS(int id, string queryOutput) : JobInfo() - { - // Fill ID parameter - ostringstream oss; - oss << id; - _param[ID] = oss.str(); - - // read query output - istringstream queryIss(queryOutput); - string line; - size_t pos = string::npos; - while( (pos == string::npos) && getline(queryIss, line) ) { - pos = line.find("job_state"); - } - - if(pos!=string::npos){ - string status; - istringstream iss(line); - iss >> status; - iss >> status; - iss >> status; - - if (status == "C") { // Completed - _param[STATE] = FINISHED; - } else if (status == "E") { // Exiting - _param[STATE] = RUNNING; - } else if (status == "H") { // Held - _param[STATE] = PAUSED; - } else if (status == "Q") { // Queued - _param[STATE] = QUEUED; - } else if (status == "R") { // Running - _param[STATE] = RUNNING; - } else if (status == "S") { // Suspend - _param[STATE] = PAUSED; - } else if (status == "T") { // Transiting - _param[STATE] = IN_PROCESS; - } else if (status == "W") { // Waiting - _param[STATE] = PAUSED; - } else { - cerr << "Unknown job state code: " << status << endl; - } - } else { - // On some batch managers, the job is deleted as soon as it is finished, - // so we have to consider that an unknown job is a finished one, even if - // it is not always true. - _param[STATE] = FINISHED; - } - } - - // Destructeur - JobInfo_ePBS::~JobInfo_ePBS() - { - // Nothing to do - } - - // Convertit une date HH:MM:SS en secondes - long JobInfo_ePBS::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_ePBS::__str__() const - { - ostringstream sst; - sst << " -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Job_PBS.hxx" -using namespace std; - -namespace Batch { - - // Ajoute un element (name,resource,value) a la liste chainee d'attributs + operateur - void Job_PBS::setResourceAttributeOP(struct attropl ** attr_list, const char * attr_name, const char * attr_resource, const char * attr_value) - { - // L'element (name,resource,value) existe-t-il deja ? si oui ptr != 0 - struct attropl * ptr = findResourceAttributeOP(*attr_list, attr_name, attr_resource); - - if (!ptr) { // L'element n'existe pas, il faut le creer - if ((ptr = lastAttributeOP(*attr_list))) { // la liste n'est pas vide - ptr->next = new struct attropl; - ptr = ptr->next; - ptr->next = 0; - - } else { // la liste est completement vide - ptr = *attr_list = new struct attropl; - ptr->next = 0; - } - - // On remplit les champs (name,resource,value) - ptr->name = new char[strlen(attr_name) + 1]; - strncpy(ptr->name, attr_name, strlen(attr_name)); - ptr->name[strlen(attr_name)] = 0; - - ptr->resource = new char[strlen(attr_resource) + 1]; - strncpy(ptr->resource, attr_resource, strlen(attr_resource)); - ptr->resource[strlen(attr_resource)] = 0; - - ptr->value = new char[strlen(attr_value) + 1]; - strncpy(ptr->value, attr_value, strlen(attr_value)); - ptr->value[strlen(attr_value)] = 0; - - } else { // L'attribut existe, on change sa valeur - delete[] ptr->value; // On efface la valeur precedente - ptr->value = new char[strlen(attr_value) + 1]; - strncpy(ptr->value, attr_value, strlen(attr_value)); - ptr->value[strlen(attr_value)] = 0; - - } - } - - - // Recherche un element (name,resource,value) dans la liste chainee d'attributs + operateur - struct attropl * Job_PBS::findResourceAttributeOP(struct attropl * attr_list, const char * attr_name, const char * attr_resource) - { - // On parcoure la liste chainee pour trouver l'element dont les champs name et resource coincident - struct attropl * ptr = attr_list; - while (ptr) { - if (!strcmp(ptr->name, attr_name) && !strcmp(ptr->resource, attr_resource)) break; - ptr = ptr->next; - } - return ptr; - } - - - // Recherche le dernier element de la liste chainee d'attributs + operateur - struct attropl * Job_PBS::lastAttributeOP(struct attropl * attr_list) - { - struct attropl * ptr = attr_list; - while (ptr && ptr->next) { - ptr = ptr->next; - } - return ptr; - } - - - // Convertit un objet Parametre en liste chainee d'attributs + operateur - struct attropl * Job_PBS::ParametreToAttributeOPList(struct attropl ** _p_attr_list, Parametre & P) - { - Parametre::iterator it; - string st_second; - for(it=P.begin(); it!=P.end(); it++) { - if ( (*it).first == ACCOUNT ) { - st_second = (*it).second.str(); - setResourceAttributeOP(_p_attr_list, ATTR_A, "", st_second.c_str()); - - - } else if ( (*it).first == CHECKPOINT ) { - setResourceAttributeOP(_p_attr_list, ATTR_c, "", "u"); - - - } else if ( (*it).first == CKPTINTERVAL ) { - // Not significant - - } else if ( (*it).first == EXECUTABLE ) { - // Already done - - } else if ( (*it).first == HOLD ) { - if (static_cast< long >((*it).second)) - setResourceAttributeOP(_p_attr_list, ATTR_h, "", USER_HOLD); - else - setResourceAttributeOP(_p_attr_list, ATTR_h, "", NO_HOLD); - - } else if ( (*it).first == INFILE ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - string sep = ""; - string stagein; - - for(Vit=V.begin(); Vit!=V.end(); Vit++, sep=",") { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur - stagein += sep + remote + "@" + local; - } - - if (stagein.size()) - setResourceAttributeOP(_p_attr_list, ATTR_stagein, "", stagein.c_str()); - - - } else if ( (*it).first == MAIL ) { - st_second = (*it).second.str(); - setResourceAttributeOP(_p_attr_list, ATTR_M, "", st_second.c_str()); - - } else if ( (*it).first == MAXCPUTIME ) { - char attr_value[32]; - long secondes = (*it).second; - long heures = secondes / 3600L; - long minutes = (secondes - 3600L * heures) / 60L; - secondes = secondes % 60L; - sprintf(attr_value, "%02ld:%02ld:%02ld", heures, minutes, secondes); - - setResourceAttributeOP(_p_attr_list, ATTR_l, "cput", attr_value); - - - } else if ( (*it).first == MAXDISKSIZE ) { - - } else if ( (*it).first == MAXRAMSIZE ) { - - } else if ( (*it).first == MAXWALLTIME ) { - char attr_value[32]; - long minutes = (*it).second; - long heures = minutes / 60L; - minutes -= 60L * heures; - sprintf(attr_value, "%02ld:%02ld:00", heures, minutes); - - setResourceAttributeOP(_p_attr_list, ATTR_l, "walltime", attr_value); - - - } else if ( (*it).first == NAME ) { - st_second = (*it).second.str(); - setResourceAttributeOP(_p_attr_list, ATTR_N, "", st_second.c_str()); - - - } else if ( (*it).first == OUTFILE ) { - Versatile V = (*it).second; - Versatile::iterator Vit; - - string sep = ""; - string stageout; - - for(Vit=V.begin(); Vit!=V.end(); Vit++, sep=",") { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple cp = cpt; - string local = cp.getLocal(); - string remote = cp.getRemote(); - - if (remote == "stdout") - setResourceAttributeOP(_p_attr_list, ATTR_o, "", local.c_str()); - - else if (remote == "stderr") - setResourceAttributeOP(_p_attr_list, ATTR_e, "", local.c_str()); - - else - // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur - stageout += sep + remote + "@" + local; - } - - if (stageout.size()) - setResourceAttributeOP(_p_attr_list, ATTR_stageout, "", stageout.c_str()); - - } else if ( (*it).first == QUEUE ) { - // Already done - - } else if ( (*it).first == STARTTIME ) { - - } else if ( (*it).first == TMPDIR ) { - - } else if ( (*it).first == USER ) { - st_second = (*it).second.str(); - setResourceAttributeOP(_p_attr_list, ATTR_u, "", st_second.c_str()); - - } - } - return *_p_attr_list; - } - - - // Convertit un objet Environnement en liste chainee d'attributs + operateur - struct attropl * Job_PBS::EnvironnementToAttributeOPList(struct attropl ** _p_attr_list, Environnement & E) - { - Environnement::iterator it; - for(it=E.begin(); it!=E.end(); it++) { - setResourceAttributeOP(_p_attr_list, ATTR_v, (*it).first.c_str(), ( (*it).first + "=" + (*it).second ).c_str()); - } - return *_p_attr_list; - } - - - // Ajoute les variables d'environnement presentes dans tout job PBS - void Job_PBS::addPBSEnvironnement(Environnement & E) - { - char * c; - - c = getenv("HOME"); - if (c) E["PBS_O_HOME"] = c; - - c = getenv("LANG"); - if (c) E["PBS_O_LANG"] = c; - - c = getenv("LOGNAME"); - if (c) E["PBS_O_LOGNAME"] = c; - - c = getenv("PATH"); - if (c) E["PBS_O_PATH"] = c; - - c = getenv("LD_LIBRARY_PATH"); - if (c) E["PBS_O_LD_LIBRARY_PATH"] = c; - - c = getenv("MAIL"); - if (c) E["PBS_O_MAIL"] = c; - - c = getenv("SHELL"); - if (c) E["PBS_O_SHELL"] = c; - - c = getenv("TZ"); - if (c) E["PBS_O_TZ"] = c; - - /* Recuperation du working directory */ - size_t size = 256; - char * buf = 0; - char * rc = 0; - do { - if (buf) delete[] buf; - buf = new char[size]; - rc = getcwd(buf, size); - size += size; - } while (!rc); - E["PBS_O_WORKDIR"] = buf; - delete[] buf; - } - - - // Ajoute un element (name,resource,value) a la liste chainee d'attributs - void Job_PBS::setResourceAttribute(struct attrl ** attr_list, const char * attr_name, const char * attr_resource, const char * attr_value) - { - // L'element (name,resource,value) existe-t-il deja ? si oui ptr != 0 - struct attrl * ptr = findResourceAttribute(*attr_list, attr_name, attr_resource); - - if (!ptr) { // L'attribut n'existe pas, il faut le creer - if ((ptr = lastAttribute(*attr_list))) { // la liste n'est pas vide - ptr->next = new struct attrl; - ptr = ptr->next; - ptr->next = 0; - - } else { // la liste est completement vide - ptr = *attr_list = new struct attrl; - ptr->next = 0; - } - - // On remplit les champs (name,resource,value) - ptr->name = new char[strlen(attr_name) + 1]; - strncpy(ptr->name, attr_name, strlen(attr_name)); - ptr->name[strlen(attr_name)] = 0; - - ptr->resource = new char[strlen(attr_resource) + 1]; - strncpy(ptr->resource, attr_resource, strlen(attr_resource)); - ptr->resource[strlen(attr_resource)] = 0; - - ptr->value = new char[strlen(attr_value) + 1]; - strncpy(ptr->value, attr_value, strlen(attr_value)); - ptr->value[strlen(attr_value)] = 0; - - } else { // L'attribut existe, on change sa valeur - delete[] ptr->value; // On efface la valeur precedente - ptr->value = new char[strlen(attr_value) + 1]; - strncpy(ptr->value, attr_value, strlen(attr_value)); - ptr->value[strlen(attr_value)] = 0; - - } - } - - // Recherche un element (name,resource,value) dans la liste chainee d'attributs - struct attrl * Job_PBS::findResourceAttribute(struct attrl * attr_list, const char * attr_name, const char * attr_resource) - { - // On parcoure la liste chainee pour trouver l'element dont les champs name et resource coincident - struct attrl * ptr = attr_list; - while (ptr) { - if (!strcmp(ptr->name, attr_name) && !strcmp(ptr->resource, attr_resource)) break; - ptr = ptr->next; - } - return ptr; - } - - - // Recherche le dernier element de la liste chainee d'attributs - struct attrl * Job_PBS::lastAttribute(struct attrl * attr_list) - { - struct attrl * ptr = attr_list; - while (ptr && ptr->next) { - ptr = ptr->next; - } - return ptr; - } - - - // Constructeur - Job_PBS::Job_PBS(const Job & job) : _p_attropl(0), _p_attrl(0), _script(0), _destination(0) - { - Parametre P = job.getParametre(); - Parametre::iterator it; - - // On extrait de l'objet Parametre le champ EXECUTABLE qui deviendra le script PBS - if ( (it=P.find(EXECUTABLE)) != P.end()) { - Versatile V = (*it).second; - string st_exe = V.str(); - const char * exe = st_exe.c_str(); - int lg = strlen(exe); - _script = new char[lg + 1]; - for (int ii=0; iinext; - delete[] current_p_attropl->name; - delete[] current_p_attropl->resource; - delete[] current_p_attropl->value; - delete current_p_attropl; - current_p_attropl = next; - } - - // On detruit la liste chainee d'attributs - struct attrl * current_p_attrl = _p_attrl; - while (current_p_attrl) { - struct attrl * next = current_p_attrl->next; - delete[] current_p_attrl->name; - delete[] current_p_attrl->resource; - delete[] current_p_attrl->value; - delete current_p_attrl; - current_p_attrl = next; - } - - // On detruit les champs alloues - delete[] _script; - delete[] _destination; - } - - - // Accesseur - struct attropl * Job_PBS::getAttributesOP() - { - return _p_attropl; - } - - // Accesseur - // Cette methode sert pour les pbs_alter de PBS - // Pbs_alter est bugg� par rapport a la specification ers_all.ps car les - // variables d'environnement ne sont pas supportees (ATTR_v) - struct attrl * Job_PBS::getAttributes() - { - if (_p_attrl == 0) { - - // On remplit la structure attrl a partir de la strucuture attropl - // (elles ne different que par le parametre op, mais elles ne sont pas interchangeables - // dans les appels) - - struct attropl * current_p_attropl = _p_attropl; - while (current_p_attropl) { - if (strcmp(current_p_attropl->name, ATTR_v)) // Bug fix for ATTR_v - setResourceAttribute(&_p_attrl, - current_p_attropl->name, - current_p_attropl->resource, - current_p_attropl->value); - - current_p_attropl = current_p_attropl->next; - } - - } - - return _p_attrl; - } - - // Accesseur - char * Job_PBS::getScript() - { - return _script; - } - - // Accesseur - char * Job_PBS::getDestination() - { - return _destination; - } - -} diff --git a/src/PBS/Batch_Job_PBS.hxx b/src/PBS/Batch_Job_PBS.hxx deleted file mode 100644 index 43a7b54..0000000 --- a/src/PBS/Batch_Job_PBS.hxx +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * Job_PBS.hxx : - * - * Auteur : Ivan DUTKA-MALEN - EDF R&D - * Mail : mailto:ivan.dutka-malen@der.edf.fr - * Date : Fri Nov 14 11:00:39 2003 - * Projet : Salome 2 - * - */ - -#ifndef _JOB_PBS_H_ -#define _JOB_PBS_H_ - -extern "C" { - -#include -#include -} -#include "Batch_Job.hxx" - -namespace Batch { - - class Job_PBS - { - public: - // Constructeur et destructeur - Job_PBS(const Job & job); - virtual ~Job_PBS(); - - // Accesseurs - struct attropl * getAttributesOP(); - struct attrl * getAttributes(); - char * getScript(); - char * getDestination(); - - protected: - struct attropl * _p_attropl; // liste chainee d'attributs + operateur - struct attrl * _p_attrl; // liste chainee d'attributs - char * _script; // chemin d'acces au script du job - char * _destination; // queue dans laquelle le job est soumis - - private: - // Ajoute un element (name,resource,value) a la liste chainee d'attributs + operateur - void setResourceAttributeOP(struct attropl ** attr_list, const char * attr_name, const char * attr_resource, const char * attr_value); - - // Recherche un element (name,resource,value) dans la liste chainee d'attributs + operateur - struct attropl * findResourceAttributeOP(struct attropl * attr_list, const char * attr_name, const char * attr_resource); - - // Recherche le dernier element de la liste chainee d'attributs + operateur - struct attropl * lastAttributeOP(struct attropl * attr_list); - - // Convertit un objet Parametre en liste chainee d'attributs + operateur - struct attropl * ParametreToAttributeOPList(struct attropl ** _p_attr_list, Parametre & param); - - // Convertit un objet Environnement en liste chainee d'attributs + operateur - struct attropl * EnvironnementToAttributeOPList(struct attropl ** _p_attr_list, Environnement & env); - - // Ajoute les variables d'environnement presentes dans tout job PBS - void addPBSEnvironnement(Environnement & E); - - - // Ajoute un element (name,resource,value) a la liste chainee d'attributs - void setResourceAttribute(struct attrl ** attr_list, const char * attr_name, const char * attr_resource, const char * attr_value); - - // Recherche un element (name,resource,value) dans la liste chainee d'attributs - struct attrl * findResourceAttribute(struct attrl * attr_list, const char * attr_name, const char * attr_resource); - - // Recherche le dernier element de la liste chainee d'attributs - struct attrl * lastAttribute(struct attrl * attr_list); - - }; - -} - -#endif diff --git a/src/PBS/CMakeLists.txt b/src/PBS/CMakeLists.txt index bf57649..9fc2dde 100644 --- a/src/PBS/CMakeLists.txt +++ b/src/PBS/CMakeLists.txt @@ -20,22 +20,9 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST PBS/Batch_BatchManager_ePBS - PBS/Batch_FactBatchManager_ePBS - PBS/Batch_JobInfo_ePBS +SET(CLASS_LIST PBS/BatchManager_PBS + PBS/FactBatchManager_PBS + PBS/JobInfo_PBS ) -IF (BUILD_PBS_INTERFACE AND PBS_FOUND) - SET(CLASS_LIST ${CLASS_LIST} - PBS/Batch_BatchManager_PBS - PBS/Batch_FactBatchManager_PBS - PBS/Batch_Job_PBS - PBS/Batch_JobInfo_PBS - ) -ENDIF (BUILD_PBS_INTERFACE AND PBS_FOUND) - APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) - -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) diff --git a/src/PBS/FactBatchManager_PBS.cxx b/src/PBS/FactBatchManager_PBS.cxx new file mode 100644 index 0000000..73eb776 --- /dev/null +++ b/src/PBS/FactBatchManager_PBS.cxx @@ -0,0 +1,58 @@ +// Copyright (C) 2007-2012 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_PBS.cxx : + * + * Auteur : Bernard SECHER - CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#include "BatchManager_PBS.hxx" +#include "FactBatchManager_PBS.hxx" + +namespace Batch { + + static FactBatchManager_PBS sFBM_PBS; + + // Constructeur + FactBatchManager_PBS::FactBatchManager_PBS() : FactBatchManager("PBS") + { + // Nothing to do + } + + // Destructeur + FactBatchManager_PBS::~FactBatchManager_PBS() + { + // Nothing to do + } + + BatchManager * FactBatchManager_PBS::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + return new BatchManager_PBS(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/PBS/FactBatchManager_PBS.hxx b/src/PBS/FactBatchManager_PBS.hxx new file mode 100644 index 0000000..c26a8ad --- /dev/null +++ b/src/PBS/FactBatchManager_PBS.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2012 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_PBS.hxx : + * + * Auteur : Bernard SECHER : CEA DEN + * Date : Avril 2008 + * Projet : PAL Salome + * + */ + +#ifndef _FACTBATCHMANAGER_PBS_H_ +#define _FACTBATCHMANAGER_PBS_H_ + +#include "Defines.hxx" + +#include "BatchManager.hxx" +#include "FactBatchManager.hxx" + +namespace Batch { + + class BatchManager_PBS; + + class BATCH_EXPORT FactBatchManager_PBS : public FactBatchManager + { + public: + // Constructeur et destructeur + FactBatchManager_PBS(); + virtual ~FactBatchManager_PBS(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + + }; + +} + +#endif diff --git a/src/PBS/JobInfo_PBS.cxx b/src/PBS/JobInfo_PBS.cxx new file mode 100644 index 0000000..179b2c3 --- /dev/null +++ b/src/PBS/JobInfo_PBS.cxx @@ -0,0 +1,120 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_PBS.cxx : emulation of PBS client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include +#include + +#include +#include "JobInfo_PBS.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + // Constructeurs + JobInfo_PBS::JobInfo_PBS(int id, string queryOutput) : JobInfo() + { + // Fill ID parameter + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + + // read query output + istringstream queryIss(queryOutput); + string line; + size_t pos = string::npos; + while( (pos == string::npos) && getline(queryIss, line) ) { + pos = line.find("job_state"); + } + + if(pos!=string::npos){ + string status; + istringstream iss(line); + iss >> status; + iss >> status; + iss >> status; + + if (status == "C") { // Completed + _param[STATE] = FINISHED; + } else if (status == "E") { // Exiting + _param[STATE] = RUNNING; + } else if (status == "H") { // Held + _param[STATE] = PAUSED; + } else if (status == "Q") { // Queued + _param[STATE] = QUEUED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "S") { // Suspend + _param[STATE] = PAUSED; + } else if (status == "T") { // Transiting + _param[STATE] = IN_PROCESS; + } else if (status == "W") { // Waiting + _param[STATE] = PAUSED; + } else { + LOG("Unknown job state code: " << status); + } + } else { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } + } + + // Destructeur + JobInfo_PBS::~JobInfo_PBS() + { + // Nothing to do + } + + // Convertit une date HH:MM:SS en secondes + long JobInfo_PBS::HMStoLong(const string & s) + { + long hour, min, sec; + + sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); + return ( ( ( hour * 60L ) + min ) * 60L ) + sec; + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_PBS::__str__() const + { + ostringstream sst; + sst << " -#include - -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -int main(int argc, char** argv) -{ - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on PBS." << endl; - cout << "*******************************************************************************************" << endl; - - // eventually remove any previous result - remove("result.txt"); - - try { - // Parse the test configuration file - SimpleParser parser; - parser.parseTestConfigFile(); - const string & host = parser.getValue("TEST_PBS_HOST"); - const string & user = parser.getValue("TEST_PBS_USER"); - const string & queue = parser.getValue("TEST_PBS_QUEUE"); - int timeout = parser.getValueAsInt("TEST_PBS_TIMEOUT"); - - char * cwd = -#ifdef WIN32 - _getcwd(NULL, 0); -#else - new char [PATH_MAX]; - getcwd(cwd, PATH_MAX); -#endif - string workdir = cwd; - delete [] cwd; - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "test-script.sh"; - p[NAME] = "Test_PBS"; - p[INFILE] = Couple(workdir + "/seta.sh", "seta.sh"); - p[INFILE] += Couple(workdir + "/setb.sh", "setb.sh"); - p[OUTFILE] = Couple(workdir + "/result.txt", "result.txt"); - p[USER] = user; - p[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 4; - p[QUEUE] = queue; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - job.setEnvironnement(e); - cout << job << endl; - - // Get the catalog - BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); - - // Create a BatchManager of type ePBS on localhost - FactBatchManager * fbm = c("PBS"); - BatchManager * bm = (*fbm)(host.c_str()); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED || state == FAILED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - } 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 - try { - SimpleParser resultParser; - resultParser.parse("result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS.cxx deleted file mode 100644 index c016089..0000000 --- a/src/PBS/Test/Test_ePBS.cxx +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2007-2012 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 -#include - -#include - -using namespace std; -using namespace Batch; - -void print_usage() -{ - cout << "usage: Test_ePBS PROTOCOL" << endl; - cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; -} - -int main(int argc, char** argv) -{ - // Parse argument - if (argc != 2) { - print_usage(); - return 1; - } - CommunicationProtocolType protocol; - if (strcmp(argv[1], "SSH") == 0) - protocol = SSH; - else if (strcmp(argv[1], "RSH") == 0) - protocol = RSH; - else { - print_usage(); - return 1; - } - - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on PBS emulation. Passwordless authentication" << endl; - cout << "must be used for this test to pass. For SSH, this can be configured with ssh-agent for" << endl; - cout << "instance. For RSH, this can be configured with the .rhosts file." << 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] = string("Test_ePBS_") + argv[1]; - 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[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 128; - p[HOMEDIR] = homedir; - p[QUEUE] = queue; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - 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(), user.c_str(), protocol, "nompi", 8); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED || state == FAILED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - } 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 - try { - SimpleParser resultParser; - resultParser.parse("resultdir/seconddirname/result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/PBS/Test/seta.sh b/src/PBS/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/PBS/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/PBS/Test/setb.sh b/src/PBS/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/PBS/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/PBS/Test/test-script.sh b/src/PBS/Test/test-script.sh deleted file mode 100755 index ae952c8..0000000 --- a/src/PBS/Test/test-script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -source seta.sh -source setb.sh - -c=`expr $a "*" $b` - -echo "MYENVVAR = $MYENVVAR" > result.txt -echo "c = $c" >> result.txt diff --git a/src/Python/CMakeLists.txt b/src/Python/CMakeLists.txt index f9a8a3a..8e901b9 100644 --- a/src/Python/CMakeLists.txt +++ b/src/Python/CMakeLists.txt @@ -28,14 +28,15 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(SWIG_SRC_FILE libBatch_Swig.i) SET_SOURCE_FILES_PROPERTIES(${SWIG_SRC_FILE} PROPERTIES CPLUSPLUS ON SWIG_FLAGS "-shadow") -SWIG_ADD_MODULE(libBatch_Swig python ${SWIG_SRC_FILE}) -SWIG_LINK_LIBRARIES(libBatch_Swig Batch ${PYTHON_LIBRARIES}) +SWIG_ADD_MODULE(libbatch python ${SWIG_SRC_FILE}) +SWIG_LINK_LIBRARIES(libbatch batch ${PYTHON_LIBRARIES}) -INSTALL(TARGETS ${SWIG_MODULE_libBatch_Swig_REAL_NAME} DESTINATION lib/python${PYTHON_VERSION}/site-packages) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libBatch_Swig.py +SET(PYTHON_VERSION "{PYTHON_VERSION_MAJOR}.{PYTHON_VERSION_MINOR}") +INSTALL(TARGETS ${SWIG_MODULE_libbatch_REAL_NAME} DESTINATION lib/python${PYTHON_VERSION}/site-packages) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libbatch.py DESTINATION lib/python${PYTHON_VERSION}/site-packages) -SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES libBatch_Swig.py) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES libbatch.py) IF (TEST_ENABLED) add_subdirectory(Test) diff --git a/src/Python/Test/CMakeLists.txt b/src/Python/Test/CMakeLists.txt index fe3d614..0119438 100644 --- a/src/Python/Test/CMakeLists.txt +++ b/src/Python/Test/CMakeLists.txt @@ -24,9 +24,7 @@ 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) + # Just copy the test script to the binary dir CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Python_Local_SH.py ${CMAKE_CURRENT_BINARY_DIR}/Test_Python_Local_SH.py COPYONLY) diff --git a/src/Python/Test/Test_Python_Local_SH.py b/src/Python/Test/Test_Python_Local_SH.py index a6dae7d..3a1e742 100644 --- a/src/Python/Test/Test_Python_Local_SH.py +++ b/src/Python/Test/Test_Python_Local_SH.py @@ -25,8 +25,8 @@ import os import sys import time -# Import libBatch library -from libBatch_Swig import * +# Import libbatch library +from libbatch import * def work(): print "*******************************************************************************************" @@ -35,31 +35,32 @@ def work(): print "*******************************************************************************************" # eventually remove any previous result - if (os.path.exists('result.txt')): - os.remove('result.txt') + if (os.path.exists("resultdir/seconddirname/result.txt")): + os.remove("resultdir/seconddirname/result.txt") # Define the job... job = Job() # ... and its parameters ... p = {} - p[EXECUTABLE] = './copied-' + config.EXEC_TEST_NAME - p[ARGUMENTS] = ["copied-seta.sh", "copied-setb.sh", "orig-result.txt"]; + p[EXECUTABLE] = config.TEST_SOURCE_DIR + "/test_script.py"; + p[ARGUMENTS] = ["copied_seta.py", "copied_setb.py", "orig_result.txt"]; p[NAME] = 'Test_Python_Local_SH' - p[WORKDIR] = config.TEST_LOCAL_SH_WORK_DIR - p[INFILE] = [('seta.sh', 'copied-seta.sh'), ('setb.sh', 'copied-setb.sh'), - (config.EXEC_TEST_FULL_PATH, 'copied-' + config.EXEC_TEST_NAME)] - p[OUTFILE] = [('result.txt', 'orig-result.txt')] + p[WORKDIR] = config.TEST_LOCAL_SH_WORKDIR + p[INFILE] = [(config.TEST_SOURCE_DIR + '/seta.py', 'copied_seta.py'), + (config.TEST_SOURCE_DIR + '/setb.py', 'copied_setb.py')] + p[OUTFILE] = [('result.txt', 'orig_result.txt')] job.setParametre(p) # ... and its environment e = {} + e["MYENVVAR"] = "MYVALUE"; job.setEnvironnement(e) print job # Get the catalog c = BatchManagerCatalog.getInstance() - # Create a BatchManager of type Local_SSH on localhost - bm = c('SH')('localhost') + # Create a BatchManager of type Local_SH on localhost + bm = c('LOCAL')('localhost', '', SH) # Submit the job to the BatchManager jobid = bm.submitJob(job) @@ -71,22 +72,31 @@ def work(): # Wait for the end of the job state = bm.waitForJobEnd(jobid, config.TEST_LOCAL_SH_TIMEOUT); + + if state == FINISHED: + print "Job", jobid, "is done" + bm.importOutputFiles(job, "resultdir/seconddirname") + elif state == FAILED: + print "Job", jobid, " finished in error" + bm.importOutputFiles(job, "resultdir/seconddirname") + return 1 + else: + print "Timeout while executing job" + return 1 + if state != FINISHED and state != FAILED: print "Error: Job not finished after timeout" return 1; - print "Job", jobid, "is done" - # test the result file - exp = "c = 12" - f = open('result.txt') - res = f.read().strip() - print "result found : %s, expected : %s" % (res, exp) - - if (res == exp): - return 0 + res = {} + execfile('resultdir/seconddirname/result.txt', res) + if (res["c"] == 12 and res["MYENVVAR"] == "MYVALUE"): + print "OK, Expected result found." + return 0 else: - return 1 + print "result found : %s, expected : %s" % (res, 'res["c"] == 12 and res["MYENVVAR"] == "MYVALUE"') + return 1 if __name__ == "__main__": retcode = work() diff --git a/src/Python/Test/config.py.in b/src/Python/Test/config.py.in index 64c7927..af5d3b4 100644 --- a/src/Python/Test/config.py.in +++ b/src/Python/Test/config.py.in @@ -24,8 +24,6 @@ import sys import os sys.path.append('${CMAKE_CURRENT_BINARY_DIR}/..') -EXEC_TEST_FULL_PATH = "${EXEC_TEST_FULL_PATH}" -EXEC_TEST_NAME = "${EXEC_TEST_NAME}" - configfile = os.environ["${TEST_CONFIG_FILE_ENV_VAR}"] execfile(configfile) +TEST_SOURCE_DIR = "${CMAKE_SOURCE_DIR}/src/Core/Test" diff --git a/src/Python/Test/seta.sh b/src/Python/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/Python/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/Python/Test/setb.sh b/src/Python/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/Python/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/Python/libBatch_Swig.i b/src/Python/libBatch_Swig.i index ff36cfd..37445c1 100644 --- a/src/Python/libBatch_Swig.i +++ b/src/Python/libBatch_Swig.i @@ -41,7 +41,7 @@ /* Le nom du module Python tel qu'il est importe */ -%module libBatch_Swig +%module libbatch /* generate docstrings with types */ %feature("autodoc", "1"); @@ -56,19 +56,17 @@ %include libBatch_Swig_exception.i %{ -#include "Batch_Defines.hxx" -#include "Batch_Constants.hxx" -#include "Batch_Job.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" - -#include "Batch_CommunicationProtocol.hxx" - -#include "Batch_BatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_BatchManagerCatalog.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_FactBatchManager_eClient.hxx" +#include "Defines.hxx" +#include "Constants.hxx" +#include "Job.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" + +#include "CommunicationProtocol.hxx" + +#include "BatchManager.hxx" +#include "BatchManagerCatalog.hxx" +#include "FactBatchManager.hxx" %} /* Les classes exportees en Python */ @@ -76,20 +74,18 @@ %ignore operator<<(std::ostream & os, const Job & job); %ignore operator<<(std::ostream & os, const JobInfo & ji); -%include Batch_Defines.hxx -%include Batch_Job.hxx -%include Batch_JobId.hxx -%include Batch_JobInfo.hxx +%include Defines.hxx +%include Job.hxx +%include JobId.hxx +%include JobInfo.hxx -%include Batch_CommunicationProtocol.hxx +%include CommunicationProtocol.hxx -%include Batch_BatchManager.hxx -%include Batch_BatchManager_eClient.hxx -%include Batch_BatchManagerCatalog.hxx -%include Batch_FactBatchManager.hxx -%include Batch_FactBatchManager_eClient.hxx +%include BatchManager.hxx +%include BatchManagerCatalog.hxx +%include FactBatchManager.hxx -%include Batch_Constants.hxx +%include Constants.hxx /* Les methodes alterJob (surchargees et mal gerees en Python) sont diff --git a/src/Python/libBatch_Swig_typemap.i b/src/Python/libBatch_Swig_typemap.i index 27a2ca0..5c9e513 100644 --- a/src/Python/libBatch_Swig_typemap.i +++ b/src/Python/libBatch_Swig_typemap.i @@ -32,11 +32,11 @@ #include #include #include -#include "Batch_ParameterTypeMap.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_JobId.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_RunTimeException.hxx" +#include "ParameterTypeMap.hxx" +#include "Parametre.hxx" +#include "JobId.hxx" +#include "FactBatchManager.hxx" +#include "RunTimeException.hxx" %} # // supprime toutes les definitions par defaut => sert au debug @@ -277,12 +277,3 @@ static bool initEnvironment(Batch::Environnement & newEnv, PyObject * input) bool res = initEnvironment($1, $input); if (!res) return NULL; } - -// Dynamic cast to FactBatchManager_eClient if necessary -%typemap(out) Batch::FactBatchManager * -{ - if(dynamic_cast($1)) - $result=SWIG_NewPointerObj((void*)$1,$descriptor(Batch::FactBatchManager_eClient *),$owner); - else - $result=SWIG_NewPointerObj((void*)$1,$descriptor(Batch::FactBatchManager *),$owner); -} diff --git a/src/SGE/BatchManager_SGE.cxx b/src/SGE/BatchManager_SGE.cxx new file mode 100644 index 0000000..ac4bea7 --- /dev/null +++ b/src/SGE/BatchManager_SGE.cxx @@ -0,0 +1,249 @@ +// Copyright (C) 2007-2012 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_SGE.cxx : emulation of SGE client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#include +#include + +#include +#include +#include + +#include +#include + +#ifdef WIN32 +#include +#else +#include +#endif + +#include +#include +#include + +#include "BatchManager_SGE.hxx" +#include "JobInfo_SGE.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_SGE::BatchManager_SGE(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + // Destructeur + BatchManager_SGE::~BatchManager_SGE() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_SGE::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const std::string workDir = params[WORKDIR]; + const string fileToExecute = params[EXECUTABLE]; + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + + // export input files on cluster + exportInputFiles(job); + + // build batch script for job + buildBatchScript(job); + + // define command to submit batch + string subCommand = string("bash -l -c \\\"cd ") + workDir + "; qsub " + fileNameToExecute + "_Batch.sh\\\""; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // find id of submitted job in output + string strjob; + istringstream iss(output); + iss >> strjob >> strjob >> strjob; + + JobId id(this, strjob); + return id; + } + + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_SGE::deleteJob(const JobId & jobid) + { + int status; + int ref; + istringstream iss(jobid.getReference()); + iss >> ref; + + // define command to delete batch + string subCommand = string("bash -l -c \\\"qdel ") + iss.str() + string("\\\""); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + status = system(command.c_str()); + if(status) + throw RunTimeException("Error of connection on remote host"); + + LOG("jobId = " << ref << "killed"); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_SGE::queryJob(const JobId & jobid) + { + int id; + istringstream iss(jobid.getReference()); + iss >> id; + + // define command to query batch + string subCommand = string("bash -l -c \\\"qstat | grep ") + iss.str() + string("\\\""); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + if (status && status != 256) + throw RunTimeException("Error of connection on remote host"); + + JobInfo_SGE ji = JobInfo_SGE(id, output); + return ji; + } + + // Methode pour le controle des jobs : teste si un job est present en machine + bool BatchManager_SGE::isRunning(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_SGE::isRunning"); + } + + void BatchManager_SGE::buildBatchScript(const Job & job) + { +#ifndef WIN32 + //TODO porting on Win32 platform + LOG("BuildBatchScript"); + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + int nbproc = 0; + int edt = 0; + int mem = 0; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); + + // Optional parameters + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + if (params.find(MAXWALLTIME) != params.end()) + edt = params[MAXWALLTIME]; + if (params.find(MAXRAMSIZE) != params.end()) + mem = params[MAXRAMSIZE]; + if (params.find(QUEUE) != params.end()) + queue = params[QUEUE].str(); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + std::string TmpFileName = Utils::createAndOpenTemporaryFile("SGE-script", tempOutputFile); + + tempOutputFile << "#! /bin/sh -f" << endl; + if (queue != "") + tempOutputFile << "#$ -q " << queue << endl; + tempOutputFile << "#$ -pe " << _mpiImpl->name() << " " << nbproc << endl; + if( edt > 0 ) + tempOutputFile << "#$ -l h_rt=" << getWallTime(edt) << endl ; + if( mem > 0 ) + tempOutputFile << "#$ -l h_vmem=" << mem << "M" << endl ; + tempOutputFile << "#$ -o " << workDir << "/logs/output.log." << rootNameToExecute << endl ; + tempOutputFile << "#$ -e " << workDir << "/logs/error.log." << rootNameToExecute << endl ; + + // Abstraction of PBS_NODEFILE - TODO + tempOutputFile << "export LIBBATCH_NODEFILE=$TMPDIR/machines" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl ; + tempOutputFile << "./" + fileNameToExecute << endl; + tempOutputFile.flush(); + tempOutputFile.close(); + + Utils::chmod(TmpFileName.c_str(), 0x1ED); + LOG("Batch script file generated is: " << TmpFileName.c_str()); + + int status = _protocol.copyFile(TmpFileName, "", "", + workDir + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) + throw RunTimeException("Error of connection on remote host"); + +#endif //WIN32 + } + + std::string BatchManager_SGE::getWallTime(const long edt) + { + long h, m; + h = edt / 60; + m = edt - h*60; + ostringstream oss; + if( m >= 10 ) + oss << h << ":" << m; + else + oss << h << ":0" << m; + oss << ":00"; // the seconds + + return oss.str(); + } + +} diff --git a/src/SGE/BatchManager_SGE.hxx b/src/SGE/BatchManager_SGE.hxx new file mode 100644 index 0000000..acdb75d --- /dev/null +++ b/src/SGE/BatchManager_SGE.hxx @@ -0,0 +1,81 @@ +// Copyright (C) 2007-2012 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_SGE.hxx : emulation of SGE client + * + * Auteur : Bernard SECHER - CEA DEN + * Mail : mailto:bernard.secher@cea.fr + * Date : Thu Apr 24 10:17:22 2008 + * Projet : PAL Salome + * + */ + +#ifndef _BATCHMANAGER_ESGE_H_ +#define _BATCHMANAGER_ESGE_H_ + +#include "Defines.hxx" +#include "JobId.hxx" +#include "JobInfo.hxx" +#include "FactBatchManager.hxx" +#include "BatchManager.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_SGE : public BatchManager + { + public: + // Constructeur et destructeur + BatchManager_SGE(const FactBatchManager * parent, const char * host="localhost", + const char * username="", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host + virtual ~BatchManager_SGE(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine + + virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente + virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente + + protected: + void buildBatchScript(const Job & job); + std::string getWallTime(const long edt); + + private: + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + + }; + +} + +#endif diff --git a/src/SGE/Batch_BatchManager_eSGE.cxx b/src/SGE/Batch_BatchManager_eSGE.cxx deleted file mode 100644 index e576631..0000000 --- a/src/SGE/Batch_BatchManager_eSGE.cxx +++ /dev/null @@ -1,303 +0,0 @@ -// Copyright (C) 2007-2012 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_eSGE.cxx : emulation of SGE client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#ifdef WIN32 -#include -#else -#include -#endif - -#include "Batch_Constants.hxx" -#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 * username, - CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl) - { - // Nothing to do - } - - // Destructeur - BatchManager_eSGE::~BatchManager_eSGE() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_eSGE::submitJob(const Job & job) - { - int status; - Parametre params = job.getParametre(); - const std::string workDir = params[WORKDIR]; - const string fileToExecute = params[EXECUTABLE]; - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - - // export input files on cluster - exportInputFiles(job); - - // build batch script for job - buildBatchScript(job); - - // define name of log file (local) - string logFile = generateTemporaryFileName("SGE-submitlog"); - - // define command to submit batch - string subCommand = string("bash -l -c \\\"cd ") + workDir + "; qsub " + fileNameToExecute + "_Batch.sh\\\""; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - command += " 2>&1"; - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) - { - ifstream error_message(logFile.c_str()); - std::string mess; - std::string temp; - while(std::getline(error_message, temp)) - mess += temp; - error_message.close(); - throw EmulationException("Error of connection on remote host, error was: " + mess); - } - - // read id of submitted job in log file - char line[128]; - FILE *fp = fopen(logFile.c_str(),"r"); - fgets( line, 128, fp); - fclose(fp); - - string strjob; - istringstream iss(line); - iss >> strjob >> strjob >> strjob; - - JobId id(this, strjob); - return id; - } - - // Ce manager permet de faire de la reprise - const Batch::JobId - BatchManager_eSGE::addJob(const Batch::Job & job, const std::string reference) - { - return JobId(this, reference); - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_eSGE::deleteJob(const JobId & jobid) - { - int status; - int ref; - istringstream iss(jobid.getReference()); - iss >> ref; - - // define command to delete batch - string subCommand = string("bash -l -c \\\"qdel ") + iss.str() + string("\\\""); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - status = system(command.c_str()); - if(status) - throw EmulationException("Error of connection on remote host"); - - cerr << "jobId = " << ref << "killed" << endl; - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_eSGE::holdJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_eSGE::releaseJob(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSGE::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw EmulationException("Not yet implemented"); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSGE::alterJob(const JobId & jobid, const Parametre & param) - { - alterJob(jobid, param, Environnement()); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSGE::alterJob(const JobId & jobid, const Environnement & env) - { - alterJob(jobid, Parametre(), env); - } - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_eSGE::queryJob(const JobId & jobid) - { - int id; - istringstream iss(jobid.getReference()); - iss >> id; - - // define name of log file (local) - string logFile = generateTemporaryFileName(string("SGE-querylog-id") + jobid.getReference()); - - // define command to query batch - string subCommand = string("bash -l -c \\\"qstat | grep ") + iss.str() + string("\\\""); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " > "; - command += logFile; - cerr << command.c_str() << endl; - 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); - return ji; - } - - // Methode pour le controle des jobs : teste si un job est present en machine - bool BatchManager_eSGE::isRunning(const JobId & jobid) - { - throw EmulationException("Not yet implemented"); - } - - void BatchManager_eSGE::buildBatchScript(const Job & job) - { -#ifndef WIN32 - //TODO porting on Win32 platform - std::cerr << "BuildBatchScript" << std::endl; - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - int nbproc = 0; - int edt = 0; - int mem = 0; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); - - // Optional parameters - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - if (params.find(MAXWALLTIME) != params.end()) - edt = params[MAXWALLTIME]; - if (params.find(MAXRAMSIZE) != params.end()) - mem = params[MAXRAMSIZE]; - if (params.find(QUEUE) != params.end()) - queue = params[QUEUE].str(); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - std::string TmpFileName = createAndOpenTemporaryFile("SGE-script", tempOutputFile); - - tempOutputFile << "#! /bin/sh -f" << endl; - if (queue != "") - tempOutputFile << "#$ -q " << queue << endl; - tempOutputFile << "#$ -pe " << _mpiImpl->name() << " " << nbproc << endl; - if( edt > 0 ) - tempOutputFile << "#$ -l h_rt=" << getWallTime(edt) << endl ; - if( mem > 0 ) - tempOutputFile << "#$ -l h_vmem=" << mem << "M" << endl ; - tempOutputFile << "#$ -o " << workDir << "/logs/output.log." << rootNameToExecute << endl ; - tempOutputFile << "#$ -e " << workDir << "/logs/error.log." << rootNameToExecute << endl ; - - // Abstraction of PBS_NODEFILE - TODO - tempOutputFile << "export LIBBATCH_NODEFILE=$TMPDIR/machines" << endl; - - // Launch the executable - tempOutputFile << "cd " << workDir << endl ; - tempOutputFile << "./" + fileNameToExecute << endl; - tempOutputFile.flush(); - tempOutputFile.close(); - - BATCH_CHMOD(TmpFileName.c_str(), 0x1ED); - cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl; - - int status = _protocol.copyFile(TmpFileName, "", "", - workDir + "/" + rootNameToExecute + "_Batch.sh", - _hostname, _username); - if (status) - throw EmulationException("Error of connection on remote host"); - -#endif //WIN32 - } - - std::string BatchManager_eSGE::getWallTime(const long edt) - { - long h, m; - h = edt / 60; - m = edt - h*60; - ostringstream oss; - if( m >= 10 ) - oss << h << ":" << m; - else - oss << h << ":0" << m; - oss << ":00"; // the seconds - - return oss.str(); - } - -} diff --git a/src/SGE/Batch_BatchManager_eSGE.hxx b/src/SGE/Batch_BatchManager_eSGE.hxx deleted file mode 100644 index 3d95501..0000000 --- a/src/SGE/Batch_BatchManager_eSGE.hxx +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2007-2012 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_eSGE.hxx : emulation of SGE client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#ifndef _BATCHMANAGER_ESGE_H_ -#define _BATCHMANAGER_ESGE_H_ - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_eSGE : public BatchManager_eClient - { - public: - // Constructeur et destructeur - BatchManager_eSGE(const FactBatchManager * parent, const char * host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host - virtual ~BatchManager_eSGE(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - virtual bool isRunning(const JobId & jobid); // teste si un job est present en machine - - virtual void setParametre(const JobId & jobid, const Parametre & param) { return alterJob(jobid, param); } // modifie un job en file d'attente - virtual void setEnvironnement(const JobId & jobid, const Environnement & env) { return alterJob(jobid, env); } // modifie un job en file d'attente - - virtual const Batch::JobId addJob(const Batch::Job & job, const std::string reference); // ajoute un nouveau job sans le soumettre - - protected: - void buildBatchScript(const Job & job); - std::string getWallTime(const long edt); - - private: - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - - }; - -} - -#endif diff --git a/src/SGE/Batch_FactBatchManager_eSGE.cxx b/src/SGE/Batch_FactBatchManager_eSGE.cxx deleted file mode 100644 index 19b575e..0000000 --- a/src/SGE/Batch_FactBatchManager_eSGE.cxx +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) 2007-2012 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_eSGE.cxx : - * - * Auteur : Bernard SECHER - CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#include "Batch_BatchManager_eSGE.hxx" -#include "Batch_FactBatchManager_eSGE.hxx" - -namespace Batch { - - static FactBatchManager_eSGE sFBM_eSGE; - - // Constructeur - FactBatchManager_eSGE::FactBatchManager_eSGE() : FactBatchManager_eClient("eSGE") - { - // Nothing to do - } - - // Destructeur - FactBatchManager_eSGE::~FactBatchManager_eSGE() - { - // Nothing to do - } - - // Functor - BatchManager * FactBatchManager_eSGE::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'"); - return new BatchManager_eSGE(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'"); - return new BatchManager_eSGE(this, hostname, username, protocolType, mpiImpl); - } - - -} diff --git a/src/SGE/Batch_FactBatchManager_eSGE.hxx b/src/SGE/Batch_FactBatchManager_eSGE.hxx deleted file mode 100644 index 84983b6..0000000 --- a/src/SGE/Batch_FactBatchManager_eSGE.hxx +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2007-2012 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_eSGE.hxx : - * - * Auteur : Bernard SECHER : CEA DEN - * Date : Avril 2008 - * Projet : PAL Salome - * - */ - -#ifndef _FACTBATCHMANAGER_eSGE_H_ -#define _FACTBATCHMANAGER_eSGE_H_ - -#include "Batch_Defines.hxx" - -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - class BATCH_EXPORT FactBatchManager_eSGE : public FactBatchManager_eClient - { - public: - // Constructeur et destructeur - FactBatchManager_eSGE(); - virtual ~FactBatchManager_eSGE(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - protected: - - private: - - }; - -} - -#endif diff --git a/src/SGE/Batch_JobInfo_eSGE.cxx b/src/SGE/Batch_JobInfo_eSGE.cxx deleted file mode 100644 index 7760544..0000000 --- a/src/SGE/Batch_JobInfo_eSGE.cxx +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_eSGE.cxx : emulation of SGE client - * - * Auteur : Bernard SECHER - CEA DEN - * Mail : mailto:bernard.secher@cea.fr - * Date : Thu Apr 24 10:17:22 2008 - * Projet : PAL Salome - * - */ - -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_JobInfo_eSGE.hxx" - -using namespace std; - -namespace Batch { - - - - // Constructeurs - JobInfo_eSGE::JobInfo_eSGE(int id, string logFile) : JobInfo() - { - // On remplit les membres _param et _env - ostringstream oss; - oss << id; - _param[ID] = oss.str(); - - // read of log file - char line[128]; - ifstream fp(logFile.c_str(),ios::in); - - string status; - string sline; - fp.getline(line,80,'\n'); - sline = string(line); - - if( sline.length() > 0 ){ - istringstream iss(sline); - iss >> status >> status >> status >> status >> status; - - if (status == "d") { // Deletion - _param[STATE] = FAILED; - } else if (status == "t") { // Transferring - _param[STATE] = IN_PROCESS; - } else if (status == "r") { // Running - _param[STATE] = RUNNING; - _running = true; - } else if (status == "R") { // Restarted - _param[STATE] = RUNNING; - _running = true; - } else if (status == "s") { // Suspended - _param[STATE] = PAUSED; - } else if (status == "S") { // Suspended - _param[STATE] = PAUSED; - } else if (status == "T") { // Threshold - _param[STATE] = PAUSED; - } else if (status == "qw") { // Queued and waiting - _param[STATE] = QUEUED; - } else if (status == "h") { // Hold - _param[STATE] = PAUSED; - } else { - cerr << "Unknown job state code: " << status << endl; - } - } else { - // TODO: Check this. I suppose that unknown jobs are finished ones. - _param[STATE] = FINISHED; - } - } - - // Teste si un job est present en machine - bool JobInfo_eSGE::isRunning() const - { - return _running; - } - - - // Destructeur - JobInfo_eSGE::~JobInfo_eSGE() - { - // Nothing to do - } - - // Convertit une date HH:MM:SS en secondes - long JobInfo_eSGE::HMStoLong(const string & s) - { - long hour, min, sec; - - sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); - return ( ( ( hour * 60L ) + min ) * 60L ) + sec; - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_eSGE::__str__() const - { - ostringstream sst; - sst << " +#include +#include + +#include "Constants.hxx" +#include "Parametre.hxx" +#include "Environnement.hxx" +#include "RunTimeException.hxx" +#include "APIInternalFailureException.hxx" +#include "JobInfo_SGE.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + + + // Constructeurs + JobInfo_SGE::JobInfo_SGE(int id, const std::string & output) : JobInfo() + { + // On remplit les membres _param et _nv + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + + // read of log file + char line[128]; + istringstream fp(output); + + string status; + string sline; + fp.getline(line,80,'\n'); + sline = string(line); + + if( sline.length() > 0 ){ + istringstream iss(sline); + iss >> status >> status >> status >> status >> status; + + if (status == "d") { // Deletion + _param[STATE] = FAILED; + } else if (status == "t") { // Transferring + _param[STATE] = IN_PROCESS; + } else if (status == "r") { // Running + _param[STATE] = RUNNING; + _running = true; + } else if (status == "R") { // Restarted + _param[STATE] = RUNNING; + _running = true; + } else if (status == "s") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "S") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "T") { // Threshold + _param[STATE] = PAUSED; + } else if (status == "qw") { // Queued and waiting + _param[STATE] = QUEUED; + } else if (status == "h") { // Hold + _param[STATE] = PAUSED; + } else { + LOG("Unknown job state code: " << status); + } + } else { + // TODO: Check this. I suppose that unknown jobs are finished ones. + _param[STATE] = FINISHED; + } + } + + // Teste si un job est present en machine + bool JobInfo_SGE::isRunning() const + { + return _running; + } + + + // Destructeur + JobInfo_SGE::~JobInfo_SGE() + { + // Nothing to do + } + + // Convertit une date HH:MM:SS en secondes + long JobInfo_SGE::HMStoLong(const string & s) + { + long hour, min, sec; + + sscanf( s.c_str(), "%ld:%ld:%ld", &hour, &min, &sec); + return ( ( ( hour * 60L ) + min ) * 60L ) + sec; + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_SGE::__str__() const + { + ostringstream sst; + sst << " -#include -#include -#include - -#include -#include -#include - -#ifdef MSVC -#include -#else -#include -#endif - -#include "Batch_Constants.hxx" -#include "Batch_BatchManager_eSSH.hxx" -#include "Batch_JobInfo_eSSH.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_eSSH::BatchManager_eSSH(const FactBatchManager * parent, const char * host, - const char * username, - CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl), - BatchManager_Local(parent, host, protocolType) - { - // Nothing to do - } - - // Destructeur - BatchManager_eSSH::~BatchManager_eSSH() - { - // Nothing to do - } - - // Methode pour le controle des jobs : soumet un job au gestionnaire - const JobId BatchManager_eSSH::submitJob(const Job & job) - { - // export input files on cluster - std::cerr << "BatchManager_eSSH::submitJob exportInputFiles" << std::endl; - Parametre param = job.getParametre(); - - // Input files copy - exportInputFiles(job); - - // Launch job - // Patch until Local Manager is patched - std::string executable = param[EXECUTABLE].str(); - std::string::size_type p1 = executable.find_last_of("/"); - std::string fileNameToExecute = "./" + executable.substr(p1+1); - Parametre new_param(param); - new_param[INFILE].eraseAll(); - new_param[OUTFILE].eraseAll(); - new_param[EXECUTABLE] = fileNameToExecute; - new_param[EXECUTIONHOST] = _hostname; - Job * j = new Job(new_param); - - - std::cerr << "BatchManager_eSSH::submitJob Local submitJob" << std::endl; - JobId id = BatchManager_Local::submitJob(*j); - delete j; - return id; - } - - // Methode pour le controle des jobs : retire un job du gestionnaire - void BatchManager_eSSH::deleteJob(const JobId & jobid) - { - BatchManager_Local::deleteJob(jobid); - } - - // Methode pour le controle des jobs : renvoie l'etat du job - JobInfo BatchManager_eSSH::queryJob(const JobId & jobid) - { - return BatchManager_Local::queryJob(jobid); - } - - // Methode pour le controle des jobs : suspend un job en file d'attente - void BatchManager_eSSH::holdJob(const JobId & jobid) - { - BatchManager_Local::holdJob(jobid); - } - - // Methode pour le controle des jobs : relache un job suspendu - void BatchManager_eSSH::releaseJob(const JobId & jobid) - { - BatchManager_Local::releaseJob(jobid); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSSH::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - BatchManager_Local::alterJob(jobid, param, env); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSSH::alterJob(const JobId & jobid, const Parametre & param) - { - BatchManager_Local::alterJob(jobid, param); - } - - // Methode pour le controle des jobs : modifie un job en file d'attente - void BatchManager_eSSH::alterJob(const JobId & jobid, const Environnement & env) - { - BatchManager_Local::alterJob(jobid, env); - } - - void BatchManager_eSSH::buildBatchScript(const Job & job) - { - Parametre params = job.getParametre(); - Environnement env = job.getEnvironnement(); - const long nbproc = params[NBPROC]; - const long edt = params[MAXWALLTIME]; - const long mem = params[MAXRAMSIZE]; - const string workDir = params[WORKDIR]; - const std::string dirForTmpFiles = params[TMPDIR]; - const string fileToExecute = params[EXECUTABLE]; - const string home = params[HOMEDIR]; - const std::string queue = params[QUEUE]; - std::string rootNameToExecute; - std::string fileNameToExecute; - std::string filelogtemp; - if( fileToExecute.size() > 0 ){ - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - -#ifdef MSVC - char fname[_MAX_FNAME]; - char ext[_MAX_EXT]; - _splitpath_s(fileToExecute.c_str(), NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT); - string execBaseName = string(fname) + ext; -#else - char* basec=strdup(fileToExecute.c_str()); - string execBaseName = string(basename(basec)); - free(basec); -#endif - - fileNameToExecute = "~/" + dirForTmpFiles + "/" + execBaseName; - - int idx = dirForTmpFiles.find("Batch/"); - filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); - } - else{ - rootNameToExecute = "command"; - } - - ofstream tempOutputFile; - std::string TmpFileName = createAndOpenTemporaryFile("SSH-script", tempOutputFile); - - tempOutputFile << "#! /bin/sh -f" << endl; - if (queue != "") - tempOutputFile << "#BSUB -q " << queue << endl; - if( edt > 0 ) - tempOutputFile << "#SSH -l walltime=" << edt*60 << endl ; - if( mem > 0 ) - tempOutputFile << "#SSH -l mem=" << mem << "mb" << endl ; - if( fileToExecute.size() > 0 ){ - tempOutputFile << "#SSH -o " << home << "/" << dirForTmpFiles << "/output.log." << filelogtemp << endl ; - tempOutputFile << "#SSH -e " << home << "/" << dirForTmpFiles << "/error.log." << filelogtemp << endl ; - } - else{ - tempOutputFile << "#SSH -o " << dirForTmpFiles << "/" << env["LOGFILE"] << ".output.log" << endl ; - tempOutputFile << "#SSH -e " << dirForTmpFiles << "/" << env["LOGFILE"] << ".error.log" << endl ; - } - if( workDir.size() > 0 ) - tempOutputFile << "cd " << workDir << endl ; - if( fileToExecute.size() > 0 ){ - tempOutputFile << _mpiImpl->boot("${SSH_NODEFILE}",nbproc); - tempOutputFile << _mpiImpl->run("${SSH_NODEFILE}",nbproc,fileNameToExecute); - tempOutputFile << _mpiImpl->halt(); - } - else{ - tempOutputFile << "source " << env["SOURCEFILE"] << endl ; - tempOutputFile << env["COMMAND"]; - } - - tempOutputFile.flush(); - tempOutputFile.close(); -#ifdef WIN32 - _chmod( -#else - chmod( -#endif - TmpFileName.c_str(), 0x1ED); - cerr << TmpFileName.c_str() << endl; - - int status = Batch::BatchManager_eClient::_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/SSH/Batch_BatchManager_eSSH.hxx b/src/SSH/Batch_BatchManager_eSSH.hxx deleted file mode 100644 index 29592bf..0000000 --- a/src/SSH/Batch_BatchManager_eSSH.hxx +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (C) 2007-2012 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_eSSH.hxx : emulation of SSH client - * - * Auteur : André RIBES - EDF R&D - * Date : Octobre 2009 - */ - -#ifndef _BATCHMANAGER_ESSH_H_ -#define _BATCHMANAGER_ESSH_H_ - -#include "Batch_Defines.hxx" -#include "Batch_JobId.hxx" -#include "Batch_JobInfo.hxx" -#include "Batch_FactBatchManager.hxx" -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_BatchManager_Local.hxx" - -namespace Batch { - - class BATCH_EXPORT BatchManager_eSSH : - virtual public BatchManager_eClient, - virtual public BatchManager_Local - { - public: - // Constructeur et destructeur - BatchManager_eSSH(const FactBatchManager * parent, const char * host="localhost", - const char * username="", - CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host - virtual ~BatchManager_eSSH(); - - // Recupere le nom du serveur par defaut - // static string BatchManager_LSF::getDefaultServer(); - - // Methodes pour le controle des jobs - virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire - virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire - virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job - - // Non implanté... - virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente - virtual void releaseJob(const JobId & jobid); // relache un job suspendu - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente - virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente - - - protected: - void buildBatchScript(const Job & job); - - private: - -#ifdef SWIG - public: - // Recupere le l'identifiant d'un job deja soumis au BatchManager - //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } - virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } -#endif - }; -} - -#endif diff --git a/src/SSH/Batch_FactBatchManager_eSSH.cxx b/src/SSH/Batch_FactBatchManager_eSSH.cxx deleted file mode 100644 index e016473..0000000 --- a/src/SSH/Batch_FactBatchManager_eSSH.cxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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_eSSH.cxx : - * - * Auteur : André RIBES : EDF R&D - * Date : Octobre 2009 - */ - -#include -#include "Batch_BatchManager_eSSH.hxx" -#include "Batch_FactBatchManager_eSSH.hxx" - -// Automatic register in the catalogue... -static Batch::FactBatchManager_eSSH sFBM_eSSH; - -Batch::FactBatchManager_eSSH::FactBatchManager_eSSH() : FactBatchManager_eClient("eSSH") {} - -Batch::FactBatchManager_eSSH::~FactBatchManager_eSSH() {} - -Batch::BatchManager * -Batch::FactBatchManager_eSSH::operator() (const char * hostname) const -{ - return new Batch::BatchManager_eSSH(this, hostname); -} - -Batch::BatchManager_eClient * -Batch::FactBatchManager_eSSH::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const -{ - //protocolType and mpiImpl are ignored. - std::cerr << "[Batch::FactBatchManager_eSSH] creating new Batch::BatchManager_eSSH with hostname = " << hostname << std::endl; - - return new Batch::BatchManager_eSSH(this, hostname, username); -} diff --git a/src/SSH/Batch_FactBatchManager_eSSH.hxx b/src/SSH/Batch_FactBatchManager_eSSH.hxx deleted file mode 100644 index 5f17dd4..0000000 --- a/src/SSH/Batch_FactBatchManager_eSSH.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) 2007-2012 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_eSSH.hxx : - * - * Auteur : André RIBES : EDF R&D - * Date : Octobre 2009 - */ - -#ifndef _FACTBATCHMANAGER_eSSH_H_ -#define _FACTBATCHMANAGER_eSSH_H_ - -#include "Batch_Defines.hxx" - -#include -#include -#include "Batch_BatchManager_eClient.hxx" -#include "Batch_FactBatchManager_eClient.hxx" - -namespace Batch { - - class BatchManager_eSSH; - - class BATCH_EXPORT FactBatchManager_eSSH : public FactBatchManager_eClient - { - public: - FactBatchManager_eSSH(); - virtual ~FactBatchManager_eSSH(); - - virtual BatchManager * operator() (const char * hostname) const; // From FactBacthManager - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; // From FactBatchManager_eClient - }; -} - -#endif diff --git a/src/SSH/Batch_JobInfo_eSSH.cxx b/src/SSH/Batch_JobInfo_eSSH.cxx deleted file mode 100644 index afc0538..0000000 --- a/src/SSH/Batch_JobInfo_eSSH.cxx +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (C) 2007-2012 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 -// -/* - * JobInfo_eSSH.cxx : emulation of SSH client - * - * Auteur : André RIBES - EDF R&D - * Date : Octobre 2009 - */ - -#include -#include -#include -#include - -#include "Batch_Constants.hxx" -#include "Batch_Parametre.hxx" -#include "Batch_Environnement.hxx" -#include "Batch_RunTimeException.hxx" -#include "Batch_APIInternalFailureException.hxx" -#include "Batch_JobInfo_eSSH.hxx" - -using namespace std; - -namespace Batch { - - // Constructeurs - JobInfo_eSSH::JobInfo_eSSH(int id, string status) : JobInfo() - { - // On remplit les membres _param et _env - ostringstream oss; - oss << id; - _param[ID] = oss.str(); - _param[STATE] = status; - } - - // Destructeur - JobInfo_eSSH::~JobInfo_eSSH() - { - // Nothing to do - } - - // Methode pour l'interfacage avec Python (SWIG) : affichage en Python - string JobInfo_eSSH::__str__() const - { - ostringstream sst; - sst << " +#include + +#include +#include +#include +#include + +#include "BatchManager_Slurm.hxx" +#include "JobInfo_Slurm.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_Slurm::BatchManager_Slurm(const FactBatchManager * parent, + const char * host, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) + : BatchManager(parent, host, username, protocolType, mpiImpl) + { + } + + BatchManager_Slurm::~BatchManager_Slurm() + { + } + + // Method to submit a job to the batch manager + const JobId BatchManager_Slurm::submitJob(const Job & job) + { + Parametre params = job.getParametre(); + const string workDir = params[WORKDIR]; + + // export input files on cluster + exportInputFiles(job); + + // build command file to submit the job and copy it on the server + string cmdFile = buildCommandFile(job); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; sbatch " + cmdFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // find id of submitted job in output + string search = "Submitted batch job "; + string::size_type pos = output.find(search); + if (pos == string::npos) + throw RunTimeException("Error in the submission of the job on the remote host"); + pos += search.size(); + string::size_type endl_pos = output.find('\n', pos); + string::size_type count = (endl_pos == string::npos)? string::npos : endl_pos - pos; + string jobref = output.substr(pos, count); + + JobId id(this, jobref); + return id; + } + + /** + * Create Slurm command file and copy it on the server. + * Return the name of the remote file. + */ + string BatchManager_Slurm::buildCommandFile(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + string tmpFileName = Utils::createAndOpenTemporaryFile("slurm-script", tempOutputFile); + + tempOutputFile << "#!/bin/bash" << endl; + tempOutputFile << "#SBATCH --output=" << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "#SBATCH --error=" << workDir << "/logs/error.log." << rootNameToExecute << endl; + + if (params.find(NAME) != params.end()) + tempOutputFile << "#SBATCH --job-name=\"" << params[NAME] << "\"" << endl; + + // Optional parameters + int nbproc = 1; + if (params.find(NBPROC) != params.end()) + nbproc = params[NBPROC]; + tempOutputFile << "#SBATCH --ntasks=" << nbproc << endl; + + if (params.find(EXCLUSIVE) != params.end()) { + if (params[EXCLUSIVE]) + tempOutputFile << "#SBATCH --exclusive" << endl; + else + tempOutputFile << "#SBATCH --share" << endl; + } + + if (params.find(MAXWALLTIME) != params.end()) + tempOutputFile << "#SBATCH --time=" << params[MAXWALLTIME] << endl; + if (params.find(MAXRAMSIZE) != params.end()) + tempOutputFile << "#SBATCH --mem=" << params[MAXRAMSIZE] << endl; + if (params.find(QUEUE) != params.end()) + tempOutputFile << "#SBATCH --partition=" << params[QUEUE] << endl; + + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "export " << iter->first << "=" << iter->second << endl; + } + + // generate nodes file + tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; + tempOutputFile << "srun hostname > $LIBBATCH_NODEFILE" << endl; + tempOutputFile << "export LIBBATCH_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl; + tempOutputFile << "./" + fileNameToExecute; + if (params.find(ARGUMENTS) != params.end()) { + Versatile V = params[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + tempOutputFile << " " << arg; + } + } + tempOutputFile << endl; + + // Remove the node file + tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << tmpFileName); + + string remoteFileName = rootNameToExecute + "_slurm.cmd"; + int status = _protocol.copyFile(tmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw RunTimeException("Cannot copy command file on host " + _hostname); + + return remoteFileName; + } + + void BatchManager_Slurm::deleteJob(const JobId & jobid) + { + // define command to delete job + string subCommand = "scancel " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + int status = system(command.c_str()); + if (status) + throw RunTimeException("Can't delete job " + jobid.getReference()); + + LOG("job " << jobid.getReference() << " killed"); + } + + JobInfo BatchManager_Slurm::queryJob(const JobId & jobid) + { + // define command to query batch + string subCommand = "squeue -o %t -j " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + string output; + Utils::getCommandOutput(command, output); + // We don't test the return code here because with jobs finished since a long time Slurm + // returns an error and a message like "slurm_load_jobs error: Invalid job id specified". + // So we consider that the job is finished when we get an error. + + JobInfo_Slurm jobinfo = JobInfo_Slurm(jobid.getReference(), output); + return jobinfo; + } + +} diff --git a/src/Slurm/BatchManager_Slurm.hxx b/src/Slurm/BatchManager_Slurm.hxx new file mode 100644 index 0000000..fd40a7f --- /dev/null +++ b/src/Slurm/BatchManager_Slurm.hxx @@ -0,0 +1,66 @@ +// Copyright (C) 2007-2012 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_Slurm.hxx : + * + * Created on: 12 may 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHMANAGER_ESLURM_H_ +#define _BATCHMANAGER_ESLURM_H_ + +#include + +#include +#include +#include +#include +#include + +namespace Batch { + + class BATCH_EXPORT BatchManager_Slurm : public BatchManager + { + public: + + BatchManager_Slurm(const FactBatchManager * parent, + const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, + const char * mpiImpl = "nompi"); + virtual ~BatchManager_Slurm(); + + // Methods to control jobs + virtual const JobId submitJob(const Job & job); + virtual void deleteJob(const JobId & jobid); + virtual JobInfo queryJob(const JobId & jobid); + + protected: + + std::string buildCommandFile(const Job & job); + + }; + +} + +#endif diff --git a/src/Slurm/Batch_BatchManager_eSlurm.cxx b/src/Slurm/Batch_BatchManager_eSlurm.cxx deleted file mode 100644 index 556012d..0000000 --- a/src/Slurm/Batch_BatchManager_eSlurm.cxx +++ /dev/null @@ -1,249 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eSlurm.cxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#include -#include - -#include -#include -#include - -#include "Batch_BatchManager_eSlurm.hxx" -#include "Batch_JobInfo_eSlurm.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_eSlurm::BatchManager_eSlurm(const FactBatchManager * parent, - const char * host, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) - : BatchManager(parent, host), - BatchManager_eClient(parent, host, username, protocolType, mpiImpl), - _nb_proc_per_node(nb_proc_per_node) - { - } - - BatchManager_eSlurm::~BatchManager_eSlurm() - { - } - - // Method to submit a job to the batch manager - const JobId BatchManager_eSlurm::submitJob(const Job & job) - { - Parametre params = job.getParametre(); - const string workDir = params[WORKDIR]; - - // export input files on cluster - exportInputFiles(job); - - // build command file to submit the job and copy it on the server - string cmdFile = buildCommandFile(job); - - // define command to submit batch - string subCommand = string("cd ") + workDir + "; sbatch " + cmdFile; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cout << command.c_str() << endl; - - // submit job - string output; - int status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) throw EmulationException("Can't submit job, error was: " + output); - - // find id of submitted job in output - string search = "Submitted batch job "; - string::size_type pos = output.find(search); - if (pos == string::npos) - throw EmulationException("Error in the submission of the job on the remote host"); - pos += search.size(); - string::size_type endl_pos = output.find('\n', pos); - string::size_type count = (endl_pos == string::npos)? string::npos : endl_pos - pos; - string jobref = output.substr(pos, count); - - JobId id(this, jobref); - return id; - } - - /** - * Create Slurm command file and copy it on the server. - * Return the name of the remote file. - */ - string BatchManager_eSlurm::buildCommandFile(const Job & job) - { - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - string tmpFileName = createAndOpenTemporaryFile("slurm-script", tempOutputFile); - - tempOutputFile << "#!/bin/bash" << endl; - tempOutputFile << "#SBATCH --output=" << workDir << "/logs/output.log." << rootNameToExecute << endl; - tempOutputFile << "#SBATCH --error=" << workDir << "/logs/error.log." << rootNameToExecute << endl; - - if (params.find(NAME) != params.end()) - tempOutputFile << "#SBATCH --job-name=\"" << params[NAME] << "\"" << endl; - - // Optional parameters - int nbproc = 1; - if (params.find(NBPROC) != params.end()) - nbproc = params[NBPROC]; - tempOutputFile << "#SBATCH --ntasks=" << nbproc << endl; - - if (params.find(EXCLUSIVE) != params.end()) { - if (params[EXCLUSIVE]) - tempOutputFile << "#SBATCH --exclusive" << endl; - else - tempOutputFile << "#SBATCH --share" << endl; - } - - if (params.find(MAXWALLTIME) != params.end()) - tempOutputFile << "#SBATCH --time=" << params[MAXWALLTIME] << endl; - if (params.find(MAXRAMSIZE) != params.end()) - tempOutputFile << "#SBATCH --mem=" << params[MAXRAMSIZE] << endl; - if (params.find(QUEUE) != params.end()) - tempOutputFile << "#SBATCH --partition=" << params[QUEUE] << endl; - - // Define environment for the job - Environnement env = job.getEnvironnement(); - for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { - tempOutputFile << "export " << iter->first << "=" << iter->second << endl; - } - - // generate nodes file - tempOutputFile << "LIBBATCH_NODEFILE=`mktemp nodefile-XXXXXXXXXX`" << endl; - tempOutputFile << "srun hostname > $LIBBATCH_NODEFILE" << endl; - tempOutputFile << "export LIBBATCH_NODEFILE" << endl; - - // Launch the executable - tempOutputFile << "cd " << workDir << endl; - tempOutputFile << "./" + fileNameToExecute << endl; - - // Remove the node file - tempOutputFile << "rm $LIBBATCH_NODEFILE" << endl; - - tempOutputFile.flush(); - tempOutputFile.close(); - - cerr << "Batch script file generated is: " << tmpFileName << endl; - - string remoteFileName = rootNameToExecute + "_slurm.cmd"; - int status = _protocol.copyFile(tmpFileName, "", "", - workDir + "/" + remoteFileName, - _hostname, _username); - if (status) - throw EmulationException("Cannot copy command file on host " + _hostname); - - return remoteFileName; - } - - void BatchManager_eSlurm::deleteJob(const JobId & jobid) - { - // define command to delete job - string subCommand = "scancel " + jobid.getReference(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - int status = system(command.c_str()); - if (status) - throw EmulationException("Can't delete job " + jobid.getReference()); - - cerr << "job " << jobid.getReference() << " killed" << endl; - } - - void BatchManager_eSlurm::holdJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eSlurm::holdJob"); - } - - void BatchManager_eSlurm::releaseJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eSlurm::releaseJob"); - } - - void BatchManager_eSlurm::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eSlurm::alterJob"); - } - - void BatchManager_eSlurm::alterJob(const JobId & jobid, const Parametre & param) - { - throw NotYetImplementedException("BatchManager_eSlurm::alterJob"); - } - - void BatchManager_eSlurm::alterJob(const JobId & jobid, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eSlurm::alterJob"); - } - - JobInfo BatchManager_eSlurm::queryJob(const JobId & jobid) - { - // define command to query batch - string subCommand = "squeue -o %t -j " + jobid.getReference(); - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - string output; - Utils::getCommandOutput(command, output); - // We don't test the return code here because with jobs finished since a long time Slurm - // returns an error and a message like "slurm_load_jobs error: Invalid job id specified". - // So we consider that the job is finished when we get an error. - - JobInfo_eSlurm jobinfo = JobInfo_eSlurm(jobid.getReference(), output); - return jobinfo; - } - - const JobId BatchManager_eSlurm::addJob(const Job & job, const string reference) - { - return JobId(this, reference); - } - -} diff --git a/src/Slurm/Batch_BatchManager_eSlurm.hxx b/src/Slurm/Batch_BatchManager_eSlurm.hxx deleted file mode 100644 index 839ff1e..0000000 --- a/src/Slurm/Batch_BatchManager_eSlurm.hxx +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eSlurm.hxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _BATCHMANAGER_ESLURM_H_ -#define _BATCHMANAGER_ESLURM_H_ - -#include - -#include -#include -#include -#include -#include - -namespace Batch { - - class BATCH_EXPORT BatchManager_eSlurm : public BatchManager_eClient - { - public: - - BatchManager_eSlurm(const FactBatchManager * parent, - const char * host = "localhost", - const char * username = "", - CommunicationProtocolType protocolType = SSH, - const char * mpiImpl = "nompi", - int nb_proc_per_node = 1); - virtual ~BatchManager_eSlurm(); - - // Methods to control jobs - virtual const JobId submitJob(const Job & job); - virtual void deleteJob(const JobId & jobid); - virtual void holdJob(const JobId & jobid); - virtual void releaseJob(const JobId & jobid); - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); - virtual void alterJob(const JobId & jobid, const Parametre & param); - virtual void alterJob(const JobId & jobid, const Environnement & env); - virtual JobInfo queryJob(const JobId & jobid); - virtual const JobId addJob(const Job & job, const std::string reference); - - protected: - - std::string buildCommandFile(const Job & job); - - int _nb_proc_per_node; - - }; - -} - -#endif diff --git a/src/Slurm/Batch_FactBatchManager_eSlurm.cxx b/src/Slurm/Batch_FactBatchManager_eSlurm.cxx deleted file mode 100644 index 36a217a..0000000 --- a/src/Slurm/Batch_FactBatchManager_eSlurm.cxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eSlurm.cxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#include - -#include "Batch_BatchManager_eSlurm.hxx" -#include "Batch_FactBatchManager_eSlurm.hxx" - -namespace Batch { - - static FactBatchManager_eSlurm sFBM_eSlurm; - - FactBatchManager_eSlurm::FactBatchManager_eSlurm() : FactBatchManager_eClient("eSLURM") - { - } - - FactBatchManager_eSlurm::~FactBatchManager_eSlurm() - { - } - - BatchManager * FactBatchManager_eSlurm::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_eSlurm on host '" << hostname << "'"); - return new BatchManager_eSlurm(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eSlurm::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_eSlurm on host '" << hostname << "'"); - return new BatchManager_eSlurm(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); - } - -} diff --git a/src/Slurm/Batch_FactBatchManager_eSlurm.hxx b/src/Slurm/Batch_FactBatchManager_eSlurm.hxx deleted file mode 100644 index 969763e..0000000 --- a/src/Slurm/Batch_FactBatchManager_eSlurm.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eSlurm.hxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _FACTBATCHMANAGER_ESLURM_H_ -#define _FACTBATCHMANAGER_ESLURM_H_ - -#include -#include -#include -#include - -namespace Batch { - - class BATCH_EXPORT FactBatchManager_eSlurm : public FactBatchManager_eClient - { - public: - - FactBatchManager_eSlurm(); - virtual ~FactBatchManager_eSlurm(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - }; - -} - -#endif diff --git a/src/Slurm/Batch_JobInfo_eSlurm.cxx b/src/Slurm/Batch_JobInfo_eSlurm.cxx deleted file mode 100644 index 3b2d711..0000000 --- a/src/Slurm/Batch_JobInfo_eSlurm.cxx +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eSlurm.cxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#include - -#include -#include - -#include "Batch_JobInfo_eSlurm.hxx" - -using namespace std; - -namespace Batch { - - JobInfo_eSlurm::JobInfo_eSlurm(const std::string & id, const std::string & queryOutput) - : JobInfo() - { - _param[ID] = id; - - // read query output, status should be on the second line - istringstream iss(queryOutput); - string status; - for (int i=0 ; i<2 ; i++) - getline(iss, status); - - if (status.size() == 0) { - // On some batch managers, the job is deleted as soon as it is finished, - // so we have to consider that an unknown job is a finished one, even if - // it is not always true. - _param[STATE] = FINISHED; - } else if (status == "CA") { // Canceled - _param[STATE] = FAILED; - } else if (status == "CD") { // Completed - _param[STATE] = FINISHED; - } else if (status == "CF") { // Configuring - _param[STATE] = QUEUED; - } else if (status == "CG") { // Completing - _param[STATE] = RUNNING; - } else if (status == "F") { // Failed - _param[STATE] = FAILED; - } else if (status == "NF") { // Node Fail - _param[STATE] = FAILED; - } else if (status == "PD") { // Pending - _param[STATE] = QUEUED; - } else if (status == "R") { // Running - _param[STATE] = RUNNING; - } else if (status == "S") { // Suspended - _param[STATE] = PAUSED; - } else if (status == "TO") { // Timeout - _param[STATE] = FAILED; - } else { - throw RunTimeException("Unknown job state code: \"" + status + "\""); - } - } - - JobInfo_eSlurm::~JobInfo_eSlurm() - { - } - -} diff --git a/src/Slurm/Batch_JobInfo_eSlurm.hxx b/src/Slurm/Batch_JobInfo_eSlurm.hxx deleted file mode 100644 index d9c4cc8..0000000 --- a/src/Slurm/Batch_JobInfo_eSlurm.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eSlurm.hxx : - * - * Created on: 12 may 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _JOBINFO_ESLURM_H_ -#define _JOBINFO_ESLURM_H_ - -#include - -#include - -namespace Batch { - - class JobInfo_eSlurm : public JobInfo - { - public: - - JobInfo_eSlurm(const std::string & id, const std::string & queryOutput); - virtual ~JobInfo_eSlurm(); - - }; - -} - -#endif diff --git a/src/Slurm/CMakeLists.txt b/src/Slurm/CMakeLists.txt index 5a1c432..e08f31d 100644 --- a/src/Slurm/CMakeLists.txt +++ b/src/Slurm/CMakeLists.txt @@ -20,13 +20,13 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST Slurm/Batch_BatchManager_eSlurm - Slurm/Batch_FactBatchManager_eSlurm - Slurm/Batch_JobInfo_eSlurm +SET(CLASS_LIST Slurm/BatchManager_Slurm + Slurm/FactBatchManager_Slurm + Slurm/JobInfo_Slurm ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -IF (TEST_ENABLED) - add_subdirectory(Test) -ENDIF (TEST_ENABLED) +IF (TEST_ENABLED AND HAS_SSH) + ADD_TEST(SLURM_SSH ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager SLURM SSH) +ENDIF (TEST_ENABLED AND HAS_SSH) diff --git a/src/Slurm/FactBatchManager_Slurm.cxx b/src/Slurm/FactBatchManager_Slurm.cxx new file mode 100644 index 0000000..c4814eb --- /dev/null +++ b/src/Slurm/FactBatchManager_Slurm.cxx @@ -0,0 +1,54 @@ +// Copyright (C) 2007-2012 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_Slurm.cxx : + * + * Created on: 12 may 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "BatchManager_Slurm.hxx" +#include "FactBatchManager_Slurm.hxx" + +namespace Batch { + + static FactBatchManager_Slurm sFBM_Slurm; + + FactBatchManager_Slurm::FactBatchManager_Slurm() : FactBatchManager("SLURM") + { + } + + FactBatchManager_Slurm::~FactBatchManager_Slurm() + { + } + + BatchManager * FactBatchManager_Slurm::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + return new BatchManager_Slurm(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/Slurm/FactBatchManager_Slurm.hxx b/src/Slurm/FactBatchManager_Slurm.hxx new file mode 100644 index 0000000..c37838c --- /dev/null +++ b/src/Slurm/FactBatchManager_Slurm.hxx @@ -0,0 +1,54 @@ +// Copyright (C) 2007-2012 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_Slurm.hxx : + * + * Created on: 12 may 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _FACTBATCHMANAGER_ESLURM_H_ +#define _FACTBATCHMANAGER_ESLURM_H_ + +#include +#include +#include + +namespace Batch { + + class BATCH_EXPORT FactBatchManager_Slurm : public FactBatchManager + { + public: + + FactBatchManager_Slurm(); + virtual ~FactBatchManager_Slurm(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + + }; + +} + +#endif diff --git a/src/Slurm/JobInfo_Slurm.cxx b/src/Slurm/JobInfo_Slurm.cxx new file mode 100644 index 0000000..6e8aac5 --- /dev/null +++ b/src/Slurm/JobInfo_Slurm.cxx @@ -0,0 +1,85 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Slurm.cxx : + * + * Created on: 12 may 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include +#include + +#include "JobInfo_Slurm.hxx" + +using namespace std; + +namespace Batch { + + JobInfo_Slurm::JobInfo_Slurm(const std::string & id, const std::string & queryOutput) + : JobInfo() + { + _param[ID] = id; + + // read query output, status should be on the second line + istringstream iss(queryOutput); + string status; + for (int i=0 ; i<2 ; i++) + getline(iss, status); + + if (status.size() == 0) { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } else if (status == "CA") { // Canceled + _param[STATE] = FAILED; + } else if (status == "CD") { // Completed + _param[STATE] = FINISHED; + } else if (status == "CF") { // Configuring + _param[STATE] = QUEUED; + } else if (status == "CG") { // Completing + _param[STATE] = RUNNING; + } else if (status == "F") { // Failed + _param[STATE] = FAILED; + } else if (status == "NF") { // Node Fail + _param[STATE] = FAILED; + } else if (status == "PD") { // Pending + _param[STATE] = QUEUED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "S") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "TO") { // Timeout + _param[STATE] = FAILED; + } else { + throw RunTimeException("Unknown job state code: \"" + status + "\""); + } + } + + JobInfo_Slurm::~JobInfo_Slurm() + { + } + +} diff --git a/src/Slurm/JobInfo_Slurm.hxx b/src/Slurm/JobInfo_Slurm.hxx new file mode 100644 index 0000000..cb03982 --- /dev/null +++ b/src/Slurm/JobInfo_Slurm.hxx @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Slurm.hxx : + * + * Created on: 12 may 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _JOBINFO_ESLURM_H_ +#define _JOBINFO_ESLURM_H_ + +#include + +#include + +namespace Batch { + + class JobInfo_Slurm : public JobInfo + { + public: + + JobInfo_Slurm(const std::string & id, const std::string & queryOutput); + virtual ~JobInfo_Slurm(); + + }; + +} + +#endif diff --git a/src/Slurm/Test/CMakeLists.txt b/src/Slurm/Test/CMakeLists.txt deleted file mode 100644 index 3163654..0000000 --- a/src/Slurm/Test/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# 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-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) - -# set the include directories -include_directories(${CMAKE_SOURCE_DIR}/src/Core) -include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -# Build the test programs and add the tests -add_executable(Test_eSlurm Test_eSlurm.cxx) -target_link_libraries(Test_eSlurm Batch SimpleParser) - -IF (HAS_SSH) - ADD_TEST(eSlurm_SSH Test_eSlurm SSH) -ENDIF (HAS_SSH) - -#IF (HAS_RSH) -# ADD_TEST(eSlurm_RSH Test_eSlurm RSH) -#ENDIF (HAS_RSH) diff --git a/src/Slurm/Test/Test_eSlurm.cxx b/src/Slurm/Test/Test_eSlurm.cxx deleted file mode 100644 index 38b5d15..0000000 --- a/src/Slurm/Test/Test_eSlurm.cxx +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2007-2012 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_eSlurm.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : May 2011 - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -void print_usage() -{ - cout << "usage: Test_eSlurm PROTOCOL" << endl; - cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; -} - -int main(int argc, char** argv) -{ - // Parse argument - if (argc != 2) { - print_usage(); - return 1; - } - CommunicationProtocolType protocol; - if (strcmp(argv[1], "SSH") == 0) - protocol = SSH; - else if (strcmp(argv[1], "RSH") == 0) - protocol = RSH; - else { - print_usage(); - return 1; - } - - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on Slurm emulation. Passwordless" << endl; - cout << "authentication must be used for this test to pass. For SSH, this can be configured with" << endl; - cout << "ssh-agent for instance. For RSH, this can be configured with the .rhosts file." << 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_ESLURM_HOMEDIR"); - const string & host = parser.getValue("TEST_ESLURM_HOST"); - const string & user = parser.getValue("TEST_ESLURM_USER"); - int timeout = parser.getValueAsInt("TEST_ESLURM_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "./test-script.sh"; - p[NAME] = string("Test eSLURM ") + argv[1]; - 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[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 50; - p[HOMEDIR] = homedir; - p[EXCLUSIVE] = true; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - 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("eSLURM")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - } else if (state == FAILED) { - cerr << "Job " << jobid.__repr__() << " finished in error" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - return 1; - } 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 - try { - SimpleParser resultParser; - resultParser.parse("resultdir/seconddirname/result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/Slurm/Test/seta.sh b/src/Slurm/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/Slurm/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/Slurm/Test/setb.sh b/src/Slurm/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/Slurm/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/Slurm/Test/test-script.sh b/src/Slurm/Test/test-script.sh deleted file mode 100755 index 1d56247..0000000 --- a/src/Slurm/Test/test-script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -. ./seta.sh -. ./setb.sh - -c=`expr $a "*" $b` - -echo "MYENVVAR = $MYENVVAR" > result.txt -echo "c = $c" >> result.txt diff --git a/src/Vishnu/BatchManager_Vishnu.cxx b/src/Vishnu/BatchManager_Vishnu.cxx new file mode 100644 index 0000000..4b7fe00 --- /dev/null +++ b/src/Vishnu/BatchManager_Vishnu.cxx @@ -0,0 +1,329 @@ +// Copyright (C) 2007-2012 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_Vishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef WIN32 +#include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "BatchManager_Vishnu.hxx" +#include "JobInfo_Vishnu.hxx" +#include "Log.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_Vishnu::BatchManager_Vishnu(const FactBatchManager * parent, + const char * host, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) + : // Force SH protocol for Vishnu + BatchManager(parent, host, username, SH, mpiImpl) + { + } + + BatchManager_Vishnu::~BatchManager_Vishnu() + { + } + + // Method to submit a job to the batch manager + const JobId BatchManager_Vishnu::submitJob(const Job & job) + { + // export input files on cluster + exportInputFiles(job); + + // build command file to submit the job + string cmdFile = buildCommandFile(job); + + // define extra parameters (that can not be defined in the command file) + Parametre params = job.getParametre(); + ostringstream extraParams; + if (params.find(NBPROC) != params.end()) + extraParams << "-P " << params[NBPROC] << " "; + if (params.find(MAXRAMSIZE) != params.end()) + extraParams << "-m " << params[MAXRAMSIZE] << " "; + + // define command to submit batch + string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); + subCommand += "vishnu_connect && "; + subCommand += "vishnu_submit_job " + extraParams.str() + _hostname + " " + cmdFile + " && "; + subCommand += "vishnu_close"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + + // submit job + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) throw RunTimeException("Can't submit job, error was: " + output); + + // find id of submitted job in output + string search = "Job Id : "; + string::size_type pos = output.find(search); + if (pos == string::npos) + throw RunTimeException("Error in the submission of the job on the remote host"); + pos += search.size(); + string::size_type endl_pos = output.find('\n', pos); + string::size_type count = (endl_pos == string::npos)? string::npos : endl_pos - pos; + string jobref = output.substr(pos, count); + if (jobref.size() == 0) + throw RunTimeException("Error in the submission of the job on the remote host"); + + JobId id(this, jobref); + return id; + } + + + void BatchManager_Vishnu::exportInputFiles(const Job& job) + { + Parametre params = job.getParametre(); + string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); + subCommand += "vishnu_connect && "; + + // create remote directories + subCommand += "vishnu_create_dir -p " + _hostname + ":" + params[WORKDIR].str() + "/logs && "; + + // copy executable + string executeFile = params[EXECUTABLE]; + if (executeFile.size() != 0) { + subCommand += "vishnu_copy_file " + executeFile + " " + + _hostname + ":" + params[WORKDIR].str() + "/ && "; + } + + // copy filesToExportList + const Versatile & V = params[INFILE]; + Versatile::const_iterator Vit; + for (Vit=V.begin(); Vit!=V.end(); Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple inputFile = cpt; + + // Get absolute paths + char * buf = getcwd(NULL, 0); + string cwd = buf; + free(buf); + + string absremote = (Utils::isAbsolutePath(inputFile.getRemote()))? + inputFile.getRemote() : + params[WORKDIR].str() + "/" + inputFile.getRemote(); + string abslocal = (Utils::isAbsolutePath(inputFile.getLocal()))? + inputFile.getLocal() : + cwd + "/" + inputFile.getLocal(); + + if (Vit != V.begin()) + subCommand += " && "; + subCommand += "vishnu_copy_file " + abslocal + " " + _hostname + ":" + absremote; + } + subCommand += " && vishnu_close"; + + // Execute command + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + string output; + int status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) + throw RunTimeException("Can't copy input files, error was: " + output); + } + + /** + * Create Vishnu command file and copy it on the server. + * Return the name of the remote file. + */ + string BatchManager_Vishnu::buildCommandFile(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw RunTimeException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw RunTimeException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + string tmpFileName = Utils::createAndOpenTemporaryFile("vishnu-script", tempOutputFile); + + tempOutputFile << "#!/bin/sh" << endl; + tempOutputFile << "#% vishnu_output=" << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "#% vishnu_rror=" << workDir << "/logs/error.log." << rootNameToExecute << endl; + + if (params.find(NAME) != params.end()) + tempOutputFile << "#% vishnu_job_name=\"" << params[NAME] << "\"" << endl; + + // Optional parameters + if (params.find(MAXWALLTIME) != params.end()) { + long totalMinutes = params[MAXWALLTIME]; + long h = totalMinutes / 60; + long m = totalMinutes - h * 60; + tempOutputFile << "#% vishnu_wallclocklimit=" << h << ":"; + if (m < 10) + tempOutputFile << "0"; + tempOutputFile << m << ":00" << endl; + } + if (params.find(QUEUE) != params.end()) + tempOutputFile << "#% vishnu_queue=" << params[QUEUE] << endl; + + // Define environment for the job + Environnement env = job.getEnvironnement(); + for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { + tempOutputFile << "export " << iter->first << "=" << iter->second << endl; + } + + // Node file + tempOutputFile << "export LIBBATCH_NODEFILE=$VISHNU_BATCHJOB_NODEFILE" << endl; + + // Launch the executable + tempOutputFile << "cd " << workDir << endl; + tempOutputFile << "./" + fileNameToExecute; + if (params.find(ARGUMENTS) != params.end()) { + Versatile V = params[ARGUMENTS]; + for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) { + StringType argt = * static_cast(*it); + string arg = argt; + tempOutputFile << " " << arg; + } + } + tempOutputFile << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + LOG("Batch script file generated is: " << tmpFileName); + return tmpFileName; + } + + void BatchManager_Vishnu::deleteJob(const JobId & jobid) + { + // define command to delete job + string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); + subCommand += "vishnu_connect && "; + subCommand += "vishnu_cancel_job " + _hostname + " " + jobid.getReference() + " && "; + subCommand += "vishnu_close"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + int status = system(command.c_str()); + if (status) + throw RunTimeException("Can't delete job " + jobid.getReference()); + + LOG("job " << jobid.getReference() << " killed"); + } + + JobInfo BatchManager_Vishnu::queryJob(const JobId & jobid) + { + // define command to query batch + string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); + subCommand += "vishnu_connect && "; + subCommand += "vishnu_get_job_info " + _hostname + " " + jobid.getReference() + " && "; + subCommand += "vishnu_close"; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + LOG(command); + + string output; + int status = Utils::getCommandOutput(command, output); + if (status != 0) + throw RunTimeException("Can't query job " + jobid.getReference()); + JobInfo_Vishnu jobinfo = JobInfo_Vishnu(jobid.getReference(), output); + return jobinfo; + } + + void BatchManager_Vishnu::importOutputFiles(const Job & job, const std::string directory) + { + // Create local result directory + char * buf = getcwd(NULL, 0); + string cwd = buf; + free(buf); + string absdir = (Utils::isAbsolutePath(directory))? directory : cwd + "/" + directory; + int status = CommunicationProtocol::getInstance(SH).makeDirectory(absdir, "", ""); + if (status != 0) { + throw RunTimeException("Can't create result directory"); + } + + string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); + subCommand += "vishnu_connect && "; + + // Copy output files + Parametre params = job.getParametre(); + const Versatile & V = params[OUTFILE]; + Versatile::const_iterator Vit; + for (Vit=V.begin(); Vit!=V.end(); Vit++) { + CoupleType cpt = *static_cast< CoupleType * >(*Vit); + Couple outputFile = cpt; + + // Get absolute paths + string absremote = (Utils::isAbsolutePath(outputFile.getRemote()))? + outputFile.getRemote() : + params[WORKDIR].str() + "/" + outputFile.getRemote(); + string abslocal = (Utils::isAbsolutePath(outputFile.getLocal()))? + outputFile.getLocal() : + absdir + "/" + outputFile.getLocal(); + + subCommand += "vishnu_copy_file " + _hostname + ":" + absremote + " " + abslocal + " && "; + } + + // Copy logs + subCommand += "vishnu_copy_file -r " +_hostname + ":" + params[WORKDIR].str() + "/logs" + " " + absdir + " && "; + subCommand += "vishnu_close"; + + // Execute command + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " 2>&1"; + LOG(command); + string output; + status = Utils::getCommandOutput(command, output); + LOG(output); + if (status != 0) + throw RunTimeException("Can't import output files, error was: " + output); + } + +} diff --git a/src/Vishnu/BatchManager_Vishnu.hxx b/src/Vishnu/BatchManager_Vishnu.hxx new file mode 100644 index 0000000..c558ec1 --- /dev/null +++ b/src/Vishnu/BatchManager_Vishnu.hxx @@ -0,0 +1,68 @@ +// Copyright (C) 2007-2012 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_Vishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHMANAGER_EVISHNU_H_ +#define _BATCHMANAGER_EVISHNU_H_ + +#include + +#include +#include +#include +#include +#include + +namespace Batch { + + class BATCH_EXPORT BatchManager_Vishnu : public BatchManager + { + public: + + BatchManager_Vishnu(const FactBatchManager * parent, + const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, + const char * mpiImpl = "nompi"); + virtual ~BatchManager_Vishnu(); + + // Methods to control jobs + virtual const JobId submitJob(const Job & job); + virtual void deleteJob(const JobId & jobid); + virtual JobInfo queryJob(const JobId & jobid); + virtual void importOutputFiles(const Job & job, const std::string directory); + + protected: + + std::string buildCommandFile(const Job & job); + void exportInputFiles(const Job & job); + + }; + +} + +#endif diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.cxx b/src/Vishnu/Batch_BatchManager_eVishnu.cxx deleted file mode 100644 index 9c39013..0000000 --- a/src/Vishnu/Batch_BatchManager_eVishnu.cxx +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eVishnu.cxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef WIN32 -#include -#endif - -#include -#include -#include -#include - -#include -#include -#include - -#include "Batch_BatchManager_eVishnu.hxx" -#include "Batch_JobInfo_eVishnu.hxx" - -using namespace std; - -namespace Batch { - - BatchManager_eVishnu::BatchManager_eVishnu(const FactBatchManager * parent, - const char * host, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) - : BatchManager(parent, host), - // Force SH protocol for Vishnu - BatchManager_eClient(parent, host, username, SH, mpiImpl), - _nb_proc_per_node(nb_proc_per_node) - { - } - - BatchManager_eVishnu::~BatchManager_eVishnu() - { - } - - // Method to submit a job to the batch manager - const JobId BatchManager_eVishnu::submitJob(const Job & job) - { - // export input files on cluster - exportInputFiles(job); - - // build command file to submit the job - string cmdFile = buildCommandFile(job); - - // define extra parameters (that can not be defined in the command file) - Parametre params = job.getParametre(); - ostringstream extraParams; - if (params.find(NBPROC) != params.end()) - extraParams << "-P " << params[NBPROC] << " "; - if (params.find(MAXRAMSIZE) != params.end()) - extraParams << "-m " << params[MAXRAMSIZE] << " "; - - // define command to submit batch - string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); - subCommand += "vishnu_connect && "; - subCommand += "vishnu_submit_job " + extraParams.str() + _hostname + " " + cmdFile + " && "; - subCommand += "vishnu_close"; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cerr << command.c_str() << endl; - - // submit job - string output; - int status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) throw EmulationException("Can't submit job, error was: " + output); - - // find id of submitted job in output - string search = "Job Id : "; - string::size_type pos = output.find(search); - if (pos == string::npos) - throw EmulationException("Error in the submission of the job on the remote host"); - pos += search.size(); - string::size_type endl_pos = output.find('\n', pos); - string::size_type count = (endl_pos == string::npos)? string::npos : endl_pos - pos; - string jobref = output.substr(pos, count); - if (jobref.size() == 0) - throw EmulationException("Error in the submission of the job on the remote host"); - - JobId id(this, jobref); - return id; - } - - - void BatchManager_eVishnu::exportInputFiles(const Job& job) - { - Parametre params = job.getParametre(); - string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); - subCommand += "vishnu_connect && "; - - // create remote directories - subCommand += "vishnu_create_dir -p " + _hostname + ":" + params[WORKDIR].str() + "/logs && "; - - // copy executable - string executeFile = params[EXECUTABLE]; - if (executeFile.size() != 0) { - subCommand += "vishnu_copy_file " + executeFile + " " + - _hostname + ":" + params[WORKDIR].str() + "/ && "; - } - - // copy filesToExportList - const Versatile & V = params[INFILE]; - Versatile::const_iterator Vit; - for (Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple inputFile = cpt; - - // Get absolute paths - char * buf = getcwd(NULL, 0); - string cwd = buf; - free(buf); - - string absremote = (Utils::isAbsolutePath(inputFile.getRemote()))? - inputFile.getRemote() : - params[WORKDIR].str() + "/" + inputFile.getRemote(); - string abslocal = (Utils::isAbsolutePath(inputFile.getLocal()))? - inputFile.getLocal() : - cwd + "/" + inputFile.getLocal(); - - if (Vit != V.begin()) - subCommand += " && "; - subCommand += "vishnu_copy_file " + abslocal + " " + _hostname + ":" + absremote; - } - subCommand += " && vishnu_close"; - - // Execute command - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cerr << command.c_str() << endl; - string output; - int status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) - throw EmulationException("Can't copy input files, error was: " + output); - } - - /** - * Create Vishnu command file and copy it on the server. - * Return the name of the remote file. - */ - string BatchManager_eVishnu::buildCommandFile(const Job & job) - { - Parametre params = job.getParametre(); - - // Job Parameters - string workDir = ""; - string fileToExecute = ""; - string queue = ""; - - // Mandatory parameters - if (params.find(WORKDIR) != params.end()) - workDir = params[WORKDIR].str(); - else - throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job."); - if (params.find(EXECUTABLE) != params.end()) - fileToExecute = params[EXECUTABLE].str(); - else - throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job."); - - string::size_type p1 = fileToExecute.find_last_of("/"); - string::size_type p2 = fileToExecute.find_last_of("."); - string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); - string fileNameToExecute = fileToExecute.substr(p1+1); - - // Create batch submit file - ofstream tempOutputFile; - string tmpFileName = createAndOpenTemporaryFile("vishnu-script", tempOutputFile); - - tempOutputFile << "#!/bin/sh" << endl; - tempOutputFile << "#% vishnu_output=" << workDir << "/logs/output.log." << rootNameToExecute << endl; - tempOutputFile << "#% vishnu_error=" << workDir << "/logs/error.log." << rootNameToExecute << endl; - - if (params.find(NAME) != params.end()) - tempOutputFile << "#% vishnu_job_name=\"" << params[NAME] << "\"" << endl; - - // Optional parameters - if (params.find(MAXWALLTIME) != params.end()) { - long totalMinutes = params[MAXWALLTIME]; - long h = totalMinutes / 60; - long m = totalMinutes - h * 60; - tempOutputFile << "#% vishnu_wallclocklimit=" << h << ":"; - if (m < 10) - tempOutputFile << "0"; - tempOutputFile << m << ":00" << endl; - } - if (params.find(QUEUE) != params.end()) - tempOutputFile << "#% vishnu_queue=" << params[QUEUE] << endl; - - // Define environment for the job - Environnement env = job.getEnvironnement(); - for (Environnement::const_iterator iter = env.begin() ; iter != env.end() ; ++iter) { - tempOutputFile << "export " << iter->first << "=" << iter->second << endl; - } - - // Node file - tempOutputFile << "export LIBBATCH_NODEFILE=$VISHNU_BATCHJOB_NODEFILE" << endl; - - // Launch the executable - tempOutputFile << "cd " << workDir << endl; - tempOutputFile << "./" + fileNameToExecute << endl; - - tempOutputFile.flush(); - tempOutputFile.close(); - - cerr << "Batch script file generated is: " << tmpFileName << endl; - return tmpFileName; - } - - void BatchManager_eVishnu::deleteJob(const JobId & jobid) - { - // define command to delete job - string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); - subCommand += "vishnu_connect && "; - subCommand += "vishnu_cancel_job " + _hostname + " " + jobid.getReference() + " && "; - subCommand += "vishnu_close"; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - int status = system(command.c_str()); - if (status) - throw EmulationException("Can't delete job " + jobid.getReference()); - - cerr << "job " << jobid.getReference() << " killed" << endl; - } - - void BatchManager_eVishnu::holdJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eVishnu::holdJob"); - } - - void BatchManager_eVishnu::releaseJob(const JobId & jobid) - { - throw NotYetImplementedException("BatchManager_eVishnu::releaseJob"); - } - - void BatchManager_eVishnu::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); - } - - void BatchManager_eVishnu::alterJob(const JobId & jobid, const Parametre & param) - { - throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); - } - - void BatchManager_eVishnu::alterJob(const JobId & jobid, const Environnement & env) - { - throw NotYetImplementedException("BatchManager_eVishnu::alterJob"); - } - - JobInfo BatchManager_eVishnu::queryJob(const JobId & jobid) - { - // define command to query batch - string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); - subCommand += "vishnu_connect && "; - subCommand += "vishnu_get_job_info " + _hostname + " " + jobid.getReference() + " && "; - subCommand += "vishnu_close"; - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - cerr << command.c_str() << endl; - - string output; - int status = Utils::getCommandOutput(command, output); - if (status != 0) - throw EmulationException("Can't query job " + jobid.getReference()); - JobInfo_eVishnu jobinfo = JobInfo_eVishnu(jobid.getReference(), output); - return jobinfo; - } - - const JobId BatchManager_eVishnu::addJob(const Job & job, const string reference) - { - return JobId(this, reference); - } - - void BatchManager_eVishnu::importOutputFiles(const Job & job, const std::string directory) - { - // Create local result directory - char * buf = getcwd(NULL, 0); - string cwd = buf; - free(buf); - string absdir = (Utils::isAbsolutePath(directory))? directory : cwd + "/" + directory; - int status = CommunicationProtocol::getInstance(SH).makeDirectory(absdir, "", ""); - if (status != 0) { - throw EmulationException("Can't create result directory"); - } - - string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; "); - subCommand += "vishnu_connect && "; - - // Copy output files - Parametre params = job.getParametre(); - const Versatile & V = params[OUTFILE]; - Versatile::const_iterator Vit; - for (Vit=V.begin(); Vit!=V.end(); Vit++) { - CoupleType cpt = *static_cast< CoupleType * >(*Vit); - Couple outputFile = cpt; - - // Get absolute paths - string absremote = (Utils::isAbsolutePath(outputFile.getRemote()))? - outputFile.getRemote() : - params[WORKDIR].str() + "/" + outputFile.getRemote(); - string abslocal = (Utils::isAbsolutePath(outputFile.getLocal()))? - outputFile.getLocal() : - absdir + "/" + outputFile.getLocal(); - - subCommand += "vishnu_copy_file " + _hostname + ":" + absremote + " " + abslocal + " && "; - } - - // Copy logs - subCommand += "vishnu_copy_file -r " +_hostname + ":" + params[WORKDIR].str() + "/logs" + " " + absdir + " && "; - subCommand += "vishnu_close"; - - // Execute command - string command = _protocol.getExecCommand(subCommand, _hostname, _username); - command += " 2>&1"; - cerr << command.c_str() << endl; - string output; - status = Utils::getCommandOutput(command, output); - cout << output; - if (status != 0) - throw EmulationException("Can't import output files, error was: " + output); - } - -} diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.hxx b/src/Vishnu/Batch_BatchManager_eVishnu.hxx deleted file mode 100644 index 094547a..0000000 --- a/src/Vishnu/Batch_BatchManager_eVishnu.hxx +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2007-2012 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_BatchManager_eVishnu.hxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _BATCHMANAGER_EVISHNU_H_ -#define _BATCHMANAGER_EVISHNU_H_ - -#include - -#include -#include -#include -#include -#include - -namespace Batch { - - class BATCH_EXPORT BatchManager_eVishnu : public BatchManager_eClient - { - public: - - BatchManager_eVishnu(const FactBatchManager * parent, - const char * host = "localhost", - const char * username = "", - CommunicationProtocolType protocolType = SSH, - const char * mpiImpl = "nompi", - int nb_proc_per_node = 1); - virtual ~BatchManager_eVishnu(); - - // Methods to control jobs - virtual const JobId submitJob(const Job & job); - virtual void deleteJob(const JobId & jobid); - virtual void holdJob(const JobId & jobid); - virtual void releaseJob(const JobId & jobid); - virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); - virtual void alterJob(const JobId & jobid, const Parametre & param); - virtual void alterJob(const JobId & jobid, const Environnement & env); - virtual JobInfo queryJob(const JobId & jobid); - virtual const JobId addJob(const Job & job, const std::string reference); - virtual void importOutputFiles(const Job & job, const std::string directory); - - protected: - - std::string buildCommandFile(const Job & job); - void exportInputFiles(const Job & job); - - int _nb_proc_per_node; - - }; - -} - -#endif diff --git a/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx b/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx deleted file mode 100644 index 3f4fc4f..0000000 --- a/src/Vishnu/Batch_FactBatchManager_eVishnu.cxx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eVishnu.cxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#include - -#include "Batch_BatchManager_eVishnu.hxx" -#include "Batch_FactBatchManager_eVishnu.hxx" - -namespace Batch { - - static FactBatchManager_eVishnu sFBM_eVishnu; - - FactBatchManager_eVishnu::FactBatchManager_eVishnu() : FactBatchManager_eClient("eVISHNU") - { - } - - FactBatchManager_eVishnu::~FactBatchManager_eVishnu() - { - } - - BatchManager * FactBatchManager_eVishnu::operator() (const char * hostname) const - { - // MESSAGE("Building new BatchManager_eVishnu on host '" << hostname << "'"); - return new BatchManager_eVishnu(this, hostname); - } - - BatchManager_eClient * FactBatchManager_eVishnu::operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node) const - { - // MESSAGE("Building new BatchManager_eVishnu on host '" << hostname << "'"); - return new BatchManager_eVishnu(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); - } - -} diff --git a/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx b/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx deleted file mode 100644 index 5bfaaeb..0000000 --- a/src/Vishnu/Batch_FactBatchManager_eVishnu.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2007-2012 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_FactBatchManager_eVishnu.hxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _FACTBATCHMANAGER_EVISHNU_H_ -#define _FACTBATCHMANAGER_EVISHNU_H_ - -#include -#include -#include -#include - -namespace Batch { - - class BATCH_EXPORT FactBatchManager_eVishnu : public FactBatchManager_eClient - { - public: - - FactBatchManager_eVishnu(); - virtual ~FactBatchManager_eVishnu(); - - virtual BatchManager * operator() (const char * hostname) const; - virtual BatchManager_eClient * operator() (const char * hostname, - const char * username, - CommunicationProtocolType protocolType, - const char * mpiImpl, - int nb_proc_per_node = 1) const; - - }; - -} - -#endif diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.cxx b/src/Vishnu/Batch_JobInfo_eVishnu.cxx deleted file mode 100644 index d4b89d4..0000000 --- a/src/Vishnu/Batch_JobInfo_eVishnu.cxx +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eVishnu.cxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#include -#include - -#include -#include - -#include "Batch_JobInfo_eVishnu.hxx" - -using namespace std; - -namespace Batch { - - JobInfo_eVishnu::JobInfo_eVishnu(const string & id, const string & queryOutput) - : JobInfo() - { - _param[ID] = id; - - // find the status in the query output - istringstream iss(queryOutput); - string status; - bool statusFound = false; - while (!statusFound && !iss.eof()) { - string line; - getline(iss, line); - size_t pos = line.find(':'); - if (pos != string::npos) { - string begline = line.substr(0, pos); - string keyword; - // Trim leading and trailing spaces of the string before ':' - size_t startpos = begline.find_first_not_of(" \t"); - size_t endpos = begline.find_last_not_of(" \t"); - if (startpos != string::npos && endpos != string::npos) - keyword = begline.substr(startpos, endpos-startpos+1); - - if (keyword == "Status") { - statusFound = true; - string endline = line.substr(pos + 1); - startpos = endline.find_first_not_of(" \t"); - endpos = endline.find_last_not_of(" \t"); - if (startpos != string::npos && endpos != string::npos) - status = endline.substr(startpos, endpos-startpos+1); - } - } - } - - if (status.size() == 0) { - // On some batch managers, the job is deleted as soon as it is finished, - // so we have to consider that an unknown job is a finished one, even if - // it is not always true. - _param[STATE] = FINISHED; - } else if (status == "QUEUED") { - _param[STATE] = QUEUED; - } else if (status == "WAITING") { - _param[STATE] = QUEUED; - } else if (status == "RUNNING") { - _param[STATE] = RUNNING; - } else if (status == "TERMINATED") { - _param[STATE] = FINISHED; - } else if (status == "CANCELLED") { - _param[STATE] = FAILED; - } else { - throw RunTimeException("Unknown job state code: \"" + status + "\""); - } - } - - JobInfo_eVishnu::~JobInfo_eVishnu() - { - } - -} diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.hxx b/src/Vishnu/Batch_JobInfo_eVishnu.hxx deleted file mode 100644 index 5341495..0000000 --- a/src/Vishnu/Batch_JobInfo_eVishnu.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (C) 2007-2012 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_JobInfo_eVishnu.hxx : - * - * Created on: 24 june 2011 - * Author : Renaud BARATE - EDF R&D - */ - -#ifndef _JOBINFO_EVISHNU_H_ -#define _JOBINFO_EVISHNU_H_ - -#include - -#include - -namespace Batch { - - class JobInfo_eVishnu : public JobInfo - { - public: - - JobInfo_eVishnu(const std::string & id, const std::string & queryOutput); - virtual ~JobInfo_eVishnu(); - - }; - -} - -#endif diff --git a/src/Vishnu/CMakeLists.txt b/src/Vishnu/CMakeLists.txt index 31ab7a2..a1fec35 100644 --- a/src/Vishnu/CMakeLists.txt +++ b/src/Vishnu/CMakeLists.txt @@ -20,13 +20,13 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -SET(CLASS_LIST Vishnu/Batch_BatchManager_eVishnu - Vishnu/Batch_FactBatchManager_eVishnu - Vishnu/Batch_JobInfo_eVishnu +SET(CLASS_LIST Vishnu/BatchManager_Vishnu + Vishnu/FactBatchManager_Vishnu + Vishnu/JobInfo_Vishnu ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) IF (TEST_ENABLED) - add_subdirectory(Test) + ADD_TEST(VISHNU ${CMAKE_BINARY_DIR}/src/Core/Test/Test_BatchManager VISHNU SH) ENDIF (TEST_ENABLED) diff --git a/src/Vishnu/FactBatchManager_Vishnu.cxx b/src/Vishnu/FactBatchManager_Vishnu.cxx new file mode 100644 index 0000000..53361b3 --- /dev/null +++ b/src/Vishnu/FactBatchManager_Vishnu.cxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2012 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_Vishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include + +#include "BatchManager_Vishnu.hxx" +#include "FactBatchManager_Vishnu.hxx" + +namespace Batch { + + static FactBatchManager_Vishnu sFBM_Vishnu; + + FactBatchManager_Vishnu::FactBatchManager_Vishnu() : FactBatchManager("VISHNU") + { + } + + FactBatchManager_Vishnu::~FactBatchManager_Vishnu() + { + } + + BatchManager * FactBatchManager_Vishnu::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const + { + // MESSAGE("Building new BatchManager_Vishnu on host '" << hostname << "'"); + return new BatchManager_Vishnu(this, hostname, username, protocolType, mpiImpl); + } + +} diff --git a/src/Vishnu/FactBatchManager_Vishnu.hxx b/src/Vishnu/FactBatchManager_Vishnu.hxx new file mode 100644 index 0000000..bc04ec2 --- /dev/null +++ b/src/Vishnu/FactBatchManager_Vishnu.hxx @@ -0,0 +1,55 @@ +// Copyright (C) 2007-2012 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_Vishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _FACTBATCHMANAGER_EVISHNU_H_ +#define _FACTBATCHMANAGER_EVISHNU_H_ + +#include +#include +#include +#include + +namespace Batch { + + class BATCH_EXPORT FactBatchManager_Vishnu : public FactBatchManager + { + public: + + FactBatchManager_Vishnu(); + virtual ~FactBatchManager_Vishnu(); + + virtual BatchManager * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; + + }; + +} + +#endif diff --git a/src/Vishnu/JobInfo_Vishnu.cxx b/src/Vishnu/JobInfo_Vishnu.cxx new file mode 100644 index 0000000..68a32b6 --- /dev/null +++ b/src/Vishnu/JobInfo_Vishnu.cxx @@ -0,0 +1,98 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Vishnu.cxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include + +#include +#include + +#include "JobInfo_Vishnu.hxx" + +using namespace std; + +namespace Batch { + + JobInfo_Vishnu::JobInfo_Vishnu(const string & id, const string & queryOutput) + : JobInfo() + { + _param[ID] = id; + + // find the status in the query output + istringstream iss(queryOutput); + string status; + bool statusFound = false; + while (!statusFound && !iss.eof()) { + string line; + getline(iss, line); + size_t pos = line.find(':'); + if (pos != string::npos) { + string begline = line.substr(0, pos); + string keyword; + // Trim leading and trailing spaces of the string before ':' + size_t startpos = begline.find_first_not_of(" \t"); + size_t endpos = begline.find_last_not_of(" \t"); + if (startpos != string::npos && endpos != string::npos) + keyword = begline.substr(startpos, endpos-startpos+1); + + if (keyword == "Status") { + statusFound = true; + string endline = line.substr(pos + 1); + startpos = endline.find_first_not_of(" \t"); + endpos = endline.find_last_not_of(" \t"); + if (startpos != string::npos && endpos != string::npos) + status = endline.substr(startpos, endpos-startpos+1); + } + } + } + + if (status.size() == 0) { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } else if (status == "QUEUED") { + _param[STATE] = QUEUED; + } else if (status == "WAITING") { + _param[STATE] = QUEUED; + } else if (status == "RUNNING") { + _param[STATE] = RUNNING; + } else if (status == "TERMINATED") { + _param[STATE] = FINISHED; + } else if (status == "CANCELLED") { + _param[STATE] = FAILED; + } else { + throw RunTimeException("Unknown job state code: \"" + status + "\""); + } + } + + JobInfo_Vishnu::~JobInfo_Vishnu() + { + } + +} diff --git a/src/Vishnu/JobInfo_Vishnu.hxx b/src/Vishnu/JobInfo_Vishnu.hxx new file mode 100644 index 0000000..db124e3 --- /dev/null +++ b/src/Vishnu/JobInfo_Vishnu.hxx @@ -0,0 +1,49 @@ +// Copyright (C) 2007-2012 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 +// +/* + * JobInfo_Vishnu.hxx : + * + * Created on: 24 june 2011 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _JOBINFO_EVISHNU_H_ +#define _JOBINFO_EVISHNU_H_ + +#include + +#include + +namespace Batch { + + class JobInfo_Vishnu : public JobInfo + { + public: + + JobInfo_Vishnu(const std::string & id, const std::string & queryOutput); + virtual ~JobInfo_Vishnu(); + + }; + +} + +#endif diff --git a/src/Vishnu/Test/CMakeLists.txt b/src/Vishnu/Test/CMakeLists.txt deleted file mode 100644 index 84d88d0..0000000 --- a/src/Vishnu/Test/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (C) 2007-2012 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 -# - -# 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-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) - -# set the include directories -include_directories(${CMAKE_SOURCE_DIR}/src/Core) -include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -# Build the test programs and add the tests -add_executable(Test_eVishnu Test_eVishnu.cxx) -target_link_libraries(Test_eVishnu Batch SimpleParser) - -IF (HAS_SSH) - ADD_TEST(eVishnu_SSH Test_eVishnu SSH) -ENDIF (HAS_SSH) - -#IF (HAS_RSH) -# ADD_TEST(eVishnu_RSH Test_eVishnu RSH) -#ENDIF (HAS_RSH) diff --git a/src/Vishnu/Test/Test_eVishnu.cxx b/src/Vishnu/Test/Test_eVishnu.cxx deleted file mode 100644 index f6c48e1..0000000 --- a/src/Vishnu/Test/Test_eVishnu.cxx +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (C) 2007-2012 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_eVishnu.cxx : - * - * Author : Renaud BARATE - EDF R&D - * Date : June 2011 - * - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; -using namespace Batch; - -int main(int argc, char** argv) -{ - cout << "*******************************************************************************************" << endl; - cout << "This program tests the batch submission based on Vishnu commands." << 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_EVISHNU_HOMEDIR"); - const string & host = parser.getValue("TEST_EVISHNU_HOST"); - const string & user = parser.getValue("TEST_EVISHNU_USER"); - int timeout = parser.getValueAsInt("TEST_EVISHNU_TIMEOUT"); - - // Define the job... - Job job; - // ... and its parameters ... - Parametre p; - p[EXECUTABLE] = "./test-script.sh"; - p[NAME] = "Test_eVISHNU"; - p[WORKDIR] = homedir + "/tmp/Batch"; - p[INFILE] = Couple("seta.sh", "seta.sh"); - p[INFILE] += Couple("setb.sh", "setb.sh"); - p[OUTFILE] = Couple("result.txt", "result.txt"); - p[NBPROC] = 1; - p[MAXWALLTIME] = 1; - p[MAXRAMSIZE] = 50; - job.setParametre(p); - // ... and its environment - Environnement e; - e["MYENVVAR"] = "MYVALUE"; - 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("eVISHNU")); - BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), SH); - - // Submit the job to the BatchManager - JobId jobid = bm->submitJob(job); - cout << jobid.__repr__() << endl; - - // Wait for the end of the job - string state = bm->waitForJobEnd(jobid, timeout); - - if (state == FINISHED) { - cout << "Job " << jobid.__repr__() << " is done" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - } else if (state == FAILED) { - cerr << "Job " << jobid.__repr__() << " finished in error" << endl; - bm->importOutputFiles(job, "resultdir/seconddirname"); - return 1; - } 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 - try { - SimpleParser resultParser; - resultParser.parse("resultdir/seconddirname/result.txt"); - cout << "Result:" << endl << resultParser; - const string & envvar = resultParser.getValue("MYENVVAR"); - int result = resultParser.getValueAsInt("c"); - if (envvar == "MYVALUE" && result == 12) { - cout << "OK, Expected result found." << endl; - return 0; - } else { - cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; - return 1; - } - } catch (ParserException e) { - cerr << "Parser error on result file: " << e.what() << endl; - return 1; - } -} diff --git a/src/Vishnu/Test/seta.sh b/src/Vishnu/Test/seta.sh deleted file mode 100644 index 42d1e38..0000000 --- a/src/Vishnu/Test/seta.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -a=4 diff --git a/src/Vishnu/Test/setb.sh b/src/Vishnu/Test/setb.sh deleted file mode 100644 index 8969060..0000000 --- a/src/Vishnu/Test/setb.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -b=3 diff --git a/src/Vishnu/Test/test-script.sh b/src/Vishnu/Test/test-script.sh deleted file mode 100755 index 1d56247..0000000 --- a/src/Vishnu/Test/test-script.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -. ./seta.sh -. ./setb.sh - -c=`expr $a "*" $b` - -echo "MYENVVAR = $MYENVVAR" > result.txt -echo "c = $c" >> result.txt