diff --git a/manifests/messaging.pp b/manifests/messaging.pp index ffb95ac7..3d038a73 100644 --- a/manifests/messaging.pp +++ b/manifests/messaging.pp @@ -32,6 +32,17 @@ # Could be set to 'disk' or 'ram'. # Defaults to 'disc' # +# [*cluster_count*] +# (optional) Queue is mirrored to count nodes in the cluster. +# If there are less than count nodes in the cluster, the queue +# is mirrored to all nodes. If there are more than count nodes +# in the cluster, and a node containing a mirror goes down, +# then a new mirror will be created on another node. +# If a value is set, RabbitMQ policy will be 'exactly'. +# Otherwise, undef will set the policy to 'all' by default. +# To enable this feature, you need 'haproxy_binding' to true. +# Defaults to undef +# # [*haproxy_binding*] # (optional) Enable or not HAproxy binding for load-balancing. # Defaults to false @@ -58,6 +69,7 @@ class cloud::messaging( $erlang_cookie, $cluster_node_type = 'disc', + $cluster_count = undef, $rabbit_names = $::hostname, $rabbit_password = 'rabbitpassword', $haproxy_binding = false, @@ -140,6 +152,24 @@ class cloud::messaging( } if $haproxy_binding { + + if $cluster_count { + $policy_name = "ha-exactly-${cluster_count}@/" + $definition = { + 'ha-mode' => 'exactly', + 'ha-params' => $cluster_count, + } + } else { + $policy_name = 'ha-all@/' + $definition = { + 'ha-mode' => 'all', + } + } + rabbitmq_policy { $policy_name: + pattern => '^(?!amq\.).*', + definition => $definition, + } + @@haproxy::balancermember{"${::fqdn}-rabbitmq": listening_service => 'rabbitmq_cluster', server_names => $::hostname, diff --git a/spec/classes/cloud_messaging_spec.rb b/spec/classes/cloud_messaging_spec.rb index 4f370cd8..42b58572 100644 --- a/spec/classes/cloud_messaging_spec.rb +++ b/spec/classes/cloud_messaging_spec.rb @@ -29,6 +29,7 @@ describe 'cloud::messaging' do :rabbit_password => 'secrete', :erlang_cookie => 'MY_COOKIE', :rabbitmq_ip => '10.0.0.1', + :haproxy_binding => false, } end @@ -90,6 +91,43 @@ describe 'cloud::messaging' do ) end end + + context 'with HAproxy binding and HA policy to exactly' do + before :each do + params.merge!( + :haproxy_binding => true, + :cluster_count => 3, + ) + end + + it 'configure ha-exactly rabbitmq_policy' do + is_expected.to contain_rabbitmq_policy('ha-exactly-3@/').with( + :pattern => '^(?!amq\.).*', + :definition => { + 'ha-mode' => 'exactly', + 'ha-params' => 3, + }, + ) + end + end + + context 'with HAproxy binding and HA policy to all' do + before :each do + params.merge!( + :haproxy_binding => true, + ) + end + + it 'configure ha-exactly rabbitmq_policy' do + is_expected.to contain_rabbitmq_policy('ha-all@/').with( + :pattern => '^(?!amq\.).*', + :definition => { + 'ha-mode' => 'all', + }, + ) + end + end + end context 'on Debian platforms' do