From 6b85763f12e42e0dc95e4bed21df722d880d3567 Mon Sep 17 00:00:00 2001 From: barate Date: Fri, 30 Mar 2012 08:35:51 +0000 Subject: [PATCH] Avoid use of temporary files in Vishnu client --- src/Vishnu/Batch_BatchManager_eVishnu.cxx | 78 ++++++++--------------- src/Vishnu/Batch_JobInfo_eVishnu.cxx | 12 ++-- src/Vishnu/Batch_JobInfo_eVishnu.hxx | 2 +- 3 files changed, 31 insertions(+), 61 deletions(-) diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.cxx b/src/Vishnu/Batch_BatchManager_eVishnu.cxx index 7ac2ee5..8cf1b65 100644 --- a/src/Vishnu/Batch_BatchManager_eVishnu.cxx +++ b/src/Vishnu/Batch_BatchManager_eVishnu.cxx @@ -35,7 +35,6 @@ #include #include -#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; } diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.cxx b/src/Vishnu/Batch_JobInfo_eVishnu.cxx index 741882e..083c055 100644 --- a/src/Vishnu/Batch_JobInfo_eVishnu.cxx +++ b/src/Vishnu/Batch_JobInfo_eVishnu.cxx @@ -27,7 +27,6 @@ */ #include -#include #include #include @@ -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, diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.hxx b/src/Vishnu/Batch_JobInfo_eVishnu.hxx index 1687ffa..5341495 100644 --- a/src/Vishnu/Batch_JobInfo_eVishnu.hxx +++ b/src/Vishnu/Batch_JobInfo_eVishnu.hxx @@ -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(); }; -- 2.39.2