Class: Karafka::Web::Pro::Ui::Controllers::Topics::TopicsController
- Inherits:
-
BaseController
- Object
- Controllers::BaseController
- BaseController
- Karafka::Web::Pro::Ui::Controllers::Topics::TopicsController
- 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
-
#create ⇒ Object
Creates topic and redirects on success.
-
#delete(topic_name) ⇒ Object
Deletes the requested topic.
-
#edit(topic_name) ⇒ Object
Renders a confirmation page for topic removal since it is a sensitive operation.
-
#index ⇒ Object
Displays list of topics we can work with.
-
#new ⇒ Object
Renders form for creating a new topic with basic details like number of partitions and the replication factor.
Instance Method Details
#create ⇒ Object
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
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
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 |
#index ⇒ Object
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 |
#new ⇒ Object
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 |