From: barate Date: Mon, 7 Sep 2009 10:01:22 +0000 (+0000) Subject: Added PBS test based on Torque. X-Git-Tag: V_1_0_0_RC3~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2fde1261612ed8f1f48e5ad4664e7686d71b1729;p=tools%2Flibbatch.git Added PBS test based on Torque. --- diff --git a/src/Core/Test/batchtest.conf b/src/Core/Test/batchtest.conf index a318eac..00b3228 100644 --- a/src/Core/Test/batchtest.conf +++ b/src/Core/Test/batchtest.conf @@ -23,6 +23,11 @@ TEST_LOCAL_SSH_FINALIZATION_TIME = 5 # Finalization time (in seconds) f TEST_PBS_HOST = "localhost" # PBS server host TEST_PBS_USER = "username" # Login for the PBS server -TEST_PBS_HOMEDIR = "/home/username" # Home directory on PBS server TEST_PBS_QUEUE = "queuename" # Queue to submit test job on PBS server TEST_PBS_TIMEOUT = 120 # Execution timeout (in seconds) for PBS Batch test + +TEST_EPBS_HOST = "localhost" # PBS server host +TEST_EPBS_USER = "username" # Login for the PBS server +TEST_EPBS_HOMEDIR = "/home/username" # Home directory on PBS server +TEST_EPBS_QUEUE = "queuename" # Queue to submit test job on PBS server +TEST_EPBS_TIMEOUT = 120 # Execution timeout (in seconds) for PBS Batch test diff --git a/src/PBS/Batch_BatchManager_PBS.cxx b/src/PBS/Batch_BatchManager_PBS.cxx index dd2b1b8..ccd48f5 100644 --- a/src/PBS/Batch_BatchManager_PBS.cxx +++ b/src/PBS/Batch_BatchManager_PBS.cxx @@ -90,12 +90,7 @@ namespace Batch { // On se connecte au serveur PBS _connect = pbs_connect(const_cast< char * >(_hostname.c_str())); if (_connect < 0) { // si erreur - char * errmsg = pbs_geterrmsg(_connect); - string msg = "PBS Server on host \""; - msg += _hostname; - msg += "\" : "; - msg += errmsg ? errmsg : "Reason unknown"; - throw ConnexionFailureException(msg.c_str()); + throw ConnexionFailureException(getErrorMessage("connect").c_str()); } } @@ -105,14 +100,23 @@ namespace Batch { // On se deconnecte du serveur PBS int rc = pbs_disconnect(_connect); if (rc < 0) { // si erreur - string msg = "PBS Server on host \""; - msg += _hostname; - msg += "\" : "; - msg += pbs_geterrmsg(_connect); - throw ConnexionFailureException(msg.c_str()); + throw ConnexionFailureException(getErrorMessage("disconnect").c_str()); } } + string BatchManager_PBS::getErrorMessage(const char * operation) const + { + char * msg = pbs_geterrmsg(_connect); + stringstream sstr; + sstr << "PBS " << operation << " error (host \"" << _hostname << "\"): "; + if (msg != NULL) { + sstr << msg; + } else { + sstr << "code = " << pbs_errno << " (" << pbse_to_txt(pbs_errno) << ")"; + } + return sstr.str(); + } + // Methode pour le controle des jobs : soumet un job au gestionnaire const JobId BatchManager_PBS::submitJob(const Job & job) { @@ -123,9 +127,7 @@ namespace Batch { jobpbs.getDestination(), NULL); if (!ref) { // si erreur - char * msg = pbs_geterrmsg(_connect); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("PBS submit error. Reason : ") + msg); + throw APIInternalFailureException(getErrorMessage("submit").c_str()); } JobId id(this, string(ref)); @@ -139,9 +141,7 @@ namespace Batch { char * ref = const_cast< char * >(jobid.getReference().c_str()); int rc = pbs_deljob(_connect, ref, 0); if (rc) { // si erreur - char * msg = pbs_geterrmsg(_connect); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("PBS deljob error. Reason : ") + msg); + throw APIInternalFailureException(getErrorMessage("deljob").c_str()); } } @@ -151,9 +151,7 @@ namespace Batch { char * ref = const_cast< char * >(jobid.getReference().c_str()); int rc = pbs_holdjob(_connect, ref, USER_HOLD, 0); if (rc) { // si erreur - char * msg = pbs_geterrmsg(_connect); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("PBS holdjob error. Reason : ") + msg); + throw APIInternalFailureException(getErrorMessage("holdjob").c_str()); } } @@ -163,9 +161,7 @@ namespace Batch { char * ref = const_cast< char * >(jobid.getReference().c_str()); int rc = pbs_rlsjob(_connect, ref, USER_HOLD, 0); if (rc) { // si erreur - char * msg = pbs_geterrmsg(_connect); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("PBS rlsjob error. Reason : ") + msg); + throw APIInternalFailureException(getErrorMessage("rlsjob").c_str()); } } @@ -182,9 +178,7 @@ namespace Batch { jobpbs.getAttributes(), NULL); if (rc) { // si erreur - char * msg = pbs_geterrmsg(_connect); - if (!msg) msg = "unknown"; - throw APIInternalFailureException(string("PBS alterjob error. Reason : ") + msg); + throw APIInternalFailureException(getErrorMessage("alterjob").c_str()); } } diff --git a/src/PBS/Batch_BatchManager_PBS.hxx b/src/PBS/Batch_BatchManager_PBS.hxx index ee6ac82..0db818f 100644 --- a/src/PBS/Batch_BatchManager_PBS.hxx +++ b/src/PBS/Batch_BatchManager_PBS.hxx @@ -80,6 +80,8 @@ namespace Batch { protected: + std::string getErrorMessage(const char * operation) const; + int _connect; // PBS connect id private: diff --git a/src/PBS/Test/CMakeLists.txt b/src/PBS/Test/CMakeLists.txt index f34be48..0ac39cd 100644 --- a/src/PBS/Test/CMakeLists.txt +++ b/src/PBS/Test/CMakeLists.txt @@ -31,7 +31,13 @@ include_directories(${CMAKE_SOURCE_DIR}/src/Core/Test) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -# Build the test program and add the test +# 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 (BUILD_PBS_INTERFACE AND PBS_FOUND) + add_executable(Test_PBS Test_PBS.cxx) + target_link_libraries(Test_PBS Batch SimpleParser) + ADD_TEST(PBS Test_PBS) +ENDIF (BUILD_PBS_INTERFACE AND PBS_FOUND) diff --git a/src/PBS/Test/Test_PBS.cxx b/src/PBS/Test/Test_PBS.cxx new file mode 100644 index 0000000..e58278d --- /dev/null +++ b/src/PBS/Test/Test_PBS.cxx @@ -0,0 +1,146 @@ +// 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_PBS.cxx : + * + * Author : Renaud BARATE - EDF R&D + * Date : September 2009 + * + */ + +#include +#include + +#include +#include +#include +#include + +#include + +#ifdef WIN32 +#include +#include +#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." << endl; + cout << "*******************************************************************************************" << endl; + + // eventually remove any previous result + remove("result.txt"); + + try { + // Parse the test configuration file + SimpleParser parser; + parser.parseTestConfigFile(); + const string & host = parser.getValue("TEST_PBS_HOST"); + const string & user = parser.getValue("TEST_PBS_USER"); + const string & queue = parser.getValue("TEST_PBS_QUEUE"); + int timeout = parser.getValueAsInt("TEST_PBS_TIMEOUT"); + + char * cwd = +#ifdef WIN32 + _getcwd(NULL, 0); +#else + new char [PATH_MAX]; + getcwd(cwd, PATH_MAX); +#endif + string workdir = cwd; + delete [] cwd; + + // Define the job... + Job job; + // ... and its parameters ... + Parametre p; + p["EXECUTABLE"] = "test-script.sh"; + p["NAME"] = "Test_PBS"; + p["INFILE"] = Couple(workdir + "/seta.sh", "seta.sh"); + p["INFILE"] += Couple(workdir + "/setb.sh", "setb.sh"); + p["OUTFILE"] = Couple(workdir + "/result.txt", "result.txt"); + p["USER"] = user; + p["NBPROC"] = 1; + p["MAXWALLTIME"] = 1; + p["MAXRAMSIZE"] = 4; + p["QUEUE"] = queue; + job.setParametre(p); + // ... and its environment + Environnement e; + job.setEnvironnement(e); + cout << job << endl; + + // Get the catalog + BatchManagerCatalog& c = BatchManagerCatalog::getInstance(); + + // Create a BatchManager of type ePBS on localhost + FactBatchManager * fbm = c("PBS"); + BatchManager * bm = (*fbm)(host.c_str()); + + // Submit the job to the BatchManager + JobId jobid = bm->submitJob(job); + cout << jobid.__repr__() << endl; + + // Wait for the end of the job + string state = "Undefined"; + for (int i=0 ; i