solr_wrapper 0.9.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/exe/solr_wrapper +1 -3
- data/lib/solr_wrapper/configuration.rb +10 -1
- data/lib/solr_wrapper/instance.rb +35 -13
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +1 -1
- data/spec/fixtures/sample_config.yml +3 -0
- data/spec/lib/solr_wrapper/configuration_spec.rb +11 -0
- data/spec/lib/solr_wrapper/instance_spec.rb +17 -0
- data/spec/lib/solr_wrapper_spec.rb +8 -0
- metadata +2 -2
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/exe/solr_wrapper
CHANGED
|
@@ -74,9 +74,7 @@ instance.wrap do |conn|
|
|
|
74
74
|
conn.with_collection(collection_options) do
|
|
75
75
|
$stderr.puts "http://#{instance.host}:#{instance.port}/solr/"
|
|
76
76
|
begin
|
|
77
|
-
|
|
78
|
-
sleep 1
|
|
79
|
-
end
|
|
77
|
+
conn.wait
|
|
80
78
|
rescue Interrupt
|
|
81
79
|
$stderr.puts "Solr is shutting down."
|
|
82
80
|
end
|
|
@@ -55,7 +55,7 @@ module SolrWrapper
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def default_download_dir
|
|
58
|
-
if defined? Rails
|
|
58
|
+
if defined?(Rails) && Rails.root
|
|
59
59
|
File.join(Rails.root, 'tmp')
|
|
60
60
|
else
|
|
61
61
|
Dir.tmpdir
|
|
@@ -99,6 +99,15 @@ module SolrWrapper
|
|
|
99
99
|
Configuration.slice(convert_keys(hash), :name, :dir)
|
|
100
100
|
end
|
|
101
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
|
+
|
|
102
111
|
private
|
|
103
112
|
|
|
104
113
|
def self.slice(source, *keys)
|
|
@@ -12,7 +12,7 @@ require 'yaml'
|
|
|
12
12
|
|
|
13
13
|
module SolrWrapper
|
|
14
14
|
class Instance
|
|
15
|
-
attr_reader :config, :md5
|
|
15
|
+
attr_reader :config, :md5
|
|
16
16
|
|
|
17
17
|
##
|
|
18
18
|
# @param [Hash] options
|
|
@@ -75,8 +75,10 @@ module SolrWrapper
|
|
|
75
75
|
|
|
76
76
|
# Wait for solr to start
|
|
77
77
|
unless status
|
|
78
|
-
sleep
|
|
78
|
+
sleep config.poll_interval
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
after_start
|
|
80
82
|
end
|
|
81
83
|
end
|
|
82
84
|
|
|
@@ -84,15 +86,9 @@ module SolrWrapper
|
|
|
84
86
|
# Stop Solr and wait for it to finish exiting
|
|
85
87
|
def stop
|
|
86
88
|
if config.managed? && started?
|
|
87
|
-
|
|
88
89
|
exec('stop', p: port)
|
|
89
|
-
|
|
90
|
-
while status
|
|
91
|
-
sleep 1
|
|
92
|
-
end
|
|
90
|
+
wait
|
|
93
91
|
end
|
|
94
|
-
|
|
95
|
-
@pid = nil
|
|
96
92
|
end
|
|
97
93
|
|
|
98
94
|
##
|
|
@@ -114,12 +110,31 @@ module SolrWrapper
|
|
|
114
110
|
false
|
|
115
111
|
end
|
|
116
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
|
+
|
|
117
126
|
##
|
|
118
127
|
# Is Solr running?
|
|
119
128
|
def started?
|
|
120
129
|
!!status
|
|
121
130
|
end
|
|
122
131
|
|
|
132
|
+
def wait
|
|
133
|
+
while (Process.getpgid(pid) rescue status)
|
|
134
|
+
sleep config.poll_interval
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
123
138
|
##
|
|
124
139
|
# Create a new collection in solr
|
|
125
140
|
# @param [Hash] options
|
|
@@ -305,7 +320,6 @@ module SolrWrapper
|
|
|
305
320
|
# JRuby
|
|
306
321
|
env_str = config.env.map { |k, v| "#{Shellwords.escape(k)}=#{Shellwords.escape(v)}" }.join(" ")
|
|
307
322
|
pid, input, output, error = IO.popen4(env_str + " " + args.join(" "))
|
|
308
|
-
@pid = pid
|
|
309
323
|
stringio = StringIO.new
|
|
310
324
|
if config.verbose? && !silence_output
|
|
311
325
|
IO.copy_stream(output, $stderr)
|
|
@@ -318,7 +332,7 @@ module SolrWrapper
|
|
|
318
332
|
input.close
|
|
319
333
|
output.close
|
|
320
334
|
error.close
|
|
321
|
-
exit_status = Process.waitpid2(
|
|
335
|
+
exit_status = Process.waitpid2(pid).last
|
|
322
336
|
else
|
|
323
337
|
IO.popen(config.env, args + [err: [:child, :out]]) do |io|
|
|
324
338
|
stringio = StringIO.new
|
|
@@ -329,8 +343,6 @@ module SolrWrapper
|
|
|
329
343
|
IO.copy_stream(io, stringio)
|
|
330
344
|
end
|
|
331
345
|
|
|
332
|
-
@pid = io.pid
|
|
333
|
-
|
|
334
346
|
_, exit_status = Process.wait2(io.pid)
|
|
335
347
|
end
|
|
336
348
|
end
|
|
@@ -345,6 +357,16 @@ module SolrWrapper
|
|
|
345
357
|
|
|
346
358
|
private
|
|
347
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
|
+
|
|
348
370
|
def extracted_version
|
|
349
371
|
File.read(config.version_file).strip if File.exists? config.version_file
|
|
350
372
|
end
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
|
@@ -41,4 +41,15 @@ describe SolrWrapper::Configuration do
|
|
|
41
41
|
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
|
|
42
42
|
end
|
|
43
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
|
|
44
55
|
end
|
|
@@ -7,6 +7,7 @@ describe SolrWrapper::Instance do
|
|
|
7
7
|
let(:client) { SimpleSolrClient::Client.new(subject.url) }
|
|
8
8
|
|
|
9
9
|
describe "#with_collection" do
|
|
10
|
+
let(:options) { { cloud: false } }
|
|
10
11
|
context "without a name" do
|
|
11
12
|
it "creates a new anonymous collection" do
|
|
12
13
|
subject.wrap do |solr|
|
|
@@ -51,6 +52,22 @@ describe SolrWrapper::Instance do
|
|
|
51
52
|
end
|
|
52
53
|
end
|
|
53
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
|
|
54
71
|
end
|
|
55
72
|
|
|
56
73
|
describe 'exec' 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-04-
|
|
11
|
+
date: 2016-04-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|