]> SALOME platform Git repositories - modules/kernel.git/blob - src/Launcher/Launcher_Job.hxx
Salome HOME
CMake: IF(WINDOWS) is deprecated - please always use IF(WIN32)
[modules/kernel.git] / src / Launcher / Launcher_Job.hxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // Author: André RIBES - EDF R&D
21 //
22 #ifndef _LAUNCHER_JOB_HXX_
23 #define _LAUNCHER_JOB_HXX_
24
25 #include "Launcher_Utils.hxx"
26 #include "ResourcesManager.hxx"
27
28 #include <stdlib.h>
29 #include <time.h>
30 #include <sys/stat.h>
31
32 #include <string>
33 #include <list>
34 #include <map>
35 #include <iostream>
36 #include <sstream>
37 #include <algorithm>
38 #include <exception>
39
40 #ifdef WITH_LIBBATCH
41 #include <libbatch/Job.hxx>
42 #include <libbatch/JobId.hxx>
43 #include <libbatch/GenericException.hxx>
44 #endif
45
46 #include <libxml/parser.h>
47
48 namespace Launcher
49 {
50   class LAUNCHER_EXPORT Job
51   {
52     public:
53       Job();
54       virtual ~Job();
55
56       // Launcher managing parameters
57       // State of a Job: CREATED, IN_PROCESS, QUEUED, RUNNING, PAUSED, FINISHED, ERROR
58       void setState(const std::string & state);
59       std::string getState();
60           // Get names or ids of hosts assigned to the job
61       std::string getAssignedHostnames();
62
63       void setNumber(const int & number);
64       int getNumber();
65
66       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
67       ParserResourcesType getResourceDefinition();
68
69       // Common parameters
70       void setJobName(const std::string & job_name);
71       virtual void setJobFile(const std::string & job_file);
72       void setWorkDirectory(const std::string & work_directory);
73       void setLocalDirectory(const std::string & local_directory);
74       void setResultDirectory(const std::string & result_directory);
75       void add_in_file(const std::string & file);
76       void add_out_file(const std::string & file);
77       void setMaximumDuration(const std::string & maximum_duration);
78       void setResourceRequiredParams(const resourceParams & resource_required_params);
79       void setQueue(const std::string & queue);
80       void setEnvFile(const std::string & env_file);
81       void setExclusive(bool exclusive);
82       void setExclusiveStr(const std::string & exclusiveStr);
83           // For COORM
84           void setLauncherFile(const std::string & launcher_file);
85           void setLauncherArgs(const std::string & launcher_args);
86
87       std::string getJobName();
88       std::string getJobFile();
89       std::string getWorkDirectory();
90       std::string getLocalDirectory();
91       std::string getResultDirectory();
92       const std::list<std::string> & get_in_files();
93       const std::list<std::string> & get_out_files();
94       std::string getMaximumDuration();
95       resourceParams getResourceRequiredParams();
96       std::string getQueue();
97       std::string getEnvFile();
98       std::string getJobType();
99       bool getExclusive();
100       std::string getExclusiveStr() const;
101
102           // For COORM
103           std::string getLauncherFile();
104           std::string getLauncherArgs();
105
106       std::string updateJobState();
107
108       void addSpecificParameter(const std::string & name,
109                                   const std::string & value);
110       const std::map<std::string, std::string> & getSpecificParameters();
111       virtual void checkSpecificParameters();
112
113       // Checks
114       void checkMaximumDuration(const std::string & maximum_duration);
115       void checkResourceRequiredParams(const resourceParams & resource_required_params);
116
117       // Helps
118       long convertMaximumDuration(const std::string & maximum_duration);
119       std::string getLaunchDate();
120
121       // Xml method
122       void addToXmlDocument(xmlNodePtr root_node);
123
124       void stopJob();
125       void removeJob();
126
127       // Abstract class
128       virtual void update_job() = 0;
129
130     protected:
131       int _number;
132
133       std::string _job_type;
134
135       std::string _state;
136       std::string _assigned_hostnames; // Assigned hostnames
137       std::string _launch_date;
138       std::string _env_file;
139
140       ParserResourcesType _resource_definition;
141
142       std::string _job_name;
143       std::string _job_file;
144       std::string _job_file_name;
145       std::string _job_file_name_complete;
146
147       std::string _work_directory;
148       std::string _local_directory;
149       std::string _result_directory;
150       std::list<std::string> _in_files;
151       std::list<std::string> _out_files;
152       std::map<std::string, std::string> _specific_parameters;
153       std::string _maximum_duration;
154       long _maximum_duration_in_second;
155       resourceParams _resource_required_params;
156       std::string _queue;
157       bool _exclusive;
158
159           // Parameters for COORM
160           std::string _launcher_file;
161           std::string _launcher_args;
162
163 #ifdef WITH_LIBBATCH
164     // Connection with LIBBATCH
165     public:      
166       Batch::Job * getBatchJob();
167       Batch::Parametre common_job_params();
168       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
169       Batch::JobId getBatchManagerJobId();
170
171     protected:
172       Batch::Job * _batch_job;
173       Batch::JobId _batch_job_id;
174 #endif
175   };
176 }
177
178 #endif
179