kazoo-ruby 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kazoo/cli/cluster.rb +7 -0
- data/lib/kazoo/cluster.rb +15 -0
- data/lib/kazoo/partition.rb +4 -0
- data/lib/kazoo/version.rb +1 -1
- data/test/cluster_test.rb +26 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b5646dda6763c39d80505cd273ec369a5710738
|
4
|
+
data.tar.gz: baac20d245bb954a07788bf7672fca21bfe838e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9df02b3597772f201d64ac7e0c5108856454297ad3994e00474bd70d1b59e22fc7541f45650487cb06c2b108e5fafab09de4ae0a13d1c482f8fab59d9d6a2eac
|
7
|
+
data.tar.gz: 0892bc22d1cd9b8d2df3353a4b0a108578c70cc5ec33c65bf59d87f3ded03b98c4f4308d50a840e8d301a4ef3675f323be23152e1548c6b019b2707b392ccfaf
|
data/lib/kazoo/cli/cluster.rb
CHANGED
@@ -23,6 +23,13 @@ module Kazoo
|
|
23
23
|
$stdout.puts "Broker #{broker_name} is non-critical and can be stopped safely."
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
desc "election", "Triggers a preferred leader election"
|
28
|
+
def election
|
29
|
+
validate_class_options!
|
30
|
+
|
31
|
+
kafka_cluster.preferred_leader_election
|
32
|
+
end
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/kazoo/cluster.rb
CHANGED
@@ -102,6 +102,21 @@ module Kazoo
|
|
102
102
|
partitions.any?(&:under_replicated?)
|
103
103
|
end
|
104
104
|
|
105
|
+
# Triggers a preferred leader elections for the provided list of partitions. If no list of
|
106
|
+
# partitions is provided, the preferred leader will be elected for all partitions in the cluster.
|
107
|
+
def preferred_leader_election(partitions: nil)
|
108
|
+
partitions = self.partitions if partitions.nil?
|
109
|
+
result = zk.create(path: "/admin/preferred_replica_election", data: JSON.generate(version: 1, partitions: partitions))
|
110
|
+
case result.fetch(:rc)
|
111
|
+
when Zookeeper::Constants::ZOK
|
112
|
+
return true
|
113
|
+
when Zookeeper::Constants::ZNODEEXISTS
|
114
|
+
raise Kazoo::Error, "Another preferred leader election is still in progress"
|
115
|
+
else
|
116
|
+
raise Kazoo::Error, "Failed to start preferred leadership election. Result code: #{result.fetch(:rc)}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
105
120
|
# Closes the zookeeper connection and clears all the local caches.
|
106
121
|
def close
|
107
122
|
zk.close
|
data/lib/kazoo/partition.rb
CHANGED
data/lib/kazoo/version.rb
CHANGED
data/test/cluster_test.rb
CHANGED
@@ -13,4 +13,30 @@ class ClusterTest < Minitest::Test
|
|
13
13
|
@cluster.topics['test.4'].partitions[2].expects(:isr).returns([@cluster.brokers[1]])
|
14
14
|
assert @cluster.under_replicated?
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_preferred_leader_election
|
18
|
+
@cluster.zk.stubs(:create).with do |parameters|
|
19
|
+
payload = JSON.parse(parameters.fetch(:data))
|
20
|
+
|
21
|
+
[
|
22
|
+
parameters.fetch(:path) == "/admin/preferred_replica_election",
|
23
|
+
payload.fetch('version') == 1,
|
24
|
+
payload.fetch('partitions').length == 1,
|
25
|
+
payload.fetch('partitions').first.fetch('topic') == 'test.1',
|
26
|
+
payload.fetch('partitions').first.fetch('partition') == 0,
|
27
|
+
].all?
|
28
|
+
end.returns(rc: Zookeeper::Constants::ZOK)
|
29
|
+
|
30
|
+
assert @cluster.preferred_leader_election(partitions: [@cluster.topic('test.1').partition(0)])
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_preferred_leader_election_in_progress
|
35
|
+
@cluster.zk.stubs(:create).returns(rc: Zookeeper::Constants::ZNODEEXISTS)
|
36
|
+
exception = assert_raises(Kazoo::Error) do
|
37
|
+
@cluster.preferred_leader_election
|
38
|
+
end
|
39
|
+
|
40
|
+
assert_equal "Another preferred leader election is still in progress", exception.message
|
41
|
+
end
|
16
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kazoo-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|