solr_wrapper 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f599156c301d05423f3d0bbb82f15bdcdc177c5
4
- data.tar.gz: 91fbd6a8b261caa96a9d13d95529f8df4edd8264
3
+ metadata.gz: f210f3f4d7beb5a3ac5ec90b1f52b79bc7f4f89f
4
+ data.tar.gz: 3f4ed6125f50d9401313f250c370f216581d2957
5
5
  SHA512:
6
- metadata.gz: 752c5a759af88d84475784ad50501e5b24f9873d3f7ab8230042a66134f5650b3bafafc6a1b417f99780613f3c5e01824e3fac25b7de717d186b8c04bcf13571
7
- data.tar.gz: 2daa20c6613fc167f64de77d6e245d1373924f9b0b1646543fe6e76d41f29846784c0c47849da0cc2c7c36a2005e8b3e3e0d6645bb80f24fa4800acef329caab
6
+ metadata.gz: 266ae3d05b9b04a5aeb7254e711bd403d76c940fbbfc19fc384851099864f244fda62f19b1ea29d0e4bcd301363330b2837dbc87508f736b64bf7dd1e13769bc
7
+ data.tar.gz: dad3bfc9e031cfd66535617ec19463c780fe7b5c77fd21e20c6aa2280ad87d1258a858d3eae563a54c1fb96a01264f0be513a7615d3b164577229d209bbc95b6
data/.travis.yml CHANGED
@@ -2,3 +2,7 @@ language: ruby
2
2
  sudo: false
3
3
  rvm:
4
4
  - 2.2.0
5
+ - jruby
6
+ cache:
7
+ directories:
8
+ - /tmp/solr-5.0.0
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in solr_wrapper.gemspec
4
- gemspec
5
-
6
- gem 'byebug'
4
+ gemspec
data/lib/solr_wrapper.rb CHANGED
@@ -10,6 +10,8 @@ module SolrWrapper
10
10
  @default_instance ||= SolrWrapper::Instance.new options
11
11
  end
12
12
 
13
+ ##
14
+ # Ensures a Solr service is running before executing the block
13
15
  def self.wrap options = {}, &block
14
16
  default_instance(options).wrap &block
15
17
  end
@@ -12,6 +12,18 @@ module SolrWrapper
12
12
  class Instance
13
13
  attr_reader :options
14
14
 
15
+ ##
16
+ # @param [Hash] options
17
+ # @option options [String] :url
18
+ # @option options [String] :version
19
+ # @option options [String] :port
20
+ # @option options [String] :version_file
21
+ # @option options [String] :instance_dir
22
+ # @option options [String] :download_path
23
+ # @option options [String] :md5sum
24
+ # @option options [Boolean] :verbose
25
+ # @option options [Boolean] :managed
26
+ # @option options [Boolean] :ignore_md5sum
15
27
  def initialize options = {}
16
28
  @options = options
17
29
  end
@@ -23,78 +35,100 @@ module SolrWrapper
23
35
  stop
24
36
  end
25
37
 
38
+ ##
39
+ # Start Solr and wait for it to become available
26
40
  def start
27
41
  extract
28
- IO.popen([solr_binary, "start", "-p", port, err: [:child, :out]]) do |io|
29
- stringio = StringIO.new
30
- if verbose?
31
- IO.copy_stream(io,$stderr)
32
- else
33
- IO.copy_stream(io, stringio)
34
- end
35
- _, exit_status = Process.wait2(io.pid)
36
- if exit_status != 0
37
- stringio.rewind
38
- raise "Unable to start solr: #{stringio.read}"
39
- end
40
- end if managed?
42
+ if managed?
43
+ exec('start', p: port)
41
44
 
42
- # Wait for solr to start
43
- unless status
44
- sleep 1
45
+ # Wait for solr to start
46
+ unless status
47
+ sleep 1
48
+ end
45
49
  end
46
- started!
47
50
  end
48
51
 
52
+ ##
53
+ # Stop Solr and wait for it to finish exiting
49
54
  def stop
50
- return unless started?
51
-
52
- IO.popen([solr_binary, "stop", "-p", port, err: [:child, :out]]) do |io|
53
- stringio = StringIO.new
54
- if verbose?
55
- IO.copy_stream(io,$stderr)
56
- else
57
- IO.copy_stream(io, stringio)
58
- end
59
- _, exit_status = Process.wait2(io.pid)
60
-
61
- if exit_status != 0
62
- stringio.rewind
63
- raise "Unable to start solr: #{stringio.read}"
64
- end
55
+ if managed? and started?
65
56
 
57
+ exec('stop', p: port)
66
58
  # Wait for solr to stop
67
59
  while status
68
60
  sleep 1
69
61
  end
70
- end if managed?
62
+ end
71
63
  end
