Class: Karafka::Web::Pro::Ui::Controllers::Topics::TopicsController

Inherits:
BaseController show all
Defined in:
lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb

Overview

The primary controller for topics listing and creation / removal

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Attribute Summary

Attributes inherited from Ui::Controllers::BaseController

#params, #session

Instance Method Summary collapse

Methods inherited from Ui::Controllers::BaseController

#cache, #initialize

Methods included from Ui::Controllers::Requests::Hookable

included, #run_after_hooks, #run_before_hooks

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#createObject

Note:

Upon creation we do not redirect to the topic config page because it may take a topic a moment to be fully available in the cluster. We “buy” ourselves this time by redirecting user back to the topics list

Creates topic and redirects on success



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 41

def create
  features.topics_management!

  begin
    Karafka::Admin.create_topic(
      params[:topic_name],
      params.int(:partitions_count),
      params.int(:replication_factor)
    )
  rescue Rdkafka::RdkafkaError => e
    @form_error = e
  end

  return new if @form_error

  redirect(
    'topics',
    success: format_flash(
      'Topic ? successfully created',
      params[:topic_name]
    )
  )
end

#delete(topic_name) ⇒ Object

Deletes the requested topic

Parameters:

  • topic_name (String)

    name of the topic we want to remove



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 80

def delete(topic_name)
  features.topics_management!

  edit(topic_name)

  Karafka::Admin.delete_topic(topic_name)

  redirect(
    'topics',
    success: format_flash(
      'Topic ? successfully deleted',
      topic_name
    )
  )
end

#edit(topic_name) ⇒ Object

Renders a confirmation page for topic removal since it is a sensitive operation

Parameters:

  • topic_name (String)


68
69
70
71
72
73
74
75
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 68

def edit(topic_name)
  features.topics_management!

  @topic = Models::Topic.find(topic_name)
  @topic_name = topic_name

  render
end

#indexObject

Displays list of topics we can work with



19
20
21
22
23
24
25
26
27
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 19

def index
  @topics = Models::Topic.all.sort_by(&:topic_name)

  unless ::Karafka::Web.config.ui.visibility.internal_topics
    @topics.delete_if { |topic| topic[:topic_name].start_with?('__') }
  end

  render
end

#newObject

Renders form for creating a new topic with basic details like number of partitions and the replication factor



31
32
33
34
35
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 31

def new
  features.topics_management!

  render
end