Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a preferred mirror to be given in the configuration #113

Merged
merged 1 commit into from
Mar 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SolrWrapper.wrap port: 8983,
|---------------|-----------------------------------------|
| instance_dir | Directory to store the solr index files |
| url | URL of the Zip file to download |
| mirror_url | Mirror to download the solr artifacts from (e.g. http://lib-solr-mirror.princeton.edu/dist/)|
| version | Solr version to download and install |
| port | port to run Solr on |
| version_file | Local path to store the currently installed version |
Expand Down
29 changes: 28 additions & 1 deletion lib/solr_wrapper/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,37 @@ def version
end
end

def mirror_url
def closest_mirror_url
"http://www.apache.org/dyn/closer.lua/lucene/solr/#{version}/solr-#{version}.zip?asjson=true"
end

def mirror_url
@mirror_url ||= if options[:mirror_url]
options[:mirror_url] + "lucene/solr/#{version}/solr-#{version}.zip"
else
begin
json = open(closest_mirror_url).read
doc = JSON.parse(json)
url = doc['preferred'] + doc['path_info']

response = Faraday.head(url)

if response.success?
url
else
archive_download_url
end

rescue Errno::ECONNRESET, SocketError, Faraday::Error
archive_download_url
end
end
end

def archive_download_url
"https://archive.apache.org/dist/lucene/solr/#{version}/solr-#{version}.zip"
end

def cloud
options[:cloud]
end
Expand Down
24 changes: 3 additions & 21 deletions lib/solr_wrapper/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def version_file
end

def md5url
if default_download_url == archive_download_url
"#{archive_download_url}.md5"
if default_download_url == static_config.archive_download_url
"#{default_download_url}.md5"
else
"http://www.us.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip.md5"
end
Expand Down Expand Up @@ -114,25 +114,7 @@ def download_dir
end

def default_download_url
@default_url ||= begin
json = open(static_config.mirror_url).read
doc = JSON.parse(json)
url = doc['preferred'] + doc['path_info']

response = Faraday.head(url)

if response.success?
url
else
archive_download_url
end
end
rescue Errno::ECONNRESET, SocketError, Faraday::Error
archive_download_url
end

def archive_download_url
"https://archive.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip"
static_config.mirror_url
end

def random_open_port
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/solr_wrapper/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@
end
end
end

describe '#mirror_url' do
context 'with a preferred mirror' do
let(:options) { { mirror_url: 'http://lib-solr-mirror.princeton.edu/dist/', version: '7.2.1' } }

it 'is the URL to the artifact on the preferred mirror' do
expect(config.mirror_url).to eq 'http://lib-solr-mirror.princeton.edu/dist/lucene/solr/7.2.1/solr-7.2.1.zip'
end
end
end
end