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
// 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());
}
}
// 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)
{
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));
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());
}
}
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());
}
}
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());
}
}
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());
}
}
protected:
+ std::string getErrorMessage(const char * operation) const;
+
int _connect; // PBS connect id
private:
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)
--- /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_PBS.cxx :
+ *
+ * Author : Renaud BARATE - EDF R&D
+ * Date : September 2009
+ *
+ */
+
+#include <iostream>
+#include <fstream>
+
+#include <Batch_Job.hxx>
+#include <Batch_BatchManagerCatalog.hxx>
+#include <Batch_FactBatchManager.hxx>
+#include <Batch_BatchManager.hxx>
+
+#include <SimpleParser.hxx>
+
+#ifdef WIN32
+#include <Windows.h>
+#include <direct.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." << 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<timeout/2 && state != "U" && state != "C"; i++) {
+ sleep(2);
+ JobInfo jinfo = jobid.queryJob();
+ state = jinfo.getParametre()["STATE"].str();
+ cout << "State is \"" << state << "\"" << endl;
+ }
+
+ if (state == "U" || state == "C") {
+ cout << "Job " << jobid.__repr__() << " is done" << endl;
+ } else {
+ cerr << "Timeout while executing job" << endl;
+ return 1;
+ }
+
+ } catch (GenericException e) {
+ cerr << "Error: " << e << endl;
+ return 1;
+ } catch (ParserException e) {
+ cerr << "Parser error: " << e.what() << endl;
+ return 1;
+ }
+
+ // test the result file
+ 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;
+}
// Parse the test configuration file
SimpleParser parser;
parser.parseTestConfigFile();
- const string & homedir = parser.getValue("TEST_PBS_HOMEDIR");
- 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");
+ 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;