solr_wrapper 0.8.0 → 0.9.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/exe/solr_wrapper +13 -5
- data/lib/solr_wrapper/configuration.rb +17 -1
- data/lib/solr_wrapper/instance.rb +45 -0
- data/lib/solr_wrapper/settings.rb +11 -1
- data/lib/solr_wrapper/tasks/solr_wrapper.rake +1 -2
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +11 -3
- data/spec/lib/solr_wrapper/instance_spec.rb +25 -1
- 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: 21a2a6e484329fe66c2531342783d9ac4007a1a3
|
|
4
|
+
data.tar.gz: 25cd86f3084f418c6a88192986b0ba6d6a2013b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 08b856eb075be3bb9521531f700ba0dd367f18917a787cda40537419707c16a69abc6c6ad27c1a64459a6642a73c7e0aa705d41e5fcc1a13d212dc5708b020fe
|
|
7
|
+
data.tar.gz: 9ee588f5119ad0806f84178b2969e7b06f26d3a0407913e5f0a99ae5d80585249a6b360e64e032795d778b3bc04173ab8419ad1b6ef4616a6eb2ea38a7e97481
|
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,12 +55,20 @@ 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
|
|
@@ -38,12 +38,28 @@ module SolrWrapper
|
|
|
38
38
|
options.fetch(:port) { SolrWrapper.default_instance_options[:port] }.to_s
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
def zookeeper_host
|
|
42
|
+
options[:zookeeper_host]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def zookeeper_port
|
|
46
|
+
options[:zookeeper_port]
|
|
47
|
+
end
|
|
48
|
+
|
|
41
49
|
def download_path
|
|
42
50
|
options[:download_path]
|
|
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
|
|
59
|
+
File.join(Rails.root, 'tmp')
|
|
60
|
+
else
|
|
61
|
+
Dir.tmpdir
|
|
62
|
+
end
|
|
47
63
|
end
|
|
48
64
|
|
|
49
65
|
def solr_options
|
|
@@ -50,6 +50,10 @@ module SolrWrapper
|
|
|
50
50
|
config.url
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def instance_dir
|
|
54
|
+
config.instance_dir
|
|
55
|
+
end
|
|
56
|
+
|
|
53
57
|
def version
|
|
54
58
|
config.version
|
|
55
59
|
end
|
|
@@ -126,12 +130,49 @@ module SolrWrapper
|
|
|
126
130
|
|
|
127
131
|
create_options = { p: port }
|
|
128
132
|
create_options[:c] = options[:name] if options[:name]
|
|
133
|
+
create_options[:n] = options[:config_name] if options[:config_name]
|
|
129
134
|
create_options[:d] = options[:dir] if options[:dir]
|
|
130
135
|
exec("create", create_options)
|
|
131
136
|
|
|
132
137
|
options[:name]
|
|
133
138
|
end
|
|
134
139
|
|
|
140
|
+
##
|
|
141
|
+
# Update the collection configuration in zookeeper
|
|
142
|
+
# @param [Hash] options
|
|
143
|
+
# @option options [String] :config_name
|
|
144
|
+
# @option options [String] :dir
|
|
145
|
+
def upconfig(options = {})
|
|
146
|
+
options[:name] ||= SecureRandom.hex
|
|
147
|
+
options[:zkhost] ||= zkhost
|
|
148
|
+
|
|
149
|
+
upconfig_options = { upconfig: true, n: options[:name] }
|
|
150
|
+
upconfig_options[:d] = options[:dir] if options[:dir]
|
|
151
|
+
upconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
152
|
+
|
|
153
|
+
exec 'zk', upconfig_options
|
|
154
|
+
|
|
155
|
+
options[:name]
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
##
|
|
159
|
+
# Copy the collection configuration from zookeeper to a local directory
|
|
160
|
+
# @param [Hash] options
|
|
161
|
+
# @option options [String] :config_name
|
|
162
|
+
# @option options [String] :dir
|
|
163
|
+
def downconfig(options = {})
|
|
164
|
+
options[:name] ||= SecureRandom.hex
|
|
165
|
+
options[:zkhost] ||= zkhost
|
|
166
|
+
|
|
167
|
+
downconfig_options = { downconfig: true, n: options[:name] }
|
|
168
|
+
downconfig_options[:d] = options[:dir] if options[:dir]
|
|
169
|
+
downconfig_options[:z] = options[:zkhost] if options[:zkhost]
|
|
170
|
+
|
|
171
|
+
exec 'zk', downconfig_options
|
|
172
|
+
|
|
173
|
+
options[:name]
|
|
174
|
+
end
|
|
175
|
+
|
|
135
176
|
##
|
|
136
177
|
# Create a new collection in solr
|
|
137
178
|
# @param [String] name collection name
|
|
@@ -314,6 +355,10 @@ module SolrWrapper
|
|
|
314
355
|
end
|
|
315
356
|
end
|
|
316
357
|
|
|
358
|
+
def zkhost
|
|
359
|
+
"#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
|
|
360
|
+
end
|
|
361
|
+
|
|
317
362
|
def raise_error_unless_extracted
|
|
318
363
|
raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
|
319
364
|
end
|
|
@@ -25,6 +25,11 @@ module SolrWrapper
|
|
|
25
25
|
'127.0.0.1'
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def zookeeper_host
|
|
29
|
+
@zookeeper_host ||= static_config.zookeeper_port
|
|
30
|
+
@zookeeper_host ||= host
|
|
31
|
+
end
|
|
32
|
+
|
|
28
33
|
##
|
|
29
34
|
# Get the port this Solr instance is running at
|
|
30
35
|
def port
|
|
@@ -32,6 +37,12 @@ module SolrWrapper
|
|
|
32
37
|
@port ||= random_open_port.to_s
|
|
33
38
|
end
|
|
34
39
|
|
|
40
|
+
def zookeeper_port
|
|
41
|
+
@zookeeper_port ||= static_config.zookeeper_port
|
|
42
|
+
@zookeeper_port ||= "#{port.to_i + 1000}"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
35
46
|
##
|
|
36
47
|
# Get a (likely) URL to the solr instance
|
|
37
48
|
def url
|
|
@@ -85,7 +96,6 @@ module SolrWrapper
|
|
|
85
96
|
|
|
86
97
|
def download_dir
|
|
87
98
|
@download_dir ||= static_config.download_dir
|
|
88
|
-
@download_dir ||= Dir.tmpdir
|
|
89
99
|
FileUtils.mkdir_p @download_dir
|
|
90
100
|
@download_dir
|
|
91
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
|
@@ -10,9 +10,13 @@ module SolrWrapper
|
|
|
10
10
|
'6.0.0'
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
def self.default_solr_port
|
|
14
|
+
'8983'
|
|
15
|
+
end
|
|
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
|
|
@@ -1,7 +1,8 @@
|
|
|
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
|
|
|
@@ -34,6 +35,24 @@ describe SolrWrapper::Instance do
|
|
|
34
35
|
end
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
context 'with a SolrCloud instance' do
|
|
39
|
+
let(:options) { { cloud: true } }
|
|
40
|
+
it 'can upload configurations' do
|
|
41
|
+
subject.wrap do |solr|
|
|
42
|
+
config_name = solr.upconfig dir: File.join(FIXTURES_DIR, 'basic_configs')
|
|
43
|
+
Dir.mktmpdir do |dir|
|
|
44
|
+
solr.downconfig name: config_name, dir: dir
|
|
45
|
+
end
|
|
46
|
+
solr.with_collection(config_name: config_name) do |collection_name|
|
|
47
|
+
core = client.core(collection_name)
|
|
48
|
+
unless defined? JRUBY_VERSION
|
|
49
|
+
expect(core.all.size).to eq 0
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
37
56
|
describe 'exec' do
|
|
38
57
|
let(:cmd) { 'start' }
|
|
39
58
|
let(:options) { { p: '4098', help: true } }
|
|
@@ -71,6 +90,11 @@ describe SolrWrapper::Instance do
|
|
|
71
90
|
it { is_expected.to eq 'http://127.0.0.1:8983/solr/' }
|
|
72
91
|
end
|
|
73
92
|
|
|
93
|
+
describe "#instance_dir" do
|
|
94
|
+
subject { solr_instance.instance_dir }
|
|
95
|
+
it { is_expected.to start_with Dir.tmpdir }
|
|
96
|
+
end
|
|
97
|
+
|
|
74
98
|
describe "#version" do
|
|
75
99
|
subject { solr_instance.version }
|
|
76
100
|
it { is_expected.to eq '6.0.0' }
|
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.9.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-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rubyzip
|