Module: Validations
Overview
Common methods used for setting up or verifing
Instance Method Summary collapse
-
#check_backup_path(raise_msg = 'backup_path is not a valid directory') ⇒ Bool
Check that the backup_path is valid.
-
#check_mogile_domain(domain, raise_msg = 'Domain does not exist in MogileFS') ⇒ Bool
Check if mogile domain is valid.
-
#check_settings_file(raise_msg = 'settings.yml not found in path. This must not be a backup profile. See: mogbak help create') ⇒ Bool
Check that the settings.yml file exists in the backup_path.
-
#connect_sqlite(raise_msg = nil) ⇒ Bool
Connect to sqlite metadata db.
-
#create_sqlite_db(raise_msg = "Could not create #{$backup_path}/db.sqlite - check permissions") ⇒ Bool
Create database for metadata.
-
#migrate_sqlite(raise_msg = "could not run migrations on #{$backup_path}/db.sqlite") ⇒ Bool
Run ActiveRecord migrations on the sqlite database.
-
#mogile_db_connect(raise_msg = 'Could not connect to MySQL database') ⇒ Bool
Connect to MogileFS mysql server.
-
#mogile_tracker_connect(raise_msg = 'Could not connect to MogileFS tracker') ⇒ Bool
Connect to mogile tracker.
Instance Method Details
#check_backup_path(raise_msg = 'backup_path is not a valid directory') ⇒ Bool
Check that the backup_path is valid
20 21 22 23 24 25 26 |
# File 'lib/validations.rb', line 20 def check_backup_path(raise_msg = 'backup_path is not a valid directory') if !File.directory?($backup_path) raise raise_msg if raise_msg return false end true end |
#check_mogile_domain(domain, raise_msg = 'Domain does not exist in MogileFS') ⇒ Bool
Check if mogile domain is valid
110 111 112 113 114 115 116 117 118 |
# File 'lib/validations.rb', line 110 def check_mogile_domain(domain, raise_msg = 'Domain does not exist in MogileFS') require('domain') domain = Domain.find_by_namespace(self.domain) if !domain raise raise_msg if raise_msg return false end true end |
#check_settings_file(raise_msg = 'settings.yml not found in path. This must not be a backup profile. See: mogbak help create') ⇒ Bool
Check that the settings.yml file exists in the backup_path
7 8 9 10 11 12 13 14 |
# File 'lib/validations.rb', line 7 def check_settings_file(raise_msg = 'settings.yml not found in path. This must not be a backup profile. See: mogbak help create') if File.exists?("#{$backup_path}/settings.yml") return true else raise raise_msg if raise_msg return false end end |
#connect_sqlite(raise_msg = nil) ⇒ Bool
Connect to sqlite metadata db
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/validations.rb', line 46 def connect_sqlite(raise_msg = nil) begin ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{$backup_path}/db.sqlite", :timeout => 10000) rescue Exception => e raise raise_msg if raise_msg raise e if $debug return false end true end |
#create_sqlite_db(raise_msg = "Could not create #{$backup_path}/db.sqlite - check permissions") ⇒ Bool
Create database for metadata
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/validations.rb', line 31 def create_sqlite_db(raise_msg = "Could not create #{$backup_path}/db.sqlite - check permissions") begin if !File.exists?("#{$backup_path}/db.sqlite") SQLite3::Database.new("#{$backup_path}/db.sqlite") end rescue Exception => e raise raise_msg if raise_msg return false end true end |
#migrate_sqlite(raise_msg = "could not run migrations on #{$backup_path}/db.sqlite") ⇒ Bool
Run ActiveRecord migrations on the sqlite database
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/validations.rb', line 60 def migrate_sqlite(raise_msg = "could not run migrations on #{$backup_path}/db.sqlite") #run migrations begin ActiveRecord::Migrator.up(File.(File.dirname(__FILE__)) + '/../db/migrate/') rescue raise raise_msg if raise_msg return false end true end |
#mogile_db_connect(raise_msg = 'Could not connect to MySQL database') ⇒ Bool
Connect to MogileFS mysql server
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/validations.rb', line 74 def mogile_db_connect(raise_msg = 'Could not connect to MySQL database') #Verify that we can connect to the mogilefs mysql server begin ActiveRecord::Base.establish_connection({:adapter => "mysql2", :host => @db_host, :port => @db_port, :username => @db_user, :password => @db_pass, :database => @db, :reconnect => true}) rescue Exception => e raise raise_msg if raise_msg return false end true end |
#mogile_tracker_connect(raise_msg = 'Could not connect to MogileFS tracker') ⇒ Bool
Connect to mogile tracker
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/validations.rb', line 94 def mogile_tracker_connect(raise_msg = 'Could not connect to MogileFS tracker') host = ["#{@tracker_ip}:#{@tracker_port}"] begin $mg = MogileFS::MogileFS.new(:domain => @domain, :hosts => host) rescue Exception => e if $debug raise e end raise raise_msg if raise_msg return false end end |