solr_cloud-connection 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d4b1ea9a7eade492c2e88434c38dadc43bcbb5a28084c4be797ce2c77eb70ce
4
- data.tar.gz: 5531b66702ac408e0631239568035f2693cbda02b06e5401b858caa3bd633d9f
3
+ metadata.gz: da67e9a6312ae058259368a9933abe711d1c0554337c59c5f688cf2f17cee606
4
+ data.tar.gz: 36b815217b2f3e806d9b639d4839f093d61327ee496fee1c3d4774039c688e48
5
5
  SHA512:
6
- metadata.gz: b6fcb28bcf8a42191ce737b4c5ae431d669a66e92b3a2d947e26c7901f3a9b5ec0afd4353d00bf6db4ae397a10c4c8aee629c366fbb6976595170b47b7cf1e2a
7
- data.tar.gz: c8689a6b34f2ba3307ac1bfd19adf2c5fff13ecfd7b6aa2fc934754c9667569b369fddfcb4f796528d3594d5babf3213c603a9871cb92edbbb28a6f78e45e006
6
+ metadata.gz: c828e6c7f7976cee46ac7b81c8955d2253253e3084e3841e26a502bf2d03808327578e69e63a47c0907dd7d38df3db27747a2383a6e8a6f9f4b1a73c69832340
7
+ data.tar.gz: 25548a6825b308a62ec376bf1b59d596a557c8508f9feeb56cabd5bc402907ecf4f7602658c5087483424844d1fffddf2c7673ecc2f16cefb3ad79f03696aba5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] - 2025-03-24
4
+ - Added some sugar for unifying aliases and collections
5
+ - Update tests
6
+ - Better errors
7
+ - Flesh out README.md to be a useful document
8
+
9
+
3
10
  ## [0.4.0] - 2023-12-07
4
11
  - Fixed rules about what names are legal collections/configsets/aliases
5
12
  - Update version and changelog
data/README.md CHANGED
@@ -1,14 +1,36 @@
1
1
  # SolrCloud::Connection
2
2
 
3
- Do basic administrative tasks on a running Solr cloud instance, including:
3
+ ## Common usage
4
4
 
5
- * create (i.e., upload) a configSet when given a `conf` directory
6
- * list, create, and delete configsets, collections, and aliases
7
- * get basic version information for the running solr
8
- * check on the health of individual collections
9
- * treat an alias (mostly) as a collection
10
- * TODO automatically generate methods to talk to defined requestHandlers
11
- * TODO Add something useful for configsets to do
5
+ ```ruby
6
+
7
+ # Connect to the server, upload a config set, make a collection based on it,
8
+ # and make an alias pointing to that collection
9
+
10
+ server = SolrCloud::Connection.new(url: url, user: user, password: pass)
11
+ cfg = server.create_configset(name: "my_cfg", confdir: "/path/to/my/conf")
12
+ cars_v1 = server.create_collection(name: "cars_v1", configset: "my_cfg")
13
+ cars = cars_v1.alias_as("cars")
14
+
15
+ ```
16
+
17
+ ## Basic functionality / Roadmap
18
+
19
+ Do basic administrative tasks on a running Solr cloud instance
20
+
21
+ * [x] create (i.e., upload) a configSet when given a `conf` directory
22
+ * [x] list, create, and delete configsets, collections, and aliases
23
+ * [x] get basic version information for the running solr
24
+ * [x] check on the health of individual collections
25
+ * [x] treat an alias (mostly) as a collection
26
+ * [ ] automatically generate methods to talk to defined requestHandlers and updateHandlers
27
+ * [ ] provide a way to talk to the analyzer for testing of fieldTypes
28
+ * [ ] hook into the schema API
29
+ * [ ] allow it to work with cores, and not just solrcloud collections (which, you know bad naming then)
30
+ * [ ] figure out how to deal with managed resources
31
+ * [ ] get info from updateHandler metrics, esp. pending documents and cumulative errors
32
+ * [ ] hook into performance metrics for easy reporting and checks
33
+ * [ ] support more of the v2 API
12
34
 
