diff --git a/chef/cookbooks/ceilometer/recipes/central_ha.rb b/chef/cookbooks/ceilometer/recipes/central_ha.rb index a6fd851e8d..0ba2451046 100644 --- a/chef/cookbooks/ceilometer/recipes/central_ha.rb +++ b/chef/cookbooks/ceilometer/recipes/central_ha.rb @@ -21,6 +21,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-ceilometer_central_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] service_name = "ceilometer-central" @@ -43,7 +44,7 @@ end crowbar_pacemaker_order_only_existing "o-#{service_name}" do - ordering ["rabbitmq", "cl-keystone", service_name] + ordering ["#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", service_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/ceilometer/recipes/server_ha.rb b/chef/cookbooks/ceilometer/recipes/server_ha.rb index 7416891ebf..1361c016f5 100644 --- a/chef/cookbooks/ceilometer/recipes/server_ha.rb +++ b/chef/cookbooks/ceilometer/recipes/server_ha.rb @@ -29,6 +29,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-ceilometer_server_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] primitives = [] @@ -66,7 +67,7 @@ end transaction_objects << "pacemaker_clone[#{clone_name}]" -order_only_existing = ["rabbitmq", "cl-keystone", clone_name] +order_only_existing = ["#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", clone_name] if node[:ceilometer][:use_mongodb] pacemaker_order "o-ceilometer-mongo" do diff --git a/chef/cookbooks/ceilometer/templates/default/ceilometer.conf.erb b/chef/cookbooks/ceilometer/templates/default/ceilometer.conf.erb index 05c9228b80..34b3101d46 100644 --- a/chef/cookbooks/ceilometer/templates/default/ceilometer.conf.erb +++ b/chef/cookbooks/ceilometer/templates/default/ceilometer.conf.erb @@ -277,7 +277,11 @@ use_stderr = false # A URL representing the messaging driver to use and its full # configuration. If not set, we fall back to the rpc_backend option # and driver specific configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) @@ -1168,7 +1172,11 @@ lock_path = /var/run/ceilometer # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1269,7 +1277,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this # option, you must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down # if heartbeat's keep-alive fails (0 disable the heartbeat). diff --git a/chef/cookbooks/cinder/recipes/controller_ha.rb b/chef/cookbooks/cinder/recipes/controller_ha.rb index 70ca1bc31c..e6ef344401 100644 --- a/chef/cookbooks/cinder/recipes/controller_ha.rb +++ b/chef/cookbooks/cinder/recipes/controller_ha.rb @@ -41,6 +41,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-cinder_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] api_primitive = "cinder-api" @@ -92,7 +93,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/cinder/templates/default/cinder.conf.erb b/chef/cookbooks/cinder/templates/default/cinder.conf.erb index 987ee2d965..f4bf7a198f 100644 --- a/chef/cookbooks/cinder/templates/default/cinder.conf.erb +++ b/chef/cookbooks/cinder/templates/default/cinder.conf.erb @@ -2689,7 +2689,11 @@ rpc_response_timeout = <%= node[:cinder][:rpc_response_timeout] %> # A URL representing the messaging driver to use and its full configuration. If # not set, we fall back to the rpc_backend option and driver specific # configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers include qpid # and zmq. (string value) @@ -3464,7 +3468,11 @@ lock_path = /var/run/cinder # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -3562,7 +3570,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this option, you # must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down if # heartbeat's keep-alive fails (0 disable the heartbeat). EXPERIMENTAL (integer diff --git a/chef/cookbooks/crowbar-openstack/libraries/helpers.rb b/chef/cookbooks/crowbar-openstack/libraries/helpers.rb index c748b2aa56..bc19182bd3 100644 --- a/chef/cookbooks/crowbar-openstack/libraries/helpers.rb +++ b/chef/cookbooks/crowbar-openstack/libraries/helpers.rb @@ -109,27 +109,65 @@ def self.rabbitmq_settings(node, barclamp) end if @rabbitmq_settings && @rabbitmq_settings.include?(instance) - Chef::Log.info("RabbitMQ server found at #{@rabbitmq_settings[instance][:address]} [cached]") + Chef::Log.info("RabbitMQ settings found [cached]") else @rabbitmq_settings ||= Hash.new - rabbit = get_node(node, "rabbitmq-server", "rabbitmq", instance) + rabbits = get_nodes(node, "rabbitmq-server", "rabbitmq", instance) - if rabbit.nil? + if rabbits.empty? Chef::Log.warn("No RabbitMQ server found!") else - @rabbitmq_settings[instance] = { - address: rabbit[:rabbitmq][:address], - port: rabbit[:rabbitmq][:port], - user: rabbit[:rabbitmq][:user], - password: rabbit[:rabbitmq][:password], - vhost: rabbit[:rabbitmq][:vhost], - url: "rabbit://#{rabbit[:rabbitmq][:user]}:" \ + one_rabbit = rabbits.first + + if one_rabbit[:rabbitmq][:cluster] + rabbit_hosts = rabbits.map do |rabbit| + port = rabbit[:rabbitmq][:port] + + "#{rabbit[:rabbitmq][:user]}:" \ "#{rabbit[:rabbitmq][:password]}@" \ - "#{rabbit[:rabbitmq][:address]}:#{rabbit[:rabbitmq][:port]}/" \ - "#{rabbit[:rabbitmq][:vhost]}" - } + "#{rabbit[:rabbitmq][:address]}:#{port}" + end + + rabbit_node_names = rabbits.map do |rabbit_node| + "\'rabbit@#{rabbit_node.name}\'" + end + + cluster_nodes = rabbit_node_names.join(",") + + @rabbitmq_settings[instance] = { + clustered: true, + ha_queues: true, + durable_queues: true, + use_legacy_configuration: false, + url: "rabbit://#{rabbit_hosts.sort.join(",")}/" \ + "#{one_rabbit[:rabbitmq][:vhost]}", + pacemaker_resource: "ms-rabbitmq", + cluster_nodes: cluster_nodes + } + Chef::Log.info("RabbitMQ cluster found") + else + rabbit = one_rabbit + port = rabbit[:rabbitmq][:port] + + @rabbitmq_settings[instance] = { + clustered: false, + ha_queues: false, + durable_queues: false, + use_legacy_configuration: true, + address: rabbit[:rabbitmq][:address], + port: rabbit[:rabbitmq][:port], + user: rabbit[:rabbitmq][:user], + password: rabbit[:rabbitmq][:password], + vhost: rabbit[:rabbitmq][:vhost], + url: "rabbit://#{rabbit[:rabbitmq][:user]}:" \ + "#{rabbit[:rabbitmq][:password]}@" \ + "#{rabbit[:rabbitmq][:address]}:#{port}/" \ + "#{rabbit[:rabbitmq][:vhost]}", + pacemaker_resource: "rabbitmq" + } - Chef::Log.info("RabbitMQ server found at #{@rabbitmq_settings[instance][:address]}") + Chef::Log.info("RabbitMQ server found") + end end end @@ -153,4 +191,9 @@ def self.get_node(node, role, barclamp, instance) result end + + def self.get_nodes(node, role, barclamp, instance) + nodes, _, _ = Chef::Search::Query.new.search(:node, "roles:#{role} AND #{barclamp}_config_environment:#{barclamp}-config-#{instance}") + nodes + end end diff --git a/chef/cookbooks/glance/recipes/ha.rb b/chef/cookbooks/glance/recipes/ha.rb index 529568cee1..1fce139020 100644 --- a/chef/cookbooks/glance/recipes/ha.rb +++ b/chef/cookbooks/glance/recipes/ha.rb @@ -47,6 +47,7 @@ crowbar_pacemaker_sync_mark "wait-glance_ha_resources" primitives = [] +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] ["registry", "api"].each do |service| @@ -94,7 +95,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/glance/templates/default/glance-api.conf.erb b/chef/cookbooks/glance/templates/default/glance-api.conf.erb index 239f64e744..ea78afe4d7 100644 --- a/chef/cookbooks/glance/templates/default/glance-api.conf.erb +++ b/chef/cookbooks/glance/templates/default/glance-api.conf.erb @@ -522,7 +522,11 @@ notification_driver = messaging # A URL representing the messaging driver to use and its full # configuration. If not set, we fall back to the rpc_backend option # and driver specific configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) @@ -1389,7 +1393,11 @@ lock_path = /var/run/glance # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1493,7 +1501,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this # option, you must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down # if heartbeat's keep-alive fails (0 disable the heartbeat). diff --git a/chef/cookbooks/glance/templates/default/glance-registry.conf.erb b/chef/cookbooks/glance/templates/default/glance-registry.conf.erb index 4d32722c56..122c7b24f7 100644 --- a/chef/cookbooks/glance/templates/default/glance-registry.conf.erb +++ b/chef/cookbooks/glance/templates/default/glance-registry.conf.erb @@ -336,7 +336,11 @@ notification_driver = messaging # A URL representing the messaging driver to use and its full # configuration. If not set, we fall back to the rpc_backend option # and driver specific configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) @@ -1123,7 +1127,11 @@ admin_tenant_name = <%= @keystone_settings['service_tenant'] %> # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1227,7 +1235,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this # option, you must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down # if heartbeat's keep-alive fails (0 disable the heartbeat). diff --git a/chef/cookbooks/heat/recipes/ha.rb b/chef/cookbooks/heat/recipes/ha.rb index d8508765c6..7cb4e6c85e 100644 --- a/chef/cookbooks/heat/recipes/ha.rb +++ b/chef/cookbooks/heat/recipes/ha.rb @@ -46,6 +46,7 @@ crowbar_pacemaker_sync_mark "wait-heat_ha_resources" primitives = [] +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] ["engine", "api", "api_cfn", "api_cloudwatch"].each do |service| @@ -92,7 +93,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", "cl-g-nova-controller", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", "cl-g-nova-controller", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/heat/templates/default/heat.conf.erb b/chef/cookbooks/heat/templates/default/heat.conf.erb index f09dc63850..10f481476e 100644 --- a/chef/cookbooks/heat/templates/default/heat.conf.erb +++ b/chef/cookbooks/heat/templates/default/heat.conf.erb @@ -395,7 +395,11 @@ use_stderr=false # A URL representing the messaging driver to use and its full configuration. If # not set, we fall back to the rpc_backend option and driver specific # configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers include qpid # and zmq. (string value) @@ -1396,7 +1400,11 @@ admin_tenant_name=<%= @keystone_settings['service_tenant'] %> # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1492,7 +1500,11 @@ rabbit_virtual_host=<%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this option, you # must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down if # heartbeat's keep-alive fails (0 disable the heartbeat). EXPERIMENTAL (integer diff --git a/chef/cookbooks/keystone/recipes/ha.rb b/chef/cookbooks/keystone/recipes/ha.rb index 37cb0b3293..49434aab92 100644 --- a/chef/cookbooks/keystone/recipes/ha.rb +++ b/chef/cookbooks/keystone/recipes/ha.rb @@ -44,6 +44,7 @@ # then we will avoid races there too as pacemaker will start the service). crowbar_pacemaker_sync_mark "wait-keystone_ha_resources" + rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] service_name = "keystone" @@ -85,7 +86,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/keystone/templates/default/keystone.conf.erb b/chef/cookbooks/keystone/templates/default/keystone.conf.erb index 0d0df70d5d..e3c3b3a201 100644 --- a/chef/cookbooks/keystone/templates/default/keystone.conf.erb +++ b/chef/cookbooks/keystone/templates/default/keystone.conf.erb @@ -246,7 +246,11 @@ use_syslog = <%= @use_syslog ? "True" : "False" %> # A URL representing the messaging driver to use and its full configuration. If # not set, we fall back to the rpc_backend option and driver specific # configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers include qpid # and zmq. (string value) @@ -1594,7 +1598,11 @@ use_pool = <%= node[:keystone][:ldap][:use_pool] %> # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1690,7 +1698,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this option, you # must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down if # heartbeat's keep-alive fails (0 disable the heartbeat). EXPERIMENTAL (integer diff --git a/chef/cookbooks/manila/recipes/controller_ha.rb b/chef/cookbooks/manila/recipes/controller_ha.rb index 80e3be0153..b8c683aee0 100644 --- a/chef/cookbooks/manila/recipes/controller_ha.rb +++ b/chef/cookbooks/manila/recipes/controller_ha.rb @@ -47,6 +47,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-manila_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] api_primitive = "manila-api" @@ -98,7 +99,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", "cl-glance", "cl-cinder", + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", "cl-glance", "cl-cinder", "cl-neutron", "cl-nova", clone_name] score "Optional" action :create diff --git a/chef/cookbooks/manila/templates/default/manila.conf.erb b/chef/cookbooks/manila/templates/default/manila.conf.erb index d57eb3e9cf..aa32556326 100644 --- a/chef/cookbooks/manila/templates/default/manila.conf.erb +++ b/chef/cookbooks/manila/templates/default/manila.conf.erb @@ -1315,7 +1315,11 @@ use_stderr = false # A URL representing the messaging driver to use and its full # configuration. If not set, we fall back to the rpc_backend option # and driver specific configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers # include qpid and zmq. (string value) @@ -1878,7 +1882,11 @@ lock_path=/var/run/manila # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1981,7 +1989,11 @@ rabbit_virtual_host=<%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this # option, you must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down # if heartbeat's keep-alive fails (0 disable the heartbeat). diff --git a/chef/cookbooks/neutron/recipes/network_agents_ha.rb b/chef/cookbooks/neutron/recipes/network_agents_ha.rb index 1959f62523..388529eba8 100644 --- a/chef/cookbooks/neutron/recipes/network_agents_ha.rb +++ b/chef/cookbooks/neutron/recipes/network_agents_ha.rb @@ -232,6 +232,8 @@ only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } end + rabbit_settings = fetch_rabbitmq_settings + crowbar_pacemaker_order_only_existing "o-#{ha_tool_primitive_name}" do # While neutron-ha-tool technically doesn't directly depend on postgresql or # rabbitmq, if these bits are not running, then neutron-server can run but @@ -239,7 +241,7 @@ # constraint on these services, but it's optional, not mandatory (because it # doesn't need to be restarted when postgresql or rabbitmq are restarted). # So explicitly depend on postgresql and rabbitmq (if they are in the cluster). - ordering "( postgresql rabbitmq g-haproxy cl-neutron-server #{agents_clone_name} ) #{ha_tool_primitive_name}" + ordering "( postgresql #{rabbit_settings[:pacemaker_resource]} g-haproxy cl-neutron-server #{agents_clone_name} ) #{ha_tool_primitive_name}" score "Mandatory" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/neutron/recipes/server_ha.rb b/chef/cookbooks/neutron/recipes/server_ha.rb index 6f43bb0f59..f09e408250 100644 --- a/chef/cookbooks/neutron/recipes/server_ha.rb +++ b/chef/cookbooks/neutron/recipes/server_ha.rb @@ -29,6 +29,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-neutron_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] primitive_name = "neutron-server" @@ -63,7 +64,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/neutron/templates/default/neutron.conf.erb b/chef/cookbooks/neutron/templates/default/neutron.conf.erb index 28207f2ca2..f72306d406 100644 --- a/chef/cookbooks/neutron/templates/default/neutron.conf.erb +++ b/chef/cookbooks/neutron/templates/default/neutron.conf.erb @@ -613,7 +613,11 @@ notification_driver = neutron.openstack.common.notifier.rpc_notifier # A URL representing the messaging driver to use and its full # configuration. If not set, we fall back to the rpc_backend # option and driver specific configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> # transport_url= +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other # drivers include qpid and zmq. (string value) @@ -1014,7 +1018,11 @@ lock_path = /var/run/neutron # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> # amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -1102,7 +1110,11 @@ rabbit_virtual_host=<%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this option, you # must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> # rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Deprecated, use rpc_backend=kombu+memory or rpc_backend=fake (boolean value) # Deprecated group/name - [DEFAULT]/fake_rabbit diff --git a/chef/cookbooks/nova/recipes/compute_ha.rb b/chef/cookbooks/nova/recipes/compute_ha.rb index 097c7a4aa2..724c3d8ae0 100644 --- a/chef/cookbooks/nova/recipes/compute_ha.rb +++ b/chef/cookbooks/nova/recipes/compute_ha.rb @@ -290,6 +290,7 @@ end end +rabbit_settings = fetch_rabbitmq_settings crowbar_pacemaker_order_only_existing "o-#{evacuate_primitive}" do # We need services required to boot an instance; most of these services are # obviously required. Some additional notes: @@ -297,7 +298,7 @@ # - cinder is used in case of boot from volume # - neutron agents are used even with DVR, if only to have a DHCP server for # the instance to get an IP address - ordering "( postgresql rabbitmq cl-keystone cl-swift-proxy cl-g-glance cl-g-cinder-controller cl-neutron-server cl-g-neutron-agents cl-g-nova-controller ) #{evacuate_primitive}" + ordering "( postgresql #{rabbit_settings[:pacemaker_resource]} cl-keystone cl-swift-proxy cl-g-glance cl-g-cinder-controller cl-neutron-server cl-g-neutron-agents cl-g-nova-controller ) #{evacuate_primitive}" score "Mandatory" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/nova/recipes/controller_ha.rb b/chef/cookbooks/nova/recipes/controller_ha.rb index 3db73649da..9ed88a727c 100644 --- a/chef/cookbooks/nova/recipes/controller_ha.rb +++ b/chef/cookbooks/nova/recipes/controller_ha.rb @@ -83,6 +83,7 @@ # Avoid races when creating pacemaker resources crowbar_pacemaker_sync_mark "wait-nova_ha_resources" +rabbit_settings = fetch_rabbitmq_settings transaction_objects = [] primitives = [] @@ -143,7 +144,7 @@ end crowbar_pacemaker_order_only_existing "o-#{clone_name}" do - ordering ["postgresql", "rabbitmq", "cl-keystone", clone_name] + ordering ["postgresql", "#{rabbit_settings[:pacemaker_resource]}", "cl-keystone", clone_name] score "Optional" action :create only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } diff --git a/chef/cookbooks/nova/templates/default/nova.conf.erb b/chef/cookbooks/nova/templates/default/nova.conf.erb index 0c908f75fa..7735969aff 100644 --- a/chef/cookbooks/nova/templates/default/nova.conf.erb +++ b/chef/cookbooks/nova/templates/default/nova.conf.erb @@ -1500,7 +1500,11 @@ notification_driver = messaging # A URL representing the messaging driver to use and its full configuration. If # not set, we fall back to the rpc_backend option and driver specific # configuration. (string value) +<% if @rabbit_settings['use_legacy_configuration'] -%> #transport_url = +<% else -%> +transport_url = <%= @rabbit_settings[:url] %> +<% end -%> # The messaging driver to use, defaults to rabbit. Other drivers include qpid # and zmq. (string value) @@ -3191,7 +3195,11 @@ lock_path = /var/run/nova # Use durable queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_durable_queues # Deprecated group/name - [DEFAULT]/rabbit_durable_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #amqp_durable_queues = false +<% else -%> +amqp_durable_queues = <%= @rabbit_settings[:durable_queues] %> +<% end -%> # Auto-delete queues in AMQP. (boolean value) # Deprecated group/name - [DEFAULT]/amqp_auto_delete @@ -3287,7 +3295,11 @@ rabbit_virtual_host = <%= @rabbit_settings[:vhost] %> # Use HA queues in RabbitMQ (x-ha-policy: all). If you change this option, you # must wipe the RabbitMQ database. (boolean value) # Deprecated group/name - [DEFAULT]/rabbit_ha_queues +<% if @rabbit_settings['use_legacy_configuration'] -%> #rabbit_ha_queues = false +<% else -%> +rabbit_ha_queues = <%= @rabbit_settings[:ha_queues] %> +<% end -%> # Number of seconds after which the Rabbit broker is considered down if # heartbeat's keep-alive fails (0 disable the heartbeat). EXPERIMENTAL (integer diff --git a/chef/cookbooks/rabbitmq/README.md b/chef/cookbooks/rabbitmq/README.md index 9d47d5a007..d6420807e1 100644 --- a/chef/cookbooks/rabbitmq/README.md +++ b/chef/cookbooks/rabbitmq/README.md @@ -8,10 +8,6 @@ default ------- Installs `rabbitmq-server` from RabbitMQ.com's APT repository. The distribution-provided version was quite old and newer features were needed. -cluster -------- -Configures nodes to be members of a RabbitMQ cluster, but does not actually join them. - Resources/Providers =================== There are 2 LWRPs for interacting with RabbitMQ. @@ -59,8 +55,6 @@ end Limitations =========== -It is quite useful as is, but clustering configuration does not currently do the dance to join the cluster members to each other. - The rabbitmq::chef recipe was only used for the chef-server cookbook and has been moved to chef-server::rabbitmq. License and Author diff --git a/chef/cookbooks/rabbitmq/attributes/default.rb b/chef/cookbooks/rabbitmq/attributes/default.rb index 0bbd8412c3..c832fba626 100644 --- a/chef/cookbooks/rabbitmq/attributes/default.rb +++ b/chef/cookbooks/rabbitmq/attributes/default.rb @@ -35,10 +35,9 @@ default[:rabbitmq][:configfile] = nil default[:rabbitmq][:logdir] = nil default[:rabbitmq][:mnesiadir] = nil -#clustering -default[:rabbitmq][:cluster] = "no" -default[:rabbitmq][:cluster_config] = "/etc/rabbitmq/rabbitmq_cluster.config" -default[:rabbitmq][:cluster_disk_nodes] = [] + +default[:rabbitmq][:cluster] = false +default[:rabbitmq][:clustername] = "rabbit@#{node[:hostname]}" # ha default[:rabbitmq][:ha][:enabled] = false diff --git a/chef/cookbooks/rabbitmq/libraries/crowbar.rb b/chef/cookbooks/rabbitmq/libraries/crowbar.rb index 35b30ffb4b..f23b27bf1d 100644 --- a/chef/cookbooks/rabbitmq/libraries/crowbar.rb +++ b/chef/cookbooks/rabbitmq/libraries/crowbar.rb @@ -8,7 +8,7 @@ def self.get_ha_vhostname(node) end def self.get_listen_address(node) - if node[:rabbitmq][:ha][:enabled] + if node[:rabbitmq][:ha][:enabled] && !node[:rabbitmq][:cluster] vhostname = get_ha_vhostname(node) net_db = Chef::DataBagItem.load("crowbar", "admin_network").raw_data net_db["allocated_by_name"]["#{vhostname}.#{node[:domain]}"]["address"] @@ -18,7 +18,7 @@ def self.get_listen_address(node) end def self.get_public_listen_address(node) - if node[:rabbitmq][:ha][:enabled] + if node[:rabbitmq][:ha][:enabled] && !node[:rabbitmq][:cluster] vhostname = get_ha_vhostname(node) net_db = Chef::DataBagItem.load("crowbar", "public_network").raw_data net_db["allocated_by_name"]["#{vhostname}.#{node[:domain]}"]["address"] diff --git a/chef/cookbooks/rabbitmq/metadata.rb b/chef/cookbooks/rabbitmq/metadata.rb index 964eda4b1a..bb09ccc51d 100644 --- a/chef/cookbooks/rabbitmq/metadata.rb +++ b/chef/cookbooks/rabbitmq/metadata.rb @@ -4,7 +4,6 @@ description "Installs and configures RabbitMQ server" version "1.2.0" recipe "rabbitmq", "Install and configure RabbitMQ" -recipe "rabbitmq::cluster", "Set up RabbitMQ clustering." depends "crowbar-openstack" depends "crowbar-pacemaker" @@ -45,22 +44,6 @@ display_name: "RabbitMQ Mnesia database directory", description: "Path to the directory for Mnesia database files." -attribute "rabbitmq/cluster", - display_name: "RabbitMQ clustering", - description: "Whether to activate clustering.", - default: "no" - -attribute "rabbitmq/cluster_config", - display_name: "RabbitMQ clustering configuration file", - description: "Path to the clustering configuration file, if cluster is yes.", - default: "/etc/rabbitmq/rabbitmq_cluster.config" - -attribute "rabbitmq/cluster_disk_nodes", - display_name: "RabbitMQ cluster disk nodes", - description: "Array of member Erlang nodenames for the disk-based storage nodes in the cluster.", - default: [], - type: "array" - attribute "rabbitmq/erlang_cookie", display_name: "RabbitMQ Erlang cookie", description: "Access cookie for clustering nodes. There is no default." diff --git a/chef/cookbooks/rabbitmq/recipes/cluster.rb b/chef/cookbooks/rabbitmq/recipes/cluster.rb deleted file mode 100644 index dd96f8af01..0000000000 --- a/chef/cookbooks/rabbitmq/recipes/cluster.rb +++ /dev/null @@ -1,35 +0,0 @@ -# -# Cookbook Name:: rabbitmq -# Recipe:: cluster -# -# Copyright 2009, Benjamin Black -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -include_recipe "rabbitmq::default" - -template "/var/lib/rabbitmq/.erlang.cookie" do - source "doterlang.cookie.erb" - owner "rabbitmq" - group "rabbitmq" - mode 0400 -end - -template "/etc/rabbitmq/rabbitmq_cluster.config" do - source "rabbitmq_cluster.config.erb" - owner "root" - group "root" - mode 0644 - notifies :restart, resources(service: "rabbitmq-server"), :immediately -end - diff --git a/chef/cookbooks/rabbitmq/recipes/default.rb b/chef/cookbooks/rabbitmq/recipes/default.rb index d306df2d6b..6e78819de2 100644 --- a/chef/cookbooks/rabbitmq/recipes/default.rb +++ b/chef/cookbooks/rabbitmq/recipes/default.rb @@ -36,12 +36,25 @@ notifies :restart, "service[rabbitmq-server]" end +rabbit_settings = fetch_rabbitmq_settings +if rabbit_settings[:clustered] + add_cluster_section = true + cluster_nodes = rabbit_settings[:cluster_nodes] +else + add_cluster_section = false + cluster_nodes = "" +end + template "/etc/rabbitmq/rabbitmq.config" do source "rabbitmq.config.erb" owner "root" group "root" mode 0644 notifies :restart, "service[rabbitmq-server]" + variables( + add_cluster_section: add_cluster_section, + cluster_nodes: cluster_nodes + ) end case node[:platform_family] diff --git a/chef/cookbooks/rabbitmq/recipes/ha_cluster.rb b/chef/cookbooks/rabbitmq/recipes/ha_cluster.rb new file mode 100644 index 0000000000..0247f6e287 --- /dev/null +++ b/chef/cookbooks/rabbitmq/recipes/ha_cluster.rb @@ -0,0 +1,91 @@ +# Copyright 2017 SUSE +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +pid_file = "/var/run/rabbitmq/pid" + +agent_name = "ocf:rabbitmq:rabbitmq-server-ha" +rabbitmq_op = {} +rabbitmq_op["monitor"] = {} +rabbitmq_op["monitor"]["interval"] = "10s" + +crowbar_pacemaker_sync_mark "wait-rabbitmq_ha_resources" + +transaction_objects = [] + +service_name = "rabbitmq" +pacemaker_primitive service_name do + agent agent_name + # nodename is empty so that we explicitly depend on the config files + params ({ + "erlang_cookie" => node[:rabbitmq][:erlang_cookie], + "pid_file" => pid_file, + "rmq_feature_health_check" => false, + "rmq_feature_local_list_queues" => false, + "default_vhost" => node[:rabbitmq][:vhost] + }) + op rabbitmq_op + action :update + only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } +end +transaction_objects.push("pacemaker_primitive[#{service_name}]") + +# no location on the role here: the ms resource will have this constraint + +ms_name = "ms-#{service_name}" +pacemaker_ms ms_name do + rsc service_name + meta ({ + "master-max" => "1", + "master-node-max" => "1", + "ordered" => "false", + "interleave" => "false", + "notify" => "true" + }) + action :update + only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } +end +transaction_objects.push("pacemaker_ms[#{ms_name}]") + +ms_location_name = openstack_pacemaker_controller_only_location_for ms_name +transaction_objects.push("pacemaker_location[#{ms_location_name}]") + +pacemaker_transaction "rabbitmq service" do + cib_objects transaction_objects + # note that this will also automatically start the resources + action :commit_new + only_if { CrowbarPacemakerHelper.is_cluster_founder?(node) } +end + +crowbar_pacemaker_sync_mark "create-rabbitmq_ha_resources" + +# wait for service to have a master, and to be active +ruby_block "wait for #{ms_name} to be started" do + block do + require "timeout" + begin + # 30s (our usual timeout) is a bit short with this OCF RA which + # stops/starts the rabbit app multiple times due to the master-slave + # config + Timeout.timeout(60) do + ::Kernel.system("crm_resource --wait --resource #{ms_name}") + ::Kernel.system("rabbitmqctl wait #{pid_file}") + end + rescue Timeout::Error + message = "RabbitMQ is not started. Please manually check for an error." + Chef::Log.fatal(message) + raise message + end + end # block +end # ruby_block diff --git a/chef/cookbooks/rabbitmq/recipes/rabbit.rb b/chef/cookbooks/rabbitmq/recipes/rabbit.rb index 08148f5885..9cf4145054 100644 --- a/chef/cookbooks/rabbitmq/recipes/rabbit.rb +++ b/chef/cookbooks/rabbitmq/recipes/rabbit.rb @@ -19,6 +19,8 @@ # ha_enabled = node[:rabbitmq][:ha][:enabled] +# we only do cluster if we do HA +cluster_enabled = node[:rabbitmq][:cluster] && ha_enabled node.set[:rabbitmq][:address] = CrowbarRabbitmqHelper.get_listen_address(node) node.set[:rabbitmq][:management_address] = node[:rabbitmq][:address] @@ -28,7 +30,10 @@ end node.set[:rabbitmq][:addresses] = addresses -if ha_enabled +if cluster_enabled + node.set[:rabbitmq][:nodename] = "rabbit@#{node[:hostname]}" + node.set[:rabbitmq][:clustername] = "rabbit@#{CrowbarRabbitmqHelper.get_ha_vhostname(node)}" +elsif ha_enabled node.set[:rabbitmq][:nodename] = "rabbit@#{CrowbarRabbitmqHelper.get_ha_vhostname(node)}" end @@ -36,11 +41,18 @@ if ha_enabled log "HA support for rabbitmq is enabled" - include_recipe "rabbitmq::ha" - # All the rabbitmqctl commands are local, and can only be run if rabbitmq is - # local - service_name = "rabbitmq" - only_if_command = "crm resource show #{service_name} | grep -q \" #{node.hostname} *$\"" + if cluster_enabled + include_recipe "rabbitmq::ha_cluster" + # only run the rabbitmqctl commands on the master node + ms_name = "ms-rabbitmq" + only_if_command = "crm resource show #{ms_name} | grep -q \" #{node.hostname} *Master$\"" + else + include_recipe "rabbitmq::ha" + # All the rabbitmqctl commands are local, and can only be run if rabbitmq is + # local + service_name = "rabbitmq" + only_if_command = "crm resource show #{service_name} | grep -q \" #{node.hostname} *$\"" + end else log "HA support for rabbitmq is disabled" end @@ -84,6 +96,27 @@ only_if only_if_command if ha_enabled end +if cluster_enabled + set_policy_command = "rabbitmqctl set_policy -p #{node[:rabbitmq][:vhost]} " \ + " ha-all '^(?!amq\.).*' '{\"ha-mode\": \"all\"}'" + check_policy_command = "rabbitmqctl list_policies -p #{node[:rabbitmq][:vhost]} | " \ + " grep -q '^#{node[:rabbitmq][:vhost]}\\s*ha-all\\s'" + + execute set_policy_command do + not_if check_policy_command + action :run + only_if only_if_command if ha_enabled + end + + check_cluster_name_command = "rabbitmqctl cluster_status | " \ + "grep -q '{cluster_name,<<\"#{node[:rabbitmq][:clustername]}\">>}'" + execute "rabbitmqctl set_cluster_name #{node[:rabbitmq][:clustername]}" do + not_if check_cluster_name_command + action :run + only_if only_if_command if ha_enabled + end +end + if node[:rabbitmq][:trove][:enabled] rabbitmq_vhost node[:rabbitmq][:trove][:vhost] do action :add diff --git a/chef/cookbooks/rabbitmq/templates/default/doterlang.cookie.erb b/chef/cookbooks/rabbitmq/templates/default/doterlang.cookie.erb deleted file mode 100644 index 80be847009..0000000000 --- a/chef/cookbooks/rabbitmq/templates/default/doterlang.cookie.erb +++ /dev/null @@ -1 +0,0 @@ -<%= node[:rabbitmq][:erlang_cookie] %> \ No newline at end of file diff --git a/chef/cookbooks/rabbitmq/templates/default/rabbitmq.config.erb b/chef/cookbooks/rabbitmq/templates/default/rabbitmq.config.erb index 97f29c40d8..72349d964a 100644 --- a/chef/cookbooks/rabbitmq/templates/default/rabbitmq.config.erb +++ b/chef/cookbooks/rabbitmq/templates/default/rabbitmq.config.erb @@ -4,6 +4,12 @@ {tcp_listeners, [ <%= node[:rabbitmq][:addresses].map { |address| "{\"#{address}\", #{node[:rabbitmq][:port]}}" }.join(", ") %> ]}, +<% if @add_cluster_section -%> + {cluster_nodes, {[ + <%= @cluster_nodes %> + ], disc} + }, +<% end -%> {disk_free_limit, 50000000} ] }, diff --git a/chef/cookbooks/rabbitmq/templates/default/rabbitmq_cluster.config.erb b/chef/cookbooks/rabbitmq/templates/default/rabbitmq_cluster.config.erb deleted file mode 100644 index 8d806dd07f..0000000000 --- a/chef/cookbooks/rabbitmq/templates/default/rabbitmq_cluster.config.erb +++ /dev/null @@ -1,5 +0,0 @@ -%%% -%% Generated by Chef for <%= node[:fqdn] %> -%%% - -[<%= node[:rabbitmq][:cluster_disk_nodes].map{|n| "\'#{n}\'"}.join(',') %>]. diff --git a/chef/data_bags/crowbar/template-rabbitmq.json b/chef/data_bags/crowbar/template-rabbitmq.json index 3ffc8c155c..0c58aa3523 100644 --- a/chef/data_bags/crowbar/template-rabbitmq.json +++ b/chef/data_bags/crowbar/template-rabbitmq.json @@ -8,6 +8,7 @@ "password": "", "user": "nova", "vhost": "/nova", + "cluster": true, "ha": { "storage": { "mode": "shared", diff --git a/chef/data_bags/crowbar/template-rabbitmq.schema b/chef/data_bags/crowbar/template-rabbitmq.schema index f11e5e2592..36b70a47d0 100644 --- a/chef/data_bags/crowbar/template-rabbitmq.schema +++ b/chef/data_bags/crowbar/template-rabbitmq.schema @@ -17,6 +17,7 @@ "password": { "type": "str", "required": true }, "user": { "type": "str", "required": true }, "vhost": { "type": "str", "required": true }, + "cluster": { "type": "bool", "required": false }, "ha" : { "type": "map", "required": true, diff --git a/crowbar_framework/app/models/rabbitmq_service.rb b/crowbar_framework/app/models/rabbitmq_service.rb index e4bd7d2263..f9bdc8856d 100644 --- a/crowbar_framework/app/models/rabbitmq_service.rb +++ b/crowbar_framework/app/models/rabbitmq_service.rb @@ -85,7 +85,7 @@ def apply_role_pre_chef_call(old_role, role, all_nodes) end end - if rabbitmq_ha_enabled + if rabbitmq_ha_enabled && !role.default_attributes["rabbitmq"]["cluster"] unless rabbitmq_elements.length == 1 && PacemakerServiceObject.is_cluster?(rabbitmq_elements[0]) raise "Internal error: HA enabled, but element is not a cluster" end @@ -100,6 +100,20 @@ def apply_role_pre_chef_call(old_role, role, all_nodes) ensure_dns_uptodate end + if role.default_attributes["rabbitmq"]["cluster"] + role.default_attributes["rabbitmq"]["erlang_cookie"] = \ + (old_role && old_role.default_attributes["rabbitmq"]["erlang_cookie"]) || random_password + end + + unless rabbitmq_ha_enabled + # cluster mode requires HA (for now); don't do a validation check as we + # still want to have the setting default to true in case people want to + # turn HA on, and in this case, result in clustering by default + role.default_attributes["rabbitmq"]["cluster"] = false + end + + role.save + @logger.debug("Rabbitmq apply_role_pre_chef_call: leaving") end @@ -108,9 +122,11 @@ def validate_proposal_after_save proposal attributes = proposal["attributes"][@bc_name] - # HA validation servers = proposal["deployment"][@bc_name]["elements"]["rabbitmq-server"] - unless servers.nil? || servers.first.nil? || !is_cluster?(servers.first) + ha_enabled = !(servers.nil? || servers.first.nil? || !is_cluster?(servers.first)) + + # Shared storage validation for HA + if ha_enabled && !attributes["cluster"] storage_mode = attributes["ha"]["storage"]["mode"] validation_error I18n.t( "barclamp.#{@bc_name}.validation.unknown_mode", storage_mode: storage_mode diff --git a/crowbar_framework/app/views/barclamp/rabbitmq/_edit_attributes.html.haml b/crowbar_framework/app/views/barclamp/rabbitmq/_edit_attributes.html.haml index cfdae04321..11ee878b95 100644 --- a/crowbar_framework/app/views/barclamp/rabbitmq/_edit_attributes.html.haml +++ b/crowbar_framework/app/views/barclamp/rabbitmq/_edit_attributes.html.haml @@ -11,14 +11,17 @@ %legend = t('.ha_header') - = select_field %w(ha storage mode), :collection => :ha_storage_mode_for_rabbitmq, "data-showit" => ["drbd", "shared"].join(";"), "data-showit-target" => "#drbd_storage_container;#shared_storage_container", "data-showit-direct" => "true" + = boolean_field %w(cluster), "data-hideit" => "true", "data-hideit-target" => "#ha_storage_container", "data-hideit-direct" => "true" - #drbd_storage_container - .alert.alert-info - = t('.ha.storage.drbd_info') - = integer_field %w(ha storage drbd size) + #ha_storage_container + = select_field %w(ha storage mode), :collection => :ha_storage_mode_for_rabbitmq, "data-showit" => ["drbd", "shared"].join(";"), "data-showit-target" => "#drbd_storage_container;#shared_storage_container", "data-showit-direct" => "true" - #shared_storage_container - = string_field %w(ha storage shared device) - = string_field %w(ha storage shared fstype) - = string_field %w(ha storage shared options) + #drbd_storage_container + .alert.alert-info + = t('.ha.storage.drbd_info') + = integer_field %w(ha storage drbd size) + + #shared_storage_container + = string_field %w(ha storage shared device) + = string_field %w(ha storage shared fstype) + = string_field %w(ha storage shared options) diff --git a/crowbar_framework/config/locales/rabbitmq/en.yml b/crowbar_framework/config/locales/rabbitmq/en.yml index f173b40084..19e6e3df40 100644 --- a/crowbar_framework/config/locales/rabbitmq/en.yml +++ b/crowbar_framework/config/locales/rabbitmq/en.yml @@ -23,6 +23,7 @@ en: user: 'User' port: 'Port' ha_header: 'High Availability' + cluster: 'Use RabbitMQ Clustering' ha: storage: mode: 'Storage Mode'