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

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

Overview

The primary controller for topics listing and creation / removal

Instance Method Summary collapse

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



72
73
74
75
76
77
78
79
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 72

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 111

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)


99
100
101
102
103
104
105
106
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 99

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



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 48

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

  @topics = filter(@topics)

  render
end

#newObject

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



62
63
64
65
66
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 62

def new
  features.topics_management!

  render
end