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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 66

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



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 105

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)


93
94
95
96
97
98
99
100
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 93

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



44
45
46
47
48
49
50
51
52
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 44

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



56
57
58
59
60
# File 'lib/karafka/web/pro/ui/controllers/topics/topics_controller.rb', line 56

def new
  features.topics_management!

  render
end