Salome HOME
Added constants to represent job status uniformly. Fixed some errors under Windows...
authorbarate <barate>
Mon, 18 Jan 2010 13:50:12 +0000 (13:50 +0000)
committerbarate <barate>
Mon, 18 Jan 2010 13:50:12 +0000 (13:50 +0000)
23 files changed:
src/Core/Batch_CommunicationProtocol.cxx
src/Core/Batch_CommunicationProtocolSSH.cxx
src/Core/Batch_Constants.cxx [new file with mode: 0644]
src/Core/Batch_Constants.hxx [new file with mode: 0644]
src/Core/Batch_Parametre.cxx
src/Core/Batch_Parametre.hxx
src/Core/CMakeLists.txt
src/LSF/Batch_JobInfo_LSF.cxx
src/LSF/Batch_JobInfo_eLSF.cxx
src/Local/Batch_BatchManager_Local.cxx
src/Local/Test/Test_Local_RSH.cxx
src/Local/Test/Test_Local_SH.cxx
src/Local/Test/Test_Local_SSH.cxx
src/PBS/Batch_JobInfo_PBS.cxx
src/PBS/Batch_JobInfo_ePBS.cxx
src/PBS/Batch_JobInfo_ePBS.hxx
src/PBS/Test/Test_ePBS.cxx
src/PBS/Test/Test_ePBS_RSH.cxx [deleted file]
src/PBS/Test/Test_ePBS_SSH.cxx [deleted file]
src/Python/Test/Test_Python_Local_SH.py
src/Python/libBatch_Swig.i
src/Python/libBatch_Swig_typemap.i
src/SGE/Batch_JobInfo_eSGE.cxx

index 530a5f3765495e98246f67c089a82dd2eb4340f1..1d70b576503e04edaa3c6d1ec3b2abc83fba014f 100644 (file)
@@ -127,9 +127,14 @@ namespace Batch {
     for (unsigned int i=0 ; i<commandArgs.size() ; i++) {
       if (i != 0) commandStr += " ";
 
-      // if the argument contains spaces, we surround it with quotes
+      // if the argument contains spaces, we surround it with simple quotes (Linux)
+      // or double quotes (Windows)
       if (commandArgs[i].find(' ') != string::npos) {
+#ifdef WIN32
+        commandStr += string("\"") + commandArgs[i] + "\"";
+#else
         commandStr += string("\'") + commandArgs[i] + "\'";
+#endif
       } else {
         commandStr += commandArgs[i];
       }
index e6b4198106337b288e20efadf2a079e9624f39dd..c1c800e5573ff0998ecd3a1146d2747a8e948cf5 100644 (file)
@@ -67,22 +67,30 @@ namespace Batch {
       if (sourceUser.size() != 0) {
         fullSource += sourceUser + "@";
       }
-      fullSource += sourceHost + ":'";
+      fullSource += sourceHost + ":";
     }
+#ifndef WIN32
+    fullSource += "'";
+#endif
     fullSource += sourcePath;
-    if (sourceHost.size() != 0)
-      fullSource += "'";
+#ifndef WIN32
+    fullSource += "'";
+#endif
 
     string fullDestination;
     if (destinationHost.size() != 0) {
       if (destinationUser.size() != 0) {
         fullDestination += destinationUser + "@";
       }
-      fullDestination += destinationHost + ":'";
+      fullDestination += destinationHost + ":";
     }
+#ifndef WIN32
+    fullDestination += "'";
+#endif
     fullDestination += destinationPath;
-    if (destinationHost.size() != 0)
-      fullDestination += "'";
+#ifndef WIN32
+    fullDestination += "'";
+#endif
 
     // Option -p is used to keep the same permissions for the destination file
     // (particularly useful to keep scripts executable when copying them)
diff --git a/src/Core/Batch_Constants.cxx b/src/Core/Batch_Constants.cxx
new file mode 100644 (file)
index 0000000..bb173ed
--- /dev/null
@@ -0,0 +1,84 @@
+//  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_Constants.cxx :
+ *
+ * Auteur : Renaud BARATE - EDF R&D
+ * Date   : January 2010
+ *
+ */
+
+#include "Batch_Constants.hxx"
+
+namespace Batch {
+
+  // Definition of the string constants (keys for the parameter map)
+  def_Constant(ACCOUNT);
+  def_Constant(ARGUMENTS);
+  def_Constant(CHECKPOINT);
+  def_Constant(CKPTINTERVAL);
+  def_Constant(CREATIONTIME);
+  def_Constant(EGROUP);
+  def_Constant(ELIGIBLETIME);
+  def_Constant(ENDTIME);
+  def_Constant(EUSER);
+  def_Constant(EXECUTABLE);
+  def_Constant(EXECUTIONHOST);
+  def_Constant(EXITCODE);
+  def_Constant(HOLD);
+  def_Constant(ID);
+  def_Constant(INFILE);
+  def_Constant(MAIL);
+  def_Constant(MAXCPUTIME);
+  def_Constant(MAXDISKSIZE);
+  def_Constant(MAXRAMSIZE);
+  def_Constant(MAXWALLTIME);
+  def_Constant(MODIFICATIONTIME);
+  def_Constant(NAME);
+  def_Constant(NBPROC);
+  def_Constant(OUTFILE);
+  def_Constant(PID);
+  def_Constant(QUEUE);
+  def_Constant(QUEUEDTIME);
+  def_Constant(SERVER);
+  def_Constant(STARTTIME);
+  def_Constant(STATE);
+  def_Constant(TEXT);
+  def_Constant(TMPDIR);
+  def_Constant(USEDCPUTIME);
+  def_Constant(USEDDISKSIZE);
+  def_Constant(USEDRAMSIZE);
+  def_Constant(USEDWALLTIME);
+  def_Constant(USER);
+  def_Constant(WORKDIR);
+  def_Constant(HOMEDIR);
+
+  // These constants define the status of a job (parameter STATE);
+  def_Constant(CREATED);
+  def_Constant(IN_PROCESS);
+  def_Constant(QUEUED);
+  def_Constant(RUNNING);
+  def_Constant(PAUSED);
+  def_Constant(FINISHED);
+  def_Constant(FAILED);
+
+}
diff --git a/src/Core/Batch_Constants.hxx b/src/Core/Batch_Constants.hxx
new file mode 100644 (file)
index 0000000..79776c7
--- /dev/null
@@ -0,0 +1,97 @@
+//  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_Constants.hxx :
+ *
+ * Auteur : Renaud BARATE - EDF R&D
+ * Date   : January 2010
+ *
+ */
+
+#ifndef _CONSTANTS_H_
+#define _CONSTANTS_H_
+
+#include <string>
+
+#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
index bc175132e0c14978eefeaa35794c2eceb789d77a..3031517e49b55b8dfb610d75f5d4a6526547a61d 100644 (file)
@@ -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)
index 17401cad05287d961af326bb7a1c8b2ed97d33a8..4ba9f7b1848bb20a404000c58c57d49caec7ebbb 100644 (file)
 #ifndef _PARAMETRE_H_
 #define _PARAMETRE_H_
 
-#include "Batch_Defines.hxx"
-
 #include <map>
 #include <string>
+
+#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)
index d45850d7f0c9880bc3fe4f56398f91445deb7075..8aa64c07721b427d5135885c7463698a9958a5c3 100644 (file)
@@ -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
index b964aba9b41d31f12b52151daff1494f98adbf85..57ae7355b856e1ee454a76d359c3e31b33be8f78 100644 (file)
@@ -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;
 
index 6f6f0631239e6764597b4c11452caa1c429df11b..eb1800257b3f5bf260c20edbbcbf77c8558f14d1 100644 (file)
@@ -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;
index fd975fe3125b24f593ae4e16e54b91087e92883d..37ea02f6be554b8fa6d27a638ee0d4ba089fce00 100644 (file)
@@ -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 );
index 8e5dc12db36bf3fdfb72b3d13a0fa932ba5ecf31..ff2dc82c0b8b71c84701e4258ad1e34074f72641 100644 (file)
@@ -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<timeout*10 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != FINISHED && state != FAILED ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 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;
     }