13
35
  In almost all cases, you can treat an alias to a collection like the underlying collection.
14
36
 
@@ -43,6 +65,8 @@ user = "solr"
43
65
  password = "SolrRocks"
44
66
  config_directory = "/path/to/myconfig/conf" # Directory 'conf' contains solrconfig.xml
45
67
 
68
+ require "solr_cloud/connection"
69
+
46
70
  server = SolrCloud::Connection.new(url: url, user: user, password: pass)
47
71
  #=> <SolrCloud::Connection http://localhost:9090>
48
72
 
@@ -66,19 +90,25 @@ server.configset_names #=> ["_default"]
66
90
 
67
91
  # Create a new configset by taking a conf directory, zipping it up,
68
92
  # and sending it to solr
69
- cset = server.create_configset(name: "horseless", confdir: config_directory) #=> <SolrCloud::Configset 'horseless' at http://localhost:9090>
93
+ cset = server.create_configset(name: "horseless", confdir: config_directory)
94
+ #=> <SolrCloud::Configset 'horseless' at http://localhost:9090>
70
95
  server.configset_names #=> ["_default", "horseless"]
71
96
 
72
97
  # That's a dumb name for a config set. Delete it and try again.
73
98
  cset.delete! #=> <SolrCloud::Connection http://localhost:9090>
74
- cset = server.create_configset(name: "cars_cfg", confdir: config_directory) #=> <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>
75
- server.configsets #=> [<SolrCloud::Configset '_default' at http://localhost:9090>, <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>]
99
+ cset = server.create_configset(name: "cars_cfg", confdir: config_directory)
100
+ #=> <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>
101
+ server.configsets
102
+ #=> [<SolrCloud::Configset '_default' at http://localhost:9090>,
103
+ # <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>]
76
104
 
77
105
  # Can't be overwritten by accident
78
- server.create_configset(name: "cars_cfg", confdir: config_directory) #=> raised #<SolrCloud::WontOverwriteError: Won't replace configset cars_cfg unless 'force: true' passed >
106
+ server.create_configset(name: "cars_cfg", confdir: config_directory)
107
+ #=> raised #<SolrCloud::WontOverwriteError: Won't replace configset cars_cfg unless 'force: true' passed >
79
108
 
80
109
  # But you can force it
81
- server.create_configset(name: "cars_cfg", confdir: config_directory, force: true) #=> <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>
110
+ server.create_configset(name: "cars_cfg", confdir: config_directory, force: true)
111
+ #=> <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>
82
112
 
83
113
  cfg = server.get_configset("cars_cfg") #=> <SolrCloud::Configset 'cars_cfg' at http://localhost:9090>
84
114
  cfg.in_use? #=> false
@@ -127,7 +157,8 @@ cars_v1.aliased? #=> true
127
157
 
128
158
  cars_v1.has_alias?("cars") #=> true
129
159
  cars_v1.alias_as("autos") #=> <SolrCloud::Alias 'autos' (alias of 'cars_v1')>
130
- cars_v1.aliases #=> [<SolrCloud::Alias 'cars' (alias of 'cars_v1')>, <SolrCloud::Alias 'autos' (alias of 'cars_v1')>]
160
+ cars_v1.aliases
161
+ #=> [<SolrCloud::Alias 'cars' (alias of 'cars_v1')>, <SolrCloud::Alias 'autos' (alias of 'cars_v1')>]
131
162
 
132
163
  cars_v1.get_alias("autos").delete! #=> <SolrCloud::Connection http://localhost:9090>
133
164
  cars_v1.aliases #=> [<SolrCloud::Alias 'cars' (alias of 'cars_v1')>]
@@ -226,5 +257,5 @@ This repository is set up to run tests under docker.
226
257
 
227
258
  ## Contributing
228
259
 
