solr_wrapper 0.2.0 → 0.3.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/.rspec +2 -0
- data/.travis.yml +1 -1
- data/README.md +55 -6
- data/exe/solr_wrapper +26 -2
- data/lib/solr_wrapper/instance.rb +113 -52
- data/lib/solr_wrapper/rake_task.rb +5 -0
- data/lib/solr_wrapper/tasks/solr_wrapper.rake +46 -0
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +6 -2
- data/spec/lib/solr_wrapper/instance_spec.rb +23 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02801c03fb674022382afba55cb728b5ec82d177
|
4
|
+
data.tar.gz: e042c59c01ab0ed69f48a0415032c5e5f798ae4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36168cce73a5fef10a0e683068363955f94f23cfc92132f6bf856b89d75605f9a804506aa8d2cd6bdc07acdc930f5053fb43a6aab7eeac311eb9d427b9f04d06
|
7
|
+
data.tar.gz: c9e006036531e1e31a23b3babda62345a1c6742d741d7ede1fa4f2eeac579f3dd3372dacfc9f6be6924dfdee883bc594b9b1f39882fe17f52db90f077cd16466
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -11,18 +11,67 @@ end
|
|
11
11
|
Or with Solr and a solr collection:
|
12
12
|
|
13
13
|
```ruby
|
14
|
-
|
15
|
-
|
16
|
-
end
|
14
|
+
SolrWrapper.wrap do |solr|
|
15
|
+
solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
|
17
16
|
end
|
17
|
+
end
|
18
18
|
```
|
19
19
|
|
20
20
|
## Basic Options
|
21
21
|
|
22
22
|
```ruby
|
23
|
-
SolrWrapper.wrap port: 8983,
|
23
|
+
SolrWrapper.wrap port: 8983,
|
24
|
+
verbose: true,
|
25
|
+
managed: true,
|
26
|
+
instance_dir: '/opt/solr'
|
24
27
|
```
|
25
28
|
|
29
|
+
Options:
|
30
|
+
|
31
|
+
|Option | |
|
32
|
+
|---------------|-----------------------------------------|
|
33
|
+
| instance_dir | Directory to store the solr index files |
|
34
|
+
| url | URL of the Zip file to download |
|
35
|
+
| version | Solr version to download and install |
|
36
|
+
| port | port to run Solr on |
|
37
|
+
| version_file | Local path to store the currently installed version |
|
38
|
+
| download_path | Local path for storing the downloaded Solr zip file |
|
39
|
+
| md5sum | Path/URL to MD5 checksum |
|
40
|
+
| solr_xml | Path to Solr configuration |
|
41
|
+
| verbose | (Boolean) |
|
42
|
+
| managed | (Boolean) |
|
43
|
+
| ignore_md5sum | (Boolean) |
|
44
|
+
| solr_options | (Hash) |
|
45
|
+
| env | (Hash) |
|
46
|
+
|
26
47
|
```ruby
|
27
|
-
solr.with_collection(name: 'collection_name', dir: '
|
28
|
-
```
|
48
|
+
solr.with_collection(name: 'collection_name', dir: 'path_to_solr_configs')
|
49
|
+
```
|
50
|
+
|
51
|
+
## From the command line
|
52
|
+
|
53
|
+
```console
|
54
|
+
$ solr_wrapper -p 8983
|
55
|
+
```
|
56
|
+
|
57
|
+
## Rake tasks
|
58
|
+
|
59
|
+
SolrWrapper provides rake tasks for installing, starting and stopping solr. To include the tasks in your Rake environment, add this to your Rakefile
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
require 'solr_wrapper/rake_task'
|
63
|
+
```
|
64
|
+
|
65
|
+
You can configure the tasks by setting `SolrWrapper.default_instance_options`. For example:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
SolrWrapper.default_instance_options = {
|
69
|
+
verbose: true,
|
70
|
+
cloud: true,
|
71
|
+
port: '8888',
|
72
|
+
version: '5.3.1',
|
73
|
+
instance_dir: 'solr',
|
74
|
+
download_dir: 'tmp'
|
75
|
+
}
|
76
|
+
require 'solr_wrapper/rake_task'
|
77
|
+
```
|
data/exe/solr_wrapper
CHANGED
@@ -4,6 +4,7 @@ require 'solr_wrapper'
|
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
options = {}
|
7
|
+
collection_options = {}
|
7
8
|
OptionParser.new do |opts|
|
8
9
|
opts.banner = "Usage: solr_wrapper [options]"
|
9
10
|
|
@@ -18,13 +19,36 @@ OptionParser.new do |opts|
|
|
18
19
|
opts.on("-pPORT", "--port PORT", "Specify the port Solr should run at (default: 8983)") do |p|
|
19
20
|
options[:port] = p
|
20
21
|
end
|
22
|
+
|
23
|
+
opts.on("-c", "--cloud", "Run solr in cloud mode") do |c|
|
24
|
+
options[:cloud] = c
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("-iDIR", "--instance_directory DIR", "Install/use solr at the given directory") do |d|
|
28
|
+
options[:instance_dir] = d
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("-lDIR", "--lib_directory DIR", "Grab extra libs from this directory") do |d|
|
32
|
+
options[:extra_lib_dir] = d
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("-nNAME", "--collection_name NAME", "Create a default solr collection with the given name") do |c|
|
36
|
+
collection_options[:name] = c
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("-dDIR", "--collection_config DIR", "Create a default solr collection with the files from the given directory") do |d|
|
40
|
+
collection_options[:dir] = d
|
41
|
+
end
|
42
|
+
|
21
43
|
end.parse!
|
22
44
|
|
23
45
|
# default to verbose
|
24
46
|
options[:verbose] = true if options[:verbose].nil?
|
25
47
|
|
26
48
|
SolrWrapper.wrap(options) do |conn|
|
27
|
-
|
28
|
-
|
49
|
+
conn.with_collection(collection_options) do
|
50
|
+
while conn.status
|
51
|
+
sleep 1
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
@@ -15,15 +15,18 @@ module SolrWrapper
|
|
15
15
|
##
|
16
16
|
# @param [Hash] options
|
17
17
|
# @option options [String] :url
|
18
|
-
# @option options [String] :
|
19
|
-
# @option options [String] :
|
20
|
-
# @option options [String] :
|
21
|
-
# @option options [
|
22
|
-
# @option options [String] :
|
23
|
-
# @option options [String] :
|
24
|
-
# @option options [String] :
|
25
|
-
# @option options [Boolean] :
|
26
|
-
# @option options [
|
18
|
+
# @option options [String] :instance_dir Directory to store the solr index files
|
19
|
+
# @option options [String] :version Solr version to download and install
|
20
|
+
# @option options [String] :port port to run Solr on
|
21
|
+
# @option options [Boolean] :cloud Run solr in cloud mode
|
22
|
+
# @option options [String] :version_file Local path to store the currently installed version
|
23
|
+
# @option options [String] :download_dir Local directory to store the downloaded Solr zip and its md5 file in (overridden by :download_path)
|
24
|
+
# @option options [String] :download_path Local path for storing the downloaded Solr zip file
|
25
|
+
# @option options [Boolean] :validate Should solr_wrapper download a new md5 and (re-)validate the zip file? (default: trueF)
|
26
|
+
# @option options [String] :md5sum Path/URL to MD5 checksum
|
27
|
+
# @option options [String] :solr_xml Path to Solr configuration
|
28
|
+
# @option options [String] :extra_lib_dir Path to directory containing extra libraries to copy into instance_dir/lib
|
29
|
+
# @option options [Boolean] :verbose return verbose info when running solr commands
|
27
30
|
# @option options [Boolean] :ignore_md5sum
|
28
31
|
# @option options [Hash] :solr_options
|
29
32
|
# @option options [Hash] :env
|
@@ -32,6 +35,7 @@ module SolrWrapper
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def wrap(&_block)
|
38
|
+
extract_and_configure
|
35
39
|
start
|
36
40
|
yield self
|
37
41
|
ensure
|
@@ -41,9 +45,9 @@ module SolrWrapper
|
|
41
45
|
##
|
42
46
|
# Start Solr and wait for it to become available
|
43
47
|
def start
|
44
|
-
|
48
|
+
extract_and_configure
|
45
49
|
if managed?
|
46
|
-
exec('start', p: port)
|
50
|
+
exec('start', p: port, c: options[:cloud])
|
47
51
|
|
48
52
|
# Wait for solr to start
|
49
53
|
unless status
|
@@ -67,12 +71,20 @@ module SolrWrapper
|
|
67
71
|
@pid = nil
|
68
72
|
end
|
69
73
|
|
74
|
+
##
|
75
|
+
# Stop Solr and wait for it to finish exiting
|
76
|
+
def restart
|
77
|
+
if managed? && started?
|
78
|
+
exec('restart', p: port, c: options[:cloud])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
70
82
|
##
|
71
83
|
# Check the status of a managed Solr service
|
72
84
|
def status
|
73
85
|
return true unless managed?
|
74
86
|
|
75
|
-
out = exec('status'
|
87
|
+
out = exec('status').read
|
76
88
|
out =~ /running on port #{port}/
|
77
89
|
end
|
78
90
|
|
@@ -90,7 +102,10 @@ module SolrWrapper
|
|
90
102
|
def create(options = {})
|
91
103
|
options[:name] ||= SecureRandom.hex
|
92
104
|
|
93
|
-
|
105
|
+
create_options = { p: port }
|
106
|
+
create_options[:c] = options[:name] if options[:name]
|
107
|
+
create_options[:d] = options[:dir] if options[:dir]
|
108
|
+
exec("create", create_options)
|
94
109
|
|
95
110
|
options[:name]
|
96
111
|
end
|
@@ -108,6 +123,8 @@ module SolrWrapper
|
|
108
123
|
# @option options [String] :name
|
109
124
|
# @option options [String] :dir
|
110
125
|
def with_collection(options = {})
|
126
|
+
return yield if options.empty?
|
127
|
+
|
111
128
|
name = create(options)
|
112
129
|
begin
|
113
130
|
yield name
|
@@ -126,24 +143,48 @@ module SolrWrapper
|
|
126
143
|
# Clean up any files solr_wrapper may have downloaded
|
127
144
|
def clean!
|
128
145
|
stop
|
129
|
-
|
146
|
+
remove_instance_dir!
|
147
|
+
FileUtils.remove_entry(download_path) if File.exists?(download_path)
|
130
148
|
FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir
|
131
|
-
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
132
149
|
FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path
|
133
150
|
FileUtils.remove_entry(version_file) if File.exists? version_file
|
134
151
|
end
|
135
152
|
|
153
|
+
##
|
154
|
+
# Clean up any files in the Solr instance dir
|
155
|
+
def remove_instance_dir!
|
156
|
+
FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
|
157
|
+
end
|
158
|
+
|
136
159
|
##
|
137
160
|
# Get a (likely) URL to the solr instance
|
138
161
|
def url
|
139
162
|
"http://127.0.0.1:#{port}/solr/"
|
140
163
|
end
|
141
164
|
|
142
|
-
|
165
|
+
def configure
|
166
|
+
raise_error_unless_extracted
|
167
|
+
FileUtils.cp options[:solr_xml], File.join(instance_dir, 'server', 'solr', 'solr.xml') if options[:solr_xml]
|
168
|
+
FileUtils.cp_r File.join(options[:extra_lib_dir], '.'), File.join(instance_dir, 'server', 'solr', 'lib') if options[:extra_lib_dir]
|
169
|
+
end
|
170
|
+
|
171
|
+
def instance_dir
|
172
|
+
@instance_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(download_url, ".zip")))
|
173
|
+
end
|
174
|
+
|
175
|
+
def extract_and_configure
|
176
|
+
instance_dir = extract
|
177
|
+
configure
|
178
|
+
instance_dir
|
179
|
+
end
|
143
180
|
|
144
181
|
# rubocop:disable Lint/RescueException
|
182
|
+
|
183
|
+
# extract a copy of solr to instance_dir
|
184
|
+
# Does noting if solr already exists at instance_dir
|
185
|
+
# @return [String] instance_dir Directory where solr has been installed
|
145
186
|
def extract
|
146
|
-
return
|
187
|
+
return instance_dir if extracted?
|
147
188
|
|
148
189
|
zip_path = download
|
149
190
|
|
@@ -162,32 +203,37 @@ module SolrWrapper
|
|
162
203
|
end
|
163
204
|
|
164
205
|
begin
|
165
|
-
FileUtils.remove_dir(
|
166
|
-
FileUtils.cp_r File.join(tmp_save_dir, File.basename(download_url, ".zip")),
|
206
|
+
FileUtils.remove_dir(instance_dir, true)
|
207
|
+
FileUtils.cp_r File.join(tmp_save_dir, File.basename(download_url, ".zip")), instance_dir
|
167
208
|
self.extracted_version = version
|
168
209
|
FileUtils.chmod 0755, solr_binary
|
169
210
|
rescue Exception => e
|
170
|
-
abort "Unable to copy #{tmp_save_dir} to #{
|
211
|
+
abort "Unable to copy #{tmp_save_dir} to #{instance_dir}: #{e.message}"
|
171
212
|
end
|
172
213
|
|
173
|
-
|
174
|
-
|
175
|
-
solr_dir
|
214
|
+
instance_dir
|
176
215
|
ensure
|
177
216
|
FileUtils.remove_entry tmp_save_dir if File.exists? tmp_save_dir
|
178
217
|
end
|
179
218
|
# rubocop:enable Lint/RescueException
|
180
219
|
|
220
|
+
protected
|
221
|
+
|
222
|
+
def extracted?
|
223
|
+
File.exists?(solr_binary) && extracted_version == version
|
224
|
+
end
|
225
|
+
|
181
226
|
def download
|
182
227
|
unless File.exists?(download_path) && validate?(download_path)
|
183
228
|
fetch_with_progressbar download_url, download_path
|
184
229
|
validate! download_path
|
185
230
|
end
|
186
|
-
|
187
231
|
download_path
|
188
232
|
end
|
189
233
|
|
190
234
|
def validate?(file)
|
235
|
+
return true if options[:validate] == false
|
236
|
+
|
191
237
|
Digest::MD5.file(file).hexdigest == expected_md5sum
|
192
238
|
end
|
193
239
|
|
@@ -199,10 +245,27 @@ module SolrWrapper
|
|
199
245
|
|
200
246
|
##
|
201
247
|
# Run a bin/solr command
|
248
|
+
# @param [String] cmd command to run
|
249
|
+
# @param [Hash] options key-value pairs to transform into command line arguments
|
250
|
+
# @return [StringIO] an IO object for the executed shell command
|
202
251
|
# @see https://github.com/apache/lucene-solr/blob/trunk/solr/bin/solr
|
252
|
+
# If you want to pass a boolean flag, include it in the +options+ hash with its value set to +true+
|
253
|
+
# the key will be converted into a boolean flag for you.
|
254
|
+
# @example start solr in cloud mode on port 8983
|
255
|
+
# exec('start', {p: '8983', c: true})
|
203
256
|
def exec(cmd, options = {})
|
204
|
-
|
205
|
-
|
257
|
+
silence_output = !options.delete(:output)
|
258
|
+
|
259
|
+
args = [solr_binary, cmd] + solr_options.merge(options).map do |k, v|
|
260
|
+
case v
|
261
|
+
when true
|
262
|
+
"-#{k}"
|
263
|
+
when false, nil
|
264
|
+
# don't return anything
|
265
|
+
else
|
266
|
+
["-#{k}", "#{v}"]
|
267
|
+
end
|
268
|
+
end.flatten.compact
|
206
269
|
|
207
270
|
if IO.respond_to? :popen4
|
208
271
|
# JRuby
|
@@ -210,44 +273,40 @@ module SolrWrapper
|
|
210
273
|
pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
|
211
274
|
@pid = pid
|
212
275
|
stringio = StringIO.new
|
213
|
-
if verbose? && !
|
276
|
+
if verbose? && !silence_output
|
214
277
|
IO.copy_stream(output, $stderr)
|
215
278
|
IO.copy_stream(error, $stderr)
|
216
279
|
else
|
217
280
|
IO.copy_stream(output, stringio)
|
218
281
|
IO.copy_stream(error, stringio)
|
219
282
|
end
|
283
|
+
|
220
284
|
input.close
|
221
285
|
output.close
|
222
286
|
error.close
|
223
|
-
|
224
|
-
stringio.rewind
|
225
|
-
|
226
|
-
if $? != 0
|
227
|
-
raise "Failed to execute solr #{cmd}: #{stringio.read}"
|
228
|
-
end
|
229
|
-
|
230
|
-
stringio
|
287
|
+
exit_status = Process.waitpid2(@pid).last
|
231
288
|
else
|
232
289
|
IO.popen(env, args + [err: [:child, :out]]) do |io|
|
233
290
|
stringio = StringIO.new
|
234
|
-
|
291
|
+
|
292
|
+
if verbose? && !silence_output
|
235
293
|
IO.copy_stream(io, $stderr)
|
236
294
|
else
|
237
295
|
IO.copy_stream(io, stringio)
|
238
296
|
end
|
297
|
+
|
239
298
|
@pid = io.pid
|
240
299
|
|
241
300
|
_, exit_status = Process.wait2(io.pid)
|
242
|
-
stringio.rewind
|
243
|
-
|
244
|
-
if exit_status != 0
|
245
|
-
raise "Failed to execute solr #{cmd}: #{stringio.read}"
|
246
|
-
end
|
247
|
-
|
248
|
-
stringio
|
249
301
|
end
|
250
302
|
end
|
303
|
+
|
304
|
+
stringio.rewind
|
305
|
+
if exit_status != 0
|
306
|
+
raise "Failed to execute solr #{cmd}: #{stringio.read}"
|
307
|
+
end
|
308
|
+
|
309
|
+
stringio
|
251
310
|
end
|
252
311
|
|
253
312
|
private
|
@@ -290,11 +349,13 @@ module SolrWrapper
|
|
290
349
|
end
|
291
350
|
|
292
351
|
def default_download_path
|
293
|
-
File.join(
|
352
|
+
File.join(download_dir, File.basename(download_url))
|
294
353
|
end
|
295
354
|
|
296
|
-
def
|
297
|
-
@
|
355
|
+
def download_dir
|
356
|
+
@download_dir ||= options.fetch(:download_dir, Dir.tmpdir)
|
357
|
+
FileUtils.mkdir_p @download_dir
|
358
|
+
@download_dir
|
298
359
|
end
|
299
360
|
|
300
361
|
def verbose?
|
@@ -302,11 +363,11 @@ module SolrWrapper
|
|
302
363
|
end
|
303
364
|
|
304
365
|
def managed?
|
305
|
-
|
366
|
+
File.exists?(instance_dir)
|
306
367
|
end
|
307
368
|
|
308
369
|
def version_file
|
309
|
-
options.fetch(:version_file, File.join(
|
370
|
+
options.fetch(:version_file, File.join(instance_dir, "VERSION"))
|
310
371
|
end
|
311
372
|
|
312
373
|
def expected_md5sum
|
@@ -314,11 +375,11 @@ module SolrWrapper
|
|
314
375
|
end
|
315
376
|
|
316
377
|
def solr_binary
|
317
|
-
File.join(
|
378
|
+
File.join(instance_dir, "bin", "solr")
|
318
379
|
end
|
319
380
|
|
320
381
|
def md5sum_path
|
321
|
-
File.join(
|
382
|
+
File.join(download_dir, File.basename(md5url))
|
322
383
|
end
|
323
384
|
|
324
385
|
def tmp_save_dir
|
@@ -357,8 +418,8 @@ module SolrWrapper
|
|
357
418
|
end
|
358
419
|
end
|
359
420
|
|
360
|
-
def
|
361
|
-
|
421
|
+
def raise_error_unless_extracted
|
422
|
+
raise RuntimeError, "there is no solr instance at #{instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
362
423
|
end
|
363
424
|
end
|
364
425
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'solr_wrapper'
|
2
|
+
|
3
|
+
## These tasks get loaded into the host context when solr_wrapper is required
|
4
|
+
namespace :solr do
|
5
|
+
desc "Load the solr options and solr instance"
|
6
|
+
task :environment do
|
7
|
+
SolrWrapper.default_instance_options[:download_dir] ||= Rails.root.to_s + '/tmp' if defined? Rails
|
8
|
+
@solr_instance = SolrWrapper.default_instance
|
9
|
+
end
|
10
|
+
|
11
|
+
desc 'Install a clean version of solr. Replaces the existing copy if there is one.'
|
12
|
+
task clean: :environment do
|
13
|
+
puts "Installing clean version of solr at #{File.expand_path(@solr_instance.instance_dir)}"
|
14
|
+
@solr_instance.remove_instance_dir!
|
15
|
+
@solr_instance.extract_and_configure
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'start solr'
|
19
|
+
task start: :environment do
|
20
|
+
begin
|
21
|
+
puts "Starting solr at #{File.expand_path(@solr_instance.instance_dir)} with options #{@solr_instance.options}"
|
22
|
+
@solr_instance.start
|
23
|
+
rescue => e
|
24
|
+
if e.message.include?("Port #{@solr_instance.port} is already being used by another process")
|
25
|
+
puts "FAILED. Port #{@solr_instance.port} is already being used."
|
26
|
+
puts " Did you already have solr running?"
|
27
|
+
puts " a) YES: Continue as you were. Solr is running."
|
28
|
+
puts " b) NO: Either set SOLR_OPTIONS[:port] to a different value or stop the process that's using port #{@solr_instance.port}."
|
29
|
+
else
|
30
|
+
raise "Failed to start solr. #{e.class}: #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'restart solr'
|
36
|
+
task restart: :environment do
|
37
|
+
puts "Restarting solr"
|
38
|
+
@solr_instance.restart
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'stop solr'
|
42
|
+
task stop: :environment do
|
43
|
+
@solr_instance.stop
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
@@ -3,11 +3,15 @@ require 'solr_wrapper/instance'
|
|
3
3
|
|
4
4
|
module SolrWrapper
|
5
5
|
def self.default_solr_version
|
6
|
-
'5.3.
|
6
|
+
'5.3.1'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.default_instance_options
|
10
|
+
@default_instance_options ||= {}
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.default_instance(options = {})
|
10
|
-
@default_instance ||= SolrWrapper::Instance.new options
|
14
|
+
@default_instance ||= SolrWrapper::Instance.new default_instance_options.merge(options)
|
11
15
|
end
|
12
16
|
|
13
17
|
##
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe SolrWrapper::Instance do
|
4
|
-
|
4
|
+
let(:solr_instance) { SolrWrapper::Instance.new }
|
5
|
+
subject { solr_instance }
|
5
6
|
let(:client) { SimpleSolrClient::Client.new("http://localhost:#{subject.port}/solr/") }
|
6
7
|
describe "#with_collection" do
|
7
8
|
it "should create a new anonymous collection" do
|
@@ -16,4 +17,25 @@ describe SolrWrapper::Instance do
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
describe 'exec' do
|
21
|
+
let(:cmd) { 'start' }
|
22
|
+
let(:options) { { p: '4098', help: true } }
|
23
|
+
subject { solr_instance.send(:exec, cmd, options) }
|
24
|
+
it 'runs the command' do
|
25
|
+
result_io = subject
|
26
|
+
expect(result_io.read).to include('Usage: solr start')
|
27
|
+
end
|
28
|
+
it 'accepts boolean flags' do
|
29
|
+
result_io = solr_instance.send(:exec, 'start', p: '4098', help: true)
|
30
|
+
expect(result_io.read).to include('Usage: solr start')
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'when something goes wrong' do
|
34
|
+
let(:cmd) { 'healthcheck' }
|
35
|
+
let(:options) { { z: 'localhost:5098' } }
|
36
|
+
it 'raises an error with the output from the shell command' do
|
37
|
+
expect { subject }.to raise_error(RuntimeError, /Failed to execute solr healthcheck: collection parameter is required!/)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
19
41
|
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: 0.
|
4
|
+
version: 0.3.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: 2015-
|
11
|
+
date: 2015-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -117,6 +117,7 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".rspec"
|
120
121
|
- ".rubocop.yml"
|
121
122
|
- ".rubocop_hound.yml"
|
122
123
|
- ".rubocop_todo.yml"
|
@@ -129,6 +130,8 @@ files:
|
|
129
130
|
- exe/solr_wrapper
|
130
131
|
- lib/solr_wrapper.rb
|
131
132
|
- lib/solr_wrapper/instance.rb
|
133
|
+
- lib/solr_wrapper/rake_task.rb
|
134
|
+
- lib/solr_wrapper/tasks/solr_wrapper.rake
|
132
135
|
- lib/solr_wrapper/version.rb
|
133
136
|
- solr_wrapper.gemspec
|
134
137
|
- spec/fixtures/basic_configs/_rest_managed.json
|
@@ -162,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
165
|
version: '0'
|
163
166
|
requirements: []
|
164
167
|
rubyforge_project:
|
165
|
-
rubygems_version: 2.4.5
|
168
|
+
rubygems_version: 2.4.5.1
|
166
169
|
signing_key:
|
167
170
|
specification_version: 4
|
168
171
|
summary: Solr 5 service wrapper
|