index e8e20b8f66c27411e28c6599f06c94a8dacaac9c..b5ecc1a99f84f751c4a5ec07830c775a59e2e11c 100644 (file)
@@ -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<timeout*10 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != FINISHED && state != FAILED ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 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;
     }
index 212ac55c8e838b6371c315acbf50a104a6f543ca..638b9b9e422eacaa07709edb45ae711428d34340 100644 (file)
@@ -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<timeout*10 && state != "Done" ; i++) {
+    for (int i=0 ; i<timeout*10 && state != FINISHED && state != FAILED ; i++) {
       usleep(100000);
       Versatile paramState = jobid.queryJob().getParametre()["STATE"];
       state = (paramState.size() > 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;
     }
index 3a474fc6954aff3821671bb05fd919ead2a05f34..addf3c04a921342c672d23def901a6df00cee6ab 100644 (file)
@@ -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;
index 75768ea0147a784cfa5fea05667e9842f1162978..2ae7a065a7abc5cdf7bad4a32633ca94bc2eba88 100644 (file)
@@ -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();
   }
 
-
 }
index 698d68a39b918119b22e10b777ec02d2203974dc..033fc984ba734c28050d8fdbd50685be22f885bc 100644 (file)
@@ -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 &);
index 19441771cbb1f07952a8c9d2641199bc8f7a1ece..b770668c8826a49a9f4ca704b5f1f11a38b701f8 100644 (file)
@@ -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 (file)
index daafecb..0000000
+++ /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 <iostream>
-#include <fstream>
-
-#include <Batch_Job.hxx>
-#include <Batch_BatchManagerCatalog.hxx>
-#include <Batch_FactBatchManager.hxx>
-#include <Batch_FactBatchManager_eClient.hxx>
-#include <Batch_BatchManager.hxx>
-#include <Batch_BatchManager_eClient.hxx>
-
-#include <SimpleParser.hxx>
-
-#ifdef WIN32
-#include <Windows.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 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 ; i<timeout/2 && state != "U"; i++) {
-      sleep(2);
-      JobInfo jinfo = jobid.queryJob();
-      state = jinfo.getParametre()["STATE"].str();
-      cout << "State is \"" << state << "\"" << endl;
-    }
-
-    if (state == "U") {
-      cout << "Job " << jobid.__repr__() << " is done" << endl;
-      bm->importOutputFiles(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 (file)
index 42e98c3..0000000
+++ /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 <iostream>
-#include <fstream>
-
-#include <Batch_Job.hxx>
-#include <Batch_BatchManagerCatalog.hxx>
-#include <Batch_FactBatchManager.hxx>
-#include <Batch_FactBatchManager_eClient.hxx>
-#include <Batch_BatchManager.hxx>
-#include <Batch_BatchManager_eClient.hxx>
-
-#include <SimpleParser.hxx>
-
-#ifdef WIN32
-#include <Windows.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 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 ; i<timeout/2 && state != "U"; i++) {
-      sleep(2);
-      JobInfo jinfo = jobid.queryJob();
-      state = jinfo.getParametre()["STATE"].str();
-      cout << "State is \"" << state << "\"" << endl;
-    }
-
-    if (state == "U") {
-      cout << "Job " << jobid.__repr__() << " is done" << endl;
-      bm->importOutputFiles(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;
-}
index 4ea755c81f7cd92d94b758a4d58f2f3b9635c2de..b013b0b5b4c2ba9a288af4f42fc3a68bef6bd3d2 100644 (file)
@@ -71,7 +71,7 @@ def work():
     # Wait for the end of the job
     state = 'Unknown'
     i=0
-    while state != 'Done' and i<config.TEST_LOCAL_SH_TIMEOUT*10:
+    while state != FINISHED and state != FAILED and i<config.TEST_LOCAL_SH_TIMEOUT*10:
         time.sleep(0.1)
         i+=1
         jinfo = jobid.queryJob()
@@ -81,7 +81,7 @@ def work():
             pass
         print "State is", state
 
-    if state != "Done":
+    if state != FINISHED and state != FAILED:
         print "Error: Job not finished after timeout"
         return 1;
 
index 9dd95f94f3d03b9b1249443c0f2c01dd13f88f33..2029f5da1449fa8af53fba86b78dbe2aca9d6cbb 100644 (file)
@@ -46,6 +46,9 @@
 /* generate docstrings with types */
 %feature("autodoc", "1");
 
+/* Include std::string conversion */
+%include std_string.i
+
 /* Inclusion des conversions de type */
 %include libBatch_Swig_typemap.i
 
 %}
 
 /* Les classes exportees en Python */
+%ignore Batch::JobId::operator=;
+%ignore operator<<(std::ostream & os, const Job & job);
+%ignore operator<<(std::ostream & os, const JobInfo & ji);
+
 %include Batch_Defines.hxx
 %include Batch_Job.hxx
 %include Batch_JobId.hxx
@@ -73,6 +80,7 @@
 %include Batch_BatchManagerCatalog.hxx
 %include Batch_FactBatchManager.hxx
 
+%include Batch_Constants.hxx
 
 
 /* Les methodes alterJob (surchargees et mal gerees en Python) sont
index 6b2a011232214e715f9ee4d8560ff2f1d90bba25..6e62cfe3340e24935572caf5715e17649e811c0b 100644 (file)
@@ -210,38 +210,3 @@ typedef int Py_ssize_t;
   $1 = E;
 }
 
-
-
-# // construction d'une string Python a partir d'une string STL
-%typemap(python,out) std::string
-{
-       $result = PyString_FromString($1.c_str());
-}
-
-
-
-# // construction d'une string STL a partir d'une string Python
-#%typemap(in) string & (string S)
-#{
-##  if (!PyString_Check($input)) {
-#    PyErr_SetString(PyExc_ValueError,"Expected a string");
-#    return NULL;
-#  }
-#
-#  S = string(PyString_AsString($input));
-#      $1 = &S; // $1 est une reference donc on lui passe une adresse
-#}
-
-
-
-# // construction d'une string STL a partir d'une string Python
-#%typemap(in) string (string S)
-#{
-##  if (!PyString_Check($input)) {
-#    PyErr_SetString(PyExc_ValueError,"Expected a string");
-#    return NULL;
-#  }
-#
-#  S = string(PyString_AsString($input));
-#      $1 = S;
-#}
index f4414379dcc03e14a759c4a36046af265483dd9f..ecaa3dad26055c0510b874e1c7acd9c4fa39f8f9 100644 (file)
@@ -65,15 +65,34 @@ namespace Batch {
     if( sline.length() > 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