Salome HOME
Add very simple log system BR_LIBBATCH_2_0
authorbarate <barate>
Mon, 28 Jan 2013 16:20:27 +0000 (16:20 +0000)
committerbarate <barate>
Mon, 28 Jan 2013 16:20:27 +0000 (16:20 +0000)
- Logs are no longer printed on stdout/stderr
- LOG macro writes a log message in file /tmp/libbatch-log-date-XXXXXX

19 files changed:
src/CCC/BatchManager_CCC.cxx
src/CCC/JobInfo_CCC.cxx
src/Core/BatchManager.cxx
src/Core/CMakeLists.txt
src/Core/CommunicationProtocol.cxx
src/Core/CommunicationProtocolRSH.cxx
src/Core/FactBatchManager.cxx
src/Core/Log.cxx [new file with mode: 0644]
src/Core/Log.hxx [new file with mode: 0644]
src/LSF/BatchManager_LSF.cxx
src/LSF/JobInfo_LSF.cxx
src/LoadLeveler/BatchManager_LL.cxx
src/Local/BatchManager_Local.cxx
src/PBS/BatchManager_PBS.cxx
src/PBS/JobInfo_PBS.cxx
src/SGE/BatchManager_SGE.cxx
src/SGE/JobInfo_SGE.cxx
src/Slurm/BatchManager_Slurm.cxx
src/Vishnu/BatchManager_Vishnu.cxx

index 715a51fc98ce6ab4124d9f4308a8b3435b57f4e0..e24c17174b7fdf569aba6aa201970578ae9f75fe 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "BatchManager_CCC.hxx"
 #include "JobInfo_CCC.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -82,24 +83,24 @@ namespace Batch {
     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
@@ -127,12 +128,12 @@ namespace Batch {
     // 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
@@ -145,7 +146,7 @@ namespace Batch {
     // 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);
@@ -256,7 +257,7 @@ namespace Batch {
     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",
@@ -275,7 +276,7 @@ namespace Batch {
     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);
index 947d36687385bd405cd00ba00f821f1ee2552ed0..510d9676e58beb80b51f41b593b1555f6d2b7164 100644 (file)
@@ -37,6 +37,7 @@
 #include "Parametre.hxx"
 #include "Environnement.hxx"
 #include "JobInfo_CCC.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -81,7 +82,7 @@ namespace Batch {
     } 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)
index c369f56c3965e81b8e9d7e2ef3766c09ed14a463..7ee7a56f2cc7c0bfeb093c8775a35a32ea2b2723 100644 (file)
@@ -40,6 +40,7 @@
 #include "BatchManager.hxx"
 #include "Utils.hxx"
 #include "NotYetImplementedException.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -148,9 +149,8 @@ namespace Batch {
     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);
@@ -161,9 +161,8 @@ namespace Batch {
         sleeptime = maxSleepTime;
       jinfo = jobid.queryJob();
       state = jinfo.getParametre()[STATE].str();
-      cout << "State is \"" << state << "\"";
     }
-    cout << endl;
+    LOG("State is \"" << state << "\"");
     return state;
   }
 
@@ -208,7 +207,7 @@ namespace Batch {
 
         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;
@@ -248,13 +247,8 @@ namespace Batch {
 
     // 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);
@@ -269,28 +263,15 @@ namespace Batch {
       }
       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 )
@@ -299,25 +280,14 @@ namespace Batch {
 
     // 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;
index 7acb3eabd8017b9a192c63b25dff7567a7b0eb41..0e5321400c56356beffafad9741ed9276661ec1e 100644 (file)
@@ -47,10 +47,11 @@ SET(CLASS_LIST Core/APIInternalFailureException
                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)
 
index b365bbac946c3c03edcc4a441bda64b887c63a28..371ba8dc362860f7d19d17bfe669f81bb9b02b34 100644 (file)
@@ -27,8 +27,6 @@
  */
 
 #include <stdlib.h>
-#include <iostream>
-#include <stdlib.h>
 
 #include <config.h>
 
@@ -44,6 +42,7 @@
 #endif
 #include "APIInternalFailureException.hxx"
 #include "RunTimeException.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -105,7 +104,7 @@ namespace Batch {
     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;
   }
@@ -125,7 +124,7 @@ namespace Batch {
                                         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;
   }
@@ -135,7 +134,7 @@ namespace Batch {
                                            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;
   }
index 59caf2d28789cab4b565557ea7e4b6e4ebcc2e55..7c69d1505c98a5d012bd79cf4251102fcfd428e9 100644 (file)
@@ -36,6 +36,7 @@
 #include <config.h>
 
 #include "CommunicationProtocolRSH.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -160,7 +161,7 @@ namespace Batch {
       newdir[0] = driveLetter;
       newdir[1] = ':';
       newdir[2] = '\0';
-      cout << "Changing directory: " << newdir << endl;
+      LOG("Changing directory: " << newdir);
       _chdir(newdir);
     }
 
