From b8e649cf4e8c4bd377f9dd16941926366e2dc6e7 Mon Sep 17 00:00:00 2001 From: barate Date: Thu, 25 Nov 2010 16:49:29 +0000 Subject: [PATCH] Added LoadLeveler client (only submit is implemented for now) --- src/CMakeLists.txt | 1 + src/Core/Batch_FactBatchManager_eClient.hxx | 4 +- src/Core/Test/batchtest.conf | 6 + src/LoadLeveler/Batch_BatchManager_eLL.cxx | 212 ++++++++++++++++++ src/LoadLeveler/Batch_BatchManager_eLL.hxx | 69 ++++++ .../Batch_FactBatchManager_eLL.cxx | 63 ++++++ .../Batch_FactBatchManager_eLL.hxx | 59 +++++ src/LoadLeveler/CMakeLists.txt | 32 +++ src/LoadLeveler/Test/CMakeLists.txt | 44 ++++ src/LoadLeveler/Test/Test_eLL.cxx | 159 +++++++++++++ src/LoadLeveler/Test/seta.sh | 3 + src/LoadLeveler/Test/setb.sh | 3 + src/LoadLeveler/Test/test-script.sh | 9 + 13 files changed, 662 insertions(+), 2 deletions(-) create mode 100644 src/LoadLeveler/Batch_BatchManager_eLL.cxx create mode 100644 src/LoadLeveler/Batch_BatchManager_eLL.hxx create mode 100644 src/LoadLeveler/Batch_FactBatchManager_eLL.cxx create mode 100644 src/LoadLeveler/Batch_FactBatchManager_eLL.hxx create mode 100644 src/LoadLeveler/CMakeLists.txt create mode 100644 src/LoadLeveler/Test/CMakeLists.txt create mode 100644 src/LoadLeveler/Test/Test_eLL.cxx create mode 100644 src/LoadLeveler/Test/seta.sh create mode 100644 src/LoadLeveler/Test/setb.sh create mode 100755 src/LoadLeveler/Test/test-script.sh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 29328cf..065ab33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -55,6 +55,7 @@ add_subdirectory (LSF) add_subdirectory (PBS) add_subdirectory (SGE) add_subdirectory (SSH) +add_subdirectory (LoadLeveler) # 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 "") diff --git a/src/Core/Batch_FactBatchManager_eClient.hxx b/src/Core/Batch_FactBatchManager_eClient.hxx index 9713f68..5c905c3 100644 --- a/src/Core/Batch_FactBatchManager_eClient.hxx +++ b/src/Core/Batch_FactBatchManager_eClient.hxx @@ -50,8 +50,8 @@ namespace Batch { virtual Batch::BatchManager_eClient * operator() (const char * hostname, const char * username, CommunicationProtocolType protocolType, - const char * mpi, - int nb_proc_per_node = 1) const = 0; + const char * mpi = "nompi", + int nb_proc_per_node = 1) const = 0; protected: diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf index 00b3228..cb300f2 100644 --- a/src/Core/Test/batchtest.conf +++ b/src/Core/Test/batchtest.conf @@ -31,3 +31,9 @@ TEST_EPBS_USER = "username" # Login for the PBS server TEST_EPBS_HOMEDIR = "/home/username" # Home directory on PBS server TEST_EPBS_QUEUE = "queuename" # Queue to submit test job on PBS server TEST_EPBS_TIMEOUT = 120 # Execution timeout (in seconds) for PBS Batch test + +TEST_ELL_HOST = "localhost" # LoadLeveler server host +TEST_ELL_USER = "username" # Login for the LoadLeveler server +TEST_ELL_HOMEDIR = "/home/username" # Home directory on LoadLeveler server +TEST_ELL_QUEUE = "classname" # Class for the test job test job on LoadLeveler server +TEST_ELL_TIMEOUT = 120 # Execution timeout (in seconds) for LoadLeveler Batch test diff --git a/src/LoadLeveler/Batch_BatchManager_eLL.cxx b/src/LoadLeveler/Batch_BatchManager_eLL.cxx new file mode 100644 index 0000000..2c3a390 --- /dev/null +++ b/src/LoadLeveler/Batch_BatchManager_eLL.cxx @@ -0,0 +1,212 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_BatchManager_eLL.cxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include + +#include + +#include "Batch_BatchManager_eLL.hxx" + +using namespace std; + +namespace Batch { + + BatchManager_eLL::BatchManager_eLL(const FactBatchManager * parent, const char * host, + const char * username, + CommunicationProtocolType protocolType, const char * mpiImpl, + int nb_proc_per_node) + : BatchManager(parent, host), + BatchManager_eClient(parent, host, username, protocolType, mpiImpl) + { + // Nothing to do + } + + BatchManager_eLL::~BatchManager_eLL() + { + // Nothing to do + } + + // Method to submit a job to the batch manager + const JobId BatchManager_eLL::submitJob(const Job & job) + { + int status; + Parametre params = job.getParametre(); + const string workDir = params[WORKDIR]; + + // export input files on cluster + exportInputFiles(job); + + // build command file to submit the job and copy it on the server + string cmdFile = buildCommandFile(job); + + // define name of log file (local) + string logFile = generateTemporaryFileName("LL-submitlog"); + + // define command to submit batch + string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile; + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; + command += logFile; + cerr << command.c_str() << endl; + status = system(command.c_str()); + if(status) + { + ifstream error_message(logFile.c_str()); + string mess; + string temp; + while(std::getline(error_message, temp)) + mess += temp; + error_message.close(); + throw EmulationException("Error of connection on remote host, error was: " + mess); + } + + // read id of submitted job in log file + string jobref; + ifstream idfile(logFile.c_str()); + unsigned int linebufsize = 1024; + char linebuf[linebufsize]; + idfile.getline(linebuf, linebufsize); + while (!idfile.eof() && strncmp(linebuf, "llsubmit:", 9) != 0) + idfile.getline(linebuf, linebufsize); + idfile.close(); + if (strncmp(linebuf, "llsubmit:", 9) == 0) + { + string line(linebuf); + string::size_type p1 = line.find_first_of("\""); + string::size_type p2 = line.find_last_of("\""); + if (p1 != p2) + jobref = line.substr(p1 + 1, p2 - p1 - 1); + } + if (jobref.size() == 0) + throw EmulationException("Error in the submission of the job on the remote host"); + + JobId id(this, jobref); + return id; + } + + /** + * Create LoadLeveler command file and copy it on the server. + * Return the name of the remote file. + */ + string BatchManager_eLL::buildCommandFile(const Job & job) + { + Parametre params = job.getParametre(); + + // Job Parameters + string workDir = ""; + string fileToExecute = ""; + string queue = ""; + + // Mandatory parameters + if (params.find(WORKDIR) != params.end()) + workDir = params[WORKDIR].str(); + else + throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job"); + if (params.find(EXECUTABLE) != params.end()) + fileToExecute = params[EXECUTABLE].str(); + else + throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job"); + + // Optional parameters + if (params.find(QUEUE) != params.end()) + queue = params[QUEUE].str(); + + string::size_type p1 = fileToExecute.find_last_of("/"); + string::size_type p2 = fileToExecute.find_last_of("."); + string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1); + string fileNameToExecute = fileToExecute.substr(p1+1); + + // Create batch submit file + ofstream tempOutputFile; + std::string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile); + + tempOutputFile << "# @ executable = " << fileNameToExecute << endl; + tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl; + tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl; + if (queue != "") + tempOutputFile << "# @ class = " << queue << endl; + tempOutputFile << "# @ job_type = bluegene" << endl; + tempOutputFile << "# @ queue" << endl; + + tempOutputFile.flush(); + tempOutputFile.close(); + + cerr << "Batch script file generated is: " << tmpFileName.c_str() << endl; + + string remoteFileName = rootNameToExecute + "_LL.cmd"; + int status = _protocol.copyFile(tmpFileName, "", "", + workDir + "/" + remoteFileName, + _hostname, _username); + if (status) + throw EmulationException("Error of connection on remote host, cannot copy batch submission file"); + + return remoteFileName; + } + + void BatchManager_eLL::deleteJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eLL::deleteJob"); + } + + void BatchManager_eLL::holdJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eLL::holdJob"); + } + + void BatchManager_eLL::releaseJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eLL::releaseJob"); + } + + void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env) + { + throw NotYetImplementedException("BatchManager_eLL::alterJob"); + } + + void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param) + { + throw NotYetImplementedException("BatchManager_eLL::alterJob"); + } + + void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env) + { + throw NotYetImplementedException("BatchManager_eLL::alterJob"); + } + + JobInfo BatchManager_eLL::queryJob(const JobId & jobid) + { + throw NotYetImplementedException("BatchManager_eLL::queryJob"); + } + + const JobId BatchManager_eLL::addJob(const Job & job, const string reference) + { + throw NotYetImplementedException("BatchManager_eLL::addJob"); + } + +} diff --git a/src/LoadLeveler/Batch_BatchManager_eLL.hxx b/src/LoadLeveler/Batch_BatchManager_eLL.hxx new file mode 100644 index 0000000..3656f69 --- /dev/null +++ b/src/LoadLeveler/Batch_BatchManager_eLL.hxx @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_BatchManager_eLL.hxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _BATCHMANAGER_ELL_H_ +#define _BATCHMANAGER_ELL_H_ + +#include + +#include "Batch_Defines.hxx" +#include "Batch_JobId.hxx" +#include "Batch_JobInfo.hxx" +#include "Batch_FactBatchManager.hxx" +#include "Batch_BatchManager_eClient.hxx" + +namespace Batch { + + class BATCH_EXPORT BatchManager_eLL : public BatchManager_eClient + { + public: + BatchManager_eLL(const FactBatchManager * parent, const char * host = "localhost", + const char * username = "", + CommunicationProtocolType protocolType = SSH, const char * mpiImpl = "nompi", + int nb_proc_per_node=1); + virtual ~BatchManager_eLL(); + + // Methods to control jobs + virtual const JobId submitJob(const Job & job); + virtual void deleteJob(const JobId & jobid); + virtual void holdJob(const JobId & jobid); + virtual void releaseJob(const JobId & jobid); + virtual void alterJob(const JobId & jobid, const Parametre & param, const Environnement & env); + virtual void alterJob(const JobId & jobid, const Parametre & param); + virtual void alterJob(const JobId & jobid, const Environnement & env); + virtual JobInfo queryJob(const JobId & jobid); + virtual const JobId addJob(const Job & job, const std::string reference); + + protected: + std::string buildCommandFile(const Job & job); + + }; + +} + +#endif diff --git a/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx b/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx new file mode 100644 index 0000000..6017873 --- /dev/null +++ b/src/LoadLeveler/Batch_FactBatchManager_eLL.cxx @@ -0,0 +1,63 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_FactBatchManager_eLL.cxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include "Batch_BatchManager_eLL.hxx" +#include "Batch_FactBatchManager_eLL.hxx" + +namespace Batch { + + static FactBatchManager_eLL sFBM_eLL; + + FactBatchManager_eLL::FactBatchManager_eLL() : FactBatchManager_eClient("eLL") + { + // Nothing to do + } + + FactBatchManager_eLL::~FactBatchManager_eLL() + { + // Nothing to do + } + + // Functor + BatchManager * FactBatchManager_eLL::operator() (const char * hostname) const + { + // MESSAGE("Building new BatchManager_eLL on host '" << hostname << "'"); + return new BatchManager_eLL(this, hostname); + } + + BatchManager_eClient * FactBatchManager_eLL::operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl, + int nb_proc_per_node) const + { + // MESSAGE("Building new BatchManager_eLL on host '" << hostname << "'"); + return new BatchManager_eLL(this, hostname, username, protocolType, mpiImpl, nb_proc_per_node); + } + +} diff --git a/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx b/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx new file mode 100644 index 0000000..5feefd9 --- /dev/null +++ b/src/LoadLeveler/Batch_FactBatchManager_eLL.hxx @@ -0,0 +1,59 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_FactBatchManager_eLL.hxx : + * + * Created on: 25 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _FACTBATCHMANAGER_ELL_H_ +#define _FACTBATCHMANAGER_ELL_H_ + +#include "Batch_Defines.hxx" + +#include "Batch_BatchManager_eClient.hxx" +#include "Batch_FactBatchManager_eClient.hxx" + +namespace Batch { + + class BatchManager_eLL; + + class BATCH_EXPORT FactBatchManager_eLL : public FactBatchManager_eClient + { + public: + // Constructeur et destructeur + FactBatchManager_eLL(); + virtual ~FactBatchManager_eLL(); + + virtual BatchManager * operator() (const char * hostname) const; + virtual BatchManager_eClient * operator() (const char * hostname, + const char * username, + CommunicationProtocolType protocolType, + const char * mpiImpl, + int nb_proc_per_node = 1) const; + + }; + +} + +#endif diff --git a/src/LoadLeveler/CMakeLists.txt b/src/LoadLeveler/CMakeLists.txt new file mode 100644 index 0000000..6db2d90 --- /dev/null +++ b/src/LoadLeveler/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(CLASS_LIST LoadLeveler/Batch_BatchManager_eLL + LoadLeveler/Batch_FactBatchManager_eLL + ) + +APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) +APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST}) + +IF (TEST_ENABLED) + add_subdirectory(Test) +ENDIF (TEST_ENABLED) diff --git a/src/LoadLeveler/Test/CMakeLists.txt b/src/LoadLeveler/Test/CMakeLists.txt new file mode 100644 index 0000000..887326a --- /dev/null +++ b/src/LoadLeveler/Test/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +# +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# Just copy the test scripts to the binary dir +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/seta.sh ${CMAKE_CURRENT_BINARY_DIR}/seta.sh COPYONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/setb.sh ${CMAKE_CURRENT_BINARY_DIR}/setb.sh COPYONLY) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test-script.sh ${CMAKE_CURRENT_BINARY_DIR}/test-script.sh COPYONLY) + +# set the include directories +include_directories(${CMAKE_SOURCE_DIR}/src/Core) +include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +# Build the test programs and add the tests +add_executable(Test_eLL Test_eLL.cxx) +target_link_libraries(Test_eLL Batch SimpleParser) + +IF (HAS_SSH) + ADD_TEST(eLL_SSH Test_eLL SSH) +ENDIF (HAS_SSH) + +#IF (HAS_RSH) +# ADD_TEST(eLL_RSH Test_eLL RSH) +#ENDIF (HAS_RSH) diff --git a/src/LoadLeveler/Test/Test_eLL.cxx b/src/LoadLeveler/Test/Test_eLL.cxx new file mode 100644 index 0000000..d394525 --- /dev/null +++ b/src/LoadLeveler/Test/Test_eLL.cxx @@ -0,0 +1,159 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Test_ePBS.cxx : + * + * Author : Renaud BARATE - EDF R&D + * Date : April 2009 + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; +using namespace Batch; + +void print_usage() +{ + cout << "usage: Test_eLL PROTOCOL" << endl; + cout << " PROTOCOL \"SSH\" or \"RSH\"" << endl; +} + +int main(int argc, char** argv) +{ + // Parse argument + if (argc != 2) { + print_usage(); + return 1; + } + CommunicationProtocolType protocol; + if (strcmp(argv[1], "SSH") == 0) + protocol = SSH; + else if (strcmp(argv[1], "RSH") == 0) + protocol = RSH; + else { + print_usage(); + return 1; + } + + cout << "*******************************************************************************************" << endl; + cout << "This program tests the batch submission based on LoadLeveler emulation. Passwordless" << endl; + cout << "authentication must be used for this test to pass. For SSH, this can be configured with" << endl; + cout << "ssh-agent for instance. For RSH, this can be configured with the .rhosts file." << endl; + cout << "*******************************************************************************************" << endl; + + // eventually remove any previous result + remove("result.txt"); + + try { + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & homedir = parser.getValue("TEST_ELL_HOMEDIR"); + const string & host = parser.getValue("TEST_ELL_HOST"); + const string & user = parser.getValue("TEST_ELL_USER"); + const string & queue = parser.getValue("TEST_ELL_QUEUE"); + int timeout = parser.getValueAsInt("TEST_ELL_TIMEOUT"); + + // Define the job... + Job job; + // ... and its parameters ... + Parametre p; + p[EXECUTABLE] = "./test-script.sh"; + p[NAME] = string("Test_eLL_") + argv[1]; + p[WORKDIR] = homedir + "/tmp/Batch"; + p[INFILE] = Couple("seta.sh", "tmp/Batch/seta.sh"); + p[INFILE] += Couple("setb.sh", "tmp/Batch/setb.sh"); + p[OUTFILE] = Couple("result.txt", "tmp/Batch/result.txt"); + p[TMPDIR] = "tmp/Batch/"; + p[NBPROC] = 1; + p[MAXWALLTIME] = 1; + p[MAXRAMSIZE] = 1; + p[HOMEDIR] = homedir; + p[QUEUE] = queue; + job.setParametre(p); + // ... and its environment + Environnement e; + e["MYENVVAR"] = "MYVALUE"; + job.setEnvironnement(e); + cout << job << endl; + + // Get the catalog + BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); + + // Create a BatchManager of type ePBS on localhost + FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("eLL")); + BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol); + + // Submit the job to the BatchManager + JobId jobid = bm->submitJob(job); + cout << jobid.__repr__() << endl; + + // Wait for the end of the job + string state = bm->waitForJobEnd(jobid, timeout); + + if (state == FINISHED || state == FAILED) { + cout << "Job " << jobid.__repr__() << " is done" << endl; + bm->importOutputFiles(job, "resultdir/seconddirname"); + } else { + cerr << "Timeout while executing job" << endl; + return 1; + } + + } catch (GenericException e) { + cerr << "Error: " << e << endl; + return 1; + } catch (ParserException e) { + cerr << "Parser error: " << e.what() << endl; + return 1; + } + + // test the result file + try { + SimpleParser resultParser; + resultParser.parse("resultdir/seconddirname/result.txt"); + cout << "Result:" << endl << resultParser; + const string & envvar = resultParser.getValue("MYENVVAR"); + int result = resultParser.getValueAsInt("c"); + if (envvar == "MYVALUE" && result == 12) { + cout << "OK, Expected result found." << endl; + return 0; + } else { + cerr << "Error, result is not the expected one (MYENVVAR = MYVALUE, c = 12)." << endl; + return 1; + } + } catch (ParserException e) { + cerr << "Parser error on result file: " << e.what() << endl; + return 1; + } +} diff --git a/src/LoadLeveler/Test/seta.sh b/src/LoadLeveler/Test/seta.sh new file mode 100644 index 0000000..42d1e38 --- /dev/null +++ b/src/LoadLeveler/Test/seta.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +a=4 diff --git a/src/LoadLeveler/Test/setb.sh b/src/LoadLeveler/Test/setb.sh new file mode 100644 index 0000000..8969060 --- /dev/null +++ b/src/LoadLeveler/Test/setb.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +b=3 diff --git a/src/LoadLeveler/Test/test-script.sh b/src/LoadLeveler/Test/test-script.sh new file mode 100755 index 0000000..ae952c8 --- /dev/null +++ b/src/LoadLeveler/Test/test-script.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +source seta.sh +source setb.sh + +c=`expr $a "*" $b` + +echo "MYENVVAR = $MYENVVAR" > result.txt +echo "c = $c" >> result.txt -- 2.39.2