Salome HOME
f19e15a6424288670ab4052a966f1abc6d0d486a
[modules/kernel.git] / src / Launcher / Launcher_Job.hxx
1 //  Copyright (C) 2009-2010  CEA/DEN, EDF R&D
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 <SALOMEconfig.h>
26 #include "Launcher_Utils.hxx"
27 #include "ResourcesManager.hxx"
28
29 #include <stdlib.h>
30 #include <time.h>
31 #include <sys/stat.h>
32
33 #include <string>
34 #include <list>
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       // Checks
97       void checkMaximumDuration(const std::string & maximum_duration);
98       void checkResourceRequiredParams(const resourceParams & resource_required_params);
99
100       // Helps
101       long convertMaximumDuration(const std::string & maximum_duration);
102       std::string getLaunchDate();
103
104       // Xml method
105       void addToXmlDocument(xmlNodePtr root_node);
106
107       // Abstract class
108       virtual void update_job() = 0;
109
110     protected:
111       int _number;
112
113       std::string _job_type;
114
115       std::string _state;
116       std::string _launch_date;
117       std::string _env_file;
118
119       ParserResourcesType _resource_definition;
120
121       std::string _job_name;
122       std::string _job_file;
123       std::string _job_file_name;
124       std::string _job_file_name_complete;
125
126       std::string _work_directory;
127       std::string _local_directory;
128       std::string _result_directory;
129       std::list<std::string> _in_files;
130       std::list<std::string> _out_files;
131       std::string _maximum_duration;
132       long _maximum_duration_in_second;
133       resourceParams _resource_required_params;
134       std::string _queue;
135
136 #ifdef WITH_LIBBATCH
137     // Connection with LIBBATCH
138     public:      
139       Batch::Job * getBatchJob();
140       Batch::Parametre common_job_params();
141       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
142       Batch::JobId getBatchManagerJobId();
143
144     protected:
145       Batch::Job * _batch_job;
146       Batch::JobId _batch_job_id;
147 #endif
148   };
149 }
150
151 #endif
152