bbaugher / apache_zookeeper

Chef cookbook for Apache Zookeeper
MIT License
9 stars 22 forks source link

Use chef search to discover zookeepers #12

Closed bbaugher closed 9 years ago

TD-4242 commented 10 years ago

I started working on this a bit so I could deploy to AWS. I added this code to the library:

# role based search to assign zookeper servers.  Inside the role set the zookeeper->role_group attribute
# most likely to the name of the role, otherwise the role can be empty.
if node["zookeeper"]["role_group"]
  keepers = search(:node, "role:#{node["zookeeper"]["role_group"]}")
  # sort to keep the search output consistant
  keepers.sort!{|x, y| x[:fqdn] <=> y[:fqdn]}
  keepers.each do |m|
    node.default["zookeeper"]["servers"].push( m[:fqdn] )
  end
end

which worked with nodes already joined to chef but it breaks at bootstrap due to, I think, the node index not being quite real time. it also doesn't work until the next chef pass anyway as it will only have the number of nodes that have started up so far.

I'll be poking around on it until I get something that will work. Let me know if you have any ideas.

bbaugher commented 10 years ago

Yes I have thought about this for a couple other services which require the same integer id per host config. The only comments I have for your implementation are,

Ultimately this solution is still not great since sorting by FQDN means ids can change as nodes are added/removed. Though this was pretty much exactly what I was thinking when I logged this.

bbaugher commented 9 years ago

Decided not to do this since I currently can't think of a good implementation. Feel free to re-open if you think you have something or create a pull