diff --git a/manifests/config.pp b/manifests/config.pp index 7f60614..1f5e46f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,90 +1,89 @@ # Class: zookeeper::config # # This module manages the configuration directories # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::config inherits zookeeper { - file { $zookeeper::cfg_dir: ensure => directory, owner => $zookeeper::user, group => $zookeeper::group, recurse => true, mode => '0644', } file { $zookeeper::log_dir: ensure => directory, owner => $zookeeper::user, group => $zookeeper::group, recurse => false, mode => '0644', } file { $zookeeper::datastore: ensure => directory, owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', recurse => false, # intentionally, puppet run would take too long #41 } if $zookeeper::datalogstore { file { $zookeeper::datalogstore: ensure => directory, owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', recurse => false, # intentionally, puppet run would take too long #41 } } if $zookeeper::service_provider != 'exhibitor' { file { "${zookeeper::cfg_dir}/zoo.cfg": owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', content => template("${module_name}/conf/zoo.cfg.erb"), } # we should notify Class['::zookeeper::service'] however it's not configured # at this point (first run), so we have to subscribe from service declaration file { "${zookeeper::cfg_dir}/myid": ensure => file, content => template("${module_name}/conf/myid.erb"), owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', require => File[$zookeeper::cfg_dir], } file { "${zookeeper::datastore}/myid": ensure => 'link', target => "${zookeeper::cfg_dir}/myid", } } file { "${zookeeper::cfg_dir}/${zookeeper::environment_file}": owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', content => template("${module_name}/conf/environment.erb"), } file { "${zookeeper::cfg_dir}/log4j.properties": owner => $zookeeper::user, group => $zookeeper::group, mode => '0644', content => template("${module_name}/conf/log4j.properties.erb"), } # Initialize the datastore if required if $zookeeper::initialize_datastore { exec { 'initialize_datastore': command => "${zookeeper::initialize_datastore_bin} --myid=${zookeeper::id}", user => $zookeeper::user, creates => "${zookeeper::datastore}/version-2", - require => [ File[$zookeeper::datastore], Class['zookeeper::install'] ], + require => [File[$zookeeper::datastore], Class['zookeeper::install']], } } } diff --git a/manifests/init.pp b/manifests/init.pp index d8ce756..04f4198 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,163 +1,165 @@ # Class: zookeeper # # This module manages ZooKeeper installation # # # Parameters: # * [global_outstanding_limit] Clients can submit requests faster than ZooKeeper can process them, # especially if there are a lot of clients. To prevent ZooKeeper from running out of memory due to # queued requests, ZooKeeper will throttle clients so that there is no more than globalOutstandingLimit # outstanding requests in the system # # # * [whitelist_4lw] Fine grained control over the set of commands ZooKeeper can execute # # whitelist_4lw = ['stat','ruok'] # -class zookeeper( +class zookeeper ( # meta options - String $ensure = $zookeeper::params::ensure, - Variant[Boolean,String] $ensure_account = $zookeeper::params::ensure_account, - Boolean $ensure_cron = $zookeeper::params::ensure_cron, - String $group = $zookeeper::params::group, - Boolean $system_group = $zookeeper::params::system_group, - Array[String] $packages = $zookeeper::params::packages, - String $shell = $zookeeper::params::shell, - String $user = $zookeeper::params::user, - Boolean $system_user = $zookeeper::params::system_user, + String $ensure = $zookeeper::params::ensure, + Variant[Boolean,String] $ensure_account = $zookeeper::params::ensure_account, + Boolean $ensure_cron = $zookeeper::params::ensure_cron, + String $group = $zookeeper::params::group, + Boolean $system_group = $zookeeper::params::system_group, + Array[String] $packages = $zookeeper::params::packages, + String $shell = $zookeeper::params::shell, + String $user = $zookeeper::params::user, + Boolean $system_user = $zookeeper::params::system_user, # installation options - Hash $archive_checksum = $zookeeper::params::archive_checksum, - Optional[String] $archive_dl_site = $zookeeper::params::archive_dl_site, - Integer $archive_dl_timeout = $zookeeper::params::archive_dl_timeout, - Optional[String] $archive_dl_url = $zookeeper::params::archive_dl_url, - String $archive_install_dir = $zookeeper::params::archive_install_dir, - Boolean $archive_symlink = $zookeeper::params::archive_symlink, - String $archive_symlink_name = $zookeeper::params::archive_symlink_name, - String $archive_version = $zookeeper::params::archive_version, - Optional[String] $proxy_server = $zookeeper::params::proxy_server, - Optional[String] $proxy_type = $zookeeper::params::proxy_type, - Optional[String] $cdhver = $zookeeper::params::cdhver, - Boolean $install_java = $zookeeper::params::install_java, - String $install_method = $zookeeper::params::install_method, - String $java_bin = $zookeeper::params::java_bin, - String $java_opts = $zookeeper::params::java_opts, - Optional[String] $java_package = $zookeeper::params::java_package, - Optional[Hash] $repo = $zookeeper::params::repo, + Hash $archive_checksum = $zookeeper::params::archive_checksum, + Optional[String] $archive_dl_site = $zookeeper::params::archive_dl_site, + Integer $archive_dl_timeout = $zookeeper::params::archive_dl_timeout, + Optional[String] $archive_dl_url = $zookeeper::params::archive_dl_url, + String $archive_install_dir = $zookeeper::params::archive_install_dir, + Boolean $archive_symlink = $zookeeper::params::archive_symlink, + String $archive_symlink_name = $zookeeper::params::archive_symlink_name, + String $archive_version = $zookeeper::params::archive_version, + Optional[String] $proxy_server = $zookeeper::params::proxy_server, + Optional[String] $proxy_type = $zookeeper::params::proxy_type, + Optional[String] $cdhver = $zookeeper::params::cdhver, + Boolean $install_java = $zookeeper::params::install_java, + String $install_method = $zookeeper::params::install_method, + String $java_bin = $zookeeper::params::java_bin, + String $java_opts = $zookeeper::params::java_opts, + Optional[String] $java_package = $zookeeper::params::java_package, + Optional[Hash] $repo = $zookeeper::params::repo, # service options - Boolean $manage_service = $zookeeper::params::manage_service, - Boolean $manage_service_file = $zookeeper::params::manage_service_file, - String $pid_dir = $zookeeper::params::pid_dir, - Optional[String] $pid_file = $zookeeper::params::pid_file, - Boolean $restart_on_change = $zookeeper::params::restart_on_change, - String $service_ensure = $zookeeper::params::service_ensure, - String $service_name = $zookeeper::params::service_name, - Optional[String] $service_provider = $zookeeper::params::service_provider, - Optional[String] $systemd_unit_want = $zookeeper::params::systemd_unit_want, - String $systemd_unit_after = $zookeeper::params::systemd_unit_after, - String $systemd_path = $zookeeper::params::systemd_path, - String $zk_dir = $zookeeper::params::zk_dir, + Boolean $manage_service = $zookeeper::params::manage_service, + Boolean $manage_service_file = $zookeeper::params::manage_service_file, + String $pid_dir = $zookeeper::params::pid_dir, + Optional[String] $pid_file = $zookeeper::params::pid_file, + Boolean $restart_on_change = $zookeeper::params::restart_on_change, + String $service_ensure = $zookeeper::params::service_ensure, + String $service_name = $zookeeper::params::service_name, + Optional[String] $service_provider = $zookeeper::params::service_provider, + Optional[String] $systemd_unit_want = $zookeeper::params::systemd_unit_want, + String $systemd_unit_after = $zookeeper::params::systemd_unit_after, + String $systemd_path = $zookeeper::params::systemd_path, + String $zk_dir = $zookeeper::params::zk_dir, # zookeeper config - String $cfg_dir = $zookeeper::params::cfg_dir, - String $cleanup_sh = $zookeeper::params::cleanup_sh, - Optional[String] $client_ip = $zookeeper::params::client_ip, - Integer $client_port = $zookeeper::params::client_port, - Optional[Integer] $secure_client_port = $zookeeper::params::secure_client_port, - Optional[Boolean] $port_unification = $zookeeper::params::port_unification, - String $datastore = $zookeeper::params::datastore, - Optional[String] $datalogstore = $zookeeper::params::datalogstore, - Integer $election_port = $zookeeper::params::election_port, - String $export_tag = $zookeeper::params::export_tag, - String $id = $zookeeper::params::id, - Integer $init_limit = $zookeeper::params::init_limit, - Boolean $initialize_datastore = $zookeeper::params::initialize_datastore, - String $initialize_datastore_bin = $zookeeper::params::initialize_datastore_bin, - Boolean $leader = $zookeeper::params::leader, - Integer $leader_port = $zookeeper::params::leader_port, - String $log_dir = $zookeeper::params::log_dir, - Boolean $manual_clean = $zookeeper::params::manual_clean, - Optional[Integer] $max_session_timeout = $zookeeper::params::max_session_timeout, - Optional[Integer] $min_session_timeout = $zookeeper::params::min_session_timeout, - Array[String] $observers = $zookeeper::params::observers, - Integer $purge_interval = $zookeeper::params::purge_interval, - Variant[Array[String],Hash[String,String]] $servers = $zookeeper::params::servers, - Integer $pre_alloc_size = $zookeeper::params::pre_alloc_size, - Integer $snap_count = $zookeeper::params::snap_count, - Integer $snap_retain_count = $zookeeper::params::snap_retain_count, - Integer $sync_limit = $zookeeper::params::sync_limit, - Integer $tick_time = $zookeeper::params::tick_time, - Integer $global_outstanding_limit = $zookeeper::params::global_outstanding_limit, - Boolean $use_sasl_auth = $zookeeper::params::use_sasl_auth, - String $zoo_dir = $zookeeper::params::zoo_dir, - String $zoo_main = $zookeeper::params::zoo_main, - Boolean $quorum_listen_on_all_ips = $zookeeper::params::quorum_listen_on_all_ips, + String $cfg_dir = $zookeeper::params::cfg_dir, + String $cleanup_sh = $zookeeper::params::cleanup_sh, + Optional[String] $client_ip = $zookeeper::params::client_ip, + Integer $client_port = $zookeeper::params::client_port, + Optional[Integer] $secure_client_port = $zookeeper::params::secure_client_port, + Optional[Boolean] $port_unification = $zookeeper::params::port_unification, + String $datastore = $zookeeper::params::datastore, + Optional[String] $datalogstore = $zookeeper::params::datalogstore, + Integer $election_port = $zookeeper::params::election_port, + String $export_tag = $zookeeper::params::export_tag, + String $id = $zookeeper::params::id, + Integer $init_limit = $zookeeper::params::init_limit, + Boolean $initialize_datastore = $zookeeper::params::initialize_datastore, + String $initialize_datastore_bin = $zookeeper::params::initialize_datastore_bin, + Boolean $leader = $zookeeper::params::leader, + Integer $leader_port = $zookeeper::params::leader_port, + String $log_dir = $zookeeper::params::log_dir, + Boolean $manual_clean = $zookeeper::params::manual_clean, + Optional[Integer] $max_session_timeout = $zookeeper::params::max_session_timeout, + Optional[Integer] $min_session_timeout = $zookeeper::params::min_session_timeout, + Array[String] $observers = $zookeeper::params::observers, + Integer $purge_interval = $zookeeper::params::purge_interval, + Variant[Array[String],Hash[String,String]] $servers = $zookeeper::params::servers, + Integer $pre_alloc_size = $zookeeper::params::pre_alloc_size, + Integer $snap_count = $zookeeper::params::snap_count, + Integer $snap_retain_count = $zookeeper::params::snap_retain_count, + Integer $sync_limit = $zookeeper::params::sync_limit, + Integer $tick_time = $zookeeper::params::tick_time, + Integer $global_outstanding_limit = $zookeeper::params::global_outstanding_limit, + Boolean $use_sasl_auth = $zookeeper::params::use_sasl_auth, + String $zoo_dir = $zookeeper::params::zoo_dir, + String $zoo_main = $zookeeper::params::zoo_main, + Boolean $quorum_listen_on_all_ips = $zookeeper::params::quorum_listen_on_all_ips, # log4j properties - String $environment_file = $zookeeper::params::environment_file, - String $log4j_prop = $zookeeper::params::log4j_prop, - String $maxfilesize = $zookeeper::params::maxfilesize, - Integer $maxbackupindex = $zookeeper::params::maxbackupindex, - Optional[Integer] $max_allowed_connections = $zookeeper::params::max_allowed_connections, - String $peer_type = $zookeeper::params::peer_type, - String $rollingfile_threshold = $zookeeper::params::rollingfile_threshold, - String $tracefile_threshold = $zookeeper::params::tracefile_threshold, - String $console_threshold = $zookeeper::params::console_threshold, - Hash[String,Hash[String,String]] $extra_appenders = $zookeeper::params::extra_appenders, + String $environment_file = $zookeeper::params::environment_file, + String $log4j_prop = $zookeeper::params::log4j_prop, + String $maxfilesize = $zookeeper::params::maxfilesize, + Integer $maxbackupindex = $zookeeper::params::maxbackupindex, + Optional[Integer] $max_allowed_connections = $zookeeper::params::max_allowed_connections, + String $peer_type = $zookeeper::params::peer_type, + String $rollingfile_threshold = $zookeeper::params::rollingfile_threshold, + String $tracefile_threshold = $zookeeper::params::tracefile_threshold, + String $console_threshold = $zookeeper::params::console_threshold, + Hash[String,Hash[String,String]] $extra_appenders = $zookeeper::params::extra_appenders, # sasl options - Hash[String, String] $sasl_users = $zookeeper::params::sasl_users, - String $keytab_path = $zookeeper::params::keytab_path, - String $principal = $zookeeper::params::principal, - String $realm = $zookeeper::params::realm, - Boolean $sasl_krb5 = $zookeeper::params::sasl_krb5, - Boolean $store_key = $zookeeper::params::store_key, - Boolean $use_keytab = $zookeeper::params::use_keytab, - Boolean $use_ticket_cache = $zookeeper::params::use_ticket_cache, - Boolean $remove_host_principal = $zookeeper::params::remove_host_principal, - Boolean $remove_realm_principal = $zookeeper::params::remove_realm_principal, + Hash[String, String] $sasl_users = $zookeeper::params::sasl_users, + String $keytab_path = $zookeeper::params::keytab_path, + String $principal = $zookeeper::params::principal, + String $realm = $zookeeper::params::realm, + Boolean $sasl_krb5 = $zookeeper::params::sasl_krb5, + Boolean $store_key = $zookeeper::params::store_key, + Boolean $use_keytab = $zookeeper::params::use_keytab, + Boolean $use_ticket_cache = $zookeeper::params::use_ticket_cache, + Boolean $remove_host_principal = $zookeeper::params::remove_host_principal, + Boolean $remove_realm_principal = $zookeeper::params::remove_realm_principal, # four letter words whitelist - Array[String] $whitelist_4lw = $zookeeper::params::whitelist_4lw, -) inherits ::zookeeper::params { - + Array[String] $whitelist_4lw = $zookeeper::params::whitelist_4lw, + # Metrics Providers + Optional[String] $metrics_provider_classname = $zookeeper::params::metrics_provider_classname, + Integer $metrics_provider_http_port = $zookeeper::params::metrics_provider_http_port, + Boolean $metrics_provider_export_jvm_info = $zookeeper::params::metrics_provider_export_jvm_info, +) inherits zookeeper::params { if $pid_file { $pid_path = $pid_file } else { $pid_path = "${pid_dir}/zookeeper.pid" } 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], } } include zookeeper::install include zookeeper::config anchor { 'zookeeper::start': } -> Class['zookeeper::install'] -> Class['zookeeper::config'] if ($use_sasl_auth) { include zookeeper::sasl Class['zookeeper::config'] -> Class['zookeeper::sasl'] -> Class['zookeeper::service'] } if ($manage_service) and ($service_provider != 'exhibitor') { include zookeeper::service Class['zookeeper::config'] -> Class['zookeeper::service'] -> Anchor['zookeeper::end'] } anchor { 'zookeeper::end': } - } diff --git a/manifests/install.pp b/manifests/install.pp index eaa5153..aaacafc 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -1,66 +1,68 @@ # Class: zookeeper::install # # This module manages installation tasks. # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::install inherits zookeeper { anchor { 'zookeeper::install::begin': } $os_family = $facts['os']['family'] # Java installation if ($zookeeper::install_java) { if !$zookeeper::java_package { fail('Java installation is required, but no java package was provided.') } validate_string($zookeeper::java_package) # Make sure the Java package is only installed once. anchor { 'zookeeper::install::java': } ensure_resource('package', $zookeeper::java_package, - {'ensure' => $zookeeper::ensure, 'allow_virtual' => true, - 'before' => Anchor['zookeeper::install::intermediate'], - 'require' => Anchor['zookeeper::install::begin']} + { 'ensure' => $zookeeper::ensure, + 'allow_virtual' => true, + 'before' => Anchor['zookeeper::install::intermediate'], + 'require' => Anchor['zookeeper::install::begin'] + } ) } anchor { 'zookeeper::install::intermediate': } # Package installation case $zookeeper::install_method { 'archive': { include zookeeper::install::archive Anchor['zookeeper::install::intermediate'] -> Class['zookeeper::install::archive'] -> Anchor['zookeeper::install::end'] } 'package': { # Repo management case $os_family { 'RedHat', 'Suse': { include zookeeper::install::repo Anchor['zookeeper::install::begin'] -> Class['zookeeper::install::repo'] } default: {} # nothing to do } include zookeeper::install::package Anchor['zookeeper::install::intermediate'] -> Class['zookeeper::install::package'] -> Anchor['zookeeper::install::end'] } default: { fail('Valid installation methods are `package` or `archive`') } } anchor { 'zookeeper::install::end': } # Post installation tasks class { 'zookeeper::post_install': require => Anchor['zookeeper::install::end'], } } diff --git a/manifests/install/archive.pp b/manifests/install/archive.pp index 653790c..d50e33a 100644 --- a/manifests/install/archive.pp +++ b/manifests/install/archive.pp @@ -1,82 +1,80 @@ # Class: zookeeper::install::archive # # This module manages archive installation # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::install::archive inherits zookeeper::install { - - # Apache updated the filename base for archive files in release 3.5.5 if versioncmp($zookeeper::archive_version, '3.5.5') >= 0 { $filename = "apache-${module_name}-${zookeeper::archive_version}-bin" $archive_dl_site = $zookeeper::archive_dl_site ? { undef => 'http://apache.org/dist/zookeeper', default => $zookeeper::archive_dl_site, } } else { $filename = "${module_name}-${zookeeper::archive_version}" $archive_dl_site = $zookeeper::archive_dl_site ? { undef => 'http://archive.apache.org/dist/zookeeper', default => $zookeeper::archive_dl_site, } } $download_url = $zookeeper::archive_dl_url ? { undef => "${archive_dl_site}/${module_name}-${zookeeper::archive_version}/${filename}.tar.gz", default => $zookeeper::archive_dl_url, } $archive_file = "${zookeeper::archive_install_dir}/${filename}.tar.gz" archive { $archive_file: ensure => present, user => 'root', group => 'root', source => $download_url, checksum => $zookeeper::archive_checksum['hash'], checksum_type => $zookeeper::archive_checksum['type'], extract_path => $zookeeper::archive_install_dir, # Extract files as the user doing the extracting, which is the user # that runs Puppet, usually root extract_flags => '-x --no-same-owner -f', creates => "${zookeeper::archive_install_dir}/${filename}", extract => true, cleanup => true, notify => Exec['chown_zookeeper_directory'], } if $zookeeper::proxy_server { Archive<| title == $archive_file |> { proxy_server => $zookeeper::proxy_server, proxy_type => $zookeeper::proxy_type, } } $symlink_require = Archive["${zookeeper::archive_install_dir}/${filename}.tar.gz"] exec { 'chown_zookeeper_directory': command => "chown -R ${zookeeper::user}:${zookeeper::group} ${zookeeper::archive_install_dir}/${filename}", path => ['/bin','/sbin'], refreshonly => true, require => $symlink_require, } if $zookeeper::archive_symlink { file { $zookeeper::archive_symlink_name: ensure => link, require => $symlink_require, target => "${zookeeper::archive_install_dir}/${filename}", owner => $zookeeper::user, group => $zookeeper::group, } } # directory is required for creating conf subdirectory if $zookeeper::zk_dir { file { $zookeeper::zk_dir: ensure => directory, owner => $zookeeper::user, group => $zookeeper::group, } } } diff --git a/manifests/install/package.pp b/manifests/install/package.pp index 2a1e49a..5639b65 100644 --- a/manifests/install/package.pp +++ b/manifests/install/package.pp @@ -1,17 +1,16 @@ # Class: zookeeper::install::package # # This module manages package installation # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::install::package inherits zookeeper::install { - # Allow installing multiple packages, like zookeeper, zookeeper-bin etc. - ensure_resource('package', $zookeeper::packages, {'ensure' => $zookeeper::ensure}) + ensure_resource('package', $zookeeper::packages, { 'ensure' => $zookeeper::ensure }) # Make sure, that service package was not installed earlier if ($zookeeper::service_provider == 'init.d' and (!member($zookeeper::packages, $zookeeper::service_package))) { package { [$zookeeper::service_package]: #init.d scripts for zookeeper ensure => $zookeeper::ensure, } } } diff --git a/manifests/params.pp b/manifests/params.pp index e1d2edd..418f369 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -1,188 +1,193 @@ # OS specific configuration should be defined here # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::params { $_defaults = { 'packages' => ['zookeeper'], } $os_family = $facts['os']['family'] $os_name = $facts['os']['name'] $os_release = $facts['os']['release']['major'] case $os_family { 'Debian': { case $os_name { 'Debian', 'Ubuntu': { $initstyle = 'systemd' } default: { $initstyle = undef } } $_os_overrides = { 'packages' => ['zookeeper', 'zookeeperd'], 'service_name' => 'zookeeper', 'service_provider' => $initstyle, 'shell' => '/bin/false', 'initialize_datastore_bin' => '/usr/bin/zookeeper-server-initialize' } # 'environment' file probably read just by Debian # see #16, #81 $environment_file = 'environment' } 'RedHat': { case $os_name { 'RedHat', 'CentOS': { if versioncmp($os_release, '7') < 0 { $initstyle = 'redhat' } else { $initstyle = 'systemd' } } default: { $initstyle = undef } } $_os_overrides = { 'packages' => ['zookeeper', 'zookeeper-server'], 'service_name' => 'zookeeper-server', 'service_provider' => $initstyle, 'shell' => '/sbin/nologin', 'initialize_datastore_bin' => '/usr/bin/zookeeper-server-initialize' } $environment_file = 'java.env' } 'Suse': { case $os_name { 'SLES': { $initstyle = 'systemd' } default: { $initstyle = undef } } $_os_overrides = { 'packages' => ['zookeeper', 'zookeeper-server'], 'service_name' => 'zookeeper-server', 'service_provider' => $initstyle, 'shell' => '/bin/false', 'initialize_datastore_bin' => '/usr/bin/zookeeper-server-initialize' } $environment_file = 'java.env' } default: { fail("Module '${module_name}' is not supported on OS: '${os_name}', family: '${os_family}'") } } $_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 = undef $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 = '5' $install_java = false $install_method = 'package' $java_bin = '/usr/bin/java' $java_opts = '' $java_package = undef $repo = undef $proxy_server = undef $proxy_type = 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' $systemd_path = '/etc/systemd/system' $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 $secure_client_port = undef $quorum_listen_on_all_ips = false $port_unification = undef $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 $initialize_datastore_bin = $_params['initialize_datastore_bin'] $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 = [] $pre_alloc_size = 65536 $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 $global_outstanding_limit = 1000 $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' $maxfilesize = '256MB' $maxbackupindex = 20 $extra_appenders = {} # sasl options $sasl_krb5 = true $sasl_users = {} $keytab_path = '/etc/zookeeper/conf/zookeeper.keytab' $principal = "zookeeper/${facts['networking']['fqdn']}" $realm = pick($trusted['domain'], $trusted['certname']) $store_key = true $use_keytab = true $use_ticket_cache = false $remove_host_principal = false $remove_realm_principal = false # whitelist of Four Letter Words commands, see https://zookeeper.apache.org/doc/r3.4.12/zookeeperAdmin.html#sc_zkCommands $whitelist_4lw = [] + + # Metrics Providers + $metrics_provider_classname = undef + $metrics_provider_http_port = 7000 + $metrics_provider_export_jvm_info = true } diff --git a/manifests/post_install.pp b/manifests/post_install.pp index 452f77e..67cd112 100644 --- a/manifests/post_install.pp +++ b/manifests/post_install.pp @@ -1,84 +1,84 @@ # Class: zookeeper::post_install # # In order to maintain compatibility with older releases, there are # some post-install task to ensure same behaviour on all platforms. # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::post_install inherits zookeeper { $os_family = $facts['os']['family'] $os_name = $facts['os']['name'] $os_release = $facts['os']['release']['major'] if ($zookeeper::manual_clean) { # User defined value $_clean = $zookeeper::manual_clean } else { # Autodetect: # Since ZooKeeper 3.4 there's no need for purging snapshots with cron case $os_family { 'Debian': { case $os_name { 'Debian', 'Ubuntu': { $_clean = false } default: { fail ("Family: '${os_family}' OS: '${os_name}' is not supported yet") } } } 'Redhat': { $_clean = false } default: { fail ("Family: '${os_family}' OS: '${os_name}' is not supported yet") } 'Suse': { case $os_name { 'SLES': { $_clean = false } default: { fail ("Family: '${os_family}' OS: '${os_name}' is not supported yet") } } } } } # If !$cleanup_count, then ensure this cron is absent. if ($_clean and $zookeeper::snap_retain_count > 0 and $zookeeper::ensure != 'absent') { - if ($zookeeper::ensure_cron){ + if ($zookeeper::ensure_cron) { include cron cron::job { 'zookeeper-cleanup': - ensure => present, - command => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}", - hour => 2, - minute => 42, - user => $zookeeper::user, + ensure => present, + command => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}", + hour => 2, + minute => 42, + user => $zookeeper::user, } - }else { + } else { file { '/etc/cron.daily/zkcleanup': - ensure => present, - content => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}", + ensure => file, + content => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}", } } } # Package removal - if($_clean and $zookeeper::ensure == 'absent'){ - if ($zookeeper::ensure_cron){ + if ($_clean and $zookeeper::ensure == 'absent') { + if ($zookeeper::ensure_cron) { class { 'cron': manage_package => false, } cron::job { 'zookeeper-cleanup': ensure => $zookeeper::ensure, } - }else{ + } else { file { '/etc/cron.daily/zkcleanup': ensure => $zookeeper::ensure, } } } } diff --git a/manifests/sasl.pp b/manifests/sasl.pp index 6ae2fd5..0642046 100644 --- a/manifests/sasl.pp +++ b/manifests/sasl.pp @@ -1,13 +1,13 @@ # Class: zookeeper::sasl # # This module manages Zookeeper sasl auth # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::sasl inherits zookeeper { - file{"${zookeeper::cfg_dir}/jaas.conf": - ensure => present, + file { "${zookeeper::cfg_dir}/jaas.conf": + ensure => file, owner => $zookeeper::user, group => $zookeeper::group, content => template("${module_name}/conf/jaas.conf.erb"), } } diff --git a/manifests/service.pp b/manifests/service.pp index 5ed07e8..ac7c8bc 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,64 +1,66 @@ # Class: zookeeper::service # # PRIVATE CLASS - do not use directly (use main `zookeeper` class). class zookeeper::service inherits zookeeper { - +# case $zookeeper::install_method { 'archive': { $_zoo_dir = "${zookeeper::archive_install_dir}/${module_name}" } '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' { + exec { 'systemctl daemon-reload # for zookeeper': + refreshonly => true, + path => $::path, + } + if $zookeeper::service_provider == 'systemd' { file { "${zookeeper::systemd_path}/${zookeeper::service_name}.service": - ensure => 'present', + ensure => file, content => template("${module_name}/zookeeper.service.erb"), - } - ~> exec { 'systemctl daemon-reload # for zookeeper': - refreshonly => true, - path => $::path, + notify => Exec['systemctl daemon-reload # for zookeeper'], } } elsif ( $zookeeper::service_provider == 'init' or $zookeeper::service_provider == 'redhat' - ) { + ) { file { "/etc/init.d/${zookeeper::service_name}": - ensure => present, + ensure => file, content => template("${module_name}/zookeeper.${facts['os']['family']}.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'], + Class['zookeeper::install'], File["${zookeeper::cfg_dir}/zoo.cfg"] ], } if $zookeeper::restart_on_change { File[$zookeeper::log_dir] ~> Service[$zookeeper::service_name] 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] - if $::zookeeper::manage_service_file and $zookeeper::service_provider == 'systemd' { - Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$::zookeeper::service_name] + + if $zookeeper::manage_service_file and $zookeeper::service_provider == 'systemd' { + Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$zookeeper::service_name] } } } diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 872da03..15f1718 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,626 +1,660 @@ require 'spec_helper' shared_examples 'zookeeper parameters' do |_os_facts, precond| # load class, handle custom params let :pre_condition do precond end it do is_expected.to contain_file(cfg_dir).with('ensure' => 'directory', 'owner' => user, 'group' => group) end it do is_expected.to contain_file(log_dir).with('ensure' => 'directory', 'owner' => user, 'group' => group) end it do is_expected.to contain_file(id_file).with('ensure' => 'file', 'owner' => user, 'group' => group).with_content(myid) end end shared_examples 'zookeeper common' do |os_facts| os_info = get_os_info(os_facts) environment_file = os_info[:environment_file] context 'extra parameters' do # set custom params let :pre_condition do 'class {"zookeeper": log4j_prop => "ERROR", snap_count => 15000, pre_alloc_size => 131072, }' end it do is_expected.to contain_file(environment_file).with_content(%r{ERROR}) is_expected.to contain_file(environment_file).with_content(%r{ZOOCFG}) # CLASSPATH won't be overriden for all install methods # is_expected.to contain_file(environment_file).with_content(%r{CLASSPATH}) end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{snapCount=15000}) end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{preAllocSize=131072}) end # leave the default value to be determined by ZooKeeper it 'does not set maxClientCnxns by default' do # due to problem with should_not not matching, we're using more complicated way is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{^#maxClientCnxns=}) end # by default do not set client IP address it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{^#clientPortAddress=}) end end - context 'install from archive' do - let :pre_condition do - 'class {"zookeeper": - install_method => "archive", - archive_version => "3.4.9", - }' - end - - it do - is_expected.to contain_file(environment_file).without_content(%r{CLASSPATH}) - end - end - context 'extra environment_file parameter' do # set custom params let :pre_condition do 'class {"zookeeper": log4j_prop => "ERROR", environment_file => "java.env", }' end it do is_expected.to contain_file('/etc/zookeeper/conf/java.env').with_content(%r{ERROR}) is_expected.not_to contain_file('/etc/zookeeper/environment') end end context 'max allowed connections' do let :pre_condition do 'class {"zookeeper": max_allowed_connections => 15, }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{maxClientCnxns=15}) end end context 'set client ip address' do let :pre_condition do 'class {"zookeeper": client_ip => "192.168.1.1", }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{clientPortAddress=192.168.1.1}) end end context 'setting tick time' do let :pre_condition do 'class {"zookeeper": tick_time => 3000, }' end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{tickTime=3000}) end end context 'setting init and sync limit' do let :pre_condition do 'class {"zookeeper": init_limit => 15, sync_limit => 10, }' end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{initLimit=15}) end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{syncLimit=10}) end end context 'setting leader' do let :pre_condition do 'class {"zookeeper": leader => false, }' end it do is_expected.to contain_file('/etc/zookeeper/conf/zoo.cfg').with_content(%r{leaderServes=no}) end end context 'myid link' do let :pre_condition do 'class {"zookeeper":}' end it do is_expected.to contain_file( '/var/lib/zookeeper/myid', ).with('ensure' => 'link', 'target' => '/etc/zookeeper/conf/myid') end end context 'without datalogstore parameter' do let :pre_condition do 'class {"zookeeper":}' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{# dataLogDir=/disk2/zookeeper}) end end context 'with datalogstore parameter' do let :pre_condition do 'class {"zookeeper": datalogstore => "/zookeeper/transaction/device", }' end let(:datalogstore) { '/zookeeper/transaction/device' } it do is_expected.to contain_file(datalogstore).with('ensure' => 'directory') end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{dataLogDir=/zookeeper/transaction/device}) end end context 'setting quorum of servers with custom ports' do let :pre_condition do 'class {"zookeeper": election_port => 3000, leader_port => 4000, servers => ["192.168.1.1", "192.168.1.2"], }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.1=192.168.1.1:3000:4000}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.2=192.168.1.2:3000:4000}) end end context 'setting quorum of servers with custom ports with servers as hash' do let :pre_condition do 'class {"zookeeper": election_port => 3000, leader_port => 4000, servers => {"12" => "192.168.1.1", "23" => "192.168.1.2"}, }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.12=192.168.1.1:3000:4000}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.23=192.168.1.2:3000:4000}) end end context 'setting quorum of servers with default ports' do let :pre_condition do 'class {"zookeeper": servers => ["192.168.1.1", "192.168.1.2"] }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.1=192.168.1.1:2888:3888}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.2=192.168.1.2:2888:3888}) end end context 'setting quorum of servers with default ports with servers as hash' do let :pre_condition do 'class {"zookeeper": servers => {"12" => "192.168.1.1", "23" => "192.168.1.2"}, }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.12=192.168.1.1:2888:3888}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.23=192.168.1.2:2888:3888}) end end context 'setting quorum of servers with default ports with observer' do let :pre_condition do 'class {"zookeeper": servers => ["192.168.1.1", "192.168.1.2", "192.168.1.3", "192.168.1.4", "192.168.1.5"], observers => ["192.168.1.4", "192.168.1.5"] }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.1=192.168.1.1:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.1=192.168.1.1:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.2=192.168.1.2:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.2=192.168.1.2:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.3=192.168.1.3:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.3=192.168.1.3:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.4=192.168.1.4:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.5=192.168.1.5:2888:3888:observer}) end end context 'setting quorum of servers with default ports with observer with servers as hash' do let :pre_condition do 'class {"zookeeper": servers => {"12" => "192.168.1.1", "23" => "192.168.1.2", "34" => "192.168.1.3", "45" => "192.168.1.4", "56" => "192.168.1.5"}, observers => ["192.168.1.4", "192.168.1.5"] }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.12=192.168.1.1:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.12=192.168.1.1:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.23=192.168.1.2:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.23=192.168.1.2:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.34=192.168.1.3:2888:3888}) end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.34=192.168.1.3:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.45=192.168.1.4:2888:3888:observer}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.56=192.168.1.5:2888:3888:observer}) end end context 'setting minSessionTimeout' do let :pre_condition do 'class {"zookeeper": min_session_timeout => 5000 }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{minSessionTimeout=5000}) end end context 'setting maxSessionTimeout' do let :pre_condition do 'class {"zookeeper": max_session_timeout => 50000 }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{maxSessionTimeout=50000}) end end context 'make sure port is not included in server IP/hostname' do let :pre_condition do 'class {"zookeeper": servers => ["192.168.1.1:2888", "192.168.1.2:2333"] }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.1=192.168.1.1:2888:3888}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{server.2=192.168.1.2:2888:3888}) end end context 'configure logging' do context 'by default set to INFO' do let :pre_condition do 'class {"zookeeper": }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/log4j.properties', ).with_content(%r{zookeeper.log.threshold=INFO}) end it do is_expected.to contain_file( '/etc/zookeeper/conf/log4j.properties', ).with_content(%r{zookeeper.console.threshold=INFO}) end end context 'allow changing rollingfile loglevel' do let :pre_condition do 'class {"zookeeper": rollingfile_threshold => "TRACE", }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/log4j.properties', ).with_content(%r{zookeeper.log.threshold=TRACE}) end end context 'allow changing console loglevel' do let :pre_condition do 'class {"zookeeper": console_threshold => "TRACE", }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/log4j.properties', ).with_content(%r{zookeeper.console.threshold=TRACE}) end end context 'allow changing tracefile loglevel' do let :pre_condition do 'class {"zookeeper": tracefile_threshold => "DEBUG", }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/log4j.properties', ).with_content(%r{log4j.appender.TRACEFILE.Threshold=DEBUG}) end end context 'setting 4lw whitelist' do let :pre_condition do 'class {"zookeeper": whitelist_4lw => ["ruok","stat"] }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{4lw.commands.whitelist=ruok,stat}) end end + context 'setting metrics provider' do + let :pre_condition do + 'class {"zookeeper": + metrics_provider_classname => "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider", + metrics_provider_http_port => 7007, + }' + end + + it do + is_expected.to contain_file( + '/etc/zookeeper/conf/zoo.cfg', + ).with_content(%r{^metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider}) + end + + it do + is_expected.to contain_file( + '/etc/zookeeper/conf/zoo.cfg', + ).with_content(%r{^metricsProvider.httpPort=7007}) + end + end + context 'set global outstanding limit' do let :pre_condition do 'class {"zookeeper": global_outstanding_limit => 2000 }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{globalOutstandingLimit=2000}) end end context 'set portUnification' do let :pre_condition do 'class {"zookeeper": port_unification => true }' end it do is_expected.to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{portUnification=true}) end end context 'default does not set portUnification' do let :pre_condition do 'class {"zookeeper":}' end it do is_expected.not_to contain_file( '/etc/zookeeper/conf/zoo.cfg', ).with_content(%r{portUnification}) end end end + context 'setting metrics provider' do + let :pre_condition do + 'class {"zookeeper": + metrics_provider_classname => "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider", + metrics_provider_http_port => 7007, + metrics_provider_export_jvm_info => false, + }' + end + + it do + is_expected.to contain_file( + '/etc/zookeeper/conf/zoo.cfg', + ).with_content(%r{metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider}) + end + + it do + is_expected.to contain_file( + '/etc/zookeeper/conf/zoo.cfg', + ).with_content(%r{metricsProvider.httpPort=7007}) + end + it do + is_expected.to contain_file( + '/etc/zookeeper/conf/zoo.cfg', + ).with_content(%r{metricsProvider.exportJvmInfo=false}) + end + end end describe 'zookeeper::config' do on_supported_os.each do |os, os_facts| os_facts[:os]['hardware'] = 'x86_64' context "on #{os}" do let(:facts) do os_facts.merge(ipaddress: '192.168.1.1') end context 'with default parameters' do let(:user) { 'zookeeper' } let(:group) { 'zookeeper' } let(:cfg_dir) { '/etc/zookeeper/conf' } let(:log_dir) { '/var/lib/zookeeper' } let(:id_file) { '/etc/zookeeper/conf/myid' } let(:myid) { %r{^1} } precond = 'class {"zookeeper": }' include_examples 'zookeeper parameters', os_facts, precond end context 'with custom parameters' do let(:user) { 'zoo' } let(:group) { 'zoo' } let(:cfg_dir) { '/var/lib/zookeeper/conf' } let(:log_dir) { '/var/lib/zookeeper/log' } let(:id_file) { '/var/lib/zookeeper/conf/myid' } let(:myid) { %r{^2} } # set custom params precond = 'class {"zookeeper": id => "2", user => "zoo", group => "zoo", cfg_dir => "/var/lib/zookeeper/conf", log_dir => "/var/lib/zookeeper/log", }' include_examples 'zookeeper parameters', os_facts, precond end include_examples 'zookeeper common', os_facts end end end diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 45263a1..1bf19ba 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -1,187 +1,187 @@ require 'spec_helper' shared_examples 'zookeeper::service' do |os_facts| let(:user) { 'zookeeper' } let(:group) { 'zookeeper' } os_info = get_os_info(os_facts) should_install_zookeeperd = os_info[:should_install_zookeeperd] service_name = os_info[:service_name] init_dir = os_info[:init_dir] init_provider = os_info[:init_provider] service_file = os_info[:service_file] case init_provider when 'systemd' context 'systemd' do let :pre_condition do 'class {"zookeeper": manage_service_file => true, service_provider => "systemd", systemd_path => "/usr/lib/systemd/system", zoo_dir => "/usr/lib/zookeeper", log_dir => "/var/log/zookeeper", }' end it { is_expected.to contain_package('zookeeper') } if should_install_zookeeperd it { is_expected.to contain_package('zookeeperd') } else it { is_expected.not_to contain_package('zookeeperd') } end it do is_expected.to contain_file( "/usr/lib/systemd/system/#{service_name}.service", - ).with('ensure' => 'present') + ).with('ensure' => 'file') end it do is_expected.to contain_file( "/usr/lib/systemd/system/#{service_name}.service", ).with_content(%r{CLASSPATH="/usr/lib/zookeeper/zookeeper.jar}) end it do is_expected.to contain_service(service_name).with( ensure: 'running', enable: true, ) end context 'install from archive' do let :pre_condition do 'class {"zookeeper": manage_service_file => true, install_method => "archive", archive_version => "3.4.9" }' end it do is_expected.to contain_file(service_file).with_content( %r{zookeeper-3\.4\.9\.jar}, ) end end context 'do not manage systemd' do let :pre_condition do 'class {"zookeeper": manage_service_file => false, zoo_dir => "/usr/lib/zookeeper", log_dir => "/var/log/zookeeper", }' end it do is_expected.not_to contain_file( '/usr/lib/systemd/system/zookeeper.service', ).with('ensure' => 'present') end it do - is_expected.not_to contain_file(service_file).with('ensure' => 'present') + is_expected.not_to contain_file(service_file).with('ensure' => 'file') end end context 'systemd dependencies' do let :pre_condition do 'class {"zookeeper": service_provider => "systemd", manage_service_file => true, manage_service => true, systemd_unit_after => "network-online.target openvpn-client@.service", systemd_unit_want => "network-online.target openvpn-client@.service", }' end it do - is_expected.to contain_file(service_file).with('ensure' => 'present') + is_expected.to contain_file(service_file).with('ensure' => 'file') end it do is_expected.to contain_file(service_file).with_content( %r{Wants=network-online.target openvpn-client@.service}, ) end it do is_expected.to contain_service(service_name).with( ensure: 'running', enable: true, ) end end end when 'init' context 'init' do let :pre_condition do 'class {"zookeeper": zoo_dir => "/usr/lib/zookeeper", log_dir => "/var/log/zookeeper", manage_service_file => true, service_provider => "init", }' end it do is_expected.to contain_file( '/etc/init.d/zookeeper', ).with('ensure' => 'present') end it do is_expected.to contain_service('zookeeper').with( ensure: 'running', enable: true, provider: 'init', ) end end context 'custom service name' do let :pre_condition do 'class {"zookeeper": manage_service_file => true, service_name => "my-zookeeper", }' end custom_service_file = if init_provider == 'systemd' "#{init_dir}/my-zookeeper.service" else "#{init_dir}/my-zookeeper" end it do - is_expected.to contain_file(custom_service_file).with('ensure' => 'present') + is_expected.to contain_file(custom_service_file).with('ensure' => 'file') end it do is_expected.to contain_service('my-zookeeper').with( ensure: 'running', enable: true, ) end end end end describe 'zookeeper::service' do on_supported_os.each do |os, os_facts| os_facts[:os]['hardware'] = 'x86_64' context "on #{os}" do let(:facts) do os_facts.merge(ipaddress: '192.168.1.1') end include_examples 'zookeeper::service', os_facts end end end diff --git a/templates/conf/zoo.cfg.erb b/templates/conf/zoo.cfg.erb index 3a9f819..8d5e7fd 100644 --- a/templates/conf/zoo.cfg.erb +++ b/templates/conf/zoo.cfg.erb @@ -1,151 +1,165 @@ # http://hadoop.apache.org/zookeeper/docs/current/zookeeperAdmin.html # The number of milliseconds of each tick tickTime=<%= scope.lookupvar("zookeeper::tick_time") %> # The number of ticks that the initial # synchronization phase can take initLimit=<%= scope.lookupvar("zookeeper::init_limit") %> # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=<%= scope.lookupvar("zookeeper::sync_limit") %> # ZooKeeper will throttle clients so that there is no more than globalOutstandingLimit outstanding requests in the system. globalOutstandingLimit=<%= scope.lookupvar('zookeeper::global_outstanding_limit') %> # the directory where the snapshot is stored. dataDir=<%= scope.lookupvar("zookeeper::datastore") %> # Place the dataLogDir to a separate physical disc for better performance <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::datalogstore")) -%> dataLogDir=<%= scope.lookupvar("zookeeper::datalogstore") %> <% else -%> # dataLogDir=/disk2/zookeeper <% end -%> # the port at which the clients will connect clientPort=<%= scope.lookupvar("zookeeper::client_port") %> # interface to bind <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::client_ip")) -%> clientPortAddress=<%= scope.lookupvar("zookeeper::client_ip") %> <% else -%> #clientPortAddress= <% end -%> # Supported since 3.5.1 <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::secure_client_port")) -%> secureClientPort=<%= scope.lookupvar("zookeeper::secure_client_port") %> <% else -%> #secureClientPort=2281 <% end -%> # Supported since 3.5.5 <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::port_unification")) -%> portUnification=<%= scope.lookupvar("zookeeper::port_unification") %> <% end -%> # specify all zookeeper servers # The first port is used by followers to connect to the leader # The second one is used for leader election #server.1=zookeeper1:2888:3888 #server.2=zookeeper2:2888:3888 #server.3=zookeeper3:2888:3888 <%- if scope.lookupvar("zookeeper::servers").is_a?(Hash) -%> <%- _servers = scope.lookupvar("zookeeper::servers") -%> <% else -%> <%# make sure @servers is a hash -%> <%- _servers = Hash.new -%> <%- scope.lookupvar("zookeeper::servers").map.each_with_index {|e, i| _servers[i + 1] = e } -%> <%- end -%> <%- _servers.each_pair do |id, host| -%> <%# make sure port is not included in hostname -%> <%- if host.index(':') -%> <%- host = host[0...(host.index(':'))] -%> <%- end -%> <%- if scope.lookupvar("zookeeper::observers").include? host -%> <%- observer_text=':observer' -%> <%- end -%> <%= "server.#{id}=#{host}:%s:%s%s" % [scope.lookupvar("zookeeper::election_port"), scope.lookupvar("zookeeper::leader_port"), observer_text ] %> <%- end -%> # Bind election_port and leader_port to all interfaces (0.0.0.0) quorumListenOnAllIPs=<%= scope.lookupvar("zookeeper::quorum_listen_on_all_ips") %> # To avoid seeks ZooKeeper allocates space in the transaction log file in # blocks of preAllocSize kilobytes. The default block size is 64M. One reason # for changing the size of the blocks is to reduce the block size if snapshots # are taken more often. (Also, see snapCount). preAllocSize=<%= scope.lookupvar("zookeeper::pre_alloc_size") %> # Clients can submit requests faster than ZooKeeper can process them, # especially if there are a lot of clients. To prevent ZooKeeper from running # out of memory due to queued requests, ZooKeeper will throttle clients so that # there is no more than globalOutstandingLimit outstanding requests in the # system. The default limit is 1,000.ZooKeeper logs transactions to a # transaction log. After snapCount transactions are written to a log file a # snapshot is started and a new transaction log file is started. The default # snapCount is 10,000. snapCount=<%= scope.lookupvar("zookeeper::snap_count") %> # If this option is defined, requests will be will logged to a trace file named # traceFile.year.month.day. #traceFile= # Leader accepts client connections. Default value is "yes". The leader machine # coordinates updates. For higher update throughput at thes slight expense of # read throughput the leader can be configured to not accept clients and focus # on coordination. <% if scope.lookupvar("zookeeper::leader") -%> leaderServes=yes <% else -%> leaderServes=no <% end -%> # Since 3.4.0: When enabled, ZooKeeper auto purge feature retains the autopurge. # snapRetainCount most recent snapshots and the corresponding transaction logs # in the dataDir and dataLogDir respectively and deletes the rest. # Defaults to 3. Minimum value is 3. autopurge.snapRetainCount=<%= scope.lookupvar("zookeeper::snap_retain_count") %> # Since 3.4.0: The time interval in hours for which the purge task has to be # triggered. Set to a positive integer (1 and above) to enable the auto purging. # Defaults to 0. autopurge.purgeInterval=<%= scope.lookupvar("zookeeper::purge_interval") %> # Maximum allowed connections <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::max_allowed_connections")) -%> maxClientCnxns=<%= scope.lookupvar("zookeeper::max_allowed_connections") %> <% else -%> #maxClientCnxns=60 <% end -%> <% if scope.lookupvar("zookeeper::peer_type") != 'UNSET' -%> # Zookeeper peer type peerType=<%= scope.lookupvar("zookeeper::peer_type") %> <% end -%> # The minimum session timeout in milliseconds that the server will allow the # client to negotiate. Defaults to 2 times the tickTime. <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::min_session_timeout")) -%> minSessionTimeout=<%= scope.lookupvar("zookeeper::min_session_timeout") %> <% else -%> #minSessionTimeout=2 <% end -%> # The maximum session timeout in milliseconds that the server will allow the # client to negotiate. Defaults to 20 times the tickTime. <% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::max_session_timeout")) -%> maxSessionTimeout=<%= scope.lookupvar("zookeeper::max_session_timeout") %> <% else -%> #maxSessionTimeout=20 <% end -%> <% if scope.lookupvar("zookeeper::use_sasl_auth") -%> # Enable SASL authentication and use the default provider/renew provided by cloudera authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider jaasLoginRenew=3600000 <% if scope.lookupvar("zookeeper::remove_host_principal") -%> kerberos.removeHostFromPrincipal=true <% end -%> <% if scope.lookupvar("zookeeper::remove_realm_principal") -%> kerberos.removeRealmFromPrincipal=true <% end -%> <% end -%> <% unless scope.lookupvar("zookeeper::whitelist_4lw").empty? -%> # Supported since 3.4.10 4lw.commands.whitelist=<%= scope.lookupvar("zookeeper::whitelist_4lw").join(',') %> <% end -%> + +# Supported since 3.6 +## Metrics Providers +# +# https://prometheus.io Metrics Exporter +<% unless [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::metrics_provider_classname")) -%> +metricsProvider.className=<%= scope.lookupvar("zookeeper::metrics_provider_classname") %> +metricsProvider.httpPort=<%= scope.lookupvar("zookeeper::metrics_provider_http_port") %> +metricsProvider.exportJvmInfo=<%= scope.lookupvar("zookeeper::metrics_provider_export_jvm_info") %> +<% else -%> +#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider +#metricsProvider.httpPort=7000 +#metricsProvider.exportJvmInfo=true +<% end -%>