Salome HOME
debug for CCRT
[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 "ResourcesManager.hxx"
26
27 #include <stdlib.h>
28 #include <time.h>
29 #include <sys/stat.h>
30
31 #include <string>
32 #include <list>
33 #include <iostream>
34 #include <sstream>
35 #include <algorithm>
36 #include <exception>
37
38 #ifdef WITH_LIBBATCH
39 #include <Batch/Batch_Job.hxx>
40 #include <Batch/Batch_Date.hxx>
41 #include <Batch/Batch_JobId.hxx>
42 #include <Batch/Batch_EmulationException.hxx>
43 #endif
44
45 namespace Launcher
46 {
47   class Job
48   {
49     public:
50       Job();
51       virtual ~Job();
52
53       // Launcher managing parameters
54       // State of a Job: CREATED, IN_PROCESS, QUEUED, RUNNING, PAUSED, FINISHED, ERROR
55       void setState(const std::string & state);
56       std::string getState();
57
58       void setNumber(const int & number);
59       int getNumber();
60
61       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
62       ParserResourcesType getResourceDefinition();
63       
64       // Common parameters
65       virtual void setJobFile(const std::string & job_file);
66       void setWorkDirectory(const std::string & work_directory);
67       void setLocalDirectory(const std::string & local_directory);
68       void setResultDirectory(const std::string & result_directory);
69       void add_in_file(const std::string & file);
70       void add_out_file(const std::string & file);
71       void setMaximumDuration(const std::string & maximum_duration);
72       void setResourceRequiredParams(const resourceParams & resource_required_params);
73       void setQueue(const std::string & queue);
74       void setEnvFile(const std::string & env_file);
75
76       std::string getJobFile();
77       std::string getWorkDirectory();
78       std::string getLocalDirectory();
79       std::string getResultDirectory();
80       const std::list<std::string> & get_in_files();
81       const std::list<std::string> & get_out_files();
82       std::string getMaximumDuration();
83       resourceParams getResourceRequiredParams();
84       std::string getQueue();
85       std::string getEnvFile();
86       
87       std::string updateJobState();
88
89       // Checks
90       void checkMaximumDuration(const std::string & maximum_duration);
91       void checkResourceRequiredParams(const resourceParams & resource_required_params);
92
93       // Helps
94       long convertMaximumDuration(const std::string & maximum_duration);
95       std::string getLaunchDate();
96
97       // Abstract class
98       virtual void update_job() = 0;
99
100     protected:
101       int _number;
102
103       std::string _state;
104       std::string _launch_date;
105       std::string _env_file;
106
107       ParserResourcesType _resource_definition;
108
109       std::string _job_file;
110       std::string _job_file_name;
111       std::string _job_file_name_complete;
112
113       std::string _work_directory;
114       std::string _local_directory;
115       std::string _result_directory;
116       std::list<std::string> _in_files;
117       std::list<std::string> _out_files;
118       std::string _maximum_duration;
119       long _maximum_duration_in_second;
120       resourceParams _resource_required_params;
121       std::string _queue;
122
123 #ifdef WITH_LIBBATCH
124     // Connection with LIBBATCH
125     public:      
126       Batch::Job * getBatchJob();
127       Batch::Parametre common_job_params();
128       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
129       Batch::JobId getBatchManagerJobId();
130
131     protected:
132       Batch::Job * _batch_job;
133       Batch::JobId _batch_job_id;
134 #endif
135   };
136 }
137
138 #endif
139