@@ -169,7 +170,7 @@ namespace Batch {
 
     // Go back to previous directory if necessary
     if (driveLetter != '\0' && driveLetter != currentDrive) {
-      cout << "Changing directory: " << cwd << endl;
+      LOG("Changing directory: " << cwd);
       _chdir(cwd);
     }
 
index e286e5b6ae1bb9c2eace5242f3005b7bbbe2e01f..dae5f124f91803e51996f33dfb7a84c3ab521623 100644 (file)
@@ -41,12 +41,6 @@ namespace Batch {
   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
diff --git a/src/Core/Log.cxx b/src/Core/Log.cxx
new file mode 100644 (file)
index 0000000..7d4f359
--- /dev/null
@@ -0,0 +1,66 @@
+//  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;
+  }
+
+}
diff --git a/src/Core/Log.hxx b/src/Core/Log.hxx
new file mode 100644 (file)
index 0000000..6647d95
--- /dev/null
@@ -0,0 +1,65 @@
+//  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
index e9388fa05e157dee61c18b049885ab6edc8705ca..a1b0dafbe9ec6350f55cb9dbda81274097640806 100644 (file)
@@ -38,6 +38,7 @@
 #include <NotYetImplementedException.hxx>
 #include "BatchManager_LSF.hxx"
 #include "JobInfo_LSF.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -64,23 +65,23 @@ namespace Batch {
     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
