Class: ManageIQ::PostgresHaAdmin::ServerStore
- Inherits:
-
Object
- Object
- ManageIQ::PostgresHaAdmin::ServerStore
- Includes:
- Logging
- Defined in:
- lib/manageiq/postgres_ha_admin/server_store.rb
Constant Summary collapse
- TABLE_NAME =
"repmgr.nodes".freeze
Instance Attribute Summary collapse
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
Instance Method Summary collapse
- #connection_info_list ⇒ Object
- #host_is_primary?(host, connection) ⇒ Boolean
-
#initialize ⇒ ServerStore
constructor
A new instance of ServerStore.
- #update_servers(connection) ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ ServerStore
Returns a new instance of ServerStore.
14 15 16 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 14 def initialize @servers = [] end |
Instance Attribute Details
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
12 13 14 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 12 def servers @servers end |
Instance Method Details
#connection_info_list ⇒ Object
18 19 20 21 22 23 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 18 def connection_info_list valid_keys = PG::Connection.conndefaults_hash.keys + [:requiressl] servers.map! do |db_info| db_info.keep_if { |k, _v| valid_keys.include?(k) } end end |
#host_is_primary?(host, connection) ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 36 def host_is_primary?(host, connection) query_repmgr(connection).each do |record| if record[:host] == host && record[:type] == 'primary' return true end end false end |
#update_servers(connection) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 25 def update_servers(connection) new_servers = query_repmgr(connection) if servers_changed?(new_servers) logger.info("Updating servers cache to #{new_servers}") @servers = new_servers end rescue IOError => err logger.error("#{err.class}: #{err}") logger.error(err.backtrace.join("\n")) end |