Skip to content

Commit

Permalink
Merge branch 'optional-broker-configuration-fixup'
Browse files Browse the repository at this point in the history
  • Loading branch information
mthssdrbrg committed May 9, 2016
2 parents 4fc90f4 + 80c7f71 commit a747369
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
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 %>

0 comments on commit a747369

Please sign in to comment.