Back to index

nordugrid-arc-nox  1.1.0~rc6
job.h
Go to the documentation of this file.
00001 #ifndef GRID_MANAGER_JOB_H
00002 #define GRID_MANAGER_JOB_H
00003 
00004 #include <sys/types.h>
00005 #include <string>
00006 
00007 #include <arc/Run.h>
00008 
00009 class JobsList;
00010 class JobLocalDescription;
00011 class JobUser;
00012 
00013 typedef enum {
00014   JOB_STATE_ACCEPTED   = 0,
00015   JOB_STATE_PREPARING  = 1,
00016   JOB_STATE_SUBMITTING = 2,
00017   JOB_STATE_INLRMS     = 3,
00018   JOB_STATE_FINISHING  = 4,
00019   JOB_STATE_FINISHED   = 5,
00020   JOB_STATE_DELETED    = 6,
00021   JOB_STATE_CANCELING  = 7,
00022   JOB_STATE_UNDEFINED  = 8
00023 } job_state_t;
00024 
00025 typedef struct {
00026   job_state_t id;
00027   const char* name;
00028   char mail_flag;
00029 } job_state_rec_t;
00030 
00031 extern job_state_rec_t states_all[JOB_STATE_UNDEFINED+1];
00032 
00033 #define JOB_STATE_NUM (JOB_STATE_UNDEFINED+1)
00034 
00035 /* all states under control */
00036 #define JOB_NUM_ACCEPTED (\
00037   jobs_num[JOB_STATE_ACCEPTED] + \
00038   jobs_num[JOB_STATE_PREPARING] + \
00039   jobs_num[JOB_STATE_SUBMITTING] + \
00040   jobs_num[JOB_STATE_INLRMS] + \
00041   jobs_num[JOB_STATE_FINISHING] + \
00042   jobs_pending \
00043 )
00044 
00045 /* states running something heavy on frontend */
00046 #define JOB_NUM_PROCESSING (\
00047   jobs_num[JOB_STATE_PREPARING] + \
00048   jobs_num[JOB_STATE_FINISHING] \
00049 )
00050 
00051 #define JOB_NUM_PREPARING (\
00052   jobs_num[JOB_STATE_PREPARING] \
00053 )
00054 
00055 #define JOB_NUM_FINISHING (\
00056   jobs_num[JOB_STATE_FINISHING] \
00057 )
00058 
00059 /* states doing their job mostly on computing nodes */
00060 #define JOB_NUM_RUNNING (\
00061   jobs_num[JOB_STATE_SUBMITTING] + \
00062   jobs_num[JOB_STATE_INLRMS] \
00063 )
00064 
00065 /*
00066   Jobs identifier. Stored as string. Normally is a big number.
00067 */
00068 typedef std::string JobId;
00069 
00070 /*
00071   Object to represent job in memory.
00072 */
00073 class JobDescription {
00074  friend class JobsList;
00075  private:
00076   /* state of the job (state machine) */
00077   job_state_t job_state;
00078   /* flag to indicate job stays at this stage due to limits imposed
00079      such jobs are not counted in couters */
00080   bool job_pending; 
00081   /* identifier */
00082   JobId job_id;
00083   /* directory to run job in */
00084   std::string session_dir;
00085   /* explanation of job's failure */
00086   std::string failure_reason;
00087   /* how long job is kept on cluster after it finished */
00088   time_t keep_finished;
00089   time_t keep_deleted;
00090   /* pointer to object containing most important parameters of job,
00091      loaded when needed. */
00092   JobLocalDescription* local;
00093   /* uid and gid of job's owner */
00094   uid_t job_uid;
00095   gid_t job_gid;
00096   /* reties left (should be reset for each state change) */
00097   int retries;
00098   /* time to perform the next retry */
00099   time_t next_retry;
00100   /* used to determine data transfer share (eg DN, VOMS VO) */
00101   std::string transfer_share;
00102  public:
00103   /* external utility beeing run to perform tasks like stage-in/our, 
00104      submit/cancel. (todo - move to private) */
00105   Arc::Run* child;
00106   /* 
00107     Constructors and destructor.
00108     Accepts:
00109       job_id - identifier
00110       dir - session_dir of job
00111       state - initial state of job
00112   */
00113   JobDescription(void);
00114   JobDescription(const JobDescription &job);
00115   JobDescription(const JobId &job_id,const std::string &dir,job_state_t state = JOB_STATE_UNDEFINED);
00116   ~JobDescription(void);
00117   job_state_t get_state() const { return job_state; };
00118   const char* get_state_name() const;
00119   static const char* get_state_name(job_state_t st);
00120   static job_state_t get_state(const char* state);
00121   const JobId& get_id() const { return job_id; };
00122   std::string SessionDir(void) const { return session_dir; };
00123   void AddFailure(const std::string &reason) {
00124     //if(failure_reason.length()) failure_reason+="\n";
00125     failure_reason+=reason; failure_reason+="\n";
00126   };
00127   const std::string& GetFailure(void) const { return failure_reason; };
00128   JobLocalDescription* get_local(void) const { return local; };
00129   void set_local(JobLocalDescription* desc) { local=desc; };
00130 //  void set_state(job_state_t state) { job_state=state; };
00131   bool operator==(const JobId &id) { return (job_id == id); };
00132   bool operator!=(const JobId &id) { return (job_id != id); };
00133   void set_uid(uid_t uid,gid_t gid) {
00134     if(uid != (uid_t)(-1)) { job_uid=uid; };
00135     if(gid != (uid_t)(-1)) { job_gid=gid; };
00136   };
00137   uid_t get_uid(void) const { return job_uid; };
00138   gid_t get_gid(void) const { return job_gid; };
00139   void set_share(std::string share);
00140   /* force 'local' to be created and read from file if not already available */
00141   bool GetLocalDescription(const JobUser &user);
00142 };
00143 #endif