Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Update to add an instance_id attribute. #26

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion libraries/zookeeper_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ZookeeperConfig < Chef::Resource
attribute(:group, kind_of: String, default: 'zookeeper')

attribute(:instance_name, kind_of: String, required: true)
attribute(:instance_id, kind_of: Integer, required: false)
attribute(:data_dir, kind_of: String, default: '/var/lib/zookeeper')
attribute(:client_port, kind_of: Integer, default: 2181)
attribute(:leader_port, kind_of: Integer, default: 2888)
Expand All @@ -34,7 +35,11 @@ class ZookeeperConfig < Chef::Resource
attribute(:properties, option_collector: true, default: {})

def myid
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would implement this slightly differently. I would set the default value of the instance_id attribute to be the index of the element in the ensemble array. After that we simply add an alias to the method so that #myid keeps on working.

attribute(:instance_id, kind_of: Integer, default: lazy { ensemble.index(instance_name).next.to_s })
alias_method :myid, :instance_id

ensemble.index(instance_name).next.to_s
if instance_id != nil
instance_id.to_s
else
ensemble.index(instance_name).next.to_s
end
end

# Outputs the +properties+ in the Java Properties file format. This is
Expand Down