chef-solr-10.12.0/0000755000175000017500000000000011772522513013046 5ustar tfheentfheenchef-solr-10.12.0/spec/0000755000175000017500000000000011772522513014000 5ustar tfheentfheenchef-solr-10.12.0/spec/spec.opts0000644000175000017500000000000611772522513015635 0ustar tfheentfheen-cbfs chef-solr-10.12.0/spec/unit/0000755000175000017500000000000011772522513014757 5ustar tfheentfheenchef-solr-10.12.0/spec/unit/application/0000755000175000017500000000000011772522513017262 5ustar tfheentfheenchef-solr-10.12.0/spec/unit/application/solr_spec.rb0000644000175000017500000004350011772522513021602 0ustar tfheentfheen# # Author:: Thomas Bishop () # Copyright:: Copyright (c) 2012 Thomas Bishop # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'spec_helper' require 'chef/solr/application/solr' describe Chef::Solr::Application::Solr do describe 'initialize' do it 'should have a default config_file option' do subject.config[:config_file].should == '/etc/chef/solr.rb' end end describe 'schema_file_path' do it 'should return the default schema file path' do subject.schema_file_path.should == '/var/chef/solr/conf/schema.xml' end context 'with a custom solr home path' do it 'should return the schema path' do Chef::Config.stub(:[]).with(:solr_home_path). and_return('/opt/chef/solr') subject.schema_file_path.should == '/opt/chef/solr/conf/schema.xml' end end end describe 'solr_config_file_path' do it 'should return the default solr config path' do subject.solr_config_file_path.should == '/var/chef/solr/conf/solrconfig.xml' end context 'with a custom solr home path' do it 'should return the solr config path' do Chef::Config.stub(:[]).with(:solr_home_path). and_return('/opt/chef/solr') subject.solr_config_file_path.should == '/opt/chef/solr/conf/solrconfig.xml' end end end describe 'schema_document' do before do @schema_path = '/opt/chef/solr/conf/schema.xml' subject.stub :schema_file_path => @schema_path @doc_contents = 'bar' end it 'should read the schema file at the correct path' do REXML::Document.stub(:new) File.should_receive(:open).with(@schema_path, 'r'). and_yield(@doc_contents) subject.schema_document end it 'should return the schema' do File.stub(:open).and_yield(@doc_contents) subject.schema_document.should be_a REXML::Document end end describe 'config_document' do before do @solr_config_path = '/opt/chef/solr/conf/solrconfig.xml' subject.stub :solr_config_file_path => @solr_config_path @doc_contents = 'bar' end it 'should read the config file at the correct path' do REXML::Document.stub(:new) File.should_receive(:open).with(@solr_config_path, 'r'). and_yield(@doc_contents) subject.config_document end it 'should return an REXML document' do File.stub(:open).and_yield(@doc_contents) subject.config_document.should be_a REXML::Document end end describe 'schema_attributes' do it 'should return the attributes of the schema element' do schema_doc_contents = '' schema_doc_contents << '' subject.stub(:schema_document). and_return(REXML::Document.new(schema_doc_contents)) subject.schema_attributes["name"].should == 'chef' subject.schema_attributes["version"].should == '1.2' end end describe 'solr_main_index_elements' do before do doc_contents = '' doc_contents << '' doc_contents << '10000' doc_contents << '' subject.stub(:config_document). and_return(REXML::Document.new(doc_contents)) end it 'should return a collection of the REXML elements' do subject.solr_main_index_elements.each { |e| e.should be_a REXML::Element } end it 'should return the correct elements' do subject.solr_main_index_elements.first.name.should == 'maxFieldLength' subject.solr_main_index_elements.first.text.should == '10000' end end describe 'solr_schema_name' do it 'should return the schema name' do subject.stub :schema_attributes => { 'name' => 'chef' } subject.solr_schema_name.should == 'chef' end end describe 'solr_schema_version' do it 'should return the schema version' do subject.stub :schema_attributes => { 'version' => '1.2' } subject.solr_schema_version.should == '1.2' end end describe 'solr_main_index_max_field_length' do before do @elements = [ REXML::Element.new('useCompoundFile').add_text('false'), REXML::Element.new('ramBufferSizeMB').add_text('32'), REXML::Element.new('maxFieldLength').add_text('10000') ] subject.stub :solr_main_index_elements => @elements end it 'should return the value of maxFieldLimit as an integer' do subject.solr_main_index_max_field_length.should == 10000 end context 'if unable to find the maxFieldLimit' do before do elements = @elements.select { |e| e.name != 'maxFieldLength' } subject.stub :solr_main_index_elements => elements end it 'should return nil' do subject.solr_main_index_max_field_length.should be_nil end end end describe 'valid_schema_name?' do it 'should return true if the schema name matches' do subject.stub :solr_schema_name => Chef::Solr::SCHEMA_NAME subject.valid_schema_name?.should be_true end it 'should return false if the schema name does not match' do subject.stub :solr_schema_name => 'foo' subject.valid_schema_name?.should be_false end end describe 'valid_schema_version?' do it 'should return true if the version name matches' do subject.stub :solr_schema_version => Chef::Solr::SCHEMA_VERSION subject.valid_schema_version?.should be_true end it 'should return false if the version name does not match' do subject.stub :solr_schema_version => '-1.0' subject.valid_schema_version?.should be_false end end describe 'check_value_of_main_index_max_field_length' do it 'should log a warning if it is set to <= 10000' do subject.stub :solr_main_index_max_field_length => 10000 pattern = /maxFieldLimit.+set to.+recommended to increase this value/ Chef::Log.should_receive(:warn).with(pattern) subject.check_value_of_main_index_max_field_length end it 'should not log a warning if it is set to > 10000' do subject.stub :solr_main_index_max_field_length => 10001 Chef::Log.should_not_receive(:warn) subject.check_value_of_main_index_max_field_length end context 'if it is not set' do it 'should log a warning if it is not set' do subject.stub :solr_main_index_max_field_length => nil Chef::Log.should_receive(:warn). with(/Unable to determine the maxFieldLimit for the mainIndex/) subject.check_value_of_main_index_max_field_length end end end describe 'solr_home_exists?' do before do Chef::Config.stub(:[]).with(:solr_home_path). and_return('/opt/chef/solr') end it 'should return true if the solr home exists' do File.stub(:directory?).with('/opt/chef/solr'). and_return(true) subject.solr_home_exist?.should be_true end it 'should return false if the solr home does not exist' do File.stub(:directory?).with('/opt/chef/solr'). and_return(false) subject.solr_home_exist?.should be_false end end describe 'solr_data_dir_exists?' do before do Chef::Config.stub(:[]).with(:solr_data_path). and_return('/opt/chef/solr') end it 'should return true if the solr data dir exists' do File.stub(:directory?).with('/opt/chef/solr'). and_return(true) subject.solr_data_dir_exist?.should be_true end it 'should return false if the solr data dir does not exist' do File.stub(:directory?).with('/opt/chef/solr'). and_return(false) subject.solr_data_dir_exist?.should be_false end end describe 'solr_jetty_home_exists?' do before do Chef::Config.stub(:[]).with(:solr_jetty_path). and_return('/opt/chef/solr') end it 'should return true if the solr jetty dir exists' do File.stub(:directory?).with('/opt/chef/solr'). and_return(true) subject.solr_jetty_home_exist?.should be_true end it 'should return false if the solr jetty dir does not exist' do File.stub(:directory?).with('/opt/chef/solr'). and_return(false) subject.solr_jetty_home_exist?.should be_false end end describe 'assert_solr_installed!' do context 'when unsuccessful' do before do message = /chef solr is not installed.+home.+data.+jetty.+misconfigured/i Chef::Log.should_receive(:fatal).with(message).and_return(true) Chef::Log.stub(:fatal) end context 'because the solr home does not exist' do before do subject.stub :solr_home_exist? => false subject.stub :solr_data_dir_exist => true subject.stub :solr_jetty_home_exist => true end it 'should log messages and exit' do lambda { subject.assert_solr_installed! }.should raise_error SystemExit end end context 'because the solr data dir does not exist' do before do subject.stub :solr_home_exist? => true subject.stub :solr_data_dir_exist => false subject.stub :solr_jetty_home_exist => true end it 'should log messages and exit' do lambda { subject.assert_solr_installed! }.should raise_error SystemExit end end context 'because the solr jetty home does not exist' do before do subject.stub :solr_home_exist? => true subject.stub :solr_data_dir_exist => true subject.stub :solr_jetty_home_exist => false end it 'should log messages and exit' do lambda { subject.assert_solr_installed! }.should raise_error SystemExit end end end context 'when solr home, data dir, and jetty home exist' do before do ['home', 'data_dir', 'jetty_home'].each do |item| subject.stub "solr_#{item}_exist?".to_sym => true end end it 'should not exit' do subject.assert_solr_installed!.should_not raise_error SystemExit end end end describe 'assert_valid_schema!' do context 'when unsuccessful' do before do message = /chef solr installation.+upgraded.+/i Chef::Log.should_receive(:fatal).with(message).and_return(true) Chef::Log.stub(:fatal) subject.stub :solr_schema_version => '' end context 'because the schema name is not valid' do before do subject.stub :valid_schema_name? => false subject.stub :valid_schema_version => true end it 'should log messages and exit' do lambda { subject.assert_valid_schema! }.should raise_error SystemExit end end context 'because the schema version is not valid' do before do subject.stub :valid_schema_name? => true subject.stub :valid_schema_version => false end it 'should log messages and exit' do lambda { subject.assert_valid_schema! }.should raise_error SystemExit end end end context 'when the schema name and version are valid' do before do ['name', 'version'].each do |item| subject.stub "valid_schema_#{item}?".to_sym => true end end it 'should not exit' do subject.assert_valid_schema!.should_not raise_error SystemExit end end end describe 'setup_application' do before do Chef::Daemon.should_receive :change_privilege end it 'should see if solr is installed' do subject.stub :assert_valid_schema! subject.stub :check_value_of_main_index_max_field_length subject.should_receive :assert_solr_installed! subject.setup_application end it 'should see if the schema is valid' do subject.stub :assert_solr_installed! subject.stub :check_value_of_main_index_max_field_length subject.should_receive :assert_valid_schema! subject.setup_application end it 'should check the maxFieldLimit setting' do subject.stub :assert_solr_installed! subject.stub :assert_valid_schema! subject.should_receive :check_value_of_main_index_max_field_length subject.setup_application end context 'with solr installed and a valid schema' do before do subject.stub :assert_solr_installed! subject.stub :assert_valid_schema! subject.stub :check_value_of_main_index_max_field_length end context 'with -L or --logfile' do before do @log_location = '/var/log/chef_solr.log' Chef::Config.stub(:[]).with(:log_location).and_return(@log_location) Chef::Config.stub(:[]).with(:log_level).and_return(:info) end it 'should open the log file for appending' do File.should_receive(:new).with(@log_location, 'a') subject.setup_application end end it 'should set the log level' do Chef::Config.stub(:[]).with(:log_location).and_return(nil) Chef::Config.stub(:[]).with(:log_level).and_return(:info) Chef::Log.should_receive(:level=).with(:info) subject.setup_application end end end describe 'run_application' do context 'with -d or --daemonize' do before do Chef::Config[:daemonize] = true Kernel.stub :exec Dir.stub :chdir end it 'should daemonize' do Chef::Daemon.should_receive(:daemonize).with('chef-solr') subject.run_application end end it 'should change to the jetty home dir' do Kernel.stub :exec Dir.should_receive(:chdir).with(Chef::Config[:solr_jetty_path]) subject.run_application end context 'after changing to the jetty home dir' do before do Dir.should_receive(:chdir).and_yield Chef::Daemon.stub :daemonize Chef::Log.stub :info end it 'should start the process with the default settings' do cmd = "java -Xmx#{Chef::Config[:solr_heap_size]} " cmd << "-Xms#{Chef::Config[:solr_heap_size]} " cmd << "-Dsolr.data.dir=#{Chef::Config[:solr_data_path]} " cmd << "-Dsolr.solr.home=#{Chef::Config[:solr_home_path]} " cmd << "-jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}" Kernel.should_receive(:exec).with(cmd) subject.run_application end it 'should log the command that solr is started with' do cmd = /java.+solr.+jar.+start\.jar/ Chef::Log.should_receive(:info).with(cmd) Kernel.stub :exec subject.run_application end context 'with custom heap' do it 'should start the process with the custom setting' do Chef::Config[:solr_heap_size] = '2048M' cmd_fragment = /-Xmx2048M -Xms2048M/ Kernel.should_receive(:exec).with(cmd_fragment) subject.run_application end end context 'with custom data path' do it 'should start the process with the custom setting' do Chef::Config[:solr_data_path] = '/opt/chef/solr_data' cmd_fragment = /-Dsolr\.data\.dir=\/opt\/chef\/solr_data/ Kernel.should_receive(:exec).with(cmd_fragment) subject.run_application end end context 'with custom home path' do it 'should start the process with the custom setting' do Chef::Config[:solr_home_path] = '/opt/chef/solr/' cmd_fragment = /-Dsolr\.solr\.home=\/opt\/chef\/solr/ Kernel.should_receive(:exec).with(cmd_fragment) subject.run_application end end context 'with custom jetty path' do it 'should start the process with the custom setting' do Chef::Config[:solr_jetty_path] = '/opt/chef/solr_jetty/' cmd_fragment = /-jar \/opt\/chef\/solr_jetty\/start.jar/ Kernel.should_receive(:exec).with(cmd_fragment) subject.run_application end end context 'with custom java opts' do it 'should start the java process with the custom setting' do Chef::Config[:solr_java_opts] = '-XX:UseLargePages' cmd_fragment = /-XX:UseLargePages/ Kernel.should_receive(:exec).with(cmd_fragment) subject.run_application end end context 'with -L or --logfile' do it 'should close the previously opened log file and reopen it' do Kernel.stub :exec subject.logfile = StringIO.new subject.should_receive(:close_and_reopen_log_file) subject.run_application end end end end describe 'close_and_reopen_log_file' do it 'should close the log and reopen it' do log = StringIO.new Chef::Log.should_receive :close STDOUT.should_receive(:reopen).with log STDERR.should_receive(:reopen).with log subject.logfile = log subject.close_and_reopen_log_file end end describe 'run' do it { should respond_to :run} end end chef-solr-10.12.0/spec/spec_helper.rb0000644000175000017500000000162611772522513016623 0ustar tfheentfheen# # Author:: Thomas Bishop () # Copyright:: Copyright (c) 2012 Thomas Bishop # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'rspec' $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))) $:.unshift(File.expand_path('../../lib/', __FILE__)) $:.unshift(File.expand_path('../../../chef/lib', __FILE__)) require 'chef/solr' chef-solr-10.12.0/README.rdoc0000644000175000017500000000054611772522513014661 0ustar tfheentfheen= chef-solr chef-solr is a Ruby container for SOLR that starts up the Search Engine for the Chef Server under Jetty. For more information, see the following pages on the Chef Wiki: * http://wiki.opscode.com/display/chef/Search * http://wiki.opscode.com/display/chef/Chef+Indexer == Copyright Copyright (c) 2009-2012 Adam Jacob. See LICENSE for details. chef-solr-10.12.0/metadata.yml0000644000175000017500000000340511772522513015353 0ustar tfheentfheen--- !ruby/object:Gem::Specification name: chef-solr version: !ruby/object:Gem::Version hash: 127 prerelease: segments: - 10 - 12 - 0 version: 10.12.0 platform: ruby authors: - Adam Jacob autorequire: bindir: bin cert_chain: [] date: 2012-06-18 00:00:00 Z dependencies: - !ruby/object:Gem::Dependency name: chef prerelease: false requirement: &id001 !ruby/object:Gem::Requirement none: false requirements: - - "=" - !ruby/object:Gem::Version hash: 127 segments: - 10 - 12 - 0 version: 10.12.0 type: :runtime version_requirements: *id001 description: | Vendored Apache Solr for use with Chef Server email: adam@opscode.com executables: - chef-solr - chef-solr-installer extensions: [] extra_rdoc_files: [] files: - README.rdoc - Rakefile - LICENSE - bin/chef-solr - bin/chef-solr-installer - lib/chef/solr/solr_installer.rb - lib/chef/solr/version.rb - lib/chef/solr/application/solr.rb - lib/chef/solr.rb - spec/unit/application/solr_spec.rb - spec/spec_helper.rb - spec/spec.opts - solr/solr-home.tar.gz - solr/solr-jetty.tar.gz homepage: http://wiki.opscode.com/display/chef licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" requirements: [] rubyforge_project: rubygems_version: 1.8.10 signing_key: specification_version: 3 summary: Search indexing for Chef test_files: [] chef-solr-10.12.0/LICENSE0000644000175000017500000002514211772522513014057 0ustar tfheentfheen Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. chef-solr-10.12.0/Rakefile0000644000175000017500000000354511772522513014522 0ustar tfheentfheen# # Author:: Adam Jacob () # Author:: Daniel DeLeo () # Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require File.dirname(__FILE__) + '/lib/chef/solr/version' require 'rubygems' require 'rake' require 'rubygems/package_task' require '../chef/tasks/rspec.rb' spec = eval(File.read(File.dirname(__FILE__) + "/chef-solr.gemspec")) desc "Create solr archives" task :tar_solr do %w{solr-home solr-jetty}.each do |tar| Dir.chdir(File.dirname(__FILE__) + "/solr/#{tar}") { sh "tar cvzf ../#{tar}.tar.gz *" } end end task :gem => :tar_solr Gem::PackageTask.new(spec) do |pkg| pkg.gem_spec = spec end desc "Install the gem" task :install => :package do sh %{gem install pkg/chef-solr-#{Chef::Solr::VERSION} --no-rdoc --no-ri} end desc "Uninstall the gem" task :uninstall do sh %{gem uninstall chef-solr -x -v #{Chef::Solr::VERSION} } end require 'rdoc/task' RDoc::Task.new do |rdoc| if File.exist?('VERSION.yml') config = YAML.load(File.read('VERSION.yml')) version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}" else version = Chef::Solr::VERSION end rdoc.rdoc_dir = 'rdoc' rdoc.title = "chef-solr #{version}" rdoc.rdoc_files.include('README*') rdoc.rdoc_files.include('lib/**/*.rb') end task :default => :spec chef-solr-10.12.0/solr/0000755000175000017500000000000011772522513014025 5ustar tfheentfheenchef-solr-10.12.0/solr/solr-home.tar.gz0000644000175000017500000003005511772522513017064 0ustar tfheentfheen-O/`޳g/vϞ=?3^L) !L~O7Qϰ t ="v?.>x#2\ㅌ(wP,X:lGOUi7Yࡢi!P%LY"7yVVh1QY7 MTme4YJ}0ͭԓǗt݀,s-KQYyx+EBWq,z[ Pմ'jz0ȣ1j :`܀p<yv]GsGQ0աeïoL snQMj금TAaA\2L-"k0 fm!mS+ t-AmT6K>|9XX>nF!ڴڛQTZ6+بgg^7,|xĬf΁md,:~ym_WO7PAc< >;LT; 0yTQH-Cr9d|9EvCc RlK@F;"n~F&jǣ+ұʻNeۼw9  {Hkd(l |giwC`$#4ydB=+xAĵA0 6֡l,ghZ󬴆eY &W-uL!/P' %}pJ !]e!u{S=A;(qeaXU}cic.M T<\ǒޫW~+r"rϯG޻hPqܱυ] ~biq\Z9 coؾ͠d,`Ghzw>0\\c=93ʌjis)b @O%Z:1XE,w8{qqu9j}1(gVι]&UE6Y ?!yfè {QaԄN@9L£“Sȍq:ȟdm߲pFO6;8L&U4dg;xѠ5D L_ٜ-9D.1Ta`>i b~aX@ BC-NY.ƙNqllS #f"̣lToӒA̢}]HbU]aa;— nj#xv-Xdk ־V9d<6!8&GZ#GV)D,A(%.4ᗟI ?*V(~/&8ҭh񱿭wS=-s1wL+-k3G86#\wD!)e޳%nxb*&T,U3ne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~ If*gdͷ+G!Բ)}sÚ,]rq39hD籕uQn/emq2)g?yqpf:֮$79WËtL.v| t7|tP~aOƾu~6ozⰚᘨ^>dzos^? X&0B2g\u,N`r2!mi\|jJa+UyȂV-tI^daHz5gKZ|1 QT4œiCaE!W1G-* 0s^kMd́_ )@iH6o}(C냃U?=O7|q~cOoכzQӏO}GFϯ/?owp?Ӱ6gz*~>?8x1ϭ7) # Copyright:: Copyright (c) 2009 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))) $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "chef", "lib"))) require 'rubygems' require 'chef/solr/application/solr' Chef::Solr::Application::Solr.new.run chef-solr-10.12.0/bin/chef-solr-installer0000755000175000017500000000165111772522513017424 0ustar tfheentfheen#!/usr/bin/env ruby # # Author:: Daniel DeLeo () # Copyright:: Copyright (c) 2009, 2011 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require 'rubygems' $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))) $:.unshift(File.expand_path('../../../chef/lib', __FILE__)) require 'chef/solr/solr_installer' Chef::SolrInstaller.new(ARGV).run chef-solr-10.12.0/lib/0000755000175000017500000000000011772522513013614 5ustar tfheentfheenchef-solr-10.12.0/lib/chef/0000755000175000017500000000000011772522513014521 5ustar tfheentfheenchef-solr-10.12.0/lib/chef/solr/0000755000175000017500000000000011772522513015500 5ustar tfheentfheenchef-solr-10.12.0/lib/chef/solr/version.rb0000644000175000017500000000033111772522513017507 0ustar tfheentfheenclass Chef class Solr VERSION = '10.12.0' # Solr Schema. Used to detect incompatibilities between installed solr and # chef-solr versions. SCHEMA_NAME = "chef" SCHEMA_VERSION = '1.2' end end chef-solr-10.12.0/lib/chef/solr/application/0000755000175000017500000000000011772522513020003 5ustar tfheentfheenchef-solr-10.12.0/lib/chef/solr/application/solr.rb0000644000175000017500000002210211772522513021304 0ustar tfheentfheen# # Author:: AJ Christensen ( "-c CONFIG", :long => "--config CONFIG", :default => "/etc/chef/solr.rb", :description => "The configuration file to use" option :log_level, :short => "-l LEVEL", :long => "--log_level LEVEL", :description => "Set the log level (debug, info, warn, error, fatal)", :proc => lambda { |l| l.to_sym } option :log_location, :short => "-L LOGLOCATION", :long => "--logfile LOGLOCATION", :description => "Set the log file location, defaults to STDOUT - recommended for daemonizing", :proc => nil option :pid_file, :short => "-P PID_FILE", :long => "--pid PIDFILE", :description => "Set the PID file location, defaults to /tmp/chef-solr.pid", :proc => nil option :help, :short => "-h", :long => "--help", :description => "Show this message", :on => :tail, :boolean => true, :show_options => true, :exit => 0 option :user, :short => "-u USER", :long => "--user USER", :description => "User to set privilege to", :proc => nil option :group, :short => "-g GROUP", :long => "--group GROUP", :description => "Group to set privilege to", :proc => nil option :daemonize, :short => "-d", :long => "--daemonize", :description => "Daemonize the process", :proc => lambda { |p| true } option :solr_jetty_path, :short => "-W PATH", :long => "--solr-jetty-dir PATH", :description => "Where to place the Solr Jetty instance" option :solr_data_path, :short => "-D PATH", :long => "--solr-data-dir PATH", :description => "Where the Solr data lives" option :solr_home_path, :short => "-H PATH", :long => "--solr-home-dir PATH", :description => "Solr home directory" option :solr_heap_size, :short => "-x SIZE", :long => "--solor-heap-size SIZE", :description => "Set the size of the Java Heap" option :solr_java_opts, :short => "-j OPTS", :long => "--java-opts OPTS", :description => "Raw options passed to Java" option :version, :short => "-v", :long => "--version", :description => "Show chef-solr version", :boolean => true, :proc => lambda {|v| puts "chef-solr: #{::Chef::Solr::VERSION}"}, :exit => 0 def initialize super end def schema_file_path @schema_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'schema.xml') end def solr_config_file_path @solr_config_file_path ||= File.join(Chef::Config[:solr_home_path], 'conf', 'solrconfig.xml') end def schema_document @schema_document ||= begin File.open(schema_file_path, 'r') do |xmlsux| REXML::Document.new(xmlsux) end end end def config_document @config_document ||=begin File.open(solr_config_file_path, 'r') do |xmlsux| REXML::Document.new(xmlsux) end end end def schema_attributes @schema_attributes ||= REXML::XPath.first(schema_document, '/schema').attributes end def solr_main_index_elements location = '/config/mainIndex/' @solr_main_index_elements ||= REXML::XPath.first(config_document, location).elements end def solr_schema_name schema_attributes["name"] end def solr_schema_version schema_attributes["version"] end def solr_main_index_max_field_length @solr_main_index_max_field_length ||=begin field_length_el = solr_main_index_elements.select do |el| el.name == 'maxFieldLength' end field_length_el.empty? ? nil : field_length_el.first.text.to_i end end def valid_schema_name? solr_schema_name == Chef::Solr::SCHEMA_NAME end def valid_schema_version? solr_schema_version == Chef::Solr::SCHEMA_VERSION end def check_value_of_main_index_max_field_length if solr_main_index_max_field_length unless solr_main_index_max_field_length > 10000 message = "The maxFieldLimit for the mainIndex is set to #{solr_main_index_max_field_length}. " message << "It's recommended to increase this value (in #{solr_config_file_path})." Chef::Log.warn message end else Chef::Log.warn "Unable to determine the maxFieldLimit for the mainIndex (in #{solr_config_file_path})" end end def solr_home_exist? File.directory?(Chef::Config[:solr_home_path]) end def solr_data_dir_exist? File.directory?(Chef::Config[:solr_data_path]) end def solr_jetty_home_exist? File.directory?(Chef::Config[:solr_jetty_path]) end def assert_solr_installed! unless solr_home_exist? && solr_data_dir_exist? && solr_jetty_home_exist? Chef::Log.fatal "Chef Solr is not installed or solr_home_path, solr_data_path, and solr_jetty_path are misconfigured." Chef::Log.fatal "Your current configuration is:" Chef::Log.fatal "solr_home_path: #{Chef::Config[:solr_home_path]}" Chef::Log.fatal "solr_data_path: #{Chef::Config[:solr_data_path]}" Chef::Log.fatal "solr_jetty_path: #{Chef::Config[:solr_jetty_path]}" Chef::Log.fatal "You can install Chef Solr using the chef-solr-installer script." exit 1 end end def assert_valid_schema! unless valid_schema_name? && valid_schema_version? Chef::Log.fatal "Your Chef Solr installation needs to be upgraded." Chef::Log.fatal "Expected schema version #{Chef::Solr::SCHEMA_VERSION} but version #{solr_schema_version} is installed." Chef::Log.fatal "Use chef-solr-installer to upgrade your Solr install after backing up your data." exit 1 end end def setup_application assert_solr_installed! assert_valid_schema! check_value_of_main_index_max_field_length # Need to redirect stdout and stderr so Java process inherits them. # If -L wasn't specified, Chef::Config[:log_location] will be an IO # object, otherwise it will be a String. # # Open this as a privileged user and hang onto it if Chef::Config[:log_location].kind_of?(String) @logfile = File.new(Chef::Config[:log_location], "a") end Chef::Log.level = Chef::Config[:log_level] Chef::Daemon.change_privilege end def run_application if Chef::Config[:daemonize] Chef::Daemon.daemonize("chef-solr") end Dir.chdir(Chef::Config[:solr_jetty_path]) do command = "java -Xmx#{Chef::Config[:solr_heap_size]} -Xms#{Chef::Config[:solr_heap_size]}" command << " -Dsolr.data.dir=#{Chef::Config[:solr_data_path]}" command << " -Dsolr.solr.home=#{Chef::Config[:solr_home_path]}" command << " #{Chef::Config[:solr_java_opts]}" if Chef::Config[:solr_java_opts] command << " -jar #{File.join(Chef::Config[:solr_jetty_path], 'start.jar')}" Chef::Log.info("Starting Solr with #{command}") # Opened earlier before we dropped privileges, don't need it anymore close_and_reopen_log_file if @logfile Kernel.exec(command) end end def close_and_reopen_log_file Chef::Log.close STDOUT.reopen(@logfile) STDERR.reopen(@logfile) end end end end end chef-solr-10.12.0/lib/chef/solr/solr_installer.rb0000644000175000017500000002440111772522513021062 0ustar tfheentfheen# # Author:: Daniel DeLeo ( cli_config.to_hash config_file_config = CompatConfig.new.from_file(cli_config.config_file).to_hash #pp :config_file_config => config_file_config apply_hash(config_file_config) apply_hash(cli_config.to_hash) #pp :combined_config => self.to_hash self end def to_hash self.class.configurables.inject({}) do |hash, config_option| value = instance_variable_get("@#{config_option}".to_sym) hash[config_option] = value if value hash end end def apply_hash(hash) hash.each do |key, value| method_for_key = "#{key}=".to_sym if respond_to?(method_for_key) send(method_for_key, value) else STDERR.puts("Configuration setting #{key} is unknown and will be ignored") end end end module CLI @config = Config.new @option_parser = OptionParser.new do |o| o.banner = "Usage: chef-solr-installer [options]" o.on('-c', '--config CONFIG_FILE', 'The configuration file to use') do |conf| @config.config_file = File.expand_path(conf) end o.on('-u', '--user USER', "User who will own Solr's data directory") do |u| @config.user = u end o.on('-g', '--group GROUP', "Group that will own Solr's data directory") do |g| @config.group = g end o.on('-p', '--base-path PATH', "The base path for the installation. Must be given before any -H -W or -D options") do |path| @config.solr_base_path = path end o.on('-H', '--solr-home-dir PATH', 'Where to create the Solr home directory. Defaults to BASE_PATH/solr') do |path| @config.solr_home_path = path end o.on('-W', '--solr-jetty-path PATH', 'Where to install Jetty for Solr. Defaults to BASE_PATH/solr-jetty ') do |path| @config.solr_jetty_path = path end o.on('-D', '--solr-data-path PATH', 'Where to create the Solr data directory. Defaults to BASE_PATH/solr/data') do |path| @config.solr_data_path = path end o.on('-n', '--noop', "Don't actually install, just show what would be done by the install") do @config.noop = true end o.on('-f', '--force', 'Overwrite any existing installation without asking for confirmation') do @config.force = true end o.on_tail('-h', '--help', 'show this message') do puts "chef-solr-installer #{Chef::Solr::VERSION}" puts '' puts o puts '' puts 'Default Settings:' @config.each_configurable do |param, value| value_for_display = value || "none/false" puts " #{param}:".ljust(20) + " #{value_for_display}" end exit 1 end o.on_tail('-v', '--version', 'show the version and exit') do puts "chef-solr-installer #{Chef::Solr::VERSION}" exit 0 end end def self.parse_options(argv) @option_parser.parse!(argv.dup) @config end def self.config @config end end end include Chef::Mixin::ShellOut PACKAGED_SOLR_DIR = File.expand_path( "../../../../solr", __FILE__) attr_reader :config def initialize(argv) @indent = 0 @config = Config.new.configure_from(argv.dup) @overwriting = false end def overwriting? @overwriting end def chef_solr_installed? File.exist?(config.solr_home_path) end def run say '' say "*** DRY RUN ***" if config.noop? if chef_solr_installed? @overwriting = true confirm_overwrite unless config.force? || config.noop? scorch_the_earth end create_solr_home create_solr_data_dir unpack_solr_jetty say "" say "Successfully installed Chef Solr." if overwriting? say "You can restore your search index using `knife index rebuild`" end end def confirm_overwrite if STDIN.tty? && STDOUT.tty? say "Chef Solr is already installed in #{config.solr_home_path}" print "Do you want to overwrite the current install? All existing Solr data will be lost. [y/n] " unless STDIN.gets =~ /^y/ say "Quitting. Try running this with --noop to see what it will change." exit 1 end else say(<<-FAIL) ERROR: Chef Solr is already installed in #{config.solr_home_path} and you did not use the --force option. Use --force to overwrite an existing installation in a non- interactive terminal. FAIL exit 1 end end def scorch_the_earth group("Removing the existing Chef Solr installation") do rm_rf(config.solr_home_path) rm_rf(config.solr_jetty_path) rm_rf(config.solr_data_path) end end def create_solr_home group("Creating Solr Home Directory") do mkdir_p(config.solr_home_path) chdir(config.solr_home_path) do sh("tar zxvf #{File.join(PACKAGED_SOLR_DIR, 'solr-home.tar.gz')}") end end end def create_solr_data_dir group("Creating Solr Data Directory") do mkdir_p(config.solr_data_path) chown(config.solr_data_path) end end def unpack_solr_jetty group("Unpacking Solr Jetty") do mkdir_p(config.solr_jetty_path) chdir(config.solr_jetty_path) do sh("tar zxvf #{File.join(PACKAGED_SOLR_DIR, 'solr-jetty.tar.gz')}") end chown(config.solr_jetty_path) end end def mkdir_p(directory) say "mkdir -p #{directory}" FileUtils.mkdir_p(directory, :mode => 0755) unless config.noop? end def chdir(dir, &block) say "entering #{dir}" if config.noop? yield if block_given? # still call the block so we get the noop output. else Dir.chdir(dir) { yield if block_given? } end end def sh(*args) opts = args[1, args.size - 1] opts_msg = opts.empty? ? '' : " #{opts.to_s}" say "#{args.first}#{opts_msg}" shell_out!(*(args << {:cwd => false})) unless config.noop? end def chown(file) if config.user msg = "chown -R #{config.user}" msg << ":#{config.group}" if config.group msg << " #{file}" say msg FileUtils.chown_R(config.user, config.group, file) unless config.noop? end end def rm_rf(path) say "rm -rf #{path}" FileUtils.rm_rf(path) unless config.noop? end def indent @indent += 1 yield @indent -= 1 end def group(message, &block) say(message) indent(&block) end def say(message) puts "#{' ' * (2 * @indent)}#{message}" end end end chef-solr-10.12.0/lib/chef/solr.rb0000644000175000017500000000003411772522513016022 0ustar tfheentfheenrequire 'chef/solr/version'