solr_wrapper 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43fa2562de12dc7692414d1bc094f342dbe846cf
4
- data.tar.gz: 15ae728b8f1baccf48c276350ef64ca27e456ee2
3
+ metadata.gz: 21a2a6e484329fe66c2531342783d9ac4007a1a3
4
+ data.tar.gz: 25cd86f3084f418c6a88192986b0ba6d6a2013b5
5
5
  SHA512:
6
- metadata.gz: cd6541cc7fc59996be5a5cb9d78ff29bbe7b6c365780586934250401cd37b8a98ec8e4cc85cd7645bbe8c6873681ab438caf84bc7571553580466c18a82f3938
7
- data.tar.gz: 4222c7863f4baf0ff5f63f963ff46e4f2cb624272885cc5cd97103f96bb3a7c61996009fe38e0833fe8681fb9819ff7901273a08c4529f3a2366396703b96fad
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: 8983)") do |p|
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.parse!
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.default_instance(options)
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
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: '8983',
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 ||= SolrWrapper::Instance.new options
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
- default_instance(options).wrap &block
39
+ instance(options).wrap &block
32
40
  end
33
41
  end
@@ -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
@@ -130,12 +130,49 @@ module SolrWrapper
130
130
 
131
131
  create_options = { p: port }
132
132
  create_options[:c] = options[:name] if options[:name]
133
+ create_options[:n] = options[:config_name] if options[:config_name]
133
134
  create_options[:d] = options[:dir] if options[:dir]
134
135
  exec("create", create_options)
135
136
 
136
137
  options[:name]
137
138
  end
138
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
+
139
176
  ##
140
177
  # Create a new collection in solr
141
178
  # @param [String] name collection name
@@ -318,6 +355,10 @@ module SolrWrapper
318
355
  end
319
356
  end
320
357
 
358
+ def zkhost
359
+ "#{config.zookeeper_host}:#{config.zookeeper_port}" if config.cloud
360
+ end
361
+
321
362
  def raise_error_unless_extracted
322
363
  raise RuntimeError, "there is no solr instance at #{config.instance_dir}. Run SolrWrapper.extract first." unless extracted?
323
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
- SolrWrapper.default_instance_options[:download_dir] ||= Rails.root.to_s + '/tmp' if defined? Rails
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.'
@@ -1,3 +1,3 @@
1
1
  module SolrWrapper
2
- VERSION = '0.8.1'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SolrWrapper::Instance do
4
- let(:solr_instance) { SolrWrapper::Instance.new }
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 } }
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.8.1
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 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip