Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9696355
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
24 KB
Subscribers
None
View Options
diff --git a/manifests/init.pp b/manifests/init.pp
index b46d42e..b6fef90 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -1,153 +1,154 @@
# Class: zookeeper
#
# This module manages ZooKeeper
class zookeeper(
# meta options
$ensure = $::zookeeper::params::ensure,
$ensure_account = $::zookeeper::params::ensure_account,
$ensure_cron = $::zookeeper::params::ensure_cron,
$group = $::zookeeper::params::group,
$system_group = $::zookeeper::params::system_group,
$packages = $::zookeeper::params::packages,
$shell = $::zookeeper::params::shell,
$user = $::zookeeper::params::user,
$system_user = $::zookeeper::params::system_user,
# installation options
$archive_checksum = $::zookeeper::params::archive_checksum,
$archive_dl_site = $::zookeeper::params::archive_dl_site,
$archive_dl_timeout = $::zookeeper::params::archive_dl_timeout,
$archive_dl_url = $::zookeeper::params::archive_dl_url,
$archive_install_dir = $::zookeeper::params::archive_install_dir,
$archive_symlink = $::zookeeper::params::archive_symlink,
$archive_symlink_name = $::zookeeper::params::archive_symlink_name,
$archive_version = $::zookeeper::params::archive_version,
$cdhver = $::zookeeper::params::cdhver,
$install_java = $::zookeeper::params::install_java,
$install_method = $::zookeeper::params::install_method,
$java_bin = $::zookeeper::params::java_bin,
$java_opts = $::zookeeper::params::java_opts,
$java_package = $::zookeeper::params::java_package,
$repo = $::zookeeper::params::repo,
# service options
$manage_service = $::zookeeper::params::manage_service,
$manage_service_file = $::zookeeper::params::manage_service_file,
$pid_dir = $::zookeeper::params::pid_dir,
$pid_file = $::zookeeper::params::pid_file,
+ $restart_on_change = $::zookeeper::params::restart_on_change,
$service_ensure = $::zookeeper::params::service_ensure,
$service_name = $::zookeeper::params::service_name,
$service_provider = $::zookeeper::params::service_provider,
$systemd_unit_want = $::zookeeper::params::systemd_unit_want,
$systemd_unit_after = $::zookeeper::params::systemd_unit_after,
$zk_dir = $::zookeeper::params::zk_dir,
# zookeeper config
$cfg_dir = $::zookeeper::params::cfg_dir,
$cleanup_sh = $::zookeeper::params::cleanup_sh,
$client_ip = $::zookeeper::params::client_ip,
$client_port = $::zookeeper::params::client_port,
$datastore = $::zookeeper::params::datastore,
$datalogstore = $::zookeeper::params::datalogstore,
$election_port = $::zookeeper::params::election_port,
$export_tag = $::zookeeper::params::export_tag,
$id = $::zookeeper::params::id,
$init_limit = $::zookeeper::params::init_limit,
$initialize_datastore = $::zookeeper::params::initialize_datastore,
$leader = $::zookeeper::params::leader,
$leader_port = $::zookeeper::params::leader_port,
$log_dir = $::zookeeper::params::log_dir,
$manual_clean = $::zookeeper::params::manual_clean,
$max_session_timeout = $::zookeeper::params::max_session_timeout,
$min_session_timeout = $::zookeeper::params::min_session_timeout,
$observers = $::zookeeper::params::observers,
$purge_interval = $::zookeeper::params::purge_interval,
$servers = $::zookeeper::params::servers,
$snap_count = $::zookeeper::params::snap_count,
$snap_retain_count = $::zookeeper::params::snap_retain_count,
$sync_limit = $::zookeeper::params::sync_limit,
$tick_time = $::zookeeper::params::tick_time,
$use_sasl_auth = $::zookeeper::params::use_sasl_auth,
$zoo_dir = $::zookeeper::params::zoo_dir,
$zoo_main = $::zookeeper::params::zoo_main,
# log4j properties
$environment_file = $::zookeeper::params::environment_file,
$log4j_prop = $::zookeeper::params::log4j_prop,
$max_allowed_connections = $::zookeeper::params::max_allowed_connections,
$peer_type = $::zookeeper::params::peer_type,
$rollingfile_threshold = $::zookeeper::params::rollingfile_threshold,
$tracefile_threshold = $::zookeeper::params::tracefile_threshold,
$console_threshold = $::zookeeper::params::console_threshold,
# sasl options
$keytab_path = $::zookeeper::params::keytab_path,
$principal = $::zookeeper::params::principal,
$realm = $::zookeeper::params::realm,
$store_key = $::zookeeper::params::store_key,
$use_keytab = $::zookeeper::params::use_keytab,
$use_ticket_cache = $::zookeeper::params::use_ticket_cache
) inherits ::zookeeper::params {
# validations are not necessary on Puppet 4
if versioncmp($::puppetversion, '4.0.0') < 0 {
validate_array($packages)
validate_bool($ensure_cron)
validate_bool($install_java)
validate_bool($initialize_datastore)
validate_bool($manage_service)
validate_bool($use_sasl_auth)
validate_hash($archive_checksum)
validate_integer($id)
validate_integer($init_limit)
validate_integer($leader_port)
validate_integer($snap_count)
validate_integer($snap_retain_count)
validate_integer($sync_limit)
validate_integer($tick_time)
}
if $pid_file {
$pid_path = $pid_file
} else {
$pid_path = "${pid_dir}/zookeeper.pid"
}
$repo_source = is_hash($repo) ? {
true => 'custom',
false => $repo
}
if $::zookeeper::ensure_account {
group { $group:
ensure => $ensure_account,
system => $system_group,
}
user { $user:
ensure => $ensure_account,
home => $datastore,
comment => 'Zookeeper',
gid => $group,
shell => $shell,
system => $system_user,
require => Group[$group],
}
}
anchor { 'zookeeper::start': }
-> class { 'zookeeper::install': }
-> class { 'zookeeper::config': }
if ($use_sasl_auth) {
class { 'zookeeper::sasl':
require => Class['::zookeeper::config'],
before => Class['::zookeeper::service'],
}
}
if ($manage_service) and ($service_provider != 'exhibitor') {
class { 'zookeeper::service':
require => Class['::zookeeper::config'],
before => Anchor['zookeeper::end'],
}
}
anchor { 'zookeeper::end': }
}
diff --git a/manifests/params.pp b/manifests/params.pp
index b66545d..2710e75 100644
--- a/manifests/params.pp
+++ b/manifests/params.pp
@@ -1,148 +1,149 @@
# OS specific configuration should be defined here
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::params {
$_defaults = {
'packages' => ['zookeeper'],
}
case $::osfamily {
'Debian': {
case $::operatingsystem {
'Debian': {
case $::operatingsystemmajrelease {
'7': { $initstyle = 'init' }
'8': { $initstyle = 'systemd' }
default: { $initstyle = undef }
}
}
'Ubuntu': {
case $::operatingsystemmajrelease {
'14.04': { $initstyle = 'upstart' }
default: { $initstyle = undef }
}
}
default: { $initstyle = undef }
}
$_os_overrides = {
'packages' => ['zookeeper', 'zookeeperd'],
'service_name' => 'zookeeper',
'service_provider' => $initstyle,
'shell' => '/bin/false',
}
# 'environment' file probably read just by Debian
# see #16, #81
$environment_file = 'environment'
}
'RedHat': {
case $::operatingsystemmajrelease {
'6': { $initstyle = 'redhat' }
'7': { $initstyle = 'systemd' }
default: { $initstyle = undef }
}
$_os_overrides = {
'packages' => ['zookeeper', 'zookeeper-server'],
'service_name' => 'zookeeper-server',
'service_provider' => $initstyle,
'shell' => '/sbin/nologin',
}
$environment_file = 'java.env'
}
default: {
fail("Module '${module_name}' is not supported on OS: '${::operatingsystem}', family: '${::osfamily}'")
}
}
$_params = merge($_defaults, $_os_overrides)
# meta options
$ensure = present
$ensure_account = present
$ensure_cron = true
$group = 'zookeeper'
$system_group = false
$packages = $_params['packages']
$shell = $_params['shell']
$user = 'zookeeper'
$system_user = false
# installation options
$archive_checksum = {}
$archive_dl_site = 'http://apache.org/dist/zookeeper'
$archive_dl_timeout = 600
$archive_dl_url = undef
$archive_install_dir = '/opt'
$archive_symlink = true
$archive_symlink_name = "${archive_install_dir}/zookeeper"
$archive_version = '3.4.8'
$cdhver = undef
$install_java = false
$install_method = 'package'
$java_bin = '/usr/bin/java'
$java_opts = ''
$java_package = undef
$repo = undef
# service options
$manage_service = true
$manage_service_file = false
$pid_dir = '/var/run'
$pid_file = undef
+ $restart_on_change = true
$service_ensure = 'running'
$service_name = $_params['service_name']
$service_provider = $_params['service_provider']
# systemd_unit_want and _after can be overridden to
# donate the matching directives in the [Unit] section
$systemd_unit_want = undef
$systemd_unit_after = 'network.target'
$zk_dir = '/etc/zookeeper'
# zookeeper config
$cfg_dir = '/etc/zookeeper/conf'
$cleanup_sh = '/usr/share/zookeeper/bin/zkCleanup.sh'
$client_ip = undef # use e.g. $::ipaddress if you want to bind to single interface
$client_port = 2181
$datastore = '/var/lib/zookeeper'
# datalogstore used to put transaction logs in separate location than snapshots
$datalogstore = undef
$election_port = 2888
$export_tag = 'zookeeper'
$id = '1'
$init_limit = 10
$initialize_datastore = false
$leader = true
$leader_port = 3888
$log_dir = '/var/log/zookeeper'
$manual_clean = false
$max_allowed_connections = undef
$max_session_timeout = undef
$min_session_timeout = undef
$observers = []
# interval in hours, purging enabled when >= 1
$purge_interval = 0
$servers = []
$snap_count = 10000
# since zookeeper 3.4, for earlier version cron task might be used
$snap_retain_count = 3
$sync_limit = 5
$tick_time = 2000
$use_sasl_auth = false
$zoo_dir = '/usr/lib/zookeeper'
$zoo_main = 'org.apache.zookeeper.server.quorum.QuorumPeerMain'
# log4j properties
$log4j_prop = 'INFO,ROLLINGFILE'
$peer_type = 'UNSET'
$rollingfile_threshold = 'INFO'
$console_threshold = 'INFO'
$tracefile_threshold = 'TRACE'
# sasl options
$keytab_path = '/etc/zookeeper/conf/zookeeper.keytab'
$principal = "zookeeper/${::fqdn}"
$realm = $::domain
$store_key = true
$use_keytab = true
$use_ticket_cache = false
}
diff --git a/manifests/service.pp b/manifests/service.pp
index 59471d7..4a1fc56 100644
--- a/manifests/service.pp
+++ b/manifests/service.pp
@@ -1,56 +1,59 @@
# Class: zookeeper::service
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::service {
require ::zookeeper::install
case $::zookeeper::install_method {
'archive': {
$_zoo_dir = "${::zookeeper::archive_install_dir}/${module_name}-${::zookeeper::archive_version}"
}
'package': {
$_zoo_dir = $::zookeeper::zoo_dir
}
default: {
fail("Install method '${::zookeeper::install_method}' is not supported.")
}
}
if $::zookeeper::manage_service_file == true {
if $::zookeeper::service_provider == 'systemd' {
file { "/usr/lib/systemd/system/${::zookeeper::service_name}.service":
ensure => 'present',
content => template("${module_name}/zookeeper.service.erb"),
}
~> exec { 'systemctl daemon-reload # for zookeeper':
refreshonly => true,
path => $::path,
notify => Service[$::zookeeper::service_name]
}
} elsif ( $::zookeeper::service_provider == 'init' or $::zookeeper::service_provider == 'redhat') {
file {"/etc/init.d/${::zookeeper::service_name}":
ensure => present,
content => template("${module_name}/zookeeper.${::osfamily}.init.erb"),
mode => '0755',
before => Service[$::zookeeper::service_name],
notify => Service[$::zookeeper::service_name]
}
}
}
service { $::zookeeper::service_name:
ensure => $::zookeeper::service_ensure,
hasstatus => true,
hasrestart => true,
provider => $::zookeeper::service_provider,
enable => true,
require => [
Class['::zookeeper::install'],
File["${::zookeeper::cfg_dir}/zoo.cfg"]
],
- subscribe => [
- File["${::zookeeper::cfg_dir}/myid"], File["${::zookeeper::cfg_dir}/zoo.cfg"],
- File["${::zookeeper::cfg_dir}/${::zookeeper::environment_file}"], File["${::zookeeper::cfg_dir}/log4j.properties"],
- ]
+ }
+
+ if $::zookeeper::restart_on_change {
+ File["${::zookeeper::cfg_dir}/myid"] ~> Service[$::zookeeper::service_name]
+ File["${::zookeeper::cfg_dir}/zoo.cfg"] ~> Service[$::zookeeper::service_name]
+ File["${::zookeeper::cfg_dir}/${::zookeeper::environment_file}"] ~> Service[$::zookeeper::service_name]
+ File["${::zookeeper::cfg_dir}/log4j.properties"] ~> Service[$::zookeeper::service_name]
}
}
diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb
index 3c2f32f..dcda658 100644
--- a/spec/classes/init_spec.rb
+++ b/spec/classes/init_spec.rb
@@ -1,343 +1,362 @@
require 'spec_helper'
describe 'zookeeper', :type => :class do
let(:facts) do
{
:operatingsystem => 'Debian',
:osfamily => 'Debian',
:lsbdistcodename => 'wheezy',
:operatingsystemmajrelease => '7',
:ipaddress => '192.168.1.1',
:puppetversion => Puppet.version,
}
end
it { is_expected.to contain_class('zookeeper::config') }
it { is_expected.to contain_class('zookeeper::install') }
it { is_expected.to contain_class('zookeeper::service') }
it { is_expected.to compile.with_all_deps }
+ it { is_expected.to contain_service('zookeeper') }
+ it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/myid]') }
+ it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/zoo.cfg]') }
+ it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/environment]') }
+ it { is_expected.to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/log4j.properties]') }
+
+ context 'skip service restart' do
+ let(:params) do
+ {
+ :restart_on_change => false,
+ }
+ end
+
+ it { is_expected.to contain_service('zookeeper') }
+ it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/myid]') }
+ it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/zoo.cfg]') }
+ it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/environment]') }
+ it { is_expected.not_to contain_service('zookeeper').that_subscribes_to('File[/etc/zookeeper/conf/log4j.properties]') }
+ end
context 'allow installing multiple packages' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
let(:params) do
{
:packages => [ 'zookeeper', 'zookeeper-bin' ],
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
it { is_expected.to contain_package('zookeeper-bin').with({:ensure => 'present'}) }
it { is_expected.to contain_service('zookeeper').with({:ensure => 'running'}) }
# datastore exec is not included by default
it { is_expected.not_to contain_exec('initialize_datastore') }
it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
it { is_expected.to contain_group('zookeeper').with({:ensure => 'present'}) }
end
context 'Cloudera packaging' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
let(:params) do
{
:packages => ['zookeeper','zookeeper-server'],
:service_name => 'zookeeper-server',
:initialize_datastore => true
}
end
it { should contain_package('zookeeper').with({:ensure => 'present'}) }
it { should contain_package('zookeeper-server').with({:ensure => 'present'}) }
it { should contain_service('zookeeper-server').with({:ensure => 'running'}) }
it { should contain_exec('initialize_datastore') }
end
context 'setting minSessionTimeout' do
let(:params) do
{
:min_session_timeout => 3000
}
end
it do
should contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/minSessionTimeout=3000/)
end
end
context 'setting maxSessionTimeout' do
let(:params) do
{
:max_session_timeout => 60000
}
end
it do
should contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/maxSessionTimeout=60000/)
end
end
context 'disable service management' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
let(:params) do
{
:manage_service => false,
}
end
it { should contain_package('zookeeper').with({:ensure => 'present'}) }
it { should_not contain_service('zookeeper').with({:ensure => 'running'}) }
it { should_not contain_class('zookeeper::service') }
end
context 'use Cloudera RPM repo' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:hardwaremodel => 'x86_64',
:puppetversion => Puppet.version,
}
end
let(:params) do
{
:repo => 'cloudera',
:cdhver => '5',
}
end
it { should contain_class('zookeeper::install::repo') }
it { should contain_yumrepo('cloudera-cdh5') }
context 'custom RPM repo' do
let(:params) do
{
:repo => {
'name' => 'myrepo',
'url' => 'http://repo.url',
'descr' => 'custom repo',
},
:cdhver => '5',
}
end
it { should contain_yumrepo('myrepo').with({:baseurl => 'http://repo.url'}) }
end
end
context 'service provider' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
# provider is detected based on facts
context 'do not set provider by default' do
it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
it do
is_expected.to contain_service('zookeeper').with({
:ensure => 'running',
:provider => 'init',
})
end
end
context 'autodetect provider on RedHat 7' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '7',
:puppetversion => Puppet.version,
}
end
it { should contain_package('zookeeper').with({:ensure => 'present'}) }
it { should contain_package('zookeeper-server').with({:ensure => 'present'}) }
it do
should contain_service('zookeeper-server').with({
:ensure => 'running',
:provider => 'systemd',
})
end
end
it { should contain_class('zookeeper::service') }
end
context 'allow passing specific version' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemmajrelease => '14.04',
:lsbdistcodename => 'trusty',
:puppetversion => Puppet.version,
}
end
let(:version) {'3.4.5+dfsg-1'}
let(:params) do
{
:ensure => version,
}
end
it { is_expected.to contain_package('zookeeper').with({:ensure => version}) }
it { is_expected.to contain_package('zookeeperd').with({:ensure => version}) }
it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
end
context 'upstart is used on Ubuntu' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'Debian',
:operatingsystem => 'Ubuntu',
:operatingsystemmajrelease => '14.04',
:lsbdistcodename => 'trusty',
:puppetversion => Puppet.version,
}
end
let(:params) do
{
}
end
it { should contain_package('zookeeper').with({:ensure => 'present'}) }
it { should contain_package('zookeeperd').with({:ensure => 'present'}) }
it do
should contain_service('zookeeper').with({
:ensure => 'running',
:provider => 'upstart',
})
end
end
context 'set pid file for init provider' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '6',
:puppetversion => Puppet.version,
}
end
let(:params) do
{
:zoo_dir => '/usr/lib/zookeeper',
:log_dir => '/var/log/zookeeper',
:manage_service => true,
:manage_service_file => true,
:service_provider => 'init',
}
end
context 'set service provider' do
it { is_expected.to contain_package('zookeeper').with({:ensure => 'present'}) }
it do
is_expected.to contain_service('zookeeper-server').with({
:ensure => 'running',
:provider => 'init',
})
end
end
it do
is_expected.to contain_file(
'/etc/init.d/zookeeper-server'
).with_content(/pidfile=\/var\/run\/zookeeper.pid/)
end
end
context 'create env file' do
let(:user) { 'zookeeper' }
let(:group) { 'zookeeper' }
context 'on RedHat' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'RedHat',
:operatingsystemmajrelease => '6',
:puppetversion => Puppet.version,
}
end
it do
is_expected.to contain_file(
'/etc/zookeeper/conf/java.env'
)
end
end
context 'on Debian' do
let(:facts) do
{
:ipaddress => '192.168.1.1',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:lsbdistcodename => 'jessie',
:operatingsystemmajrelease => '8',
:puppetversion => Puppet.version,
}
end
it do
is_expected.to contain_file(
'/etc/zookeeper/conf/environment'
)
end
end
end
context 'managed by exhibitor' do
let(:params) do
{
:service_provider => 'exhibitor',
:service_name => 'zookeeper',
:cfg_dir => '/opt/zookeeper/conf',
}
end
it { is_expected.not_to contain_class('zookeeper::service') }
it { is_expected.not_to contain_service('zookeeper') }
it { is_expected.not_to contain_file('/opt/zookeeper/conf/zoo.cfg') }
it { is_expected.not_to contain_file('/opt/zookeeper/conf/myid') }
end
context 'install from archive' do
let(:params) do
{
install_method: 'archive',
archive_version: '3.4.9',
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('Zookeeper::Install::Archive') }
it { is_expected.not_to contain_package('zookeeper').with({:ensure => 'present'}) }
it { is_expected.to contain_service('zookeeper').with({:ensure => 'running'}) }
it { is_expected.to contain_user('zookeeper').with({:ensure => 'present'}) }
it { is_expected.to contain_group('zookeeper').with({:ensure => 'present'}) }
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Aug 18, 7:55 PM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3327448
Attached To
R146 puppet-deric-zookeeper
Event Timeline
Log In to Comment