@@ -103,12 +104,12 @@ namespace Batch {
     // 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
@@ -121,7 +122,7 @@ namespace Batch {
     // 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);
@@ -251,7 +252,7 @@ namespace Batch {
     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, "", "",
@@ -284,7 +285,7 @@ namespace Batch {
 
     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");
index c9e6bb10dd988af266c7dec7a7c2c1e1f9bc8c1f..2413b48853bfd2fb79ba24595a19be2c67acc92e 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <Constants.hxx>
 #include "JobInfo_LSF.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -82,7 +83,7 @@ namespace Batch {
       } 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)
index c5fe1b204a840aee3975bb8a401956603ddf592b..f62871ebcdf109ede5bccf3d6549144933abc5ee 100644 (file)
@@ -37,6 +37,7 @@
 #include "FactBatchManager_LL.hxx"
 #include "BatchManager_LL.hxx"
 #include "JobInfo_LL.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -70,12 +71,12 @@ namespace Batch {
     // 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
@@ -199,7 +200,7 @@ namespace Batch {
     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, "", "",
@@ -216,13 +217,13 @@ namespace Batch {
     // 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)
@@ -230,7 +231,7 @@ namespace Batch {
     // 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)
index e47a42a609ab8def2c87c053ce4d8fec6ae7dbbe..6d1ae1a81bfc51a910752990eaa20b6eb53e398c 100644 (file)
@@ -56,6 +56,7 @@
 #include "BatchManager_Local.hxx"
 #include "RunTimeException.hxx"
 #include "Utils.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -80,8 +81,8 @@ namespace Batch {
       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);
       }
@@ -147,8 +148,7 @@ namespace Batch {
         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);
@@ -165,7 +165,7 @@ namespace Batch {
     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 <-------- @@@
@@ -183,7 +183,7 @@ namespace Batch {
     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 <-------- @@@
@@ -377,7 +377,7 @@ namespace Batch {
     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, "", "",
@@ -391,7 +391,7 @@ namespace Batch {
       // 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;
@@ -452,7 +452,7 @@ namespace Batch {
 #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);
@@ -481,7 +481,7 @@ namespace Batch {
     // 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;
   }
@@ -524,22 +524,22 @@ namespace Batch {
       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
@@ -553,12 +553,12 @@ namespace Batch {
           _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;
         }
       }
@@ -569,7 +569,7 @@ namespace Batch {
         _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
@@ -590,7 +590,7 @@ namespace Batch {
         //            << "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);
@@ -601,7 +601,7 @@ namespace Batch {
 
 
         } 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);
@@ -624,26 +624,26 @@ namespace Batch {
 
           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
@@ -696,7 +696,7 @@ namespace Batch {
         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
@@ -710,7 +710,7 @@ namespace Batch {
 
       // 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
@@ -719,7 +719,7 @@ namespace Batch {
 
     } catch (GenericException & e) {
 
-      std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+      LOG("Caught exception : " << e.type << " : " << e.message);
     }
 
     exit(99);
@@ -748,7 +748,7 @@ namespace Batch {
         comstr += command[i];
       }
 
-      UNDER_LOCK( cout << "*** debug_command = " << comstr << endl );
+      UNDER_LOCK( LOG("*** debug_command = " << comstr) );
 
       STARTUPINFO si;
       ZeroMemory( &si, sizeof(si) );
@@ -769,7 +769,7 @@ namespace Batch {
 
     } catch (GenericException & e) {
 
-      std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+      LOG("Caught exception : " << e.type << " : " << e.message);
     }
 
     return pi.hProcess;
index 7dfd666d8dac6ccc7893af6a43c03f8b955b8c78..ae18c2329b96edb8d68cb64f7d415cee952ee24b 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "BatchManager_PBS.hxx"
 #include "JobInfo_PBS.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -74,12 +75,12 @@ namespace Batch {
     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
@@ -100,12 +101,12 @@ namespace Batch {
     // 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
@@ -118,7 +119,7 @@ namespace Batch {
     // 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);
@@ -239,7 +240,7 @@ namespace Batch {
     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, "", "",
index 514e2589fe16cfe16a221f4a034ce7339026643e..179b2c378c60532eff69b384e77add5f013e6ec5 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <Constants.hxx>
 #include "JobInfo_PBS.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -80,7 +81,7 @@ namespace Batch {
       } 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,
index 72d8b3cd644f8baa1aadcc02fd4f57bf6f8f44cb..ac4bea76747fb68561005c447fed3d63af8bcb49 100644 (file)
@@ -51,6 +51,7 @@
 
 #include "BatchManager_SGE.hxx"
 #include "JobInfo_SGE.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -90,12 +91,12 @@ namespace Batch {
     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
@@ -119,12 +120,12 @@ namespace Batch {
     // 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
@@ -137,7 +138,7 @@ namespace Batch {
     // 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);
@@ -158,7 +159,7 @@ namespace Batch {
   {
 #ifndef WIN32
     //TODO porting on Win32 platform
-    std::cerr << "BuildBatchScript" << std::endl;
+    LOG("BuildBatchScript");
     Parametre params = job.getParametre();
 
     // Job Parameters
@@ -219,7 +220,7 @@ namespace Batch {
     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",
index 2f14ac43c550ab02f60dd0a314c35f8f6ecad07a..db8e1a13388cd466018cef5b994f5a5b5c754591 100644 (file)
@@ -39,6 +39,7 @@
 #include "RunTimeException.hxx"
 #include "APIInternalFailureException.hxx"
 #include "JobInfo_SGE.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -88,7 +89,7 @@ namespace Batch {
       } 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.
index dfce7cd0063d0b41e20d8c4b4f4235a1ef2c5a86..13cb2a62405d0a39f3331370882e2910af226e7f 100644 (file)
@@ -32,6 +32,7 @@
 #include <NotYetImplementedException.hxx>
 #include <Constants.hxx>
 #include <Utils.hxx>
+#include <Log.hxx>
 
 #include "BatchManager_Slurm.hxx"
 #include "JobInfo_Slurm.hxx"
@@ -69,12 +70,12 @@ namespace Batch {
     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
@@ -180,7 +181,7 @@ namespace Batch {
     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, "", "",
@@ -197,13 +198,13 @@ namespace Batch {
     // 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)
@@ -211,7 +212,7 @@ namespace Batch {
     // 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
index 291f0961787a6462b9649ba9b21ad2ec64a0059d..4b7fe000129791e26c31639e03b77010026bb900 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "BatchManager_Vishnu.hxx"
 #include "JobInfo_Vishnu.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -83,12 +84,12 @@ namespace Batch {
     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
@@ -152,10 +153,10 @@ namespace Batch {
     // 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);
   }
@@ -237,7 +238,7 @@ namespace Batch {
     tempOutputFile.flush();
     tempOutputFile.close();
 
-    cerr << "Batch script file generated is: " << tmpFileName << endl;
+    LOG("Batch script file generated is: " << tmpFileName);
     return tmpFileName;
   }
 
@@ -249,13 +250,13 @@ namespace Batch {
     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)
@@ -266,7 +267,7 @@ namespace Batch {
     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);
@@ -317,10 +318,10 @@ namespace Batch {
     // 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);
   }