72
64
 
65
+ ##
66
+ # Check the status of a managed Solr service
73
67
  def status
74
68
  return true unless managed?
75
69
 
76
- stringio = StringIO.new
70
+ out = exec('status', output: true).read
71
+ out =~ /running on port #{port}/
72
+ end
77
73
 
78
- IO.popen([solr_binary, "status", "-p", port, err: [:child, :out]]) do |io|
79
- IO.copy_stream(io, stringio)
74
+ ##
75
+ # Is Solr running?
76
+ def started?
77
+ !!status
78
+ end
80
79
 
81
- _, exit_status = Process.wait2(io.pid)
80
+ ##
81
+ # Create a new collection in solr
82
+ # @param [Hash] options
83
+ # @option options [String] :name
84
+ # @option options [String] :dir
85
+ def create options = {}
86
+ options[:name] ||= SecureRandom.hex
82
87
 
83
- stringio.rewind
88
+ exec("create", c: options[:name], d: options[:dir], p: port)
84
89
 
85
- if exit_status != 0
86
- raise "Unable to query solr status: #{stringio.read}"
87
- end
90
+ options[:name]
91
+ end
92
+
93
+ ##
94
+ # Create a new collection in solr
95
+ # @param [String] name collection name
96
+ def delete name, options = {}
97
+ exec("delete", c: name, p: port)
98
+ end
99
+
100
+ ##
101
+ # Create a new collection, run the block, and then clean up the collection
102
+ # @param [Hash] options
103
+ # @option options [String] :name
104
+ # @option options [String] :dir
105
+ def with_collection options = {}
106
+ name = create(options)
107
+ begin
108
+ yield name
109
+ ensure
110
+ delete name
88
111
  end
112
+ end
89
113
 
90
- out = stringio.read
91
- out =~ /running on port #{port}/
114
+ ##
115
+ # Get the port this Solr instance is running at
116
+ def port
117
+ options.fetch(:port, "8983").to_s
92
118
  end
93
119
 
94
- def started?
95
- !!status
120
+ ##
121
+ # Clean up any files solr_wrapper may have downloaded
122
+ def clean!
123
+ stop
124
+ FileUtils.remove_entry(download_path) if File.exists? download_path
125
+ FileUtils.remove_entry(tmp_save_dir, true) if File.exists? tmp_save_dir
126
+ FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir
127
+ FileUtils.remove_entry(md5sum_path) if File.exists? md5sum_path
128
+ FileUtils.remove_entry(version_file) if File.exists? version_file
96
129
  end
97
130
 
131
+ protected
98
132
  def extract
99
133
  return solr_dir if File.exists?(solr_binary) and extracted_version == version
100
134
 
@@ -129,95 +163,76 @@ module SolrWrapper
129
163
  end
130
164
 
131
165
  def download
132
- unless File.exists? download_path and md5sum(download_path) == expected_md5sum
133
- pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
134
- open(url, content_length_proc: lambda {|t|
135
- if t && 0 < t
136
- pbar.total = t
137
- end
138
- },
139
- progress_proc: lambda {|s|
140
- pbar.progress = s
141
- }) do |io|
142
- IO.copy_stream(io,download_path)
143
- end
144
-
145
- unless md5sum(download_path) == expected_md5sum
146
- raise "MD5 mismatch" unless options[:ignore_md5sum]
147
- end
166
+ unless File.exists? download_path and validate? download_path
167
+ fetch_with_progressbar url, download_path
168
+ validate!
148
169
  end
149
170
 
150
171
  download_path
151
172
  end
152
173
 
153
- def port
154
- options.fetch(:port, "8983")
174
+ def validate? file
175
+ Digest::MD5.file(file).hexdigest == expected_md5sum
155
176
  end
156
177
 
157
- def create options = {}
158
- options[:name] ||= SecureRandom.hex
159
-
160
- IO.popen([solr_binary, "create", "-c", options[:name], "-d", options[:dir], "-p", port, err: [:child, :out]]) do |io|
161
- if verbose?
162
- IO.copy_stream(io,$stderr)
163
- end
178
+ def validate! file
179
+ unless validate? download_path
180
+ raise "MD5 mismatch" unless options[:ignore_md5sum]
164
181
  end
165
-
166
- options[:name]
167
182
  end
