class Hako::Scripts::SwitchHitter
Public Instance Methods
configure(options)
click to toggle source
@param [Hash] options
# File lib/hako/scripts/switch_hitter.rb, line 12 def configure(options) @options = options end
deploy_finished(containers)
click to toggle source
@param [Hash<String, Container>] containers @return [nil]
# File lib/hako/scripts/switch_hitter.rb, line 18 def deploy_finished(containers) hit_switch end
Also aliased as: rollback
Private Instance Methods
endpoint()
click to toggle source
@return [Hash]
# File lib/hako/scripts/switch_hitter.rb, line 27 def endpoint raise Error.new("Switch hitter endpoint is not configured") unless @options['endpoint'] @options['endpoint'] end
endpoint_host()
click to toggle source
@return [String]
# File lib/hako/scripts/switch_hitter.rb, line 44 def endpoint_host endpoint_uri.host end
endpoint_path()
click to toggle source
@return [String]
# File lib/hako/scripts/switch_hitter.rb, line 54 def endpoint_path endpoint_uri.path end
endpoint_port()
click to toggle source
@return [Fixnum]
# File lib/hako/scripts/switch_hitter.rb, line 49 def endpoint_port endpoint_uri.port end
endpoint_scheme()
click to toggle source
@return [String]
# File lib/hako/scripts/switch_hitter.rb, line 38 def endpoint_scheme raise Error.new("Switch hitter endpoint scheme must be http or https") unless %w/http https/.include?(endpoint_uri.scheme) endpoint_uri.scheme end
endpoint_uri()
click to toggle source
@return [URI]
# File lib/hako/scripts/switch_hitter.rb, line 33 def endpoint_uri @uri ||= URI.parse(endpoint) end
hit_switch()
click to toggle source
@return [nil]
# File lib/hako/scripts/switch_hitter.rb, line 64 def hit_switch Hako.logger.info("Switch endpoint #{endpoint}") net_http = http(endpoint_host, endpoint_port) net_http.use_ssl = endpoint_scheme == 'https' if @dry_run Hako.logger.info("Switch hitter will request #{endpoint} [dry-run]") return end net_http.start do req = Net::HTTP::Get.new(endpoint_uri.request_uri) res = net_http.request(req) unless res.code == '200' raise Error.new("Switch hitter HTTP Error: #{res.code}: #{res.body}") end Hako.logger.info("Enabled #{endpoint} at #{res.body}") end end
http(host, port)
click to toggle source
@return [Net::HTTP]
# File lib/hako/scripts/switch_hitter.rb, line 59 def http(host, port) Net::HTTP.new(host, port) end