Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Slurm / JobInfo_Slurm.cxx
1 // Copyright (C) 2007-2021  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, or (at your option) any later version.
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 // Utility function to test if string str1 starts with str2
39 bool starts_with(const std::string & str1, const std::string & str2)
40 {
41         if (str1.length() < str2.length()) {
42                 return false;
43         }
44         return (str1.substr(0, str2.length()) == str2);
45 }
46
47
48 namespace Batch {
49
50   JobInfo_Slurm::JobInfo_Slurm(const std::string & id, const std::string & queryOutput)
51     : JobInfo()
52   {
53     _param[ID] = id;
54
55     // We test only the beginning of the string because some extra info can be added by sacct
56     // command (e.g. CANCELLED+)
57     if (starts_with(queryOutput, "BOOT_FAIL")) {
58         _param[STATE] = FAILED;
59     } else if (starts_with(queryOutput, "CANCELLED")) {
60       _param[STATE] = FAILED;
61     } else if (starts_with(queryOutput, "COMPLETED")) {
62       _param[STATE] = FINISHED;
63     } else if (starts_with(queryOutput, "CONFIGURI")) {
64       _param[STATE] = RUNNING;
65     } else if (starts_with(queryOutput, "COMPLETIN")) {
66       _param[STATE] = RUNNING;
67     } else if (starts_with(queryOutput, "DEADLINE")) {
68       _param[STATE] = FAILED;
69     } else if (starts_with(queryOutput, "FAILED")) {
70       _param[STATE] = FAILED;
71     } else if (starts_with(queryOutput, "NODE_FAIL")) {
72       _param[STATE] = FAILED;
73     } else if (starts_with(queryOutput, "OUT_OF_ME")) {
74       _param[STATE] = FAILED;
75     } else if (starts_with(queryOutput, "PENDING")) {
76       _param[STATE] = QUEUED;
77     } else if (starts_with(queryOutput, "PREEMPTED")) {
78       _param[STATE] = FAILED;
79     } else if (starts_with(queryOutput, "RUNNING")) {
80       _param[STATE] = RUNNING;
81     } else if (starts_with(queryOutput, "RESV_DEL_")) {
82       _param[STATE] = PAUSED;
83     } else if (starts_with(queryOutput, "REQUEUE")) {
84       _param[STATE] = PAUSED;
85     } else if (starts_with(queryOutput, "RESIZING")) {
86       _param[STATE] = PAUSED;
87     } else if (starts_with(queryOutput, "REVOKED")) {
88       _param[STATE] = FAILED;
89     } else if (starts_with(queryOutput, "SIGNALING")) {
90       _param[STATE] = FAILED;
91     } else if (starts_with(queryOutput, "SPECIAL_E")) {
92       _param[STATE] = FAILED;
93     } else if (starts_with(queryOutput, "STAGE_OUT")) {
94       _param[STATE] = FAILED;
95     } else if (starts_with(queryOutput, "STOPPED")) {
96       _param[STATE] = FAILED;
97     } else if (starts_with(queryOutput, "SUSPENDED")) {
98       _param[STATE] = PAUSED;
99     } else if (starts_with(queryOutput, "TIMEOUT")) {
100       _param[STATE] = FAILED;
101     } else {
102       throw RunTimeException("Unknown job state: \"" + queryOutput + "\"");
103     }
104   }
105
106   JobInfo_Slurm::~JobInfo_Slurm()
107   {
108   }
109
110 }