From 2a465e51fe8c18f5732714dfba052d568ed0e716 Mon Sep 17 00:00:00 2001 From: barate Date: Mon, 18 Jan 2010 13:50:12 +0000 Subject: [PATCH] Added constants to represent job status uniformly. Fixed some errors under Windows. Cleaned Swig code. Removed again some old files that reappeared with the merge. --- src/Core/Batch_CommunicationProtocol.cxx | 7 +- src/Core/Batch_CommunicationProtocolSSH.cxx | 20 ++- src/Core/Batch_Constants.cxx | 84 +++++++++++ src/Core/Batch_Constants.hxx | 97 +++++++++++++ src/Core/Batch_Parametre.cxx | 5 +- src/Core/Batch_Parametre.hxx | 59 ++------ src/Core/CMakeLists.txt | 1 + src/LSF/Batch_JobInfo_LSF.cxx | 1 + src/LSF/Batch_JobInfo_eLSF.cxx | 22 ++- src/Local/Batch_BatchManager_Local.cxx | 10 +- src/Local/Test/Test_Local_RSH.cxx | 4 +- src/Local/Test/Test_Local_SH.cxx | 4 +- src/Local/Test/Test_Local_SSH.cxx | 4 +- src/PBS/Batch_JobInfo_PBS.cxx | 21 ++- src/PBS/Batch_JobInfo_ePBS.cxx | 45 +++--- src/PBS/Batch_JobInfo_ePBS.hxx | 8 +- src/PBS/Test/Test_ePBS.cxx | 4 +- src/PBS/Test/Test_ePBS_RSH.cxx | 147 -------------------- src/PBS/Test/Test_ePBS_SSH.cxx | 147 -------------------- src/Python/Test/Test_Python_Local_SH.py | 4 +- src/Python/libBatch_Swig.i | 8 ++ src/Python/libBatch_Swig_typemap.i | 35 ----- src/SGE/Batch_JobInfo_eSGE.cxx | 35 +++-- 23 files changed, 331 insertions(+), 441 deletions(-) create mode 100644 src/Core/Batch_Constants.cxx create mode 100644 src/Core/Batch_Constants.hxx delete mode 100644 src/PBS/Test/Test_ePBS_RSH.cxx delete mode 100644 src/PBS/Test/Test_ePBS_SSH.cxx diff --git a/src/Core/Batch_CommunicationProtocol.cxx b/src/Core/Batch_CommunicationProtocol.cxx index 530a5f3..1d70b57 100644 --- a/src/Core/Batch_CommunicationProtocol.cxx +++ b/src/Core/Batch_CommunicationProtocol.cxx @@ -127,9 +127,14 @@ namespace Batch { for (unsigned int i=0 ; i + +#include "Batch_Defines.hxx" + +// These macros simplify the creation of new string constants for keys and +// values in parameters map. +// TODO: replace those static declarations by an external description file (XML for instance) +#define decl_extern_Constant(constant) extern BATCH_EXPORT const std::string constant +#define def_Constant(constant) const std::string constant = #constant + +namespace Batch { + + // Declaration of the keys for the parameter map + decl_extern_Constant(ACCOUNT); + decl_extern_Constant(ARGUMENTS); + decl_extern_Constant(CHECKPOINT); + decl_extern_Constant(CKPTINTERVAL); + decl_extern_Constant(CREATIONTIME); + decl_extern_Constant(EGROUP); + decl_extern_Constant(ELIGIBLETIME); + decl_extern_Constant(ENDTIME); + decl_extern_Constant(EUSER); + decl_extern_Constant(EXECUTABLE); + decl_extern_Constant(EXECUTIONHOST); + decl_extern_Constant(EXITCODE); + decl_extern_Constant(HOLD); + decl_extern_Constant(ID); + decl_extern_Constant(INFILE); + decl_extern_Constant(MAIL); + decl_extern_Constant(MAXCPUTIME); + decl_extern_Constant(MAXDISKSIZE); + decl_extern_Constant(MAXRAMSIZE); + decl_extern_Constant(MAXWALLTIME); + decl_extern_Constant(MODIFICATIONTIME); + decl_extern_Constant(NAME); + decl_extern_Constant(NBPROC); + decl_extern_Constant(OUTFILE); + decl_extern_Constant(PID); + decl_extern_Constant(QUEUE); + decl_extern_Constant(QUEUEDTIME); + decl_extern_Constant(SERVER); + decl_extern_Constant(STARTTIME); + decl_extern_Constant(STATE); + decl_extern_Constant(TEXT); + decl_extern_Constant(TMPDIR); + decl_extern_Constant(USEDCPUTIME); + decl_extern_Constant(USEDDISKSIZE); + decl_extern_Constant(USEDRAMSIZE); + decl_extern_Constant(USEDWALLTIME); + decl_extern_Constant(USER); + decl_extern_Constant(WORKDIR); + decl_extern_Constant(HOMEDIR); + + // These constants define the status of a job (parameter STATE) + decl_extern_Constant(CREATED); + decl_extern_Constant(IN_PROCESS); + decl_extern_Constant(QUEUED); + decl_extern_Constant(RUNNING); + decl_extern_Constant(PAUSED); + decl_extern_Constant(FINISHED); + decl_extern_Constant(FAILED); + +} + +#endif diff --git a/src/Core/Batch_Parametre.cxx b/src/Core/Batch_Parametre.cxx index bc17513..3031517 100644 --- a/src/Core/Batch_Parametre.cxx +++ b/src/Core/Batch_Parametre.cxx @@ -34,9 +34,8 @@ using namespace std; -// Definition des membres constants statiques -// Definition des noms globaux pour les clefs en tant que references -// TODO : supprimer les declarations statiques des clefs de la map +// TODO: These definitions in global namespace are here only to avoid breaking Kernel compilation for now. +// They must be removed as soon as possible. def_static_MapKey(ACCOUNT) def_static_MapKey(ARGUMENTS) def_static_MapKey(CHECKPOINT) diff --git a/src/Core/Batch_Parametre.hxx b/src/Core/Batch_Parametre.hxx index 17401ca..4ba9f7b 100644 --- a/src/Core/Batch_Parametre.hxx +++ b/src/Core/Batch_Parametre.hxx @@ -31,21 +31,18 @@ #ifndef _PARAMETRE_H_ #define _PARAMETRE_H_ -#include "Batch_Defines.hxx" - #include #include + +#include "Batch_Defines.hxx" +#include "Batch_Constants.hxx" #include "Batch_InvalidKeyException.hxx" #include "Batch_Versatile.hxx" -// Ces macros permettent de simplifier l'ajout de nouvelles -// clefs dans la map Parametre -// TODO : remplacer ce mecanisme statique par la lecture -// TODO : d'une descrption dans un fichier exterieur (genre XML) - +// TODO: These declarations are here only to avoid breaking Kernel compilation for now. +// They must be removed as soon as possible. #define def_extern_MapKey(mk) extern BATCH_EXPORT const std::string & mk; -#define def_static_MapKey(mk) const std::string Batch::Parametre::mk(#mk); \ - const std::string & mk = Batch::Parametre::mk; +#define def_static_MapKey(mk) const std::string & mk = #mk; namespace Batch { @@ -65,48 +62,6 @@ namespace Batch { // Operateur d'affectation Parametre & operator =(const Parametre & PM); - // Declarations statique des clefs de la map - // TODO : supprimer les declarations statiques des clefs de la map - static const std::string ACCOUNT; - static const std::string ARGUMENTS; - static const std::string CHECKPOINT; - static const std::string CKPTINTERVAL; - static const std::string CREATIONTIME; - static const std::string EGROUP; - static const std::string ELIGIBLETIME; - static const std::string ENDTIME; - static const std::string EUSER; - static const std::string EXECUTABLE; - static const std::string EXECUTIONHOST; - static const std::string EXITCODE; - static const std::string HOLD; - static const std::string ID; - static const std::string INFILE; - static const std::string MAIL; - static const std::string MAXCPUTIME; - static const std::string MAXDISKSIZE; - static const std::string MAXRAMSIZE; - static const std::string MAXWALLTIME; - static const std::string MODIFICATIONTIME; - static const std::string NAME; - static const std::string NBPROC; - static const std::string OUTFILE; - static const std::string PID; - static const std::string QUEUE; - static const std::string QUEUEDTIME; - static const std::string SERVER; - static const std::string STARTTIME; - static const std::string STATE; - static const std::string TEXT; - static const std::string TMPDIR; - static const std::string USEDCPUTIME; - static const std::string USEDDISKSIZE; - static const std::string USEDRAMSIZE; - static const std::string USEDWALLTIME; - static const std::string USER; - static const std::string WORKDIR; - static const std::string HOMEDIR; - protected: std::map< std::string, TypeParam > TypeMap; // map interne servant a controler le type de la valeur associee a chaque clef @@ -116,6 +71,8 @@ namespace Batch { } +// TODO: These declarations in global namespace are here only to avoid breaking Kernel compilation for now. +// They must be removed as soon as possible. def_extern_MapKey(ACCOUNT) def_extern_MapKey(ARGUMENTS) def_extern_MapKey(CHECKPOINT) diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index d45850d..8aa64c0 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -28,6 +28,7 @@ SET(CLASS_LIST Core/Batch_APIInternalFailureException Core/Batch_CharType Core/Batch_CommunicationProtocol Core/Batch_ConnexionFailureException + Core/Batch_Constants Core/Batch_Couple Core/Batch_CoupleType Core/Batch_Date diff --git a/src/LSF/Batch_JobInfo_LSF.cxx b/src/LSF/Batch_JobInfo_LSF.cxx index b964aba..57ae735 100644 --- a/src/LSF/Batch_JobInfo_LSF.cxx +++ b/src/LSF/Batch_JobInfo_LSF.cxx @@ -126,6 +126,7 @@ namespace Batch { if (IS_POST_ERR(jobInfo.status)) status << " Job is post-error;"; + // TODO: Use constants for STATE instead _param[STATE] = status.str(); _running = IS_FINISH(jobInfo.status) ? false : true; diff --git a/src/LSF/Batch_JobInfo_eLSF.cxx b/src/LSF/Batch_JobInfo_eLSF.cxx index 6f6f063..eb18002 100644 --- a/src/LSF/Batch_JobInfo_eLSF.cxx +++ b/src/LSF/Batch_JobInfo_eLSF.cxx @@ -63,7 +63,27 @@ namespace Batch { fp >> username; fp >> status; - _param[STATE] = status; + if (status == "PEND") { // Pending + _param[STATE] = QUEUED; + } else if (status == "PSUSP") { // Suspended while pending + _param[STATE] = PAUSED; + } else if (status == "RUN") { // Running + _param[STATE] = RUNNING; + } else if (status == "USUSP") { // Suspended while running + _param[STATE] = PAUSED; + } else if (status == "SSUSP") { // Suspended by LSF + _param[STATE] = PAUSED; + } else if (status == "DONE") { // Finished successfully + _param[STATE] = FINISHED; + } else if (status == "EXIT") { // Finished in error + _param[STATE] = FAILED; + } else if (status == "UNKWN") { // Lost contact + _param[STATE] = FAILED; + } else if (status == "ZOMBI") { // Zombie + _param[STATE] = FAILED; + } else { + cerr << "Unknown job state code: " << status << endl; + } if( status.find("RUN") != string::npos) _running = true; diff --git a/src/Local/Batch_BatchManager_Local.cxx b/src/Local/Batch_BatchManager_Local.cxx index fd975fe..37ea02f 100644 --- a/src/Local/Batch_BatchManager_Local.cxx +++ b/src/Local/Batch_BatchManager_Local.cxx @@ -560,7 +560,7 @@ namespace Batch { ostringstream thread_id_sst; thread_id_sst << id; param[ID] = thread_id_sst.str(); - param[STATE] = "Running"; + param[STATE] = Batch::RUNNING; #ifndef WIN32 param[PID] = child; #endif @@ -589,7 +589,7 @@ namespace Batch { if (exitCode != STILL_ACTIVE) { pthread_mutex_lock(&_bm._threads_mutex); _bm._threads[id].status = DONE; - _bm._threads[id].param[STATE] = "Done"; + _bm._threads[id].param[STATE] = Batch::FINISHED; pthread_mutex_unlock(&_bm._threads_mutex); // @@@ --------> SECTION CRITIQUE <-------- @@@ UNDER_LOCK( cout << "Father sees his child is DONE: exit code = " << exitCode << endl ); @@ -619,7 +619,7 @@ namespace Batch { // @@@ --------> SECTION CRITIQUE <-------- @@@ pthread_mutex_lock(&_bm._threads_mutex); _bm._threads[id].status = STOPPED; - _bm._threads[id].param[STATE] = "Stopped"; + _bm._threads[id].param[STATE] = Batch::PAUSED; pthread_mutex_unlock(&_bm._threads_mutex); // @@@ --------> SECTION CRITIQUE <-------- @@@ UNDER_LOCK( cout << "Father sees his child is STOPPED : " << child_wait_rc << endl ); @@ -630,7 +630,7 @@ namespace Batch { // @@@ --------> SECTION CRITIQUE <-------- @@@ pthread_mutex_lock(&_bm._threads_mutex); _bm._threads[id].status = DONE; - _bm._threads[id].param[STATE] = "Done"; + _bm._threads[id].param[STATE] = Batch::FINISHED; pthread_mutex_unlock(&_bm._threads_mutex); // @@@ --------> SECTION CRITIQUE <-------- @@@ UNDER_LOCK( cout << "Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")" << endl ); @@ -642,7 +642,7 @@ namespace Batch { // @@@ --------> SECTION CRITIQUE <-------- @@@ pthread_mutex_lock(&_bm._threads_mutex); _bm._threads[id].status = DEAD; - _bm._threads[id].param[STATE] = "Dead"; + _bm._threads[id].param[STATE] = Batch::FAILED; pthread_mutex_unlock(&_bm._threads_mutex); // @@@ --------> SECTION CRITIQUE <-------- @@@ UNDER_LOCK( cout << "Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")" << endl ); diff --git a/src/Local/Test/Test_Local_RSH.cxx b/src/Local/Test/Test_Local_RSH.cxx index 8e5dc12..ff2dc82 100644 --- a/src/Local/Test/Test_Local_RSH.cxx +++ b/src/Local/Test/Test_Local_RSH.cxx @@ -102,14 +102,14 @@ int main(int argc, char** argv) // Wait for the end of the job string state = "Unknown"; - for (int i=0 ; i 0) ? paramState.str() : "Unknown"; cout << "Job state is: " << state << endl; } - if (state != "Done") { + if (state != FINISHED && state != FAILED) { cerr << "Error: Job not finished after timeout" << endl; return 1; } diff --git a/src/Local/Test/Test_Local_SH.cxx b/src/Local/Test/Test_Local_SH.cxx index e8e20b8..b5ecc1a 100644 --- a/src/Local/Test/Test_Local_SH.cxx +++ b/src/Local/Test/Test_Local_SH.cxx @@ -102,14 +102,14 @@ int main(int argc, char** argv) // Wait for the end of the job string state = "Unknown"; - for (int i=0 ; i 0) ? paramState.str() : "Unknown"; cout << "Job state is: " << state << endl; } - if (state != "Done") { + if (state != FINISHED && state != FAILED) { cerr << "Error: Job not finished after timeout" << endl; return 1; } diff --git a/src/Local/Test/Test_Local_SSH.cxx b/src/Local/Test/Test_Local_SSH.cxx index 212ac55..638b9b9 100644 --- a/src/Local/Test/Test_Local_SSH.cxx +++ b/src/Local/Test/Test_Local_SSH.cxx @@ -105,14 +105,14 @@ int main(int argc, char** argv) // Wait for the end of the job string state = "Unknown"; - for (int i=0 ; i 0) ? paramState.str() : "Unknown"; cout << "Job state is: " << state << endl; } - if (state != "Done") { + if (state != FINISHED && state != FAILED) { cerr << "Error: Job not finished after timeout" << endl; return 1; } diff --git a/src/PBS/Batch_JobInfo_PBS.cxx b/src/PBS/Batch_JobInfo_PBS.cxx index 3a474fc..addf3c0 100644 --- a/src/PBS/Batch_JobInfo_PBS.cxx +++ b/src/PBS/Batch_JobInfo_PBS.cxx @@ -78,7 +78,26 @@ namespace Batch { _param[USER] = value; } else if (name == ATTR_state) { - _param[STATE] = value; + string status = value; + if (status == "C") { // Completed + _param[STATE] = FINISHED; + } else if (status == "E") { // Exiting + _param[STATE] = RUNNING; + } else if (status == "H") { // Held + _param[STATE] = PAUSED; + } else if (status == "Q") { // Queued + _param[STATE] = QUEUED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "S") { // Suspend + _param[STATE] = PAUSED; + } else if (status == "T") { // Transiting + _param[STATE] = IN_PROCESS; + } else if (status == "W") { // Waiting + _param[STATE] = PAUSED; + } else { + cerr << "Unknown job state code: " << status << endl; + } } else if (name == ATTR_queue) { _param[QUEUE] = value; diff --git a/src/PBS/Batch_JobInfo_ePBS.cxx b/src/PBS/Batch_JobInfo_ePBS.cxx index 75768ea..2ae7a06 100644 --- a/src/PBS/Batch_JobInfo_ePBS.cxx +++ b/src/PBS/Batch_JobInfo_ePBS.cxx @@ -43,8 +43,6 @@ using namespace std; namespace Batch { - - // Constructeurs JobInfo_ePBS::JobInfo_ePBS(int id, string logFile) : JobInfo() { @@ -57,7 +55,6 @@ namespace Batch { char line[128]; ifstream fp(logFile.c_str(),ios::in); - string status; string sline; size_t pos = string::npos; while( (pos == string::npos) && fp.getline(line,80,'\n') ){ @@ -66,28 +63,39 @@ namespace Batch { }; if(pos!=string::npos){ + string status; istringstream iss(sline); iss >> status; iss >> status; iss >> status; - } - else - status = "U"; - _param[STATE] = status; - - if( status.find("R") != string::npos) - _running = true; - - } - - // Teste si un job est present en machine - bool JobInfo_ePBS::isRunning() const - { - return _running; + if (status == "C") { // Completed + _param[STATE] = FINISHED; + } else if (status == "E") { // Exiting + _param[STATE] = RUNNING; + } else if (status == "H") { // Held + _param[STATE] = PAUSED; + } else if (status == "Q") { // Queued + _param[STATE] = QUEUED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "S") { // Suspend + _param[STATE] = PAUSED; + } else if (status == "T") { // Transiting + _param[STATE] = IN_PROCESS; + } else if (status == "W") { // Waiting + _param[STATE] = PAUSED; + } else { + cerr << "Unknown job state code: " << status << endl; + } + } else { + // On some batch managers, the job is deleted as soon as it is finished, + // so we have to consider that an unknown job is a finished one, even if + // it is not always true. + _param[STATE] = FINISHED; + } } - // Destructeur JobInfo_ePBS::~JobInfo_ePBS() { @@ -114,5 +122,4 @@ namespace Batch { return sst.str(); } - } diff --git a/src/PBS/Batch_JobInfo_ePBS.hxx b/src/PBS/Batch_JobInfo_ePBS.hxx index 698d68a..033fc98 100644 --- a/src/PBS/Batch_JobInfo_ePBS.hxx +++ b/src/PBS/Batch_JobInfo_ePBS.hxx @@ -42,24 +42,18 @@ namespace Batch { { public: // Constructeurs et destructeur - JobInfo_ePBS() : _running(false) {}; + JobInfo_ePBS() {}; JobInfo_ePBS(int id,std::string logFile); virtual ~JobInfo_ePBS(); // Constructeur par recopie JobInfo_ePBS(const JobInfo_ePBS & jinfo) : JobInfo(jinfo) {}; - // Teste si un job est present en machine - virtual bool isRunning() const; - // Methodes pour l'interfacage avec Python (SWIG) // TODO : supprimer ces methodes et transferer leur definitions dans SWIG std::string __str__() const; // SWIG : affichage en Python std::string __repr__() const { return __str__(); }; // SWIG : affichage en Python - protected: - bool _running; // etat du job en machine - private: // Convertit une date HH:MM:SS en secondes long HMStoLong(const std::string &); diff --git a/src/PBS/Test/Test_ePBS.cxx b/src/PBS/Test/Test_ePBS.cxx index 1944177..b770668 100644 --- a/src/PBS/Test/Test_ePBS.cxx +++ b/src/PBS/Test/Test_ePBS.cxx @@ -136,7 +136,7 @@ int main(int argc, char** argv) JobInfo jinfo = jobid.queryJob(); string state = jinfo.getParametre()["STATE"].str(); cout << "State is \"" << state << "\""; - while (!timeoutReached && state != "U" && state != "C") { + while (!timeoutReached && state != FINISHED && state != FAILED) { cout << ", sleeping " << sleeptime << "s..." << endl; sleep(sleeptime); time += sleeptime; @@ -152,7 +152,7 @@ int main(int argc, char** argv) } cout << endl; - if (state == "U" || state == "C") { + if (state == FINISHED || state == FAILED) { cout << "Job " << jobid.__repr__() << " is done" << endl; bm->importOutputFiles(job, "."); } else { diff --git a/src/PBS/Test/Test_ePBS_RSH.cxx b/src/PBS/Test/Test_ePBS_RSH.cxx deleted file mode 100644 index daafecb..0000000 --- a/src/PBS/Test/Test_ePBS_RSH.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// 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 -#include - -#include -#include -#include -#include -#include -#include - -#include - -#ifdef WIN32 -#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 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 ; iimportOutputFiles(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; -} diff --git a/src/PBS/Test/Test_ePBS_SSH.cxx b/src/PBS/Test/Test_ePBS_SSH.cxx deleted file mode 100644 index 42e98c3..0000000 --- a/src/PBS/Test/Test_ePBS_SSH.cxx +++ /dev/null @@ -1,147 +0,0 @@ -// 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 -#include - -#include -#include -#include -#include -#include -#include - -#include - -#ifdef WIN32 -#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 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 ; iimportOutputFiles(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; -} diff --git a/src/Python/Test/Test_Python_Local_SH.py b/src/Python/Test/Test_Python_Local_SH.py index 4ea755c..b013b0b 100644 --- a/src/Python/Test/Test_Python_Local_SH.py +++ b/src/Python/Test/Test_Python_Local_SH.py @@ -71,7 +71,7 @@ def work(): # Wait for the end of the job state = 'Unknown' i=0 - while state != 'Done' and i 0 ){ istringstream iss(sline); iss >> status >> status >> status >> status >> status; - } - else - status = "e"; - - _param[STATE] = status; - - if( status.find("r") != string::npos) - _running = true; + if (status == "d") { // Deletion + _param[STATE] = FAILED; + } else if (status == "t") { // Transferring + _param[STATE] = IN_PROCESS; + } else if (status == "r") { // Running + _param[STATE] = RUNNING; + _running = true; + } else if (status == "R") { // Restarted + _param[STATE] = RUNNING; + _running = true; + } else if (status == "s") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "S") { // Suspended + _param[STATE] = PAUSED; + } else if (status == "T") { // Threshold + _param[STATE] = PAUSED; + } else if (status == "qw") { // Queued and waiting + _param[STATE] = QUEUED; + } else if (status == "h") { // Hold + _param[STATE] = PAUSED; + } else { + cerr << "Unknown job state code: " << status << endl; + } + } else { + // TODO: Check this. I suppose that unknown jobs are finished ones. + _param[STATE] = FINISHED; + } } // Teste si un job est present en machine -- 2.30.2