about_page 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- about_page (0.1.0)
4
+ about_page (0.1.1)
5
5
  rails (~> 3.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -7,15 +7,26 @@ To use in a Hydra app:
7
7
 
8
8
  # In config/initializers/about_page.rb
9
9
  AboutPage.configure do |config|
10
- config.app_name = MyApplication.name # Application Name
11
- config.app_version = MyApplication::VERSION # Application Version
12
- config.fedora = AboutPage::Fedora.new(ActiveFedora::Base.connection_for_pid(0)) # Rubydora::Repository instance
13
- config.solr = AboutPage::Solr.new(ActiveFedora.solr) # RSolr instance
10
+ config.app = { :name => MyApplication.name, :version => MyApplication::VERSION }
11
+ config.environment = AboutPage::Environment.new({
12
+ 'Ruby' => /^(RUBY|GEM_|rvm)/ # This defines a "Ruby" subsection containing
13
+ # environment variables whose names match the RegExp
14
+ })
15
+ config.request = AboutPage::RequestEnvironment.new({
16
+ 'HTTP Server' => /^(SERVER_|POW_)/ # This defines an "HTTP Server" subsection containing
17
+ # request variables whose names match the RegExp
18
+ })
19
+ config.dependencies = AboutPage::Dependencies.new
20
+ config.fedora = AboutPage::Fedora.new(ActiveFedora::Base.connection_for_pid(0)) # Rubydora::Repository instance
21
+ config.solr = AboutPage::Solr.new(ActiveFedora.solr) # RSolr instance
14
22
  end
15
23
 
16
24
  # In config/routes.rb
17
25
  mount AboutPage::Engine => '/about(.:format)' # Or whever you want to access the about page
18
-
26
+
27
+ # In app/assets/stylesheets/application.scss
28
+ @import "about_page"
29
+
19
30
  ## Known Issues
20
31
 
21
32
  * Solr must have LukeHandler enabled on /luke
@@ -1,20 +1,39 @@
1
1
  module AboutPage
2
2
  class AboutController < ApplicationController
3
+ before_filter :load_and_filter_configuration
3
4
  before_filter :only => :index do
4
5
  AboutPage.configuration.preflight(request)
5
6
  end
6
7
 
7
- def index
8
+ def load_and_filter_configuration
8
9
  @configuration = AboutPage.configuration
9
10
 
10
11
  @configuration = @configuration.select { |key, value| (params[:filter].split(/[\W\+]/) + ["app"]).include? key.to_s } if params[:filter]
11
12
  @configuration.set_headers!(response)
13
+ end
12
14
 
15
+ def index
13
16
  respond_to do |format|
14
17
  format.html { render :status => @configuration.valid? ? 200 : 417 } # about_page.html.erb
15
18
  format.json { render :json => @configuration.to_json }
16
19
  format.xml { render :xml => @configuration.to_xml }
17
20
  end
18
21
  end
22
+
23
+ def health
24
+ @states = @configuration.map do |key,profile|
25
+ if profile.class.respond_to?(:validators) and profile.class.validators.length > 0
26
+ health = profile.valid? ? 'ok' : 'error'
27
+ { 'component' => key.to_s, 'status' => health, 'errors' => profile.errors.to_a }
28
+ else
29
+ nil
30
+ end
31
+ end.compact
32
+ respond_to do |format|
33
+ format.html { render }
34
+ format.json { render :json => @states }
35
+ format.xml { render :xml => @states }
36
+ end
37
+ end
19
38
  end
20
39
  end
@@ -1,4 +1,5 @@
1
- <h1>Dependencies</h1>
1
+ <h2>Dependencies</h2>
2
+ <h4 style="font-weight: normal">Explicit dependencies are in <span class="dependency required">bold</span>.</h4>
2
3
  <div class="dependencies">
3
4
  <ul>
4
5
  <% profile.spec_list.each do |dep,version,groups| %>
@@ -1,4 +1,4 @@
1
- <h1><%= key.to_s.humanize %></h1>
1
+ <h2><%= key.to_s.humanize %></h2>
2
2
  <% profile.each_pair do |section,env| %>
3
3
  <h3><%= section %></h3>
4
4
  <div class="environment">
@@ -1,2 +1,2 @@
1
- <h1><%= key %></h1>
1
+ <h2><%= key %></h2>
2
2
  <%= exception %>
@@ -1,4 +1,4 @@
1
- <h1><%= key.to_s.humanize %></h1>
1
+ <h2><%= key.to_s.humanize %></h2>
2
2
  <% profile.messages.each do |msg| %>
3
3
  <div><%= msg %></div>
4
4
  <% end if profile.respond_to? :messages %>
@@ -0,0 +1,19 @@
1
+ <div class="about_page">
2
+ <h3>Service Health</h3>
3
+ <ul>
4
+ <% @states.each do |component| %>
5
+ <li class="component">
6
+ <b><%=component['component']%></b>
7
+ <span class="label label-<%=component['status'] == 'error' ? 'important' : 'success'%>"><%=component['status']%></span>
8
+ <% if component['errors'].length > 0 %>
9
+ <ul>
10
+ <li>
11
+ <%= component['errors'].to_a.join('</li><li>').html_safe %>
12
+ </li>
13
+ </ul>
14
+ <% end %>
15
+ </li>
16
+ <% end %>
17
+ </ul>
18
+ </div>
19
+
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  AboutPage::Engine.routes.draw do
2
+ match 'health' => 'about_page/about#health'
2
3
  match ":filter" => 'about_page/about#index'
3
4
  root :to => 'about_page/about#index'
4
5
  end
@@ -4,7 +4,7 @@ module AboutPage
4
4
 
5
5
  validates_each :profile do |record, attr, value|
6
6
  unless value.present?
7
- record.errors.add attr, ": unable to connect to Fedora: #{record.rubydora.inspect}"
7
+ record.errors.add attr, ": unable to connect to Fedora at #{record.rubydora.config[:url]}"
8
8
  end
9
9
  end
10
10
 
@@ -4,9 +4,9 @@ module AboutPage
4
4
 
5
5
  attr_accessor :rsolr, :options
6
6
 
7
- validates_each :schema do |record, attr, value|
8
- unless value.present?
9
- record.errors.add attr, ": unable to connect to Solr: #{record.rsolr.inspect}"
7
+ validates_each :ping do |record, attr, value|
8
+ unless value == 'OK'
9
+ record.errors.add attr, ": unable to ping Solr at #{record.rsolr.uri.to_s}"
10
10
  end
11
11
  end
12
12
  validates :numDocs, :numericality => { :greater_than_or_equal_to => Proc.new { |c| c.expects(:numDocs) } }
@@ -28,6 +28,12 @@ module AboutPage
28
28
  @request_expectations = {}
29
29
  end
30
30
 
31
+ def ping
32
+ rsolr.get('admin/ping')['status']
33
+ rescue
34
+ nil
35
+ end
36
+
31
37
  def schema
32
38
  @schema ||= rsolr.get self.options[:luke], :params => { :show => 'schema', :numTerms => 0 }
33
39
  rescue
@@ -1,3 +1,3 @@
1
1
  module AboutPage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe AboutPage::Solr do
4
4
  before :each do
5
5
  @mock_solr_connection = double('RSolr::Connection')
6
+ @mock_solr_connection.stub(:uri, URI.parse("http://example.edu/solr"))
6
7
  end
7
8
 
8
9
  subject { AboutPage::Solr.new(@mock_solr_connection) }
@@ -29,18 +30,28 @@ describe AboutPage::Solr do
29
30
 
30
31
  describe "#valid?" do
31
32
  it "should be ok if the number of documents in the index is greater than or equal to the :minimum_numdocs" do
33
+ subject.stub(:ping).and_return { 'OK' }
32
34
  subject.stub(:schema).and_return { { 'index' => { :numDocs => 1 } } }
33
35
  subject.stub(:expects).and_return 1
34
36
  subject.should be_valid
35
37
  end
36
38
 
37
39
  it "should be not be ok if the number of documents in the index is less than the :minimum_numdocs" do
40
+ subject.stub(:ping).and_return { 'OK' }
38
41
  subject.stub(:schema).and_return { { 'index' => { :numDocs => 1 } } }
39
42
  subject.stub(:expects).and_return 5
40
43
  subject.should_not be_valid
41
44
  end
42
45
 
43
46
  it "should not be ok if the index :numDocs param is not set" do
47
+ subject.stub(:ping).and_return { 'OK' }
48
+ subject.stub(:schema).and_return { { 'index' => { } } }
49
+ subject.stub(:expects).and_return 1
50
+ subject.should_not be_valid
51
+ end
52
+
53
+ it "should not be ok if the server doesn't respond to ping" do
54
+ subject.stub(:ping).and_return nil
44
55
  subject.stub(:schema).and_return { { 'index' => { } } }
45
56
  subject.stub(:expects).and_return 1
46
57
  subject.should_not be_valid
@@ -49,6 +60,7 @@ describe AboutPage::Solr do
49
60
 
50
61
  describe "#set_headers!" do
51
62
  it "should add helpful headers when something is wrong" do
63
+ subject.stub(:ping).and_return { 'OK' }
52
64
  subject.stub(:schema).and_return { { 'index' => { :numDocs => 1 } } }
53
65
  subject.stub(:expects).and_return 5
54
66
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: about_page
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-07-29 00:00:00.000000000 Z
13
+ date: 2013-07-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -117,6 +117,7 @@ files:
117
117
  - app/views/about_page/about/_environment.html.erb
118
118
  - app/views/about_page/about/_exception.html.erb
119
119
  - app/views/about_page/about/_generic_hash.html.erb
120
+ - app/views/about_page/about/health.html.erb
120
121
  - app/views/about_page/about/index.html.erb
121
122
  - config/routes.rb
122
123
  - lib/about_page.rb
@@ -186,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
187
  version: '0'
187
188
  segments:
188
189
  - 0
189
- hash: -2674301641569901463
190
+ hash: 1267964176528258893
190
191
  required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  none: false
192
193
  requirements:
@@ -195,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
196
  version: '0'
196
197
  segments:
197
198
  - 0
198
- hash: -2674301641569901463
199
+ hash: 1267964176528258893
199
200
  requirements: []
200
201
  rubyforge_project:
201
202
  rubygems_version: 1.8.23