Class: KafkaCommand::TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/kafka_command/topics_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /clusters/:cluster_id/topics



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/kafka_command/topics_controller.rb', line 59

def create
  @cluster = Cluster.find(params[:cluster_id])
  @topic = @cluster.create_topic(
    params[:name],
    num_partitions: params[:num_partitions].to_i,
    replication_factor: params[:replication_factor].to_i,
    config: build_config
  )

  render_success(
    @topic,
    status: :created,
    redirection_path: cluster_topics_path,
    flash: { success: 'Topic created' },
    include_config: true
  )
end

#destroyObject

DELETE /clusters/:cluster_id/topics/:id



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/kafka_command/topics_controller.rb', line 104

def destroy
  @cluster = Cluster.find(params[:cluster_id])
  @topic = @cluster.topics.find { |t| t.name == params[:id] }

  if @topic.nil?
    render_error('Topic not found', status: 404)
  else
    @topic.destroy
    render_success(
      @topic,
      status: :no_content,
      redirection_path: cluster_topics_path,
      flash: { success: "Topic \"#{@topic.name}\" is marked for deletion. <strong>Note: This will have no impact if delete.topic.enable is not set to true.</strong>".html_safe }
    )
  end
end

#editObject

GET /clusters/:cluster_id/topics/edit



52
53
54
55
56
# File 'app/controllers/kafka_command/topics_controller.rb', line 52

def edit
  @cluster = Cluster.find(params[:cluster_id])
  @topic = @cluster.topics.find { |t| t.name == params[:id] }
  @redirect_path = params[:redirect_path]
end

#indexObject

GET /clusters/:cluster_id/topics



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/kafka_command/topics_controller.rb', line 18

def index
  @cluster = Cluster.find(params[:cluster_id])
  @topics = @cluster.topics

  flash[:search] = params[:name]

  if params[:name].present?
    @topics = @topics.select do |t|
      regex = /#{params[:name]}/i
      t.name.match?(regex)
    end
  end

  render_success(@topics)
end

#newObject

GET /clusters/:cluster_id/topics/new



47
48
49
# File 'app/controllers/kafka_command/topics_controller.rb', line 47

def new
  @cluster = Cluster.find(params[:cluster_id])
end

#showObject

GET /clusters/:cluster_id/topics/:id



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/kafka_command/topics_controller.rb', line 35

def show
  @cluster = Cluster.find(params[:cluster_id])
  @topic = @cluster.topics.find { |t| t.name == params[:id] }

  if @topic.nil?
    render_error('Topic not found', status: 404)
  else
    render_success(@topic, include_config: true)
  end
end

#updateObject

PATCH/PUT /clusters/:cluster_id/topics/:id



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/kafka_command/topics_controller.rb', line 78

def update
  cluster = Cluster.find(params[:cluster_id])
  @topic = cluster.topics.find { |t| t.name == params[:id] }

  render_error('Topic not found', status: 404) && (return) if @topic.nil?
  if params[:num_partitions]
    @topic.set_partitions!(params[:num_partitions].to_i) unless params[:num_partitions].to_i == @topic.partitions.count
  end

  if build_config.present?
    @topic.set_configs!(
      max_message_bytes: params[:max_message_bytes],
      retention_ms: params[:retention_ms],
      retention_bytes: params[:retention_bytes]
    )
  end

  render_success(
    @topic,
    status: :ok,
    redirection_path: params[:redirect_path] || cluster_topics_path,
    flash: { success: 'Topic updated' }
  )
end