chef-solr 0.8.6 → 0.8.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/chef/solr.rb +16 -13
- data/lib/chef/solr/application/indexer.rb +24 -9
- data/lib/chef/solr/application/rebuild.rb +13 -5
- data/lib/chef/solr/application/solr.rb +25 -10
- data/spec/chef/solr_spec.rb +64 -0
- data/spec/spec.opts +1 -0
- metadata +6 -5
data/Rakefile
CHANGED
@@ -30,7 +30,7 @@ require 'spec/rake/spectask'
|
|
30
30
|
Spec::Rake::SpecTask.new(:spec) do |spec|
|
31
31
|
spec.libs << 'lib' << 'spec'
|
32
32
|
spec.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
-
spec.spec_opts =
|
33
|
+
spec.spec_opts = ['--options', File.expand_path(File.dirname(__FILE__) + '/spec/spec.opts')]
|
34
34
|
end
|
35
35
|
|
36
36
|
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.8
|
data/lib/chef/solr.rb
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -34,6 +34,9 @@ require 'uri'
|
|
34
34
|
|
35
35
|
class Chef
|
36
36
|
class Solr
|
37
|
+
|
38
|
+
VERSION = "0.8.8"
|
39
|
+
|
37
40
|
include Chef::Mixin::XMLEscape
|
38
41
|
|
39
42
|
attr_accessor :solr_url, :http
|
@@ -73,7 +76,7 @@ class Chef
|
|
73
76
|
|
74
77
|
def solr_add(data)
|
75
78
|
data = [data] unless data.kind_of?(Array)
|
76
|
-
|
79
|
+
|
77
80
|
Chef::Log.debug("adding to SOLR: #{data.inspect}")
|
78
81
|
xml_document = LibXML::XML::Document.new
|
79
82
|
xml_add = LibXML::XML::Node.new("add")
|
@@ -97,19 +100,19 @@ class Chef
|
|
97
100
|
def solr_commit(opts={})
|
98
101
|
post_to_solr(generate_single_element("commit", opts))
|
99
102
|
end
|
100
|
-
|
103
|
+
|
101
104
|
def solr_optimize(opts={})
|
102
105
|
post_to_solr(generate_single_element("optimize", opts))
|
103
106
|
end
|
104
|
-
|
107
|
+
|
105
108
|
def solr_rollback
|
106
109
|
post_to_solr(generate_single_element("rollback"))
|
107
110
|
end
|
108
|
-
|
111
|
+
|
109
112
|
def solr_delete_by_id(ids)
|
110
113
|
post_to_solr(generate_delete_document("id", ids))
|
111
114
|
end
|
112
|
-
|
115
|
+
|
113
116
|
def solr_delete_by_query(queries)
|
114
117
|
post_to_solr(generate_delete_document("query", queries))
|
115
118
|
end
|
@@ -117,20 +120,20 @@ class Chef
|
|
117
120
|
def rebuild_index(url=Chef::Config[:couchdb_url], db=Chef::Config[:couchdb_database])
|
118
121
|
solr_delete_by_query("X_CHEF_database_CHEF_X:#{db}")
|
119
122
|
solr_commit
|
120
|
-
|
123
|
+
|
121
124
|
results = {}
|
122
|
-
[Chef::ApiClient, Chef::Node, Chef::
|
125
|
+
[Chef::ApiClient, Chef::Node, Chef::Role].each do |klass|
|
123
126
|
results[klass.name] = reindex_all(klass) ? "success" : "failed"
|
124
127
|
end
|
125
128
|
databags = Chef::DataBag.cdb_list(true)
|
126
129
|
Chef::Log.info("Reloading #{databags.size.to_s} #{Chef::DataBag} objects into the indexer")
|
127
|
-
databags.each { |i| i.add_to_index; i.list(true).each { |x| x.add_to_index } }
|
128
|
-
results[Chef::DataBag.name] = "success"
|
130
|
+
databags.each { |i| i.add_to_index; i.list(true).each { |x| x.add_to_index } }
|
131
|
+
results[Chef::DataBag.name] = "success"
|
129
132
|
results
|
130
133
|
end
|
131
134
|
|
132
135
|
private
|
133
|
-
|
136
|
+
|
134
137
|
def reindex_all(klass, metadata={})
|
135
138
|
begin
|
136
139
|
items = klass.cdb_list(true)
|
@@ -204,7 +207,7 @@ class Chef
|
|
204
207
|
def escape(s)
|
205
208
|
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
|
206
209
|
'%'+$1.unpack('H2'*$1.size).join('%').upcase
|
207
|
-
}.tr(' ', '+')
|
210
|
+
}.tr(' ', '+')
|
208
211
|
end
|
209
212
|
|
210
213
|
end
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -29,14 +29,14 @@ class Chef
|
|
29
29
|
class Solr
|
30
30
|
class Application
|
31
31
|
class Indexer < Chef::Application
|
32
|
-
|
33
|
-
option :config_file,
|
32
|
+
|
33
|
+
option :config_file,
|
34
34
|
:short => "-c CONFIG",
|
35
35
|
:long => "--config CONFIG",
|
36
36
|
:default => "/etc/chef/solr.rb",
|
37
37
|
:description => "The configuration file to use"
|
38
38
|
|
39
|
-
option :log_level,
|
39
|
+
option :log_level,
|
40
40
|
:short => "-l LEVEL",
|
41
41
|
:long => "--log_level LEVEL",
|
42
42
|
:description => "Set the log level (debug, info, warn, error, fatal)",
|
@@ -48,6 +48,13 @@ class Chef
|
|
48
48
|
:description => "Set the log file location, defaults to STDOUT - recommended for daemonizing",
|
49
49
|
:proc => nil
|
50
50
|
|
51
|
+
option :pid_file,
|
52
|
+
:short => "-P PID_FILE",
|
53
|
+
:long => "--pid PIDFILE",
|
54
|
+
:description => "Set the PID file location, defaults to /tmp/chef-solr-indexer.pid",
|
55
|
+
:proc => nil
|
56
|
+
|
57
|
+
|
51
58
|
option :help,
|
52
59
|
:short => "-h",
|
53
60
|
:long => "--help",
|
@@ -94,7 +101,15 @@ class Chef
|
|
94
101
|
option :amqp_vhost,
|
95
102
|
:long => "--amqp-vhost VHOST",
|
96
103
|
:description => "The amqp vhost"
|
97
|
-
|
104
|
+
|
105
|
+
option :version,
|
106
|
+
:short => "-v",
|
107
|
+
:long => "--version",
|
108
|
+
:description => "Show chef-solr-indexer version",
|
109
|
+
:boolean => true,
|
110
|
+
:proc => lambda {|v| puts "chef-solr-indexer: #{::Chef::Solr::VERSION}"},
|
111
|
+
:exit => 0
|
112
|
+
|
98
113
|
Signal.trap("INT") do
|
99
114
|
begin
|
100
115
|
AmqpClient.instance.stop
|
@@ -102,15 +117,15 @@ class Chef
|
|
102
117
|
end
|
103
118
|
fatal!("SIGINT received, stopping", 2)
|
104
119
|
end
|
105
|
-
|
106
|
-
Kernel.trap("TERM") do
|
120
|
+
|
121
|
+
Kernel.trap("TERM") do
|
107
122
|
begin
|
108
123
|
AmqpClient.instance.stop
|
109
124
|
rescue Bunny::ProtocolError, Bunny::ConnectionError, Bunny::UnsubscribeError
|
110
125
|
end
|
111
126
|
fatal!("SIGTERM received, stopping", 1)
|
112
127
|
end
|
113
|
-
|
128
|
+
|
114
129
|
def initialize
|
115
130
|
super
|
116
131
|
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -26,14 +26,14 @@ class Chef
|
|
26
26
|
class Solr
|
27
27
|
class Application
|
28
28
|
class Rebuild < Chef::Application
|
29
|
-
|
30
|
-
option :config_file,
|
29
|
+
|
30
|
+
option :config_file,
|
31
31
|
:short => "-c CONFIG",
|
32
32
|
:long => "--config CONFIG",
|
33
33
|
:default => "/etc/chef/solr.rb",
|
34
34
|
:description => "The configuration file to use"
|
35
35
|
|
36
|
-
option :log_level,
|
36
|
+
option :log_level,
|
37
37
|
:short => "-l LEVEL",
|
38
38
|
:long => "--log_level LEVEL",
|
39
39
|
:description => "Set the log level (debug, info, warn, error, fatal)",
|
@@ -64,6 +64,14 @@ class Chef
|
|
64
64
|
:long => "--couchdb-url URL",
|
65
65
|
:description => "The CouchDB URL"
|
66
66
|
|
67
|
+
option :version,
|
68
|
+
:short => "-v",
|
69
|
+
:long => "--version",
|
70
|
+
:description => "Show chef-solr-rebuild version",
|
71
|
+
:boolean => true,
|
72
|
+
:proc => lambda {|v| puts "chef-solr-rebuild: #{::Chef::Solr::VERSION}"},
|
73
|
+
:exit => 0
|
74
|
+
|
67
75
|
def initialize
|
68
76
|
super
|
69
77
|
|
@@ -6,9 +6,9 @@
|
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
8
8
|
# You may obtain a copy of the License at
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Unless required by applicable law or agreed to in writing, software
|
13
13
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
14
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -21,19 +21,20 @@ require 'chef/config'
|
|
21
21
|
require 'chef/application'
|
22
22
|
require 'chef/daemon'
|
23
23
|
require 'chef/client'
|
24
|
+
require 'chef/solr'
|
24
25
|
|
25
26
|
class Chef
|
26
27
|
class Solr
|
27
28
|
class Application
|
28
29
|
class Solr < Chef::Application
|
29
|
-
|
30
|
-
option :config_file,
|
30
|
+
|
31
|
+
option :config_file,
|
31
32
|
:short => "-c CONFIG",
|
32
33
|
:long => "--config CONFIG",
|
33
34
|
:default => "/etc/chef/solr.rb",
|
34
35
|
:description => "The configuration file to use"
|
35
36
|
|
36
|
-
option :log_level,
|
37
|
+
option :log_level,
|
37
38
|
:short => "-l LEVEL",
|
38
39
|
:long => "--log_level LEVEL",
|
39
40
|
:description => "Set the log level (debug, info, warn, error, fatal)",
|
@@ -45,6 +46,12 @@ class Chef
|
|
45
46
|
:description => "Set the log file location, defaults to STDOUT - recommended for daemonizing",
|
46
47
|
:proc => nil
|
47
48
|
|
49
|
+
option :pid_file,
|
50
|
+
:short => "-P PID_FILE",
|
51
|
+
:long => "--pid PIDFILE",
|
52
|
+
:description => "Set the PID file location, defaults to /tmp/chef-solr.pid",
|
53
|
+
:proc => nil
|
54
|
+
|
48
55
|
option :help,
|
49
56
|
:short => "-h",
|
50
57
|
:long => "--help",
|
@@ -95,11 +102,19 @@ class Chef
|
|
95
102
|
option :solr_java_opts,
|
96
103
|
:short => "-j OPTS",
|
97
104
|
:long => "--java-opts OPTS",
|
98
|
-
:description => "Raw options passed to Java"
|
105
|
+
:description => "Raw options passed to Java"
|
106
|
+
|
107
|
+
option :version,
|
108
|
+
:short => "-v",
|
109
|
+
:long => "--version",
|
110
|
+
:description => "Show chef-solr version",
|
111
|
+
:boolean => true,
|
112
|
+
:proc => lambda {|v| puts "chef-solr: #{::Chef::Solr::VERSION}"},
|
113
|
+
:exit => 0
|
99
114
|
|
100
115
|
def initialize
|
101
116
|
super
|
102
|
-
Chef::Log.level = Chef::Config[:log_level]
|
117
|
+
Chef::Log.level = Chef::Config[:log_level]
|
103
118
|
end
|
104
119
|
|
105
120
|
def setup_application
|
@@ -113,7 +128,7 @@ class Chef
|
|
113
128
|
|
114
129
|
# Create the Jetty container
|
115
130
|
unless File.directory?(Chef::Config[:solr_jetty_path])
|
116
|
-
Chef::Log.warn("Initializing the Jetty container")
|
131
|
+
Chef::Log.warn("Initializing the Jetty container")
|
117
132
|
solr_jetty_dir = Chef::Resource::Directory.new(Chef::Config[:solr_jetty_path], nil, c.node)
|
118
133
|
solr_jetty_dir.recursive(true)
|
119
134
|
solr_jetty_dir.run_action(:create)
|
@@ -125,7 +140,7 @@ class Chef
|
|
125
140
|
|
126
141
|
# Create the solr home
|
127
142
|
unless File.directory?(Chef::Config[:solr_home_path])
|
128
|
-
Chef::Log.warn("Initializing Solr home directory")
|
143
|
+
Chef::Log.warn("Initializing Solr home directory")
|
129
144
|
solr_home_dir = Chef::Resource::Directory.new(Chef::Config[:solr_home_path], nil, c.node)
|
130
145
|
solr_home_dir.recursive(true)
|
131
146
|
solr_home_dir.run_action(:create)
|
@@ -135,7 +150,7 @@ class Chef
|
|
135
150
|
solr_jetty_untar.run_action(:run)
|
136
151
|
end
|
137
152
|
|
138
|
-
# Create the solr data path
|
153
|
+
# Create the solr data path
|
139
154
|
unless File.directory?(Chef::Config[:solr_data_path])
|
140
155
|
Chef::Log.warn("Initializing Solr data directory")
|
141
156
|
solr_data_dir = Chef::Resource::Directory.new(Chef::Config[:solr_data_path], nil, c.node)
|
data/spec/chef/solr_spec.rb
CHANGED
@@ -170,5 +170,69 @@ describe Chef::Solr do
|
|
170
170
|
@solr.solr_delete_by_query([ "foo:bar", "baz:bum" ])
|
171
171
|
end
|
172
172
|
end
|
173
|
+
|
174
|
+
describe "rebuilding the index" do
|
175
|
+
before do
|
176
|
+
Chef::Config[:couchdb_database] = "chunky_bacon"
|
177
|
+
end
|
178
|
+
|
179
|
+
it "deletes the index and commits" do
|
180
|
+
@solr.should_receive(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
|
181
|
+
@solr.should_receive(:solr_commit)
|
182
|
+
@solr.stub!(:reindex_all)
|
183
|
+
Chef::DataBag.stub!(:cdb_list).and_return([])
|
184
|
+
@solr.rebuild_index
|
185
|
+
end
|
186
|
+
|
187
|
+
it "reindexes Chef::ApiClient, Chef::Node, and Chef::Role objects, reporting the results as a hash" do
|
188
|
+
@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
|
189
|
+
@solr.stub!(:solr_commit)
|
190
|
+
@solr.should_receive(:reindex_all).with(Chef::ApiClient).and_return(true)
|
191
|
+
@solr.should_receive(:reindex_all).with(Chef::Node).and_return(true)
|
192
|
+
@solr.should_receive(:reindex_all).with(Chef::Role).and_return(true)
|
193
|
+
Chef::DataBag.stub!(:cdb_list).and_return([])
|
194
|
+
|
195
|
+
result = @solr.rebuild_index
|
196
|
+
result["Chef::ApiClient"].should == "success"
|
197
|
+
result["Chef::Node"].should == "success"
|
198
|
+
result["Chef::Role"].should == "success"
|
199
|
+
end
|
200
|
+
|
201
|
+
it "does not reindex Chef::OpenIDRegistration or Chef::WebUIUser objects" do
|
202
|
+
# hi there. the reason we're specifying this behavior is because these objects
|
203
|
+
# are not properly indexed in the first place and trying to reindex them
|
204
|
+
# tickles a bug in our CamelCase to snake_case code. See CHEF-1009.
|
205
|
+
@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
|
206
|
+
@solr.stub!(:solr_commit)
|
207
|
+
@solr.stub!(:reindex_all).with(Chef::ApiClient)
|
208
|
+
@solr.stub!(:reindex_all).with(Chef::Node)
|
209
|
+
@solr.stub!(:reindex_all).with(Chef::Role)
|
210
|
+
@solr.should_not_receive(:reindex_all).with(Chef::OpenIDRegistration)
|
211
|
+
@solr.should_not_receive(:reindex_all).with(Chef::WebUIUser)
|
212
|
+
Chef::DataBag.stub!(:cdb_list).and_return([])
|
213
|
+
|
214
|
+
@solr.rebuild_index
|
215
|
+
end
|
216
|
+
|
217
|
+
it "reindexes databags" do
|
218
|
+
one_data_item = Chef::DataBagItem.new
|
219
|
+
one_data_item.raw_data = {"maybe"=>"snakes actually are evil", "id" => "just_sayin"}
|
220
|
+
two_data_item = Chef::DataBagItem.new
|
221
|
+
two_data_item.raw_data = {"tone_depth"=>"rumble_fish", "id" => "eff_yes"}
|
222
|
+
data_bag = Chef::DataBag.new
|
223
|
+
data_bag.stub!(:list).and_return([one_data_item, two_data_item])
|
224
|
+
|
225
|
+
@solr.stub!(:solr_delete_by_query).with("X_CHEF_database_CHEF_X:chunky_bacon")
|
226
|
+
@solr.stub!(:solr_commit)
|
227
|
+
@solr.stub!(:reindex_all)
|
228
|
+
Chef::DataBag.stub!(:cdb_list).and_return([data_bag])
|
229
|
+
|
230
|
+
data_bag.should_receive(:add_to_index)
|
231
|
+
one_data_item.should_receive(:add_to_index)
|
232
|
+
two_data_item.should_receive(:add_to_index)
|
233
|
+
|
234
|
+
@solr.rebuild_index["Chef::DataBag"].should == "success"
|
235
|
+
end
|
236
|
+
end
|
173
237
|
|
174
238
|
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-cbfs
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
8
|
+
- 8
|
9
|
+
version: 0.8.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Adam Jacob
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-17 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -55,8 +55,8 @@ dependencies:
|
|
55
55
|
segments:
|
56
56
|
- 0
|
57
57
|
- 8
|
58
|
-
-
|
59
|
-
version: 0.8.
|
58
|
+
- 8
|
59
|
+
version: 0.8.8
|
60
60
|
type: :runtime
|
61
61
|
version_requirements: *id003
|
62
62
|
description:
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- spec/chef/solr/index_spec.rb
|
90
90
|
- spec/chef/solr/query_spec.rb
|
91
91
|
- spec/chef/solr_spec.rb
|
92
|
+
- spec/spec.opts
|
92
93
|
- spec/spec_helper.rb
|
93
94
|
- LICENSE
|
94
95
|
has_rdoc: true
|