Skip to content

Commit ae9be74

Browse files
committed
Merge branch 'CHEF-1018' of git://github.com/jtimberman/chef into jtimberman/CHEF-1018
2 parents 2e9df52 + a7a507a commit ae9be74

4 files changed

Lines changed: 64 additions & 36 deletions

File tree

chef-solr/lib/chef/solr.rb

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,6 +34,9 @@
3434

3535
class Chef
3636
class Solr
37+
38+
VERSION = "0.8.6"
39+
3740
include Chef::Mixin::XMLEscape
3841

3942
attr_accessor :solr_url, :http
@@ -73,7 +76,7 @@ def post_to_solr(doc)
7376

7477
def solr_add(data)
7578
data = [data] unless data.kind_of?(Array)
76-
79+
7780
Chef::Log.debug("adding to SOLR: #{data.inspect}")
7881
xml_document = LibXML::XML::Document.new
7982
xml_add = LibXML::XML::Node.new("add")
@@ -97,40 +100,40 @@ def solr_add(data)
97100
def solr_commit(opts={})
98101
post_to_solr(generate_single_element("commit", opts))
99102
end
100-
103+
101104
def solr_optimize(opts={})
102105
post_to_solr(generate_single_element("optimize", opts))
103106
end
104-
107+
105108
def solr_rollback
106109
post_to_solr(generate_single_element("rollback"))
107110
end
108-
111+
109112
def solr_delete_by_id(ids)
110113
post_to_solr(generate_delete_document("id", ids))
111114
end
112-
115+
113116
def solr_delete_by_query(queries)
114117
post_to_solr(generate_delete_document("query", queries))
115118
end
116119

117120
def rebuild_index(url=Chef::Config[:couchdb_url], db=Chef::Config[:couchdb_database])
118121
solr_delete_by_query("X_CHEF_database_CHEF_X:#{db}")
119122
solr_commit
120-
123+
121124
results = {}
122125
[Chef::ApiClient, Chef::Node, Chef::OpenIDRegistration, Chef::Role, Chef::WebUIUser].each do |klass|
123126
results[klass.name] = reindex_all(klass) ? "success" : "failed"
124127
end
125128
databags = Chef::DataBag.cdb_list(true)
126129
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"
129132
results
130133
end
131134

132135
private
133-
136+
134137
def reindex_all(klass, metadata={})
135138
begin
136139
items = klass.cdb_list(true)
@@ -204,7 +207,7 @@ def to_params(params_hash)
204207
def escape(s)
205208
s.to_s.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
206209
'%'+$1.unpack('H2'*$1.size).join('%').upcase
207-
}.tr(' ', '+')
210+
}.tr(' ', '+')
208211
end
209212

210213
end

chef-solr/lib/chef/solr/application/indexer.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,14 +29,14 @@ class Chef
2929
class Solr
3030
class Application
3131
class Indexer < Chef::Application
32-
33-
option :config_file,
32+
33+
option :config_file,
3434
:short => "-c CONFIG",
3535
:long => "--config CONFIG",
3636
:default => "/etc/chef/solr.rb",
3737
:description => "The configuration file to use"
3838

39-
option :log_level,
39+
option :log_level,
4040
:short => "-l LEVEL",
4141
:long => "--log_level LEVEL",
4242
:description => "Set the log level (debug, info, warn, error, fatal)",
@@ -101,23 +101,31 @@ class Indexer < Chef::Application
101101
option :amqp_vhost,
102102
:long => "--amqp-vhost VHOST",
103103
:description => "The amqp vhost"
104-
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+
105113
Signal.trap("INT") do
106114
begin
107115
AmqpClient.instance.stop
108116
rescue Bunny::ProtocolError, Bunny::ConnectionError, Bunny::UnsubscribeError
109117
end
110118
fatal!("SIGINT received, stopping", 2)
111119
end
112-
113-
Kernel.trap("TERM") do
120+
121+
Kernel.trap("TERM") do
114122
begin
115123
AmqpClient.instance.stop
116124
rescue Bunny::ProtocolError, Bunny::ConnectionError, Bunny::UnsubscribeError
117125
end
118126
fatal!("SIGTERM received, stopping", 1)
119127
end
120-
128+
121129
def initialize
122130
super
123131

