Skip to content

Commit d744e32

Browse files
authored
Merge pull request voxpupuli#354 from cybercom-finland/template-cleanup
Refactor most configuration to use EPP templates
2 parents c069ce7 + 54f6ae5 commit d744e32

17 files changed

+338
-339
lines changed

functions/sort_hash.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# @summary Return a sorted hash
2+
# @api private
3+
function jira::sort_hash(Hash $input) >> Hash {
4+
# Puppet hashes are "insertion order", so this works to sort by key
5+
Hash(sort(Array($input)))
6+
}

manifests/config.pp

Lines changed: 108 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# -----------------------------------------------------------------------------
16-
class jira::config inherits jira {
16+
class jira::config {
17+
# This class should be used from init.pp with a dependency on jira::install
18+
# and sending a refresh to jira::service
19+
assert_private()
20+
1721
File {
1822
owner => $jira::user,
1923
group => $jira::group,
@@ -27,68 +31,140 @@
2731
# can't use pick_default: https://tickets.puppetlabs.com/browse/MODULES-11018
2832
$dbschema = if $jira::dbschema { $jira::dbschema } else { $dbschema_default }
2933

34+
if $jira::java_opts {
35+
deprecation('jira::java_opts', 'jira::java_opts is deprecated. Please use jira::jvm_extra_args')
36+
$jvm_extra_args_real = "${jira::java_opts} ${jira::jvm_extra_args}"
37+
} else {
38+
$jvm_extra_args_real = $jira::jvm_extra_args
39+
}
40+
41+
# Allow some backwards compatibility;
42+
if $jira::poolsize {
43+
deprecation('jira::poolsize', 'jira::poolsize is deprecated and simply sets max-pool-size. Please use jira::pool_max_size instead and remove this configuration')
44+
$pool_max_size_real = pick($jira::pool_max_size, $jira::poolsize)
45+
} else {
46+
$pool_max_size_real = $jira::pool_max_size
47+
}
48+
49+
if $jira::tomcat_redirect_https_port {
50+
unless $jira::tomcat_native_ssl {
51+
fail('You need to set jira::tomcat_native_ssl to true when using jira::tomcat_redirect_https_port')
52+
}
53+
}
54+
55+
if $jira::dbport {
56+
$dbport_real = $jira::dbport
57+
} else {
58+
$dbport_real = $jira::db ? {
59+
'postgresql' => '5432',
60+
'mysql' => '3306',
61+
'oracle' => '1521',
62+
'sqlserver' => '1433',
63+
'h2' => '',
64+
}
65+
}
66+
67+
if $jira::dbdriver {
68+
$dbdriver_real = $jira::dbdriver
69+
} else {
70+
$dbdriver_real = $jira::db ? {
71+
'postgresql' => 'org.postgresql.Driver',
72+
'mysql' => 'com.mysql.jdbc.Driver',
73+
'oracle' => 'oracle.jdbc.OracleDriver',
74+
'sqlserver' => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
75+
'h2' => 'org.h2.Driver',
76+
}
77+
}
78+
79+
if $jira::dbtype {
80+
$dbtype_real = $jira::dbtype
81+
} else {
82+
$dbtype_real = $jira::db ? {
83+
'postgresql' => 'postgres72',
84+
'mysql' => 'mysql',
85+
'oracle' => 'oracle10g',
86+
'sqlserver' => 'mssql',
87+
'h2' => 'h2',
88+
}
89+
}
90+
91+
if $jira::dburl {
92+
$dburl_real = $jira::dburl
93+
}
94+
else {
95+
$dburl_real = $jira::db ? {
96+
'postgresql' => "jdbc:${jira::db}://${jira::dbserver}:${dbport_real}/${jira::dbname}",
97+
'mysql' => "jdbc:${jira::db}://${jira::dbserver}:${dbport_real}/${jira::dbname}?useUnicode=true&characterEncoding=UTF8&sessionVariables=default_storage_engine=InnoDB",
98+
'oracle' => "jdbc:${jira::db}:thin:@${jira::dbserver}:${dbport_real}:${jira::dbname}",
99+
'sqlserver' => "jdbc:jtds:${jira::db}://${jira::dbserver}:${dbport_real}/${jira::dbname}",
100+
'h2' => "jdbc:h2:file:/${jira::homedir}/database/${jira::dbname}",
101+
}
102+
}
103+
104+
if $jira::tomcat_protocol_ssl {
105+
$tomcat_protocol_ssl_real = $jira::tomcat_protocol_ssl
106+
} else {
107+
if versioncmp($jira::version, '7.3.0') >= 0 {
108+
$tomcat_protocol_ssl_real = 'org.apache.coyote.http11.Http11NioProtocol'
109+
} else {
110+
$tomcat_protocol_ssl_real = 'org.apache.coyote.http11.Http11Protocol'
111+
}
112+
}
113+
114+
$jira_properties = {
115+
'jira.websudo.is.disabled' => !$jira::enable_secure_admin_sessions,
116+
}
117+
$merged_jira_config_properties = jira::sort_hash($jira_properties + $jira::jira_config_properties)
118+
119+
# Configuration logic ends, resources begin:
120+
30121
file { "${jira::webappdir}/bin/user.sh":
31-
content => template('jira/user.sh.erb'),
122+
content => epp('jira/user.sh.epp'),
32123
mode => '0755',
33-
require => [
34-
Class['jira::install'],
35-
File[$jira::webappdir],
36-
File[$jira::homedir],
37-
],
38124
}
39125

40-
-> file { "${jira::webappdir}/bin/setenv.sh":
41-
content => template('jira/setenv.sh.erb'),
126+
file { "${jira::webappdir}/bin/setenv.sh":
127+
content => epp('jira/setenv.sh.epp'),
42128
mode => '0755',
43-
require => Class['jira::install'],
44-
notify => Class['jira::service'],
45129
}
46130

47-
-> file { "${jira::homedir}/dbconfig.xml":
131+
file { "${jira::homedir}/dbconfig.xml":
48132
content => epp('jira/dbconfig.xml.epp'),
49133
mode => '0600',
50-
require => [Class['jira::install'],File[$jira::homedir]],
51-
notify => Class['jira::service'],
52134
}
53135

54136
if $jira::script_check_java_manage {
55137
file { "${jira::webappdir}/bin/check-java.sh":
56138
content => template($jira::script_check_java_template),
57139
mode => '0755',
58-
require => [
59-
Class['jira::install'],
60-
File["${jira::webappdir}/bin/setenv.sh"],
61-
],
62-
notify => Class['jira::service'],
140+
require => File["${jira::webappdir}/bin/setenv.sh"],
63141
}
64142
}
65143

66144
file { "${jira::webappdir}/conf/server.xml":
67-
content => template('jira/server.xml.erb'),
145+
content => epp('jira/server.xml.epp'),
68146
mode => '0600',
69-
require => Class['jira::install'],
70-
notify => Class['jira::service'],
71147
}
72-
-> file { "${jira::webappdir}/conf/context.xml":
73-
content => template('jira/context.xml.erb'),
148+
149+
file { "${jira::webappdir}/conf/context.xml":
150+
content => epp('jira/context.xml.epp'),
74151
mode => '0600',
75-
require => Class['jira::install'],
76-
notify => Class['jira::service'],
77152
}
78153

79154
file { "${jira::homedir}/jira-config.properties":
80-
content => template('jira/jira-config.properties.erb'),
155+
content => inline_epp(@(EOF)
156+
<% $merged_jira_config_properties.each |$key, $val| { -%>
157+
<%= $key %> = <%= $val %>
158+
<%- } -%>
159+
| EOF
160+
),
81161
mode => '0600',
82-
require => [Class['jira::install'],File[$jira::homedir]],
83-
notify => Class['jira::service'],
84162
}
85163

86164
if $jira::datacenter {
87165
file { "${jira::homedir}/cluster.properties":
88-
content => template('jira/cluster.properties.erb'),
166+
content => epp('jira/cluster.properties.epp'),
89167
mode => '0600',
90-
require => [Class['jira::install'],File[$jira::homedir]],
91-
notify => Class['jira::service'],
92168
}
93169
}
94170
}

manifests/facts.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
file { "${dir}/facts.d/jira_facts.rb":
4646
ensure => $ensure,
47-
content => template('jira/facts.rb.erb'),
47+
content => epp('jira/facts.rb.epp'),
4848
mode => '0755',
4949
}
5050
}

manifests/init.pp

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,6 @@
173173
deprecation('jira::enable_connection_pooling', 'jira::enable_connection_pooling has been removed and does nothing. Please simply configure the connection pooling parameters')
174174
}
175175

176-
if $java_opts {
177-
deprecation('jira::java_opts', 'jira::java_opts is deprecated. Please use jira::jvm_extra_args')
178-
$jvm_extra_args_real = "${java_opts} ${jvm_extra_args}"
179-
} else {
180-
$jvm_extra_args_real = $jvm_extra_args
181-
}
182-
183-
# Allow some backwards compatibility;
184-
if $poolsize {
185-
deprecation('jira::poolsize', 'jira::poolsize is deprecated and simply sets max-pool-size. Please use jira::pool_max_size instead and remove this configuration')
186-
$pool_max_size_real = pick($pool_max_size, $poolsize)
187-
} else {
188-
$pool_max_size_real = $pool_max_size
189-
}
190-
191176
if $tomcat_redirect_https_port {
192177
unless ($tomcat_native_ssl) {
193178
fail('You need to set native_ssl to true when using tomcat_redirect_https_port')
@@ -217,65 +202,6 @@
217202
$webappdir = $extractdir
218203
}
219204

220-
if $dbport {
221-
$dbport_real = $dbport
222-
} else {
223-
$dbport_real = $db ? {
224-
'postgresql' => '5432',
225-
'mysql' => '3306',
226-
'oracle' => '1521',
227-
'sqlserver' => '1433',
228-
'h2' => '',
229-
}
230-
}
231-
232-
if $dbdriver {
233-
$dbdriver_real = $dbdriver
234-
} else {
235-
$dbdriver_real = $db ? {
236-
'postgresql' => 'org.postgresql.Driver',
237-
'mysql' => 'com.mysql.jdbc.Driver',
238-
'oracle' => 'oracle.jdbc.OracleDriver',
239-
'sqlserver' => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
240-
'h2' => 'org.h2.Driver',
241-
}
242-
}
243-
244-
if $dbtype {
245-
$dbtype_real = $dbtype
246-
} else {
247-
$dbtype_real = $db ? {
248-
'postgresql' => 'postgres72',
249-
'mysql' => 'mysql',
250-
'oracle' => 'oracle10g',
251-
'sqlserver' => 'mssql',
252-
'h2' => 'h2',
253-
}
254-
}
255-
256-
if $dburl {
257-
$dburl_real = $dburl
258-
}
259-
else {
260-
$dburl_real = $db ? {
261-
'postgresql' => "jdbc:${db}://${dbserver}:${dbport_real}/${dbname}",
262-
'mysql' => "jdbc:${db}://${dbserver}:${dbport_real}/${dbname}?useUnicode=true&amp;characterEncoding=UTF8&amp;sessionVariables=default_storage_engine=InnoDB",
263-
'oracle' => "jdbc:${db}:thin:@${dbserver}:${dbport_real}:${dbname}",
264-
'sqlserver' => "jdbc:jtds:${db}://${dbserver}:${dbport_real}/${dbname}",
265-
'h2' => "jdbc:h2:file:/${jira::homedir}/database/${dbname}",
266-
}
267-
}
268-
269-
if $tomcat_protocol_ssl {
270-
$tomcat_protocol_ssl_real = $tomcat_protocol_ssl
271-
} else {
272-
if versioncmp($version, '7.3.0') >= 0 {
273-
$tomcat_protocol_ssl_real = 'org.apache.coyote.http11.Http11NioProtocol'
274-
} else {
275-
$tomcat_protocol_ssl_real = 'org.apache.coyote.http11.Http11Protocol'
276-
}
277-
}
278-
279205
if ! empty($ajp) {
280206
if ! ('port' in $ajp) {
281207
fail('You need to specify a valid port for the AJP connector.')
@@ -289,8 +215,6 @@
289215
}
290216
}
291217

292-
$merged_jira_config_properties = merge( { 'jira.websudo.is.disabled' => !$enable_secure_admin_sessions }, $jira_config_properties)
293-
294218
if $javahome == undef {
295219
fail('You need to specify a value for javahome')
296220
}

manifests/sso.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
) {
1616
file { "${jira::webappdir}/atlassian-jira/WEB-INF/classes/crowd.properties":
1717
ensure => file,
18-
content => template('jira/crowd.properties'),
18+
content => epp('jira/crowd.properties.epp'),
1919
mode => '0660',
2020
owner => $jira::user,
2121
group => $jira::group,

templates/cluster.properties.epp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This ID must be unique across the cluster
2+
jira.node.id = <%= $facts['fqdn'] %>
3+
# The location of the shared home directory for all JIRA nodes
4+
jira.shared.home = <%= $jira::shared_homedir %>
5+
<% if $jira::ehcache_listener_host { -%>
6+
ehcache.listener.hostName = <%= $jira::ehcache_listener_host %>
7+
<% } -%>
8+
<% if $jira::ehcache_listener_port { -%>
9+
ehcache.listener.port = <%= $jira::ehcache_listener_port %>
10+
<% } -%>
11+
<% if $jira::ehcache_object_port { -%>
12+
ehcache.object.port = <%= $jira::ehcache_object_port %>
13+
<% } -%>

templates/cluster.properties.erb

Lines changed: 0 additions & 13 deletions
This file was deleted.

templates/context.xml.erb renamed to templates/context.xml.epp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@
3232
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
3333
-->
3434

35-
<% if ! scope.lookupvar('jira::resources').empty? -%>
36-
<% scope.lookupvar('jira::resources').each do |name, values| -%>
37-
<Resource name = "<%= name %>"
38-
<% values.each_pair do |key,value| -%>
39-
<%= key %> = <%= "\"#{value}\"" %>
40-
<% end -%>
35+
<% jira::sort_hash($jira::resources).each |$name, $values| { -%>
36+
<Resource name = "<%= $name %>"
37+
<% jira::sort_hash($values).each |$key, $value| { -%>
38+
<%= $key %> = "<%= $value %>"
39+
<% } -%>
4140
/>
42-
<% end -%>
43-
<% end -%>
41+
<% } -%>
4442
<JarScanner scanManifest="false"/>
4543
</Context>

templates/crowd.properties

Lines changed: 0 additions & 11 deletions
This file was deleted.

templates/crowd.properties.epp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
application.name <%= $jira::sso::application_name %>
2+
application.password <%= $jira::sso::application_password %>
3+
application.login.url <%= $jira::sso::application_login_url %>
4+
5+
crowd.server.url <%= $jira::sso::crowd_server_url %>
6+
crowd.base.url <%= $jira::sso::crowd_base_url %>
7+
8+
session.isauthenticated <%= $jira::sso::session_isauthenticated %>
9+
session.tokenkey <%= $jira::sso::session_tokenkey %>
10+
session.validationinterval <%= $jira::sso::session_validationinterval %>
11+
session.lastvalidation <%= $jira::sso::session_lastvalidation %>

0 commit comments

Comments
 (0)