Merge "MongoDB: Add support for Sharding configuration"
This commit is contained in:
@@ -1,105 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
#
|
|
||||||
# == Class: cloud::database::nosql::mongodb
|
|
||||||
#
|
|
||||||
# Install a nosql server (MongoDB)
|
|
||||||
#
|
|
||||||
# === Parameters:
|
|
||||||
#
|
|
||||||
# [*bind_ip*]
|
|
||||||
# (optional) IP address on which mongod instance should listen
|
|
||||||
# Defaults to '127.0.0.1'
|
|
||||||
#
|
|
||||||
# [*nojournal*]
|
|
||||||
# (optional) Disable mongodb internal cache. This is not recommended for
|
|
||||||
# production but results in a much faster boot process.
|
|
||||||
# http://docs.mongodb.org/manual/reference/configuration-options/#nojournal
|
|
||||||
# Defaults to false
|
|
||||||
#
|
|
||||||
# [*replset_members*]
|
|
||||||
# (optional) Ceilometer Replica set members hostnames
|
|
||||||
# Should be an array. Example: ['node1', 'node2', node3']
|
|
||||||
# If set to false, the setup won't be HA and no replicaset will be created.
|
|
||||||
# Defaults to hostname
|
|
||||||
#
|
|
||||||
# [*firewall_settings*]
|
|
||||||
# (optional) Allow to add custom parameters to firewall rules
|
|
||||||
# Should be an hash.
|
|
||||||
# Default to {}
|
|
||||||
#
|
|
||||||
# [*mongodb_version*]
|
|
||||||
# (optional) Specify MongoDB version
|
|
||||||
# Default to '2.4.0'
|
|
||||||
#
|
|
||||||
class cloud::database::nosql::mongodb(
|
|
||||||
$bind_ip = '127.0.0.1',
|
|
||||||
$nojournal = false,
|
|
||||||
$replset_members = $::hostname,
|
|
||||||
$firewall_settings = {},
|
|
||||||
$mongodb_version = '2.4.0',
|
|
||||||
) {
|
|
||||||
|
|
||||||
# should be an array
|
|
||||||
$array_bind_ip = any2array($bind_ip)
|
|
||||||
$array_replset_members = any2array($replset_members)
|
|
||||||
|
|
||||||
# Red Hat & CentOS use packages from RHCL or EPEL to support systemd
|
|
||||||
# so manage_package_repo should be at false regarding to mongodb module
|
|
||||||
if $::osfamily == 'RedHat' {
|
|
||||||
$manage_package_repo = false
|
|
||||||
} else {
|
|
||||||
# Debian & Ubuntu are picked from mongodb repo to get recent version
|
|
||||||
$manage_package_repo = true
|
|
||||||
}
|
|
||||||
|
|
||||||
class { '::mongodb::globals':
|
|
||||||
manage_package_repo => $manage_package_repo,
|
|
||||||
version => $mongodb_version,
|
|
||||||
}->
|
|
||||||
class { '::mongodb':
|
|
||||||
bind_ip => $array_bind_ip,
|
|
||||||
nojournal => $nojournal,
|
|
||||||
replset => 'ceilometer',
|
|
||||||
logpath => '/var/log/mongodb/mongod.log',
|
|
||||||
}
|
|
||||||
|
|
||||||
exec {'check_mongodb' :
|
|
||||||
command => "/usr/bin/mongo ${bind_ip}:27017",
|
|
||||||
logoutput => false,
|
|
||||||
tries => 60,
|
|
||||||
try_sleep => 5,
|
|
||||||
require => Service['mongodb'],
|
|
||||||
}
|
|
||||||
|
|
||||||
if $replset_members {
|
|
||||||
mongodb_replset{'ceilometer':
|
|
||||||
members => $array_replset_members,
|
|
||||||
before => Anchor['mongodb setup done'],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
anchor {'mongodb setup done' :
|
|
||||||
require => Exec['check_mongodb'],
|
|
||||||
}
|
|
||||||
|
|
||||||
if $::cloud::manage_firewall {
|
|
||||||
cloud::firewall::rule{ '100 allow mongodb access':
|
|
||||||
port => '27017',
|
|
||||||
extras => $firewall_settings,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
64
manifests/database/nosql/mongodb/mongod.pp
Normal file
64
manifests/database/nosql/mongodb/mongod.pp
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# == Class: cloud::database::nosql::mongodb::mongod
|
||||||
|
#
|
||||||
|
# Install a MongoDB server & the replicasets
|
||||||
|
#
|
||||||
|
# === Parameters:
|
||||||
|
#
|
||||||
|
# [*enable*]
|
||||||
|
# (optional) Should mongod be running.
|
||||||
|
# Defaults to 'true'
|
||||||
|
#
|
||||||
|
# [*replset*]
|
||||||
|
# (optional) MongoDB replicaset to configure
|
||||||
|
# Define the replset to enable on the mongodb server
|
||||||
|
# Example:
|
||||||
|
# { 'ceilometer' => { 'members' => '10.0.0.1:27017' }}
|
||||||
|
# Defaults to {}
|
||||||
|
#
|
||||||
|
# [*mongod_port*]
|
||||||
|
# (optional) Port for the firewall to enable
|
||||||
|
# Based on the mode the mongod process is started with, the port
|
||||||
|
# it will listen on might change.
|
||||||
|
# Defaults to '27017'
|
||||||
|
#
|
||||||
|
# [*firewall_settings*]
|
||||||
|
# (optional) Allow to add custom parameters to firewall rules
|
||||||
|
# Should be an hash.
|
||||||
|
# Defaults to {}
|
||||||
|
#
|
||||||
|
class cloud::database::nosql::mongodb::mongod(
|
||||||
|
$enable = true,
|
||||||
|
$replset = {},
|
||||||
|
$mongod_port = '27017',
|
||||||
|
$firewall_settings = {},
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $enable {
|
||||||
|
include ::mongodb::globals
|
||||||
|
include ::mongodb::server
|
||||||
|
create_resources('mongodb_replset', $replset)
|
||||||
|
|
||||||
|
if $::cloud::manage_firewall {
|
||||||
|
cloud::firewall::rule{ '100 allow mongod access':
|
||||||
|
port => $mongod_port,
|
||||||
|
extras => $firewall_settings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
69
manifests/database/nosql/mongodb/mongos.pp
Normal file
69
manifests/database/nosql/mongodb/mongos.pp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2014 eNovance SAS <licensing@enovance.com>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# == Class: cloud::database::nosql::mongodb::mongos
|
||||||
|
#
|
||||||
|
# Install and configure mongos (daemon responsible for sharding in MongoDB)
|
||||||
|
#
|
||||||
|
# === Parameters:
|
||||||
|
#
|
||||||
|
# [*enable*]
|
||||||
|
# (optional) Should mongos be running.
|
||||||
|
# Defaults to 'true'
|
||||||
|
#
|
||||||
|
# [*shards*]
|
||||||
|
# (optional) Hash of shards to create
|
||||||
|
# Example :
|
||||||
|
# { 'ceilometer' =>
|
||||||
|
# {
|
||||||
|
# 'member' => 'ceilometer/10.0.0.1:27018',
|
||||||
|
# 'keys' => [{'ceilometer.name' => { 'name' => 1 }}, {'ceilometer.foo' => { 'bar' => 1 }}]
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
# Defaults to {}
|
||||||
|
#
|
||||||
|
# [*mongos_port*]
|
||||||
|
# (optional) Port for the firewall to enable
|
||||||
|
# Based on the mode the mongos process is started with, the port
|
||||||
|
# it will listen on might change.
|
||||||
|
# Defaults to '27017'
|
||||||
|
#
|
||||||
|
# [*firewall_settings*]
|
||||||
|
# (optional) Allow to add custom parameters to firewall rules
|
||||||
|
# Should be an hash.
|
||||||
|
# Defaults to {}
|
||||||
|
#
|
||||||
|
#
|
||||||
|
class cloud::database::nosql::mongodb::mongos(
|
||||||
|
$enable = true,
|
||||||
|
$shards = {},
|
||||||
|
$mongos_port = '27017',
|
||||||
|
$firewall_settings = {},
|
||||||
|
) {
|
||||||
|
|
||||||
|
if $enable {
|
||||||
|
include ::mongodb::globals
|
||||||
|
include ::mongodb::mongos
|
||||||
|
create_resources('mongodb_shard', $shards)
|
||||||
|
|
||||||
|
if $::cloud::manage_firewall {
|
||||||
|
cloud::firewall::rule{ '100 allow mongos access':
|
||||||
|
port => $mongos_port,
|
||||||
|
extras => $firewall_settings,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -13,55 +13,48 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
# Unit tests for cloud::database:nosql::mongodb class
|
# Unit tests for cloud::database:nosql::mongodb::mongod class
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'cloud::database::nosql::mongodb' do
|
describe 'cloud::database::nosql::mongodb::mongod' do
|
||||||
|
|
||||||
shared_examples_for 'openstack database nosql' do
|
shared_examples_for 'openstack database nosql' do
|
||||||
|
|
||||||
let :params do
|
let :params do
|
||||||
{ :bind_ip => '10.0.0.1',
|
{
|
||||||
:nojournal => false,
|
:replset => { 'ceilometer' => { 'members' => ['10.0.0.1'] } }
|
||||||
:mongodb_version => '2.4.0',
|
}
|
||||||
:replset_members => ['node1', 'node2', 'node3'] }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configure mongodb server' do
|
it 'configure mongodb::globals' do
|
||||||
is_expected.to contain_class('mongodb::globals').with(
|
is_expected.to contain_class('mongodb::globals')
|
||||||
:manage_package_repo => platform_params[:manage_package_repo],
|
end
|
||||||
:version => '2.4.0',
|
|
||||||
)
|
it 'configure mongodb::mongos' do
|
||||||
is_expected.to contain_class('mongodb::globals').with_before('Class[Mongodb]')
|
is_expected.to contain_class('mongodb::server')
|
||||||
is_expected.to contain_class('mongodb').with(
|
|
||||||
:bind_ip => ['10.0.0.1'],
|
|
||||||
:nojournal => false,
|
|
||||||
:logpath => '/var/log/mongodb/mongod.log',
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'configure mongodb replicasets' do
|
it 'configure mongodb replicasets' do
|
||||||
is_expected.to contain_exec('check_mongodb').with(
|
|
||||||
:command => "/usr/bin/mongo 10.0.0.1:27017",
|
|
||||||
:logoutput => false,
|
|
||||||
:tries => 60,
|
|
||||||
:try_sleep => 5
|
|
||||||
)
|
|
||||||
is_expected.to contain_mongodb_replset('ceilometer').with(
|
is_expected.to contain_mongodb_replset('ceilometer').with(
|
||||||
:members => ['node1', 'node2', 'node3']
|
:members => ['10.0.0.1']
|
||||||
)
|
)
|
||||||
is_expected.to contain_anchor('mongodb setup done')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without replica set' do
|
context 'when enable is set to false' do
|
||||||
before :each do
|
before :each do
|
||||||
params.merge!( :replset_members => false)
|
params.merge!(:enable => false)
|
||||||
end
|
end
|
||||||
it 'do not configure mongodb replicasets' do
|
|
||||||
is_expected.not_to contain_mongodb_replset('ceilometer')
|
it 'does not configure mongodb::globals' do
|
||||||
|
is_expected.not_to contain_class('mongodb::globals')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not configure mongodb::server' do
|
||||||
|
is_expected.not_to contain_class('mongodb::server')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with default firewall enabled' do
|
context 'with default firewall enabled' do
|
||||||
@@ -69,7 +62,7 @@ describe 'cloud::database::nosql::mongodb' do
|
|||||||
"class { 'cloud': manage_firewall => true }"
|
"class { 'cloud': manage_firewall => true }"
|
||||||
end
|
end
|
||||||
it 'configure mongodb firewall rules' do
|
it 'configure mongodb firewall rules' do
|
||||||
is_expected.to contain_firewall('100 allow mongodb access').with(
|
is_expected.to contain_firewall('100 allow mongod access').with(
|
||||||
:port => '27017',
|
:port => '27017',
|
||||||
:proto => 'tcp',
|
:proto => 'tcp',
|
||||||
:action => 'accept',
|
:action => 'accept',
|
||||||
@@ -85,7 +78,7 @@ describe 'cloud::database::nosql::mongodb' do
|
|||||||
params.merge!(:firewall_settings => { 'limit' => '50/sec' } )
|
params.merge!(:firewall_settings => { 'limit' => '50/sec' } )
|
||||||
end
|
end
|
||||||
it 'configure mongodb firewall rules with custom parameter' do
|
it 'configure mongodb firewall rules with custom parameter' do
|
||||||
is_expected.to contain_firewall('100 allow mongodb access').with(
|
is_expected.to contain_firewall('100 allow mongod access').with(
|
||||||
:port => '27017',
|
:port => '27017',
|
||||||
:proto => 'tcp',
|
:proto => 'tcp',
|
||||||
:action => 'accept',
|
:action => 'accept',
|
||||||
108
spec/classes/cloud_database_nosql_mongodb_mongos_spec.rb
Normal file
108
spec/classes/cloud_database_nosql_mongodb_mongos_spec.rb
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2015 eNovance SAS <licensing@enovance.com>
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe 'cloud::database::nosql::mongodb::mongos' do
|
||||||
|
|
||||||
|
shared_examples_for 'mongodb mongos service' do
|
||||||
|
|
||||||
|
let :params do
|
||||||
|
{
|
||||||
|
:enable => true,
|
||||||
|
:shards => {
|
||||||
|
'ceilometer' => {
|
||||||
|
'member' => 'ceilometer/10.0.0.1:27018',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configure mongodb::globals' do
|
||||||
|
is_expected.to contain_class('mongodb::globals')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configure mongodb::mongos' do
|
||||||
|
is_expected.to contain_class('mongodb::mongos')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'configure the ceilometer shard' do
|
||||||
|
is_expected.to contain_mongodb_shard('ceilometer')
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when enable is set to false' do
|
||||||
|
before :each do
|
||||||
|
params.merge!(:enable => false)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not configure mongodb::globals' do
|
||||||
|
is_expected.not_to contain_class('mongodb::globals')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not configure mongodb::mongos' do
|
||||||
|
is_expected.not_to contain_class('mongodb::mongos')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with default firewall enabled' do
|
||||||
|
let :pre_condition do
|
||||||
|
"class { 'cloud': manage_firewall => true }"
|
||||||
|
end
|
||||||
|
it 'configure mongodb firewall rules' do
|
||||||
|
is_expected.to contain_firewall('100 allow mongos access').with(
|
||||||
|
:port => '27017',
|
||||||
|
:proto => 'tcp',
|
||||||
|
:action => 'accept',
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with custom firewall enabled' do
|
||||||
|
let :pre_condition do
|
||||||
|
"class { 'cloud': manage_firewall => true }"
|
||||||
|
end
|
||||||
|
before :each do
|
||||||
|
params.merge!(:firewall_settings => { 'limit' => '50/sec' } )
|
||||||
|
end
|
||||||
|
it 'configure mongos firewall rules with custom parameter' do
|
||||||
|
is_expected.to contain_firewall('100 allow mongos access').with(
|
||||||
|
:port => '27017',
|
||||||
|
:proto => 'tcp',
|
||||||
|
:action => 'accept',
|
||||||
|
:limit => '50/sec',
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on Debian platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'Debian', }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'mongodb mongos service'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'on RedHat platforms' do
|
||||||
|
let :facts do
|
||||||
|
{ :osfamily => 'RedHat' }
|
||||||
|
end
|
||||||
|
|
||||||
|
it_configures 'mongodb mongos service'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user