From b643659806a2d2ac40688337ecfb9909573f81e7 Mon Sep 17 00:00:00 2001 From: ribes Date: Tue, 10 Nov 2009 09:30:26 +0000 Subject: [PATCH] Add New Type of eClient -> eSSH, based on SSH BatchManager in Local --- src/CMakeLists.txt | 2 + src/Core/Batch_BatchManager_eClient.cxx | 8 +- src/Core/Batch_BatchManager_eClient.hxx | 2 +- src/Core/Batch_CommunicationProtocol.cxx | 1 + src/Core/Batch_Versatile.hxx | 2 +- src/LSF/Batch_BatchManager_eLSF.cxx | 6 +- src/Local/Batch_BatchManager_Local.cxx | 38 +++- src/Local/Batch_BatchManager_Local.hxx | 2 +- src/PBS/Batch_BatchManager_ePBS.cxx | 5 +- src/SGE/Batch_BatchManager_eSGE.cxx | 7 +- src/SSH/Batch_BatchManager_eSSH.cxx | 243 +++++++++++++++++++++++ src/SSH/Batch_BatchManager_eSSH.hxx | 81 ++++++++ src/SSH/Batch_FactBatchManager_eSSH.cxx | 52 +++++ src/SSH/Batch_FactBatchManager_eSSH.hxx | 56 ++++++ src/SSH/Batch_JobInfo_eSSH.cxx | 71 +++++++ src/SSH/Batch_JobInfo_eSSH.hxx | 54 +++++ src/SSH/CMakeLists.txt | 33 +++ 17 files changed, 654 insertions(+), 9 deletions(-) create mode 100644 src/SSH/Batch_BatchManager_eSSH.cxx create mode 100644 src/SSH/Batch_BatchManager_eSSH.hxx create mode 100644 src/SSH/Batch_FactBatchManager_eSSH.cxx create mode 100644 src/SSH/Batch_FactBatchManager_eSSH.hxx create mode 100644 src/SSH/Batch_JobInfo_eSSH.cxx create mode 100644 src/SSH/Batch_JobInfo_eSSH.hxx create mode 100644 src/SSH/CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fe08a3c..3a5d9d5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,7 @@ ENDIF (BUILD_LOCAL_SUBMISSION) add_subdirectory (LSF) add_subdirectory (PBS) add_subdirectory (SGE) +add_subdirectory (SSH) # Make a copy of the built value and clear the built value for the next run of cmake SET(SRC_FILES ${SRC_FILES_BUILD} CACHE INTERNAL "") @@ -65,6 +66,7 @@ SET(HDR_FILES_BUILD CACHE INTERNAL "") add_library (Batch SHARED ${SRC_FILES}) include_directories(${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/Core) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Local) target_link_libraries(Batch ${PTHREAD_LIBRARY}) IF (WIN32) diff --git a/src/Core/Batch_BatchManager_eClient.cxx b/src/Core/Batch_BatchManager_eClient.cxx index c386f2a..6380167 100644 --- a/src/Core/Batch_BatchManager_eClient.cxx +++ b/src/Core/Batch_BatchManager_eClient.cxx @@ -37,6 +37,8 @@ #include #include +#include + #ifdef WIN32 #include #include @@ -69,7 +71,8 @@ namespace Batch { // Destructeur BatchManager_eClient::~BatchManager_eClient() { - delete _mpiImpl; + if (_mpiImpl) + delete _mpiImpl; } void BatchManager_eClient::exportInputFiles(const Job& job) @@ -147,6 +150,7 @@ namespace Batch { Parametre params = job.getParametre(); Versatile V = params[OUTFILE]; Versatile::iterator Vit; + _username = string(params[USER]); for(Vit=V.begin(); Vit!=V.end(); Vit++) { CoupleType cpt = *static_cast< CoupleType * >(*Vit); @@ -181,7 +185,7 @@ namespace Batch { else if(mpiImpl == "prun") return new MpiImpl_PRUN(); else if(mpiImpl == "nompi") - throw EmulationException("you must specify an mpi implementation for batch manager"); + return NULL; else{ ostringstream oss; oss << mpiImpl << " : not yet implemented"; diff --git a/src/Core/Batch_BatchManager_eClient.hxx b/src/Core/Batch_BatchManager_eClient.hxx index 74e8cbc..9a043b9 100644 --- a/src/Core/Batch_BatchManager_eClient.hxx +++ b/src/Core/Batch_BatchManager_eClient.hxx @@ -44,7 +44,7 @@ namespace Batch { class Job; - class BATCH_EXPORT BatchManager_eClient : public BatchManager + class BATCH_EXPORT BatchManager_eClient : virtual public BatchManager { public: // Constructeur et destructeur diff --git a/src/Core/Batch_CommunicationProtocol.cxx b/src/Core/Batch_CommunicationProtocol.cxx index da4d49c..ef804f7 100644 --- a/src/Core/Batch_CommunicationProtocol.cxx +++ b/src/Core/Batch_CommunicationProtocol.cxx @@ -28,6 +28,7 @@ #include #include +#include #include diff --git a/src/Core/Batch_Versatile.hxx b/src/Core/Batch_Versatile.hxx index 6a3a945..2f9f944 100644 --- a/src/Core/Batch_Versatile.hxx +++ b/src/Core/Batch_Versatile.hxx @@ -105,9 +105,9 @@ namespace Batch { std::string getName() const; void setName(const std::string & name); - protected: // Efface tous les elements internes de l'objet virtual void eraseAll(); + protected: DiscriminatorType _discriminator; // type de l'element interne size_type _maxsize; // nombre max d'elements internes diff --git a/src/LSF/Batch_BatchManager_eLSF.cxx b/src/LSF/Batch_BatchManager_eLSF.cxx index a74a4b2..f5a9fab 100644 --- a/src/LSF/Batch_BatchManager_eLSF.cxx +++ b/src/LSF/Batch_BatchManager_eLSF.cxx @@ -38,6 +38,9 @@ #include #include +#include +#include + #ifdef WIN32 #include #else @@ -53,7 +56,8 @@ namespace Batch { BatchManager_eLSF::BatchManager_eLSF(const FactBatchManager * parent, const char * host, CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager_eClient(parent, host, protocolType, mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl), + BatchManager(parent, host) { // Nothing to do } diff --git a/src/Local/Batch_BatchManager_Local.cxx b/src/Local/Batch_BatchManager_Local.cxx index 4166e3f..446ef1a 100644 --- a/src/Local/Batch_BatchManager_Local.cxx +++ b/src/Local/Batch_BatchManager_Local.cxx @@ -443,6 +443,9 @@ namespace Batch { string local = cp.getLocal(); string remote = cp.getRemote(); + std::cerr << workdir << std::endl; + std::cerr << remote << std::endl; + int status = p_ta->getBatchManager().getProtocol().copyFile(local, "", "", workdir + "/" + remote, executionhost, user); @@ -463,6 +466,8 @@ namespace Batch { // On forke/exec un nouveau process pour pouvoir controler le fils // (plus finement qu'avec un appel system) // int rc = system(commande.c_str()); + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 10 && echo end", NULL}; + //execv("/usr/bin/ssh", parmList); #ifdef WIN32 child = p_ta->launchWin32ChildProcess(); p_ta->pere(child); @@ -594,6 +599,14 @@ namespace Batch { int child_rc = 0; pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */); if (child_wait_rc > 0) { + UNDER_LOCK( cout << "Status is: " << WIFEXITED( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WEXITSTATUS( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WIFSIGNALED( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WTERMSIG( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WCOREDUMP( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WIFSTOPPED( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WSTOPSIG( child_rc) << endl); + UNDER_LOCK( cout << "Status is: " << WIFCONTINUED( child_rc) << endl); if (WIFSTOPPED(child_rc)) { // NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED // soit positionne dans l'appel a waitpid ci-dessus. Ce flag est couramment @@ -740,6 +753,10 @@ namespace Batch { Parametre param = _job.getParametre(); Parametre::iterator it; + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; + //int result = execv("/usr/bin/ssh", parmList); + //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); + //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); try { // EXECUTABLE is MANDATORY, if missing, we exit with failure notification @@ -761,6 +778,7 @@ namespace Batch { argv[command.size()] = NULL; UNDER_LOCK( cout << "*** debug_command = " << comstr << endl ); + UNDER_LOCK( cout << "*** debug_command = " << argv[0] << endl ); // Create the environment for the new process. Note (RB): Here we change the environment for // the process launched in local. It would seem more logical to set the environment for the @@ -784,11 +802,16 @@ namespace Batch { envp[i] = NULL; } + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; + //int result = execv("/usr/bin/ssh", parmList); + //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); + //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); // On positionne les limites systeme imposees au fils if (param.find(MAXCPUTIME) != param.end()) { + UNDER_LOCK( cout << "AAAAAAAAAAAAAAAAAAaa" << endl ); int maxcputime = param[MAXCPUTIME]; struct rlimit limit; limit.rlim_cur = maxcputime; @@ -797,6 +820,7 @@ namespace Batch { } if (param.find(MAXDISKSIZE) != param.end()) { + UNDER_LOCK( cout << "BBBBBBBBBBBBBBBBBBBbb" << endl ); int maxdisksize = param[MAXDISKSIZE]; struct rlimit limit; limit.rlim_cur = maxdisksize * 1024; @@ -805,6 +829,7 @@ namespace Batch { } if (param.find(MAXRAMSIZE) != param.end()) { + UNDER_LOCK( cout << "CCCCCCCCCCCCCCCCCcc" << endl ); int maxramsize = param[MAXRAMSIZE]; struct rlimit limit; limit.rlim_cur = maxramsize * 1024; @@ -813,6 +838,10 @@ namespace Batch { } + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 1 && echo end", NULL}; + //int result = execv("/usr/bin/ssh", parmList); + //UNDER_LOCK( cout << "*** debug_command = " << result << endl ); + //UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); // On cree une session pour le fils de facon a ce qu'il ne soit pas // detruit lorsque le shell se termine (le shell ouvre une session et @@ -827,7 +856,14 @@ namespace Batch { // On execute la commande du fils - execve(argv[0], argv, envp); + //int result = execve(argv[0], argv, envp); + std::cerr << "EXECVE !!!!!!" << std::endl; + execve(argv[0], argv, NULL); + UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl ); + //int result = execv(argv[0], argv); + // + //char *const parmList[] = {"/usr/bin/ssh", "localhost", "-l", "aribes", "sleep 10 && echo end", NULL}; + //int result = execv("/usr/bin/ssh", parmList); // No need to deallocate since nothing happens after a successful exec diff --git a/src/Local/Batch_BatchManager_Local.hxx b/src/Local/Batch_BatchManager_Local.hxx index d6fc0f7..bae6592 100644 --- a/src/Local/Batch_BatchManager_Local.hxx +++ b/src/Local/Batch_BatchManager_Local.hxx @@ -58,7 +58,7 @@ namespace Batch { class FactBatchManager; - class BATCH_EXPORT BatchManager_Local : public BatchManager + class BATCH_EXPORT BatchManager_Local : virtual public BatchManager { private: #ifdef WIN32 diff --git a/src/PBS/Batch_BatchManager_ePBS.cxx b/src/PBS/Batch_BatchManager_ePBS.cxx index 38593b3..e676860 100644 --- a/src/PBS/Batch_BatchManager_ePBS.cxx +++ b/src/PBS/Batch_BatchManager_ePBS.cxx @@ -37,6 +37,8 @@ #include #include +#include +#include #include #ifdef MSVC @@ -54,7 +56,8 @@ namespace Batch { BatchManager_ePBS::BatchManager_ePBS(const FactBatchManager * parent, const char * host, CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager_eClient(parent, host, protocolType, mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl), + BatchManager(parent, host) { // Nothing to do } diff --git a/src/SGE/Batch_BatchManager_eSGE.cxx b/src/SGE/Batch_BatchManager_eSGE.cxx index dc7845e..26177e2 100644 --- a/src/SGE/Batch_BatchManager_eSGE.cxx +++ b/src/SGE/Batch_BatchManager_eSGE.cxx @@ -36,6 +36,10 @@ #include #include #include + +#include +#include + #ifdef WIN32 #include #else @@ -51,7 +55,8 @@ namespace Batch { BatchManager_eSGE::BatchManager_eSGE(const FactBatchManager * parent, const char * host, CommunicationProtocolType protocolType, const char * mpiImpl) - : BatchManager_eClient(parent, host, protocolType, mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl), + BatchManager(parent, host) { // Nothing to do } diff --git a/src/SSH/Batch_BatchManager_eSSH.cxx b/src/SSH/Batch_BatchManager_eSSH.cxx new file mode 100644 index 0000000..3e085d4 --- /dev/null +++ b/src/SSH/Batch_BatchManager_eSSH.cxx @@ -0,0 +1,243 @@ +// 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_eSSH.cxx : emulation of SSH client + * + * Auteur : André RIBES - EDF R&D + * Date : Octobre 2009 + */ + +#include +#include +#include +#include + +#include +#include +#include + +#ifdef MSVC +#include +#else +#include +#endif + +#include "Batch_BatchManager_eSSH.hxx" +#include "Batch_JobInfo_eSSH.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_eSSH::BatchManager_eSSH(const FactBatchManager * parent, const char * host, + CommunicationProtocolType protocolType, const char * mpiImpl) + : BatchManager_eClient(parent, host, protocolType, mpiImpl), + BatchManager_Local(parent, host, protocolType), + BatchManager(parent, host) + { + // Nothing to do + } + + // Destructeur + BatchManager_eSSH::~BatchManager_eSSH() + { + // Nothing to do + } + + // Methode pour le controle des jobs : soumet un job au gestionnaire + const JobId BatchManager_eSSH::submitJob(const Job & job) + { + // export input files on cluster + std::cerr << "BatchManager_eSSH::submitJob exportInputFiles" << std::endl; + Parametre param = job.getParametre(); + + // Creates job repertories + if (string(param[TMPDIR]) != "") + { + string subCommand = string("mkdir -p ") + string(param[TMPDIR]); + string command = BatchManager_eClient::_protocol.getExecCommand(subCommand, _hostname, _username); + cerr << command.c_str() << endl; + int status = system(command.c_str()); + if(status) { + std::ostringstream oss; + oss << status; + std::string ex_mess("Error of connection on remote host ! status = "); + ex_mess += oss.str(); + throw EmulationException(ex_mess.c_str()); + } + } + if (string(param[TMPDIR]) != "") + { + string subCommand = string("mkdir -p ") + string(param[WORKDIR]); + string command = BatchManager_eClient::_protocol.getExecCommand(subCommand, _hostname, _username); + cerr << command.c_str() << endl; + int status = system(command.c_str()); + if(status) { + std::ostringstream oss; + oss << status; + std::string ex_mess("Error of connection on remote host ! status = "); + ex_mess += oss.str(); + throw EmulationException(ex_mess.c_str()); + } + } + + Parametre new_param(param); + new_param[OUTFILE].eraseAll(); // Patch until Local Manager is patched + Job * j = new Job(new_param); + std::cerr << "BatchManager_eSSH::submitJob Local submitJob" << std::endl; + JobId id = BatchManager_Local::submitJob(*j); + delete j; + return id; + } + + // Methode pour le controle des jobs : retire un job du gestionnaire + void BatchManager_eSSH::deleteJob(const JobId & jobid) + { + BatchManager_Local::deleteJob(jobid); + } + + // Methode pour le controle des jobs : renvoie l'etat du job + JobInfo BatchManager_eSSH::queryJob(const JobId & jobid) + { + return BatchManager_Local::queryJob(jobid); + } + + // Methode pour le controle des jobs : suspend un job en file d'attente + void BatchManager_eSSH::holdJob(const JobId & jobid) + { + BatchManager_Local::holdJob(jobid); + } + + // Methode pour le controle des jobs : relache un job suspendu + void BatchManager_eSSH::releaseJob(const JobId & jobid) + { + BatchManager_Local::releaseJob(jobid); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSSH::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + BatchManager_Local::alterJob(jobid, param, env); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSSH::alterJob(const JobId & jobid, const Parametre & param) + { + BatchManager_Local::alterJob(jobid, param); + } + + // Methode pour le controle des jobs : modifie un job en file d'attente + void BatchManager_eSSH::alterJob(const JobId & jobid, const Environnement & env) + { + BatchManager_Local::alterJob(jobid, env); + } + + void BatchManager_eSSH::buildBatchScript(const Job & job) + { + Parametre params = job.getParametre(); + Environnement env = job.getEnvironnement(); + const long nbproc = params[NBPROC]; + const long edt = params[MAXWALLTIME]; + const long mem = params[MAXRAMSIZE]; + const string workDir = params[WORKDIR]; + const std::string dirForTmpFiles = params[TMPDIR]; + const string fileToExecute = params[EXECUTABLE]; + const string home = params[HOMEDIR]; + const std::string queue = params[QUEUE]; + std::string rootNameToExecute; + std::string fileNameToExecute; + std::string filelogtemp; + if( fileToExecute.size() > 0 ){ + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + +#ifdef MSVC + char fname[_MAX_FNAME]; + char ext[_MAX_EXT]; + _splitpath_s(fileToExecute.c_str(), NULL, 0, NULL, 0, fname, _MAX_FNAME, ext, _MAX_EXT); + string execBaseName = string(fname) + ext; +#else + char* basec=strdup(fileToExecute.c_str()); + string execBaseName = string(basename(basec)); + free(basec); +#endif + + fileNameToExecute = "~/" + dirForTmpFiles + "/" + execBaseName; + + int idx = dirForTmpFiles.find("Batch/"); + filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + } + else{ + rootNameToExecute = "command"; + } + + ofstream tempOutputFile; + std::string TmpFileName = createAndOpenTemporaryFile("SSH-script", tempOutputFile); + + tempOutputFile << "#! /bin/sh -f" << endl; + if (queue != "") + tempOutputFile << "#BSUB -q " << queue << endl; + if( edt > 0 ) + tempOutputFile << "#SSH -l walltime=" << edt*60 << endl ; + if( mem > 0 ) + tempOutputFile << "#SSH -l mem=" << mem << "mb" << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << "#SSH -o " << home << "/" << dirForTmpFiles << "/output.log." << filelogtemp << endl ; + tempOutputFile << "#SSH -e " << home << "/" << dirForTmpFiles << "/error.log." << filelogtemp << endl ; + } + else{ + tempOutputFile << "#SSH -o " << dirForTmpFiles << "/" << env["LOGFILE"] << ".output.log" << endl ; + tempOutputFile << "#SSH -e " << dirForTmpFiles << "/" << env["LOGFILE"] << ".error.log" << endl ; + } + if( workDir.size() > 0 ) + tempOutputFile << "cd " << workDir << endl ; + if( fileToExecute.size() > 0 ){ + tempOutputFile << _mpiImpl->boot("${SSH_NODEFILE}",nbproc); + tempOutputFile << _mpiImpl->run("${SSH_NODEFILE}",nbproc,fileNameToExecute); + tempOutputFile << _mpiImpl->halt(); + } + else{ + tempOutputFile << "source " << env["SOURCEFILE"] << endl ; + tempOutputFile << env["COMMAND"]; + } + + tempOutputFile.flush(); + tempOutputFile.close(); +#ifdef WIN32 + _chmod( +#else + chmod( +#endif + TmpFileName.c_str(), 0x1ED); + cerr << TmpFileName.c_str() << endl; + + int status = Batch::BatchManager_eClient::_protocol.copyFile(TmpFileName, "", "", + dirForTmpFiles + "/" + rootNameToExecute + "_Batch.sh", + _hostname, _username); + if (status) + throw EmulationException("Error of connection on remote host"); + + remove(TmpFileName.c_str()); + } + +} diff --git a/src/SSH/Batch_BatchManager_eSSH.hxx b/src/SSH/Batch_BatchManager_eSSH.hxx new file mode 100644 index 0000000..a95f2aa --- /dev/null +++ b/src/SSH/Batch_BatchManager_eSSH.hxx @@ -0,0 +1,81 @@ +// 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_eSSH.hxx : emulation of SSH client + * + * Auteur : André RIBES - EDF R&D + * Date : Octobre 2009 + */ + +#ifndef _BATCHMANAGER_ESSH_H_ +#define _BATCHMANAGER_ESSH_H_ + +#include "Batch_Defines.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_FactBatchManager.hxx" +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_BatchManager_Local.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_eSSH : + virtual public BatchManager_eClient, + virtual public BatchManager_Local + { + public: + // Constructeur et destructeur + BatchManager_eSSH(const FactBatchManager * parent, const char * host="localhost", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host + virtual ~BatchManager_eSSH(); + + // Recupere le nom du serveur par defaut + // static string BatchManager_LSF::getDefaultServer(); + + // Methodes pour le controle des jobs + virtual const JobId submitJob(const Job & job); // soumet un job au gestionnaire + virtual void deleteJob(const JobId & jobid); // retire un job du gestionnaire + virtual JobInfo queryJob(const JobId & jobid); // renvoie l'etat du job + + // Non implanté... + virtual void holdJob(const JobId & jobid); // suspend un job en file d'attente + virtual void releaseJob(const JobId & jobid); // relache un job suspendu + virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Parametre & param); // modifie un job en file d'attente + virtual void alterJob(const JobId & jobid, const Environnement & env); // modifie un job en file d'attente + + + protected: + void buildBatchScript(const Job & job); + + private: + +#ifdef SWIG + public: + // Recupere le l'identifiant d'un job deja soumis au BatchManager + //virtual const JobId getJobIdByReference(const string & ref) { return BatchManager::getJobIdByReference(ref); } + virtual const JobId getJobIdByReference(const char * ref) { return BatchManager::getJobIdByReference(ref); } +#endif + }; +} + +#endif diff --git a/src/SSH/Batch_FactBatchManager_eSSH.cxx b/src/SSH/Batch_FactBatchManager_eSSH.cxx new file mode 100644 index 0000000..28b7082 --- /dev/null +++ b/src/SSH/Batch_FactBatchManager_eSSH.cxx @@ -0,0 +1,52 @@ +// 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_eSSH.cxx : + * + * Auteur : André RIBES : EDF R&D + * Date : Octobre 2009 + */ + +#include +#include "Batch_BatchManager_eSSH.hxx" +#include "Batch_FactBatchManager_eSSH.hxx" + +Batch::FactBatchManager_eSSH::FactBatchManager_eSSH() : FactBatchManager_eClient("eSSH") {} + +Batch::FactBatchManager_eSSH::~FactBatchManager_eSSH() {} + +Batch::BatchManager * +Batch::FactBatchManager_eSSH::operator() (const char * hostname) const +{ + return new Batch::BatchManager_eSSH(this, hostname); +} + +Batch::BatchManager_eClient * +Batch::FactBatchManager_eSSH::operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const +{ + //protocolType and mpiImpl are ignored. + std::cerr << "[Batch::FactBatchManager_eSSH] creating new Batch::BatchManager_eSSH with hostname = " << hostname << std::endl; + + return new Batch::BatchManager_eSSH(this, hostname); +} diff --git a/src/SSH/Batch_FactBatchManager_eSSH.hxx b/src/SSH/Batch_FactBatchManager_eSSH.hxx new file mode 100644 index 0000000..5014cd4 --- /dev/null +++ b/src/SSH/Batch_FactBatchManager_eSSH.hxx @@ -0,0 +1,56 @@ +// 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_eSSH.hxx : + * + * Auteur : André RIBES : EDF R&D + * Date : Octobre 2009 + */ + +#ifndef _FACTBATCHMANAGER_eSSH_H_ +#define _FACTBATCHMANAGER_eSSH_H_ + +#include "Batch_Defines.hxx" + +#include +#include +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_FactBatchManager_eClient.hxx" + +namespace Batch { + + class BatchManager_eSSH; + + class BATCH_EXPORT FactBatchManager_eSSH : public FactBatchManager_eClient + { + public: + FactBatchManager_eSSH(); + virtual ~FactBatchManager_eSSH(); + + virtual BatchManager * operator() (const char * hostname) const; // From FactBacthManager + virtual BatchManager_eClient * operator() (const char * hostname, + CommunicationProtocolType protocolType, + const char * mpiImpl) const; // From FactBatchManager_eClient + }; +} + +#endif diff --git a/src/SSH/Batch_JobInfo_eSSH.cxx b/src/SSH/Batch_JobInfo_eSSH.cxx new file mode 100644 index 0000000..fd899de --- /dev/null +++ b/src/SSH/Batch_JobInfo_eSSH.cxx @@ -0,0 +1,71 @@ +// 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 +// +/* + * JobInfo_eSSH.cxx : emulation of SSH client + * + * Auteur : André RIBES - EDF R&D + * Date : Octobre 2009 + */ + +#include +#include +#include +#include +#include "Batch_Parametre.hxx" +#include "Batch_Environnement.hxx" +#include "Batch_RunTimeException.hxx" +#include "Batch_APIInternalFailureException.hxx" +#include "Batch_JobInfo_eSSH.hxx" + +using namespace std; + +namespace Batch { + + // Constructeurs + JobInfo_eSSH::JobInfo_eSSH(int id, string status) : JobInfo() + { + // On remplit les membres _param et _env + ostringstream oss; + oss << id; + _param[ID] = oss.str(); + _param[STATE] = status; + } + + // Destructeur + JobInfo_eSSH::~JobInfo_eSSH() + { + // Nothing to do + } + + // Methode pour l'interfacage avec Python (SWIG) : affichage en Python + string JobInfo_eSSH::__str__() const + { + ostringstream sst; + sst << "