168
-
169
- def delete name, options = {}
170
- IO.popen([solr_binary, "delete", "-c", name, "-p", port, err: [:child, :out]]) do |io|
171
- if verbose?
172
- IO.copy_stream(io,$stderr)
183
+
184
+ ##
185
+ # Run a bin/solr command
186
+ # @see https://github.com/apache/lucene-solr/blob/trunk/solr/bin/solr
187
+ def exec cmd, options = {}
188
+ output = !!options.delete(:output)
189
+ args = [solr_binary, cmd] + options.map { |k,v| ["-#{k}", "#{v}"] }.flatten
190
+
191
+ if IO.respond_to? :popen4
192
+ # JRuby
193
+ pid, input, output, error = IO.popen4(args.join(" "))
194
+
195
+ stringio = StringIO.new
196
+ if verbose? and !output
197
+ IO.copy_stream(output,$stderr)
198
+ IO.copy_stream(error,$stderr)
199
+ else
200
+ IO.copy_stream(output, stringio)
201
+ IO.copy_stream(error, stringio)
173
202
  end
174
- end
175
- end
203
+ input.close
204
+ output.close
205
+ error.close
206
+
207
+ stringio.rewind
176
208
 
177
- def with_collection options = {}
178
- name = create(options)
179
- begin
180
- yield name
181
- ensure
182
- delete name
183
- end
184
- end
209
+ if $? != 0
210
+ raise "Failed to execute solr #{cmd}: #{stringio.read}"
211
+ end
185
212
 
186
- private
187
- def expected_md5sum
188
- @md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
189
- end
213
+ stringio
214
+ else
215
+ IO.popen(args + [err: [:child, :out]]) do |io|
216
+ stringio = StringIO.new
217
+ if verbose? and !output
218
+ IO.copy_stream(io,$stderr)
219
+ else
220
+ IO.copy_stream(io, stringio)
221
+ end
222
+ _, exit_status = Process.wait2(io.pid)
190
223
 
191
- def md5sum file
192
- Digest::MD5.file(file).hexdigest
193
- end
224
+ stringio.rewind
194
225
 
195
- def md5file
196
- unless File.exists? md5sum_path
197
- pbar = ProgressBar.create(title: File.basename(md5url), total: nil, format: "%t: |%B| %p%% (%e )")
198
- open(md5url, content_length_proc: lambda {|t|
199
- if t && 0 < t
200
- pbar.total = t
226
+ if exit_status != 0
227
+ raise "Failed to execute solr #{cmd}: #{stringio.read}"
201
228
  end
202
- },
203
- progress_proc: lambda {|s|
204
- pbar.progress = s
205
- }) do |io|
206
- IO.copy_stream(io, md5sum_path)
229
+
230
+ stringio
207
231
  end
208
232
  end
209
-
210
- md5sum_path
211
- end
212
-
213
- def md5url
214
- "http://www.us.apache.org/dist/lucene/solr/#{version}/solr-#{version}.zip.md5"
215
- end
216
-
217
- def md5sum_path
218
- File.join(Dir.tmpdir, File.basename(md5url))
219
233
  end
220
234
 
235
+ private
221
236
  def url
222
237
  @download_url ||= options.fetch(:url, default_url)
223
238
  end
@@ -231,8 +246,16 @@ module SolrWrapper
231
246
  end
232
247
  end
233
248
 
249
+ def md5url
250
+ "http://www.us.apache.org/dist/lucene/solr/#{version}/solr-#{version}.zip.md5"
251
+ end
252
+
234
253
  def version
235
- @version ||= options.fetch(:version, SolrWrapper.default_solr_version)
254
+ @version ||= options.fetch(:version, default_solr_version)
255
+ end
256
+
257
+ def default_solr_version
258
+ SolrWrapper.default_solr_version
236
259
  end
237
260
 
238
261
  def download_path
@@ -247,28 +270,54 @@ module SolrWrapper
247
270
  @solr_dir ||= options.fetch(:instance_dir, File.join(Dir.tmpdir, File.basename(default_url, ".zip")))
248
271
  end
249
272
 
250
- def tmp_save_dir
251
- @tmp_save_dir ||= Dir.mktmpdir
273
+ def verbose?
274
+ !!options.fetch(:verbose, false)
252
275
  end
253
276
 
277
+ def managed?
278
+ !!options.fetch(:managed, true)
279
+ end
280
+
281
+ def version_file
282
+ options.fetch(:version_file, File.join(solr_dir, "VERSION"))
283
+ end
284
+
285
+ def expected_md5sum
286
+ @md5sum ||= options.fetch(:md5sum, open(md5file).read.split(" ").first)
287
+ end
288
+
254
289
  def solr_binary
255
290
  File.join(solr_dir, "bin", "solr")
256
291
  end
257
-
258
- def started! status = true
259
- @started = status
292
+
293
+ def md5sum_path
294
+ File.join(Dir.tmpdir, File.basename(md5url))
260
295
  end
261
296
 
262
- def verbose?
263
- !!options.fetch(:verbose, false)
297
+ def tmp_save_dir
298
+ @tmp_save_dir ||= Dir.mktmpdir
264
299
  end
265
300
 
