Class: Deadpool::FailoverProtocol::Base
- Inherits:
-
Object
- Object
- Deadpool::FailoverProtocol::Base
- Defined in:
- lib/deadpool/failover_protocol.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize(config, failover_config, logger) ⇒ Base
constructor
A new instance of Base.
-
#initiate_failover_protocol! ⇒ Object
Overwrite this if you need to.
-
#preflight_check ⇒ Object
Return true or false Don’t update system state.
-
#promote_to_primary(new_primary) ⇒ Object
Promote the host to primary.
-
#setup ⇒ Object
Implementation specific initialization should be placed here.
-
#system_check ⇒ Object
Perform checks against anything that could cause a failover protocol to fail Perform checks on system state.
Constructor Details
#initialize(config, failover_config, logger) ⇒ Base
Returns a new instance of Base.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/deadpool/failover_protocol.rb', line 13 def initialize(config, failover_config, logger) @name = failover_config[:name].nil? ? '' : failover_config[:name] @state = Deadpool::State.new @name, self.class @config = config @logger = logger @primary_host = @config[:primary_host] @secondary_host = @config[:secondary_host] @failover_config = failover_config setup end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/deadpool/failover_protocol.rb', line 11 def config @config end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/deadpool/failover_protocol.rb', line 10 def logger @logger end |
Instance Method Details
#initiate_failover_protocol! ⇒ Object
Overwrite this if you need to. Update state to reflect that failover has been initiated. State must be updated to no less than WARNING. State must be CRITICAL if any step of the protocol fails. Lock the state at whatever stage the failover reached. return true or false on success or failure.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deadpool/failover_protocol.rb', line 35 def initiate_failover_protocol! logger.info "Performing Preflight Check" @state.set_state WARNING, "Failover Protocol Initiated." if preflight_check logger.info "Preflight Check Passed." @state. "Preflight Check Passed." else logger.error "Preflight Check Failed! Aborting Failover Protocol." @state.escalate_status_code CRITICAL @state. "Preflight Check Failed! Failover Protocol Aborted!" @state.lock return false end if promote_to_primary(@secondary_host) logger.info "#{@secondary_host} successfully promoted to primary" @state. "Failover Protocol Successful." @state.lock return true else logger.info "#{@secondary_host} promotion failed." @state.escalate_status_code CRITICAL @state. "Failover Protocol Failed!" @state.lock return false end end |
#preflight_check ⇒ Object
Return true or false Don’t update system state. return true or false success or failure
67 68 69 |
# File 'lib/deadpool/failover_protocol.rb', line 67 def preflight_check return false end |
#promote_to_primary(new_primary) ⇒ Object
Promote the host to primary. This is used by initiate_failover_protocol! and for manual promotion by an administrator. new_primary is an IP address TODO: change new_primary to be a config label. return true or false success or failure
76 77 78 |
# File 'lib/deadpool/failover_protocol.rb', line 76 def promote_to_primary(new_primary) return false end |
#setup ⇒ Object
Implementation specific initialization should be placed here.
25 26 |
# File 'lib/deadpool/failover_protocol.rb', line 25 def setup end |
#system_check ⇒ Object
Perform checks against anything that could cause a failover protocol to fail Perform checks on system state. return New Deadpool::StateSnapshot
83 84 85 |
# File 'lib/deadpool/failover_protocol.rb', line 83 def system_check return Deadpool::StateSnapshot.new @state end |