229
- Bugs, functionality suggestions, API suggestions, feature requests, etc. all welcom
260
+ Bugs, functionality suggestions, API suggestions, feature requests, etc. all welcome
230
261
  on GitHub at https://github.com/mlibrary/solr_cloud-connection.
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ require "standard/rake"
10
10
  task default: %i[spec standard docs]
11
11
  task docs: %i[yard]
12
12
 
13
- require 'yard'
13
+ require "yard"
14
14
 
15
15
  YARD::Rake::YardocTask.new do |t|
16
16
  t.files = ["lib/**/*.rb"] # optional
@@ -41,13 +41,13 @@ module SolrCloud
41
41
  # @return [Collection] the now-current collection
42
42
  def switch_collection_to(coll)
43
43
  collect_name = case coll
44
- when String
45
- coll
46
- when Collection
47
- coll.name
48
- else
49
- raise "Alias#switch_collection_to only takes a name(string) or a collection, not '#{coll}'"
50
- end
44
+ when String
45
+ coll
46
+ when Collection
47
+ coll.name
48
+ else
49
+ raise "Alias#switch_collection_to only takes a name(string) or a collection, not '#{coll}'"
50
+ end
51
51
  raise NoSuchCollectionError unless connection.has_collection?(collect_name)
52
52
  connection.create_alias(name: name, collection_name: collect_name, force: true)
53
53
  end
@@ -55,10 +55,10 @@ module SolrCloud
55
55
 
56
56
  def ==(other)
57
57
  case other
58
- when SolrCloud::Collection
59
- self.collection.name == other.collection.name
60
- else
61
- false
58
+ when SolrCloud::Collection
59
+ collection.name == other.collection.name
60
+ else
61
+ false
62
62
  end
63
63
  end
64
64
 
@@ -68,7 +68,7 @@ module SolrCloud
68
68
  def delete!
69
69
  return connection unless exist?
70
70
  raise CollectionAliasedError.new("Cannot delete collection #{name}; it has alias(s) #{alias_names.join(", ")}") if aliased?
71
- connection.get("solr/admin/collections", { action: "DELETE", name: name })
71
+ connection.get("solr/admin/collections", {action: "DELETE", name: name})
72
72
  connection
73
73
  end
74
74
 
@@ -181,10 +181,10 @@ module SolrCloud
181
181
 
182
182
  def add(docs)
183
183
  docarray = if docs === Array
184
- docs
185
- else
186
- [docs]
187
- end
184
+ docs
185
+ else
186
+ [docs]
187
+ end
188
188
  post("solr/#{name}/update/") do |r|
189
189
  r.body = docarray
190
190
  end
@@ -200,10 +200,10 @@ module SolrCloud
200
200
  def inspect
201
201
  anames = alias_names
202
202
  astring = if anames.empty?
203
- ""
204
- else
205
- " (aliased by #{anames.map { |x| "'#{x}'" }.join(", ")})"
206
- end
203
+ ""
204
+ else
205
+ " (aliased by #{anames.map { |x| "'#{x}'" }.join(", ")})"
206
+ end
207
207
  "<#{self.class} '#{name}'#{astring}>"
208
208
  end
209
209
 
@@ -7,7 +7,6 @@ module SolrCloud
7
7
  # throw an error if that's an illegal operation (because a collection is
8
8
  # using it)
9
9
  class Configset
10
-
11
10
  # @return [String] the name of this configset
12
11
  attr_reader :name
13
12
 
@@ -5,7 +5,6 @@ module SolrCloud
5
5
  # methods having to do with aliases, to be included by the connection object.
6
6
  # These are split out only to make it easier to deal with them.
7
7
  module AliasAdmin
8
-
9
8
  # A simple data-class to pair an alias with its collection
10
9
  AliasCollectionPair = Struct.new(:alias, :collection)
11
10
 
@@ -24,7 +23,7 @@ module SolrCloud
24
23
  end
25
24
  raise NoSuchCollectionError.new("Can't find collection #{collection_name}") unless has_collection?(collection_name)
26
25
  if has_alias?(name) && !force
