Class: Karafka::Web::Pro::Ui::Controllers::Topics::TopicsController
- Inherits:
-
BaseController
- Object
- Ui::Controllers::BaseController
- 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
Constant Summary
Constants inherited from Ui::Controllers::BaseController
Ui::Controllers::BaseController::Models
Instance Attribute Summary
Attributes inherited from Ui::Controllers::BaseController
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.
Methods inherited from Ui::Controllers::BaseController
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
#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
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
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
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 |
#index ⇒ Object
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 |
#new ⇒ Object
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 |