Salome HOME
5ef6c32fcd7fb9ff578c260738ff65887c3376f7
[tools/libbatch.git] / src / Slurm / JobInfo_Slurm.cxx
1 //  Copyright (C) 2007-2013  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  *  JobInfo_Slurm.cxx :
24  *
25  *  Created on: 12 may 2011
26  *  Author : Renaud BARATE - EDF R&D
27  */
28
29 #include <sstream>
30
31 #include <RunTimeException.hxx>
32 #include <Constants.hxx>
33
34 #include "JobInfo_Slurm.hxx"
35
36 using namespace std;
37
38 namespace Batch {
39
40   JobInfo_Slurm::JobInfo_Slurm(const std::string & id, const std::string & queryOutput)
41     : JobInfo()
42   {
43     _param[ID] = id;
44
45     // read query output, status should be on the second line
46     istringstream iss(queryOutput);
47     string status;
48     for (int i=0 ; i<2 ; i++)
49       getline(iss, status);
50
51     if (status.size() == 0) {
52       // On some batch managers, the job is deleted as soon as it is finished,
53       // so we have to consider that an unknown job is a finished one, even if
54       // it is not always true.
55       _param[STATE] = FINISHED;
56     } else if (status == "CA") { // Canceled
57       _param[STATE] = FAILED;
58     } else if (status == "CD") { // Completed
59       _param[STATE] = FINISHED;
60     } else if (status == "CF") { // Configuring
61       _param[STATE] = QUEUED;
62     } else if (status == "CG") { // Completing
63       _param[STATE] = RUNNING;
64     } else if (status == "F") {  // Failed
65       _param[STATE] = FAILED;
66     } else if (status == "NF") { // Node Fail
67       _param[STATE] = FAILED;
68     } else if (status == "PD") { // Pending
69       _param[STATE] = QUEUED;
70     } else if (status == "R") {  // Running
71       _param[STATE] = RUNNING;
72     } else if (status == "S") {  // Suspended
73       _param[STATE] = PAUSED;
74     } else if (status == "TO") { // Timeout
75       _param[STATE] = FAILED;
76     } else {
77       throw RunTimeException("Unknown job state code: \"" + status + "\"");
78     }
79   }
80
81   JobInfo_Slurm::~JobInfo_Slurm()
82   {
83   }
84
85 }