27
- raise WontOverwriteError.new("Alias '#{name}' already points to collection '#{self.get_alias(name).collection.name}'; won't overwrite without force: true")
26
+ raise WontOverwriteError.new("Alias '#{name}' already points to collection '#{get_alias(name).collection.name}'; won't overwrite without force: true")
28
27
  end
29
28
  connection.get("solr/admin/collections", action: "CREATEALIAS", name: name, collections: collection_name)
30
29
  get_alias(name)
@@ -83,5 +82,3 @@ module SolrCloud
83
82
  end
84
83
  end
85
84
  end
86
-
87
-
@@ -20,17 +20,16 @@ module SolrCloud
20
20
  # @raise [WontOverwriteError] if the collection already exists
21
21
  # @return [Collection] the collection created
22
22
  def create_collection(name:, configset:, shards: 1, replication_factor: 1)
23
-
24
23
  unless legal_solr_name?(name)
25
24
  raise IllegalNameError.new("'#{name}' is not a valid solr name. Use only ASCII letters/numbers, dash, and underscore")
26
25
  end
27
26
 
28
27
  configset_name = case configset
29
- when Configset
30
- configset.name
31
- else
32
- configset.to_s
33
- end
28
+ when Configset
29
+ configset.name
30
+ else
31
+ configset.to_s
32
+ end
34
33
  raise WontOverwriteError.new("Collection #{name} already exists") if has_collection?(name)
35
34
  raise NoSuchConfigSetError.new("Configset '#{configset_name}' doesn't exist") unless has_configset?(configset_name)
36
35
 
@@ -7,7 +7,6 @@ module SolrCloud
7
7
  # methods having to do with configsets, to be included by the connection object.
8
8
  # These are split out only to make it easier to deal with them.
9
9
  module ConfigsetAdmin
10
-
11
10
  # Given the path to a solr configuration "conf" directory (i.e., the one with
12
11
  # solrconfig.xml in it), zip it up and send it to solr as a new configset.
13
12
  # @param name [String] Name to give the new configset
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SolrCloud
4
4
  class Connection
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -31,12 +31,20 @@ module SolrCloud
31
31
  # @return [String] String representation of the URL to solr
32
32
  attr_reader :url
33
33
 
34
+ # @return [String] solr user
35
+ attr_reader :user
36
+ alias_method :username, :user
37
+
38
+ # @return [String] Solr password
39
+ attr_reader :password
40
+
34
41
  # @return [#info] The logger
35
42
  attr_reader :logger
36
43
 
37
44
  # @return [Faraday::Connection] the underlying Faraday connection
38
45
  attr_reader :connection
39
46
 
47
+
40
48
  # let the underlying connection handle HTTP verbs
41
49
 
42
50
  # @!method get
@@ -72,12 +80,12 @@ module SolrCloud
72
80
  @user = user
73
81
  @password = password
74
82
  @logger = case logger
75
- when :off, :none
76
- Logger.new(File::NULL, level: Logger::FATAL)
77
- when nil
78
- Logger.new($stderr, level: Logger::WARN)
79
- else
80
- logger
83
+ when :off, :none
84
+ Logger.new(File::NULL, level: Logger::FATAL)
85
+ when nil
86
+ Logger.new($stderr, level: Logger::WARN)
87
+ else
88
+ logger
81
89
  end
82
90
  @connection = create_raw_connection(url: url, adapter: adapter, user: user, password: password, logger: @logger)
83
91
  bail_if_incompatible!
@@ -112,10 +120,6 @@ module SolrCloud
112
120
  end
113
121
  end
114
122
 
115
- # Allow accessing the raw_connection via "connection". Yes, connection.connection
116
- # can be confusing, but it makes the *_admin stuff easier to read.
117
- alias_method :connection, :connection
118
-
119
123
  # Check to see if we can actually talk to the solr in question
120
124
  # raise [UnsupportedSolr] if the solr version isn't at least 8
121
125
  # raise [ConnectionFailed] if we can't connect for some reason
@@ -192,6 +196,3 @@ module SolrCloud
192
196
  end
