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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89757bee4b135ad94b20ef03dd75627928ac6430
4
- data.tar.gz: babf18793c68d48949a54fadaa9c26a846cc90df
3
+ metadata.gz: 6b5646dda6763c39d80505cd273ec369a5710738
4
+ data.tar.gz: baac20d245bb954a07788bf7672fca21bfe838e4
5
5
  SHA512:
6
- metadata.gz: 0fe533d27ff5eceb5cde6b60cb45137382c2498cf1ed97d51e5e59ed8755ec033ccc421915cd4cb16bf9729652d2d2c39675af31eeb1a9a528d468f8c8489625
7
- data.tar.gz: d7cf53f56a7c2765d3f85b890e3acab71d5969970fc26ada8247404101d350f51f64b89a16c1987ad3303a2390909f94b8bc38bbbd4a3c56fb0e7e857becc5f7
6
+ metadata.gz: 9df02b3597772f201d64ac7e0c5108856454297ad3994e00474bd70d1b59e22fc7541f45650487cb06c2b108e5fafab09de4ae0a13d1c482f8fab59d9d6a2eac
7
+ data.tar.gz: 0892bc22d1cd9b8d2df3353a4b0a108578c70cc5ec33c65bf59d87f3ded03b98c4f4308d50a840e8d301a4ef3675f323be23152e1548c6b019b2707b392ccfaf
@@ -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
@@ -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
@@ -81,6 +81,10 @@ module Kazoo
81
81
  end
82
82
  end
83
83
 
84
+ def to_json(generator)
85
+ generator.generate(topic: topic.name, partition: id)
86
+ end
87
+
84
88
  protected
85
89
 
86
90
  def refresh_state
@@ -1,3 +1,3 @@
1
1
  module Kazoo
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -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.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-10-09 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor