Class: SolrWrapper::Instance
- Inherits:
-
Object
- Object
- SolrWrapper::Instance
- Defined in:
- lib/solr_wrapper/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
Instance Method Summary collapse
-
#clean! ⇒ Object
Clean up any files solr_wrapper may have downloaded.
- #configure ⇒ Object
-
#create(options = {}) ⇒ Object
Create a new collection in solr.
-
#delete(name, _options = {}) ⇒ Object
Create a new collection in solr.
-
#extract ⇒ String
extract a copy of solr to instance_dir Does noting if solr already exists at instance_dir.
- #extract_and_configure ⇒ Object
- #host ⇒ Object
-
#initialize(options = {}) ⇒ Instance
constructor
A new instance of Instance.
- #port ⇒ Object
-
#remove_instance_dir! ⇒ Object
Clean up any files in the Solr instance dir.
-
#restart ⇒ Object
Stop Solr and wait for it to finish exiting.
-
#start ⇒ Object
Start Solr and wait for it to become available.
-
#started? ⇒ Boolean
Is Solr running?.
-
#status ⇒ Object
Check the status of a managed Solr service.
-
#stop ⇒ Object
Stop Solr and wait for it to finish exiting.
- #url ⇒ Object
- #version ⇒ Object
-
#with_collection(options = {}) ⇒ Object
Create a new collection, run the block, and then clean up the collection.
- #wrap(&_block) ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/solr_wrapper/instance.rb', line 16 def config @config end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
16 17 18 |
# File 'lib/solr_wrapper/instance.rb', line 16 def md5 @md5 end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
16 17 18 |
# File 'lib/solr_wrapper/instance.rb', line 16 def pid @pid end |
Instance Method Details
#clean! ⇒ Object
Clean up any files solr_wrapper may have downloaded
161 162 163 164 165 166 167 168 |
# File 'lib/solr_wrapper/instance.rb', line 161 def clean! stop remove_instance_dir! FileUtils.remove_entry(config.download_path) if File.exists?(config.download_path) FileUtils.remove_entry(config.tmp_save_dir, true) if File.exists? config.tmp_save_dir md5.clean! FileUtils.remove_entry(config.version_file) if File.exists? config.version_file end |
#configure ⇒ Object
176 177 178 179 180 |
# File 'lib/solr_wrapper/instance.rb', line 176 def configure raise_error_unless_extracted FileUtils.cp config.solr_xml, File.join(config.instance_dir, 'server', 'solr', 'solr.xml') if config.solr_xml FileUtils.cp_r File.join(config.extra_lib_dir, '.'), File.join(config.instance_dir, 'server', 'solr', 'lib') if config.extra_lib_dir end |
#create(options = {}) ⇒ Object
Create a new collection in solr
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/solr_wrapper/instance.rb', line 125 def create( = {}) [:name] ||= SecureRandom.hex = { p: port } [:c] = [:name] if [:name] [:d] = [:dir] if [:dir] exec("create", ) [:name] end |
#delete(name, _options = {}) ⇒ Object
Create a new collection in solr
139 140 141 |
# File 'lib/solr_wrapper/instance.rb', line 139 def delete(name, = {}) exec("delete", c: name, p: port) end |
#extract ⇒ String
extract a copy of solr to instance_dir Does noting if solr already exists at instance_dir
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/solr_wrapper/instance.rb', line 191 def extract return config.instance_dir if extracted? zip_path = download begin Zip::File.open(zip_path) do |zip_file| # Handle entries one by one zip_file.each do |entry| dest_file = File.join(config.tmp_save_dir, entry.name) FileUtils.remove_entry(dest_file, true) entry.extract(dest_file) end end rescue Exception => e abort "Unable to unzip #{zip_path} into #{config.tmp_save_dir}: #{e.}" end begin FileUtils.remove_dir(config.instance_dir, true) FileUtils.cp_r File.join(config.tmp_save_dir, File.basename(config.download_url, ".zip")), config.instance_dir self.extracted_version = config.version FileUtils.chmod 0755, config.solr_binary rescue Exception => e abort "Unable to copy #{config.tmp_save_dir} to #{config.instance_dir}: #{e.}" end config.instance_dir ensure FileUtils.remove_entry config.tmp_save_dir if File.exists? config.tmp_save_dir end |
#extract_and_configure ⇒ Object
182 183 184 |
# File 'lib/solr_wrapper/instance.rb', line 182 def extract_and_configure extract.tap { configure } end |
#host ⇒ Object
42 43 44 |
# File 'lib/solr_wrapper/instance.rb', line 42 def host config.host end |
#port ⇒ Object
46 47 48 |
# File 'lib/solr_wrapper/instance.rb', line 46 def port config.port end |
#remove_instance_dir! ⇒ Object
Clean up any files in the Solr instance dir
172 173 174 |
# File 'lib/solr_wrapper/instance.rb', line 172 def remove_instance_dir! FileUtils.remove_entry(instance_dir, true) if File.exists? instance_dir end |
#restart ⇒ Object
Stop Solr and wait for it to finish exiting
97 98 99 100 101 |
# File 'lib/solr_wrapper/instance.rb', line 97 def restart if config.managed? && started? exec('restart', p: port, c: config.cloud) end end |
#start ⇒ Object
Start Solr and wait for it to become available
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/solr_wrapper/instance.rb', line 68 def start extract_and_configure if config.managed? exec('start', p: port, c: config.cloud) # Wait for solr to start unless status sleep 1 end end end |
#started? ⇒ Boolean
Is Solr running?
116 117 118 |
# File 'lib/solr_wrapper/instance.rb', line 116 def started? !!status end |
#status ⇒ Object
Check the status of a managed Solr service
105 106 107 108 109 110 111 112 |
# File 'lib/solr_wrapper/instance.rb', line 105 def status return true unless config.managed? out = exec('status').read out =~ /running on port #{port}/ rescue false end |
#stop ⇒ Object
Stop Solr and wait for it to finish exiting
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/solr_wrapper/instance.rb', line 82 def stop if config.managed? && started? exec('stop', p: port) # Wait for solr to stop while status sleep 1 end end @pid = nil end |
#url ⇒ Object
50 51 52 |
# File 'lib/solr_wrapper/instance.rb', line 50 def url config.url end |
#version ⇒ Object
54 55 56 |
# File 'lib/solr_wrapper/instance.rb', line 54 def version config.version end |
#with_collection(options = {}) ⇒ Object
Create a new collection, run the block, and then clean up the collection
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/solr_wrapper/instance.rb', line 148 def with_collection( = {}) return yield if .empty? name = create() begin yield name ensure delete name end end |
#wrap(&_block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/solr_wrapper/instance.rb', line 58 def wrap(&_block) extract_and_configure start yield self ensure stop end |