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.
- #log_current_server_store(handler_name) ⇒ Object
- #sanitized_connection_parameters(params) ⇒ Object
- #sanitized_servers_array(server_array) ⇒ Object
- #update_servers(connection, handler_name = "unspecified handler") ⇒ 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
37 38 39 40 41 42 43 44 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 37 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 |
#log_current_server_store(handler_name) ⇒ Object
46 47 48 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 46 def log_current_server_store(handler_name) logger.info("#{log_prefix(__callee__)} Current servers cache: #{sanitized_servers_array(@servers)} for #{handler_name}") end |
#sanitized_connection_parameters(params) ⇒ Object
54 55 56 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 54 def sanitized_connection_parameters(params) params.reject { |k, _v| k.to_s == "password" } end |
#sanitized_servers_array(server_array) ⇒ Object
50 51 52 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 50 def sanitized_servers_array(server_array) server_array.collect { |p| sanitized_connection_parameters(p) } end |
#update_servers(connection, handler_name = "unspecified handler") ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/manageiq/postgres_ha_admin/server_store.rb', line 25 def update_servers(connection, handler_name = "unspecified handler") new_servers = query_repmgr(connection) if servers_changed?(new_servers) log_current_server_store(handler_name) logger.info("#{log_prefix(__callee__)} Updating servers cache to #{sanitized_servers_array(new_servers)} for #{handler_name}") @servers = new_servers end rescue IOError => err logger.error("#{log_prefix(__callee__)} #{err.class}: #{err}") logger.error(err.backtrace.join("\n")) end |