Skip to content

Commit

Permalink
Merge pull request #19 from kontera-technologies/pushing-new-version
Browse files Browse the repository at this point in the history
fix status check
  • Loading branch information
hagaigubber authored Dec 16, 2021
2 parents 7dfde64 + 45d76b0 commit 7eabb12
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions lib/nutcracker/web/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ def initialize(nutcracker, external_servers = [])
haml :index
end

get '/status' do
get '/status.json' do
content_type :json
# return array of maps each map is {instance_ip => [unresposive_node_ports],instance_ip => [unresposive_node_ports]}
# exaple: [{"127.0.0.1"=>["6370", "6371", "6372", "6373"]}, {"192.168.1.114"=>["6370"]}]
unresponsive_ndoes = @nutcracker.
# return status 500 if there are unresposive_node in the list, if empty return 200

@nutcracker.
config.
values.
map {|x| x["servers"] + [x["listen"]]}.
map { |x| x["servers"] + [x["listen"]] }.
flatten.
map {|x| x.split(":")}.
map {|host, port| Thread.new {TCPSocket.new(host,port).close.nil? rescue {:host=>host,:port=>port} } }.
map { |x| x.split(":") }.
map { |host, port| Thread.new { { host: host, port: port, ok: (TCPSocket.new(host,port).close rescue false) } } }.
map(&:value).
flatten.
reject { |node_health| node_health[:ok]}. #cleare all healthy nodes from the nodes array
tap { |unhealthy_nodes| status(500) unless unhealthy_nodes.empty? }.
group_by{|k| k[:host]}.
map {|k,v| [k=>v.map { |v| v[:port] }] }.
flatten
#if there are unresposive_node in the list return status 401, if empty return 200
status = unresponsive_ndoes.empty?.tap {|x| status(x ? 200 : 401)}
flatten.
to_json
end

get '/overview.json' do
Expand Down

0 comments on commit 7eabb12

Please sign in to comment.