193
197
  end
194
198
  end
195
-
196
-
197
-
data/readme.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "pathname"
3
4
  $LOAD_PATH.unshift Pathname.new(__dir__) + "lib"
4
5
  require_relative "lib/solr_cloud/connection"
@@ -7,13 +8,11 @@ url = "http://localhost:9090"
7
8
  user = "solr"
8
9
  pass = "SolrRocks"
9
10
 
10
-
11
11
  server = SolrCloud::Connection.new(url: url, user: user, password: pass) #=>
12
12
 
13
-
14
- server.aliases.each {|a| a.delete!}
15
- server.collections.each {|c| c.delete!}
16
- server.configsets.reject {|c| c.name == "_default"}.each {|c| c.delete!}
13
+ server.aliases.each { |a| a.delete! }
14
+ server.collections.each { |c| c.delete! }
15
+ server.configsets.reject { |c| c.name == "_default" }.each { |c| c.delete! }
17
16
 
18
17
  # or bring your own Faraday object
19
18
  # server2 = SolrCloud::Connection.new_with_faraday(faraday_connection)
@@ -83,8 +82,6 @@ begin
83
82
  rescue
84
83
  end
85
84
 
86
-
87
-
88
85
  ##### Aliases
89
86
 
90
87
  # We'll want to alias it so we can just use 'cars'
@@ -125,9 +122,6 @@ cars.switch_collection_to("cars_v1")
125
122
  server.collection_names
126
123
 
127
124
  # They even == to each other
128
- cars
129
- cars == cars_v1
130
- cars == cars_v2
131
125
 
132
126
  # But sometimes you want to differentiate them from each other
133
127
  server.only_collection_names
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_cloud-connection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill Dueber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-22 00:00:00.000000000 Z
11
+ date: 2024-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -53,75 +53,107 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: pry
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: dotenv
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: standard
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 1.35.0
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '1.0'
90
93
  type: :development
91
94
  prerelease: false
92
95
  version_requirements: !ruby/object:Gem::Requirement
93
96
  requirements:
94
97
  - - ">="
95
98
  - !ruby/object:Gem::Version
96
- version: '0'
99
+ version: 1.35.0
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: simplecov
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
107
  - - ">="
102
108
  - !ruby/object:Gem::Version
103
- version: '0'
109
+ version: 0.22.0
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '0.0'
104
113
  type: :development
105
114
  prerelease: false
106
115
  version_requirements: !ruby/object:Gem::Requirement
107
116
  requirements:
108
117
  - - ">="
109
118
  - !ruby/object:Gem::Version
110
- version: '0'
119
+ version: 0.22.0
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.0'
111
123
  - !ruby/object:Gem::Dependency
112
124
  name: yard
113
125
  requirement: !ruby/object:Gem::Requirement
114
126
  requirements:
115
127
  - - ">="
116
128
  - !ruby/object:Gem::Version
117
- version: '0'
129
+ version: 0.9.0
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 0.9.0
118
133
  type: :development
119
134
  prerelease: false
120
135
  version_requirements: !ruby/object:Gem::Requirement
121
136
  requirements:
122
137
  - - ">="
123
138
  - !ruby/object:Gem::Version
124
- version: '0'
139
+ version: 0.9.0
140
+ - - "~>"
141
+ - !ruby/object:Gem::Version
142
+ version: 0.9.0
143
+ - !ruby/object:Gem::Dependency
144
+ name: dotenv
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '3.0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - "~>"
155
+ - !ruby/object:Gem::Version
156
+ version: '3.0'
125
157
  description:
126
158
  email:
127
159
  - bill@dueber.com
@@ -170,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
202
  - !ruby/object:Gem::Version
171
203
  version: '0'
172
204
  requirements: []
173
- rubygems_version: 3.4.17
205
+ rubygems_version: 3.5.11
174
206
  signing_key:
175
207
  specification_version: 4
176
208
  summary: Do basic administrative operations on a solr cloud instance and collections