solr_wrapper 0.10.0 → 0.16.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 +3 -3
- data/README.md +28 -2
- data/exe/solr_wrapper +43 -6
- data/lib/solr_wrapper/client.rb +36 -0
- data/lib/solr_wrapper/configuration.rb +22 -18
- data/lib/solr_wrapper/downloader.rb +2 -0
- data/lib/solr_wrapper/instance.rb +16 -8
- data/lib/solr_wrapper/settings.rb +29 -9
- data/lib/solr_wrapper/tasks/solr_wrapper.rake +2 -2
- data/lib/solr_wrapper/version.rb +1 -1
- data/lib/solr_wrapper.rb +4 -1
- data/solr_wrapper.gemspec +2 -0
- data/spec/fixtures/another_sample_config.yml +2 -0
- data/spec/fixtures/sample_config.yml +1 -0
- data/spec/lib/solr_wrapper/client_spec.rb +25 -0
- data/spec/lib/solr_wrapper/configuration_spec.rb +14 -5
- data/spec/lib/solr_wrapper/instance_spec.rb +39 -1
- data/spec/spec_helper.rb +1 -0
- metadata +36 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6e8efc2491de8905a2041eea0f2f20fec15f679e
|
|
4
|
+
data.tar.gz: dc5882eb1d93b37e85d6f6643a1e5e2f72a826b4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 549aa457e595f347bf9470bc23e0f7a49b01cf5cefaef9af22a943b623fc974926fc6e9a14e05c898cd5e5a491cb4f9c864a39cf058d3713aa4210fe924bf14d
|
|
7
|
+
data.tar.gz: e7f28b13c0d59fbe0f77efb8f28da82820cd9e6f78d46e050932c0eff465c5a794366609767f59c98a52cebe3df75b0b44745cc2d6cbcb3527b0654c2cdae0aa
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -26,7 +26,7 @@ SolrWrapper.wrap port: 8983,
|
|
|
26
26
|
instance_dir: '/opt/solr'
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
### Valid ruby and YAML options
|
|
30
30
|
|
|
31
31
|
|Option | |
|
|
32
32
|
|---------------|-----------------------------------------|
|
|
@@ -35,7 +35,8 @@ Options:
|
|
|
35
35
|
| version | Solr version to download and install |
|
|
36
36
|
| port | port to run Solr on |
|
|
37
37
|
| version_file | Local path to store the currently installed version |
|
|
38
|
-
|
|
|
38
|
+
| download_dir | Local path for storing the downloaded Solr zip file |
|
|
39
|
+
| solr_zip_path | Local path to the Solr zip file |
|
|
39
40
|
| md5sum | Path/URL to MD5 checksum |
|
|
40
41
|
| solr_xml | Path to Solr configuration |
|
|
41
42
|
| verbose | (Boolean) |
|
|
@@ -43,6 +44,7 @@ Options:
|
|
|
43
44
|
| ignore_md5sum | (Boolean) |
|
|
44
45
|
| solr_options | (Hash) |
|
|
45
46
|
| env | (Hash) |
|
|
47
|
+
| persist | (Boolean) Preserves the data in you collection between startups |
|
|
46
48
|
|
|
47
49
|
```ruby
|
|
48
50
|
solr.with_collection(name: 'collection_name', dir: 'path_to_solr_configs')
|
|
@@ -53,6 +55,30 @@ solr.with_collection(name: 'collection_name', dir: 'path_to_solr_configs')
|
|
|
53
55
|
```console
|
|
54
56
|
$ solr_wrapper -p 8983
|
|
55
57
|
```
|
|
58
|
+
To see a list of valid options when using solr_wrapper to launch a Solr instance from the command line:
|
|
59
|
+
```
|
|
60
|
+
$ solr_wrapper -h
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Configuration file
|
|
64
|
+
SolrWrapper can read configuration options from a YAML configuration file.
|
|
65
|
+
By default, it looks for configuration files at `.solr_wrapper` and `~/.solr_wrapper`.
|
|
66
|
+
|
|
67
|
+
You can also specify a configuration file when launching from the command line as follows:
|
|
68
|
+
```
|
|
69
|
+
$ solr_wrapper -config <path_to_config_file>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Cleaning your repository from the command line
|
|
73
|
+
|
|
74
|
+
By defualt SorlWrapper will clean out your data when it shuts down.
|
|
75
|
+
If you utilize the preserve option your data will remain between runs.
|
|
76
|
+
|
|
77
|
+
To clean out data that is being preserved explicitly run:
|
|
78
|
+
```
|
|
79
|
+
$ solr_wrapper <configuration options> clean
|
|
80
|
+
```
|
|
81
|
+
***Note*** You must use the same configuration options on the clean command as you do on the run command to clean the correct instance.
|
|
56
82
|
|
|
57
83
|
## Rake tasks
|
|
58
84
|
|
data/exe/solr_wrapper
CHANGED
|
@@ -5,8 +5,14 @@ require 'optparse'
|
|
|
5
5
|
|
|
6
6
|
options = {}
|
|
7
7
|
collection_options = {}
|
|
8
|
+
subtext = <<HELP
|
|
9
|
+
Commonly used command are:
|
|
10
|
+
clean : cleans all data from solr and configures a clean instance based on configuration options
|
|
11
|
+
See 'solr_wrapper COMMAND --help' for more information on a specific command.
|
|
12
|
+
HELP
|
|
13
|
+
|
|
8
14
|
args = OptionParser.new do |opts|
|
|
9
|
-
opts.banner = "Usage: solr_wrapper [options]"
|
|
15
|
+
opts.banner = "Usage: solr_wrapper [options] subcommand"
|
|
10
16
|
|
|
11
17
|
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
|
12
18
|
options[:verbose] = v
|
|
@@ -32,8 +38,8 @@ args = OptionParser.new do |opts|
|
|
|
32
38
|
options[:cloud] = c
|
|
33
39
|
end
|
|
34
40
|
|
|
35
|
-
opts.on("--
|
|
36
|
-
options[:
|
|
41
|
+
opts.on("--solr_zip_path PATH", "Download/use solr at the given path") do |d|
|
|
42
|
+
options[:solr_zip_path] = d
|
|
37
43
|
end
|
|
38
44
|
|
|
39
45
|
opts.on("-iDIR", "--instance_directory DIR", "Install/use solr at the given directory") do |d|
|
|
@@ -52,12 +58,33 @@ args = OptionParser.new do |opts|
|
|
|
52
58
|
collection_options[:dir] = d
|
|
53
59
|
end
|
|
54
60
|
|
|
61
|
+
opts.on("--[no-]persist", "Persist the solr connection data") do |d|
|
|
62
|
+
collection_options[:persist] = d
|
|
63
|
+
end
|
|
64
|
+
|
|
55
65
|
opts.on("--no-checksum", "Skip running checksum validation on the downloaded file") do |d|
|
|
56
66
|
options[:ignore_md5sum] = true
|
|
57
67
|
end
|
|
68
|
+
|
|
69
|
+
opts.separator ""
|
|
70
|
+
opts.separator subtext
|
|
58
71
|
end
|
|
59
72
|
|
|
73
|
+
|
|
74
|
+
subcommands = {
|
|
75
|
+
'clean' => OptionParser.new do |opts|
|
|
76
|
+
opts.banner = "Usage: clean"
|
|
77
|
+
end,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
60
81
|
begin
|
|
82
|
+
args.order!
|
|
83
|
+
command = ARGV.shift
|
|
84
|
+
if command
|
|
85
|
+
raise "Bad subcommand: #{command}" unless subcommands[command]
|
|
86
|
+
subcommands[command].order!
|
|
87
|
+
end
|
|
61
88
|
args.parse!
|
|
62
89
|
rescue => error
|
|
63
90
|
$stderr.puts "ERROR: #{error}\n"
|
|
@@ -65,10 +92,18 @@ rescue => error
|
|
|
65
92
|
exit 1
|
|
66
93
|
end
|
|
67
94
|
|
|
68
|
-
# default to verbose
|
|
69
|
-
options[:verbose] = true if options[:verbose].nil?
|
|
70
|
-
|
|
71
95
|
instance = SolrWrapper.instance(options)
|
|
96
|
+
|
|
97
|
+
if command == 'clean'
|
|
98
|
+
if instance.started?
|
|
99
|
+
$stderr.puts "Please stop solr before cleaning"
|
|
100
|
+
exit 1
|
|
101
|
+
end
|
|
102
|
+
$stderr.puts "cleaning #{instance.instance_dir}..."
|
|
103
|
+
instance.remove_instance_dir!
|
|
104
|
+
exit 0
|
|
105
|
+
end
|
|
106
|
+
|
|
72
107
|
$stderr.print "Starting Solr #{instance.version} on port #{instance.port} ... "
|
|
73
108
|
instance.wrap do |conn|
|
|
74
109
|
conn.with_collection(collection_options) do
|
|
@@ -76,6 +111,8 @@ instance.wrap do |conn|
|
|
|
76
111
|
begin
|
|
77
112
|
conn.wait
|
|
78
113
|
rescue Interrupt
|
|
114
|
+
Signal.trap("SIGTERM") {"IGNORE"}
|
|
115
|
+
Signal.trap("SIGINT") {"IGNORE"}
|
|
79
116
|
$stderr.puts "Solr is shutting down."
|
|
80
117
|
end
|
|
81
118
|
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'faraday'
|
|
2
|
+
require 'json'
|
|
3
|
+
|
|
4
|
+
module SolrWrapper
|
|
5
|
+
# Solr REST API client to get status information
|
|
6
|
+
class Client
|
|
7
|
+
attr_reader :url
|
|
8
|
+
|
|
9
|
+
def initialize(url)
|
|
10
|
+
@url = url
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Check if a core or collection exists
|
|
14
|
+
def exists?(core_or_collection_name)
|
|
15
|
+
collection?(core_or_collection_name) || core?(core_or_collection_name)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def collection?(name)
|
|
21
|
+
response = conn.get('admin/collections?action=LIST&wt=json')
|
|
22
|
+
data = JSON.parse(response.body)
|
|
23
|
+
return if data['error'] && data['error']['msg'] == 'Solr instance is not running in SolrCloud mode.'
|
|
24
|
+
data['collections'].include? name
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def core?(name)
|
|
28
|
+
response = conn.get('admin/cores?action=STATUS&wt=json&core=' + name)
|
|
29
|
+
!JSON.parse(response.body)['status'][name].empty?
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def conn
|
|
33
|
+
@conn ||= Faraday.new(url: url)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -2,9 +2,11 @@ module SolrWrapper
|
|
|
2
2
|
class Configuration
|
|
3
3
|
attr_reader :options
|
|
4
4
|
|
|
5
|
-
def initialize(options)
|
|
6
|
-
@
|
|
7
|
-
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
@config = options[:config]
|
|
7
|
+
@verbose = options[:verbose]
|
|
8
|
+
|
|
9
|
+
@options = load_configs(Array(options[:config])).merge(options)
|
|
8
10
|
end
|
|
9
11
|
|
|
10
12
|
def solr_xml
|
|
@@ -46,8 +48,8 @@ module SolrWrapper
|
|
|
46
48
|
options[:zookeeper_port]
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
def
|
|
50
|
-
options[:
|
|
51
|
+
def solr_zip_path
|
|
52
|
+
options[:solr_zip_path]
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def download_dir
|
|
@@ -55,7 +57,7 @@ module SolrWrapper
|
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
def default_download_dir
|
|
58
|
-
if defined?(Rails) && Rails.root
|
|
60
|
+
if defined?(Rails) && Rails.respond_to?(:root) && Rails.root
|
|
59
61
|
File.join(Rails.root, 'tmp')
|
|
60
62
|
else
|
|
61
63
|
Dir.tmpdir
|
|
@@ -87,7 +89,7 @@ module SolrWrapper
|
|
|
87
89
|
end
|
|
88
90
|
|
|
89
91
|
def verbose?
|
|
90
|
-
!!options.fetch(:verbose, false)
|
|
92
|
+
@verbose || (options && !!options.fetch(:verbose, false))
|
|
91
93
|
end
|
|
92
94
|
|
|
93
95
|
def version_file
|
|
@@ -96,7 +98,7 @@ module SolrWrapper
|
|
|
96
98
|
|
|
97
99
|
def collection_options
|
|
98
100
|
hash = options.fetch(:collection, {})
|
|
99
|
-
Configuration.slice(convert_keys(hash), :name, :dir)
|
|
101
|
+
Configuration.slice(convert_keys(hash), :name, :dir, :persist)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
104
|
def configsets
|
|
@@ -114,21 +116,23 @@ module SolrWrapper
|
|
|
114
116
|
keys.each_with_object({}) { |k, hash| hash[k] = source[k] if source.has_key?(k) }
|
|
115
117
|
end
|
|
116
118
|
|
|
117
|
-
def
|
|
118
|
-
|
|
119
|
+
def load_configs(config_files)
|
|
120
|
+
config = {}
|
|
121
|
+
|
|
122
|
+
(default_configuration_paths + config_files.compact).each do |p|
|
|
119
123
|
path = File.expand_path(p)
|
|
120
|
-
|
|
124
|
+
next unless File.exist? path
|
|
125
|
+
config.merge!(read_config(path))
|
|
121
126
|
end
|
|
122
127
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return {}
|
|
126
|
-
end
|
|
128
|
+
config
|
|
129
|
+
end
|
|
127
130
|
|
|
128
|
-
|
|
131
|
+
def read_config(config_file)
|
|
132
|
+
$stdout.puts "Loading configuration from #{config_file}" if verbose?
|
|
129
133
|
config = YAML.load(ERB.new(IO.read(config_file)).result(binding))
|
|
130
134
|
unless config
|
|
131
|
-
$stderr.puts "Unable to parse config #{config_file}" if verbose
|
|
135
|
+
$stderr.puts "Unable to parse config #{config_file}" if verbose?
|
|
132
136
|
return {}
|
|
133
137
|
end
|
|
134
138
|
convert_keys(config)
|
|
@@ -139,7 +143,7 @@ module SolrWrapper
|
|
|
139
143
|
end
|
|
140
144
|
|
|
141
145
|
def default_configuration_paths
|
|
142
|
-
['.
|
|
146
|
+
['~/.solr_wrapper.yml', '~/.solr_wrapper', '.solr_wrapper.yml', '.solr_wrapper']
|
|
143
147
|
end
|
|
144
148
|
end
|
|
145
149
|
end
|
|
@@ -7,6 +7,8 @@ module SolrWrapper
|
|
|
7
7
|
open(url, content_length_proc: ->(bytes) { pbar.total = bytes }, progress_proc: ->(bytes) { pbar.progress = bytes }) do |io|
|
|
8
8
|
IO.copy_stream(io, output)
|
|
9
9
|
end
|
|
10
|
+
rescue OpenURI::HTTPError => e
|
|
11
|
+
raise SolrWrapperError, "Unable to download solr from #{url}\n#{e.message}"
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
class SafeProgressBar < ProgressBar::Base
|
|
@@ -22,8 +22,8 @@ module SolrWrapper
|
|
|
22
22
|
# @option options [String] :port port to run Solr on
|
|
23
23
|
# @option options [Boolean] :cloud Run solr in cloud mode
|
|
24
24
|
# @option options [String] :version_file Local path to store the currently installed version
|
|
25
|
-
# @option options [String] :download_dir Local directory to store the downloaded Solr zip and its md5 file in (overridden by :
|
|
26
|
-
# @option options [String] :
|
|
25
|
+
# @option options [String] :download_dir Local directory to store the downloaded Solr zip and its md5 file in (overridden by :solr_zip_path)
|
|
26
|
+
# @option options [String] :solr_zip_path Local path for storing the downloaded Solr zip file
|
|
27
27
|
# @option options [Boolean] :validate Should solr_wrapper download a new md5 and (re-)validate the zip file? (default: trueF)
|
|
28
28
|
# @option options [String] :md5sum Path/URL to MD5 checksum
|
|
29
29
|
# @option options [String] :solr_xml Path to Solr configuration
|
|
@@ -147,6 +147,10 @@ module SolrWrapper
|
|
|
147
147
|
create_options[:c] = options[:name] if options[:name]
|
|
148
148
|
create_options[:n] = options[:config_name] if options[:config_name]
|
|
149
149
|
create_options[:d] = options[:dir] if options[:dir]
|
|
150
|
+
|
|
151
|
+
# short-circuit if we're using persisted data with an existing core/collection
|
|
152
|
+
return if options[:persist] && create_options[:c] && client.exists?(create_options[:c])
|
|
153
|
+
|
|
150
154
|
exec("create", create_options)
|
|
151
155
|
|
|
152
156
|
options[:name]
|
|
@@ -208,7 +212,7 @@ module SolrWrapper
|
|
|
208
212
|
begin
|
|
209
213
|
yield name
|
|
210
214
|
ensure
|
|
211
|
-
delete name
|
|
215
|
+
delete name unless options[:persist]
|
|
212
216
|
end
|
|
213
217
|
end
|
|
214
218
|
|
|
@@ -217,7 +221,7 @@ module SolrWrapper
|
|
|
217
221
|
def clean!
|
|
218
222
|
stop
|
|
219
223
|
remove_instance_dir!
|
|
220
|
-
FileUtils.remove_entry(config.
|
|
224
|
+
FileUtils.remove_entry(config.download_dir, true) if File.exists?(config.download_dir)
|
|
221
225
|
FileUtils.remove_entry(config.tmp_save_dir, true) if File.exists? config.tmp_save_dir
|
|
222
226
|
md5.clean!
|
|
223
227
|
FileUtils.remove_entry(config.version_file) if File.exists? config.version_file
|
|
@@ -285,11 +289,11 @@ module SolrWrapper
|
|
|
285
289
|
end
|
|
286
290
|
|
|
287
291
|
def download
|
|
288
|
-
unless File.exists?(config.
|
|
289
|
-
Downloader.fetch_with_progressbar config.download_url, config.
|
|
290
|
-
md5.validate! config.
|
|
292
|
+
unless File.exists?(config.solr_zip_path) && md5.validate?(config.solr_zip_path)
|
|
293
|
+
Downloader.fetch_with_progressbar config.download_url, config.solr_zip_path
|
|
294
|
+
md5.validate! config.solr_zip_path
|
|
291
295
|
end
|
|
292
|
-
config.
|
|
296
|
+
config.solr_zip_path
|
|
293
297
|
end
|
|
294
298
|
|
|
295
299
|
##
|
|
@@ -381,6 +385,10 @@ module SolrWrapper
|
|
|
381
385
|
"#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
|
|
382
386
|
end
|
|
383
387
|
|
|
388
|
+
def client
|
|
389
|
+
SolrWrapper::Client.new(url)
|
|
390
|
+
end
|
|
391
|
+
|
|
384
392
|
def raise_error_unless_extracted
|
|
385
393
|
raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
|
|
386
394
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'delegate'
|
|
2
|
+
require 'faraday'
|
|
2
3
|
|
|
3
4
|
module SolrWrapper
|
|
4
5
|
# Configuraton that comes from static and dynamic sources.
|
|
@@ -51,7 +52,7 @@ module SolrWrapper
|
|
|
51
52
|
|
|
52
53
|
def instance_dir
|
|
53
54
|
@instance_dir ||= static_config.instance_dir
|
|
54
|
-
@instance_dir ||= File.join(
|
|
55
|
+
@instance_dir ||= File.join(tmpdir, File.basename(download_url, ".zip"))
|
|
55
56
|
end
|
|
56
57
|
|
|
57
58
|
def managed?
|
|
@@ -63,9 +64,9 @@ module SolrWrapper
|
|
|
63
64
|
@download_url ||= default_download_url
|
|
64
65
|
end
|
|
65
66
|
|
|
66
|
-
def
|
|
67
|
-
@
|
|
68
|
-
@
|
|
67
|
+
def solr_zip_path
|
|
68
|
+
@solr_zip_path ||= static_config.solr_zip_path
|
|
69
|
+
@solr_zip_path ||= default_solr_zip_path
|
|
69
70
|
end
|
|
70
71
|
|
|
71
72
|
def version_file
|
|
@@ -90,7 +91,15 @@ module SolrWrapper
|
|
|
90
91
|
|
|
91
92
|
private
|
|
92
93
|
|
|
93
|
-
def
|
|
94
|
+
def tmpdir
|
|
95
|
+
if defined?(Rails) && Rails.root
|
|
96
|
+
File.join(Rails.root, 'tmp')
|
|
97
|
+
else
|
|
98
|
+
Dir.tmpdir
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def default_solr_zip_path
|
|
94
103
|
File.join(download_dir, File.basename(download_url))
|
|
95
104
|
end
|
|
96
105
|
|
|
@@ -100,15 +109,26 @@ module SolrWrapper
|
|
|
100
109
|
@download_dir
|
|
101
110
|
end
|
|
102
111
|
|
|
103
|
-
|
|
104
112
|
def default_download_url
|
|
105
113
|
@default_url ||= begin
|
|
106
114
|
json = open(static_config.mirror_url).read
|
|
107
115
|
doc = JSON.parse(json)
|
|
108
|
-
doc['preferred'] + doc['path_info']
|
|
116
|
+
url = doc['preferred'] + doc['path_info']
|
|
117
|
+
|
|
118
|
+
response = Faraday.head(url)
|
|
119
|
+
|
|
120
|
+
if response.success?
|
|
121
|
+
url
|
|
122
|
+
else
|
|
123
|
+
archive_download_url
|
|
124
|
+
end
|
|
109
125
|
end
|
|
110
|
-
rescue SocketError
|
|
111
|
-
|
|
126
|
+
rescue Errno::ECONNRESET, SocketError, Faraday::Error
|
|
127
|
+
archive_download_url
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def archive_download_url
|
|
131
|
+
"http://archive.apache.org/dist/lucene/solr/#{static_config.version}/solr-#{static_config.version}.zip"
|
|
112
132
|
end
|
|
113
133
|
|
|
114
134
|
def random_open_port
|
|
@@ -4,7 +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
|
-
@solr_instance = SolrWrapper.
|
|
7
|
+
@solr_instance = SolrWrapper.default_instance
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
desc 'Install a clean version of solr. Replaces the existing copy if there is one.'
|
|
@@ -17,7 +17,7 @@ namespace :solr do
|
|
|
17
17
|
desc 'start solr'
|
|
18
18
|
task start: :environment do
|
|
19
19
|
begin
|
|
20
|
-
puts "Starting solr at #{
|
|
20
|
+
puts "Starting solr at #{@solr_instance.config.url}"
|
|
21
21
|
@solr_instance.start
|
|
22
22
|
rescue => e
|
|
23
23
|
if e.message.include?("Port #{@solr_instance.port} is already being used by another process")
|
data/lib/solr_wrapper/version.rb
CHANGED
data/lib/solr_wrapper.rb
CHANGED
|
@@ -4,10 +4,11 @@ require 'solr_wrapper/settings'
|
|
|
4
4
|
require 'solr_wrapper/md5'
|
|
5
5
|
require 'solr_wrapper/downloader'
|
|
6
6
|
require 'solr_wrapper/instance'
|
|
7
|
+
require 'solr_wrapper/client'
|
|
7
8
|
|
|
8
9
|
module SolrWrapper
|
|
9
10
|
def self.default_solr_version
|
|
10
|
-
'6.
|
|
11
|
+
'6.2.0'
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def self.default_solr_port
|
|
@@ -38,4 +39,6 @@ module SolrWrapper
|
|
|
38
39
|
def self.wrap(options = {}, &block)
|
|
39
40
|
instance(options).wrap &block
|
|
40
41
|
end
|
|
42
|
+
|
|
43
|
+
class SolrWrapperError < StandardError; end
|
|
41
44
|
end
|
data/solr_wrapper.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
+
spec.add_dependency "faraday"
|
|
21
22
|
spec.add_dependency "rubyzip"
|
|
22
23
|
spec.add_dependency "ruby-progressbar"
|
|
23
24
|
|
|
@@ -27,4 +28,5 @@ Gem::Specification.new do |spec|
|
|
|
27
28
|
spec.add_development_dependency "rspec"
|
|
28
29
|
spec.add_development_dependency "simple_solr_client"
|
|
29
30
|
spec.add_development_dependency "coveralls"
|
|
31
|
+
spec.add_development_dependency "fakeweb"
|
|
30
32
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SolrWrapper::Client do
|
|
4
|
+
subject { described_class.new('http://localhost:8983/solr/') }
|
|
5
|
+
|
|
6
|
+
describe '#exists?' do
|
|
7
|
+
it 'checks if a solrcloud collection exists' do
|
|
8
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/collections?action=LIST&wt=json', body: '{ "collections": ["x", "y", "z"]}')
|
|
9
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=a', body: '{ "status": { "a": {} } }')
|
|
10
|
+
|
|
11
|
+
expect(subject.exists?('x')).to eq true
|
|
12
|
+
expect(subject.exists?('a')).to eq false
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'checks if a solr core exists' do
|
|
16
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/collections?action=LIST&wt=json', body: '{ "error": { "msg": "Solr instance is not running in SolrCloud mode."} }')
|
|
17
|
+
|
|
18
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=x', body: '{ "status": { "x": { "name": "x" } } }')
|
|
19
|
+
FakeWeb.register_uri(:get, 'http://localhost:8983/solr/admin/cores?action=STATUS&wt=json&core=a', body: '{ "status": { "a": {} } }')
|
|
20
|
+
|
|
21
|
+
expect(subject.exists?('x')).to eq true
|
|
22
|
+
expect(subject.exists?('a')).to eq false
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -22,13 +22,22 @@ describe SolrWrapper::Configuration do
|
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
describe "#
|
|
25
|
+
describe "#load_configs" do
|
|
26
26
|
before do
|
|
27
27
|
allow(config).to receive(:default_configuration_paths).and_return([])
|
|
28
28
|
end
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
context 'with a single config file' do
|
|
30
|
+
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
31
|
+
it "uses values from the config file" do
|
|
32
|
+
expect(config.port).to eq '9999'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
context 'with multiple config files' do
|
|
36
|
+
let(:options) { { config: ['spec/fixtures/sample_config.yml', 'spec/fixtures/another_sample_config.yml'] } }
|
|
37
|
+
it "uses values from the config file" do
|
|
38
|
+
expect(config.port).to eq '9998'
|
|
39
|
+
expect(config.verbose?).to eq true
|
|
40
|
+
end
|
|
32
41
|
end
|
|
33
42
|
end
|
|
34
43
|
|
|
@@ -38,7 +47,7 @@ describe SolrWrapper::Configuration do
|
|
|
38
47
|
end
|
|
39
48
|
let(:options) { { config: 'spec/fixtures/sample_config.yml' } }
|
|
40
49
|
it "uses values from the config file" do
|
|
41
|
-
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/')
|
|
50
|
+
expect(config.collection_options).to eq(name: 'project-development', dir: 'solr/config/', persist: false)
|
|
42
51
|
end
|
|
43
52
|
end
|
|
44
53
|
|
|
@@ -34,6 +34,44 @@ describe SolrWrapper::Instance do
|
|
|
34
34
|
solr_instance.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) {}
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
|
+
|
|
38
|
+
context 'persistent collections' do
|
|
39
|
+
it "creates a new collection with options from the config" do
|
|
40
|
+
expect(solr_instance).to receive(:create).with(
|
|
41
|
+
hash_including(name: 'project-development'))
|
|
42
|
+
expect(solr_instance).not_to receive(:delete)
|
|
43
|
+
solr_instance.with_collection(name: 'project-development', dir: 'solr/config/', persist: true) {}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
describe 'single solr node' do
|
|
47
|
+
it 'allows persistent collection on restart' do
|
|
48
|
+
subject.wrap do |solr|
|
|
49
|
+
solr.with_collection(name: 'solr-node-persistent-core', dir: File.join(FIXTURES_DIR, 'basic_configs'), persist: true) {}
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
subject.wrap do |solr|
|
|
53
|
+
solr.with_collection(name: 'solr-node-persistent-core', dir: File.join(FIXTURES_DIR, 'basic_configs'), persist: true) {}
|
|
54
|
+
solr.delete 'solr-node-persistent-core'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
describe 'solr cloud' do
|
|
60
|
+
let(:options) { { cloud: true } }
|
|
61
|
+
|
|
62
|
+
it 'allows persistent collection on restart' do
|
|
63
|
+
subject.wrap do |solr|
|
|
64
|
+
config_name = solr.upconfig dir: File.join(FIXTURES_DIR, 'basic_configs')
|
|
65
|
+
solr.with_collection(name: 'solr-cloud-persistent-collection', config_name: config_name, persist: true) {}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
subject.wrap do |solr|
|
|
69
|
+
solr.with_collection(name: 'solr-cloud-persistent-collection', persist: true) {}
|
|
70
|
+
solr.delete 'solr-cloud-persistent-collection'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
37
75
|
end
|
|
38
76
|
|
|
39
77
|
context 'with a SolrCloud instance' do
|
|
@@ -114,7 +152,7 @@ describe SolrWrapper::Instance do
|
|
|
114
152
|
|
|
115
153
|
describe "#version" do
|
|
116
154
|
subject { solr_instance.version }
|
|
117
|
-
it { is_expected.to eq '6.
|
|
155
|
+
it { is_expected.to eq '6.2.0' }
|
|
118
156
|
end
|
|
119
157
|
|
|
120
158
|
describe "#md5" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solr_wrapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.16.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-08-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: rubyzip
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -108,6 +122,20 @@ dependencies:
|
|
|
108
122
|
- - ">="
|
|
109
123
|
- !ruby/object:Gem::Version
|
|
110
124
|
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: fakeweb
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
111
139
|
description:
|
|
112
140
|
email:
|
|
113
141
|
- chris@cbeer.info
|
|
@@ -129,6 +157,7 @@ files:
|
|
|
129
157
|
- coveralls.yml
|
|
130
158
|
- exe/solr_wrapper
|
|
131
159
|
- lib/solr_wrapper.rb
|
|
160
|
+
- lib/solr_wrapper/client.rb
|
|
132
161
|
- lib/solr_wrapper/configuration.rb
|
|
133
162
|
- lib/solr_wrapper/downloader.rb
|
|
134
163
|
- lib/solr_wrapper/instance.rb
|
|
@@ -138,6 +167,7 @@ files:
|
|
|
138
167
|
- lib/solr_wrapper/tasks/solr_wrapper.rake
|
|
139
168
|
- lib/solr_wrapper/version.rb
|
|
140
169
|
- solr_wrapper.gemspec
|
|
170
|
+
- spec/fixtures/another_sample_config.yml
|
|
141
171
|
- spec/fixtures/basic_configs/_rest_managed.json
|
|
142
172
|
- spec/fixtures/basic_configs/currency.xml
|
|
143
173
|
- spec/fixtures/basic_configs/lang/stopwords_en.txt
|
|
@@ -147,6 +177,7 @@ files:
|
|
|
147
177
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
148
178
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
149
179
|
- spec/fixtures/sample_config.yml
|
|
180
|
+
- spec/lib/solr_wrapper/client_spec.rb
|
|
150
181
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
151
182
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
152
183
|
- spec/lib/solr_wrapper_spec.rb
|
|
@@ -171,11 +202,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
171
202
|
version: '0'
|
|
172
203
|
requirements: []
|
|
173
204
|
rubyforge_project:
|
|
174
|
-
rubygems_version: 2.
|
|
205
|
+
rubygems_version: 2.5.1
|
|
175
206
|
signing_key:
|
|
176
207
|
specification_version: 4
|
|
177
208
|
summary: Solr 5 service wrapper
|
|
178
209
|
test_files:
|
|
210
|
+
- spec/fixtures/another_sample_config.yml
|
|
179
211
|
- spec/fixtures/basic_configs/_rest_managed.json
|
|
180
212
|
- spec/fixtures/basic_configs/currency.xml
|
|
181
213
|
- spec/fixtures/basic_configs/lang/stopwords_en.txt
|
|
@@ -185,6 +217,7 @@ test_files:
|
|
|
185
217
|
- spec/fixtures/basic_configs/stopwords.txt
|
|
186
218
|
- spec/fixtures/basic_configs/synonyms.txt
|
|
187
219
|
- spec/fixtures/sample_config.yml
|
|
220
|
+
- spec/lib/solr_wrapper/client_spec.rb
|
|
188
221
|
- spec/lib/solr_wrapper/configuration_spec.rb
|
|
189
222
|
- spec/lib/solr_wrapper/instance_spec.rb
|
|
190
223
|
- spec/lib/solr_wrapper_spec.rb
|