Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup optional broker configuration #100

Merged
merged 1 commit into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .kitchen.docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ provisioner:
md5_checksum: <%= ENV.fetch('KAFKA_MD5', '').inspect %>
ulimit_file: 128000
broker:
broker.id: 1
controlled.shutdown.enable: <%= ENV.fetch('KAFKA_CTRL_SHUTDOWN', false) %>
log.dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
broker:
id: 1
controlled:
shutdown:
enable: <%= ENV.fetch('KAFKA_CTRL_SHUTDOWN', false) %>
log:
dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
zookeeper.connect: ['localhost:2181']
log4j:
appenders:
Expand Down
12 changes: 8 additions & 4 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ provisioner:
md5_checksum: <%= ENV.fetch('KAFKA_MD5', '').inspect %>
ulimit_file: 128000
broker:
broker.id: 1
controlled.shutdown.enable: <%= ENV.fetch('KAFKA_CTRL_SHUTDOWN', false) %>
log.dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
zookeeper.connect: ['localhost:2181']
broker:
id: 1
controlled:
shutdown:
enable: <%= ENV.fetch('KAFKA_CTRL_SHUTDOWN', false) %>
log:
dirs: ['/mnt/kafka-logs-1', '/mnt/kafka-logs-2']
zookeeper_connect: ['localhost:2181']
log4j:
appenders:
zookeeperAppender:
Expand Down
13 changes: 13 additions & 0 deletions libraries/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@

module Kafka
module Configuration
def render_option?(value)
case value
when Hash
value.values.all? do |v|
render_option?(v)
end
when Array
!value.empty?
else
!value.nil?
end
end

def render_option(prefix, value)
prefix = convert_key(prefix)
case value
Expand Down
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def broker_attribute?(*parts)
end
key = parts.pop
r = parts.reduce(broker) { |b, p| b.fetch(p, b) }
r.fetch(key, nil)
r.attribute?(key)
end

def fetch_broker_attribute(*parts)
Expand Down
4 changes: 2 additions & 2 deletions spec/recipes/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@

context 'when set to `nil`' do
let :broker_attributes do
{broker_id: nil}
{broker: {id: nil}}
end

it 'does not override it' do
expect(node.kafka.broker.broker_id).to be_nil
expect(node.kafka.broker['broker']['id']).to be_nil
end
end

Expand Down
2 changes: 1 addition & 1 deletion templates/default/server.properties.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Local modifications will be overwritten.

<% @config.each do |key, value| %>
<% unless value.nil? %>
<% if render_option?(value) %>
<%= render_option(key, value) %>
<% end %>
<% end %>