lib/hako/scripts/switch_hitter.rb in hako-switch-hitter-0.1.0 vs lib/hako/scripts/switch_hitter.rb in hako-switch-hitter-0.1.1
- old
+ new
@@ -23,36 +23,36 @@
private
# @return [Hash]
def endpoint
- raise Error.new("Switch hitter endpoint is not configured") unless @options[:endpoint]
- @options[:endpoint]
+ raise Error.new("Switch hitter endpoint is not configured") unless @options['endpoint']
+ @options['endpoint']
end
# @return [String]
def endpoint_proto
- endpoint[:proto] || protocol
+ endpoint['proto'] || protocol
end
# @return [String]
def endpoint_host
- return endpoint[:host] if endpoint[:host]
+ return endpoint['host'] if endpoint['host']
load_balancer = describe_load_balancer
load_balancer.dns_name
end
# @return [Fixnum]
def endpoint_port
- endpoint[:port] || port
+ endpoint['port'] || port
end
# @return [String]
def endpoint_path
- raise Error.new("Switch hitter path is not configured") unless endpoint[:path]
- endpoint[:path]
+ raise Error.new("Switch hitter path is not configured") unless endpoint['path']
+ endpoint['path']
end
# @return [Net::HTTP]
def http(host, port)
Net::HTTP.new(host, port)
@@ -66,10 +66,15 @@
if endpoint_proto.upcase == 'HTTPS'
net_http.use_ssl = true
net_http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
+ if @dry_run
+ Hako.logger.info("Switch hitter will request #{endpoint_proto.downcase}://#{endpoint_host}:#{endpoint_port}#{endpoint_path} [dry-run]")
+ return
+ end
+
net_http.start do
req = Net::HTTP::Get.new(endpoint_path)
res = net_http.request(req)
unless res.code == '200'
raise Error.new("Switch hitter HTTP Error: #{res.code}: #{res.body}")
@@ -78,20 +83,20 @@
end
end
# @return [String]
def region
- @app.yaml.fetch(:scheduler).fetch(:region)
+ @app.yaml.fetch('scheduler').fetch('region')
end
# @return [Fixnum]
def port
- @app.yaml.fetch(:scheduler).fetch(:elb_v2).fetch(:listeners)[0].port
+ @app.yaml.fetch('scheduler').fetch('elb_v2').fetch('listeners')[0].fetch('port')
end
# @return [String]
def protocol
- @app.yaml.fetch(:scheduler).fetch(:elb_v2).fetch(:listeners)[0].protocol
+ @app.yaml.fetch('scheduler').fetch('elb_v2').fetch('listeners')[0].fetch('protocol')
end
# @return [Aws::ElasticLoadBalancingV2::Client]
def elb_v2
@elb_v2 ||= Aws::ElasticLoadBalancingV2::Client.new(region: region)