From 53fd4b1b0cb352b13f21a986cbe1a2e46eb1ac60 Mon Sep 17 00:00:00 2001 From: barate Date: Tue, 30 Nov 2010 10:14:52 +0000 Subject: [PATCH] Added method queryJob for LoadLeveler --- src/LoadLeveler/Batch_BatchManager_eLL.cxx | 40 ++++--- src/LoadLeveler/Batch_JobInfo_eLL.cxx | 121 +++++++++++++++++++++ src/LoadLeveler/Batch_JobInfo_eLL.hxx | 48 ++++++++ src/LoadLeveler/CMakeLists.txt | 1 + 4 files changed, 196 insertions(+), 14 deletions(-) create mode 100644 src/LoadLeveler/Batch_JobInfo_eLL.cxx create mode 100644 src/LoadLeveler/Batch_JobInfo_eLL.hxx diff --git a/src/LoadLeveler/Batch_BatchManager_eLL.cxx b/src/LoadLeveler/Batch_BatchManager_eLL.cxx index 2c3a390..9044a96 100644 --- a/src/LoadLeveler/Batch_BatchManager_eLL.cxx +++ b/src/LoadLeveler/Batch_BatchManager_eLL.cxx @@ -32,6 +32,7 @@ #include #include "Batch_BatchManager_eLL.hxx" +#include "Batch_JobInfo_eLL.hxx" using namespace std; @@ -75,13 +76,13 @@ namespace Batch { command += logFile; cerr << command.c_str() << endl; status = system(command.c_str()); - if(status) + if (status) { ifstream error_message(logFile.c_str()); string mess; string temp; - while(std::getline(error_message, temp)) - mess += temp; + while(getline(error_message, temp)) + mess += temp; error_message.close(); throw EmulationException("Error of connection on remote host, error was: " + mess); } @@ -89,15 +90,12 @@ namespace Batch { // read id of submitted job in log file string jobref; ifstream idfile(logFile.c_str()); - unsigned int linebufsize = 1024; - char linebuf[linebufsize]; - idfile.getline(linebuf, linebufsize); - while (!idfile.eof() && strncmp(linebuf, "llsubmit:", 9) != 0) - idfile.getline(linebuf, linebufsize); + string line; + while (idfile && line.compare(0, 9, "llsubmit:") != 0) + getline(idfile, line); idfile.close(); - if (strncmp(linebuf, "llsubmit:", 9) == 0) + if (line.compare(0, 9, "llsubmit:") == 0) { - string line(linebuf); string::size_type p1 = line.find_first_of("\""); string::size_type p2 = line.find_last_of("\""); if (p1 != p2) @@ -144,7 +142,7 @@ namespace Batch { // Create batch submit file ofstream tempOutputFile; - std::string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile); + string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile); tempOutputFile << "# @ executable = " << fileNameToExecute << endl; tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl; @@ -157,14 +155,14 @@ namespace Batch { tempOutputFile.flush(); tempOutputFile.close(); - cerr << "Batch script file generated is: " << tmpFileName.c_str() << endl; + cerr << "Batch script file generated is: " << tmpFileName << endl; string remoteFileName = rootNameToExecute + "_LL.cmd"; int status = _protocol.copyFile(tmpFileName, "", "", workDir + "/" + remoteFileName, _hostname, _username); if (status) - throw EmulationException("Error of connection on remote host, cannot copy batch submission file"); + throw EmulationException("Cannot copy command file on host " + _hostname); return remoteFileName; } @@ -201,7 +199,21 @@ namespace Batch { JobInfo BatchManager_eLL::queryJob(const JobId & jobid) { - throw NotYetImplementedException("BatchManager_eLL::queryJob"); + // define name of log file (local) + string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference()); + + // define command to query batch + string subCommand = "llq -f %st " + jobid.getReference(); + string command = _protocol.getExecCommand(subCommand, _hostname, _username); + command += " > "; + command += logFile; + cerr << command.c_str() << endl; + int status = system(command.c_str()); + if (status != 0) + throw EmulationException("Can't query job " + jobid.getReference()); + + JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile); + return jobinfo; } const JobId BatchManager_eLL::addJob(const Job & job, const string reference) diff --git a/src/LoadLeveler/Batch_JobInfo_eLL.cxx b/src/LoadLeveler/Batch_JobInfo_eLL.cxx new file mode 100644 index 0000000..33f9ef2 --- /dev/null +++ b/src/LoadLeveler/Batch_JobInfo_eLL.cxx @@ -0,0 +1,121 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_JobInfo_eLL.cxx : + * + * Created on: 30 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#include +#include +#include + +#include + +#include "Batch_JobInfo_eLL.hxx" + +using namespace std; + +namespace Batch { + + JobInfo_eLL::JobInfo_eLL(const std::string & id, const std::string & logFile) + : JobInfo() + { + _param[ID] = id; + + // read log file + ifstream log(logFile.c_str()); + string line; + + // status should be on the third line + for (int i=0 ; i<3 ; i++) + getline(log, line); + 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 == "C") { // Completed + _param[STATE] = FINISHED; + } else if (status == "R") { // Running + _param[STATE] = RUNNING; + } else if (status == "I") { // Idle + _param[STATE] = QUEUED; + } else if (status == "CA") { // Canceled + _param[STATE] = FAILED; + } else if (status == "CK") { // Checkpointing + _param[STATE] = RUNNING; + } else if (status == "CP") { // Complete Pending + _param[STATE] = RUNNING; + } else if (status == "D") { // Deferred + _param[STATE] = QUEUED; + } else if (status == "NQ") { // Not Queued + _param[STATE] = QUEUED; + } else if (status == "NR") { // Not Run + _param[STATE] = FAILED; + } else if (status == "P") { // Pending + _param[STATE] = RUNNING; + } else if (status == "E") { // Preempted + _param[STATE] = RUNNING; + } else if (status == "EP") { // Preempt Pending + _param[STATE] = RUNNING; + } else if (status == "X") { // Rejected + _param[STATE] = FAILED; + } else if (status == "XP") { // Reject Pending + _param[STATE] = QUEUED; + } else if (status == "RM") { // Removed + _param[STATE] = FAILED; + } else if (status == "RP") { // Remove Pending + _param[STATE] = FAILED; + } else if (status == "MP") { // Resume Pending + _param[STATE] = RUNNING; + } else if (status == "ST") { // Starting + _param[STATE] = RUNNING; + } else if (status == "S") { // System Hold + _param[STATE] = PAUSED; + } else if (status == "TX") { // Terminated + _param[STATE] = FAILED; + } else if (status == "HS") { // User & System Hold + _param[STATE] = PAUSED; + } else if (status == "H") { // User Hold + _param[STATE] = PAUSED; + } else if (status == "V") { // Vacated + _param[STATE] = FAILED; + } else if (status == "VP") { // Vacate Pending + _param[STATE] = FAILED; + } else { + throw RunTimeException("Unknown job state code: \"" + status + "\""); + } + } + + JobInfo_eLL::~JobInfo_eLL() + { + // Nothing to do + } + +} diff --git a/src/LoadLeveler/Batch_JobInfo_eLL.hxx b/src/LoadLeveler/Batch_JobInfo_eLL.hxx new file mode 100644 index 0000000..c0307ca --- /dev/null +++ b/src/LoadLeveler/Batch_JobInfo_eLL.hxx @@ -0,0 +1,48 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +/* + * Batch_JobInfo_eLL.hxx : + * + * Created on: 30 nov. 2010 + * Author : Renaud BARATE - EDF R&D + */ + +#ifndef _JOBINFO_ELL_H_ +#define _JOBINFO_ELL_H_ + +#include + +#include + +namespace Batch { + + class JobInfo_eLL : public JobInfo + { + public: + JobInfo_eLL(const std::string & id, const std::string & logFile); + virtual ~JobInfo_eLL(); + + }; + +} + +#endif diff --git a/src/LoadLeveler/CMakeLists.txt b/src/LoadLeveler/CMakeLists.txt index 6db2d90..af0bc49 100644 --- a/src/LoadLeveler/CMakeLists.txt +++ b/src/LoadLeveler/CMakeLists.txt @@ -22,6 +22,7 @@ SET(CLASS_LIST LoadLeveler/Batch_BatchManager_eLL LoadLeveler/Batch_FactBatchManager_eLL + LoadLeveler/Batch_JobInfo_eLL ) APPEND_CLASSES_TO_SRC_FILES(${CLASS_LIST}) -- 2.39.2