Module: SolrCloud::Connection::ConfigsetAdmin
- Included in:
- SolrCloud::Connection
- Defined in:
- lib/solr_cloud/connection/configset_admin.rb
Overview
methods having to do with configsets, to be included by the connection object. These are split out only to make it easier to deal with them.
Defined Under Namespace
Classes: ZipFileGenerator
Instance Method Summary collapse
-
#configset_names ⇒ Array<String>
The names of the config sets.
-
#configsets ⇒ Array<Configset>
Get a list of the already-defined configSets.
-
#create_configset(name:, confdir:, force: false) ⇒ Configset
Given the path to a solr configuration “conf” directory (i.e., the one with solrconfig.xml in it), zip it up and send it to solr as a new configset.
-
#delete_configset(name) ⇒ Connection
Remove the configuration set with the given name.
-
#get_configset(name) ⇒ Object
Get an existing configset.
-
#has_configset?(name) ⇒ Boolean
Check to see if a configset is defined.
Instance Method Details
#configset_names ⇒ Array<String>
Returns the names of the config sets.
44 45 46 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 44 def configset_names connection.get("api/cluster/configs").body["configSets"] end |
#configsets ⇒ Array<Configset>
Get a list of the already-defined configSets
39 40 41 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 39 def configsets configset_names.map { |cs| Configset.new(name: cs, connection: self) } end |
#create_configset(name:, confdir:, force: false) ⇒ Configset
Given the path to a solr configuration “conf” directory (i.e., the one with solrconfig.xml in it), zip it up and send it to solr as a new configset.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 17 def create_configset(name:, confdir:, force: false) config_set_name = name unless legal_solr_name?(config_set_name) raise IllegalNameError.new("'#{config_set_name}' is not a valid solr configset name. Use only ASCII letters/numbers, dash, and underscore") end if has_configset?(config_set_name) && !force raise WontOverwriteError.new("Won't replace configset #{config_set_name} unless 'force: true' passed ") end zfile = "#{Dir.tmpdir}/solr_add_configset_#{name}_#{Time.now.hash}.zip" z = ZipFileGenerator.new(confdir, zfile) z.write @connection.put("api/cluster/configs/#{config_set_name}") do |req| req.body = File.binread(zfile) end # TODO: Error check in here somewhere FileUtils.rm(zfile, force: true) get_configset(name) end |
#delete_configset(name) ⇒ Connection
Remove the configuration set with the given name. No-op if the configset doesn’t actually exist. Test with #has_configset? and SolrCloud::Configset#in_use? manually if need be.
In general, prefer using SolrCloud::Configset#delete! instead of running everything through the connection object.
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 69 def delete_configset(name) if has_configset? name connection.delete("api/cluster/configs/#{name}") end self rescue Faraday::BadRequestError => e msg = e.response[:body]["error"]["msg"] if msg.match?(/not delete ConfigSet/) raise ConfigSetInUseError.new msg else raise e end end |
#get_configset(name) ⇒ Object
Get an existing configset
56 57 58 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 56 def get_configset(name) Configset.new(name: name, connection: self) end |
#has_configset?(name) ⇒ Boolean
Check to see if a configset is defined
51 52 53 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 51 def has_configset?(name) configset_names.include? name.to_s end |