chef-solr/lib/chef/solr/application/rebuild.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -26,14 +26,14 @@ class Chef
2626
class Solr
2727
class Application
2828
class Rebuild < Chef::Application
29-
30-
option :config_file,
29+
30+
option :config_file,
3131
:short => "-c CONFIG",
3232
:long => "--config CONFIG",
3333
:default => "/etc/chef/solr.rb",
3434
:description => "The configuration file to use"
3535

36-
option :log_level,
36+
option :log_level,
3737
:short => "-l LEVEL",
3838
:long => "--log_level LEVEL",
3939
:description => "Set the log level (debug, info, warn, error, fatal)",
@@ -64,6 +64,14 @@ class Rebuild < Chef::Application
6464
:long => "--couchdb-url URL",
6565
:description => "The CouchDB URL"
6666

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+
6775
def initialize
6876
super
6977

chef-solr/lib/chef/solr/application/solr.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
9-
#
9+
#
1010
# http://www.apache.org/licenses/LICENSE-2.0
11-
#
11+
#
1212
# Unless required by applicable law or agreed to in writing, software
1313
# distributed under the License is distributed on an "AS IS" BASIS,
1414
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,19 +21,20 @@
2121
require 'chef/application'
2222
require 'chef/daemon'
2323
require 'chef/client'
24+
require 'chef/solr'
2425

2526
class Chef
2627
class Solr
2728
class Application
2829
class Solr < Chef::Application
29-
30-
option :config_file,
30+
31+
option :config_file,
3132
:short => "-c CONFIG",
3233
:long => "--config CONFIG",
3334
:default => "/etc/chef/solr.rb",
3435
:description => "The configuration file to use"
3536

36-
option :log_level,
37+
option :log_level,
3738
:short => "-l LEVEL",
3839
:long => "--log_level LEVEL",
3940
:description => "Set the log level (debug, info, warn, error, fatal)",
@@ -101,11 +102,19 @@ class Solr < Chef::Application
101102
option :solr_java_opts,
102103
:short => "-j OPTS",
103104
:long => "--java-opts OPTS",
104-
: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
105114

106115
def initialize
107116
super
108-
Chef::Log.level = Chef::Config[:log_level]
117+
Chef::Log.level = Chef::Config[:log_level]
109118
end
110119

111120
def setup_application
@@ -119,7 +128,7 @@ def setup_application
119128

120129
# Create the Jetty container
121130
unless File.directory?(Chef::Config[:solr_jetty_path])
122-
Chef::Log.warn("Initializing the Jetty container")
131+
Chef::Log.warn("Initializing the Jetty container")
123132
solr_jetty_dir = Chef::Resource::Directory.new(Chef::Config[:solr_jetty_path], nil, c.node)
124133
solr_jetty_dir.recursive(true)
125134
solr_jetty_dir.run_action(:create)
@@ -131,7 +140,7 @@ def setup_application
131140

132141
# Create the solr home
133142
unless File.directory?(Chef::Config[:solr_home_path])
134-
Chef::Log.warn("Initializing Solr home directory")
143+
Chef::Log.warn("Initializing Solr home directory")
135144
solr_home_dir = Chef::Resource::Directory.new(Chef::Config[:solr_home_path], nil, c.node)
136145
solr_home_dir.recursive(true)
137146
solr_home_dir.run_action(:create)
@@ -141,7 +150,7 @@ def setup_application
141150
solr_jetty_untar.run_action(:run)
142151
end
143152

144-
# Create the solr data path
153+
# Create the solr data path
145154
unless File.directory?(Chef::Config[:solr_data_path])
146155
Chef::Log.warn("Initializing Solr data directory")
147156
solr_data_dir = Chef::Resource::Directory.new(Chef::Config[:solr_data_path], nil, c.node)

0 commit comments

Comments
 (0)