Skip to content

Commit b79864c

Browse files
committed
Merge pull request #210 from wkalt/ticket/master/pdb-1430-overwritable-java-args
(PDB-1430) overwritable java_args
2 parents e371db7 + 4a1f324 commit b79864c

6 files changed

Lines changed: 65 additions & 15 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,13 @@ Java VM options used for overriding default Java VM options specified in PuppetD
377377

378378
Example: to set `-Xmx512m -Xms256m` options use `{ '-Xmx' => '512m', '-Xms' => '256m' }`
379379

380+
####`merge_default_java_args`
381+
382+
Sets whether the provided java args should be merged with the defaults, or
383+
should override the defaults. This setting is necessary if any of the defaults
384+
are to be removed. Defaults to true. If false, the `java_args` in the puppetdb
385+
init config file will reflect only what is passed via the `java_args` param.
386+
380387
####`max_threads`
381388

382389
Jetty option to explicitly set max-thread. The default is undef, so the PuppetDB-jetty default is used.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Puppet::Parser::Functions
2+
newfunction(:puppetdb_flatten_java_args, :type => :rvalue) do |args|
3+
java_args = args[0] || {}
4+
args = ""
5+
java_args.each {|k,v| args += "#{k}#{v} "}
6+
"\"#{args.chomp(' ')}\""
7+
end
8+
end

manifests/init.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
$confdir = $puppetdb::params::confdir,
6262
$manage_firewall = $puppetdb::params::manage_firewall,
6363
$java_args = $puppetdb::params::java_args,
64+
$merge_default_java_args = $puppetdb::params::merge_default_java_args,
6465
$max_threads = $puppetdb::params::max_threads,
6566
$command_threads = $puppetdb::params::command_threads,
6667
$store_usage = $puppetdb::params::store_usage,
@@ -108,6 +109,7 @@
108109
puppetdb_service_status => $puppetdb_service_status,
109110
confdir => $confdir,
110111
java_args => $java_args,
112+
merge_default_java_args => $merge_default_java_args,
111113
max_threads => $max_threads,
112114
read_database => $read_database,
113115
read_database_host => $read_database_host,

manifests/params.pp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@
5757
$read_conn_keep_alive = '45'
5858
$read_conn_lifetime = '0'
5959

60-
$manage_firewall = true
61-
$java_args = {}
60+
$manage_firewall = true
61+
$java_args = {}
62+
$merge_default_java_args = true
6263

6364
$puppetdb_package = 'puppetdb'
6465
$puppetdb_service = 'puppetdb'

manifests/server.pp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
$confdir = $puppetdb::params::confdir,
5757
$manage_firewall = $puppetdb::params::manage_firewall,
5858
$java_args = $puppetdb::params::java_args,
59+
$merge_default_java_args = $puppetdb::params::merge_default_java_args,
5960
$max_threads = $puppetdb::params::max_threads,
6061
$command_threads = $puppetdb::params::command_threads,
6162
$store_usage = $puppetdb::params::store_usage,
@@ -235,19 +236,30 @@
235236
}
236237

237238
if !empty($java_args) {
238-
create_resources(
239-
'ini_subsetting',
240-
puppetdb_create_subsetting_resource_hash(
241-
$java_args,
242-
{ ensure => present,
243-
section => '',
244-
key_val_separator => '=',
245-
path => $puppetdb::params::puppetdb_initconf,
246-
setting => 'JAVA_ARGS',
247-
require => Package[$puppetdb_package],
248-
notify => Service[$puppetdb_service],
249-
})
250-
)
239+
if $merge_default_java_args {
240+
create_resources(
241+
'ini_subsetting',
242+
puppetdb_create_subsetting_resource_hash(
243+
$java_args,
244+
{ensure => present,
245+
section => '',
246+
key_val_separator => '=',
247+
path => $puppetdb::params::puppetdb_initconf,
248+
setting => 'JAVA_ARGS',
249+
require => Package[$puppetdb_package],
250+
notify => Service[$puppetdb_service],
251+
}))
252+
} else {
253+
ini_setting {'java_args':
254+
ensure => present,
255+
section => '',
256+
path => $puppetdb::params::puppetdb_initconf,
257+
setting => 'JAVA_ARGS',
258+
require => Package[$puppetdb_package],
259+
notify => Service[$puppetdb_service],
260+
value => puppetdb_flatten_java_args($java_args),
261+
}
262+
}
251263
}
252264

253265
service { $puppetdb_service:

spec/unit/classes/server_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,25 @@
4444
end
4545

4646
end
47+
48+
describe 'when specifying JAVA_ARGS with merge_default_java_args false' do
49+
let (:params) do
50+
{
51+
'java_args' => {'-Xms' => '2g'},
52+
'merge_default_java_args' => false,
53+
}
54+
end
55+
56+
context 'on standard PuppetDB' do
57+
it { should contain_ini_setting('java_args').
58+
with(
59+
'ensure' => 'present',
60+
'path' => '/etc/sysconfig/puppetdb',
61+
'section' => '',
62+
'setting' => 'JAVA_ARGS',
63+
'value' => '"-Xms2g"'
64+
)}
65+
end
66+
end
4767
end
4868
end

0 commit comments

Comments
 (0)