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>
Get the names of all defined configsets.
-
#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) ⇒ Configset
Get an existing configset by name.
-
#has_configset?(name) ⇒ Boolean
Check to see if a configset with the given name is defined.
Instance Method Details
#configset_names ⇒ Array<String>
Get the names of all defined configsets.
The API endpoint differs across major Solr versions:
- Solr 8: uses the V2 API (+GET /api/cluster/configs+).
- Solr 9+: uses the V1 API (+GET /solr/admin/configs?action=LIST+). The V2 configset path changed between Solr 8 and Solr 9; V1 is used for consistency on Solr 9 and later.
72 73 74 75 76 77 78 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 72 def configset_names if solr9_or_later? connection.get("solr/admin/configs", action: "LIST").body["configSets"] else connection.get("api/cluster/configs").body["configSets"] end end |
#configsets ⇒ Array<Configset>
Get a list of the already-defined configsets.
58 59 60 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 58 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.
The upload API endpoint differs across major Solr versions:
- Solr 8: uses the V2 API (+PUT /api/cluster/configs/
+), which was the canonical configset path in Solr 8. - Solr 9+: uses the V2 API (+PUT /api/configsets/
+). The V2 configset path moved from /api/cluster/configs/<name>(Solr 8) to/api/configsets/<name>(Solr 9+). The new V2 PUT defaults to overwriting an existing configset, which means in-use configsets can be replaced without deleting them first.
Dispatches via SolrCloud::Connection#solr9_or_later?; see #upload_configset_v9 and #upload_configset_v8 for the version-specific implementations.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 32 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" ZipFileGenerator.new(confdir, zfile).write if solr9_or_later? upload_configset_v9(config_set_name, zfile) else upload_configset_v8(config_set_name, zfile) end get_configset(name) ensure FileUtils.rm(zfile, force: true) if zfile 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.
The delete API endpoint differs across major Solr versions:
- Solr 8: uses the V2 API (+DELETE /api/cluster/configs/
+). - Solr 9+: uses the V1 API (+GET /solr/admin/configs?action=DELETE+). The V2 configset path changed between Solr 8 and Solr 9; V1 is used for consistency on Solr 9 and later.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 115 def delete_configset(name) if has_configset?(name) if solr9_or_later? connection.get("solr/admin/configs", action: "DELETE", name: name) else connection.delete("api/cluster/configs/#{name}") end 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) ⇒ Configset
Does not verify that the configset actually exists; use #has_configset? to check first if needed.
Get an existing configset by name.
93 94 95 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 93 def get_configset(name) Configset.new(name: name, connection: self) end |
#has_configset?(name) ⇒ Boolean
Check to see if a configset with the given name is defined.
83 84 85 |
# File 'lib/solr_cloud/connection/configset_admin.rb', line 83 def has_configset?(name) configset_names.include? name.to_s end |