rvm 1.08

rconfig.h

Go to the documentation of this file.
00001 #ifndef __rconfig_h__
00002 #define __rconfig_h__
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009 
00010 #include "asserts.h"
00011 #include "types.h"
00012 #include "tstamp.h"
00013 
00014 //----------------------------------------------------------------------------
00015 
00016 class parser;
00017 class parse_job;
00018 
00019 /** A configuration manager support class:
00020         Used to specify a single subdirectory in a path of subdirectory names for a
00021         unique path under the archive directory for each job
00022         */
00023 class archive_path_element
00024 {
00025 public:
00026         enum element_type {
00027                 jobname,
00028                 groupname,
00029                 hostname,
00030                 pathname,
00031                 permutation,
00032                 literal
00033         };
00034 
00035         void clear(void);
00036 
00037         archive_path_element();
00038         archive_path_element(const archive_path_element& a_class);
00039         archive_path_element(const element_type& a_enum);
00040         archive_path_element(const std::string& a_str);
00041 
00042         void assign(const archive_path_element& a_class);
00043         void assign(const element_type& a_enum);
00044         void assign(const std::string& a_str);
00045 
00046         const element_type& type(void) const;
00047         const std::string& value(void) const;
00048         const std::string str(void) const;
00049 
00050         archive_path_element& operator=(const archive_path_element& a_class);
00051         archive_path_element& operator=(const element_type a_enum);
00052         archive_path_element& operator=(const std::string& a_str);
00053 
00054 private:
00055         element_type m_type;
00056         std::string m_literal;
00057 };
00058 
00059 /** A configuration manager support class:
00060         Used to specify a unique subdirectory in the archive for each job (made up
00061         of archive_path_element's)
00062  */
00063 class archive_path : public std::vector<archive_path_element>
00064 {
00065 public:
00066         typedef std::vector<archive_path_element> type;
00067 
00068         void reset(void);
00069 
00070         archive_path();
00071         archive_path(const archive_path& a_class);
00072         archive_path(const archive_path_element& a_class);
00073         archive_path(const std::string& a_class);
00074 
00075         void push_back(const archive_path& a_class);
00076         void push_back(const archive_path_element& a_class);
00077         void push_back(const std::string& a_str);
00078 
00079         void assign(const archive_path& a_class);
00080         void assign(const archive_path_element& a_class);
00081         void assign(const std::string& a_str);
00082 
00083         const std::string str(void) const;
00084 
00085         archive_path& operator=(const archive_path& a_class);
00086         archive_path& operator=(const archive_path_element& a_class);
00087         archive_path& operator=(const std::string& a_str);
00088 
00089 private:
00090 };
00091 
00092 /** A configuration manager support class:
00093         Used to map rsync exit codes to actions for rvm to take
00094  */
00095 class rsync_behavior
00096 {
00097 public:
00098         enum behavior_type {
00099                 quit,
00100                 fail,
00101                 retry,
00102                 retry_without_hardlinks,
00103                 ok
00104         };
00105         typedef behavior_type value_type;
00106         typedef std::map<uint16, value_type> map_type;
00107         static const uint16 default_behavior = ((uint16)-1);
00108 
00109         void clear(void);
00110         void reset(void);
00111 
00112         rsync_behavior();
00113         rsync_behavior(const rsync_behavior& a_class);
00114 
00115         void assign(const uint16 a_code, const value_type a_action);
00116         void assign(const rsync_behavior& a_class);
00117         void assign(const std::string& a_str);
00118 
00119         const value_type operator[](const uint16 a_code) const;
00120         value_type& operator[](const uint16 a_code);
00121         rsync_behavior& operator=(const rsync_behavior& a_class);
00122         rsync_behavior& operator=(const value_type a_enum);
00123         rsync_behavior& operator=(const std::string& a_str);
00124 
00125         const value_type default_value(void) const;
00126         const map_type& map_value(void) const;
00127 
00128 private:
00129         map_type m_map;
00130         value_type m_default;
00131 };
00132 
00133 class configuration_manager;
00134 
00135 /** Hold configuration data for a single job */
00136 class job
00137 {
00138 public:
00139         enum rsync_connection_type {
00140                 connection_remote,
00141                 connection_local,
00142                 connection_server
00143         };
00144         enum rsync_behavior_type {
00145                 behavior_ok,
00146                 behavior_fail,
00147                 behavior_retry,
00148                 behavior_retry_without_hardlinks
00149         };
00150         typedef std::vector<std::string> excludes_type;
00151         typedef std::vector<std::string> includes_type;
00152         typedef std::vector<std::string> paths_type;
00153 
00154         job();
00155         job(const job& a_job);
00156 
00157         void clear(void);
00158         void assign(const job& a_job);
00159 
00160         job& operator=(const job& a_job);
00161 
00162         std::string default_config_path;
00163         uint16 default_config_line;
00164         std::string config_path;
00165         uint16 config_line;
00166         class archive_path archive_path;
00167         excludes_type excludes;
00168         includes_type includes;
00169         std::string groupname;
00170         std::string hostname;
00171         std::string jobname;
00172         paths_type paths;
00173         class rsync_behavior rsync_behavior;
00174         rsync_connection_type rsync_connection;
00175         bool rsync_hardlink;
00176         bool rsync_multi_hardlink;
00177         uint16 rsync_multi_hardlink_max;
00178         std::string rsync_options;
00179         std::string rsync_remote_user;
00180         std::string rsync_remote_path;
00181         std::string rsync_remote_module;
00182         uint16 rsync_remote_port;
00183         uint16 rsync_retry_count;
00184         uint16 rsync_retry_delay;
00185         uint16 rsync_timeout;
00186 
00187         const std::string generate_archive_path(const std::string& a_path) const;
00188         const std::string generate_source_path(const std::string& a_path) const;
00189         const std::string generate_job_id(void) const;
00190         const std::vector<std::string> generate_rsync_options_vector(void) const;
00191         const std::string common_pathname(void) const;
00192         void check(void);
00193 
00194 private:
00195 
00196         friend class parser;
00197 };
00198 
00199 /** Keep up with configuration settings for RVM and it's jobs */
00200 class configuration_manager
00201 {
00202 public:
00203         enum action_type {
00204                 action_help,
00205                 action_version,
00206                 action_archive,
00207                 action_relink,
00208                 action_check_config
00209         };
00210         enum cfgfile_type {
00211                 config_file,
00212                 job_file,
00213         };
00214         enum overflow_type {
00215                 overflow_quit,
00216                 overflow_delete_oldest,
00217                 overflow_delete_until_free
00218         };
00219         enum selection_type {
00220                 selection_round_robin,
00221                 selection_max_free
00222         };
00223         enum logging_type {
00224                 logging_manager,
00225                 logging_child,
00226                 logging_rsync
00227         };
00228         typedef std::pair<cfgfile_type, std::string> cfgfile_element;
00229         typedef class std::vector<cfgfile_element> cfgfiles_type;
00230         typedef std::vector<job> jobs_type;
00231         typedef std::vector<std::string> vaults_type;
00232 
00233         void clear(void);
00234 
00235         configuration_manager();
00236 
00237         void init(int argc, char const *argv[]);
00238         void check(void) const;
00239         const bool initialized(void) const;
00240 
00241         const action_type action(void) const;
00242         const bool use_default(void) const;
00243         void default_file(const std::string& a_path);
00244         const std::string& default_file(void) const;
00245         void default_logdir(const std::string& a_path);
00246         const class timestamp& timestamp(void) const;
00247         const std::string& link_catalog_dir(void) const;
00248         const std::string& log_dir(void) const;
00249         const bool delete_old_log_files(void) const;
00250         const bool delete_old_report_files(void) const;
00251         const std::string& rsync_local_path(void) const;
00252         const uint16& rsync_parallel(void) const;
00253         const uint16& io_poll_interval(void) const;
00254         const timestamp::resolution_type timestamp_resolution(void) const;
00255         const vaults_type& vaults(void) const;
00256         const overflow_type& vault_overflow_behavior(void) const;
00257         const uint16& vault_overflow_blocks(void) const;
00258         const uint16& vault_overflow_inodes(void) const;
00259         const selection_type& vault_selection_behavior(void) const;
00260         const bool vault_locking(void) const;
00261         const job& default_job(void) const;
00262         const jobs_type& jobs(void) const;
00263         const logging_type& logging_level(void) const;
00264         const logging_type& error_logging_level(void) const;
00265 
00266 private:
00267         bool m_initialized;
00268         uint16 m_configs_read;
00269         std::string m_default_file;
00270         action_type m_action;
00271         bool m_default;
00272         class timestamp m_timestamp;
00273         cfgfiles_type m_cfgfiles;
00274         std::string m_link_catalog_dir;
00275         std::string m_log_dir;
00276         std::string m_rsync_local_path;
00277         uint16 m_rsync_parallel;
00278         uint16 m_io_poll_interval;
00279         std::vector<std::string> m_vaults;
00280         overflow_type m_vault_overflow_behavior;
00281         uint16 m_vault_overflow_blocks;
00282         uint16 m_vault_overflow_inodes;
00283         selection_type m_vault_selection_behavior;
00284         bool m_vault_locking;
00285         bool m_delete_old_log_files;
00286         bool m_delete_old_report_files;
00287         job m_default_job;
00288         jobs_type m_jobs;
00289         logging_type m_logging_level;
00290         logging_type m_error_logging_level;
00291 
00292         friend class global_parser;
00293         friend class job_parser;
00294 
00295         void read_config(const std::string& a_path);
00296         void read_job(const std::string& a_path);
00297 };
00298 
00299 void parse_line(
00300         std::istream& a_in, 
00301         std::string& a_keyword, 
00302         std::string& a_value
00303         );
00304 
00305 /** A configuration manager support class:
00306         Used to parse a configuration file from the perspective of a global context
00307  */
00308 class global_parser
00309 {
00310 public:
00311         global_parser(
00312                 const std::string& a_path,
00313                 uint16& a_line,
00314                 std::istream& a_in
00315                 );
00316 
00317 private:
00318         const std::string* m_path;
00319         std::istream* m_in;
00320         uint16* m_line;
00321 
00322         const std::string location(void);
00323         void read_config(const std::string& a_path);
00324         void read_job(const std::string& a_path, job& a_job);
00325 
00326         void parse(void);
00327         void parse_default(const std::string& a_value);
00328         void parse_include(const std::string& a_value);
00329         void parse_include_job(const std::string& a_value);
00330         void parse_job(const std::string& a_value);
00331         void parse_link_catalog_dir(const std::string& a_value);
00332         void parse_log_dir(const std::string& a_value);
00333         void parse_delete_old_log_files(const std::string& a_value);
00334         void parse_delete_old_report_files(const std::string& a_value);
00335         void parse_logging_level(const std::string& a_value);
00336         void parse_error_logging_level(const std::string& a_value);
00337         void parse_rsync_local_path(const std::string& a_value);
00338         void parse_rsync_parallel(const std::string& a_value);
00339         void parse_io_poll_interval(const std::string& a_value);
00340         void parse_timestamp_resolution(const std::string& a_value);
00341         void parse_vault(const std::string& a_value);
00342         void parse_vault_overflow_behavior(const std::string& a_value);
00343         void parse_vault_overflow_blocks(const std::string& a_value);
00344         void parse_vault_overflow_inodes(const std::string& a_value);
00345         void parse_vault_selection_behavior(const std::string& a_value);
00346         void parse_vault_locking(const std::string& a_value);
00347 };
00348 
00349 /** A configuration manager support class:
00350         Used to parse a configuration file from the perspective of a job context
00351  */
00352 class job_parser
00353 {
00354 public:
00355         job_parser(
00356                 job * a_job, 
00357                 const std::string& a_path,
00358                 uint16& a_line,
00359                 std::istream& a_in,
00360                 const std::string& a_block_delimiter,
00361                 const bool a_default_context
00362                 );
00363 
00364 private:
00365         job* m_job;
00366         const std::string* m_path;
00367         std::istream* m_in;
00368         uint16* m_line;
00369         const std::string* m_delimiter;
00370         bool m_default_context;
00371 
00372         const std::string location(void);
00373         void read_job(const std::string& a_path);
00374 
00375         void parse(void);
00376         void parse_archive_path(const std::string& a_value);
00377         void parse_clear(const std::string& a_value);
00378         void parse_exclude_from(const std::string& a_value);
00379         void parse_include_from(const std::string& a_value);
00380         void parse_groupname(const std::string& a_value);
00381         void parse_hostname(const std::string& a_value);
00382         void parse_include(const std::string& a_value);
00383         void parse_jobname(const std::string& a_value);
00384         void parse_path(const std::string& a_value);
00385         void parse_rsync_behavior(const std::string& a_value);
00386         void parse_rsync_connection_type(const std::string& a_value);
00387         void parse_rsync_hardlink(const std::string& a_value);
00388         void parse_rsync_multi_hardlink(const std::string& a_value);
00389         void parse_rsync_multi_hardlink_max(const std::string& a_value);
00390         void parse_rsync_options(const std::string& a_value);
00391         void parse_rsync_options_context(const std::string& a_value);
00392         void parse_rsync_remote_user(const std::string& a_value);
00393         void parse_rsync_remote_path(const std::string& a_value);
00394         void parse_rsync_remote_port(const std::string& a_value);
00395         void parse_rsync_remote_module(const std::string& a_value);
00396         void parse_rsync_retry_count(const std::string& a_value);
00397         void parse_rsync_retry_delay(const std::string& a_value);
00398         void parse_rsync_timeout(const std::string& a_value);
00399 };
00400 
00401 extern configuration_manager config;
00402 
00403 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines