Back to index

nordugrid-arc-nox  1.1.0~rc6
users.h
Go to the documentation of this file.
00001 #ifndef GRID_MANAGER_USERS_H
00002 #define GRID_MANAGER_USERS_H
00003 
00004 #include <sys/types.h>
00005 #include <string>
00006 #include <list>
00007 
00008 #include <arc/Run.h>
00009 
00010 #include "../conf/conf_cache.h"
00011 
00012 class JobsList;
00013 class RunPlugin;
00014 
00015 class JobUser;
00016 
00017 /*
00018   Object to run external processes associated with user (helper)
00019 */
00020 class JobUserHelper {
00021  private:
00022   /* command beeing run */
00023   std::string command;
00024   /* object representing running process */
00025   Arc::Run *proc;
00026  public:
00027   JobUserHelper(const std::string &cmd);
00028   ~JobUserHelper(void);
00029   /* start process if it is not running yet */
00030   bool run(JobUser &user);
00031 };
00032 
00033 /*
00034   Description of user - owner of jobs
00035 */
00036 class JobUser {
00037  public:
00038   typedef enum {
00039     jobinfo_share_private = 0,
00040     jobinfo_share_group = 1,
00041     jobinfo_share_all = 2
00042   } jobinfo_share_t;
00043  private:
00044   /* directory where files explaining jobs are stored */
00045   std::string control_dir;
00046   /* directories where directories used to run jobs are created */
00047   std::vector<std::string> session_roots;
00048   /* cache information */
00049   CacheConfig * cache_params;
00050   /* default LRMS and queue to use */
00051   std::string default_lrms;
00052   std::string default_queue;
00053   /* local name, home directory, uid and gid of this user */
00054   std::string unix_name;
00055   std::string home;
00056   uid_t uid;
00057   gid_t gid;
00058   jobinfo_share_t sharelevel;
00059   /* How long jobs are kept after job finished. This is 
00060      default and maximal value. */
00061   time_t keep_finished;
00062   time_t keep_deleted;
00063   bool strict_session;
00064   /* Maximal value of times job is allowed to be rerun. 
00065      Default is 0. */
00066   int reruns;
00067   /* not used */
00068   unsigned long long int diskspace;
00069   /* if this object is valid */
00070   bool valid;
00071   /* list of associated external processes */
00072   std::list<JobUserHelper> helpers;
00073   /* List of jobs belonging to this user */
00074   JobsList *jobs;    /* filled by external functions */
00075   RunPlugin* cred_plugin;
00076  public:
00077   JobsList* get_jobs() const { 
00078     return jobs;
00079   };
00080   void operator=(JobsList *jobs_list) { 
00081     jobs=jobs_list;
00082   };
00083   JobUser(void);
00084   JobUser(const std::string &unix_name,RunPlugin* cred_plugin = NULL);
00085   JobUser(uid_t uid,RunPlugin* cred_plugin = NULL);
00086   JobUser(const JobUser &user);
00087   ~JobUser(void);
00088   /* Set and get corresponding private values */
00089   void SetControlDir(const std::string &dir);
00090   void SetSessionRoot(const std::string &dir);
00091   void SetSessionRoot(const std::vector<std::string> &dirs);
00092   void SetCacheParams(CacheConfig* params);
00093   void SetLRMS(const std::string &lrms_name,const std::string &queue_name);
00094   void SetKeepFinished(time_t ttl) { keep_finished=ttl; };
00095   void SetKeepDeleted(time_t ttr) { keep_deleted=ttr; };
00096   void SetReruns(int n) { reruns=n; };
00097   void SetDiskSpace(unsigned long long int n) { diskspace=n; };
00098   void SetStrictSession(bool v) { strict_session=v; };
00099   void SetShareLevel(jobinfo_share_t s) { sharelevel=s; };
00100   bool CreateDirectories(void);
00101   bool is_valid(void) { return valid; };
00102   const std::string & ControlDir(void) const { return control_dir; };
00103   const std::string & SessionRoot(std::string job_id = "") const;
00104   const std::vector<std::string> & SessionRoots() const { return session_roots; };
00105   CacheConfig * CacheParams(void) const { return cache_params; };
00106   bool CachePrivate(void) const { return false; };
00107   const std::string & DefaultLRMS(void) const { return default_lrms; };
00108   const std::string & DefaultQueue(void) const { return default_queue; };
00109   const std::string & UnixName(void) const { return unix_name; };
00110   const std::string & Home(void) const { return home; };
00111   time_t KeepFinished(void) const { return keep_finished; };
00112   time_t KeepDeleted(void) const { return keep_deleted; };
00113   bool StrictSession(void) const { return strict_session; };
00114   jobinfo_share_t ShareLevel(void) const { return sharelevel; };
00115   uid_t get_uid(void) const { return uid; };
00116   gid_t get_gid(void) const { return gid; };
00117   int Reruns(void) const { return reruns; };
00118   RunPlugin* CredPlugin(void) { return cred_plugin; };
00119   unsigned long long int DiskSpace(void) { return diskspace; };
00120   bool operator==(std::string name) { return (name == unix_name); };
00121   /* Change owner of the process to this user if su=true.
00122      Otherwise just set environment variables USER_ID and USER_NAME */
00123   bool SwitchUser(bool su = true) const;
00124   void add_helper(const std::string &helper) {
00125     helpers.push_back(JobUserHelper(helper));
00126   };
00127   bool has_helpers(void) { return (helpers.size() != 0); };
00128   /* Start/restart all helper processes */
00129   bool run_helpers(void);
00130   bool substitute(std::string& param) const;
00131 };
00132 
00133 /*
00134   List of users serviced by grid-manager.
00135   Just wrapper around 'list<JobUser>' with little additional
00136   functionality.
00137 */
00138 class JobUsers {
00139  private:
00140   std::list<JobUser> users;
00141  public:
00142   typedef std::list<JobUser>::iterator iterator;
00143   typedef std::list<JobUser>::const_iterator const_iterator;
00144   JobUsers(void);
00145   ~JobUsers(void);
00146   iterator begin(void) { return users.begin(); };
00147   const_iterator begin(void) const { return users.begin(); };
00148   iterator end(void) { return users.end(); };
00149   const_iterator end(void) const { return users.end(); };
00150   size_t size(void) const { return users.size(); };
00151   /* Create new user object and push into list */
00152   iterator AddUser(const std::string &unix_name,RunPlugin* cred_plugin = NULL,const std::string &control_dir = "",const std::vector<std::string> *session_root = NULL);
00153   iterator DeleteUser(iterator &user) { return users.erase(user); };
00154   /* Check existance of user of given unix name */
00155   bool HasUser(const std::string &name) {
00156     for(iterator i=users.begin();i!=users.end();++i)
00157       if((*i) == name) return true;
00158     return false;
00159   };
00160   std::string ControlDir(iterator user);
00161   std::string ControlDir(const std::string user);
00162   /* Find user of given unix name */
00163   iterator find(const std::string user);
00164   /* Start/restart all associated processes of all users */
00165   bool run_helpers(void);
00166   bool substitute(std::string& param) const;
00167 };
00168 
00169 #endif