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];
}
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)
--- /dev/null
+// 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);
+
+}
--- /dev/null
+// 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
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)
#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 {
// 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
}
+// 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)
Core/Batch_CharType
Core/Batch_CommunicationProtocol
Core/Batch_ConnexionFailureException
+ Core/Batch_Constants
Core/Batch_Couple
Core/Batch_CoupleType
Core/Batch_Date
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;
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;
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
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 );
// @@@ --------> 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 );
// @@@ --------> 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 );
// @@@ --------> 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 );
// 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;
}
// 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;
}
// 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;
}
_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;
namespace Batch {
-
-
// Constructeurs
JobInfo_ePBS::JobInfo_ePBS(int id, string logFile) : JobInfo()
{
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') ){
};
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()
{
return sst.str();
}
-
}
{
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 &);
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;
}
cout << endl;
- if (state == "U" || state == "C") {
+ if (state == FINISHED || state == FAILED) {
cout << "Job " << jobid.__repr__() << " is done" << endl;
bm->importOutputFiles(job, ".");
} else {
+++ /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_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;
-}
+++ /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_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;
-}
# 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()
pass
print "State is", state
- if state != "Done":
+ if state != FINISHED and state != FAILED:
print "Error: Job not finished after timeout"
return 1;
/* 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
%include Batch_BatchManagerCatalog.hxx
%include Batch_FactBatchManager.hxx
+%include Batch_Constants.hxx
/* Les methodes alterJob (surchargees et mal gerees en Python) sont
$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;
-#}
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