#include "BatchManager_CCC.hxx"
#include "JobInfo_CCC.hxx"
+#include "Log.hxx"
using namespace std;
std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
// export input files on cluster
- cerr << "Export des fichiers en entree" << endl;
+ LOG("Export des fichiers en entree");
exportInputFiles(job);
// build batch script for job
- cerr << "Construction du script de batch" << endl;
+ LOG("Construction du script de batch");
buildBatchScript(job);
- cerr << "Script envoye" << endl;
+ LOG("Script envoye");
// define command to submit batch
string subCommand = string("bash -l -c \\\"cd ") + workDir + "; ccc_msub " + fileNameToExecute + "_Batch.sh\\\"";
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// find id of submitted job in output
// define command to delete batch
string subCommand = string("bash -l -c \\\"ccc_mdel ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status)
throw RunTimeException("Error of connection on remote host");
- cerr << "jobId = " << ref << "killed" << endl;
+ LOG("jobId = " << ref << "killed");
}
// Methode pour le controle des jobs : renvoie l'etat du job
// define command to query batch
string subCommand = string("bash -l -c \\\"bjobs ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
tempOutputFile.close();
Utils::chmod(TmpFileName.c_str(), 0x1ED);
- cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ LOG("Batch script file generated is: " << TmpFileName.c_str());
int status = _protocol.copyFile(TmpFileName, "", "",
workDir + "/" + rootNameToExecute + "_Batch.sh",
string subCommand = string("echo ");
subCommand += tmpdir;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
#include "Parametre.hxx"
#include "Environnement.hxx"
#include "JobInfo_CCC.hxx"
+#include "Log.hxx"
using namespace std;
} else if (status == "ZOMBI") { // Zombie
_param[STATE] = FAILED;
} else {
- cerr << "Unknown job state code: " << status << endl;
+ LOG("Unknown job state code: " << status);
}
if( status.find("RUN") != string::npos)
#include "BatchManager.hxx"
#include "Utils.hxx"
#include "NotYetImplementedException.hxx"
+#include "Log.hxx"
using namespace std;
bool timeoutReached = (testTimeout && time >= timeout);
JobInfo jinfo = jobid.queryJob();
string state = jinfo.getParametre()[STATE].str();
- cout << "State is \"" << state << "\"";
while (!timeoutReached && state != FINISHED && state != FAILED) {
- cout << ", sleeping " << sleeptime << "s..." << endl;
+ LOG("State is \"" << state << "\"" << ", sleeping " << sleeptime << "s...");
Utils::sleep(sleeptime);
time += sleeptime;
timeoutReached = (testTimeout && time >= timeout);
sleeptime = maxSleepTime;
jinfo = jobid.queryJob();
state = jinfo.getParametre()[STATE].str();
- cout << "State is \"" << state << "\"";
}
- cout << endl;
+ LOG("State is \"" << state << "\"");
return state;
}
string subCommand = string("chmod u+x ") + remoteExec;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status) {
std::ostringstream oss;
// Create local result directory
int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
- if (status) {
- string mess("Directory creation failed. Status is :");
- ostringstream status_str;
- status_str << status;
- mess += status_str.str();
- cerr << mess << endl;
- }
+ if (status)
+ LOG("Directory creation failed. Status is: " << status);
for(Vit=V.begin(); Vit!=V.end(); Vit++) {
CoupleType cpt = *static_cast< CoupleType * >(*Vit);
}
status = _protocol.copyFile(remotePath, _hostname, _username,
localPath, "", "");
- if (status) {
- // Try to get what we can (logs files)
- // throw BatchException("Error of connection on remote host");
- std::string mess("Copy command failed ! status is :");
- ostringstream status_str;
- status_str << status;
- mess += status_str.str();
- cerr << mess << endl;
- }
+ if (status)
+ LOG("Copy command failed. Status is: " << status);
}
// Copy logs
status = _protocol.copyFile(string(params[WORKDIR]) + string("/logs"), _hostname, _username,
directory, "", "");
- if (status) {
- std::string mess("Copy logs directory failed ! status is :");
- ostringstream status_str;
- status_str << status;
- mess += status_str.str();
- cerr << mess << endl;
- }
-
+ if (status)
+ LOG("Copy logs directory failed. Status is: " << status);
}
bool BatchManager::importDumpStateFile( const Job & job, const string directory )
// Create local result directory
int status = CommunicationProtocol::getInstance(SH).makeDirectory(directory, "", "");
- if (status) {
- string mess("Directory creation failed. Status is :");
- ostringstream status_str;
- status_str << status;
- mess += status_str.str();
- cerr << mess << endl;
- }
+ if (status)
+ LOG("Directory creation failed. Status is: " << status);
bool ret = true;
status = _protocol.copyFile(string(params[WORKDIR]) + string("/dumpState*.xml"), _hostname, _username,
directory, "", "");
if (status) {
- // Try to get what we can (logs files)
- // throw BatchException("Error of connection on remote host");
- std::string mess("Copy command failed ! status is :");
- ostringstream status_str;
- status_str << status;
- mess += status_str.str();
- cerr << mess << endl;
+ LOG("Copy command failed. Status is: " << status);
ret = false;
}
return ret;
Core/StringType
Core/TypeMismatchException
Core/Versatile
- Core/Utils
)
-APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST})
+APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}
+ Core/Utils
+ Core/Log)
APPEND_CLASSES_TO_HDR_FILES(${CLASS_LIST})
APPEND_CLASSES_TO_HDR_FILES(Core/Defines)
*/
#include <stdlib.h>
-#include <iostream>
-#include <stdlib.h>
#include <config.h>
#endif
#include "APIInternalFailureException.hxx"
#include "RunTimeException.hxx"
+#include "Log.hxx"
using namespace std;
string command = commandStringFromArgs(getCopyCommandArgs(sourcePath, sourceHost, sourceUser,
destinationPath, destinationHost,
destinationUser));
- cout << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
return status;
}
const std::string & user) const
{
string command = getExecCommand(getRemoveSubCommand(path), host, user);
- cout << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
return status;
}
const std::string & user) const
{
string command = getExecCommand(getMakeDirectorySubCommand(path), host, user);
- cout << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
return status;
}
#include <config.h>
#include "CommunicationProtocolRSH.hxx"
+#include "Log.hxx"
using namespace std;
newdir[0] = driveLetter;
newdir[1] = ':';
newdir[2] = '\0';
- cout << "Changing directory: " << newdir << endl;
+ LOG("Changing directory: " << newdir);
_chdir(newdir);
}
// Go back to previous directory if necessary
if (driveLetter != '\0' && driveLetter != currentDrive) {
- cout << "Changing directory: " << cwd << endl;
+ LOG("Changing directory: " << cwd);
_chdir(cwd);
}
FactBatchManager::FactBatchManager(const string & _t) : type(_t)
{
BatchManagerCatalog::getInstance().addFactBatchManager(type.c_str(), this);
-
- /*
- ostringstream msg;
- msg << "FactBatchManager of type '" << type << "' inserted into catalog";
- cerr << msg.str().c_str() << endl;
- */
}
// Destructeur
--- /dev/null
+// Copyright (C) 2007-2012 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
+//
+/*
+ * Log.cxx :
+ *
+ * Created on: 28 jan. 2013
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#include "Utils.hxx"
+#include "Log.hxx"
+
+using namespace std;
+
+namespace Batch {
+
+ Log::Log()
+ {
+ const size_t BUFSIZE = 32;
+ char date[BUFSIZE];
+ time_t curtime = time(NULL);
+ strftime(date, BUFSIZE, "%Y-%m-%d_%H-%M-%S", localtime(&curtime));
+ string prefix = string("log-") + date;
+ Utils::createAndOpenTemporaryFile(prefix, _stream);
+ }
+
+ Log::~Log()
+ {
+ _stream.close();
+ }
+
+ void Log::log(const string & msg)
+ {
+ const size_t BUFSIZE = 32;
+ char timestamp[BUFSIZE];
+ time_t curtime = time(NULL);
+ strftime(timestamp, BUFSIZE, "%Y-%m-%d_%H-%M-%S", localtime(&curtime));
+ getInstance()._stream << timestamp << ": " << msg << endl;
+ }
+
+ Log & Log::getInstance()
+ {
+ static Log instance;
+ return instance;
+ }
+
+}
--- /dev/null
+// Copyright (C) 2007-2012 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
+//
+/*
+ * Log.hxx :
+ *
+ * Created on: 28 jan. 2013
+ * Author : Renaud BARATE - EDF R&D
+ */
+
+#ifndef _LOG_H_
+#define _LOG_H_
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#include "Defines.hxx"
+
+#define LOG(msg) {std::ostringstream sstream; sstream << msg; Log::log(sstream.str());}
+
+namespace Batch {
+
+ class BATCH_EXPORT Log
+ {
+ public:
+ virtual ~Log();
+
+ static void log(const std::string & msg);
+
+ private:
+
+ Log();
+
+ static Log & getInstance();
+
+ // Forbid the use of copy constructor and assignment operator
+ Log(const Log & orig) {}
+ void operator=(const Log & orig) {}
+
+ std::ofstream _stream;
+
+ };
+
+}
+
+#endif
#include <NotYetImplementedException.hxx>
#include "BatchManager_LSF.hxx"
#include "JobInfo_LSF.hxx"
+#include "Log.hxx"
using namespace std;
const std::string workDir = params[WORKDIR];
// export input files on cluster
- cerr << "Export des fichiers en entree" << endl;
+ LOG("Export des fichiers en entree");
exportInputFiles(job);
// build batch script for job
- cerr << "Construction du script de batch" << endl;
+ LOG("Construction du script de batch");
string scriptFile = buildSubmissionScript(job);
- cerr << "Script envoye" << endl;
+ LOG("Script envoye");
// define command to submit batch
string subCommand = string("cd ") + workDir + "; bsub < " + scriptFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// read id of submitted job in output
// define command to delete batch
string subCommand = string("bkill ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status)
throw RunTimeException("Error of connection on remote host");
- cerr << "jobId = " << ref << "killed" << endl;
+ LOG("jobId = " << ref << "killed");
}
// Methode pour le controle des jobs : renvoie l'etat du job
// define command to query batch
string subCommand = string("bjobs ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ LOG("Batch script file generated is: " << TmpFileName.c_str());
string remoteFileName = rootNameToExecute + "_Batch.sh";
int status = _protocol.copyFile(TmpFileName, "", "",
string subCommand = string("echo $HOME");
string command = _protocol.getExecCommand(subCommand, _hostname, _username) + " > " + filelogtemp;
- cerr << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
if (status)
throw RunTimeException("Error of launching home command on remote host");
#include <Constants.hxx>
#include "JobInfo_LSF.hxx"
+#include "Log.hxx"
using namespace std;
} else if (status == "ZOMBI") { // Zombie
_param[STATE] = FAILED;
} else {
- cerr << "Unknown job state code: " << status << endl;
+ LOG("Unknown job state code: " << status);
}
if( status.find("RUN") != string::npos)
#include "FactBatchManager_LL.hxx"
#include "BatchManager_LL.hxx"
#include "JobInfo_LL.hxx"
+#include "Log.hxx"
using namespace std;
// define command to submit batch
string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// find id of submitted job in output
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << tmpFileName << endl;
+ LOG("Batch script file generated is: " << tmpFileName);
string remoteFileName = rootNameToExecute + "_LL.cmd";
int status = _protocol.copyFile(tmpFileName, "", "",
// define command to delete job
string subCommand = "llcancel " + jobid.getReference();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
if (status)
throw RunTimeException("Can't delete job " + jobid.getReference());
- cerr << "job " << jobid.getReference() << " killed" << endl;
+ LOG("job " << jobid.getReference() << " killed");
}
JobInfo BatchManager_LL::queryJob(const JobId & jobid)
// define command to query batch
string subCommand = "llq -f %st " + jobid.getReference();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
if (status != 0)
#include "BatchManager_Local.hxx"
#include "RunTimeException.hxx"
#include "Utils.hxx"
+#include "Log.hxx"
using namespace std;
pthread_mutex_lock(&_threads_mutex);
string state = iter->second.param[STATE];
if (state != FINISHED && state != FAILED) {
- UNDER_LOCK( cout << "Warning: Job " << iter->first <<
- " is not finished, it will now be canceled." << endl );
+ UNDER_LOCK( LOG("Warning: Job " << iter->first <<
+ " is not finished, it will now be canceled."));
pthread_cancel(iter->second.thread_id);
pthread_cond_wait(&_threadSyncCondition, &_threads_mutex);
}
pthread_cancel(_threads[id].thread_id);
pthread_cond_wait(&_threadSyncCondition, &_threads_mutex);
} else {
- cout << "Cannot delete job " << jobid.getReference() <<
- ". Job is already finished." << endl;
+ LOG("Cannot delete job " << jobid.getReference() << ". Job is already finished.");
}
}
pthread_mutex_unlock(&_threads_mutex);
istringstream iss(jobid.getReference());
iss >> id;
- UNDER_LOCK( cout << "BatchManager is sending HOLD command to the thread " << id << endl );
+ UNDER_LOCK( LOG("BatchManager is sending HOLD command to the thread " << id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
istringstream iss(jobid.getReference());
iss >> id;
- UNDER_LOCK( cout << "BatchManager is sending RELEASE command to the thread " << id << endl );
+ UNDER_LOCK( LOG("BatchManager is sending RELEASE command to the thread " << id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << tmpFileName << endl;
+ LOG("Batch script file generated is: " << tmpFileName);
Utils::chmod(tmpFileName.c_str(), 0x1ED);
int status = _bm._protocol.copyFile(tmpFileName, "", "",
// pscp does not preserve access permissions on files
string subCommand = string("chmod u+x ") + remotePath;
string command = _bm._protocol.getExecCommand(subCommand, _bm._hostname, _bm._username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status) {
std::ostringstream oss;
#else
child = fork();
if (child < 0) { // erreur
- UNDER_LOCK( cerr << "Fork impossible (rc=" << child << ")" << endl );
+ UNDER_LOCK( LOG("Fork impossible (rc=" << child << ")") );
} else if (child > 0) { // pere
p_ta->pere(child);
// On invoque la fonction de nettoyage de la memoire
delete_on_exit(arg);
- UNDER_LOCK( cout << "Father is leaving" << endl );
+ UNDER_LOCK( LOG("Father is leaving") );
pthread_exit(NULL);
return NULL;
}
DWORD exitCode;
GetExitCodeProcess(child, &exitCode);
if (exitCode != STILL_ACTIVE) {
- UNDER_LOCK( cout << "Father sees his child is DONE: exit code = " << exitCode << endl );
+ UNDER_LOCK( LOG("Father sees his child is DONE: exit code = " << exitCode) );
break;
}
#else
int child_rc = 0;
pid_t child_wait_rc = waitpid(child, &child_rc, WNOHANG /* | WUNTRACED */);
if (child_wait_rc > 0) {
- UNDER_LOCK( cout << "Status is: " << WIFEXITED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WEXITSTATUS( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WIFSIGNALED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WTERMSIG( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WCOREDUMP( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WIFSTOPPED( child_rc) << endl);
- UNDER_LOCK( cout << "Status is: " << WSTOPSIG( child_rc) << endl);
+ UNDER_LOCK( LOG("Status is: " << WIFEXITED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WEXITSTATUS( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WIFSIGNALED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WTERMSIG( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WCOREDUMP( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WIFSTOPPED( child_rc)) );
+ UNDER_LOCK( LOG("Status is: " << WSTOPSIG( child_rc)) );
#ifdef WIFCONTINUED
- UNDER_LOCK( cout << "Status is: " << WIFCONTINUED( child_rc) << endl); // not compilable on sarge
+ UNDER_LOCK( LOG("Status is: " << WIFCONTINUED( child_rc)) ); // not compilable on sarge
#endif
if (WIFSTOPPED(child_rc)) {
// NOTA : pour rentrer dans cette section, il faut que le flag WUNTRACED
_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 );
+ UNDER_LOCK( LOG("Father sees his child is STOPPED : " << child_wait_rc) );
}
else {
// Le fils est termine, on sort de la boucle et du if englobant
- UNDER_LOCK( cout << "Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")" << endl );
+ UNDER_LOCK( LOG("Father sees his child is DONE : " << child_wait_rc << " (child_rc=" << (WIFEXITED(child_rc) ? WEXITSTATUS(child_rc) : -1) << ")") );
break;
}
}
_bm._threads[_id].hasFailed = true;
pthread_mutex_unlock(&_bm._threads_mutex);
// @@@ --------> SECTION CRITIQUE <-------- @@@
- UNDER_LOCK( cout << "Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")" << endl );
+ UNDER_LOCK( LOG("Father sees his child is DEAD : " << child_wait_rc << " (Reason : " << strerror(errno) << ")") );
break;
}
#endif
// << "maxwalltime = " << maxwalltime << endl
// << "int(maxwalltime * 1.1) = " << int(maxwalltime * 1.1) << endl;
if (child_elapsedtime_minutes > long((float)maxwalltime * 1.1) ) { // On se donne 10% de marge avant le KILL
- UNDER_LOCK( cout << "Father is sending KILL command to the thread " << _id << endl );
+ UNDER_LOCK( LOG("Father is sending KILL command to the thread " << _id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
pthread_mutex_lock(&_bm._threads_mutex);
} else if (child_elapsedtime_minutes > maxwalltime ) {
- UNDER_LOCK( cout << "Father is sending TERM command to the thread " << _id << endl );
+ UNDER_LOCK( LOG("Father is sending TERM command to the thread " << _id) );
// On introduit une commande dans la queue du thread
// @@@ --------> SECTION CRITIQUE <-------- @@@
pthread_mutex_lock(&_bm._threads_mutex);
switch (cmd) {
case NOP:
- UNDER_LOCK( cout << "Father does nothing to his child" << endl );
+ UNDER_LOCK( LOG("Father does nothing to his child") );
break;
#ifndef WIN32
case HOLD:
- UNDER_LOCK( cout << "Father is sending SIGSTOP signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGSTOP signal to his child") );
kill(child, SIGSTOP);
break;
case RELEASE:
- UNDER_LOCK( cout << "Father is sending SIGCONT signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGCONT signal to his child") );
kill(child, SIGCONT);
break;
case TERM:
- UNDER_LOCK( cout << "Father is sending SIGTERM signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGTERM signal to his child") );
kill(child, SIGTERM);
break;
case KILL:
- UNDER_LOCK( cout << "Father is sending SIGKILL signal to his child" << endl );
+ UNDER_LOCK( LOG("Father is sending SIGKILL signal to his child") );
kill(child, SIGKILL);
break;
#endif
comstr += command[i] + " ";
}
argv[command.size()] = NULL;
- UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << comstr) );
// On cree une session pour le fils de facon a ce qu'il ne soit pas
// detruit lorsque le shell se termine (le shell ouvre une session et
// On execute la commande du fils
execv(argv[0], argv);
- UNDER_LOCK( cout << "*** debug_command = " << strerror(errno) << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << strerror(errno)) );
// No need to deallocate since nothing happens after a successful exec
// Normalement on ne devrait jamais arriver ici
} catch (GenericException & e) {
- std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+ LOG("Caught exception : " << e.type << " : " << e.message);
}
exit(99);
comstr += command[i];
}
- UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
+ UNDER_LOCK( LOG("*** debug_command = " << comstr) );
STARTUPINFO si;
ZeroMemory( &si, sizeof(si) );
} catch (GenericException & e) {
- std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+ LOG("Caught exception : " << e.type << " : " << e.message);
}
return pi.hProcess;
#include "BatchManager_PBS.hxx"
#include "JobInfo_PBS.hxx"
+#include "Log.hxx"
using namespace std;
string subCommand = string("cd ") + workDir + "; qsub " + scriptFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// normally output contains only id of submitted job, we just need to remove the final \n
// define command to delete batch
string subCommand = string("qdel ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if (status)
throw RunTimeException("Error of connection on remote host");
- cerr << "jobId = " << ref << "killed" << endl;
+ LOG("jobId = " << ref << "killed");
}
// Methode pour le controle des jobs : renvoie l'etat du job
// define command to query batch
string subCommand = string("qstat -f ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ LOG("Batch script file generated is: " << TmpFileName.c_str());
string remoteFileName = rootNameToExecute + "_Batch.sh";
int status = _protocol.copyFile(TmpFileName, "", "",
#include <Constants.hxx>
#include "JobInfo_PBS.hxx"
+#include "Log.hxx"
using namespace std;
} else if (status == "W") { // Waiting
_param[STATE] = PAUSED;
} else {
- cerr << "Unknown job state code: " << status << endl;
+ LOG("Unknown job state code: " << status);
}
} else {
// On some batch managers, the job is deleted as soon as it is finished,
#include "BatchManager_SGE.hxx"
#include "JobInfo_SGE.hxx"
+#include "Log.hxx"
using namespace std;
string subCommand = string("bash -l -c \\\"cd ") + workDir + "; qsub " + fileNameToExecute + "_Batch.sh\\\"";
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// find id of submitted job in output
// define command to delete batch
string subCommand = string("bash -l -c \\\"qdel ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
status = system(command.c_str());
if(status)
throw RunTimeException("Error of connection on remote host");
- cerr << "jobId = " << ref << "killed" << endl;
+ LOG("jobId = " << ref << "killed");
}
// Methode pour le controle des jobs : renvoie l'etat du job
// define command to query batch
string subCommand = string("bash -l -c \\\"qstat | grep ") + iss.str() + string("\\\"");
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
{
#ifndef WIN32
//TODO porting on Win32 platform
- std::cerr << "BuildBatchScript" << std::endl;
+ LOG("BuildBatchScript");
Parametre params = job.getParametre();
// Job Parameters
tempOutputFile.close();
Utils::chmod(TmpFileName.c_str(), 0x1ED);
- cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ LOG("Batch script file generated is: " << TmpFileName.c_str());
int status = _protocol.copyFile(TmpFileName, "", "",
workDir + "/" + rootNameToExecute + "_Batch.sh",
#include "RunTimeException.hxx"
#include "APIInternalFailureException.hxx"
#include "JobInfo_SGE.hxx"
+#include "Log.hxx"
using namespace std;
} else if (status == "h") { // Hold
_param[STATE] = PAUSED;
} else {
- cerr << "Unknown job state code: " << status << endl;
+ LOG("Unknown job state code: " << status);
}
} else {
// TODO: Check this. I suppose that unknown jobs are finished ones.
#include <NotYetImplementedException.hxx>
#include <Constants.hxx>
#include <Utils.hxx>
+#include <Log.hxx>
#include "BatchManager_Slurm.hxx"
#include "JobInfo_Slurm.hxx"
string subCommand = string("cd ") + workDir + "; sbatch " + cmdFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cout << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// find id of submitted job in output
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << tmpFileName << endl;
+ LOG("Batch script file generated is: " << tmpFileName);
string remoteFileName = rootNameToExecute + "_slurm.cmd";
int status = _protocol.copyFile(tmpFileName, "", "",
// define command to delete job
string subCommand = "scancel " + jobid.getReference();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
if (status)
throw RunTimeException("Can't delete job " + jobid.getReference());
- cerr << "job " << jobid.getReference() << " killed" << endl;
+ LOG("job " << jobid.getReference() << " killed");
}
JobInfo BatchManager_Slurm::queryJob(const JobId & jobid)
// define command to query batch
string subCommand = "squeue -o %t -j " + jobid.getReference();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
Utils::getCommandOutput(command, output);
// We don't test the return code here because with jobs finished since a long time Slurm
#include "BatchManager_Vishnu.hxx"
#include "JobInfo_Vishnu.hxx"
+#include "Log.hxx"
using namespace std;
subCommand += "vishnu_close";
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
// submit job
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0) throw RunTimeException("Can't submit job, error was: " + output);
// find id of submitted job in output
// Execute command
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0)
throw RunTimeException("Can't copy input files, error was: " + output);
}
tempOutputFile.flush();
tempOutputFile.close();
- cerr << "Batch script file generated is: " << tmpFileName << endl;
+ LOG("Batch script file generated is: " << tmpFileName);
return tmpFileName;
}
subCommand += "vishnu_cancel_job " + _hostname + " " + jobid.getReference() + " && ";
subCommand += "vishnu_close";
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
int status = system(command.c_str());
if (status)
throw RunTimeException("Can't delete job " + jobid.getReference());
- cerr << "job " << jobid.getReference() << " killed" << endl;
+ LOG("job " << jobid.getReference() << " killed");
}
JobInfo BatchManager_Vishnu::queryJob(const JobId & jobid)
subCommand += "vishnu_get_job_info " + _hostname + " " + jobid.getReference() + " && ";
subCommand += "vishnu_close";
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
int status = Utils::getCommandOutput(command, output);
// Execute command
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " 2>&1";
- cerr << command.c_str() << endl;
+ LOG(command);
string output;
status = Utils::getCommandOutput(command, output);
- cout << output;
+ LOG(output);
if (status != 0)
throw RunTimeException("Can't import output files, error was: " + output);
}