Back to index

nordugrid-arc-nox  1.1.0~rc6
states.h
Go to the documentation of this file.
00001 #ifndef GRID_MANAGER_STATES_H
00002 #define GRID_MANAGER_STATES_H
00003 
00004 #include <sys/types.h>
00005 #include <list>
00006 #include "../jobs/job.h"
00007 
00008 /* default job ttl after finished - 1 week */
00009 #define DEFAULT_KEEP_FINISHED (7*24*60*60)
00010 /* default job ttr after deleted - 1 month */
00011 #define DEFAULT_KEEP_DELETED (30*24*60*60)
00012 /* default maximal number of jobs in memory */
00013 #define DEFAULT_MAX_JOBS (100)
00014 /* default maximal allowed amount of reruns */
00015 #define DEFAULT_JOB_RERUNS (5)
00016 /* not used */
00017 #define DEFAULT_DISKSPACE (200*1024L*1024L)
00018 /* default maximum down/upload retries */
00019 #define DEFAULT_MAX_RETRIES (10)
00020 
00021 class JobUser;
00022 class JobLocalDescription;
00023 class ContinuationPlugins;
00024 class RunPlugin;
00025 
00026 /*
00027 typedef struct {
00028   job_state_t id;
00029   char* str;
00030   char mail_flag;
00031 } job_state_rec_t;
00032 */
00033 
00034 /*
00035   List of jobs. This object is cross-linked to JobUser object, which
00036   represents owner of these jobs.
00037   Static members of this class store global parameters. In a future
00038   some of them can become user/job list specific.
00039 */
00040 class JobsList {
00041  public:
00042   typedef std::list<JobDescription>::iterator iterator;
00043  private:
00044   /* these static members should be protected by lock, but job
00045      status change is single threaded, so not yet */
00046   /* number of jobs for every state */
00047   static int jobs_num[JOB_STATE_NUM];
00048   static int jobs_pending;
00049   /* maximal allowed values */
00050   static int max_jobs_running;
00051   static int max_jobs_processing;
00052   static int max_jobs_processing_emergency;
00053   static int max_jobs;
00054   static unsigned int max_processing_share;
00055   static std::string share_type;
00056   static unsigned long long int min_speed;
00057   static time_t min_speed_time;
00058   static unsigned long long int min_average_speed;
00059   static time_t max_inactivity_time;
00060   static int max_downloads;
00061   static int max_retries;
00062   static bool use_secure_transfer;
00063   static bool use_passive_transfer;
00064   static bool use_local_transfer;
00065   static unsigned int wakeup_period;
00066   std::list<JobDescription> jobs;
00067  /* the list of shares with defined limits */
00068   static std::map<std::string, int> limited_share;
00069  /* counters of share for preparing/finishing states */
00070   std::map<std::string, int> preparing_job_share;
00071   std::map<std::string, int> finishing_job_share;
00072  /* current max share for preparing/finishing */
00073   std::map<std::string, int> preparing_max_share;
00074   std::map<std::string, int> finishing_max_share;
00075   JobUser *user;
00076   ContinuationPlugins *plugins;
00077   /* Add job into list without checking if it is already there
00078      'i' will be set to iterator pointing at new job */
00079   bool AddJobNoCheck(const JobId &id,iterator &i,uid_t uid,gid_t gid);
00080   bool AddJobNoCheck(const JobId &id,uid_t uid,gid_t gid);
00081   /* Perform all actions necessary in case of job failure */
00082   bool FailedJob(const iterator &i);
00083   /*
00084      Remove Job from list. All corresponding files are deleted 
00085      and pointer is advanced. 
00086      if finished is not set - job is in not destroyed if it is FINISHED
00087      if active is not set - job is not destroyed if it is not UNDEFINED
00088   */
00089   bool DestroyJob(iterator &i,bool finished=true,bool active=true);
00090   /* Perform actions necessary in case job goes to/is in
00091      SUBMITTING/CANCELING state */
00092   bool state_submitting(const iterator &i,bool &state_changed,bool cancel=false);
00093   /* Same for PREPARING/FINISHING */
00094   bool state_loading(const iterator &i,bool &state_changed,bool up,bool &retry);
00095   bool JobPending(JobsList::iterator &i);
00096   job_state_t JobFailStateGet(const iterator &i);
00097   bool JobFailStateRemember(const iterator &i,job_state_t state);
00098   bool RecreateTransferLists(const JobsList::iterator &i);
00099  public:
00100   /* Constructor. 'user' contains associated user */ 
00101   JobsList(JobUser &user,ContinuationPlugins &plugins);
00102   ~JobsList(void);
00103   iterator FindJob(const JobId &id);
00104   iterator begin(void) { return jobs.begin(); };
00105   iterator end(void) { return jobs.end(); };
00106   size_t size(void) const { return jobs.size(); };
00107   static void SetMaxJobs(int max = -1,int max_running = -1) {
00108     max_jobs=max;
00109     max_jobs_running=max_running;
00110   };
00111   static void SetMaxJobsLoad(int max_processing = -1,int max_processing_emergency = 1,int max_down = -1) {
00112     max_jobs_processing=max_processing;
00113     max_jobs_processing_emergency=max_processing_emergency;
00114     max_downloads=max_down;
00115   };
00116   static void GetMaxJobs(int &max,int &max_running) {
00117     max=max_jobs;
00118     max_running=max_jobs_running;
00119   };
00120   static void GetMaxJobsLoad(int &max_processing,int &max_processing_emergency,int &max_down) {
00121     max_processing=max_jobs_processing;
00122     max_processing_emergency=max_jobs_processing_emergency;
00123     max_down=max_downloads;
00124   };
00125   static void SetSpeedControl(unsigned long long int min=0,time_t min_time=300,unsigned long long int min_average=0,time_t max_time=300) {
00126     min_speed = min;
00127     min_speed_time = min_time;
00128     min_average_speed = min_average;
00129     max_inactivity_time = max_time;
00130   };
00131   static void SetSecureTransfer(bool val) {
00132     use_secure_transfer=val;
00133   };
00134   static void SetPassiveTransfer(bool val) {
00135     use_passive_transfer=val;
00136   };
00137   static void SetLocalTransfer(bool val) {
00138     use_local_transfer=val;
00139   };
00140   static void SetWakeupPeriod(unsigned int t) { wakeup_period=t; };
00141   static unsigned int WakeupPeriod(void) { return wakeup_period; };
00142   static void SetMaxRetries(int r) {JobsList::max_retries = r; };
00143   static int MaxRetries() { return JobsList::max_retries; };
00144   static void SetTransferShare(unsigned int max_share, std::string type){
00145     max_processing_share = max_share;
00146     share_type = type;
00147   };
00148   static bool AddLimitedShare(std::string share_name, unsigned int share_limit) {
00149     if(max_processing_share == 0)
00150       return false;
00151     if(share_limit == 0)
00152       share_limit = max_processing_share;
00153     limited_share[share_name] = share_limit;
00154     return true;
00155   }
00156 
00157  /* Add job to list */
00158   bool AddJob(JobUser &user,const JobId &id,uid_t uid,gid_t gid);
00159   bool AddJob(const JobId &id,uid_t uid,gid_t gid);
00160   /* Analyze current state of job, perform necessary actions and
00161      advance state or remove job if needed. Iterator 'i' is 
00162      advanced inside this function */
00163   bool ActJob(const JobId &id,bool hard_job = false); /* analyze job */
00164   bool ActJob(iterator &i,bool hard_job = false); /* analyze job */
00165   void CalculateShares();
00166   bool ActJobs(bool hard_job = false); /* analyze all jobs */
00167   /* Look for new (or old FINISHED) jobs. Jobs are added to list
00168      with state undefined */
00169   bool ScanNewJobs(bool hard_job = false);
00170   /*
00171     Destroy all jobs in list according to 'finished' an 'active'.
00172     (See DestroyJob).
00173   */
00174   bool DestroyJobs(bool finished=true,bool active=true);
00175   /* (See GetLocalDescription of JobDescription object) */
00176   bool GetLocalDescription(const JobsList::iterator &i);
00177   void ActJobUndefined(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00178   void ActJobAccepted(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00179   void ActJobPreparing(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00180   void ActJobSubmitting(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00181   void ActJobCanceling(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00182   void ActJobInlrms(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00183   void ActJobFinishing(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00184   void ActJobFinished(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00185   void ActJobDeleted(iterator &i,bool hard_job,bool& once_more,bool& delete_job,bool& job_error,bool& state_changed);
00186 
00187 };
00188 
00189 #endif
00190 
00191