Class: Karafka::Cli::Topics::Align

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/cli/topics/align.rb

Overview

Note:

This command does NOT repartition and does NOT create new topics. It only aligns configuration of existing topics.

Aligns configuration of all the declarative topics that exist based on the declarative topics definitions.

Takes into consideration already existing settings, so will only align what is needed.

Keep in mind, this is NOT transactional. Kafka topic changes are not transactional so it is highly recommended to test it before running in prod.

Instance Method Summary collapse

Methods included from Helpers::Colorize

#green, #grey, #red, #yellow

Instance Method Details

#callBoolean

Returns true if there were any changes applied, otherwise false.

Returns:

  • (Boolean)

    true if there were any changes applied, otherwise false



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/karafka/cli/topics/align.rb', line 18

def call
  if candidate_topics.empty?
    puts "#{yellow('Skipping')} because no declarative topics exist."

    return false
  end

  resources_to_migrate = build_resources_to_migrate

  if resources_to_migrate.empty?
    puts "#{yellow('Skipping')} because there are no configurations to align."

    return false
  end

  names = resources_to_migrate.map(&:name).join(', ')
  puts "Updating configuration of the following topics: #{names}"
  Karafka::Admin::Configs.alter(resources_to_migrate)
  puts "#{green('Updated')} all requested topics configuration."

  true
end