Salome HOME
Added possibility to add specific parameters in the client classes. Added parameter...
[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 #include <Batch_Constants.hxx>
35
36 #include "Batch_JobInfo_eLL.hxx"
37
38 using namespace std;
39
40 namespace Batch {
41
42   JobInfo_eLL::JobInfo_eLL(const std::string & id, const std::string & logFile)
43     : JobInfo()
44   {
45     _param[ID] = id;
46
47     // read log file
48     ifstream log(logFile.c_str());
49     string line;
50
51     // status should be on the third line
52     for (int i=0 ; i<3 ; i++)
53       getline(log, line);
54     log.close();
55     string status;
56     istringstream iss(line);
57     iss >> status;
58
59     if (status.size() == 0) {
60       // On some batch managers, the job is deleted as soon as it is finished,
61       // so we have to consider that an unknown job is a finished one, even if
62       // it is not always true.
63       _param[STATE] = FINISHED;
64     } else if (status == "C") { // Completed
65       _param[STATE] = FINISHED;
66     } else if (status == "R") { // Running
67       _param[STATE] = RUNNING;
68     } else if (status == "I") { // Idle
69       _param[STATE] = QUEUED;
70     } else if (status == "CA") { // Canceled
71       _param[STATE] = FAILED;
72     } else if (status == "CK") { // Checkpointing
73       _param[STATE] = RUNNING;
74     } else if (status == "CP") { // Complete Pending
75       _param[STATE] = RUNNING;
76     } else if (status == "D") { // Deferred
77       _param[STATE] = QUEUED;
78     } else if (status == "NQ") { // Not Queued
79       _param[STATE] = QUEUED;
80     } else if (status == "NR") { // Not Run
81       _param[STATE] = FAILED;
82     } else if (status == "P") { // Pending
83       _param[STATE] = RUNNING;
84     } else if (status == "E") { // Preempted
85       _param[STATE] = RUNNING;
86     } else if (status == "EP") { // Preempt Pending
87       _param[STATE] = RUNNING;
88     } else if (status == "X") { // Rejected
89       _param[STATE] = FAILED;
90     } else if (status == "XP") { // Reject Pending
91       _param[STATE] = QUEUED;
92     } else if (status == "RM") { // Removed
93       _param[STATE] = FAILED;
94     } else if (status == "RP") { // Remove Pending
95       _param[STATE] = FAILED;
96     } else if (status == "MP") { // Resume Pending
97       _param[STATE] = RUNNING;
98     } else if (status == "ST") { // Starting
99       _param[STATE] = RUNNING;
100     } else if (status == "S") { // System Hold
101       _param[STATE] = PAUSED;
102     } else if (status == "TX") { // Terminated
103       _param[STATE] = FAILED;
104     } else if (status == "HS") { // User & System Hold
105       _param[STATE] = PAUSED;
106     } else if (status == "H") { // User Hold
107       _param[STATE] = PAUSED;
108     } else if (status == "V") { // Vacated
109       _param[STATE] = FAILED;
110     } else if (status == "VP") { // Vacate Pending
111       _param[STATE] = FAILED;
112     } else {
113       throw RunTimeException("Unknown job state code: \"" + status + "\"");
114     }
115   }
116
117   JobInfo_eLL::~JobInfo_eLL()
118   {
119     // Nothing to do
120   }
121
122 }