Salome HOME
windows port
[modules/kernel.git] / src / Launcher / Launcher_Job.hxx
1 //  Copyright (C) 2009 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 // Author: AndrĂ© RIBES - EDF R&D
20
21 #ifndef _LAUNCHER_JOB_HXX_
22 #define _LAUNCHER_JOB_HXX_
23
24 #include <SALOMEconfig.h>
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 <iostream>
35 #include <sstream>
36 #include <algorithm>
37 #include <exception>
38
39 #ifdef WITH_LIBBATCH
40 #include <Batch/Batch_Job.hxx>
41 #include <Batch/Batch_Date.hxx>
42 #include <Batch/Batch_JobId.hxx>
43 #include <Batch/Batch_EmulationException.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();
58
59       void setNumber(const int & number);
60       int getNumber();
61
62       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
63       ParserResourcesType getResourceDefinition();
64       
65       // Common parameters
66       virtual void setJobFile(const std::string & job_file);
67       void setWorkDirectory(const std::string & work_directory);
68       void setLocalDirectory(const std::string & local_directory);
69       void setResultDirectory(const std::string & result_directory);
70       void add_in_file(const std::string & file);
71       void add_out_file(const std::string & file);
72       void setMaximumDuration(const std::string & maximum_duration);
73       void setResourceRequiredParams(const resourceParams & resource_required_params);
74       void setQueue(const std::string & queue);
75       void setEnvFile(const std::string & env_file);
76
77       std::string getJobFile();
78       std::string getWorkDirectory();
79       std::string getLocalDirectory();
80       std::string getResultDirectory();
81       const std::list<std::string> & get_in_files();
82       const std::list<std::string> & get_out_files();
83       std::string getMaximumDuration();
84       resourceParams getResourceRequiredParams();
85       std::string getQueue();
86       std::string getEnvFile();
87       
88       std::string updateJobState();
89
90       // Checks
91       void checkMaximumDuration(const std::string & maximum_duration);
92       void checkResourceRequiredParams(const resourceParams & resource_required_params);
93
94       // Helps
95       long convertMaximumDuration(const std::string & maximum_duration);
96       std::string getLaunchDate();
97
98       // Abstract class
99       virtual void update_job() = 0;
100
101     protected:
102       int _number;
103
104       std::string _state;
105       std::string _launch_date;
106       std::string _env_file;
107
108       ParserResourcesType _resource_definition;
109
110       std::string _job_file;
111       std::string _job_file_name;
112       std::string _job_file_name_complete;
113
114       std::string _work_directory;
115       std::string _local_directory;
116       std::string _result_directory;
117       std::list<std::string> _in_files;
118       std::list<std::string> _out_files;
119       std::string _maximum_duration;
120       long _maximum_duration_in_second;
121       resourceParams _resource_required_params;
122       std::string _queue;
123
124 #ifdef WITH_LIBBATCH
125     // Connection with LIBBATCH
126     public:      
127       Batch::Job * getBatchJob();
128       Batch::Parametre common_job_params();
129       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
130       Batch::JobId getBatchManagerJobId();
131
132     protected:
133       Batch::Job * _batch_job;
134       Batch::JobId _batch_job_id;
135 #endif
136   };
137 }
138
139 #endif
140