solr_wrapper 0.7.0 → 0.10.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/.rubocop.yml +4 -1
- data/.travis.yml +6 -2
- data/exe/solr_wrapper +14 -8
- data/lib/solr_wrapper/configuration.rb +59 -18
- data/lib/solr_wrapper/downloader.rb +15 -9
- data/lib/solr_wrapper/instance.rb +81 -14
- data/lib/solr_wrapper/settings.rb +13 -1
- data/lib/solr_wrapper/tasks/solr_wrapper.rake +1 -2
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +12 -4
- data/spec/fixtures/sample_config.yml +7 -0
- data/spec/lib/solr_wrapper/configuration_spec.rb +31 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +62 -6
- data/spec/lib/solr_wrapper_spec.rb +8 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7916cf546d675d2a3f008f4a271aa4fc2cf7b8ae
|
|
4
|
+
data.tar.gz: 3d2e1456ff74edb606a60cef2fa1731ae5a74351
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff2b8b312c13c8b68c233f0799c68f36761109beea56fe2648485a89be28980b53d16d5646479ce58c0575cdde11025ff9ed74b81c923eb923953dcfbcf862cf
|
|
7
|
+
data.tar.gz: 58a248017fd9ec7330af89ca300d686710a6c71c36d96d9af5cd1967e8c1a703be7618835d30d3f5f7066958e1046fef686f3fa2b0d2d308e3c8f4990c3963fe
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/exe/solr_wrapper
CHANGED
|
@@ -5,14 +5,14 @@ require 'optparse'
|
|
|
5
5
|
|
|
6
6
|
options = {}
|
|
7
7
|
collection_options = {}
|
|
8
|
-
OptionParser.new do |opts|
|
|
8
|
+
args = OptionParser.new do |opts|
|
|
9
9
|
opts.banner = "Usage: solr_wrapper [options]"
|
|
10
10
|
|
|
11
11
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
|
12
12
|
options[:verbose] = v
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
opts.on("--config", "Load configuration from a file") do |v|
|
|
15
|
+
opts.on("--config FILE", "Load configuration from a file") do |v|
|
|
16
16
|
options[:config] = v
|
|
17
17
|
end
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@ OptionParser.new do |opts|
|
|
|
20
20
|
options[:version] = v
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default:
|
|
23
|
+
opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default: #{SolrWrapper.default_solr_port})") do |p|
|
|
24
24
|
if p == 'random'
|
|
25
25
|
options[:port] = nil
|
|
26
26
|
else
|
|
@@ -55,20 +55,26 @@ OptionParser.new do |opts|
|
|
|
55
55
|
opts.on("--no-checksum", "Skip running checksum validation on the downloaded file") do |d|
|
|
56
56
|
options[:ignore_md5sum] = true
|
|
57
57
|
end
|
|
58
|
-
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
begin
|
|
61
|
+
args.parse!
|
|
62
|
+
rescue => error
|
|
63
|
+
$stderr.puts "ERROR: #{error}\n"
|
|
64
|
+
$stderr.puts args.help
|
|
65
|
+
exit 1
|
|
66
|
+
end
|
|
59
67
|
|
|
60
68
|
# default to verbose
|
|
61
69
|
options[:verbose] = true if options[:verbose].nil?
|
|
62
70
|
|
|
63
|
-
instance = SolrWrapper.
|
|
71
|
+
instance = SolrWrapper.instance(options)
|
|
64
72
|
$stderr.print "Starting Solr #{instance.version} on port #{instance.port} ... "
|
|
65
73
|
instance.wrap do |conn|
|
|
66
74
|
conn.with_collection(collection_options) do
|
|
67
75
|
$stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
|
|
68
76
|
begin
|
|
69
|
-
|
|
70
|
-
sleep 1
|
|
71
|
-
end
|
|
77
|
+
conn.wait
|
|
72
78
|
rescue Interrupt
|
|
73
79
|
$stderr.puts "Solr is shutting down."
|
|
74
80
|
end
|
|
@@ -3,8 +3,8 @@ module SolrWrapper
|
|
|
3
3
|
attr_reader :options
|
|
4
4
|
|
|
5
5
|
def initialize(options)
|
|
6
|
-
@options = options
|
|
7
|
-
|
|
6
|
+
@options = read_config(options[:config], options[:verbose])
|
|
7
|
+
.merge options
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def solr_xml
|
|
@@ -35,7 +35,15 @@ module SolrWrapper
|
|
|
35
35
|
# Check if the port option has been explicitly set to nil.
|
|
36
36
|
# this means to start solr wrapper on a random open port
|
|
37
37
|
return nil if options.key?(:port) && !options[:port]
|
|
38
|
-
options
|
|
38
|
+
options.fetch(:port) { SolrWrapper.default_instance_options[:port] }.to_s
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def zookeeper_host
|
|
42
|
+
options[:zookeeper_host]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def zookeeper_port
|
|
46
|
+
options[:zookeeper_port]
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
def download_path
|
|
@@ -43,7 +51,15 @@ module SolrWrapper
|
|
|
43
51
|
end
|
|
44
52
|
|
|
45
53
|
def download_dir
|
|
46
|
-
options[:download_dir]
|
|
54
|
+
options[:download_dir] || default_download_dir
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def default_download_dir
|
|
58
|
+
if defined?(Rails) && Rails.root
|
|
59
|
+
File.join(Rails.root, 'tmp')
|
|
60
|
+
else
|
|
61
|
+
Dir.tmpdir
|
|
62
|
+
end
|
|
47
63
|
end
|
|
48
64
|
|
|
49
65
|
def solr_options
|
|
@@ -78,27 +94,52 @@ module SolrWrapper
|
|
|
78
94
|
options[:version_file]
|
|
79
95
|
end
|
|
80
96
|
|
|
97
|
+
def collection_options
|
|
98
|
+
hash = options.fetch(:collection, {})
|
|
99
|
+
Configuration.slice(convert_keys(hash), :name, :dir)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def configsets
|
|
103
|
+
configsets = options[:configsets] || []
|
|
104
|
+
configsets.map { |x| convert_keys(x) }
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def poll_interval
|
|
108
|
+
options.fetch(:poll_interval, 1)
|
|
109
|
+
end
|
|
110
|
+
|
|
81
111
|
private
|
|
82
112
|
|
|
83
|
-
def
|
|
84
|
-
|
|
113
|
+
def self.slice(source, *keys)
|
|
114
|
+
keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def read_config(config_file, verbose)
|
|
85
118
|
default_configuration_paths.each do |p|
|
|
86
119
|
path = File.expand_path(p)
|
|
87
|
-
|
|
120
|
+
config_file ||= path if File.exist? path
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
unless config_file
|
|
124
|
+
$stdout.puts "No config specified" if verbose
|
|
125
|
+
return {}
|
|
88
126
|
end
|
|
89
127
|
|
|
90
|
-
if
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
end
|
|
97
|
-
collection_config = config.delete(:collection) || {}
|
|
98
|
-
@options = config.merge(options)
|
|
99
|
-
elsif verbose?
|
|
100
|
-
$stdout.puts "No config specified"
|
|
128
|
+
$stdout.puts "Loading configuration from #{config_file}" if verbose
|
|
129
|
+
config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
|
|
130
|
+
unless config
|
|
131
|
+
$stderr.puts "Unable to parse config #{config_file}" if verbose
|
|
132
|
+
return {}
|
|
101
133
|
end
|
|
134
|
+
convert_keys(config)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def convert_keys(hash)
|
|
138
|
+
hash.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def default_configuration_paths
|
|
142
|
+
['.solr_wrapper', '~/.solr_wrapper']
|
|
102
143
|
end
|
|
103
144
|
end
|
|
104
145
|
end
|
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
require 'ruby-progressbar'
|
|
2
|
+
|
|
1
3
|
module SolrWrapper
|
|
2
4
|
class Downloader
|
|
3
5
|
def self.fetch_with_progressbar(url, output)
|
|
4
|
-
pbar =
|
|
5
|
-
open(url, content_length_proc:
|
|
6
|
-
if t && 0 < t
|
|
7
|
-
pbar.total = t
|
|
8
|
-
end
|
|
9
|
-
end,
|
|
10
|
-
progress_proc: lambda do|s|
|
|
11
|
-
pbar.progress = s
|
|
12
|
-
end) do |io|
|
|
6
|
+
pbar = SafeProgressBar.new(title: File.basename(url), total: nil, format: '%t: |%B| %p%% (%e )')
|
|
7
|
+
open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
|
|
13
8
|
IO.copy_stream(io, output)
|
|
14
9
|
end
|
|
15
10
|
end
|
|
11
|
+
|
|
12
|
+
class SafeProgressBar < ProgressBar::Base
|
|
13
|
+
def progress=(new_progress)
|
|
14
|
+
self.total = new_progress if total <= new_progress
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def total=(new_total)
|
|
19
|
+
super if new_total && new_total > 0
|
|
20
|
+
end
|
|
21
|
+
end
|
|
16
22
|
end
|
|
17
23
|
end
|
|
@@ -2,7 +2,6 @@ require 'digest'
|
|
|
2
2
|
require 'fileutils'
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'open-uri'
|
|
5
|
-
require 'ruby-progressbar'
|
|
6
5
|
require 'securerandom'
|
|
7
6
|
require 'socket'
|
|
8
7
|
require 'stringio'
|
|
@@ -13,7 +12,7 @@ require 'yaml'
|
|
|
13
12
|
|
|
14
13
|
module SolrWrapper
|
|
15
14
|
class Instance
|
|
16
|
-
attr_reader :config, :md5
|
|
15
|
+
attr_reader :config, :md5
|
|
17
16
|
|
|
18
17
|
##
|
|
19
18
|
# @param [Hash] options
|
|
@@ -51,6 +50,10 @@ module SolrWrapper
|
|
|
51
50
|
config.url
|
|
52
51
|
end
|
|
53
52
|
|
|
53
|
+
def instance_dir
|
|
54
|
+
config.instance_dir
|
|
55
|
+
end
|
|
56
|
+
|
|
54
57
|
def version
|
|
55
58
|
config.version
|
|
56
59
|
end
|
|
@@ -72,8 +75,10 @@ module SolrWrapper
|
|
|
72
75
|
|
|
73
76
|
# Wait for solr to start
|
|
74
77
|
unless status
|
|
75
|
-
sleep
|
|
78
|
+
sleep config.poll_interval
|
|
76
79
|
end
|
|
80
|
+
|
|
81
|
+
after_start
|
|
77
82
|
end
|
|
78
83
|
end
|
|
79
84
|
|
|
@@ -81,15 +86,9 @@ module SolrWrapper
|
|
|
81
86
|
# Stop Solr and wait for it to finish exiting
|
|
82
87
|
def stop
|
|
83
88
|
if config.managed? && started?
|
|
84
|
-
|
|
85
89
|
exec('stop', p: port)
|
|
86
|
-
|
|
87
|
-
while status
|
|
88
|
-
sleep 1
|
|
89
|
-
end
|
|
90
|
+
wait
|
|
90
91
|
end
|
|
91
|
-
|
|
92
|
-
@pid = nil
|
|
93
92
|
end
|
|
94
93
|
|
|
95
94
|
##
|
|
@@ -111,12 +110,31 @@ module SolrWrapper
|
|
|
111
110
|
false
|
|
112
111
|
end
|
|
113
112
|
|
|
113
|
+
def pid
|
|
114
|
+
return unless config.managed?
|
|
115
|
+
|
|
116
|
+
@pid ||= begin
|
|
117
|
+
out = exec('status').read
|
|
118
|
+
out.match(/process (?<pid>\d+) running on port #{port}/) do |m|
|
|
119
|
+
m[:pid].to_i
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
rescue
|
|
123
|
+
nil
|
|
124
|
+
end
|
|
125
|
+
|
|
114
126
|
##
|
|
115
127
|
# Is Solr running?
|
|
116
128
|
def started?
|
|
117
129
|
!!status
|
|
118
130
|
end
|
|
119
131
|
|
|
132
|
+
def wait
|
|
133
|
+
while (Process.getpgid(pid) rescue status)
|
|
134
|
+
sleep config.poll_interval
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
120
138
|
##
|
|
121
139
|
# Create a new collection in solr
|
|
122
140
|
# @param [Hash] options
|
|
@@ -127,12 +145,49 @@ module SolrWrapper
|
|
|
127
145
|
|
|
128
146
|
create_options = { p: port }
|
|
129
147
|
create_options[:c] = options[:name] if options[:name]
|
|
148
|
+
create_options[:n] = options[:config_name] if options[:config_name]
|
|
130
149
|
create_options[:d] = options[:dir] if options[:dir]
|
|
131
150
|
exec("create", create_options)
|
|
132
151
|
|
|
133
152
|
options[:name]
|
|
134
153
|
end
|
|
135
154
|
|
|
155
|
+
##
|
|
156
|
+
# Update the collection configuration in zookeeper
|
|
157
|
+
# @param [Hash] options
|
|
158
|
+
# @option options [String] :config_name
|
|
159
|
+
# @option options [String] :dir
|
|
160
|
+
def upconfig(options = {})
|
|
161
|
+
options[:name] ||= SecureRandom.hex
|
|
162
|
+
options[:zkhost] ||= zkhost
|
|
163
|
+
|
|
164
|
+
upconfig_options = { upconfig: true, n: options[:name] }
|
|
165
|
+
upconfig_options[:d] = options[:dir] if options[:dir]
|
|
166
|
+
upconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
167
|
+
|
|
168
|
+
exec 'zk', upconfig_options
|
|
169
|
+
|
|
170
|
+
options[:name]
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
##
|
|
174
|
+
# Copy the collection configuration from zookeeper to a local directory
|
|
175
|
+
# @param [Hash] options
|
|
176
|
+
# @option options [String] :config_name
|
|
177
|
+
# @option options [String] :dir
|
|
178
|
+
def downconfig(options = {})
|
|
179
|
+
options[:name] ||= SecureRandom.hex
|
|
180
|
+
options[:zkhost] ||= zkhost
|
|
181
|
+
|
|
182
|
+
downconfig_options = { downconfig: true, n: options[:name] }
|
|
183
|
+
downconfig_options[:d] = options[:dir] if options[:dir]
|
|
184
|
+
downconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
185
|
+
|
|
186
|
+
exec 'zk', downconfig_options
|
|
187
|
+
|
|
188
|
+
options[:name]
|
|
189
|
+
end
|
|
190
|
+
|
|
136
191
|
##
|
|
137
192
|
# Create a new collection in solr
|
|
138
193
|
# @param [String] name collection name
|
|
@@ -146,6 +201,7 @@ module SolrWrapper
|
|
|
146
201
|
# @option options [String] :name
|
|
147
202
|
# @option options [String] :dir
|
|
148
203
|
def with_collection(options = {})
|
|
204
|
+
options = config.collection_options.merge(options)
|
|
149
205
|
return yield if options.empty?
|
|
150
206
|
|
|
151
207
|
name = create(options)
|
|
@@ -264,7 +320,6 @@ module SolrWrapper
|
|
|
264
320
|
# JRuby
|
|
265
321
|
env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
|
|
266
322
|
pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
|
|
267
|
-
@pid = pid
|
|
268
323
|
stringio = StringIO.new
|
|
269
324
|
if config.verbose? && !silence_output
|
|
270
325
|
IO.copy_stream(output, $stderr)
|
|
@@ -277,7 +332,7 @@ module SolrWrapper
|
|
|
277
332
|
input.close
|
|
278
333
|
output.close
|
|
279
334
|
error.close
|
|
280
|
-
exit_status = Process.waitpid2(
|
|
335
|
+
exit_status = Process.waitpid2(pid).last
|
|
281
336
|
else
|
|
282
337
|
IO.popen(config.env, args + [err: [:child, :out]]) do |io|
|
|
283
338
|
stringio = StringIO.new
|
|
@@ -288,8 +343,6 @@ module SolrWrapper
|
|
|
288
343
|
IO.copy_stream(io, stringio)
|
|
289
344
|
end
|
|
290
345
|
|
|
291
|
-
@pid = io.pid
|
|
292
|
-
|
|
293
346
|
_, exit_status = Process.wait2(io.pid)
|
|
294
347
|
end
|
|
295
348
|
end
|
|
@@ -304,6 +357,16 @@ module SolrWrapper
|
|
|
304
357
|
|
|
305
358
|
private
|
|
306
359
|
|
|
360
|
+
def after_start
|
|
361
|
+
create_configsets if config.cloud
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def create_configsets
|
|
365
|
+
config.configsets.each do |configset|
|
|
366
|
+
upconfig(configset)
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
307
370
|
def extracted_version
|
|
308
371
|
File.read(config.version_file).strip if File.exists? config.version_file
|
|
309
372
|
end
|
|
@@ -314,6 +377,10 @@ module SolrWrapper
|
|
|
314
377
|
end
|
|
315
378
|
end
|
|
316
379
|
|
|
380
|
+
def zkhost
|
|
381
|
+
"#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
|
|
382
|
+
end
|
|
383
|
+
|
|
317
384
|
def raise_error_unless_extracted
|
|
318
385
|
raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
|
319
386
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'delegate'
|
|
2
|
+
|
|
1
3
|
module SolrWrapper
|
|
2
4
|
# Configuraton that comes from static and dynamic sources.
|
|
3
5
|
class Settings < Delegator
|
|
@@ -23,6 +25,11 @@ module SolrWrapper
|
|
|
23
25
|
'127.0.0.1'
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
def zookeeper_host
|
|
29
|
+
@zookeeper_host ||= static_config.zookeeper_port
|
|
30
|
+
@zookeeper_host ||= host
|
|
31
|
+
end
|
|
32
|
+
|
|
26
33
|
##
|
|
27
34
|
# Get the port this Solr instance is running at
|
|
28
35
|
def port
|
|
@@ -30,6 +37,12 @@ module SolrWrapper
|
|
|
30
37
|
@port ||= random_open_port.to_s
|
|
31
38
|
end
|
|
32
39
|
|
|
40
|
+
def zookeeper_port
|
|
41
|
+
@zookeeper_port ||= static_config.zookeeper_port
|
|
42
|
+
@zookeeper_port ||= "#{port.to_i + 1000}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
33
46
|
##
|
|
34
47
|
# Get a (likely) URL to the solr instance
|
|
35
48
|
def url
|
|
@@ -83,7 +96,6 @@ module SolrWrapper
|
|
|
83
96
|
|
|
84
97
|
def download_dir
|
|
85
98
|
@download_dir ||= static_config.download_dir
|
|
86
|
-
@download_dir ||= Dir.tmpdir
|
|
87
99
|
FileUtils.mkdir_p @download_dir
|
|
88
100
|
@download_dir
|
|
89
101
|
end
|
|
@@ -4,8 +4,7 @@ require 'solr_wrapper'
|
|
|
4
4
|
namespace :solr do
|
|
5
5
|
desc "Load the solr options and solr instance"
|
|
6
6
|
task :environment do
|
|
7
|
-
|
|
8
|
-
@solr_instance = SolrWrapper.default_instance
|
|
7
|
+
@solr_instance = SolrWrapper.instance
|
|
9
8
|
end
|
|
10
9
|
|
|
11
10
|
desc 'Install a clean version of solr. Replaces the existing copy if there is one.'
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
|
@@ -7,12 +7,16 @@ require 'solr_wrapper/instance'
|
|
|
7
7
|
|
|
8
8
|
module SolrWrapper
|
|
9
9
|
def self.default_solr_version
|
|
10
|
-
'
|
|
10
|
+
'6.0.0'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.default_solr_port
|
|
14
|
+
'8983'
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def self.default_instance_options
|
|
14
18
|
@default_instance_options ||= {
|
|
15
|
-
port:
|
|
19
|
+
port: SolrWrapper.default_solr_port,
|
|
16
20
|
version: SolrWrapper.default_solr_version
|
|
17
21
|
}
|
|
18
22
|
end
|
|
@@ -22,12 +26,16 @@ module SolrWrapper
|
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def self.default_instance(options = {})
|
|
25
|
-
@default_instance ||=
|
|
29
|
+
@default_instance ||= instance(default_instance_options)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.instance(options = {})
|
|
33
|
+
SolrWrapper::Instance.new(options)
|
|
26
34
|
end
|
|
27
35
|
|
|
28
36
|
##
|
|
29
37
|
# Ensures a Solr service is running before executing the block
|
|
30
38
|
def self.wrap(options = {}, &block)
|
|
31
|
-
|
|
39
|
+
instance(options).wrap &block
|
|
32
40
|
end
|
|
33
41
|
end
|
|
@@ -21,4 +21,35 @@ describe SolrWrapper::Configuration do
|
|
|
21
21
|
it { is_expected.to eq '8888' }
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
|
+
|
|
25
|
+
describe "#read_config" do
|
|
26
|
+
before do
|
|
27
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
28
|
+
end
|
|
29
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
30
|
+
it "uses values from the config file" do
|
|
31
|
+
expect(config.port).to eq '9999'
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe "#collection_options" do
|
|
36
|
+
before do
|
|
37
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
38
|
+
end
|
|
39
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
40
|
+
it "uses values from the config file" do
|
|
41
|
+
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
describe '#configsets' do
|
|
46
|
+
before do
|
|
47
|
+
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
48
|
+
end
|
|
49
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
50
|
+
|
|
51
|
+
it 'uses values from the config file' do
|
|
52
|
+
expect(config.configsets).to include(name: 'project-development-configset', dir: 'solr/config/')
|
|
53
|
+
end
|
|
54
|
+
end
|
|
24
55
|
end
|
|
@@ -1,22 +1,73 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe SolrWrapper::Instance do
|
|
4
|
-
let(:
|
|
4
|
+
let(:options) { {} }
|
|
5
|
+
let(:solr_instance) { SolrWrapper::Instance.new(options) }
|
|
5
6
|
subject { solr_instance }
|
|
6
7
|
let(:client) { SimpleSolrClient::Client.new(subject.url) }
|
|
7
8
|
|
|
8
9
|
describe "#with_collection" do
|
|
9
|
-
|
|
10
|
+
let(:options) { { cloud: false } }
|
|
11
|
+
context "without a name" do
|
|
12
|
+
it "creates a new anonymous collection" do
|
|
13
|
+
subject.wrap do |solr|
|
|
14
|
+
solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
|
|
15
|
+
core = client.core(collection_name)
|
|
16
|
+
unless defined? JRUBY_VERSION
|
|
17
|
+
expect(core.schema.field('id').name).to eq 'id'
|
|
18
|
+
expect(core.schema.field('id').stored).to eq true
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
context "with a config file" do
|
|
25
|
+
before do
|
|
26
|
+
allow(solr_instance.config).to receive(:collection_options)
|
|
27
|
+
.and_return(name: 'project-development', dir: 'solr/config/')
|
|
28
|
+
allow(solr_instance).to receive(:delete)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "creates a new collection with options from the config" do
|
|
32
|
+
expect(solr_instance).to receive(:create).with(
|
|
33
|
+
hash_including(name: "project-development", dir: anything))
|
|
34
|
+
solr_instance.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) {}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
context 'with a SolrCloud instance' do
|
|
40
|
+
let(:options) { { cloud: true } }
|
|
41
|
+
it 'can upload configurations' do
|
|
10
42
|
subject.wrap do |solr|
|
|
11
|
-
solr.
|
|
43
|
+
config_name = solr.upconfig dir: File.join(FIXTURES_DIR, 'basic_configs')
|
|
44
|
+
Dir.mktmpdir do |dir|
|
|
45
|
+
solr.downconfig name: config_name, dir: dir
|
|
46
|
+
end
|
|
47
|
+
solr.with_collection(config_name: config_name) do |collection_name|
|
|
12
48
|
core = client.core(collection_name)
|
|
13
49
|
unless defined? JRUBY_VERSION
|
|
14
|
-
expect(core.
|
|
15
|
-
expect(core.schema.field('id').stored).to eq true
|
|
50
|
+
expect(core.all.size).to eq 0
|
|
16
51
|
end
|
|
17
52
|
end
|
|
18
53
|
end
|
|
19
54
|
end
|
|
55
|
+
|
|
56
|
+
context 'with a config file' do
|
|
57
|
+
before do
|
|
58
|
+
allow(solr_instance.config).to receive(:configsets)
|
|
59
|
+
.and_return([name: 'project-development', dir: 'solr/config/'])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'creates a new configsets with options from the config' do
|
|
63
|
+
expect(subject).to receive(:upconfig).with(
|
|
64
|
+
hash_including(name: 'project-development', dir: anything))
|
|
65
|
+
|
|
66
|
+
subject.wrap do
|
|
67
|
+
# no-op
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
20
71
|
end
|
|
21
72
|
|
|
22
73
|
describe 'exec' do
|
|
@@ -56,9 +107,14 @@ describe SolrWrapper::Instance do
|
|
|
56
107
|
it { is_expected.to eq 'http://127.0.0.1:8983/solr/' }
|
|
57
108
|
end
|
|
58
109
|
|
|
110
|
+
describe "#instance_dir" do
|
|
111
|
+
subject { solr_instance.instance_dir }
|
|
112
|
+
it { is_expected.to start_with Dir.tmpdir }
|
|
113
|
+
end
|
|
114
|
+
|
|
59
115
|
describe "#version" do
|
|
60
116
|
subject { solr_instance.version }
|
|
61
|
-
it { is_expected.to eq '
|
|
117
|
+
it { is_expected.to eq '6.0.0' }
|
|
62
118
|
end
|
|
63
119
|
|
|
64
120
|
describe "#md5" do
|
|
@@ -13,6 +13,14 @@ describe SolrWrapper do
|
|
|
13
13
|
end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
describe '.instance' do
|
|
17
|
+
context 'without arguments' do
|
|
18
|
+
it 'inherits the defaults' do
|
|
19
|
+
expect(SolrWrapper.instance.port).to eq '8983'
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
16
24
|
describe ".default_instance_options=" do
|
|
17
25
|
it "sets default options" do
|
|
18
26
|
SolrWrapper.default_instance_options = { port: '1234' }
|
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: 0.
|
|
4
|
+
version: 0.10.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: 2016-
|
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
147
147
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
148
148
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
149
|
+
- spec/fixtures/sample_config.yml
|
|
149
150
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
150
151
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
151
152
|
- spec/lib/solr_wrapper_spec.rb
|
|
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
170
171
|
version: '0'
|
|
171
172
|
requirements: []
|
|
172
173
|
rubyforge_project:
|
|
173
|
-
rubygems_version: 2.5.1
|
|
174
|
+
rubygems_version: 2.4.5.1
|
|
174
175
|
signing_key:
|
|
175
176
|
specification_version: 4
|
|
176
177
|
summary: Solr 5 service wrapper
|
|
@@ -183,8 +184,8 @@ test_files:
|
|
|
183
184
|
- spec/fixtures/basic_configs/solrconfig.xml
|
|
184
185
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
185
186
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
187
|
+
- spec/fixtures/sample_config.yml
|
|
186
188
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
187
189
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
188
190
|
- spec/lib/solr_wrapper_spec.rb
|
|
189
191
|
- spec/spec_helper.rb
|
|
190
|
-
has_rdoc:
|