Salome HOME
Avoid use of temporary files in Vishnu client
authorbarate <barate>
Fri, 30 Mar 2012 08:35:51 +0000 (08:35 +0000)
committerbarate <barate>
Fri, 30 Mar 2012 08:35:51 +0000 (08:35 +0000)
src/Vishnu/Batch_BatchManager_eVishnu.cxx
src/Vishnu/Batch_JobInfo_eVishnu.cxx
src/Vishnu/Batch_JobInfo_eVishnu.hxx

index 7ac2ee57c1ceb9bc5323667c229abc285f85f534..8cf1b657e876ffdb10456367ddd17c9d2d28934e 100644 (file)
@@ -35,7 +35,6 @@
 #include <Batch_Constants.hxx>
 #include <Batch_Utils.hxx>
 
-#include "Batch_FactBatchManager_eVishnu.hxx"
 #include "Batch_BatchManager_eVishnu.hxx"
 #include "Batch_JobInfo_eVishnu.hxx"
 
@@ -63,10 +62,6 @@ namespace Batch {
   // Method to submit a job to the batch manager
   const JobId BatchManager_eVishnu::submitJob(const Job & job)
   {
-    int status;
-    Parametre params = job.getParametre();
-    const string workDir = params[WORKDIR];
-
     // export input files on cluster
     exportInputFiles(job);
 
@@ -74,46 +69,35 @@ namespace Batch {
     string cmdFile = buildCommandFile(job);
 
     // define extra parameters (that can not be defined in the command file)
+    Parametre params = job.getParametre();
     ostringstream extraParams;
     if (params.find(NBPROC) != params.end())
       extraParams << "-P " << params[NBPROC] << " ";
     if (params.find(MAXRAMSIZE) != params.end())
       extraParams << "-m " << params[MAXRAMSIZE] << " ";
 
-    // define name of log file (local)
-    string logFile = generateTemporaryFileName("vishnu-submitlog");
-
     // define command to submit batch
     string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; ");
     subCommand += "vishnu_connect -p 2; ";
     subCommand += "vishnu_submit_job " + extraParams.str() + _hostname + " " + cmdFile;
-    string command = _protocol.getExecCommand(subCommand,
-                                              _hostname,
-                                              _username);
-    command += " > ";
-    command += logFile;
-    cerr << command.c_str() << endl;
-    status = system(command.c_str());
-    if (status)
-    {
-      ifstream error_message(logFile.c_str());
-      string mess;
-      string temp;
-      while(getline(error_message, temp))
-        mess += temp;
-      error_message.close();
-      throw EmulationException("Error of connection on remote host, error was: " + mess);
-    }
-
-    // read id of submitted job in log file
-    string jobref;
-    ifstream idfile(logFile.c_str());
-    string line;
-    while (idfile && line.compare(0, 13, "Job Id     : ") != 0)
-      getline(idfile, line);
-    idfile.close();
-    if (line.compare(0, 13, "Job Id     : ") == 0)
-      jobref = line.substr(13);
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    command += " 2>&1";
+
+    // submit job
+    string output;
+    int status = Utils::getCommandOutput(command, output);
+    cout << output;
+    if (status != 0) throw EmulationException("Can't submit job, error was: " + output);
+
+    // find id of submitted job in output
+    string search = "Job Id     : ";
+    string::size_type pos = output.find(search);
+    if (pos == string::npos)
+      throw EmulationException("Error in the submission of the job on the remote host");
+    pos += search.size();
+    string::size_type endl_pos = output.find('\n', pos);
+    string::size_type count = (endl_pos == string::npos)? string::npos : endl_pos - pos;
+    string jobref = output.substr(pos, count);
     if (jobref.size() == 0)
       throw EmulationException("Error in the submission of the job on the remote host");
 
@@ -261,14 +245,10 @@ namespace Batch {
 
   void BatchManager_eVishnu::deleteJob(const JobId & jobid)
   {
-    string vishnuJobId;
-    istringstream iss(jobid.getReference());
-    getline(iss, vishnuJobId, ':');
-
     // define command to delete job
     string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; ");
     subCommand += "vishnu_connect -p 2; ";
-    subCommand += "vishnu_cancel_job " + _hostname + " " + vishnuJobId;
+    subCommand += "vishnu_cancel_job " + _hostname + " " + jobid.getReference();
     string command = _protocol.getExecCommand(subCommand, _hostname, _username);
     cerr << command.c_str() << endl;
 
@@ -306,26 +286,18 @@ namespace Batch {
 
   JobInfo BatchManager_eVishnu::queryJob(const JobId & jobid)
   {
-    // define name of log file (local)
-    string logFile = generateTemporaryFileName("vishnu-querylog-" + jobid.getReference());
-
-    string vishnuJobId;
-    istringstream iss(jobid.getReference());
-    getline(iss, vishnuJobId, ':');
-
     // define command to query batch
     string subCommand = string("export OMNIORB_CONFIG=$VISHNU_CONFIG_FILE; ");
     subCommand += "vishnu_connect -p 2; ";
-    subCommand += "vishnu_get_job_info " + _hostname + " " + vishnuJobId;
+    subCommand += "vishnu_get_job_info " + _hostname + " " + jobid.getReference();
     string command = _protocol.getExecCommand(subCommand, _hostname, _username);
-    command += " > ";
-    command += logFile;
     cerr << command.c_str() << endl;
-    int status = system(command.c_str());
+
+    string output;
+    int status = Utils::getCommandOutput(command, output);
     if (status != 0)
       throw EmulationException("Can't query job " + jobid.getReference());
-
-    JobInfo_eVishnu jobinfo = JobInfo_eVishnu(jobid.getReference(), logFile);
+    JobInfo_eVishnu jobinfo = JobInfo_eVishnu(jobid.getReference(), output);
     return jobinfo;
   }
 
index 741882ee7e5aee37ebe372239a853b7fc85b5796..083c05593a8046d061d21e782a512df391061c7e 100644 (file)
@@ -27,7 +27,6 @@
  */
 
 #include <iostream>
-#include <fstream>
 #include <sstream>
 
 #include <Batch_RunTimeException.hxx>
@@ -39,18 +38,18 @@ using namespace std;
 
 namespace Batch {
 
-  JobInfo_eVishnu::JobInfo_eVishnu(const std::string & id, const std::string & logFile)
+  JobInfo_eVishnu::JobInfo_eVishnu(const string & id, const string & queryOutput)
     : JobInfo()
   {
     _param[ID] = id;
 
-    // find the status in the log file
-    ifstream log(logFile.c_str());
+    // find the status in the query output
+    istringstream iss(queryOutput);
     string status;
     bool statusFound = false;
-    while (!statusFound && !log.eof()) {
+    while (!statusFound && !iss.eof()) {
       string line;
-      getline(log, line);
+      getline(iss, line);
       size_t pos = line.find(':');
       if (pos != string::npos) {
         string begline = line.substr(0, pos);
@@ -71,7 +70,6 @@ namespace Batch {
         }
       }
     }
-    log.close();
 
     if (status.size() == 0) {
       // On some batch managers, the job is deleted as soon as it is finished,
index 1687ffac67a0935a64d18205fbb7e9e5b731beb2..53414952936ee857cd67855ea1a45b33b655c205 100644 (file)
@@ -39,7 +39,7 @@ namespace Batch {
   {
   public:
 
-    JobInfo_eVishnu(const std::string & id, const std::string & logFile);
+    JobInfo_eVishnu(const std::string & id, const std::string & queryOutput);
     virtual ~JobInfo_eVishnu();
 
   };