266
- def managed?
267
- !!options.fetch(:managed, true)
301
+ def fetch_with_progressbar url, output
302
+ pbar = ProgressBar.create(title: File.basename(url), total: nil, format: "%t: |%B| %p%% (%e )")
303
+ open(url, content_length_proc: lambda {|t|
304
+ if t && 0 < t
305
+ pbar.total = t
306
+ end
307
+ },
308
+ progress_proc: lambda {|s|
309
+ pbar.progress = s
310
+ }) do |io|
311
+ IO.copy_stream(io,output)
312
+ end
268
313
  end
269
314
 
270
- def version_file
271
- options.fetch(:version_file, File.join(solr_dir, "VERSION"))
315
+ def md5file
316
+ unless File.exists? md5sum_path
317
+ fetch_with_progressbar md5url, md5sum_path
318
+ end
319
+
320
+ md5sum_path
272
321
  end
273
322
 
274
323
  def extracted_version
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/solr_wrapper.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Chris Beer"]
10
10
  spec.email = ["chris@cbeer.info"]
11
11
  spec.summary = %q{Solr 5 service wrapper}
12
- spec.homepage = ""
12
+ spec.homepage = "https://github.com/cbeer/solr_wrapper"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
@@ -8,8 +8,10 @@ describe SolrWrapper::Instance do
8
8
  subject.wrap do |solr|
9
9
  solr.with_collection(dir: File.join(FIXTURES_DIR, "basic_configs")) do |collection_name|
10
10
  core = client.core(collection_name)
11
- expect(core.schema.field('id').name).to eq 'id'
12
- expect(core.schema.field('id').stored).to eq true
11
+ unless defined? JRUBY_VERSION
12
+ expect(core.schema.field('id').name).to eq 'id'
13
+ expect(core.schema.field('id').stored).to eq true
14
+ end
13
15
  end
14
16
  end
15
17
  end
metadata CHANGED
@@ -1,122 +1,122 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubyzip
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - ">="
16
+ - - '>='
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
- type: :runtime
19
+ name: rubyzip
21
20
  prerelease: false
21
+ type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ruby-progressbar
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - ">="
30
+ - - '>='
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
- type: :runtime
33
+ name: ruby-progressbar
35
34
  prerelease: false
35
+ type: :runtime
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - "~>"
44
+ - - ~>
46
45
  - !ruby/object:Gem::Version
47
46
  version: '1.7'
48
- type: :development
47
+ name: bundler
49
48
  prerelease: false
49
+ type: :development
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - "~>"
58
+ - - ~>
60
59
  - !ruby/object:Gem::Version
61
60
  version: '10.0'
62
- type: :development
61
+ name: rake
63
62
  prerelease: false
63
+ type: :development
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - ">="
72
+ - - '>='
74
73
  - !ruby/object:Gem::Version
75
74
  version: '0'
76
- type: :development
75
+ name: rspec
77
76
  prerelease: false
77
+ type: :development
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: simple_solr_client
85
84
  requirement: !ruby/object:Gem::Requirement
86
85
  requirements:
87
- - - ">="
86
+ - - '>='
88
87
  - !ruby/object:Gem::Version
89
88
  version: '0'
90
- type: :development
89
+ name: simple_solr_client
91
90
  prerelease: false
91
+ type: :development
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: coveralls
99
98
  requirement: !ruby/object:Gem::Requirement
100
99
  requirements:
101
- - - ">="
100
+ - - '>='
102
101
  - !ruby/object:Gem::Version
103
102
  version: '0'
104
- type: :development
103
+ name: coveralls
105
104
  prerelease: false
105
+ type: :development
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description:
111
+ description:
112
112
  email:
113
113
  - chris@cbeer.info
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".gitignore"
119
- - ".travis.yml"
118
+ - .gitignore
119
+ - .travis.yml
120
120
  - Gemfile
121
121
  - LICENSE
122
122
  - README.md
@@ -137,28 +137,28 @@ files:
137
137
  - spec/lib/solr_wrapper/instance_spec.rb
138
138
  - spec/lib/solr_wrapper_spec.rb
139
139
  - spec/spec_helper.rb
140
- homepage: ''
140
+ homepage: https://github.com/cbeer/solr_wrapper
141
141
  licenses:
142
142
  - MIT
143
143
  metadata: {}
144
- post_install_message:
144
+ post_install_message:
145
145
  rdoc_options: []
146
146
  require_paths:
147
147
  - lib
148
148
  required_ruby_version: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">="
155
+ - - '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
158
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.4.5
161
- signing_key:
159
+ rubyforge_project:
160
+ rubygems_version: 2.1.9
161
+ signing_key:
162
162
  specification_version: 4
163
163
  summary: Solr 5 service wrapper
164
164
  test_files: