Skip to content

Commit

Permalink
Merge 5cfbacd into 99878d4
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jul 26, 2018
2 parents 99878d4 + 5cfbacd commit 1e00a52
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
7 changes: 6 additions & 1 deletion lib/blacklight/abstract_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ def search(_params = {})
raise NotImplementedError
end

##
# Query the fields that exist from the index
# @return [Hash]
def reflect_fields
raise NotImplementedError
end

##
# Is the repository in a working state?
def ping
raise NotImplementedError
end

private

def connection_config
Expand Down
8 changes: 8 additions & 0 deletions lib/blacklight/solr/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def reflect_fields
send_and_receive('admin/luke', params: { fl: '*', 'json.nl' => 'map' })['fields']
end

##
# @return [boolean] true if the repository is reachable
def ping
response = connection.send_and_receive 'admin/ping', {}
Blacklight.logger.info("Ping [#{connection.uri}] returned: '#{response['status']}'")
response['status'] == "OK"
end

##
# Execute a solr query
# TODO: Make this private after we have a way to abstract admin/luke and ping
Expand Down
21 changes: 8 additions & 13 deletions lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,18 @@ namespace :blacklight do
namespace :check do
desc "Check the Solr connection and controller configuration"
task :solr, [:controller_name] => [:environment] do
errors = 0
verbose = ENV.fetch('VERBOSE', false).present?

conn = Blacklight.default_index.connection
puts "[#{conn.uri}]"

print " - admin/ping: "
begin
response = conn.send_and_receive 'admin/ping', {}
puts response['status']
errors += 1 unless response['status'] == "OK"
conn = Blacklight.default_index
if conn.ping
puts "OK"
else
puts "Unable to reach: #{conn.uri}"
exit 1
end
rescue => e
errors += 1
puts e.to_s
exit 1
end

exit 1 if errors > 0
end

task :controller, [:controller_name] => [:environment] do |_, args|
Expand Down
7 changes: 6 additions & 1 deletion spec/models/blacklight/solr/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CatalogController.blacklight_config.deep_copy
end

subject do
subject(:repository) do
Blacklight::Solr::Repository.new blacklight_config
end

Expand Down Expand Up @@ -146,5 +146,10 @@
end
end

describe '#ping' do
subject { repository.ping }
it { is_expected.to be true }
end


end

0 comments on commit 1e00a52

Please sign in to comment.