Class: Karafka::Cli::Topics::Plan

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

Overview

Plans the migration process and prints what changes are going to be applied if migration would to be executed

Instance Method Summary collapse

Methods included from Helpers::Colorize

#green, #grey, #red, #yellow

Instance Method Details

#callBoolean

Figures out scope of changes that need to happen

Returns:

  • (Boolean)

    true if running migrate would change anything, false otherwise



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/karafka/cli/topics/plan.rb', line 11

def call
  # If no changes at all, just print and stop
  if topics_to_create.empty? && topics_to_repartition.empty? && topics_to_alter.empty?
    puts "Karafka will #{yellow('not')} perform any actions. No changes needed."

    return false
  end

  unless topics_to_create.empty?
    puts 'Following topics will be created:'
    puts

    topics_to_create.each do |topic|
      puts "  #{green('+')} #{topic.name}:"
      puts "    #{green('+')} partitions: \"#{topic.declaratives.partitions}\""

      topic.declaratives.details.each do |name, value|
        puts "    #{green('+')} #{name}: \"#{value}\""
      end

      puts
    end
  end

  unless topics_to_repartition.empty?
    puts 'Following topics will be repartitioned:'
    puts

    topics_to_repartition.each do |topic, partitions|
      from = partitions
      to = topic.declaratives.partitions

      puts "  #{yellow('~')} #{topic.name}:"
      puts "    #{yellow('~')} partitions: \"#{red(from)}\" #{grey('=>')} \"#{green(to)}\""
      puts
    end
  end

  unless topics_to_alter.empty?
    puts 'Following topics will have configuration changes:'
    puts

    topics_to_alter.each do |topic, configs|
      puts "  #{yellow('~')} #{topic.name}:"

      configs.each do |name, changes|
        from = changes.fetch(:from)
        to = changes.fetch(:to)
        action = changes.fetch(:action)
        type = action == :change ? yellow('~') : green('+')
        puts "    #{type} #{name}: \"#{red(from)}\" #{grey('=>')} \"#{green(to)}\""
      end

      puts
    end
  end

  true
end