Back to index

salome-kernel  6.5.0
Launcher_Job.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // Author: André RIBES - EDF R&D
00021 //
00022 #ifndef _LAUNCHER_JOB_HXX_
00023 #define _LAUNCHER_JOB_HXX_
00024 
00025 #include "Launcher_Utils.hxx"
00026 #include "ResourcesManager.hxx"
00027 
00028 #include <stdlib.h>
00029 #include <time.h>
00030 #include <sys/stat.h>
00031 
00032 #include <string>
00033 #include <list>
00034 #include <map>
00035 #include <iostream>
00036 #include <sstream>
00037 #include <algorithm>
00038 #include <exception>
00039 
00040 #ifdef WITH_LIBBATCH
00041 #include <Batch/Batch_Job.hxx>
00042 #include <Batch/Batch_Date.hxx>
00043 #include <Batch/Batch_JobId.hxx>
00044 #include <Batch/Batch_EmulationException.hxx>
00045 #endif
00046 
00047 #include <libxml/parser.h>
00048 
00049 namespace Launcher
00050 {
00051   class LAUNCHER_EXPORT Job
00052   {
00053     public:
00054       Job();
00055       virtual ~Job();
00056 
00057       // Launcher managing parameters
00058       // State of a Job: CREATED, IN_PROCESS, QUEUED, RUNNING, PAUSED, FINISHED, ERROR
00059       void setState(const std::string & state);
00060       std::string getState();
00061 
00062       void setNumber(const int & number);
00063       int getNumber();
00064 
00065       virtual void setResourceDefinition(const ParserResourcesType & resource_definition);
00066       ParserResourcesType getResourceDefinition();
00067 
00068       // Common parameters
00069       void setJobName(const std::string & job_name);
00070       virtual void setJobFile(const std::string & job_file);
00071       void setWorkDirectory(const std::string & work_directory);
00072       void setLocalDirectory(const std::string & local_directory);
00073       void setResultDirectory(const std::string & result_directory);
00074       void add_in_file(const std::string & file);
00075       void add_out_file(const std::string & file);
00076       void setMaximumDuration(const std::string & maximum_duration);
00077       void setResourceRequiredParams(const resourceParams & resource_required_params);
00078       void setQueue(const std::string & queue);
00079       void setEnvFile(const std::string & env_file);
00080 
00081       std::string getJobName();
00082       std::string getJobFile();
00083       std::string getWorkDirectory();
00084       std::string getLocalDirectory();
00085       std::string getResultDirectory();
00086       const std::list<std::string> & get_in_files();
00087       const std::list<std::string> & get_out_files();
00088       std::string getMaximumDuration();
00089       resourceParams getResourceRequiredParams();
00090       std::string getQueue();
00091       std::string getEnvFile();
00092       std::string getJobType();
00093 
00094       std::string updateJobState();
00095 
00096       void addSpecificParameter(const std::string & name,
00097                                   const std::string & value);
00098       const std::map<std::string, std::string> & getSpecificParameters();
00099       virtual void checkSpecificParameters();
00100 
00101       // Checks
00102       void checkMaximumDuration(const std::string & maximum_duration);
00103       void checkResourceRequiredParams(const resourceParams & resource_required_params);
00104 
00105       // Helps
00106       long convertMaximumDuration(const std::string & maximum_duration);
00107       std::string getLaunchDate();
00108 
00109       // Xml method
00110       void addToXmlDocument(xmlNodePtr root_node);
00111 
00112       void stopJob();
00113       void removeJob();
00114 
00115       // Abstract class
00116       virtual void update_job() = 0;
00117 
00118     protected:
00119       int _number;
00120 
00121       std::string _job_type;
00122 
00123       std::string _state;
00124       std::string _launch_date;
00125       std::string _env_file;
00126 
00127       ParserResourcesType _resource_definition;
00128 
00129       std::string _job_name;
00130       std::string _job_file;
00131       std::string _job_file_name;
00132       std::string _job_file_name_complete;
00133 
00134       std::string _work_directory;
00135       std::string _local_directory;
00136       std::string _result_directory;
00137       std::list<std::string> _in_files;
00138       std::list<std::string> _out_files;
00139       std::map<std::string, std::string> _specific_parameters;
00140       std::string _maximum_duration;
00141       long _maximum_duration_in_second;
00142       resourceParams _resource_required_params;
00143       std::string _queue;
00144 
00145 #ifdef WITH_LIBBATCH
00146     // Connection with LIBBATCH
00147     public:      
00148       Batch::Job * getBatchJob();
00149       Batch::Parametre common_job_params();
00150       void setBatchManagerJobId(Batch::JobId batch_manager_job_id);
00151       Batch::JobId getBatchManagerJobId();
00152 
00153     protected:
00154       Batch::Job * _batch_job;
00155       Batch::JobId _batch_job_id;
00156 #endif
00157   };
00158 }
00159 
00160 #endif
00161