#cmakedefine MSVC
#cmakedefine MINGW
-/* A path to a rcp-like command */
-#define RCP "@RCP@"
+/* SH tools (sh, cp, rm) found on the system */
+#cmakedefine HAS_SH
+
+/* A path to a sh-like command */
+#cmakedefine SH_COMMAND "@SH_COMMAND@"
/* A path to a rm-like command */
-#define RM "@RM@"
+#cmakedefine RM_COMMAND "@RM_COMMAND@"
/* A path to a cp-like command */
-#define CP "@CP@"
+#cmakedefine CP_COMMAND "@CP_COMMAND@"
+
+/* RSH tools (rsh, rcp) found on the system */
+#cmakedefine HAS_RSH
/* A path to a rsh-like command */
-#define RSH "@RSH@"
+#cmakedefine RSH_COMMAND "@RSH_COMMAND@"
-/* A path to a scp-like command */
-#define SCP "@SCP@"
+/* A path to a rcp-like command */
+#cmakedefine RCP_COMMAND "@RCP_COMMAND@"
-/* A path to a sh-like command */
-#define SH "@SH@"
-#cmakedefine SH_COMMAND_IS_CMD
+/* SSH tools (ssh, scp) found on the system */
+#cmakedefine HAS_SSH
/* A path to a ssh-like command */
-#define SSH "@SSH@"
+#cmakedefine SSH_COMMAND "@SSH_COMMAND@"
+
+/* A path to a scp-like command */
+#cmakedefine SCP_COMMAND "@SCP_COMMAND@"
#endif
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-MACRO(FIND_LOCAL_COMMAND VAR COMMAND)
- FIND_PROGRAM(${VAR} NAMES ${COMMAND} ${ARGN})
+MACRO(FIND_LOCAL_COMMAND VAR UNIX_COMMAND WIN32_COMMAND)
+ IF (WIN32)
+ FIND_PROGRAM(${VAR} ${WIN32_COMMAND})
+ ELSE (WIN32)
+ FIND_PROGRAM(${VAR} ${UNIX_COMMAND})
+ ENDIF (WIN32)
IF (${VAR})
- MESSAGE(STATUS "${COMMAND} found : ${${VAR}}")
+ MESSAGE(STATUS "${VAR} found : ${${VAR}}")
ELSE (${VAR})
- MESSAGE(STATUS "${COMMAND} not found, local submission might not work properly")
- SET(${VAR} /bin/false)
+ MESSAGE(STATUS "${VAR} not found, local submission might not work properly")
ENDIF (${VAR})
- MARK_AS_ADVANCED(${VAR})
ENDMACRO(FIND_LOCAL_COMMAND)
-MESSAGE(STATUS "Looking for commands needed for local submission...")
-
-FIND_PROGRAM(RM rm)
-IF (RM)
- MESSAGE(STATUS "rm found : ${RM}")
-ELSE (RM)
+MACRO(FIND_LOCAL_COMMAND_WIN32_DEF VAR UNIX_COMMAND WIN32_DEFAULT)
IF (WIN32)
- MESSAGE(STATUS "using 'del' as rm command")
- SET(RM del)
+ SET(${VAR} ${WIN32_DEFAULT} CACHE STRING "${VAR}")
+ MESSAGE(STATUS "${VAR} found : using '${${VAR}}' (Windows default)")
ELSE (WIN32)
- MESSAGE(STATUS "rm not found, local submission might not work properly")
- SET(RM /bin/false)
+ FIND_LOCAL_COMMAND(${VAR} ${UNIX_COMMAND} ${WIN32_DEFAULT})
ENDIF (WIN32)
-ENDIF (RM)
-MARK_AS_ADVANCED(RM)
+ENDMACRO(FIND_LOCAL_COMMAND_WIN32_DEF)
-FIND_PROGRAM(SH sh)
-IF (SH)
- MESSAGE(STATUS "sh found : ${SH}")
-ELSE (SH)
- FIND_PROGRAM(CMD cmd)
- IF (CMD)
- MESSAGE(STATUS "cmd found : ${CMD}")
- SET(SH ${CMD})
- SET(SH_COMMAND_IS_CMD TRUE)
- ELSE (CMD)
- MESSAGE(STATUS "sh not found, local submission might not work properly")
- SET(SH /bin/false)
- ENDIF (CMD)
-ENDIF (SH)
-MARK_AS_ADVANCED(CMD SH SH_COMMAND_IS_CMD)
+MACRO(EVAL VAR)
+ IF(${ARGN})
+ SET(${VAR} TRUE)
+ ELSE(${ARGN})
+ SET(${VAR} FALSE)
+ ENDIF(${ARGN})
+ENDMACRO(EVAL)
-FIND_PROGRAM(CP cp)
-IF (CP)
- MESSAGE(STATUS "cp found : ${CP}")
-ELSE (CP)
- IF (WIN32)
- MESSAGE(STATUS "using 'copy' as cp command")
- SET(CP copy)
- ELSE (WIN32)
- MESSAGE(STATUS "cp not found, local submission might not work properly")
- SET(CP /bin/false)
- ENDIF (WIN32)
-ENDIF (CP)
-MARK_AS_ADVANCED(CP)
+MESSAGE(STATUS "Looking for commands needed for local submission...")
+
+FIND_LOCAL_COMMAND_WIN32_DEF(RM_COMMAND rm del)
+FIND_LOCAL_COMMAND(SH_COMMAND sh cmd.exe)
+FIND_LOCAL_COMMAND_WIN32_DEF(CP_COMMAND cp copy)
+FIND_LOCAL_COMMAND(RSH_COMMAND rsh rsh)
+FIND_LOCAL_COMMAND(RCP_COMMAND rcp rcp)
+FIND_LOCAL_COMMAND(SSH_COMMAND ssh plink)
+FIND_LOCAL_COMMAND(SCP_COMMAND scp pscp)
-FIND_LOCAL_COMMAND(RSH rsh)
-FIND_LOCAL_COMMAND(RCP rcp)
-FIND_LOCAL_COMMAND(SSH ssh plink)
-FIND_LOCAL_COMMAND(SCP scp pscp)
+EVAL (HAS_SH SH_COMMAND AND CP_COMMAND AND RM_COMMAND)
+EVAL (HAS_RSH RSH_COMMAND AND RCP_COMMAND)
+EVAL (HAS_SSH SSH_COMMAND AND SCP_COMMAND)
*
*/
-#include "Batch_BatchManager_eClient.hxx"
-#include "Batch_RunTimeException.hxx"
-
#include <ctime>
#include <iostream>
#include <fstream>
#include <io.h>
#endif
-#include "Batch_config.h"
+#include <Batch_config.h>
+
+#include "Batch_BatchManager_eClient.hxx"
+#include "Batch_RunTimeException.hxx"
#ifdef MSVC
#define EXISTS(path) _access_s(path, 0) == 0
namespace Batch {
BatchManager_eClient::BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host,
- const char* protocol, const char* mpiImpl)
- : BatchManager(parent, host), _protocol(protocol), _username("")
+ CommunicationProtocolType protocolType, const char* mpiImpl)
+ : BatchManager(parent, host), _protocol(CommunicationProtocol::getInstance(protocolType)), _username("")
{
// instanciation of mpi implementation needed to launch executable in batch script
_mpiImpl = FactoryMpiImpl(mpiImpl);
// Destructeur
BatchManager_eClient::~BatchManager_eClient()
{
- // Nothing to do
delete _mpiImpl;
}
Versatile::iterator Vit;
_username = string(params[USER]);
- string command = "\"";
- string copy_command = "\"";
-
- // Test protocol
- if( _protocol == "rsh" ) {
- command += RSH;
- copy_command += RCP;
- } else if( _protocol == "ssh" ) {
- command += SSH;
- copy_command += SCP;
- } else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
- copy_command += "\" ";
-
- // First step : creating batch tmp files directory
- if(_username != ""){
- command += _username + "@";
- }
- command += _hostname;
- command += " mkdir -p ";
- command += string(params[TMPDIR]);
+ string subCommand = string("mkdir -p ") + string(params[TMPDIR]);
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status) {
// Second step : copy fileToExecute into
// batch tmp files directory
string executeFile = params[EXECUTABLE];
- if( executeFile.size() > 0 ){
- command = copy_command;
- command += string(params[EXECUTABLE]);
- command += " ";
- if(_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += string(params[TMPDIR]);
- cerr << command.c_str() << endl;
- status = system(command.c_str());
+ if (executeFile.size() != 0) {
+ status = _protocol.copyFile(executeFile, "", "",
+ params[TMPDIR], _hostname, _username);
if(status) {
std::ostringstream oss;
oss << status;
}
#ifdef WIN32
- // On Windows, we make the remote file executable afterward because pscp does not preserve
- // access permissions on files
- command = "\"";
- if( _protocol == "rsh" ) {
- command += RSH;
- } else if( _protocol == "ssh" ) {
- command += SSH;
- } else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
- if(_username != ""){
- command += _username + "@";
- }
- command += _hostname;
- command += " chmod u+x ";
- command += string(params[TMPDIR]) + "/" + string(params[EXECUTABLE]);
+ // On Windows, we make the remote file executable afterward because
+ // pscp does not preserve access permissions on files
+ subCommand = string("chmod u+x ") + string(params[TMPDIR]) + "/" +
+ string(params[EXECUTABLE]);
+ command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status) {
for(Vit=V.begin(); Vit!=V.end(); Vit++) {
CoupleType cpt = *static_cast< CoupleType * >(*Vit);
Couple inputFile = cpt;
- command = copy_command;
- command += inputFile.getLocal();
- command += " ";
- if(_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += inputFile.getRemote();
- cerr << command.c_str() << endl;
- status = system(command.c_str());
+ status = _protocol.copyFile(inputFile.getLocal(), "", "",
+ inputFile.getRemote(), _hostname, _username);
if(status) {
std::ostringstream oss;
oss << status;
void BatchManager_eClient::importOutputFiles( const Job & job, const string directory ) throw(EmulationException)
{
- int status;
-
Parametre params = job.getParametre();
Versatile V = params[OUTFILE];
Versatile::iterator Vit;
for(Vit=V.begin(); Vit!=V.end(); Vit++) {
CoupleType cpt = *static_cast< CoupleType * >(*Vit);
Couple outputFile = cpt;
-
- string command = "\"";
-
- // Test protocol
- if( _protocol == "rsh" ) {
- command += RCP;
- } else if( _protocol == "ssh" ) {
- command += SCP;
- } else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += outputFile.getRemote();
- command += " ";
- command += directory;
- cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
- {
+ int status = _protocol.copyFile(outputFile.getRemote(), _hostname, _username,
+ directory, "", "");
+ if (status) {
// Try to get what we can (logs files)
// throw BatchException("Error of connection on remote host");
std::string mess("Copy command failed ! status is :");
#else
string fileName = getTmpDir() + "/" + prefix + "-XXXXXX";
- char buf[fileName.size()+1];
+ char * buf = new char[fileName.size()+1];
fileName.copy(buf, fileName.size());
buf[fileName.size()] = '\0';
int fd = mkstemp(buf);
- if (fd == -1)
+ if (fd == -1) {
+ delete[] buf;
throw RunTimeException(string("Can't create temporary file ") + fileName);
+ }
fileName = buf;
+ delete[] buf;
outputStream.open(fileName.c_str());
close(fd); // Close the file descriptor so that the file is not opened twice
#else
- char buf[baseName.size()+1];
+ char * buf = new char[baseName.size() + 1];
baseName.copy(buf, baseName.size());
buf[baseName.size()] = '\0';
- if (mkdtemp(buf) == NULL)
+ if (mkdtemp(buf) == NULL) {
+ delete[] buf;
throw RunTimeException(string("Can't create temporary directory ") + baseName);
+ }
tmpDirName = buf;
+ delete[] buf;
#endif
#include "Batch_MpiImpl.hxx"
#include "Batch_BatchManager.hxx"
#include "Batch_EmulationException.hxx"
+#include "Batch_CommunicationProtocol.hxx"
#include <string>
public:
// Constructeur et destructeur
BatchManager_eClient(const Batch::FactBatchManager * parent, const char* host="localhost",
- const char* protocol="ssh", const char* mpiImpl="mpich1");
+ CommunicationProtocolType protocolType = SSH, const char* mpiImpl="mpich1");
virtual ~BatchManager_eClient();
void importOutputFiles( const Job & job, const std::string directory ) throw(EmulationException);
protected:
- std::string _protocol; // protocol to access _hostname
+ const CommunicationProtocol & _protocol; // protocol to access _hostname
std::string _username; // username to access _hostname
MpiImpl *_mpiImpl; // Mpi implementation to launch executable in batch script
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocol.cxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#include <iostream>
+
+#include <Batch_config.h>
+
+#include "Batch_CommunicationProtocol.hxx"
+#include "Batch_CommunicationProtocolRSH.hxx"
+#include "Batch_CommunicationProtocolSH.hxx"
+#include "Batch_CommunicationProtocolSSH.hxx"
+#include "Batch_APIInternalFailureException.hxx"
+#include "Batch_RunTimeException.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+ CommunicationProtocol::~CommunicationProtocol()
+ {
+ }
+
+ const CommunicationProtocol & CommunicationProtocol::getInstance(CommunicationProtocolType protocolType)
+ {
+ if (protocolType == SH) {
+ #ifdef HAS_SH
+ static CommunicationProtocolSH instanceSH;
+ return instanceSH;
+ #else
+ throw RunTimeException("Can't use SH protocol (SH tools were "
+ "not found on the system at compile time).");
+ #endif
+ } else if (protocolType == RSH) {
+#ifdef HAS_RSH
+ static CommunicationProtocolRSH instanceRSH;
+ return instanceRSH;
+#else
+ throw RunTimeException("Can't use RSH protocol (RSH tools were "
+ "not found on the system at compile time).");
+#endif
+ } else if (protocolType == SSH) {
+#ifdef HAS_SSH
+ static CommunicationProtocolSSH instanceSSH;
+ return instanceSSH;
+#else
+ throw RunTimeException("Can't use SSH protocol (SSH tools were "
+ "not found on the system at compile time).");
+#endif
+ } else
+ throw APIInternalFailureException("Unknown communication protocol.");
+ }
+
+ string CommunicationProtocol::getExecCommand(const string & subCommand,
+ const string & host,
+ const string & user) const
+ {
+ return commandStringFromArgs(getExecCommandArgs(subCommand, host, user));
+ }
+
+ int CommunicationProtocol::copyFile(const std::string & sourcePath,
+ const std::string & sourceHost,
+ const std::string & sourceUser,
+ const std::string & destinationPath,
+ const std::string & destinationHost,
+ const std::string & destinationUser) const
+ {
+ string command = commandStringFromArgs(getCopyCommandArgs(sourcePath, sourceHost, sourceUser,
+ destinationPath, destinationHost,
+ destinationUser));
+ cout << command.c_str() << endl;
+ int status = system(command.c_str());
+ return status;
+ }
+
+ string CommunicationProtocol::getRemoveSubCommand(const string & path) const
+ {
+ return string("rm ") + path;
+ }
+
+ int CommunicationProtocol::removeFile(const std::string & path,
+ const std::string & host,
+ const std::string & user) const
+ {
+ string command = getExecCommand(getRemoveSubCommand(path), host, user);
+ cout << command.c_str() << endl;
+ int status = system(command.c_str());
+ return status;
+ }
+
+ string CommunicationProtocol::commandStringFromArgs(const vector<string> & 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<commandArgs.size() ; i++) {
+ if (i != 0) commandStr += " ";
+
+ // if the argument contains spaces, we surround it with double quotes
+ if (commandArgs[i].find(' ') != string::npos) {
+ commandStr += string("\"") + commandArgs[i] + "\"";
+ } else {
+ commandStr += commandArgs[i];
+ }
+ }
+
+#ifdef WIN32
+ commandStr += "\"";
+#endif
+
+ return commandStr;
+ }
+
+}
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocol.hxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifndef _BATCHCOMMUNICATIONPROTOCOL_H_
+#define _BATCHCOMMUNICATIONPROTOCOL_H_
+
+#include <string>
+#include <vector>
+
+#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<std::string> getExecCommandArgs(const std::string & subCommand,
+ const std::string & host,
+ const std::string & user) const=0;
+
+ virtual int copyFile(const std::string & sourcePath,
+ const std::string & sourceHost,
+ const std::string & sourceUser,
+ const std::string & destinationPath,
+ const std::string & destinationHost,
+ const std::string & destinationUser) const;
+
+ virtual int removeFile(const std::string & path,
+ const std::string & host,
+ const std::string & user) const;
+
+ protected:
+
+ virtual std::vector<std::string> getCopyCommandArgs(const std::string & sourcePath,
+ const std::string & sourceHost,
+ const std::string & sourceUser,
+ const std::string & destinationPath,
+ const std::string & destinationHost,
+ const std::string & destinationUser) const=0;
+
+ virtual std::string getRemoveSubCommand(const std::string & path) const;
+
+ std::string commandStringFromArgs(const std::vector<std::string> & args) const;
+
+ };
+
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolRSH.cxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifdef WIN32
+#include <direct.h>
+#include <iostream>
+
+#include <Batch_RunTimeException.hxx>
+#endif
+
+#include <Batch_config.h>
+
+#include "Batch_CommunicationProtocolRSH.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+ vector<string> CommunicationProtocolRSH::getExecCommandArgs(const string & subCommand,
+ const string & host,
+ const string & user) const
+ {
+ vector<string> 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<string> CommunicationProtocolRSH::getCopyCommandArgs(const string & sourcePath,
+ const string & sourceHost,
+ const string & sourceUser,
+ const string & destinationPath,
+ const string & destinationHost,
+ const string & destinationUser) const
+ {
+ vector<string> cmd;
+
+ string fullSource;
+ if (sourceHost.size() != 0) {
+ if (sourceUser.size() != 0) {
+#ifdef WIN32
+ fullSource += sourceHost + "." + sourceUser + ":";
+#else
+ fullSource += sourceUser + "@" + sourceHost + ":";
+#endif
+ } else {
+ fullSource += sourceHost + ":";
+ }
+ }
+ fullSource += sourcePath;
+
+ string fullDestination;
+ if (destinationHost.size() != 0) {
+ if (destinationUser.size() != 0) {
+#ifdef WIN32
+ fullDestination += destinationHost + "." + destinationUser + ":";
+#else
+ fullDestination += destinationUser + "@" + destinationHost + ":";
+#endif
+ } else {
+ fullDestination += destinationHost + ":";
+ }
+ }
+ fullDestination += destinationPath;
+
+ cmd.push_back(RCP_COMMAND);
+ cmd.push_back(fullSource);
+ cmd.push_back(fullDestination);
+
+ return cmd;
+ }
+
+#ifdef WIN32
+ int CommunicationProtocolRSH::copyFile(const std::string & sourcePath,
+ const std::string & sourceHost,
+ const std::string & sourceUser,
+ const std::string & destinationPath,
+ const std::string & destinationHost,
+ const std::string & destinationUser) const
+ {
+ // On Windows, we can't use drive letters in the paths of rcp command because they
+ // are confused with host names. So we must first change the working directory and
+ // then copy the file using its path without the drive letter.
+
+ // Extract the drive letter from the source path
+ string sourcePathWithoutDrive;
+ char sourceDriveLetter = getDriveLetter(sourcePath, &sourcePathWithoutDrive);
+ // Error if we have a drive letter and it is a remote path
+ if (sourceDriveLetter != '\0' && sourceHost.size() != 0)
+ throw RunTimeException(string("Invalid path: ") + sourcePath + " for host " + sourceHost);
+
+ // Extract the drive letter from the destination path
+ string destinationPathWithoutDrive;
+ char destinationDriveLetter = getDriveLetter(destinationPath, &destinationPathWithoutDrive);
+ // Error if we have a drive letter and it is a remote path
+ if (destinationDriveLetter != '\0' && destinationHost.size() != 0)
+ throw RunTimeException(string("Invalid path: ") + destinationPath + " for host " + destinationHost);
+
+ // Error if we have two drive letters and they are different
+ if (sourceDriveLetter != '\0' && destinationDriveLetter != '\0' &&
+ sourceDriveLetter != destinationDriveLetter)
+ throw RunTimeException(string("Can't use RCP to copy files between different drives: ") +
+ sourcePath + (", ") + destinationPath);
+
+ // Now get the drive letter to use if there is one
+ char driveLetter = (sourceDriveLetter != '\0') ? sourceDriveLetter : destinationDriveLetter;
+
+ // Get the drive of the current working directory
+ char cwd[_MAX_PATH];
+ _getcwd(cwd, _MAX_PATH);
+ char currentDrive = getDriveLetter(cwd);
+
+ // Change working directory if necessary
+ if (driveLetter != '\0' && driveLetter != currentDrive) {
+ char newdir[3];
+ newdir[0] = driveLetter;
+ newdir[1] = ':';
+ newdir[2] = '\0';
+ cout << "Changing directory: " << newdir << endl;
+ _chdir(newdir);
+ }
+
+ int status = CommunicationProtocol::copyFile(sourcePathWithoutDrive, sourceHost, sourceUser,
+ destinationPathWithoutDrive, destinationHost, destinationUser);
+
+ // Go back to previous directory if necessary
+ if (driveLetter != '\0' && driveLetter != currentDrive) {
+ cout << "Changing directory: " << cwd << endl;
+ _chdir(cwd);
+ }
+
+ return status;
+ }
+
+ char CommunicationProtocolRSH::getDriveLetter(const string & path, string * pathWithoutDrive) const
+ {
+ if (path.find(':') != string::npos) {
+ // Error if the colon is not the second character
+ if (path.size() < 2 || path[1] != ':')
+ throw RunTimeException(string("Invalid path: ") + path);
+ else {
+ if (pathWithoutDrive != NULL) *pathWithoutDrive = path.substr(2);
+ return path[0];
+ }
+ } else {
+ if (pathWithoutDrive != NULL) *pathWithoutDrive = path;
+ return '\0';
+ }
+ }
+
+#endif
+
+}
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolRSH.hxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifndef _BATCHCOMMUNICATIONPROTOCOLRSH_H_
+#define _BATCHCOMMUNICATIONPROTOCOLRSH_H_
+
+#include <string>
+#include <vector>
+
+#include "Batch_Defines.hxx"
+#include "Batch_CommunicationProtocol.hxx"
+
+namespace Batch {
+
+ class BATCH_EXPORT CommunicationProtocolRSH : public CommunicationProtocol
+ {
+ public:
+ std::vector<std::string> getExecCommandArgs(const std::string & subCommand,
+ const std::string & host,
+ const std::string & user) const;
+
+ std::vector<std::string> 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
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolSH.cxx :
+ *
+ * Created on: 16 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#include <Batch_config.h>
+
+#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<fixedPath.size() ; i++) {
+ if (fixedPath[i] == '/') fixedPath[i] = '\\';
+ }
+ #endif
+ return fixedPath;
+ }
+
+ vector<string> CommunicationProtocolSH::getExecCommandArgs(const string & subCommand,
+ const string & host,
+ const string & user) const
+ {
+ vector<string> 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<string> CommunicationProtocolSH::getCopyCommandArgs(const string & sourcePath,
+ const string & sourceHost,
+ const string & sourceUser,
+ const string & destinationPath,
+ const string & destinationHost,
+ const string & destinationUser) const
+ {
+ vector<string> cmd;
+ cmd.push_back(CP_COMMAND);
+ cmd.push_back(fixPath(sourcePath));
+ cmd.push_back(fixPath(destinationPath));
+ return cmd;
+ }
+
+ string CommunicationProtocolSH::getRemoveSubCommand(const string & path) const
+ {
+ return string(RM_COMMAND) + " " + path;
+ }
+
+}
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolSH.hxx :
+ *
+ * Created on: 16 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifndef _BATCHCOMMUNICATIONPROTOCOLSH_H_
+#define _BATCHCOMMUNICATIONPROTOCOLSH_H_
+
+#include <string>
+#include <vector>
+
+#include "Batch_Defines.hxx"
+#include "Batch_CommunicationProtocol.hxx"
+
+namespace Batch {
+
+ class BATCH_EXPORT CommunicationProtocolSH : public CommunicationProtocol
+ {
+ public:
+ std::vector<std::string> getExecCommandArgs(const std::string & subCommand,
+ const std::string & host,
+ const std::string & user) const;
+
+ std::vector<std::string> getCopyCommandArgs(const std::string & sourcePath,
+ const std::string & sourceHost,
+ const std::string & sourceUser,
+ const std::string & destinationPath,
+ const std::string & destinationHost,
+ const std::string & destinationUser) const;
+
+ std::string getRemoveSubCommand(const std::string & path) const;
+
+ protected:
+
+ std::string fixPath(const std::string & path) const;
+
+ };
+
+}
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolSSH.cxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#include <Batch_config.h>
+
+#include "Batch_CommunicationProtocolSSH.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+ vector<string> CommunicationProtocolSSH::getExecCommandArgs(const string & subCommand,
+ const string & host,
+ const string & user) const
+ {
+ vector<string> 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<string> CommunicationProtocolSSH::getCopyCommandArgs(const string & sourcePath,
+ const string & sourceHost,
+ const string & sourceUser,
+ const string & destinationPath,
+ const string & destinationHost,
+ const string & destinationUser) const
+ {
+ vector<string> cmd;
+
+ string fullSource;
+ if (sourceHost.size() != 0) {
+ if (sourceUser.size() != 0) {
+ fullSource += sourceUser + "@";
+ }
+ fullSource += sourceHost + ":";
+ }
+ fullSource += sourcePath;
+
+ string fullDestination;
+ if (destinationHost.size() != 0) {
+ if (destinationUser.size() != 0) {
+ fullDestination += destinationUser + "@";
+ }
+ fullDestination += destinationHost + ":";
+ }
+ fullDestination += destinationPath;
+
+ // Option -p is used to keep the same permissions for the destination file
+ // (particularly useful to keep scripts executable when copying them)
+ cmd.push_back(SCP_COMMAND);
+ cmd.push_back("-p");
+ cmd.push_back(fullSource);
+ cmd.push_back(fullDestination);
+
+ return cmd;
+ }
+
+}
--- /dev/null
+// Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Batch_CommunicationProtocolSSH.hxx :
+ *
+ * Created on: 14 sept. 2009
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifndef _BATCHCOMMUNICATIONPROTOCOLSSH_H_
+#define _BATCHCOMMUNICATIONPROTOCOLSSH_H_
+
+#include <string>
+#include <vector>
+
+#include "Batch_Defines.hxx"
+#include "Batch_CommunicationProtocol.hxx"
+
+namespace Batch {
+
+ class BATCH_EXPORT CommunicationProtocolSSH : public CommunicationProtocol
+ {
+ public:
+ std::vector<std::string> getExecCommandArgs(const std::string & subCommand,
+ const std::string & host,
+ const std::string & user) const;
+
+ std::vector<std::string> 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
*
*/
-#ifndef _FACTBATCHMANAGER_eClient_H_
-#define _FACTBATCHMANAGER_eClient_H_
+#ifndef _FACTBATCHMANAGER_ECLIENT_H_
+#define _FACTBATCHMANAGER_ECLIENT_H_
#include <string>
-#include <map>
+
#include "Batch_FactBatchManager.hxx"
+#include "Batch_BatchManager_eClient.hxx"
+#include "Batch_CommunicationProtocol.hxx"
namespace Batch {
-
- class BatchManager_eClient;
- class FactBatchManager_eClient : public FactBatchManager
+ class BATCH_EXPORT FactBatchManager_eClient : public FactBatchManager
{
public:
// Constructeur et destructeur
FactBatchManager_eClient(const std::string & type);
virtual ~FactBatchManager_eClient();
- virtual Batch::BatchManager_eClient * operator() (const char * hostname,const char * protocol, const char * mpi) const = 0;
+ virtual Batch::BatchManager_eClient * operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpi) const = 0;
protected:
Core/Batch_BatchManagerCatalog
Core/Batch_BoolType
Core/Batch_CharType
+ Core/Batch_CommunicationProtocol
Core/Batch_ConnexionFailureException
Core/Batch_Couple
Core/Batch_CoupleType
Core/Batch_Versatile
)
+IF (HAS_SH)
+ SET(CLASS_LIST ${CLASS_LIST}
+ Core/Batch_CommunicationProtocolSH
+ )
+ENDIF (HAS_SH)
+
+IF (HAS_RSH)
+ SET(CLASS_LIST ${CLASS_LIST}
+ Core/Batch_CommunicationProtocolRSH
+ )
+ENDIF (HAS_RSH)
+
+IF (HAS_SSH)
+ SET(CLASS_LIST ${CLASS_LIST}
+ Core/Batch_CommunicationProtocolSSH
+ )
+ENDIF (HAS_SSH)
+
APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST})
APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST})
APPEND_CLASSES_TO_HDR_FILES(Core/Batch_Defines)
#include <iostream>
#include <fstream>
#include <sstream>
+#include <string>
#include <sys/stat.h>
-#include <string.h>
-#include <stdlib.h>
-#include "Batch_BatchManager_eLSF.hxx"
#ifdef WIN32
-# include <time.h>
-# include <io.h>
+#include <io.h>
#else
-# include <libgen.h>
+#include <libgen.h>
#endif
+#include "Batch_BatchManager_eLSF.hxx"
+#include "Batch_JobInfo_eLSF.hxx"
+
using namespace std;
namespace Batch {
- BatchManager_eLSF::BatchManager_eLSF(const FactBatchManager * parent, const char * host, const char * protocol, const char * mpiImpl) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_eClient(parent,host,protocol,mpiImpl)
+ BatchManager_eLSF::BatchManager_eLSF(const FactBatchManager * parent, const char * host,
+ CommunicationProtocolType protocolType, const char * mpiImpl)
+ : BatchManager_eClient(parent, host, protocolType, mpiImpl)
{
// Nothing to do
}
// build batch script for job
buildBatchScript(job);
- // define name of log file
- string logFile="/tmp/logs/";
- logFile += getenv("USER");
- logFile += "/batchSalome_";
- srand ( time(NULL) );
- int ir = rand();
- ostringstream oss;
- oss << ir;
- logFile += oss.str();
- logFile += ".log";
-
- string command;
+ // define name of log file (local)
+ string logFile = generateTemporaryFileName("LSF-submitlog");
// define command to submit batch
- command = _protocol;
- command += " ";
-
- if(_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"cd " ;
- command += dirForTmpFiles ;
- command += "; bsub < " ;
- command += fileNameToExecute ;
- command += "_Batch.sh\" > ";
+ string subCommand = string("cd ") + dirForTmpFiles + "; bsub < " +
+ fileNameToExecute + "_Batch.sh";
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+ command += " > ";
command += logFile;
cerr << command.c_str() << endl;
status = system(command.c_str());
istringstream iss(jobid.getReference());
iss >> ref;
- // define command to submit batch
- string command;
- command = _protocol;
- command += " ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"bkill " ;
- command += iss.str();
- command += "\"";
+ // define command to delete batch
+ string subCommand = string("bkill ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
- if(status)
+ if (status)
throw EmulationException("Error of connection on remote host");
cerr << "jobId = " << ref << "killed" << endl;
istringstream iss(jobid.getReference());
iss >> id;
- // define name of log file
- string logFile="/tmp/logs/";
- logFile += getenv("USER");
- logFile += "/batchSalome_";
-
- srand ( time(NULL) );
- int ir = rand();
- ostringstream oss;
- oss << ir;
- logFile += oss.str();
- logFile += ".log";
+ // define name of log file (local)
+ string logFile = generateTemporaryFileName(string("LSF-querylog-id") + jobid.getReference());
- string command;
- int status;
-
- // define command to submit batch
- command = _protocol;
- command += " ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"bjobs " ;
- command += iss.str();
- command += "\" > ";
+ // define command to query batch
+ string subCommand = string("bjobs ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+ command += " > ";
command += logFile;
cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
+ int status = system(command.c_str());
+ if (status)
throw EmulationException("Error of connection on remote host");
JobInfo_eLSF ji = JobInfo_eLSF(id,logFile);
void BatchManager_eLSF::buildBatchScript(const Job & job)
{
#ifndef WIN32 //TODO: need for porting on Windows
- int status;
Parametre params = job.getParametre();
Environnement env = job.getEnvironnement();
const int nbproc = params[NBPROC];
TmpFileName.c_str(), 0x1ED);
cerr << TmpFileName.c_str() << endl;
- string command;
- if( _protocol == "rsh" )
- command = "rcp ";
- else if( _protocol == "ssh" )
- command = "scp ";
- else
- throw EmulationException("Unknown protocol");
- command += TmpFileName;
- command += " ";
- if(_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += dirForTmpFiles ;
- command += "/" ;
- command += rootNameToExecute ;
- command += "_Batch.sh" ;
- cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
+ int status = _protocol.copyFile(TmpFileName, "", "",
+ dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh",
+ _hostname, _username);
+ if (status)
throw EmulationException("Error of connection on remote host");
remove(TmpFileName.c_str());
*
*/
-#ifndef _BATCHMANAGER_eLSF_H_
-#define _BATCHMANAGER_eLSF_H_
+#ifndef _BATCHMANAGER_ELSF_H_
+#define _BATCHMANAGER_ELSF_H_
-#include "Batch_Defines.hxx"
-
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_eLSF.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager.hxx"
-#include "Batch_BatchManager_eClient.hxx"
+#include <Batch_Defines.hxx>
+#include <Batch_JobId.hxx>
+#include <Batch_JobInfo.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_BatchManager_eClient.hxx>
namespace Batch {
- class Job;
- class JobId;
- class JobInfo;
- class FactBatchManager;
-
class BATCH_EXPORT BatchManager_eLSF : public BatchManager_eClient
{
public:
// Constructeur et destructeur
- BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="nompi") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
+ BatchManager_eLSF(const FactBatchManager * parent, const char * host="localhost",
+ CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host
virtual ~BatchManager_eLSF();
// Recupere le nom du serveur par defaut
*
*/
-#include <string>
#include "Batch_BatchManager_eLSF.hxx"
#include "Batch_FactBatchManager_eLSF.hxx"
-//#include "utilities.h"
namespace Batch {
return new BatchManager_eLSF(this, hostname);
}
- BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const
+ BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const
{
// MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'");
- return new BatchManager_eLSF(this, hostname, protocol, mpiImpl);
+ return new BatchManager_eLSF(this, hostname, protocolType, mpiImpl);
}
}
#ifndef _FACTBATCHMANAGER_eLSF_H_
#define _FACTBATCHMANAGER_eLSF_H_
-#include "Batch_Defines.hxx"
-
-#include <string>
-#include <map>
-#include "Batch_BatchManager_eClient.hxx"
-#include "Batch_FactBatchManager_eClient.hxx"
+#include <Batch_Defines.hxx>
+#include <Batch_BatchManager_eClient.hxx>
+#include <Batch_FactBatchManager_eClient.hxx>
namespace Batch {
- class BatchManager_eLSF;
-
class BATCH_EXPORT FactBatchManager_eLSF : public FactBatchManager_eClient
{
public:
virtual ~FactBatchManager_eLSF();
virtual BatchManager * operator() (const char * hostname) const;
- virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const;
+ virtual BatchManager_eClient * operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const;
protected:
* 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 <iostream>
#include <sys/types.h>
#ifdef WIN32
-# include <direct.h>
+#include <direct.h>
#include "Batch_RunTimeException.hxx"
#else
-# include <sys/wait.h>
-# include <unistd.h>
+#include <sys/wait.h>
+#include <unistd.h>
#endif
#include <ctime>
#include <pthread.h>
// Constructeur
- BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host)
+ BatchManager_Local::BatchManager_Local(const FactBatchManager * parent, const char * host,
+ CommunicationProtocolType protocolType)
throw(InvalidArgumentException,ConnexionFailureException)
- : BatchManager(parent, host), _connect(0), _threads_mutex(), _threads(), _thread_id_id_association_mutex(),
- _thread_id_id_association_cond(), _thread_id_id_association()
+ : BatchManager(parent, host), _connect(0), _threads_mutex(), _threads(),
+ _protocol(CommunicationProtocol::getInstance(protocolType)),
+ _thread_id_id_association_mutex(), _thread_id_id_association_cond(), _thread_id_id_association()
{
pthread_mutex_init(&_threads_mutex, NULL);
pthread_mutex_init(&_thread_id_id_association_mutex, NULL);
pthread_cond_destroy(&_thread_id_id_association_cond);
}
+ const CommunicationProtocol & BatchManager_Local::getProtocol() const
+ {
+ return _protocol;
+ }
+
// Methode pour le controle des jobs : soumet un job au gestionnaire
const JobId BatchManager_Local::submitJob(const Job & job)
{
}
+ vector<string> 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<StringType *>(*it);
+ string arg = argt;
+ exec_sub_cmd << " " << arg;
+ }
+ }
+
+ string user;
+ Parametre::const_iterator it = param.find(USER);
+ if (it != param.end()) {
+ user = string(it->second);
+ }
+
+ return _protocol.getExecCommandArgs(exec_sub_cmd.str(), param[EXECUTIONHOST], user);
+ }
+
+
// Fabrique un identifiant unique pour les threads puisque le thread_id n'est pas unique
// au cours du temps (il peut etre reutilise lorsqu'un thread se termine)
// ATTENTION : cette methode est uniquement protegee par la section critique de l'association
string local = cp.getLocal();
string remote = cp.getRemote();
- string copy_cmd = p_ta->getBatchManager().copy_command("", "", local, user,
- executionhost, workdir + "/" + remote);
- UNDER_LOCK( cout << "Copying : " << copy_cmd << endl );
-#ifdef WIN32
- copy_cmd = string("\"") + copy_cmd + string("\"");
-#endif
-
- if (system(copy_cmd.c_str()) ) {
+ int status = p_ta->getBatchManager().getProtocol().copyFile(local, "", "",
+ workdir + "/" + remote,
+ executionhost, user);
+ if (status) {
// Echec de la copie
rc |= 1;
} else {
string local = cp.getLocal();
string remote = cp.getRemote();
- string copy_cmd = p_ta->getBatchManager().copy_command(user, executionhost, workdir + "/" + remote,
- "", "", local);
- UNDER_LOCK( cout << "Copying : " << copy_cmd << endl );
-#ifdef WIN32
- copy_cmd = string("\"") + copy_cmd + string("\"");
-#endif
-
- if (system(copy_cmd.c_str()) ) {
+ int status = p_ta->getBatchManager().getProtocol().copyFile(workdir + "/" + remote,
+ executionhost, user,
+ local, "", "");
+ if (status) {
// Echec de la copie
rc |= 1;
} else {
if ( (rc == 0) || (child < 0) ) {
std::vector<string>::const_iterator it;
for(it=files_to_delete.begin(); it!=files_to_delete.end(); it++) {
- string remove_cmd = p_ta->getBatchManager().remove_command(user, executionhost, *it);
+ p_ta->getBatchManager().getProtocol().removeFile(*it, executionhost, user);
+/* string remove_cmd = p_ta->getBatchManager().remove_command(user, executionhost, *it);
UNDER_LOCK( cout << "Removing : " << remove_cmd << endl );
#ifdef WIN32
remove_cmd = string("\"") + remove_cmd + string("\"");
#endif
- system(remove_cmd.c_str());
+ system(remove_cmd.c_str());*/
}
}
try {
// EXECUTABLE is MANDATORY, if missing, we exit with failure notification
- char * execpath = NULL;
+ vector<string> command;
if (param.find(EXECUTABLE) != param.end()) {
- string executable = _bm.exec_command(param);
- execpath = new char [executable.size() + 1];
- strncpy(execpath, executable.c_str(), executable.size() + 1);
+ command = _bm.exec_command(param);
} else exit(1);
- string debug_command = execpath;
-
- string name = (param.find(NAME) != param.end()) ? param[NAME] : param[EXECUTABLE];
-
- char ** argv = NULL;
- if (param.find(ARGUMENTS) != param.end()) {
- Versatile V = param[ARGUMENTS];
-
- argv = new char * [V.size() + 2]; // 1 pour name et 1 pour le NULL terminal
-
- argv[0] = new char [name.size() + 1];
- strncpy(argv[0], name.c_str(), name.size() + 1);
-
- debug_command += string(" # ") + argv[0];
-
- int i = 1;
- for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++, i++) {
- StringType argt = * static_cast<StringType *>(*it);
- string arg = argt;
- argv[i] = new char [arg.size() + 1];
- strncpy(argv[i], arg.c_str(), arg.size() + 1);
- debug_command += string(" # ") + argv[i];
- }
-
- // assert (i == V.size() + 1)
- argv[i] = NULL;
+ // Build the argument array argv from the command
+ char ** argv = new char * [command.size() + 1];
+ string comstr;
+ for (string::size_type i=0 ; i<command.size() ; i++) {
+ argv[i] = new char[command[i].size() + 1];
+ strncpy(argv[i], command[i].c_str(), command[i].size() + 1);
+ if (i>0) comstr += " # ";
+ comstr += command[i];
}
+ argv[command.size()] = NULL;
- UNDER_LOCK( cout << "*** debug_command = " << debug_command << endl );
-
-
+ UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
// Create the environment for the new process. Note (RB): Here we change the environment for
// the process launched in local. It would seem more logical to set the environment for the
// On execute la commande du fils
- execve(execpath, argv, envp);
+ execve(argv[0], argv, envp);
// No need to deallocate since nothing happens after a successful exec
try {
// EXECUTABLE is MANDATORY, if missing, we throw an exception
- string exec_command;
+ vector<string> exec_command;
if (param.find(EXECUTABLE) != param.end()) {
exec_command = _bm.exec_command(param);
} else {
throw RunTimeException("Parameter \"EXECUTABLE\" is mandatory for local batch submission");
}
- if (param.find(ARGUMENTS) != param.end()) {
- Versatile V = param[ARGUMENTS];
-
- for(Versatile::const_iterator it=V.begin() ; it!=V.end() ; it++) {
- StringType argt = * static_cast<StringType *>(*it);
- exec_command += string(" ") + string(argt);
- }
+ // Build the command string from the command argument vector
+ string comstr;
+ for (unsigned int i=0 ; i<exec_command.size() ; i++) {
+ if (i>0) comstr += " ";
+ comstr += exec_command[i];
}
- UNDER_LOCK( cout << "*** exec_command = " << exec_command << endl );
-
+ UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
// Create the environment for the new process. Note (RB): Here we change the environment for
// the process launched in local. It would seem more logical to set the environment for the
ZeroMemory( &pi, sizeof(pi) );
// Copy the command to a non-const buffer
- char * buffer = strdup(exec_command.c_str());
+ char * buffer = strdup(comstr.c_str());
// launch the new process
BOOL res = CreateProcess(NULL, buffer, NULL, NULL, FALSE,
* 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_Defines.hxx>
+#include <Batch_CommunicationProtocol.hxx>
#ifdef WIN32
#include <Windows.h>
public:
// Constructeur et destructeur
- BatchManager_Local(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
+ BatchManager_Local(const FactBatchManager * parent,
+ const char * host="localhost",
+ CommunicationProtocolType protocolType = SSH)
+ throw(InvalidArgumentException,
+ ConnexionFailureException); // connexion a la machine host
virtual ~BatchManager_Local();
// Recupere le nom du serveur par defaut
// static string BatchManager_Local::getDefaultServer();
+ // Get the underlying communication protocol
+ const CommunicationProtocol & getProtocol() const;
+
// Methodes pour le controle des jobs
virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire
virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire
pthread_mutex_t _threads_mutex;
std::map<Id, Child > _threads;
- // Methode abstraite qui renvoie la commande de copie du fichier source en destination
- virtual std::string copy_command( const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const = 0;
-
- // Methode abstraite qui renvoie la commande a executer
- virtual std::string exec_command(Parametre & param) const = 0;
-
- // Methode abstraite qui renvoie la commande d'effacement du fichier
- virtual std::string remove_command( const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const = 0;
+ const CommunicationProtocol & _protocol;
+
+ // Methode qui renvoie la commande a executer
+ std::vector<std::string> exec_command(const Parametre & param) const;
private:
struct ThreadIdIdAssociation {
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_RSH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <cstdlib>
-#include <sys/types.h>
-#ifndef WIN32
-#include <sys/wait.h>
-#include <unistd.h>
-#endif
-#include <ctime>
-#include <pthread.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-
-#include "Batch_IOMutex.hxx"
-#include "Batch_BatchManager_Local_RSH.hxx"
-
-#include "Batch_config.h"
-
-#ifndef RCP
-#error "RCP undefined. You must set RCP to a valid path to a rcp-like command."
-#endif
-
-#ifndef RSH
-#error "RSH undefined. You must set RSH to a valid path to a rsh-like command."
-#endif
-
-using namespace std;
-
-namespace Batch {
-
-
- // Constructeur
- BatchManager_Local_RSH::BatchManager_Local_RSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
- {
- }
-
- // Destructeur
- BatchManager_Local_RSH::~BatchManager_Local_RSH()
- {
- }
-
-
- // Methode abstraite qui renvoie la commande de copie du fichier source en destination
- string BatchManager_Local_RSH::copy_command(const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- ostringstream fullsource;
- if (host_source.size() != 0) {
- if (user_source.size() != 0) {
-#ifdef WIN32
- fullsource << host_source << "." << user_source << ":";
-#else
- fullsource << user_source << "@" << host_source << ":";
-#endif
- } else {
- fullsource << host_source << ":";
- }
- }
- fullsource << source;
-
- ostringstream fulldestination;
- if (host_destination.size() != 0) {
- if (user_destination.size() != 0) {
-#ifdef WIN32
- fulldestination << host_destination << "." << user_destination << ":";
-#else
- fulldestination << user_destination << "@" << host_destination << ":";
-#endif
- } else {
- fulldestination << host_destination << ":";
- }
- }
- fulldestination << destination;
-
- ostringstream copy_cmd;
- copy_cmd << "\"" << RCP << "\" " << fullsource.str() << " " << fulldestination.str();
- return copy_cmd.str();
- }
-
- // Methode abstraite qui renvoie la commande a executer
- string BatchManager_Local_RSH::exec_command(Parametre & param) const
- {
- ostringstream exec_sub_cmd;
- exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE];
-
- if (param.find(ARGUMENTS) != param.end()) {
- Versatile V = param[ARGUMENTS];
- for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
- StringType argt = * static_cast<StringType *>(*it);
- string arg = argt;
- exec_sub_cmd << " " << arg;
- }
- }
-
- Versatile new_arguments;
- new_arguments.setMaxSize(0);
- new_arguments = string(param[EXECUTIONHOST]);
-
-
- if (param.find(USER) != param.end()) {
- new_arguments += "-l";
- new_arguments += string(param[USER]);
- }
-
-#ifdef WIN32
- new_arguments += "-n";
-#endif
-
- new_arguments += exec_sub_cmd.str();
-
- param[ARGUMENTS] = new_arguments;
-
- // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
- param[EXECUTABLE] = RSH;
- param.erase(NAME);
-
- return RSH;
- }
-
- // Methode qui renvoie la commande d'effacement du fichier
- string BatchManager_Local_RSH::remove_command(const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- string fulldestination = (host_destination.size()) ? host_destination : "localhost";
- if (user_destination.size() != 0) {
- fulldestination += " -l " + user_destination;
- }
-
- // We consider here that the remote system is UNIX-like and has a "rm" command. Using the
- // RM macro would be pointless here since the remote system is different from the local one.
- ostringstream remove_cmd;
- remove_cmd << "\"" << RSH << "\" " << fulldestination;
-#ifdef WIN32
- remove_cmd << " -n";
-#endif
- remove_cmd << " rm " << destination;
- return remove_cmd.str();
- }
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_RSH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#ifndef _BATCHMANAGER_LOCAL_RSH_H_
-#define _BATCHMANAGER_LOCAL_RSH_H_
-
-#include "Batch_Defines.hxx"
-
-#include <vector>
-#include <map>
-#include <queue>
-#include <deque>
-#include <pthread.h>
-#include "Batch_Job.hxx"
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_Local.hxx"
-#include "Batch_Job_Local.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager_Local.hxx"
-
-namespace Batch {
-
- class FactBatchManager;
-
- class BATCH_EXPORT BatchManager_Local_RSH : public BatchManager_Local
- {
- public:
- // Constructeur et destructeur
- BatchManager_Local_RSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
- virtual ~BatchManager_Local_RSH();
-
- protected:
- // Methode qui renvoie la commande de copie du fichier source en destination
- virtual std::string copy_command( const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- // Methode qui renvoie la commande a executer
- virtual std::string exec_command(Parametre & param) const;
-
- // Methode qui renvoie la commande d'effacement du fichier
- virtual std::string remove_command( const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- };
-
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_SH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <SALOMEconfig.h>
-#endif
-
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <cstdlib>
-#include <sys/types.h>
-#ifndef WIN32
-#include <sys/wait.h>
-#include <unistd.h>
-#endif
-#include <ctime>
-#include <pthread.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include "Batch_IOMutex.hxx"
-#include "Batch_BatchManager_Local_SH.hxx"
-
-#include "Batch_config.h"
-
-#ifndef RM
-#error "RM undefined. You must set RM to a valid path to a rm-like command."
-#endif
-
-#ifndef CP
-#error "CP undefined. You must set CP to a valid path to a cp-like command."
-#endif
-
-#ifndef SH
-#error "SH undefined. You must set SH to a valid path to a sh-like command."
-#endif
-
-using namespace std;
-
-namespace Batch {
-
- // Simple method to fix path strings depending on the platform. On Windows, it will replace
- // forward slashes '/' by backslashes '\'. On Unix, the path is just copied without change.
- string BatchManager_Local_SH::fixPath(const string & path) const
- {
- string fixedPath = path;
-#ifdef WIN32
- for (int i=0 ; i<fixedPath.size() ; i++) {
- if (fixedPath[i] == '/') fixedPath[i] = '\\';
- }
-#endif
- return fixedPath;
- }
-
- // Constructeur
- BatchManager_Local_SH::BatchManager_Local_SH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
- {
- }
-
- // Destructeur
- BatchManager_Local_SH::~BatchManager_Local_SH()
- {
- }
-
-
- // Methode qui renvoie la commande de copie du fichier source en destination
- string BatchManager_Local_SH::copy_command(const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- ostringstream copy_cmd;
- if (strchr(CP, ' ') == NULL)
- copy_cmd << CP;
- else
- copy_cmd << "\"" << CP << "\"";
- copy_cmd << " \"" << fixPath(source) << "\" \"" << fixPath(destination) << "\"";
- return copy_cmd.str();
- }
-
- // Methode qui renvoie la commande a executer
- string BatchManager_Local_SH::exec_command(Parametre & param) const
- {
- ostringstream exec_sub_cmd;
-#ifdef WIN32
- exec_sub_cmd << "\"";
-#endif
-#ifdef SH_COMMAND_IS_CMD
- char drive[_MAX_DRIVE];
- _splitpath_s(fixPath(param[WORKDIR]).c_str(), drive, _MAX_DRIVE, NULL, 0, NULL, 0, NULL, 0);
- if (strlen(drive) > 0) exec_sub_cmd << drive << " && ";
- exec_sub_cmd << "cd " << fixPath(param[WORKDIR]) << " && " << fixPath(param[EXECUTABLE]);
-#else
- exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE];
-#endif
-
- if (param.find(ARGUMENTS) != param.end()) {
- Versatile V = param[ARGUMENTS];
- for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
- StringType argt = * static_cast<StringType *>(*it);
- string arg = argt;
- exec_sub_cmd << " " << arg;
- }
- }
-#ifdef WIN32
- exec_sub_cmd << "\"";
-#endif
-
-#ifdef SH_COMMAND_IS_CMD
- param[ARGUMENTS] = "/c";
-#else
- param[ARGUMENTS] = "-c";
-#endif
- param[ARGUMENTS] += exec_sub_cmd.str();
-
- return fixPath(SH);
- }
-
- // Methode qui renvoie la commande d'effacement du fichier
- string BatchManager_Local_SH::remove_command(const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- ostringstream remove_cmd;
- if (strchr(RM, ' ') == NULL)
- remove_cmd << RM;
- else
- remove_cmd << "\"" << RM << "\"";
-
- remove_cmd << " \"" << fixPath(destination) << "\"";
- return remove_cmd.str();
- }
-
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_SH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#ifndef _BATCHMANAGER_LOCAL_SH_H_
-#define _BATCHMANAGER_LOCAL_SH_H_
-
-#include "Batch_Defines.hxx"
-
-#include <vector>
-#include <map>
-#include <queue>
-#include <deque>
-#include <pthread.h>
-#include "Batch_Job.hxx"
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_Local.hxx"
-#include "Batch_Job_Local.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager_Local.hxx"
-
-namespace Batch {
-
- class FactBatchManager;
-
- class BATCH_EXPORT BatchManager_Local_SH : public BatchManager_Local
- {
- public:
- // Constructeur et destructeur
- BatchManager_Local_SH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
- virtual ~BatchManager_Local_SH();
-
- protected:
- std::string fixPath(const std::string & path) const;
-
- // Methode qui renvoie la commande de copie du fichier source en destination
- virtual std::string copy_command( const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- // Methode qui renvoie la commande a executer
- virtual std::string exec_command(Parametre & param) const;
-
- // Methode qui renvoie la commande d'effacement du fichier
- virtual std::string remove_command( const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- };
-
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_SSH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#ifdef HAVE_CONFIG_H
-# include <SALOMEconfig.h>
-#endif
-
-#include <iostream>
-#include <fstream>
-#include <sstream>
-#include <cstdlib>
-#include <sys/types.h>
-#ifndef WIN32
-#include <sys/wait.h>
-#include <unistd.h>
-#endif
-#include <ctime>
-
-#include <pthread.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include "Batch_IOMutex.hxx"
-#include "Batch_BatchManager_Local_SSH.hxx"
-
-#include "Batch_config.h"
-
-#ifndef RM
-#error "RM undefined. You must set RM to a valid path to a rm-like command."
-#endif
-
-#ifndef SCP
-#error "SCP undefined. You must set SCP to a valid path to a scp-like command."
-#endif
-
-#ifndef SSH
-#error "SSH undefined. You must set SSH to a valid path to a ssh-like command."
-#endif
-
-using namespace std;
-
-namespace Batch {
-
-
- // Constructeur
- BatchManager_Local_SSH::BatchManager_Local_SSH(const FactBatchManager * parent, const char * host) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_Local(parent, host)
- {
- }
-
- // Destructeur
- BatchManager_Local_SSH::~BatchManager_Local_SSH()
- {
- }
-
-
- // Methode abstraite qui renvoie la commande de copie du fichier source en destination
- string BatchManager_Local_SSH::copy_command(const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- ostringstream fullsource;
- if (host_source.size() != 0) {
- if (user_source.size() != 0) {
- fullsource << user_source << "@";
- }
- fullsource << host_source << ":";
- }
- fullsource << source;
-
- ostringstream fulldestination;
- if (host_destination.size() != 0) {
- if (user_destination.size() != 0) {
- fulldestination << user_destination << "@";
- }
- fulldestination << host_destination << ":";
- }
- fulldestination << destination;
-
- ostringstream copy_cmd;
- // Option -p is used to keep the same permissions for the destination file (particularly useful to keep scripts
- // executable when copying them)
- copy_cmd << "\"" << SCP << "\" -p " << fullsource.str() << " " << fulldestination.str();
- return copy_cmd.str();
- }
-
- // Methode abstraite qui renvoie la commande a executer
- string BatchManager_Local_SSH::exec_command(Parametre & param) const
- {
- ostringstream exec_sub_cmd;
-#ifdef WIN32
- exec_sub_cmd << "\"";
-#endif
- exec_sub_cmd << "cd " << param[WORKDIR] << " && " << param[EXECUTABLE];
-
- if (param.find(ARGUMENTS) != param.end()) {
- Versatile V = param[ARGUMENTS];
- for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
- StringType argt = * static_cast<StringType *>(*it);
- string arg = argt;
- exec_sub_cmd << " " << arg;
- }
- }
-#ifdef WIN32
- exec_sub_cmd << "\"";
-#endif
-
-
- Versatile new_arguments;
- new_arguments.setMaxSize(0);
- new_arguments = string(param[EXECUTIONHOST]);
-
-
- if (param.find(USER) != param.end()) {
- new_arguments += "-l";
- new_arguments += string(param[USER]);
- }
-
- new_arguments += exec_sub_cmd.str();
-
- param[ARGUMENTS] = new_arguments;
-
- // Sous Linux on est oblige de modifier ces deux parametres pour faire fonctionner la commande rsh
- param[EXECUTABLE] = SSH;
- param.erase(NAME);
-
- return SSH;
- }
-
- // Methode qui renvoie la commande d'effacement du fichier
- string BatchManager_Local_SSH::remove_command(const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const
- {
- string fulldestination = (host_destination.size()) ? host_destination : "localhost";
- if (user_destination.size() != 0) {
- fulldestination += " -l " + user_destination;
- }
-
- // We consider here that the remote system is UNIX-like and has a "rm" command. Using the
- // RM macro would be pointless here since the remote system is different from the local one.
- ostringstream remove_cmd;
- remove_cmd << "\"" << SSH << "\" " << fulldestination << " \"rm " << destination << "\"";
- return remove_cmd.str();
- }
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * BatchManager_Local_SSH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Mail : mailto:ivan.dutka-malen@der.edf.fr
- * Date : Thu Nov 6 10:17:22 2003
- * Projet : Salome 2
- *
- */
-
-#ifndef _BATCHMANAGER_LOCAL_SSH_H_
-#define _BATCHMANAGER_LOCAL_SSH_H_
-
-#include "Batch_Defines.hxx"
-
-#include <vector>
-#include <map>
-#include <queue>
-#include <deque>
-#include <pthread.h>
-#include "Batch_Job.hxx"
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_Local.hxx"
-#include "Batch_Job_Local.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager_Local.hxx"
-
-namespace Batch {
-
- class FactBatchManager;
-
- class BATCH_EXPORT BatchManager_Local_SSH : public BatchManager_Local
- {
- public:
- // Constructeur et destructeur
- BatchManager_Local_SSH(const FactBatchManager * parent, const char * host="localhost") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
- virtual ~BatchManager_Local_SSH();
-
- protected:
- // Methode qui renvoie la commande de copie du fichier source en destination
- virtual std::string copy_command( const std::string & user_source,
- const std::string & host_source,
- const std::string & source,
- const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- // Methode qui renvoie la commande a executer
- virtual std::string exec_command(Parametre & param) const;
-
- // Methode qui renvoie la commande d'effacement du fichier
- virtual std::string remove_command( const std::string & user_destination,
- const std::string & host_destination,
- const std::string & destination) const;
-
- };
-
-}
-
-#endif
* 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 <string>
+#include <Batch_config.h>
+
#include "Batch_BatchManager_Local.hxx"
#include "Batch_FactBatchManager_Local.hxx"
-//#include "utilities.h"
namespace Batch {
-// static FactBatchManager_Local sFBM_Local;
+#ifdef HAS_SH
+ static FactBatchManager_Local sFBM_Local_SH("SH", SH);
+#endif
+
+#ifdef HAS_RSH
+ static FactBatchManager_Local sFBM_Local_RSH("RSH", RSH);
+#endif
+
+#ifdef HAS_SSH
+ static FactBatchManager_Local sFBM_Local_SSH("SSH", SSH);
+#endif
// Constructeur
- FactBatchManager_Local::FactBatchManager_Local() : FactBatchManager("Local")
+ FactBatchManager_Local::FactBatchManager_Local(const char * name,
+ CommunicationProtocolType protocolType)
+ : FactBatchManager(name),
+ _protocolType(protocolType)
{
// Nothing to do
}
}
// Functor
-// BatchManager * FactBatchManager_Local::operator() (const char * hostname) const
-// {
-// // MESSAGE("Building new BatchManager_Local on host '" << hostname << "'");
-// return new BatchManager_Local(this, hostname);
-// }
-
+ BatchManager * FactBatchManager_Local::operator() (const char * hostname) const
+ {
+ // MESSAGE("Building new BatchManager_Local on host '" << hostname << "'");
+ return new BatchManager_Local(this, hostname, _protocolType);
+ }
}
* 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_FactBatchManager.hxx>
+#include <Batch_CommunicationProtocol.hxx>
namespace Batch {
- class BatchManager_Local;
-
class FactBatchManager_Local : public FactBatchManager
{
public:
// Constructeur et destructeur
- FactBatchManager_Local();
+ FactBatchManager_Local(const char * name, CommunicationProtocolType protocolType);
virtual ~FactBatchManager_Local();
- virtual BatchManager * operator() (const char * hostname) const = 0;
+ virtual BatchManager * operator() (const char * hostname) const;
protected:
+ CommunicationProtocolType _protocolType;
+
private:
};
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_RSH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#include <string>
-#include "Batch_BatchManager_Local_RSH.hxx"
-#include "Batch_FactBatchManager_Local_RSH.hxx"
-//#include "utilities.h"
-
-namespace Batch {
-
- static FactBatchManager_Local_RSH sFBM_Local_RSH;
-
- // Constructeur
- FactBatchManager_Local_RSH::FactBatchManager_Local_RSH() : FactBatchManager("RSH")
- {
- // Nothing to do
- }
-
- // Destructeur
- FactBatchManager_Local_RSH::~FactBatchManager_Local_RSH()
- {
- // Nothing to do
- }
-
- // Functor
- BatchManager * FactBatchManager_Local_RSH::operator() (const char * hostname) const
- {
- // MESSAGE("Building new BatchManager_Local_RSH on host '" << hostname << "'");
- return new BatchManager_Local_RSH(this, hostname);
- }
-
-
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_RSH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#ifndef _FACTBATCHMANAGER_LOCAL_RSH_H_
-#define _FACTBATCHMANAGER_LOCAL_RSH_H_
-
-#include "Batch_FactBatchManager.hxx"
-
-namespace Batch {
-
- class BatchManager_Local_RSH;
-
- class FactBatchManager_Local_RSH : public FactBatchManager
- {
- public:
- // Constructeur et destructeur
- FactBatchManager_Local_RSH();
- virtual ~FactBatchManager_Local_RSH();
-
- virtual BatchManager * operator() (const char * hostname) const;
-
- protected:
-
- private:
-
- };
-
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_SH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#include <string>
-#include "Batch_BatchManager_Local_SH.hxx"
-#include "Batch_FactBatchManager_Local_SH.hxx"
-//#include "utilities.h"
-
-namespace Batch {
-
- static FactBatchManager_Local_SH sFBM_Local_SH;
-
- // Constructeur
- FactBatchManager_Local_SH::FactBatchManager_Local_SH() : FactBatchManager("SH")
- {
- // Nothing to do
- }
-
- // Destructeur
- FactBatchManager_Local_SH::~FactBatchManager_Local_SH()
- {
- // Nothing to do
- }
-
- // Functor
- BatchManager * FactBatchManager_Local_SH::operator() (const char * hostname) const
- {
- // MESSAGE("Building new BatchManager_Local_SH on host '" << hostname << "'");
- return new BatchManager_Local_SH(this, hostname);
- }
-
-
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_SH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#ifndef _FACTBATCHMANAGER_LOCAL_SH_H_
-#define _FACTBATCHMANAGER_LOCAL_SH_H_
-
-#include "Batch_FactBatchManager.hxx"
-
-namespace Batch {
-
- class BatchManager_Local_SH;
-
- class FactBatchManager_Local_SH : public FactBatchManager
- {
- public:
- // Constructeur et destructeur
- FactBatchManager_Local_SH();
- virtual ~FactBatchManager_Local_SH();
-
- virtual BatchManager * operator() (const char * hostname) const;
-
- protected:
-
- private:
-
- };
-
-}
-
-#endif
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_SSH.cxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#include <string>
-#include "Batch_BatchManager_Local_SSH.hxx"
-#include "Batch_FactBatchManager_Local_SSH.hxx"
-//#include "utilities.h"
-
-namespace Batch {
-
- static FactBatchManager_Local_SSH sFBM_Local_SSH;
-
- // Constructeur
- FactBatchManager_Local_SSH::FactBatchManager_Local_SSH() : FactBatchManager("SSH")
- {
- // Nothing to do
- }
-
- // Destructeur
- FactBatchManager_Local_SSH::~FactBatchManager_Local_SSH()
- {
- // Nothing to do
- }
-
- // Functor
- BatchManager * FactBatchManager_Local_SSH::operator() (const char * hostname) const
- {
- // MESSAGE("Building new BatchManager_Local_SSH on host '" << hostname << "'");
- return new BatchManager_Local_SSH(this, hostname);
- }
-
-
-}
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * FactBatchManager_Local_SSH.hxx :
- *
- * Auteur : Ivan DUTKA-MALEN - EDF R&D
- * Date : Septembre 2004
- * Projet : SALOME 2
- *
- */
-
-#ifndef _FACTBATCHMANAGER_LOCAL_SSH_H_
-#define _FACTBATCHMANAGER_LOCAL_SSH_H_
-
-#include "Batch_FactBatchManager.hxx"
-
-namespace Batch {
-
- class BatchManager_Local_SSH;
-
- class FactBatchManager_Local_SSH : public FactBatchManager
- {
- public:
- // Constructeur et destructeur
- FactBatchManager_Local_SSH();
- virtual ~FactBatchManager_Local_SSH();
-
- virtual BatchManager * operator() (const char * hostname) const;
-
- protected:
-
- private:
-
- };
-
-}
-
-#endif
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-SET(CLASS_LIST Local/Batch_BatchManager_Local_RSH
- Local/Batch_BatchManager_Local_SH
- Local/Batch_BatchManager_Local_SSH
- Local/Batch_BatchManager_Local
- Local/Batch_FactBatchManager_Local_RSH
- Local/Batch_FactBatchManager_Local_SH
- Local/Batch_FactBatchManager_Local_SSH
+SET(CLASS_LIST Local/Batch_BatchManager_Local
Local/Batch_FactBatchManager_Local
Local/Batch_IOMutex
Local/Batch_Job_Local
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Build the executable to use for the local test program
-add_executable(Exec_Test Exec_Test.cxx)
-GET_TARGET_PROPERTY(EXEC_TEST_FULL_PATH_TEMP Exec_Test LOCATION)
-GET_FILENAME_COMPONENT(EXEC_TEST_NAME_TEMP ${EXEC_TEST_FULL_PATH_TEMP} NAME)
-SET(EXEC_TEST_FULL_PATH ${EXEC_TEST_FULL_PATH_TEMP} CACHE INTERNAL "")
-SET(EXEC_TEST_NAME ${EXEC_TEST_NAME_TEMP} CACHE INTERNAL "")
-
-# Configure the config file for all the test scripts
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Local_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_Local_config.h)
-
# Just copy the test scripts to the binary dir
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY)
include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
-# Build the test programs
-add_executable(Test_Local_SH Test_Local_SH.cxx)
-target_link_libraries(Test_Local_SH Batch SimpleParser)
-
-add_executable(Test_Local_RSH Test_Local_RSH.cxx)
-target_link_libraries(Test_Local_RSH Batch SimpleParser)
-
-add_executable(Test_Local_SSH Test_Local_SSH.cxx)
-target_link_libraries(Test_Local_SSH Batch SimpleParser)
-
-# Add the tests themselves
-ADD_TEST(Local_SH Test_Local_SH)
-ADD_TEST(Local_RSH Test_Local_RSH)
-ADD_TEST(Local_SSH Test_Local_SSH)
+# Build the test programs and add the tests
+IF (HAS_SH)
+
+ # Build the executable to use for the local test program
+ add_executable(Exec_Test Exec_Test.cxx)
+ GET_TARGET_PROPERTY(EXEC_TEST_FULL_PATH_TEMP Exec_Test LOCATION)
+ GET_FILENAME_COMPONENT(EXEC_TEST_NAME_TEMP ${EXEC_TEST_FULL_PATH_TEMP} NAME)
+ SET(EXEC_TEST_FULL_PATH ${EXEC_TEST_FULL_PATH_TEMP} CACHE INTERNAL "")
+ SET(EXEC_TEST_NAME ${EXEC_TEST_NAME_TEMP} CACHE INTERNAL "")
+
+ # Configure the config file for the test
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Local_config.h.in ${CMAKE_CURRENT_BINARY_DIR}/Test_Local_config.h)
+
+ add_executable(Test_Local_SH Test_Local_SH.cxx)
+ target_link_libraries(Test_Local_SH Batch SimpleParser)
+ ADD_TEST(Local_SH Test_Local_SH)
+
+ENDIF (HAS_SH)
+
+IF (HAS_SSH)
+ add_executable(Test_Local_SSH Test_Local_SSH.cxx)
+ target_link_libraries(Test_Local_SSH Batch SimpleParser)
+ ADD_TEST(Local_SSH Test_Local_SSH)
+ENDIF (HAS_SSH)
+
+IF (HAS_RSH)
+ add_executable(Test_Local_RSH Test_Local_RSH.cxx)
+ target_link_libraries(Test_Local_RSH Batch SimpleParser)
+ ADD_TEST(Local_RSH Test_Local_RSH)
+ENDIF (HAS_RSH)
// 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
// 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
// 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
#include <sstream>
#include <sys/stat.h>
-#include "Batch_config.h"
+#include <Batch_config.h>
#ifdef MSVC
#include <io.h>
#endif
#include "Batch_BatchManager_ePBS.hxx"
+#include "Batch_JobInfo_ePBS.hxx"
using namespace std;
namespace Batch {
BatchManager_ePBS::BatchManager_ePBS(const FactBatchManager * parent, const char * host,
- const char * protocol, const char * mpiImpl)
- : BatchManager_eClient(parent, host, protocol, mpiImpl)
+ CommunicationProtocolType protocolType, const char * mpiImpl)
+ : BatchManager_eClient(parent, host, protocolType, mpiImpl)
{
// Nothing to do
}
string logFile = generateTemporaryFileName("PBS-submitlog");
// define command to submit batch
- string command = "\"";
-
- // Test protocol
- if( _protocol == "rsh" )
- command += RSH;
- else if( _protocol == "ssh" )
- command += SSH;
- else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
-
- if(_username != ""){
- command += _username + "@";
- }
-
- command += _hostname + " ";
-#ifndef WIN32
- command += "\"";
-#endif
- command += "cd " ;
- command += dirForTmpFiles ;
- command += "; qsub " ;
- command += fileNameToExecute ;
- command += "_Batch.sh";
-#ifndef WIN32
- command += "\"";
-#endif
+ string subCommand = string("cd ") + dirForTmpFiles + "; qsub " +
+ fileNameToExecute + "_Batch.sh";
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " > ";
command += logFile;
cerr << command.c_str() << endl;
throw EmulationException("Error of connection on remote host");
// read id of submitted job in log file
- char line[128];
- FILE *fp = fopen(logFile.c_str(),"r");
- fgets( line, 128, fp);
- fclose(fp);
+ ifstream idfile(logFile.c_str());
+ string sline;
+ idfile >> sline;
+ idfile.close();
+ if (sline.size() == 0)
+ throw EmulationException("Error in the submission of the job on the remote host");
- string sline(line);
size_t pos = sline.find(".");
string strjob;
if(pos == string::npos)
istringstream iss(jobid.getReference());
iss >> ref;
- // define command to submit batch
- string command;
- command = _protocol;
- command += " ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"qdel " ;
- command += iss.str();
- command += "\"";
+ // define command to delete batch
+ string subCommand = string("qdel ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
- if(status)
+ if (status)
throw EmulationException("Error of connection on remote host");
cerr << "jobId = " << ref << "killed" << endl;
string logFile = generateTemporaryFileName(string("PBS-querylog-id") + jobid.getReference());
// define command to query batch
- string command = "\"";
-
- // Test protocol
- if( _protocol == "rsh" )
- command += RSH;
- else if( _protocol == "ssh" )
- command += SSH;
- else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
-
- if (_username != ""){
- command += _username + "@";
- }
-
- command += _hostname + " ";
-#ifndef WIN32
- command += "\"";
-#endif
- command += "qstat -f " ;
- command += iss.str();
-#ifndef WIN32
- command += "\"";
-#endif
+ string subCommand = string("qstat -f ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " > ";
command += logFile;
cerr << command.c_str() << endl;
void BatchManager_ePBS::buildBatchScript(const Job & job)
{
- int status;
Parametre params = job.getParametre();
Environnement env = job.getEnvironnement();
const long nbproc = params[NBPROC];
TmpFileName.c_str(), 0x1ED);
cerr << TmpFileName.c_str() << endl;
- string command = "\"";
-
- // Test protocol
- if( _protocol == "rsh" ) {
- command += RCP;
- } else if( _protocol == "ssh" ) {
- command += SCP;
- } else
- throw EmulationException("Unknown protocol : only rsh and ssh are known !");
-
- command += "\" ";
-
- command += TmpFileName;
- command += " ";
- if(_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += dirForTmpFiles ;
- command += "/" ;
- command += rootNameToExecute ;
- command += "_Batch.sh" ;
- cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
+ int status = _protocol.copyFile(TmpFileName, "", "",
+ dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh",
+ _hostname, _username);
+ if (status)
throw EmulationException("Error of connection on remote host");
remove(TmpFileName.c_str());
*
*/
-#ifndef _BATCHMANAGER_eLSF_H_
-#define _BATCHMANAGER_eLSF_H_
+#ifndef _BATCHMANAGER_EPBS_H_
+#define _BATCHMANAGER_EPBS_H_
-#include "Batch_Defines.hxx"
-
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_ePBS.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager.hxx"
-#include "Batch_BatchManager_eClient.hxx"
+#include <Batch_Defines.hxx>
+#include <Batch_JobId.hxx>
+#include <Batch_JobInfo.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_BatchManager_eClient.hxx>
namespace Batch {
- class Job;
- class JobId;
- class JobInfo;
- class FactBatchManager;
-
class BATCH_EXPORT BatchManager_ePBS : public BatchManager_eClient
{
public:
// Constructeur et destructeur
BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost",
- const char * protocol="ssh", const char * mpiImpl="nompi"); // connexion a la machine host
+ CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host
virtual ~BatchManager_ePBS();
// Recupere le nom du serveur par defaut
return new BatchManager_ePBS(this, hostname);
}
- BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const
+ BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const
{
// MESSAGE("Building new BatchManager_PBS on host '" << hostname << "'");
- return new BatchManager_ePBS(this, hostname, protocol, mpiImpl);
+ return new BatchManager_ePBS(this, hostname, protocolType, mpiImpl);
}
virtual ~FactBatchManager_ePBS();
virtual BatchManager * operator() (const char * hostname) const;
- virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const;
+ virtual BatchManager_eClient * operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const;
protected:
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Build the test programs and add the tests
-add_executable(Test_ePBS Test_ePBS.cxx)
-target_link_libraries(Test_ePBS Batch SimpleParser)
-ADD_TEST(ePBS Test_ePBS)
+IF (HAS_SSH)
+ add_executable(Test_ePBS_SSH Test_ePBS_SSH.cxx)
+ target_link_libraries(Test_ePBS_SSH Batch SimpleParser)
+ ADD_TEST(ePBS_SSH Test_ePBS_SSH)
+ENDIF (HAS_SSH)
+
+IF (HAS_RSH)
+ add_executable(Test_ePBS_RSH Test_ePBS_RSH.cxx)
+ target_link_libraries(Test_ePBS_RSH Batch SimpleParser)
+ ADD_TEST(ePBS_RSH Test_ePBS_RSH)
+ENDIF (HAS_RSH)
IF (BUILD_PBS_INTERFACE AND PBS_FOUND)
add_executable(Test_PBS Test_PBS.cxx)
+++ /dev/null
-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-/*
- * Test_ePBS.cxx :
- *
- * Author : Renaud BARATE - EDF R&D
- * Date : April 2009
- *
- */
-
-#include <iostream>
-#include <fstream>
-
-#include <Batch_Job.hxx>
-#include <Batch_BatchManagerCatalog.hxx>
-#include <Batch_FactBatchManager.hxx>
-#include <Batch_FactBatchManager_eClient.hxx>
-#include <Batch_BatchManager.hxx>
-#include <Batch_BatchManager_eClient.hxx>
-
-#include <SimpleParser.hxx>
-
-#ifdef WIN32
-#include <Windows.h>
-#define sleep(seconds) Sleep((seconds)*1000)
-#define usleep(useconds) Sleep((useconds)/1000)
-#endif
-
-using namespace std;
-using namespace Batch;
-
-int main(int argc, char** argv)
-{
- cout << "*******************************************************************************************" << endl;
- cout << "This program tests the batch submission based on PBS emulation. Passwordless SSH" << endl;
- cout << "authentication must be used for this test to pass (this can be configured with ssh-agent" << endl;
- cout << "for instance). You also need to create a directory \"tmp/Batch\" in your home directory on" << endl;
- cout << "the PBS server before running this test." << endl;
- cout << "*******************************************************************************************" << endl;
-
- // eventually remove any previous result
- remove("result.txt");
-
- try {
- // Parse the test configuration file
- SimpleParser parser;
- parser.parseTestConfigFile();
- const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
- const string & host = parser.getValue("TEST_EPBS_HOST");
- const string & user = parser.getValue("TEST_EPBS_USER");
- const string & queue = parser.getValue("TEST_EPBS_QUEUE");
- int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
-
- // Define the job...
- Job job;
- // ... and its parameters ...
- Parametre p;
- p["EXECUTABLE"] = "./test-script.sh";
- p["NAME"] = "Test_ePBS";
- p["WORKDIR"] = homedir + "/tmp/Batch";
- p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
- p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
- p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
- p["TMPDIR"] = "tmp/Batch/";
- p["USER"] = user;
- p["NBPROC"] = 1;
- p["MAXWALLTIME"] = 1;
- p["MAXRAMSIZE"] = 4;
- p["HOMEDIR"] = homedir;
- p["QUEUE"] = queue;
- job.setParametre(p);
- // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
- Environnement e;
- const char * sshAuthSock = getenv("SSH_AUTH_SOCK");
- if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock;
- job.setEnvironnement(e);
- cout << job << endl;
-
- // Get the catalog
- BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
-
- // Create a BatchManager of type ePBS on localhost
- FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
- BatchManager_eClient * bm = (*fbm)(host.c_str(), "ssh", "lam");
-
- // Submit the job to the BatchManager
- JobId jobid = bm->submitJob(job);
- cout << jobid.__repr__() << endl;
-
- // Wait for the end of the job
- string state = "Undefined";
- for (int i=0 ; i<timeout/2 && state != "U"; i++) {
- sleep(2);
- JobInfo jinfo = jobid.queryJob();
- state = jinfo.getParametre()["STATE"].str();
- cout << "State is \"" << state << "\"" << endl;
- }
-
- if (state == "U") {
- cout << "Job " << jobid.__repr__() << " is done" << endl;
- bm->importOutputFiles(job, ".");
- } else {
- cerr << "Timeout while executing job" << endl;
- return 1;
- }
-
- } catch (GenericException e) {
- cerr << "Error: " << e << endl;
- return 1;
- } catch (ParserException e) {
- cerr << "Parser error: " << e.what() << endl;
- return 1;
- }
-
- // test the result file
- string exp = "c = 12";
- string res;
- ifstream f("result.txt");
- getline(f, res);
- f.close();
-
- cout << "result found : " << res << ", expected : " << exp << endl;
-
- if (res == exp)
- return 0;
- else
- return 1;
-}
--- /dev/null
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Test_ePBS.cxx :
+ *
+ * Author : Renaud BARATE - EDF R&D
+ * Date : April 2009
+ *
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <Batch_Job.hxx>
+#include <Batch_BatchManagerCatalog.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_FactBatchManager_eClient.hxx>
+#include <Batch_BatchManager.hxx>
+#include <Batch_BatchManager_eClient.hxx>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
+
+using namespace std;
+using namespace Batch;
+
+int main(int argc, char** argv)
+{
+ cout << "*******************************************************************************************" << endl;
+ cout << "This program tests the batch submission based on PBS emulation with RSH. Passwordless RSH" << endl;
+ cout << "authentication must be used for this test to pass (this can be configured with the .rhosts" << endl;
+ cout << "file). You also need to create a directory \"tmp/Batch\" in your home directory on the PBS" << endl;
+ cout << "server before running this test." << endl;
+ cout << "*******************************************************************************************" << endl;
+
+ // eventually remove any previous result
+ remove("result.txt");
+
+ try {
+ // Parse the test configuration file
+ SimpleParser parser;
+ parser.parseTestConfigFile();
+ const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
+ const string & host = parser.getValue("TEST_EPBS_HOST");
+ const string & user = parser.getValue("TEST_EPBS_USER");
+ const string & queue = parser.getValue("TEST_EPBS_QUEUE");
+ int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
+
+ // Define the job...
+ Job job;
+ // ... and its parameters ...
+ Parametre p;
+ p["EXECUTABLE"] = "./test-script.sh";
+ p["NAME"] = "Test_ePBS_RSH";
+ p["WORKDIR"] = homedir + "/tmp/Batch";
+ p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
+ p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
+ p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
+ p["TMPDIR"] = "tmp/Batch/";
+ p["USER"] = user;
+ p["NBPROC"] = 1;
+ p["MAXWALLTIME"] = 1;
+ p["MAXRAMSIZE"] = 4;
+ p["HOMEDIR"] = homedir;
+ p["QUEUE"] = queue;
+ job.setParametre(p);
+ // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
+ Environnement e;
+ const char * sshAuthSock = getenv("SSH_AUTH_SOCK");
+ if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock;
+ job.setEnvironnement(e);
+ cout << job << endl;
+
+ // Get the catalog
+ BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
+
+ // Create a BatchManager of type ePBS on localhost
+ FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
+ BatchManager_eClient * bm = (*fbm)(host.c_str(), RSH, "lam");
+
+ // Submit the job to the BatchManager
+ JobId jobid = bm->submitJob(job);
+ cout << jobid.__repr__() << endl;
+
+ // Wait for the end of the job
+ string state = "Undefined";
+ for (int i=0 ; i<timeout/2 && state != "U"; i++) {
+ sleep(2);
+ JobInfo jinfo = jobid.queryJob();
+ state = jinfo.getParametre()["STATE"].str();
+ cout << "State is \"" << state << "\"" << endl;
+ }
+
+ if (state == "U") {
+ cout << "Job " << jobid.__repr__() << " is done" << endl;
+ bm->importOutputFiles(job, ".");
+ } else {
+ cerr << "Timeout while executing job" << endl;
+ return 1;
+ }
+
+ } catch (GenericException e) {
+ cerr << "Error: " << e << endl;
+ return 1;
+ } catch (ParserException e) {
+ cerr << "Parser error: " << e.what() << endl;
+ return 1;
+ }
+
+ // test the result file
+ string exp = "c = 12";
+ string res;
+ ifstream f("result.txt");
+ getline(f, res);
+ f.close();
+
+ cout << "result found : " << res << ", expected : " << exp << endl;
+
+ if (res == exp)
+ return 0;
+ else
+ return 1;
+}
--- /dev/null
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+/*
+ * Test_ePBS.cxx :
+ *
+ * Author : Renaud BARATE - EDF R&D
+ * Date : April 2009
+ *
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <Batch_Job.hxx>
+#include <Batch_BatchManagerCatalog.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_FactBatchManager_eClient.hxx>
+#include <Batch_BatchManager.hxx>
+#include <Batch_BatchManager_eClient.hxx>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#define sleep(seconds) Sleep((seconds)*1000)
+#define usleep(useconds) Sleep((useconds)/1000)
+#endif
+
+using namespace std;
+using namespace Batch;
+
+int main(int argc, char** argv)
+{
+ cout << "*******************************************************************************************" << endl;
+ cout << "This program tests the batch submission based on PBS emulation with SSH. Passwordless SSH" << endl;
+ cout << "authentication must be used for this test to pass (this can be configured with ssh-agent" << endl;
+ cout << "for instance). You also need to create a directory \"tmp/Batch\" in your home directory on" << endl;
+ cout << "the PBS server before running this test." << endl;
+ cout << "*******************************************************************************************" << endl;
+
+ // eventually remove any previous result
+ remove("result.txt");
+
+ try {
+ // Parse the test configuration file
+ SimpleParser parser;
+ parser.parseTestConfigFile();
+ const string & homedir = parser.getValue("TEST_EPBS_HOMEDIR");
+ const string & host = parser.getValue("TEST_EPBS_HOST");
+ const string & user = parser.getValue("TEST_EPBS_USER");
+ const string & queue = parser.getValue("TEST_EPBS_QUEUE");
+ int timeout = parser.getValueAsInt("TEST_EPBS_TIMEOUT");
+
+ // Define the job...
+ Job job;
+ // ... and its parameters ...
+ Parametre p;
+ p["EXECUTABLE"] = "./test-script.sh";
+ p["NAME"] = "Test_ePBS_SSH";
+ p["WORKDIR"] = homedir + "/tmp/Batch";
+ p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
+ p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
+ p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
+ p["TMPDIR"] = "tmp/Batch/";
+ p["USER"] = user;
+ p["NBPROC"] = 1;
+ p["MAXWALLTIME"] = 1;
+ p["MAXRAMSIZE"] = 4;
+ p["HOMEDIR"] = homedir;
+ p["QUEUE"] = queue;
+ job.setParametre(p);
+ // ... and its environment (SSH_AUTH_SOCK env var is important for ssh agent authentication)
+ Environnement e;
+ const char * sshAuthSock = getenv("SSH_AUTH_SOCK");
+ if (sshAuthSock != NULL) e["SSH_AUTH_SOCK"] = sshAuthSock;
+ job.setEnvironnement(e);
+ cout << job << endl;
+
+ // Get the catalog
+ BatchManagerCatalog& c = BatchManagerCatalog::getInstance();
+
+ // Create a BatchManager of type ePBS on localhost
+ FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
+ BatchManager_eClient * bm = (*fbm)(host.c_str(), SSH, "lam");
+
+ // Submit the job to the BatchManager
+ JobId jobid = bm->submitJob(job);
+ cout << jobid.__repr__() << endl;
+
+ // Wait for the end of the job
+ string state = "Undefined";
+ for (int i=0 ; i<timeout/2 && state != "U"; i++) {
+ sleep(2);
+ JobInfo jinfo = jobid.queryJob();
+ state = jinfo.getParametre()["STATE"].str();
+ cout << "State is \"" << state << "\"" << endl;
+ }
+
+ if (state == "U") {
+ cout << "Job " << jobid.__repr__() << " is done" << endl;
+ bm->importOutputFiles(job, ".");
+ } else {
+ cerr << "Timeout while executing job" << endl;
+ return 1;
+ }
+
+ } catch (GenericException e) {
+ cerr << "Error: " << e << endl;
+ return 1;
+ } catch (ParserException e) {
+ cerr << "Parser error: " << e.what() << endl;
+ return 1;
+ }
+
+ // test the result file
+ string exp = "c = 12";
+ string res;
+ ifstream f("result.txt");
+ getline(f, res);
+ f.close();
+
+ cout << "result found : " << res << ", expected : " << exp << endl;
+
+ if (res == exp)
+ return 0;
+ else
+ return 1;
+}
if (PyList_Check(_PyO)) { // c'est une liste
_maxsize = PyList_Size(_PyO);
- for(int i=0; i<_maxsize; i++) {
- PyObject * val = PyList_GetItem(_PyO, i);
- if (PyString_Check(val)) {
- *this += PyString_AsString(val);
-
- } else if (PyTuple_Check(val) &&
- (PyTuple_Size(val) == 2) &&
- PyString_Check( PyTuple_GetItem(val,0) ) &&
- PyString_Check( PyTuple_GetItem(val,1) ) ) {
- *this += Couple( PyString_AsString( PyTuple_GetItem(val,0) ),
- PyString_AsString( PyTuple_GetItem(val,1) )
- );
-
- } else {
- PyErr_SetString(PyExc_RuntimeWarning, "PyVersatile::PyVersatile(const PyObject * PyO) : invalid PyObject");
- }
+ for (size_type i=0; i<_maxsize; i++) {
+ PyObject * val = PyList_GetItem(_PyO, i);
+ if (PyString_Check(val)) {
+ *this += PyString_AsString(val);
+
+ } else if (PyTuple_Check(val) &&
+ (PyTuple_Size(val) == 2) &&
+ PyString_Check( PyTuple_GetItem(val,0) ) &&
+ PyString_Check( PyTuple_GetItem(val,1) ) ) {
+ *this += Couple( PyString_AsString( PyTuple_GetItem(val,0) ),
+ PyString_AsString( PyTuple_GetItem(val,1) )
+ );
+
+ } else {
+ PyErr_SetString(PyExc_RuntimeWarning, "PyVersatile::PyVersatile(const PyObject * PyO) : invalid PyObject");
+ }
}
} else if (PyString_Check(_PyO)) { // c'est une string
const char * s = PyString_AsString(_PyO);
Versatile V = string(s);
*this = V;
-
+
} else if (PyInt_Check(_PyO)) { // c'est un int
*this = PyInt_AsLong(_PyO);
if (_maxsize != 1) { // une liste
obj = PyList_New(0);
for(Versatile::const_iterator it=begin(); it!=end(); it++) {
-// char ch[2] = {0, 0};
- string st;
- Couple cp;
-// PyObject * tuple;
- switch (_discriminator) {
- // case BOOL:
- // PyList_Append(obj, PyInt_FromLong(* static_cast<BoolType *>(*it)));
- // break;
-
- // case CHAR:
- // *ch = * static_cast<CharType *>(*it);
- // PyList_Append(obj, PyString_FromString(ch));
- // break;
-
- // case INT:
- // PyList_Append(obj, PyInt_FromLong(* static_cast<IntType *>(*it)));
- // break;
-
- case LONG:
- PyList_Append(obj, PyInt_FromLong(* static_cast<LongType *>(*it)));
- break;
-
- case STRING:
- st = * static_cast<StringType *>(*it);
- PyList_Append(obj, PyString_FromString(st.c_str()));
- break;
-
- case COUPLE:
- cp = * static_cast<CoupleType *>(*it);
-// tuple = PyTuple_New(2);
-// PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) );
-// PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) );
-// PyList_Append(obj, tuple);
- PyList_Append(obj, Py_BuildValue("(ss)", cp.getLocal().c_str(), cp.getRemote().c_str() ));
- break;
-
- case UNDEFINED:
- PyList_Append(obj, Py_None);
- break;
- }
+ // char ch[2] = {0, 0};
+ string st;
+ Couple cp;
+ // PyObject * tuple;
+ switch (_discriminator) {
+ // case BOOL:
+ // PyList_Append(obj, PyInt_FromLong(* static_cast<BoolType *>(*it)));
+ // break;
+
+ // case CHAR:
+ // *ch = * static_cast<CharType *>(*it);
+ // PyList_Append(obj, PyString_FromString(ch));
+ // break;
+
+ // case INT:
+ // PyList_Append(obj, PyInt_FromLong(* static_cast<IntType *>(*it)));
+ // break;
+
+ case LONG:
+ PyList_Append(obj, PyInt_FromLong(* static_cast<LongType *>(*it)));
+ break;
+
+ case STRING:
+ st = * static_cast<StringType *>(*it);
+ PyList_Append(obj, PyString_FromString(st.c_str()));
+ break;
+
+ case COUPLE:
+ cp = * static_cast<CoupleType *>(*it);
+ // tuple = PyTuple_New(2);
+ // PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) );
+ // PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) );
+ // PyList_Append(obj, tuple);
+ PyList_Append(obj, Py_BuildValue("(ss)", cp.getLocal().c_str(), cp.getRemote().c_str() ));
+ break;
+
+ case UNDEFINED:
+ PyList_Append(obj, Py_None);
+ break;
+ }
}
} else { // un scalaire
-// char ch[2] = {0, 0};
+ // char ch[2] = {0, 0};
string st;
Couple cp;
-// PyObject * tuple;
+ // PyObject * tuple;
switch (_discriminator) {
- // case BOOL:
- // obj = PyInt_FromLong(* static_cast<BoolType *>(front()));
- // break;
+ // case BOOL:
+ // obj = PyInt_FromLong(* static_cast<BoolType *>(front()));
+ // break;
- // case CHAR:
- // *ch = * static_cast<CharType *>(front());
- // obj = PyString_FromString(ch);
- // break;
+ // case CHAR:
+ // *ch = * static_cast<CharType *>(front());
+ // obj = PyString_FromString(ch);
+ // break;
- // case INT:
- // obj = PyInt_FromLong(* static_cast<IntType *>(front()));
- // break;
+ // case INT:
+ // obj = PyInt_FromLong(* static_cast<IntType *>(front()));
+ // break;
case LONG:
- obj = PyInt_FromLong(* static_cast<LongType *>(front()));
- break;
+ obj = PyInt_FromLong(* static_cast<LongType *>(front()));
+ break;
case STRING:
- st = * static_cast<StringType *>(front());
- obj = PyString_FromString(st.c_str());
- break;
+ st = * static_cast<StringType *>(front());
+ obj = PyString_FromString(st.c_str());
+ break;
case COUPLE:
- cp = * static_cast<CoupleType *>(front());
-// tuple = PyTuple_New(2);
-// PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) );
-// PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) );
-// obj = PyList_New(0);
-// PyList_Append(obj, tuple);
- obj = Py_BuildValue("[(ss)]", cp.getLocal().c_str(), cp.getRemote().c_str() );
- break;
+ cp = * static_cast<CoupleType *>(front());
+ // tuple = PyTuple_New(2);
+ // PyTuple_SetItem(tuple, 0, PyString_FromString( cp.getLocal().c_str() ) );
+ // PyTuple_SetItem(tuple, 1, PyString_FromString( cp.getRemote().c_str() ) );
+ // obj = PyList_New(0);
+ // PyList_Append(obj, tuple);
+ obj = Py_BuildValue("[(ss)]", cp.getLocal().c_str(), cp.getRemote().c_str() );
+ break;
case UNDEFINED:
- obj = Py_None;
- break;
+ obj = Py_None;
+ break;
}
}
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-# Configure the config file for all the test scripts
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py)
-
-# Just copy the test scripts to the binary dir
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY)
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY)
-CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Python_Local_SH.py
- ${CMAKE_CURRENT_BINARY_DIR}/Test_Python_Local_SH.py COPYONLY)
-
-# Add the test
-IF (BUILD_LOCAL_SUBMISSION)
+IF (BUILD_LOCAL_SUBMISSION AND HAS_SH)
+ # Configure the config file for the test script
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.py.in ${CMAKE_CURRENT_BINARY_DIR}/config.py)
+
+ # Just copy the test scripts to the binary dir
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY)
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY)
+ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Test_Python_Local_SH.py
+ ${CMAKE_CURRENT_BINARY_DIR}/Test_Python_Local_SH.py COPYONLY)
+
+ # Add the test
ADD_TEST(Python_Local_SH ${PYTHON_EXECUTABLE} Test_Python_Local_SH.py)
-ENDIF (BUILD_LOCAL_SUBMISSION)
+ENDIF (BUILD_LOCAL_SUBMISSION AND HAS_SH)
#include <fstream>
#include <sstream>
#include <sys/stat.h>
-#include "Batch_BatchManager_eSGE.hxx"
-#include <stdlib.h>
#ifdef WIN32
-# include <time.h>
-# include <io.h>
+#include <io.h>
#else
#include <libgen.h>
#endif
+#include "Batch_BatchManager_eSGE.hxx"
+#include "Batch_JobInfo_eSGE.hxx"
+
using namespace std;
namespace Batch {
- BatchManager_eSGE::BatchManager_eSGE(const FactBatchManager * parent, const char * host, const char * protocol, const char * mpiImpl) throw(InvalidArgumentException,ConnexionFailureException) : BatchManager_eClient(parent,host,protocol,mpiImpl)
+ BatchManager_eSGE::BatchManager_eSGE(const FactBatchManager * parent, const char * host,
+ CommunicationProtocolType protocolType, const char * mpiImpl)
+ : BatchManager_eClient(parent, host, protocolType, mpiImpl)
{
// Nothing to do
}
// build batch script for job
buildBatchScript(job);
- // define name of log file
- string logFile="/tmp/logs/";
- logFile += getenv("USER");
- logFile += "/batchSalome_";
- srand ( time(NULL) );
- int ir = rand();
- ostringstream oss;
- oss << ir;
- logFile += oss.str();
- logFile += ".log";
-
- string command;
+ // define name of log file (local)
+ string logFile = generateTemporaryFileName("SGE-submitlog");
// define command to submit batch
- command = _protocol;
- command += " ";
-
- if(_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"cd " ;
- command += dirForTmpFiles ;
- command += "; qsub " ;
- command += fileNameToExecute ;
- command += "_Batch.sh\" > ";
+ string subCommand = string("cd ") + dirForTmpFiles + "; qsub " +
+ fileNameToExecute + "_Batch.sh";
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+ command += " > ";
command += logFile;
cerr << command.c_str() << endl;
status = system(command.c_str());
istringstream iss(jobid.getReference());
iss >> ref;
- // define command to submit batch
- string command;
- command = _protocol;
- command += " ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"qdel " ;
- command += iss.str();
- command += "\"";
+ // define command to delete batch
+ string subCommand = string("qdel ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
status = system(command.c_str());
if(status)
istringstream iss(jobid.getReference());
iss >> id;
- // define name of log file
- string logFile="/tmp/logs/";
- logFile += getenv("USER");
- logFile += "/batchSalome_";
-
- ostringstream oss;
- oss << this << "_" << id;
- logFile += oss.str();
- logFile += ".log";
+ // define name of log file (local)
+ string logFile = generateTemporaryFileName(string("SGE-querylog-id") + jobid.getReference());
- string command;
- int status;
-
- // define command to submit batch
- command = _protocol;
- command += " ";
-
- if (_username != ""){
- command += _username;
- command += "@";
- }
-
- command += _hostname;
- command += " \"qstat | grep " ;
- command += iss.str();
- command += "\" > ";
+ // define command to query batch
+ string subCommand = string("qstat | grep ") + iss.str();
+ string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+ command += " > ";
command += logFile;
cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status && status != 256)
+ int status = system(command.c_str());
+ if (status && status != 256)
throw EmulationException("Error of connection on remote host");
JobInfo_eSGE ji = JobInfo_eSGE(id,logFile);
{
#ifndef WIN32
//TODO porting on Win32 platform
- int status;
Parametre params = job.getParametre();
Environnement env = job.getEnvironnement();
const long nbproc = params[NBPROC];
chmod(TmpFileName.c_str(), 0x1ED);
cerr << TmpFileName.c_str() << endl;
- string command;
- if( _protocol == "rsh" )
- command = "rcp ";
- else if( _protocol == "ssh" )
- command = "scp ";
- else
- throw EmulationException("Unknown protocol");
- command += TmpFileName;
- command += " ";
- if(_username != ""){
- command += _username;
- command += "@";
- }
- command += _hostname;
- command += ":";
- command += dirForTmpFiles ;
- command += "/" ;
- command += rootNameToExecute ;
- command += "_Batch.sh" ;
- cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
+ int status = _protocol.copyFile(TmpFileName, "", "",
+ dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh",
+ _hostname, _username);
+ if (status)
throw EmulationException("Error of connection on remote host");
remove(TmpFileName.c_str());
*
*/
-#ifndef _BATCHMANAGER_eLSF_H_
-#define _BATCHMANAGER_eLSF_H_
+#ifndef _BATCHMANAGER_ESGE_H_
+#define _BATCHMANAGER_ESGE_H_
-#include "Batch_Defines.hxx"
-#include "Batch_JobId.hxx"
-#include "Batch_JobInfo.hxx"
-#include "Batch_JobInfo_eSGE.hxx"
-#include "Batch_InvalidArgumentException.hxx"
-#include "Batch_ConnexionFailureException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
-#include "Batch_NotYetImplementedException.hxx"
-#include "Batch_BatchManager.hxx"
-#include "Batch_BatchManager_eClient.hxx"
+#include <Batch_Defines.hxx>
+#include <Batch_JobId.hxx>
+#include <Batch_JobInfo.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_BatchManager_eClient.hxx>
namespace Batch {
- class Job;
- class JobId;
- class JobInfo;
- class FactBatchManager;
-
class BATCH_EXPORT BatchManager_eSGE : public BatchManager_eClient
{
public:
// Constructeur et destructeur
- BatchManager_eSGE(const FactBatchManager * parent, const char * host="localhost", const char * protocol="ssh", const char * mpiImpl="nompi") throw(InvalidArgumentException,ConnexionFailureException); // connexion a la machine host
+ BatchManager_eSGE(const FactBatchManager * parent, const char * host="localhost",
+ CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host
virtual ~BatchManager_eSGE();
// Recupere le nom du serveur par defaut
*
*/
-#include <string>
#include "Batch_BatchManager_eSGE.hxx"
#include "Batch_FactBatchManager_eSGE.hxx"
-//#include "utilities.h"
namespace Batch {
return new BatchManager_eSGE(this, hostname);
}
- BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname, const char * protocol, const char * mpiImpl) const
+ BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const
{
// MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'");
- return new BatchManager_eSGE(this, hostname, protocol, mpiImpl);
+ return new BatchManager_eSGE(this, hostname, protocolType, mpiImpl);
}
namespace Batch {
- class BatchManager_eSGE;
-
class BATCH_EXPORT FactBatchManager_eSGE : public FactBatchManager_eClient
{
public:
virtual ~FactBatchManager_eSGE();
virtual BatchManager * operator() (const char * hostname) const;
- virtual BatchManager_eClient * operator() (const char * hostname, const char * protocol, const char * mpiImpl) const;
+ virtual BatchManager_eClient * operator() (const char * hostname,
+ CommunicationProtocolType protocolType,
+ const char * mpiImpl) const;
protected: