From: barate Date: Mon, 27 Jun 2011 12:56:37 +0000 (+0000) Subject: Finished first implementation of Vishnu client X-Git-Tag: V1_4_0_VISHNU~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=093c22548088184e19acc495ba293f51471ccd82;p=tools%2Flibbatch.git Finished first implementation of Vishnu client --- diff --git a/src/Vishnu/Batch_BatchManager_eVishnu.cxx b/src/Vishnu/Batch_BatchManager_eVishnu.cxx index 5de808b..94e1baf 100644 --- a/src/Vishnu/Batch_BatchManager_eVishnu.cxx +++ b/src/Vishnu/Batch_BatchManager_eVishnu.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -76,7 +77,7 @@ namespace Batch { // 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); @@ -107,6 +108,10 @@ namespace Batch { 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; } @@ -198,8 +203,18 @@ namespace Batch { 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; @@ -240,8 +255,18 @@ namespace Batch { // 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; diff --git a/src/Vishnu/Batch_JobInfo_eVishnu.cxx b/src/Vishnu/Batch_JobInfo_eVishnu.cxx index b68934c..786103e 100644 --- a/src/Vishnu/Batch_JobInfo_eVishnu.cxx +++ b/src/Vishnu/Batch_JobInfo_eVishnu.cxx @@ -44,42 +44,47 @@ namespace Batch { { _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 + "\"");