Refactoring of mongodb host selector

* Moving ugly puppet logic into a function.
* Making simple mode work same as HA mode
  with primary and slave nodes

Change-Id: Ic5a334364afcd3673d1353db3685025e9da40b97
Closes-bug: 1308988
This commit is contained in:
Dmitry Ilyin 2014-04-23 22:30:50 +04:00
parent 8f705f8cea
commit 7effd0b11a
6 changed files with 114 additions and 110 deletions

View File

@ -0,0 +1,43 @@
module Puppet::Parser::Functions
newfunction(:mongo_hosts, :type => :rvalue, :doc => <<-EOS
Return a comma-separated list of hosts with roles 'primary-mongo' and 'mongo'
Argument1: $nodes_hash, mandatory argument
Argument2: 'array' or 'string' Return values as an array or a string? Default: string
Argument3: roles to select, primary-mongo and mongo by default
Returns: a string of ips, separated by a comma
EOS
) do |args|
nodes = args[0]
type = args[1] || 'string'
roles = args[2] || %w(primary-mongo mongo)
roles = Array(roles) unless roles.is_a?(Array)
unless nodes.is_a?(Array) && nodes.any? && nodes.first.is_a?(Hash) && nodes.first['uid']
raise Puppet::ParseError, 'You should provide $nodes_hash as the first argument of this fuction! It should be an array of hashes with node information.'
end
unless %w(array string).include? type
raise Puppet::ParseError, 'Type should be either array or string!'
end
unless roles.any?
raise Puppet::ParseError, 'You should give at list one role to filter!'
end
hosts = []
roles.each do |r|
nodes.inject(hosts) do |h,n|
h.push(n['internal_address']) if (n['role'] == r) && n['internal_address']
h
end
end
if type == 'string'
hosts.join(',')
else
hosts
end
end
end

View File

