Class: Ktl::MigrationPlan

Inherits:
Object
  • Object
show all
Defined in:
lib/ktl/migration_plan.rb

Instance Method Summary collapse

Constructor Details

#initialize(zk_client, old_leader, new_leader) ⇒ MigrationPlan

Returns a new instance of MigrationPlan.



5
6
7
8
9
# File 'lib/ktl/migration_plan.rb', line 5

def initialize(zk_client, old_leader, new_leader)
  @zk_client = zk_client
  @old_leader = old_leader.to_java
  @new_leader = new_leader.to_java
end

Instance Method Details

#generateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ktl/migration_plan.rb', line 11

def generate
  plan = Scala::Collection::Map.empty
  topics = @zk_client.all_topics
  assignments = ScalaEnumerable.new(@zk_client.replica_assignment_for_topics(topics))
  assignments.each do |item|
    topic_partition = item.first
    replicas = item.last
    if replicas.contains?(@old_leader)
      index = replicas.index_of(@old_leader)
      new_replicas = replicas.updated(index, @new_leader, CanBuildFrom)
      plan += Scala::Tuple.new(topic_partition, new_replicas)
    end
  end
  plan
end