Salome HOME
Add the preprocess feature to SALOME_Launcher.
[modules/kernel.git] / src / Launcher / Launcher_Job.hxx
1 // Copyright (C) 2009-2016  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, or (at your option) any later version.
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 namespace Launcher
47 {
48   class LAUNCHER_EXPORT Job
49   {
50     public:
51       Job();
52       virtual ~Job();
53
54       // Launcher managing parameters
55       // State of a Job: CREATED, IN_PROCESS, QUEUED, RUNNING, PAUSED, FINISHED, ERROR
56       void setState(const std::string & state);
57       std::string getState() const;
58           // Get names or ids of hosts assigned to the job
59       std::string getAssignedHostnames();
60
61       void setNumber(const int & number);
62       int getNumber();
63
64       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
65       ParserResourcesType getResourceDefinition() const;
66
67       // Common parameters
68       void setJobName(const std::string & job_name);
69       virtual void setJobFile(const std::string & job_file);
70       void setPreCommand(const std::string & preCommand);
71       void setWorkDirectory(const std::string & work_directory);
72       void setLocalDirectory(const std::string & local_directory);
73       void setResultDirectory(const std::string & result_directory);
74       void add_in_file(const std::string & file);
75       void add_out_file(const std::string & file);
76       void setMaximumDuration(const std::string & maximum_duration);
77       void setResourceRequiredParams(const resourceParams & resource_required_params);
78       void setQueue(const std::string & queue);
79       void setEnvFile(const std::string & env_file);
80       void setExclusive(bool exclusive);
81       void setExclusiveStr(const std::string & exclusiveStr);
82       void setMemPerCpu(unsigned long mem_per_cpu);
83       void setWCKey(const std::string & wckey);
84       void setExtraParams(const std::string & extra_params);
85       void setReference(const std::string & reference);
86       // For COORM
87       void setLauncherFile(const std::string & launcher_file);
88       void setLauncherArgs(const std::string & launcher_args);
89
90       std::string getJobName() const;
91       std::string getJobFile() const;
92       std::string getPreCommand() const;
93       std::string getWorkDirectory() const;
94       std::string getLocalDirectory() const;
95       std::string getResultDirectory() const;
96       const std::list<std::string> & get_in_files() const;
97       const std::list<std::string> & get_out_files() const;
98       std::string getMaximumDuration() const;
99       resourceParams getResourceRequiredParams() const;
100       std::string getQueue() const;
101       std::string getEnvFile() const;
102       std::string getJobType() const;
103       bool getExclusive() const;
104       std::string getExclusiveStr() const;
105       unsigned long getMemPerCpu() const;
106       std::string getWCKey() const;
107       std::string getExtraParams() const;
108       std::string getReference() const;
109
110       // For COORM
111       std::string getLauncherFile() const;
112       std::string getLauncherArgs() const;
113
114       std::string updateJobState();
115
116       void addSpecificParameter(const std::string & name,
117                                   const std::string & value);
118       const std::map<std::string, std::string> & getSpecificParameters() const;
119       virtual void checkSpecificParameters();
120
121       // Checks
122       void checkMaximumDuration(const std::string & maximum_duration);
123       void checkResourceRequiredParams(const resourceParams & resource_required_params);
124
125       // Helps
126       long convertMaximumDuration(const std::string & maximum_duration);
127       std::string getLaunchDate() const;
128
129       void stopJob();
130       void removeJob();
131
132       // Abstract class
133       virtual void update_job() = 0;
134
135     protected:
136       int _number;
137
138       std::string _job_type;
139
140       std::string _state;
141       std::string _assigned_hostnames; // Assigned hostnames
142       std::string _launch_date;
143       std::string _env_file;
144
145       ParserResourcesType _resource_definition;
146
147       std::string _job_name;
148       std::string _job_file;
149       std::string _job_file_name;
150       std::string _job_file_name_complete;
151       std::string _pre_command;
152
153       std::string _work_directory;
154       std::string _local_directory;
155       std::string _result_directory;
156       std::list<std::string> _in_files;
157       std::list<std::string> _out_files;
158       std::map<std::string, std::string> _specific_parameters;
159       std::string _maximum_duration;
160       long _maximum_duration_in_second;
161       resourceParams _resource_required_params;
162       std::string _queue;
163       bool _exclusive;
164       unsigned long _mem_per_cpu;
165       std::string _wckey;
166       std::string _extra_params;
167       std::string _reference; //! Reference of the job for the batch manager
168
169       // Parameters for COORM
170       std::string _launcher_file;
171       std::string _launcher_args;
172
173 #ifdef WITH_LIBBATCH
174     // Connection with LIBBATCH
175     public:      
176       Batch::Job * getBatchJob();
177       Batch::Parametre common_job_params();
178       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
179       Batch::JobId getBatchManagerJobId() const;
180
181     protected:
182       Batch::Job * _batch_job;
183       Batch::JobId _batch_job_id;
184 #endif
185   };
186 }
187
188 #endif