#include <cstdlib>
#include <iostream>
#include <fstream>
+#include <sstream>
#include <Batch_NotYetImplementedException.hxx>
#include <Batch_Constants.hxx>
// define command to submit batch
string subCommand = string("cd ") + workDir + "; ";
subCommand += ". ~/.vishnu/vishnu.env ;";
- subCommand += "vishnu_connect " + params[VISHNU_USERID].str() +
+ subCommand += "vishnu_connect -p 2 " + params[VISHNU_USERID].str() +
" -w " + params[VISHNU_PASSWORD].str() + "; ";
subCommand += "vishnu_submit_job " + params[VISHNU_MACHINEID].str() + " " + cmdFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
if (jobref.size() == 0)
throw EmulationException("Error in the submission of the job on the remote host");
+ // Store the userId, password and machineId with the jobId in the job reference
+ // (for further queries)
+ jobref = params[VISHNU_USERID].str() + ":" + params[VISHNU_PASSWORD].str() + ":" +
+ params[VISHNU_MACHINEID].str() + ":" + jobref;
JobId id(this, jobref);
return id;
}
void BatchManager_eVishnu::deleteJob(const JobId & jobid)
{
+ // split job reference in Vishnu userId / password / machineId / jobId
+ string vishnuUserId, vishnuPassword, vishnuMachineId, vishnuJobId;
+ istringstream iss(jobid.getReference());
+ getline(iss, vishnuUserId, ':');
+ getline(iss, vishnuPassword, ':');
+ getline(iss, vishnuMachineId, ':');
+ getline(iss, vishnuJobId, ':');
+
// define command to delete job
- string subCommand = "vishnu_cancel_job " + jobid.getReference();
+ string subCommand = ". ~/.vishnu/vishnu.env ;";
+ subCommand += "vishnu_connect -p 2 " + vishnuUserId + " -w " + vishnuPassword + "; ";
+ subCommand += "vishnu_cancel_job " + vishnuMachineId + " " + vishnuJobId;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
cerr << command.c_str() << endl;
// define name of log file (local)
string logFile = generateTemporaryFileName("vishnu-querylog-" + jobid.getReference());
+ // split job reference in Vishnu userId / password / machineId / jobId
+ string vishnuUserId, vishnuPassword, vishnuMachineId, vishnuJobId;
+ istringstream iss(jobid.getReference());
+ getline(iss, vishnuUserId, ':');
+ getline(iss, vishnuPassword, ':');
+ getline(iss, vishnuMachineId, ':');
+ getline(iss, vishnuJobId, ':');
+
// define command to query batch
- string subCommand = "vishnu_get_job_info " + jobid.getReference();
+ string subCommand = ". ~/.vishnu/vishnu.env ;";
+ subCommand += "vishnu_connect -p 2 " + vishnuUserId + " -w " + vishnuPassword + "; ";
+ subCommand += "vishnu_get_job_info " + vishnuMachineId + " " + vishnuJobId;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
command += " > ";
command += logFile;
{
_param[ID] = id;
- // read log file
+ // find the status in the log file
ifstream log(logFile.c_str());
- string line;
-
- // status should be on the second line
- for (int i=0 ; i<2 ; i++)
+ string status;
+ bool statusFound = false;
+ while (!statusFound && !log.eof()) {
+ string line;
getline(log, line);
+ size_t pos = line.find(':');
+ if (pos != string::npos) {
+ string begline = line.substr(0, pos);
+ string keyword;
+ // Trim leading and trailing spaces of the string before ':'
+ size_t startpos = begline.find_first_not_of(" \t");
+ size_t endpos = begline.find_last_not_of(" \t");
+ if (startpos != string::npos && endpos != string::npos)
+ keyword = begline.substr(startpos, endpos-startpos+1);
+
+ if (keyword == "Status") {
+ statusFound = true;
+ string endline = line.substr(pos + 1);
+ startpos = endline.find_first_not_of(" \t");
+ endpos = endline.find_last_not_of(" \t");
+ if (startpos != string::npos && endpos != string::npos)
+ status = endline.substr(startpos, endpos-startpos+1);
+ }
+ }
+ }
log.close();
- string status;
- istringstream iss(line);
- iss >> status;
if (status.size() == 0) {
// On some batch managers, the job is deleted as soon as it is finished,
// so we have to consider that an unknown job is a finished one, even if
// it is not always true.
_param[STATE] = FINISHED;
- } else if (status == "CA") { // Canceled
- _param[STATE] = FAILED;
- } else if (status == "CD") { // Completed
- _param[STATE] = FINISHED;
- } else if (status == "CF") { // Configuring
- _param[STATE] = QUEUED;
- } else if (status == "CG") { // Completing
- _param[STATE] = RUNNING;
- } else if (status == "F") { // Failed
- _param[STATE] = FAILED;
- } else if (status == "NF") { // Node Fail
- _param[STATE] = FAILED;
- } else if (status == "PD") { // Pending
+ } else if (status == "QUEUED") {
_param[STATE] = QUEUED;
- } else if (status == "R") { // Running
+ } else if (status == "RUNNING") {
_param[STATE] = RUNNING;
- } else if (status == "S") { // Suspended
- _param[STATE] = PAUSED;
- } else if (status == "TO") { // Timeout
+ } else if (status == "TERMINATED") {
+ _param[STATE] = FINISHED;
+ } else if (status == "CANCELLED") {
_param[STATE] = FAILED;
} else {
throw RunTimeException("Unknown job state code: \"" + status + "\"");