solr_wrapper 1.2.0 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/README.md +3 -2
- data/exe/solr_wrapper +1 -1
- data/lib/solr_wrapper.rb +1 -1
- data/lib/solr_wrapper/checksum_validator.rb +57 -0
- data/lib/solr_wrapper/configuration.rb +32 -5
- data/lib/solr_wrapper/instance.rb +12 -9
- data/lib/solr_wrapper/settings.rb +4 -35
- data/lib/solr_wrapper/version.rb +1 -1
- data/spec/lib/solr_wrapper/configuration_spec.rb +10 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +3 -3
- metadata +3 -3
- data/lib/solr_wrapper/md5.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3991dd503c5902e6012328a4663edff78f669fbf
|
4
|
+
data.tar.gz: 7d17c2fcc21fa1e370a4903c393de8b3ae207f76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 650abf178f6f41be0f6a96c01699edbdee09a82d6bcca41223ce0c185524bc0d59ec549c669232abab75e85ce187bdb03acf759f94033b0fb2cdd2071b0e1a99
|
7
|
+
data.tar.gz: 29f4b23edfee5ee869b1626c0f88775468106dff2ae5a2059ef1d805cc3d7f03e76d9c285f9e0822583026190160db0d1ae8a361745b8b45a599e70d01f35e1a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -32,16 +32,17 @@ SolrWrapper.wrap port: 8983,
|
|
32
32
|
|---------------|-----------------------------------------|
|
33
33
|
| instance_dir | Directory to store the solr index files |
|
34
34
|
| url | URL of the Zip file to download |
|
35
|
+
| mirror_url | Mirror to download the solr artifacts from (e.g. http://lib-solr-mirror.princeton.edu/dist/)|
|
35
36
|
| version | Solr version to download and install |
|
36
37
|
| port | port to run Solr on |
|
37
38
|
| version_file | Local path to store the currently installed version |
|
38
39
|
| download_dir | Local path for storing the downloaded Solr zip file |
|
39
40
|
| solr_zip_path | Local path to the Solr zip file |
|
40
|
-
|
|
41
|
+
| checksum | Path/URL to checksum |
|
41
42
|
| solr_xml | Path to Solr configuration |
|
42
43
|
| verbose | (Boolean) |
|
43
44
|
| managed | (Boolean) |
|
44
|
-
|
|
45
|
+
| ignore_checksum | (Boolean) |
|
45
46
|
| solr_options | (Hash) |
|
46
47
|
| env | (Hash) |
|
47
48
|
| persist | (Boolean) Preserves the data in you collection between startups |
|
data/exe/solr_wrapper
CHANGED
data/lib/solr_wrapper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'solr_wrapper/version'
|
2
2
|
require 'solr_wrapper/configuration'
|
3
3
|
require 'solr_wrapper/settings'
|
4
|
-
require 'solr_wrapper/
|
4
|
+
require 'solr_wrapper/checksum_validator'
|
5
5
|
require 'solr_wrapper/downloader'
|
6
6
|
require 'solr_wrapper/instance'
|
7
7
|
require 'solr_wrapper/client'
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module SolrWrapper
|
2
|
+
class ChecksumValidator
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
ALGORITHM = 'sha1'
|
6
|
+
|
7
|
+
def initialize(config)
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def clean!
|
12
|
+
path = checksum_path(ALGORITHM)
|
13
|
+
FileUtils.remove_entry(path) if File.exist? path
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate?(file)
|
17
|
+
return true if config.validate == false
|
18
|
+
Digest.const_get(ALGORITHM.upcase).file(file).hexdigest == expected_sum(ALGORITHM)
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate!(file)
|
22
|
+
unless validate? file
|
23
|
+
raise "Checksum mismatch" unless config.ignore_checksum
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def checksumurl(suffix)
|
30
|
+
if config.default_download_url == config.static_config.archive_download_url
|
31
|
+
"#{config.default_download_url}.#{suffix}"
|
32
|
+
else
|
33
|
+
"http://www.us.apache.org/dist/lucene/solr/#{config.static_config.version}/solr-#{config.static_config.version}.zip.#{suffix}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def checksum_path(suffix)
|
38
|
+
File.join(config.download_dir, File.basename(checksumurl(suffix)))
|
39
|
+
end
|
40
|
+
|
41
|
+
def expected_sum(alg)
|
42
|
+
config.checksum || read_file(alg)
|
43
|
+
end
|
44
|
+
|
45
|
+
def read_file(alg)
|
46
|
+
open(checksumfile(alg)).read.split(" ").first
|
47
|
+
end
|
48
|
+
|
49
|
+
def checksumfile(alg)
|
50
|
+
path = checksum_path(alg)
|
51
|
+
unless File.exist? path
|
52
|
+
Downloader.fetch_with_progressbar checksumurl(alg), path
|
53
|
+
end
|
54
|
+
path
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -23,12 +23,12 @@ module SolrWrapper
|
|
23
23
|
options[:validate]
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
options[:
|
26
|
+
def ignore_checksum
|
27
|
+
options[:ignore_checksum]
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
options[:
|
30
|
+
def checksum
|
31
|
+
options[:checksum]
|
32
32
|
end
|
33
33
|
|
34
34
|
def url
|
@@ -89,10 +89,37 @@ module SolrWrapper
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
def
|
92
|
+
def closest_mirror_url
|
93
93
|
"http://www.apache.org/dyn/closer.lua/lucene/solr/#{version}/solr-#{version}.zip?asjson=true"
|
94
94
|
end
|
95
95
|
|
96
|
+
def mirror_url
|
97
|
+
@mirror_url ||= if options[:mirror_url]
|
98
|
+
options[:mirror_url] + "lucene/solr/#{version}/solr-#{version}.zip"
|
99
|
+
else
|
100
|
+
begin
|
101
|
+
json = open(closest_mirror_url).read
|
102
|
+
doc = JSON.parse(json)
|
103
|
+
url = doc['preferred'] + doc['path_info']
|
104
|
+
|
105
|
+
response = Faraday.head(url)
|
106
|
+
|
107
|
+
if response.success?
|
108
|
+
url
|
109
|
+
else
|
110
|
+
archive_download_url
|
111
|
+
end
|
112
|
+
|
113
|
+
rescue Errno::ECONNRESET, SocketError, Faraday::Error
|
114
|
+
archive_download_url
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def archive_download_url
|
120
|
+
"https://archive.apache.org/dist/lucene/solr/#{version}/solr-#{version}.zip"
|
121
|
+
end
|
122
|
+
|
96
123
|
def cloud
|
97
124
|
options[:cloud]
|
98
125
|
end
|
@@ -13,7 +13,7 @@ require 'retriable'
|
|
13
13
|
|
14
14
|
module SolrWrapper
|
15
15
|
class Instance
|
16
|
-
attr_reader :config
|
16
|
+
attr_reader :config
|
17
17
|
|
18
18
|
##
|
19
19
|
# @param [Hash] options
|
@@ -23,20 +23,19 @@ module SolrWrapper
|
|
23
23
|
# @option options [String] :port port to run Solr on
|
24
24
|
# @option options [Boolean] :cloud Run solr in cloud mode
|
25
25
|
# @option options [String] :version_file Local path to store the currently installed version
|
26
|
-
# @option options [String] :download_dir Local directory to store the downloaded Solr zip and its
|
26
|
+
# @option options [String] :download_dir Local directory to store the downloaded Solr zip and its checksum file in (overridden by :solr_zip_path)
|
27
27
|
# @option options [String] :solr_zip_path Local path for storing the downloaded Solr zip file
|
28
|
-
# @option options [Boolean] :validate Should solr_wrapper download a new
|
29
|
-
# @option options [String] :
|
28
|
+
# @option options [Boolean] :validate Should solr_wrapper download a new checksum and (re-)validate the zip file? (default: trueF)
|
29
|
+
# @option options [String] :checksum Path/URL to checksum
|
30
30
|
# @option options [String] :solr_xml Path to Solr configuration
|
31
31
|
# @option options [String] :extra_lib_dir Path to directory containing extra libraries to copy into instance_dir/lib
|
32
32
|
# @option options [Boolean] :verbose return verbose info when running solr commands
|
33
|
-
# @option options [Boolean] :
|
33
|
+
# @option options [Boolean] :ignore_checksum
|
34
34
|
# @option options [Hash] :solr_options
|
35
35
|
# @option options [Hash] :env
|
36
36
|
# @option options [String] :config
|
37
37
|
def initialize(options = {})
|
38
38
|
@config = Settings.new(Configuration.new(options))
|
39
|
-
@md5 = MD5.new(@config)
|
40
39
|
end
|
41
40
|
|
42
41
|
def host
|
@@ -228,7 +227,7 @@ module SolrWrapper
|
|
228
227
|
remove_instance_dir!
|
229
228
|
FileUtils.remove_entry(config.download_dir, true) if File.exist?(config.download_dir)
|
230
229
|
FileUtils.remove_entry(config.tmp_save_dir, true) if File.exist? config.tmp_save_dir
|
231
|
-
|
230
|
+
checksum_validator.clean!
|
232
231
|
FileUtils.remove_entry(config.version_file) if File.exist? config.version_file
|
233
232
|
end
|
234
233
|
|
@@ -294,9 +293,9 @@ module SolrWrapper
|
|
294
293
|
end
|
295
294
|
|
296
295
|
def download
|
297
|
-
unless File.exist?(config.solr_zip_path) &&
|
296
|
+
unless File.exist?(config.solr_zip_path) && checksum_validator.validate?(config.solr_zip_path)
|
298
297
|
Downloader.fetch_with_progressbar config.download_url, config.solr_zip_path
|
299
|
-
|
298
|
+
checksum_validator.validate! config.solr_zip_path
|
300
299
|
end
|
301
300
|
config.solr_zip_path
|
302
301
|
end
|
@@ -327,6 +326,10 @@ module SolrWrapper
|
|
327
326
|
|
328
327
|
private
|
329
328
|
|
329
|
+
def checksum_validator
|
330
|
+
@checksum_validator ||= ChecksumValidator.new(config)
|
331
|
+
end
|
332
|
+
|
330
333
|
def after_start
|
331
334
|
create_configsets if config.cloud
|
332
335
|
end
|
@@ -43,7 +43,6 @@ module SolrWrapper
|
|
43
43
|
@zookeeper_port ||= "#{port.to_i + 1000}"
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
46
|
##
|
48
47
|
# Get a (likely) URL to the solr instance
|
49
48
|
def url
|
@@ -73,18 +72,6 @@ module SolrWrapper
|
|
73
72
|
static_config.version_file || File.join(instance_dir, "VERSION")
|
74
73
|
end
|
75
74
|
|
76
|
-
def md5url
|
77
|
-
if default_download_url == archive_download_url
|
78
|
-
"#{archive_download_url}.md5"
|
79
|
-
else
|
80
|
-
"http://www.us.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip.md5"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def md5sum_path
|
85
|
-
File.join(download_dir, File.basename(md5url))
|
86
|
-
end
|
87
|
-
|
88
75
|
def solr_binary
|
89
76
|
File.join(instance_dir, "bin", "solr")
|
90
77
|
end
|
@@ -93,6 +80,10 @@ module SolrWrapper
|
|
93
80
|
@tmp_save_dir ||= Dir.mktmpdir
|
94
81
|
end
|
95
82
|
|
83
|
+
def default_download_url
|
84
|
+
static_config.mirror_url
|
85
|
+
end
|
86
|
+
|
96
87
|
private
|
97
88
|
|
98
89
|
def tmpdir
|
@@ -113,28 +104,6 @@ module SolrWrapper
|
|
113
104
|
@download_dir
|
114
105
|
end
|
115
106
|
|
116
|
-
def default_download_url
|
117
|
-
@default_url ||= begin
|
118
|
-
json = open(static_config.mirror_url).read
|
119
|
-
doc = JSON.parse(json)
|
120
|
-
url = doc['preferred'] + doc['path_info']
|
121
|
-
|
122
|
-
response = Faraday.head(url)
|
123
|
-
|
124
|
-
if response.success?
|
125
|
-
url
|
126
|
-
else
|
127
|
-
archive_download_url
|
128
|
-
end
|
129
|
-
end
|
130
|
-
rescue Errno::ECONNRESET, SocketError, Faraday::Error
|
131
|
-
archive_download_url
|
132
|
-
end
|
133
|
-
|
134
|
-
def archive_download_url
|
135
|
-
"https://archive.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip"
|
136
|
-
end
|
137
|
-
|
138
107
|
def random_open_port
|
139
108
|
socket = Socket.new(:INET, :STREAM, 0)
|
140
109
|
begin
|
data/lib/solr_wrapper/version.rb
CHANGED
@@ -83,4 +83,14 @@ describe SolrWrapper::Configuration do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
describe '#mirror_url' do
|
88
|
+
context 'with a preferred mirror' do
|
89
|
+
let(:options) { { mirror_url: 'http://lib-solr-mirror.princeton.edu/dist/', version: '7.2.1' } }
|
90
|
+
|
91
|
+
it 'is the URL to the artifact on the preferred mirror' do
|
92
|
+
expect(config.mirror_url).to eq 'http://lib-solr-mirror.princeton.edu/dist/lucene/solr/7.2.1/solr-7.2.1.zip'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
86
96
|
end
|
@@ -159,8 +159,8 @@ describe SolrWrapper::Instance do
|
|
159
159
|
it { is_expected.to eq 'solr-version-number' }
|
160
160
|
end
|
161
161
|
|
162
|
-
describe "#
|
163
|
-
subject { solr_instance.
|
164
|
-
it { is_expected.to be_instance_of SolrWrapper::
|
162
|
+
describe "#checksum_validator" do
|
163
|
+
subject { solr_instance.send(:checksum_validator) }
|
164
|
+
it { is_expected.to be_instance_of SolrWrapper::ChecksumValidator }
|
165
165
|
end
|
166
166
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solr_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -171,11 +171,11 @@ files:
|
|
171
171
|
- coveralls.yml
|
172
172
|
- exe/solr_wrapper
|
173
173
|
- lib/solr_wrapper.rb
|
174
|
+
- lib/solr_wrapper/checksum_validator.rb
|
174
175
|
- lib/solr_wrapper/client.rb
|
175
176
|
- lib/solr_wrapper/configuration.rb
|
176
177
|
- lib/solr_wrapper/downloader.rb
|
177
178
|
- lib/solr_wrapper/instance.rb
|
178
|
-
- lib/solr_wrapper/md5.rb
|
179
179
|
- lib/solr_wrapper/popen4_runner.rb
|
180
180
|
- lib/solr_wrapper/popen_runner.rb
|
181
181
|
- lib/solr_wrapper/rake_task.rb
|
data/lib/solr_wrapper/md5.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
module SolrWrapper
|
2
|
-
class MD5
|
3
|
-
attr_reader :config
|
4
|
-
def initialize(config)
|
5
|
-
@config = config
|
6
|
-
end
|
7
|
-
|
8
|
-
def clean!
|
9
|
-
FileUtils.remove_entry(config.md5sum_path) if File.exist? config.md5sum_path
|
10
|
-
end
|
11
|
-
|
12
|
-
def validate?(file)
|
13
|
-
return true if config.validate == false
|
14
|
-
|
15
|
-
Digest::MD5.file(file).hexdigest == expected_sum
|
16
|
-
end
|
17
|
-
|
18
|
-
def validate!(file)
|
19
|
-
unless validate? file
|
20
|
-
raise "MD5 mismatch" unless config.ignore_md5sum
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def expected_sum
|
27
|
-
@md5sum ||= config.md5sum
|
28
|
-
@md5sum ||= read_file
|
29
|
-
end
|
30
|
-
|
31
|
-
def read_file
|
32
|
-
open(md5file).read.split(" ").first
|
33
|
-
end
|
34
|
-
|
35
|
-
def md5file
|
36
|
-
unless File.exist? config.md5sum_path
|
37
|
-
Downloader.fetch_with_progressbar config.md5url, config.md5sum_path
|
38
|
-
end
|
39
|
-
|
40
|
-
config.md5sum_path
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|