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.
45 46 47 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 45 def configset_names connection.get("api/cluster/configs").body["configSets"] end |
#configsets ⇒ Array<Configset>
Get a list of the already-defined configSets
40 41 42 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 40 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.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 18 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 70 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
57 58 59 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 57 def get_configset(name) Configset.new(name: name, connection: self) end |
#has_configset?(name) ⇒ Boolean
Check to see if a configset is defined
52 53 54 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 52 def has_configset?(name) configset_names.include? name.to_s end |