Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin server options from ZK 3.5.5 - update #140

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
}

if $::zookeeper::service_provider != 'exhibitor' {
if !$::zookeeper::admin_enable_server {
$enable_admin_server_config = false
} elsif $::zookeeper::install_method == 'archive' and versioncmp($::zookeeper::archive_version, '3.5.5') >= 0 {
$enable_admin_server_config = true
} elsif $::zookeeper::install_method == 'archive' and versioncmp($::zookeeper::archive_version, '3.5.5') < 0 {
$enable_admin_server_config = false
} elsif $::zookeeper::install_method == 'package' and $::zookeeper::ensure =~ /^[0-9]/ and versioncmp($::zookeeper::ensure, '3.5.5') < 0 {
$enable_admin_server_config = false
} else {
$enable_admin_server_config = true
}

file { "${::zookeeper::cfg_dir}/zoo.cfg":
owner => $::zookeeper::user,
group => $::zookeeper::group,
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
Boolean $remove_realm_principal = $::zookeeper::params::remove_realm_principal,
# four letter words whitelist
Array[String] $whitelist_4lw = $::zookeeper::params::whitelist_4lw,
Boolean $admin_enable_server = $::zookeeper::params::admin_enable_server,
String $admin_server_address = $::zookeeper::params::admin_server_address,
Integer $admin_server_port = $::zookeeper::params::admin_server_port,
Integer $admin_idle_timeout = $::zookeeper::params::admin_idle_timeout,
String $admin_command_url = $::zookeeper::params::admin_command_url,
) inherits ::zookeeper::params {

if $pid_file {
Expand Down
9 changes: 8 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,19 @@
$sasl_users = {}
$keytab_path = '/etc/zookeeper/conf/zookeeper.keytab'
$principal = "zookeeper/${::fqdn}"
$realm = pick($trusted['domain'], $trusted['certname'])
$realm = pick($trusted['domain'], $trusted['certname'], 'realm')
$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 = []

# admin server options
$admin_enable_server = true
$admin_server_address = '0.0.0.0'
$admin_server_port = 8080
$admin_idle_timeout = 30000
$admin_command_url = '/commands'
}
165 changes: 154 additions & 11 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,161 @@
end

context 'extra environment_file parameter' do
# set custom params
let :pre_condition do
'class {"zookeeper":
log4j_prop => "ERROR",
environment_file => "java.env",
}'
end
# set custom params
let :pre_condition do
'class {"zookeeper":
log4j_prop => "ERROR",
environment_file => "java.env",
}'
end

it do
should contain_file('/etc/zookeeper/conf/java.env').with_content(/ERROR/)
should_not contain_file('/etc/zookeeper/environment')
end
end

context 'admin server options absent if enabled for install_method package < 3.5.5' do
enable = true
port = '3000'
url = '/alternative'
let :pre_condition do
"class {'zookeeper':
ensure => '3.5.4',
admin_enable_server => #{enable},
admin_server_port => #{port},
admin_command_url => '#{url}'
}"
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.enableServer=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.serverPort=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.commandURL=/)
end
end

context 'admin server options on if enabled for > 3.5.5' do
enable = true
port = '3000'
url = '/alternative'
let :pre_condition do
"class {'zookeeper':
install_method => 'archive',
archive_version => '3.5.5',
admin_enable_server => #{enable},
admin_server_port => #{port},
admin_command_url => '#{url}'
}"
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.enableServer=#{enable}/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.serverPort=#{port}/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.commandURL=#{url}/)
end
end

context 'admin server options on by default if enabled for >= 3.5.5' do
enable = true
port = '3000'
url = '/alternative'
let :pre_condition do
"class {'zookeeper':
install_method => 'archive',
archive_version => '3.5.5',
admin_server_port => #{port},
admin_command_url => '#{url}'
}"
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.enableServer=#{enable}/)

it do
should contain_file('/etc/zookeeper/conf/java.env').with_content(/ERROR/)
should_not contain_file('/etc/zookeeper/environment')
end
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.serverPort=#{port}/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).with_content(/admin.commandURL=#{url}/)
end
end

context 'admin server options missing if disabled' do
enable = false
port = '3000'
url = '/alternative'
let :pre_condition do
"class {'zookeeper':
install_method => 'archive',
archive_version => '3.5.5',
admin_enable_server => #{enable},
admin_server_port => #{port},
admin_command_url => '#{url}'
}"
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.enableServer=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.serverPort=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.commandURL=/)
end
end

context 'admin server missing if version < 3.5.5 even if enabled' do
enable = true
port = '3000'
url = '/alternative'
let :pre_condition do
"class {'zookeeper':
install_method => 'archive',
archive_version => '3.5.4',
admin_enable_server => #{enable},
admin_server_port => #{port},
admin_command_url => '#{url}'
}"
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.enableServer=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.serverPort=/)

is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg'
).without_content(/admin.commandURL=/)
end
end

context 'max allowed connections' do
Expand Down
13 changes: 13 additions & 0 deletions templates/conf/zoo.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ clientPortAddress=<%= scope.lookupvar("zookeeper::client_ip") %>
#clientPortAddress=
<% end -%>

<% if @enable_admin_server_config -%>
# Set to "false" to disable the AdminServer. By default the AdminServer is enabled.
admin.enableServer=<%= scope.lookupvar('zookeeper::admin_enable_server') %>
# The address the embedded Jetty server listens on. Defaults to 0.0.0.0.
admin.serverAddress=<%= scope.lookupvar('zookeeper::admin_server_address') %>
# The port the embedded Jetty server listens on. Defaults to 8080.
admin.serverPort=<%= scope.lookupvar('zookeeper::admin_server_port') %>
# Set the maximum idle time in milliseconds that a connection can wait before sending or receiving data. Defaults to 30000 ms.
admin.idleTimeout=<%= scope.lookupvar('zookeeper::admin_idle_timeout') %>
# The URL for listing and issuing commands relative to the root URL. Defaults to "/commands".
admin.commandURL=<%= scope.lookupvar('zookeeper::admin_command_url') %>
<% 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
Expand Down