Salome HOME
Added method queryJob for LoadLeveler
[tools/libbatch.git] / src / LoadLeveler / Batch_JobInfo_eLL.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  *  Batch_JobInfo_eLL.cxx :
24  *
25  *  Created on: 30 nov. 2010
26  *  Author : Renaud BARATE - EDF R&D
27  */
28
29 #include <iostream>
30 #include <fstream>
31 #include <sstream>
32
33 #include <Batch_RunTimeException.hxx>
34
35 #include "Batch_JobInfo_eLL.hxx"
36
37 using namespace std;
38
39 namespace Batch {
40
41   JobInfo_eLL::JobInfo_eLL(const std::string & id, const std::string & logFile)
42     : JobInfo()
43   {
44     _param[ID] = id;
45
46     // read log file
47     ifstream log(logFile.c_str());
48     string line;
49
50     // status should be on the third line
51     for (int i=0 ; i<3 ; i++)
52       getline(log, line);
53     log.close();
54     string status;
55     istringstream iss(line);
56     iss >> status;
57
58     if (status.size() == 0) {
59       // On some batch managers, the job is deleted as soon as it is finished,
60       // so we have to consider that an unknown job is a finished one, even if
61       // it is not always true.
62       _param[STATE] = FINISHED;
63     } else if (status == "C") { // Completed
64       _param[STATE] = FINISHED;
65     } else if (status == "R") { // Running
66       _param[STATE] = RUNNING;
67     } else if (status == "I") { // Idle
68       _param[STATE] = QUEUED;
69     } else if (status == "CA") { // Canceled
70       _param[STATE] = FAILED;
71     } else if (status == "CK") { // Checkpointing
72       _param[STATE] = RUNNING;
73     } else if (status == "CP") { // Complete Pending
74       _param[STATE] = RUNNING;
75     } else if (status == "D") { // Deferred
76       _param[STATE] = QUEUED;
77     } else if (status == "NQ") { // Not Queued
78       _param[STATE] = QUEUED;
79     } else if (status == "NR") { // Not Run
80       _param[STATE] = FAILED;
81     } else if (status == "P") { // Pending
82       _param[STATE] = RUNNING;
83     } else if (status == "E") { // Preempted
84       _param[STATE] = RUNNING;
85     } else if (status == "EP") { // Preempt Pending
86       _param[STATE] = RUNNING;
87     } else if (status == "X") { // Rejected
88       _param[STATE] = FAILED;
89     } else if (status == "XP") { // Reject Pending
90       _param[STATE] = QUEUED;
91     } else if (status == "RM") { // Removed
92       _param[STATE] = FAILED;
93     } else if (status == "RP") { // Remove Pending
94       _param[STATE] = FAILED;
95     } else if (status == "MP") { // Resume Pending
96       _param[STATE] = RUNNING;
97     } else if (status == "ST") { // Starting
98       _param[STATE] = RUNNING;
99     } else if (status == "S") { // System Hold
100       _param[STATE] = PAUSED;
101     } else if (status == "TX") { // Terminated
102       _param[STATE] = FAILED;
103     } else if (status == "HS") { // User & System Hold
104       _param[STATE] = PAUSED;
105     } else if (status == "H") { // User Hold
106       _param[STATE] = PAUSED;
107     } else if (status == "V") { // Vacated
108       _param[STATE] = FAILED;
109     } else if (status == "VP") { // Vacate Pending
110       _param[STATE] = FAILED;
111     } else {
112       throw RunTimeException("Unknown job state code: \"" + status + "\"");
113     }
114   }
115
116   JobInfo_eLL::~JobInfo_eLL()
117   {
118     // Nothing to do
119   }
120
121 }