diff --git a/.rubocop.yml b/.rubocop.yml index c2ebc88..d8796d0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,546 +1,550 @@ require: rubocop-rspec AllCops: # Puppet Server 5 defaults to jruby 1.7 so TargetRubyVersion must stay at 1.9 until we drop support for puppet 5 TargetRubyVersion: 1.9 Include: - ./**/*.rb Exclude: - files/**/* - vendor/**/* - .vendor/**/* - pkg/**/* - spec/fixtures/**/* - Gemfile - Rakefile - Guardfile - Vagrantfile Lint/ConditionPosition: Enabled: True Lint/ElseLayout: Enabled: True Lint/UnreachableCode: Enabled: True Lint/UselessComparison: Enabled: True Lint/EnsureReturn: Enabled: True Lint/HandleExceptions: Enabled: True Lint/LiteralInCondition: Enabled: True Lint/ShadowingOuterLocalVariable: Enabled: True Lint/LiteralInInterpolation: Enabled: True Style/HashSyntax: Enabled: True Style/RedundantReturn: Enabled: True Layout/EndOfLine: Enabled: False Lint/AmbiguousOperator: Enabled: True Lint/AssignmentInCondition: Enabled: True Layout/SpaceBeforeComment: Enabled: True Style/AndOr: Enabled: True Style/RedundantSelf: Enabled: True Metrics/BlockLength: Enabled: False # Method length is not necessarily an indicator of code quality Metrics/MethodLength: Enabled: False # Module length is not necessarily an indicator of code quality Metrics/ModuleLength: Enabled: False Style/WhileUntilModifier: Enabled: True Lint/AmbiguousRegexpLiteral: Enabled: True Security/Eval: Enabled: True Lint/BlockAlignment: Enabled: True Lint/DefEndAlignment: Enabled: True Lint/EndAlignment: Enabled: True Lint/DeprecatedClassMethods: Enabled: True Lint/Loop: Enabled: True Lint/ParenthesesAsGroupedExpression: Enabled: True Lint/RescueException: Enabled: True Lint/StringConversionInInterpolation: Enabled: True Lint/UnusedBlockArgument: Enabled: True Lint/UnusedMethodArgument: Enabled: True Lint/UselessAccessModifier: Enabled: True Lint/UselessAssignment: Enabled: True Lint/Void: Enabled: True Layout/AccessModifierIndentation: Enabled: True Style/AccessorMethodName: Enabled: True Style/Alias: Enabled: True Layout/AlignArray: Enabled: True Layout/AlignHash: Enabled: True Layout/AlignParameters: Enabled: True Metrics/BlockNesting: Enabled: True Style/AsciiComments: Enabled: True Style/Attr: Enabled: True Style/BracesAroundHashParameters: Enabled: True Style/CaseEquality: Enabled: True Layout/CaseIndentation: Enabled: True Style/CharacterLiteral: Enabled: True Style/ClassAndModuleCamelCase: Enabled: True Style/ClassAndModuleChildren: Enabled: False Style/ClassCheck: Enabled: True # Class length is not necessarily an indicator of code quality Metrics/ClassLength: Enabled: False Style/ClassMethods: Enabled: True Style/ClassVars: Enabled: True Style/WhenThen: Enabled: True Style/WordArray: Enabled: True Style/UnneededPercentQ: Enabled: True Layout/Tab: Enabled: True Layout/SpaceBeforeSemicolon: Enabled: True Layout/TrailingBlankLines: Enabled: True Layout/SpaceInsideBlockBraces: Enabled: True Layout/SpaceInsideBrackets: Enabled: True Layout/SpaceInsideHashLiteralBraces: Enabled: True Layout/SpaceInsideParens: Enabled: True Layout/LeadingCommentSpace: Enabled: True Layout/SpaceBeforeFirstArg: Enabled: True Layout/SpaceAfterColon: Enabled: True Layout/SpaceAfterComma: Enabled: True Layout/SpaceAfterMethodName: Enabled: True Layout/SpaceAfterNot: Enabled: True Layout/SpaceAfterSemicolon: Enabled: True Layout/SpaceAroundEqualsInParameterDefault: Enabled: True Layout/SpaceAroundOperators: Enabled: True Layout/SpaceBeforeBlockBraces: Enabled: True Layout/SpaceBeforeComma: Enabled: True Style/CollectionMethods: Enabled: True Layout/CommentIndentation: Enabled: True Style/ColonMethodCall: Enabled: True Style/CommentAnnotation: Enabled: True # 'Complexity' is very relative Metrics/CyclomaticComplexity: Enabled: False Style/ConstantName: Enabled: True Style/Documentation: Enabled: False Style/DefWithParentheses: Enabled: True Style/PreferredHashMethods: Enabled: True Layout/DotPosition: EnforcedStyle: trailing Style/DoubleNegation: Enabled: True Style/EachWithObject: Enabled: True Layout/EmptyLineBetweenDefs: Enabled: True Layout/IndentArray: Enabled: True Layout/IndentHash: Enabled: True Layout/IndentationConsistency: Enabled: True Layout/IndentationWidth: Enabled: True Layout/EmptyLines: Enabled: True Layout/EmptyLinesAroundAccessModifier: Enabled: True Style/EmptyLiteral: Enabled: True # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Enabled: False Style/MethodCallWithoutArgsParentheses: Enabled: True Style/MethodDefParentheses: Enabled: True Style/LineEndConcatenation: Enabled: True Layout/TrailingWhitespace: Enabled: True Style/StringLiterals: Enabled: True Style/TrailingCommaInArguments: Enabled: True Style/TrailingCommaInLiteral: Enabled: True Style/GlobalVars: Enabled: True Style/GuardClause: Enabled: True Style/IfUnlessModifier: Enabled: True Style/MultilineIfThen: Enabled: True Style/NegatedIf: Enabled: True Style/NegatedWhile: Enabled: True Style/Next: Enabled: True Style/SingleLineBlockParams: Enabled: True Style/SingleLineMethods: Enabled: True Style/SpecialGlobalVars: Enabled: True Style/TrivialAccessors: Enabled: True Style/UnlessElse: Enabled: True Style/VariableInterpolation: Enabled: True Style/VariableName: Enabled: True Style/WhileUntilDo: Enabled: True Style/EvenOdd: Enabled: True Style/FileName: Enabled: True Style/For: Enabled: True Style/Lambda: Enabled: True Style/MethodName: Enabled: True Style/MultilineTernaryOperator: Enabled: True Style/NestedTernaryOperator: Enabled: True Style/NilComparison: Enabled: True Style/FormatString: Enabled: True Style/MultilineBlockChain: Enabled: True Style/Semicolon: Enabled: True Style/SignalException: Enabled: True Style/NonNilCheck: Enabled: True Style/Not: Enabled: True Style/NumericLiterals: Enabled: True Style/OneLineConditional: Enabled: True Style/OpMethod: Enabled: True Style/ParenthesesAroundCondition: Enabled: True Style/PercentLiteralDelimiters: Enabled: True Style/PerlBackrefs: Enabled: True Style/PredicateName: Enabled: True Style/RedundantException: Enabled: True Style/SelfAssignment: Enabled: True Style/Proc: Enabled: True Style/RaiseArgs: Enabled: True Style/RedundantBegin: Enabled: True Style/RescueModifier: Enabled: True # based on https://github.com/voxpupuli/modulesync_config/issues/168 Style/RegexpLiteral: EnforcedStyle: percent_r Enabled: True Lint/UnderscorePrefixedVariableName: Enabled: True Metrics/ParameterLists: Enabled: False Lint/RequireParentheses: Enabled: True Style/ModuleFunction: Enabled: True Lint/Debugger: Enabled: True Style/IfWithSemicolon: Enabled: True Style/Encoding: Enabled: True Style/BlockDelimiters: Enabled: True Layout/MultilineBlockLayout: Enabled: True # 'Complexity' is very relative Metrics/AbcSize: Enabled: False # 'Complexity' is very relative Metrics/PerceivedComplexity: Enabled: False Lint/UselessAssignment: Enabled: True Layout/ClosingParenthesisIndentation: Enabled: True # RSpec RSpec/BeforeAfterAll: Exclude: - spec/acceptance/**/* # We don't use rspec in this way RSpec/DescribeClass: Enabled: False # Example length is not necessarily an indicator of code quality RSpec/ExampleLength: Enabled: False RSpec/NamedSubject: Enabled: False # disabled for now since they cause a lot of issues # these issues aren't easy to fix RSpec/RepeatedDescription: Enabled: False RSpec/NestedGroups: Enabled: False # this is broken on ruby1.9 Layout/IndentHeredoc: Enabled: False # disable Yaml safe_load. This is needed to support ruby2.0.0 development envs Security/YAMLLoad: Enabled: false # This affects hiera interpolation, as well as some configs that we push. Style/FormatStringToken: Enabled: false # This is useful, but sometimes a little too picky about where unit tests files # are located. RSpec/FilePath: Enabled: false + +RSpec/MultipleExpectations: + Max: 2 + diff --git a/manifests/config.pp b/manifests/config.pp index f4776e5..383e262 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 => "/usr/bin/zookeeper-server-initialize --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 acc1cb6..0420df9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,168 +1,166 @@ # 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, # 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[Variant[String,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, # 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, 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, 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 $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, # 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, # 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, # four letter words whitelist Array[String] $whitelist_4lw = $zookeeper::params::whitelist_4lw, # Metrics Providers - Integer $metrics_provider_http_port = $zookeeper::params::metrics_provider_http_port, - Boolean $metrics_provider_export_jvm_info = $zookeeper::metrics_provider_export_jvm_info, Optional[String] $metrics_provider_classname = $zookeeper::params::metrics_provider_classname, -) inherits ::zookeeper::params { - + 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" } $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], } } 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 d83028b..d4c2b26 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'] # Repo management case $os_family { 'RedHat', 'Suse': { include zookeeper::install::repo Anchor['zookeeper::install::begin'] -> Class['zookeeper::install::repo'] } default: {} # nothing to do } # 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': { 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/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 0c19087..81914f2 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,64 +1,65 @@ # 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 { - Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$::zookeeper::service_name] + if $zookeeper::manage_service_file { + 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 917bd51..d7c90a8 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -1,622 +1,627 @@ 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, }' end it do is_expected.to contain_file(environment_file).with_content(%r{ERROR}) - 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 # 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, - metrics_provider_export_jvm_info => false + 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}) + ).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}) + ).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 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 d061a18..88bba5d 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') + ).with('ensure' => 'file') 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') + ).with('ensure' => 'file') 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 8041409..20ce550 100644 --- a/templates/conf/zoo.cfg.erb +++ b/templates/conf/zoo.cfg.erb @@ -1,159 +1,158 @@ # 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 -%> # 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 -%> # 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=65536 # 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 -<% if ! [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::metrics_provider_classname")) -%> +<% 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 -%>