Class: ManageIQ::PostgresHaAdmin::FailoverDatabases
- Inherits:
-
Object
- Object
- ManageIQ::PostgresHaAdmin::FailoverDatabases
- Defined in:
- lib/manageiq/postgres_ha_admin/failover_databases.rb
Constant Summary collapse
- TABLE_NAME =
"repmgr.nodes".freeze
Instance Attribute Summary collapse
-
#yml_file ⇒ Object
readonly
Returns the value of attribute yml_file.
Instance Method Summary collapse
- #active_databases ⇒ Object
- #active_databases_conninfo_hash ⇒ Object
- #host_is_repmgr_primary?(host, connection) ⇒ Boolean
-
#initialize(yml_file, logger) ⇒ FailoverDatabases
constructor
A new instance of FailoverDatabases.
- #update_failover_yml(connection) ⇒ Object
Constructor Details
#initialize(yml_file, logger) ⇒ FailoverDatabases
Returns a new instance of FailoverDatabases.
12 13 14 15 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 12 def initialize(yml_file, logger) @yml_file = yml_file @logger = logger end |
Instance Attribute Details
#yml_file ⇒ Object (readonly)
Returns the value of attribute yml_file.
10 11 12 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 10 def yml_file @yml_file end |
Instance Method Details
#active_databases ⇒ Object
24 25 26 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 24 def active_databases all_databases.select { |record| record[:active] } end |
#active_databases_conninfo_hash ⇒ Object
17 18 19 20 21 22 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 17 def active_databases_conninfo_hash valid_keys = PG::Connection.conndefaults_hash.keys + [:requiressl] active_databases.map! do |db_info| db_info.keep_if { |k, _v| valid_keys.include?(k) } end end |
#host_is_repmgr_primary?(host, connection) ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 36 def host_is_repmgr_primary?(host, connection) query_repmgr(connection).each do |record| if record[:host] == host && entry_is_active_master?(record) return true end end false end |
#update_failover_yml(connection) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/manageiq/postgres_ha_admin/failover_databases.rb', line 28 def update_failover_yml(connection) arr_yml = query_repmgr(connection) File.write(yml_file, arr_yml.to_yaml) unless arr_yml.empty? rescue IOError => err @logger.error("#{err.class}: #{err}") @logger.error(err.backtrace.join("\n")) end |