Salome HOME
Add very simple log system
[tools/libbatch.git] / src / Vishnu / BatchManager_Vishnu.cxx
index f9069b1cd4eaec20ba73aaee87c0e70899c9ae50..4b7fe000129791e26c31639e03b77010026bb900 100644 (file)
 #include <fstream>
 #include <sstream>
 
-#include <NotYetImplementedException.hxx>
 #include <Constants.hxx>
 #include <Utils.hxx>
 
 #include "BatchManager_Vishnu.hxx"
 #include "JobInfo_Vishnu.hxx"
+#include "Log.hxx"
 
 using namespace std;
 
@@ -84,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
@@ -153,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);
   }
@@ -224,12 +224,21 @@ namespace Batch {
 
     // Launch the executable
     tempOutputFile << "cd " << workDir << endl;
-    tempOutputFile << "./" + fileNameToExecute << endl;
+    tempOutputFile << "./" + fileNameToExecute;
+    if (params.find(ARGUMENTS) != params.end()) {
+      Versatile V = params[ARGUMENTS];
+      for(Versatile::const_iterator it=V.begin(); it!=V.end(); it++) {
+        StringType argt = * static_cast<StringType *>(*it);
+        string     arg  = argt;
+        tempOutputFile << " " << arg;
+      }
+    }
+    tempOutputFile << endl;
 
     tempOutputFile.flush();
     tempOutputFile.close();
 
-    cerr << "Batch script file generated is: " << tmpFileName << endl;
+    LOG("Batch script file generated is: " << tmpFileName);
     return tmpFileName;
   }
 
@@ -241,38 +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;
-  }
-
-  void BatchManager_Vishnu::holdJob(const JobId & jobid)
-  {
-    throw NotYetImplementedException("BatchManager_Vishnu::holdJob");
-  }
-
-  void BatchManager_Vishnu::releaseJob(const JobId & jobid)
-  {
-    throw NotYetImplementedException("BatchManager_Vishnu::releaseJob");
-  }
-
-  void BatchManager_Vishnu::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
-  {
-    throw NotYetImplementedException("BatchManager_Vishnu::alterJob");
-  }
-
-  void BatchManager_Vishnu::alterJob(const JobId & jobid, const Parametre & param)
-  {
-    throw NotYetImplementedException("BatchManager_Vishnu::alterJob");
-  }
-
-  void BatchManager_Vishnu::alterJob(const JobId & jobid, const Environnement & env)
-  {
-    throw NotYetImplementedException("BatchManager_Vishnu::alterJob");
+    LOG("job " << jobid.getReference() << " killed");
   }
 
   JobInfo BatchManager_Vishnu::queryJob(const JobId & jobid)
@@ -283,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);
@@ -293,11 +277,6 @@ namespace Batch {
     return jobinfo;
   }
 
-  const JobId BatchManager_Vishnu::addJob(const Job & job, const string reference)
-  {
-    return JobId(this, reference);
-  }
-
   void BatchManager_Vishnu::importOutputFiles(const Job & job, const std::string directory)
   {
     // Create local result directory
@@ -339,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);
   }