@ -1,10 +1,10 @@
# == Class: openstack::mongo
class openstack::mongo (
$ceilometer_database = "ceilometer_database",
$ceilometer_user = "ceilometer_user",
$ceilometer_database = "ceilometer",
$ceilometer_user = "ceilometer",
$ceilometer_metering_secret = undef,
$ceilometer_db_password = $ceilometer_hash[db_password],
$ceilometer_db_password = "ceilometer",
$ceilometer_metering_secret = "ceilometer",
$mongodb_port = 27017,
$mongodb_bind_address = ['0.0.0.0'],

View File

@ -1,8 +1,8 @@
# == Class: openstack::mongo_primary
class openstack::mongo_primary (
$ceilometer_database = "ceilometer_database",
$ceilometer_user = "ceilometer_user",
$ceilometer_database = "ceilometer",
$ceilometer_user = "ceilometer",
$ceilometer_metering_secret = undef,
$ceilometer_db_password = "ceilometer",
$ceilometer_metering_secret = "ceilometer",
@ -11,8 +11,17 @@ class openstack::mongo_primary (
$mongodb_port = 27017,
) {
$replset_setup = size($ceilometer_replset_members) > 0
notify {"MongoDB params: $mongodb_bind_address": } ->
if size($ceilometer_replset_members) > 0 {
$replset_setup = true
$keyfile = '/etc/mongodb.key'
$replset = 'ceilometer'
} else {
$replset_setup = false
$keyfile = undef
$replset = undef
}
notify {"MongoDB params: $mongodb_bind_address" :} ->
class {'::mongodb::client':
} ->
@ -21,9 +30,9 @@ class openstack::mongo_primary (
port => $mongodb_port,
verbose => true,
bind_ip => $mongodb_bind_address,
replset => 'ceilometer',
auth => true,
keyfile => '/etc/mongodb.key'
auth => true,
replset => $replset,
keyfile => $keyfile,
} ->
class {'::mongodb::replset':
@ -31,20 +40,38 @@ class openstack::mongo_primary (
replset_members => $ceilometer_replset_members,
} ->
notify {"mongodb configuring databases" :} ->
mongodb::db { $ceilometer_database:
user => $ceilometer_user,
password => $ceilometer_db_password,
roles => ['readWrite', 'dbAdmin', 'dbOwner'],
roles => [
'readWrite',
'dbAdmin',
'dbOwner'
],
} ->
mongodb::db { 'admin':
user => 'admin',
password => $ceilometer_db_password,
roles => ['userAdmin','readWrite', 'dbAdmin', 'dbAdminAnyDatabase', 'readAnyDatabase', 'readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin', 'clusterManager', 'clusterMonitor', 'hostManager', 'root' ],
roles => [
'userAdmin',
'readWrite',
'dbAdmin',
'dbAdminAnyDatabase',
'readAnyDatabase',
'readWriteAnyDatabase',
'userAdminAnyDatabase',
'clusterAdmin',
'clusterManager',
'clusterMonitor',
'hostManager',
'root'
],
} ->
notify {"mongodb primary finished": }
# notify {"mongo: $ceilometer_db_password": }
}
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :

View File

@ -1,8 +1,8 @@
# == Class: openstack::mongo_secondary
class openstack::mongo_secondary (
$ceilometer_database = "ceilometer_database",
$ceilometer_user = "ceilometer_user",
$ceilometer_database = "ceilometer",
$ceilometer_user = "ceilometer",
$ceilometer_metering_secret = undef,
$ceilometer_db_password = "ceilometer",
$ceilometer_metering_secret = "ceilometer",

View File

@ -161,49 +161,6 @@ class osnailyfacter::cluster_ha {
$cinder_iscsi_bind_addr = $::storage_address
if $::fuel_settings['ceilometer'] {
$mongo_node = filter_nodes($nodes_hash,'role','mongo')
$mongo_primary_node = filter_nodes($nodes_hash,'role','primary-mongo')
$mongo_secondary_hosts = values(nodes_to_hash($mongo_node,'name','internal_address'))
if is_hash($mongo_node[0]) {
$mongo_node_address = $mongo_node[0]['internal_address']
notify {"MongoDB: $mongo_node_address": }
}
if is_hash($mongo_primary_node[0]) {
$mongo_primary_node_address = $mongo_primary_node[0]['internal_address']
notify {"MongoDB_Primary: $mongo_primary_node_address": }
}
# MBF
$current_ceilometer_db_type = "mongodb"
# Connect to prymary node
# $current_ceilometer_db_address = $mongo_primary_node_address
# Connect to ReplicaSet Example
# connection = mongodb://mongos1:27017,mongos2:27017,mongos3:27017/ceilometer?readPreference=secondary&w=2&wtimeoutMS=2000
if is_hash($mongo_node[0]) {
$mongo_slave_node_address_0 = $mongo_node[0]['internal_address']
}
if is_hash($mongo_node[1]) {
$mongo_slave_node_address_1 = $mongo_node[1]['internal_address']
}
if is_hash($mongo_primary_node[0]) {
if size($mongo_secondary_hosts) > 0 {
$current_ceilometer_db_address = inline_template("<%=[@mongo_primary_node_address]\
.concat(@mongo_secondary_hosts)\
.select{|x| not (x.nil? or x.empty?)}.join(',') %>")
} else {
$current_ceilometer_db_address = "$mongo_primary_node_address"
}
} else {
$current_ceilometer_db_address = '127.0.0.1'
}
notify {"Ceilometer_connection_string: $current_ceilometer_db_address": }
}
$mongodb_bind_address_list = ['127.0.0.1']
# Determine who should get the volume service
if (member($roles, 'cinder') and $storage_hash['volumes_lvm']) {
$manage_volumes = 'iscsi'
@ -350,8 +307,8 @@ class osnailyfacter::cluster_ha {
ceilometer_db_password => $::osnailyfacter::cluster_ha::ceilometer_hash[db_password],
ceilometer_user_password => $::osnailyfacter::cluster_ha::ceilometer_hash[user_password],
ceilometer_metering_secret => $::osnailyfacter::cluster_ha::ceilometer_hash[metering_secret],
ceilometer_db_type => $::osnailyfacter::cluster_ha::current_ceilometer_db_type,
ceilometer_db_host => $::osnailyfacter::cluster_ha::current_ceilometer_db_address,
ceilometer_db_type => 'mongodb',
ceilometer_db_host => mongo_hosts($nodes_hash),
galera_nodes => $::osnailyfacter::cluster_ha::controller_nodes,
novnc_address => $::internal_address,
sahara => $::osnailyfacter::cluster_ha::sahara_hash[enabled],
@ -634,39 +591,20 @@ class osnailyfacter::cluster_ha {
} # COMPUTE ENDS
"mongo" : {
#notify {"MongoDB bind address 4: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
#$::osnailyfacter::cluster_ha::mongodb_bind_address_list += ["$::internal_address"]
# Append does not works as expeced, use workaround!
notify {"MongoDB bind address 5: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
$::osnailyfacter::cluster_ha::mongodb_bind_address_list[1] = $::internal_address
notify {"MongoDB bind address 6: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
class { 'openstack::mongo_secondary':
mongodb_bind_address => $::osnailyfacter::cluster_ha::mongodb_bind_address_list,
mongodb_bind_address => [ '127.0.0.1', $::internal_address ],
}
} # MONGO ENDS
"primary-mongo" : {
#notify {"MongoDB bind address 1: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
#$::osnailyfacter::cluster_ha::mongodb_bind_address_list += ["$::internal_address"]
# Append does not works as expeced, use workaround!
notify {"MongoDB bind address 2: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
$::osnailyfacter::cluster_ha::mongodb_bind_address_list[1] = $::internal_address
notify {"MongoDB bind address 3: $::osnailyfacter::cluster_ha::mongodb_bind_address_list": }
class { 'openstack::mongo_primary':
mongodb_bind_address => $::osnailyfacter::cluster_ha::mongodb_bind_address_list,
ceilometer_database => "ceilometer",
ceilometer_metering_secret => $::osnailyfacter::cluster_ha::ceilometer_hash[metering_secret],
ceilometer_db_password => $::osnailyfacter::cluster_ha::ceilometer_hash[db_password],
ceilometer_replset_members => $mongo_secondary_hosts,
ceilometer_db_user => 'ceilometer',
mongodb_bind_address => [ '127.0.0.1', $::internal_address ],
ceilometer_metering_secret => $ceilometer_hash['metering_secret'],
ceilometer_db_password => $ceilometer_hash['db_password'],
ceilometer_replset_members => mongo_hosts($nodes_hash, 'array', 'mongo')
}
} # MONGO PRIMARYENDS
} # PRIMARY-MONGO ENDS
"cinder" : {
include keystone::python

View File

@ -86,20 +86,6 @@ class osnailyfacter::cluster_simple {
$controller_node_public = $controller[0]['public_address']
$roles = node_roles($nodes_hash, $::fuel_settings['uid'])
if $::fuel_settings['ceilometer'] {
$mongo_node = filter_nodes($nodes_hash,'role','mongo')
if is_hash($mongo_node[0]) {
$mongo_node_address = $mongo_node[0]['internal_address']
}
# MBF
$current_ceilometer_db_type = "mongodb"
$current_ceilometer_db_address = $mongo_node_address
notify {"MongoDB: $mongo_node_address": }
}
# AMQP client configuration
$amqp_port = '5672'
$amqp_hosts = "${controller_node_address}:${amqp_port}"
@ -204,8 +190,8 @@ class osnailyfacter::cluster_simple {
ceilometer_db_password => $ceilometer_hash[db_password],
ceilometer_user_password => $ceilometer_hash[user_password],
ceilometer_metering_secret => $ceilometer_hash[metering_secret],
ceilometer_db_type => $current_ceilometer_db_type,
ceilometer_db_host => $current_ceilometer_db_address,
ceilometer_db_type => 'mongodb',
ceilometer_db_host => mongo_hosts($nodes_hash),
queue_provider => $::queue_provider,
amqp_hosts => $amqp_hosts,
amqp_user => $rabbit_hash['user'],
@ -441,18 +427,28 @@ class osnailyfacter::cluster_simple {
}
} # COMPUTE ENDS
"mongo" : {
class { 'openstack::mongo':
mongodb_bind_address => [ $mongo_node[0]['internal_address'], '127.0.0.1' ],
ceilometer_database => "ceilometer",
ceilometer_user => "ceilometer",
ceilometer_metering_secret => $ceilometer_hash[metering_secret],
ceilometer_db_password => $ceilometer_hash[db_password],
class { 'openstack::mongo_secondary':
mongodb_bind_address => [ '127.0.0.1', $::internal_address ],
}
} # MONGO ENDS
"primary-mongo" : {
class { 'openstack::mongo_primary':
mongodb_bind_address => [ '127.0.0.1', $::internal_address ],
ceilometer_metering_secret => $ceilometer_hash['metering_secret'],
ceilometer_db_password => $ceilometer_hash['db_password'],
ceilometer_replset_members => mongo_hosts($nodes_hash, 'array', 'mongo')
}
} # PRIMARY-MONGO ENDS
# "mongo" : {
# class { 'openstack::mongo':
# mongodb_bind_address => [ '127.0.0.1', $::internal_address ],
# ceilometer_metering_secret => $ceilometer_hash['metering_secret'],
# ceilometer_db_password => $ceilometer_hash['db_password'],
# }
# } # MONGO ENDS
"cinder" : {
include keystone::python