Salome HOME
bbff80f54a2a2f1d48085d95a21806130a5731a2
[modules/kernel.git] / src / Launcher / Launcher_Job.hxx
1 // Copyright (C) 2009-2012  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 <Batch/Batch_Job.hxx>
42 #include <Batch/Batch_Date.hxx>
43 #include <Batch/Batch_JobId.hxx>
44 #include <Batch/Batch_EmulationException.hxx>
45 #endif
46
47 #include <libxml/parser.h>
48
49 namespace Launcher
50 {
51   class LAUNCHER_EXPORT Job
52   {
53     public:
54       Job();
55       virtual ~Job();
56
57       // Launcher managing parameters
58       // State of a Job: CREATED, IN_PROCESS, QUEUED, RUNNING, PAUSED, FINISHED, ERROR
59       void setState(const std::string & state);
60       std::string getState();
61
62       void setNumber(const int & number);
63       int getNumber();
64
65       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
66       ParserResourcesType getResourceDefinition();
67
68       // Common parameters
69       void setJobName(const std::string & job_name);
70       virtual void setJobFile(const std::string & job_file);
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
81       std::string getJobName();
82       std::string getJobFile();
83       std::string getWorkDirectory();
84       std::string getLocalDirectory();
85       std::string getResultDirectory();
86       const std::list<std::string> & get_in_files();
87       const std::list<std::string> & get_out_files();
88       std::string getMaximumDuration();
89       resourceParams getResourceRequiredParams();
90       std::string getQueue();
91       std::string getEnvFile();
92       std::string getJobType();
93
94       std::string updateJobState();
95
96       void addSpecificParameter(const std::string & name,
97                                   const std::string & value);
98       const std::map<std::string, std::string> & getSpecificParameters();
99       virtual void checkSpecificParameters();
100
101       // Checks
102       void checkMaximumDuration(const std::string & maximum_duration);
103       void checkResourceRequiredParams(const resourceParams & resource_required_params);
104
105       // Helps
106       long convertMaximumDuration(const std::string & maximum_duration);
107       std::string getLaunchDate();
108
109       // Xml method
110       void addToXmlDocument(xmlNodePtr root_node);
111
112       void stopJob();
113       void removeJob();
114
115       // Abstract class
116       virtual void update_job() = 0;
117
118     protected:
119       int _number;
120
121       std::string _job_type;
122
123       std::string _state;
124       std::string _launch_date;
125       std::string _env_file;
126
127       ParserResourcesType _resource_definition;
128
129       std::string _job_name;
130       std::string _job_file;
131       std::string _job_file_name;
132       std::string _job_file_name_complete;
133
134       std::string _work_directory;
135       std::string _local_directory;
136       std::string _result_directory;
137       std::list<std::string> _in_files;
138       std::list<std::string> _out_files;
139       std::map<std::string, std::string> _specific_parameters;
140       std::string _maximum_duration;
141       long _maximum_duration_in_second;
142       resourceParams _resource_required_params;
143       std::string _queue;
144
145 #ifdef WITH_LIBBATCH
146     // Connection with LIBBATCH
147     public:      
148       Batch::Job * getBatchJob();
149       Batch::Parametre common_job_params();
150       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
151       Batch::JobId getBatchManagerJobId();
152
153     protected:
154       Batch::Job * _batch_job;
155       Batch::JobId _batch_job_id;
156 #endif
157   };
158 }
159
160 #endif
161