Skip to content

Commit

Permalink
Fix about page crash when Matterhorn cannot be reached
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Aug 13, 2014
1 parent affe214 commit 4bb6dda
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
45 changes: 24 additions & 21 deletions app/views/about_page/about/_matterhorn.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
<h2>Matterhorn Services</h2>
<div>
<ul class="unstyled">

<div class="progress" style="width: 300px; float: right;">
<div class="bar bar-success" style="width: <%= profile.storage['percentage_free'] %>%;"> </div>
<div style="width: 100%; position: absolute;font-weight: bold;padding-left:10px; padding-top: 1px; color: white;">
<%= profile.storage['percentage_free_text'] %>
</div>
<div style="width:
100%; position: absolute;font-weight: bold;padding-left:10px;">
<%= profile.storage['percentage_free_text'] %>
</div>
</div>
<% if profile.ping %>
<ul class="unstyled">

<div class="progress" style="width: 300px; float: right;">
<div class="bar bar-success" style="width: <%= profile.storage['percentage_free'] %>%;"> </div>
<div style="width: 100%; position: absolute;font-weight: bold;padding-left:10px; padding-top: 1px; color: white;">
<%= profile.storage['percentage_free_text'] %>
</div>
<div style="width:
100%; position: absolute;font-weight: bold;padding-left:10px;">
<%= profile.storage['percentage_free_text'] %>
</div>
</div>

<% profile.to_h['service'].sort { |a,b| a['type'] <=> b['type'] }.each do |service| %>
<%
active = service['active'] ? '<span class="label label-success">active</span>' : '<span class="label label-important">inactive</span>'
online = service['online'] ? '<span class="label label-success">online</span>' : '<span class="label label-important">offline</span>'
%>
<li><%=active.html_safe%> <%=online.html_safe%> <%=service['type']%></li>
<% end %>
</ul>
<% profile.to_h['service'].sort { |a,b| a['type'] <=> b['type'] }.each do |service| %>
<%
active = service['active'] ? '<span class="label label-success">active</span>' : '<span class="label label-important">inactive</span>'
online = service['online'] ? '<span class="label label-success">online</span>' : '<span class="label label-important">offline</span>'
%>
<li><%=active.html_safe%> <%=online.html_safe%> <%=service['type']%></li>
<% end %>
</ul>
<% else %>
Matterhorn cannot be reached on <%= profile.rubyhorn.config_for_environment[:url] %>
<% end %>
</div>

4 changes: 2 additions & 2 deletions lib/avalon/about/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(options={})
end

def jobs
pidfiles = Dir[File.join(Rails.root,@options[:pid_dir],'delayed_job.*.pid')].sort { |a,b|
pidfiles = Dir[Rails.root.join(@options[:pid_dir],'delayed_*.pid')].sort { |a,b|
File.basename(a).scan(/\d+/).first.to_i <=> File.basename(b).scan(/\d+/).first.to_i
}
pidfiles.collect do |pidfile|
Expand Down Expand Up @@ -70,4 +70,4 @@ def to_h
end
end
end
end
end
11 changes: 9 additions & 2 deletions lib/avalon/about/matterhorn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Matterhorn < AboutPage::Configuration::Node
end
end
validates_each :services do |record, attr, value|
if record.services.empty?
record.errors.add attr, "No services reported"
end
record.services.each { |s|
if s['service_state'].to_s != 'NORMAL'
record.errors.add s['type'], ": #{s['service_state']} (#{complete_status(s)})"
Expand All @@ -35,7 +38,9 @@ class Matterhorn < AboutPage::Configuration::Node
}
end
validates_each :storage do |record, attr, value|
if record.storage['percentage_free'] < 10
if record.storage == 'N/A'
record.errors.add attr, "Cannot determine current matterhorn storage"
elsif record.storage['percentage_free'] < 10
record.errors.add attr, "#{record.storage['percentage_free']}% free"
end
end
Expand All @@ -59,11 +64,13 @@ def storage
@storage['percentage_free'] = (@storage['usable'].to_f / @storage['size'].to_f * 100).round
@storage['percentage_free_text'] = "#{number_to_human_size(@storage['usable'])} (#{@storage['percentage_free']}%) out of #{number_to_human_size(@storage['size'])} available"
@storage
rescue
'N/A'
end

def to_h
services = rubyhorn.client.services['services']['service'] rescue []
{ 'service'=>services, 'storage'=>rubyhorn.client.storage }
{ 'service'=>services, 'storage'=>storage }
end

def self.complete_status(service)
Expand Down

0 comments on commit 4bb6dda

Please sign in to comment.