Chef recipe for hazelcast cluster

Hello guys and girls,

Because the hazelcast recipe I’ve found in the supermarket was much too complicated for what I needed I rewrote it.
The problem I have now is that when I need to create a hazecast cluster from 2-N machines, I simply cannot think of a solution that will deploy hazelcast and create config on all these machines, each machine having in the config the IPs of all the machines from the cluster (as it should).

So the first thing I thought of was to have an attribute file like:

default['cluster']['iscluster'] = true
default['cluster']['clusteredips'] = ['192.168.10.70','192.168.10.71']

and for each cluster from every environment I should change the clusteredips attribute to match the IPs for the machines of that cluster on that environment. As you can see, this is not the best way, because I have to modify the attribute file every time I create a new cluster.

The second thing I thought of was to store clusteredips attribute in the environment file as I have a cluster for each environment… for now… but if that changes, I have a big problem… and there’s the problem.

The last thing I thought of (and it would have been the most useful thing) was that I should have clusteredips as attribute on each hazelcast node, and that would have solved a second problem… that if a machines is not part of a cluster, but is part of an environment which also has a hazelcast cluster, that machine would have in the config only one IP. But that it’s not working since I cannot store attributes in the node’s json.

Is there a better solution? Is there someone that had the same problem and found another solution that works?

Thank you.

Gabriel

I typically use search via role/recipe to get an array of hashes.

in your recipe:

cluster_members = search('node', "chef_environment:#{node.chef_environment} AND role:<your_hazelcast_role>")

template '/path/to/config' do
  variables :cluster_members => cluster_members
  <source, owner, foo...>
end      

from there, you can manipulate the array inside your template however you want. i.e.

<% cluster_members.each do |member| %>
Members [5] {
   Member [<%= member['ipaddress'] %>:5701]
}
<% end %>

this is also great because chef will scale the template up/down any time you add/remove a node with a matching recipe/role.

edit: altered the template info after finding a sample hazelcast config to hopefully make a bit more sense.

Great ideea.
Thank you.
Gabriel

The problem is still not solved.
In the recipe I have

cluster_members = search('node', "chef_environment:#{node.chef_environment} AND role:hazelcast")

But I might have in the same environment a node that will have a single instance of hazelcast and another two that will be in a cluster.

Let’s say I have an environment called QA and 3 nodes:
cache01
cache02
cache03

cache01 will need to have hazelcast non clustered and cache02 and 03 form a hazelcast cluster.

How do you deal with that problem?
Thank you,
Gabriel

Hi, from what I see, inside the template, cluster_members variable doesn’t
have @.

To separate clusters that live in the same chef environment, you could just
give each cluster a name. That name can be passed in at bootstrap via
first_boot.json or as an attribute that lives in a role.

I suppose you could also use one data_bag per env, with each cluster as a
data_bag item.

if you have multiple nodes in the same environment running the same app but in different ways (clustered vs non-clustered, leader vs follower, etc etc), I would recommend using two distinct roles. That would be the easiest and cleanest that I can see. They could, potentially, run the exact same recipe(s) and only be separated to match or not match search results, if that’s the only difference you need.

In the end I decided that I should split the hazelcast recipe in two recipes (because I needed to have another map in the hazelcast.xml which was not applying to all nodes) instead of using a condition which would have complicated my life.
Then I’ve created two roles (one for each recipe) and then I’ve used environments attributes for each recipe (clustered (yes/no) and clusteredIPs (where cluster=true)).

Thank you all for your help.
Gabriel