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

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

Overview

Controller responsible for management of topics configs

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

#edit(topic_name, property_name) ⇒ Object

Allows for editing of a particular configuration setting To simplify things we do not allow for batch editing of multiple parameters

Parameters:

  • topic_name (String)
  • property_name (String)

Raises:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/karafka/web/pro/ui/controllers/topics/configs_controller.rb', line 37

def edit(topic_name, property_name)
  features.topics_management!

  # This will load all the configs so we can validate that a requested config exists
  # and we can get its current value for the form
  index(topic_name)

  @property = @configs.find { |config| config.name == property_name }

  raise(Errors::Ui::NotFoundError) unless @property
  raise(Errors::Ui::ForbiddenError) if @property.read_only?

  render
end

#index(topic_name) ⇒ Object

Displays requested topic config details

Parameters:

  • topic_name (String)

    topic we’re interested in



25
26
27
28
29
30
31
# File 'lib/karafka/web/pro/ui/controllers/topics/configs_controller.rb', line 25

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

  @configs = refine(@topic.configs)

  render
end

#update(topic_name, property_name) ⇒ Object

Tries to apply config change on a topic and either returns the error info or redirects if changed

Parameters:

  • topic_name (String)
  • property_name (String)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/karafka/web/pro/ui/controllers/topics/configs_controller.rb', line 56

def update(topic_name, property_name)
  edit(topic_name, property_name)

  property_value = params[:property_value]

  begin
    resource = Karafka::Admin::Configs::Resource.new(type: :topic, name: topic_name)
    resource.set(property_name, property_value)
    Karafka::Admin::Configs.alter(resource)
  rescue Rdkafka::RdkafkaError => e
    @form_error = e
  end

  return edit(topic_name, property_name) if @form_error

  redirect(
    "topics/#{topic_name}/config",
    success: format_flash(
      'Topic ? property ? successfully altered',
      topic_name,
      property_name
    )
  )
end