6 changes: 3 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fixtures:
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
staging: "git://github.com/nanliu/puppet-staging.git"
stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
concat: "https://github.com/puppetlabs/puppetlabs-concat.git"
staging: "https://github.com/nanliu/puppet-staging.git"
symlinks:
tomcat: "#{source_dir}"
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
##2014-11-11 - Supported Release 1.2.0
###Summary

This is primarily a feature release, with a couple of bugfixes for tests and metadata.

####Features
- Add `install_from_source` parameter to class `tomcat`
- Add `purge_connectors` parameter to class `tomcat` and define `tomcat::server::connector`

####Bugfixes
- Fix dependencies to remove missing dependency warnings with the PMT
- Use `curl -k` in the tests

##2014-10-28 - Supported Release 1.1.0
###Summary

Expand Down
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
- [tomcat::service](#tomcatservice)
- [tomcat::setenv::entry](#tomcatsetenventry)
- [tomcat::war](#tomcatwar)
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
6. [Limitations - OS compatibility, etc.](#limitations)
7. [Development - Guide for contributing to the module](#development)
* [Contributing](#contributing)
* [Tests](#running-tests)

Expand Down Expand Up @@ -55,10 +55,11 @@ puppet module upgrade puppetlabs-stdlib
The simplest way to get Tomcat up and running with the tomcat module is to install the Tomcat package from EPEL,

```puppet
class { 'tomcat': }
class { 'tomcat':
install_from_source => false,
}
class { 'epel': }->
tomcat::instance{ 'default':
install_from_source => false,
package_name => 'tomcat',
}->
```
Expand Down Expand Up @@ -160,7 +161,7 @@ tomcat::config::server::connector { 'tomcat8-jsvc':
}
```

Then you would set `connector_ensure` to 'absent', and provide `notify` for the service.
Then you would set `connector_ensure` to 'absent', and provide `notify` for the service.

```puppet
tomcat::config::server::connector { 'tomcat8-jsvc':
Expand Down Expand Up @@ -223,6 +224,18 @@ Sets the user to run Tomcat as.

Sets the group to run Tomcat as.

#####`$install_from_source`

Specifies whether or not to install from source. A Boolean that defaults to 'true'.

#####`$purge_connectors`

Specifies whether or not to purge existing Connector elements from server.xml.

For example, if you specify an HTTP connector element using ```tomcat::instance::connector``` and ```purge_connectors``` is set to ```true``` then existing HTTP connectors will be removed and only the HTTP connector you have specified will remain once the module has been applied.

This is useful if you want to change the ports of existing connectors instead of adding additional connectors. Boolean that defaults to 'false'.

#####`$manage_user`

Specifies whether or not to manage the user. Boolean that defaults to 'true'.
Expand Down Expand Up @@ -437,7 +450,7 @@ Specifies the base directory for the Tomcat installation. Only affects the insta

#####`$install_from_source`

Specifies whether or not to install from source. A Boolean that defaults to 'true'.
Specifies whether or not to install from source.

#####`$source_url`

Expand Down
14 changes: 13 additions & 1 deletion manifests/config/server/connector.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
$parent_service = 'Catalina',
$additional_attributes = {},
$attributes_to_remove = [],
$purge_connectors = $::tomcat::purge_connectors,
) {
if versioncmp($::augeasversion, '1.0.0') < 0 {
fail('Server configurations require Augeas >= 1.0.0')
}

validate_re($connector_ensure, '^(present|absent|true|false)$')
validate_hash($additional_attributes)
validate_bool($purge_connectors)

if $protocol {
$_protocol = $protocol
Expand All @@ -39,6 +41,16 @@

$path = "Server/Service[#attribute/name='${parent_service}']"

if $purge_connectors {
$_purge_connectors = "rm Server//Connector[#attribute/protocol='${_protocol}']"
} else {
$_purge_connectors = undef
}

if $purge_connectors and ($connector_ensure =~ /^(absent|false)$/) {
fail('$connector_ensure must be set to \'true\' or \'present\' to use $purge_connectors')
}

if $connector_ensure =~ /^(absent|false)$/ {
if ! $port {
$base_path = "${path}/Connector[#attribute/protocol='${_protocol}']"
Expand All @@ -65,7 +77,7 @@
$_attributes_to_remove = undef
}

$changes = delete_undef_values(flatten([$_port, $_protocol_change, $_additional_attributes, $_attributes_to_remove]))
$changes = delete_undef_values(flatten([ $_purge_connectors, $_port, $_protocol_change, $_additional_attributes, $_attributes_to_remove ]))
}

augeas { "server-${catalina_base}-${parent_service}-connector-${port}":
Expand Down
24 changes: 15 additions & 9 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@
# Boolean specifying whether or not to manage the group. Defaults to true.
#
class tomcat (
$catalina_home = $::tomcat::params::catalina_home,
$user = $::tomcat::params::user,
$group = $::tomcat::params::group,
$manage_user = true,
$manage_group = true,
$catalina_home = $::tomcat::params::catalina_home,
$user = $::tomcat::params::user,
$group = $::tomcat::params::group,
$install_from_source = true,
$purge_connectors = false,
$manage_user = true,
$manage_group = true,
) inherits ::tomcat::params {
validate_bool($install_from_source)
validate_bool($purge_connectors)
validate_bool($manage_user)
validate_bool($manage_group)

Expand All @@ -36,10 +40,12 @@
default: { }
}

file { $catalina_home:
ensure => directory,
owner => $user,
group => $group,
if $install_from_source {
file { $catalina_home:
ensure => directory,
owner => $user,
group => $group,
}
}

if $manage_user {
Expand Down
2 changes: 1 addition & 1 deletion manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
define tomcat::instance (
$catalina_home = undef,
$catalina_base = undef,
$install_from_source = true,
$install_from_source = $::tomcat::install_from_source,
$source_url = undef,
$source_strip_first_dir = undef,
$package_ensure = undef,
Expand Down
8 changes: 4 additions & 4 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-tomcat",
"version": "1.1.0",
"version": "1.2.0",
"author": "puppetlabs",
"summary": "Puppet module for managing Apache Tomcat.",
"license": "Apache 2.0",
Expand Down Expand Up @@ -67,8 +67,8 @@
}
],
"dependencies": [
{"name":"puppetlabs-stdlib","version_requirement":">= 4.2.0"},
{"name":"puppetlabs-concat","version_requirement":">= 1.0.4"},
{"name":"nanliu-staging","version_requirement":">= 0.4.1"}
{"name":"puppetlabs/stdlib","version_requirement":">= 4.2.0"},
{"name":"puppetlabs/concat","version_requirement":">= 1.0.4"},
{"name":"nanliu/staging","version_requirement":">= 0.4.1"}
]
}
2 changes: 1 addition & 1 deletion spec/acceptance/acceptance_1_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
stop_test = true if UNSUPPORTED_PLATFORMS.any?{ |up| fact('osfamily') == up} || confine_array.any?

tcat_version = String.new
shell('curl http://tomcat.apache.org/download-80.cgi?Preferred=http%3A%2F%2Fmirror.nexcess.net%2Fapache%2F', :acceptable_exit_codes => 0) do |r|
shell('curl -k http://tomcat.apache.org/download-80.cgi?Preferred=http%3A%2F%2Fmirror.nexcess.net%2Fapache%2F', :acceptable_exit_codes => 0) do |r|
/apache-tomcat-(.{4,7}).tar.gz/.match(r.stdout).to_a.uniq.each do |m|
if m.length < 7
tcat_version = m
Expand Down
11 changes: 10 additions & 1 deletion spec/acceptance/acceptance_2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
stop_test = true if UNSUPPORTED_PLATFORMS.any?{ |up| fact('osfamily') == up}

tcat_version = String.new
shell('curl http://tomcat.apache.org/download-60.cgi?Preferred=http%3A%2F%2Fmirror.symnds.com%2Fsoftware%2FApache%2F', :acceptable_exit_codes => 0) do |r|
shell('curl -k http://tomcat.apache.org/download-60.cgi?Preferred=http%3A%2F%2Fmirror.symnds.com%2Fsoftware%2FApache%2F', :acceptable_exit_codes => 0) do |r|
/apache-tomcat-(.{4,7}).tar.gz/.match(r.stdout).to_a.uniq.each do |m|
if m.length < 7
tcat_version = m
Expand All @@ -17,6 +17,9 @@
context 'Initial install Tomcat and verification' do
it 'Should apply the manifest without error' do
pp = <<-EOS
Staging::File {
curl_option => '-k',
}
class { 'tomcat':}
class { 'java':}
tomcat::instance { 'tomcat6':
Expand Down Expand Up @@ -139,6 +142,9 @@ class { 'java':}
context 'Start Tomcat without war' do
it 'Should apply the manifest without error' do
pp = <<-EOS
Staging::File {
curl_option => '-k',
}
class{ 'tomcat':}
tomcat::war { 'tomcat6039-sample.war':
catalina_base => '/opt/apache-tomcat/tomcat6039',
Expand Down Expand Up @@ -179,6 +185,9 @@ class { 'java':}
context 'deploy the war' do
it 'Should apply the manifest without error' do
pp = <<-EOS
Staging::File {
curl_option => '-k',
}
class{ 'tomcat':}
tomcat::war { 'tomcat6-sample.war':
catalina_base => '/opt/apache-tomcat/tomcat6',
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/acceptance_3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
stop_test = true if UNSUPPORTED_PLATFORMS.any?{ |up| fact('osfamily') == up}

tcat_version = String.new
shell('curl http://tomcat.apache.org/download-70.cgi?Preferred=http%3A%2F%2Fwww.dsgnwrld.com%2Fam%2F', :acceptable_exit_codes => 0) do |r|
shell('curl -k http://tomcat.apache.org/download-70.cgi?Preferred=http%3A%2F%2Fwww.dsgnwrld.com%2Fam%2F', :acceptable_exit_codes => 0) do |r|
/apache-tomcat-(.{4,7}).tar.gz/.match(r.stdout).to_a.uniq.each do |m|
if m.length < 7
tcat_version = m
Expand All @@ -14,7 +14,7 @@

describe 'Tomcat Install source -defaults', :unless => stop_test do

shell('curl -o /tmp/sample.war https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/sample.war', :acceptable_exit_codes => 0)
shell('curl -k -o /tmp/sample.war https://tomcat.apache.org/tomcat-8.0-doc/appdev/sample/sample.war', :acceptable_exit_codes => 0)

context 'Initial install Tomcat and verification' do
it 'Should apply the manifest without error' do
Expand Down
14 changes: 14 additions & 0 deletions spec/classes/tomcat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@
}
end

context "not installing from source" do
let :facts do
{
:osfamily => 'Debian'
}
end
let :params do
{
:install_from_source => false,
}
end
it { is_expected.not_to contain_file("/opt/apache-tomcat") }
end

context "not managing user/group" do
let :facts do
{
Expand Down
50 changes: 50 additions & 0 deletions spec/defines/config/server/connector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,42 @@
)
}
end
context 'set all the things with purge_connectors' do
let :params do
{
:port => '8180',
:catalina_base => '/opt/apache-tomcat/test',
:protocol => 'AJP/1.3',
:purge_connectors => true,
:parent_service => 'Catalina2',
:additional_attributes => {
'redirectPort' => '8543',
'connectionTimeout' => '20000',
},
:attributes_to_remove => [
'foo',
'bar',
'baz'
],
}
end
it { is_expected.to contain_augeas('server-/opt/apache-tomcat/test-Catalina2-connector-8180'
).with(
'lens' => 'Xml.lns',
'incl' => '/opt/apache-tomcat/test/conf/server.xml',
'changes' => [
'rm Server//Connector[#attribute/protocol=\'AJP/1.3\']',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/port 8180',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/protocol AJP/1.3',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/redirectPort 8543',
'set Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/connectionTimeout 20000',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/foo',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/bar',
'rm Server/Service[#attribute/name=\'Catalina2\']/Connector[#attribute/port=\'8180\']/#attribute/baz',
],
)
}
end
context 'remove connector' do
let :params do
{
Expand Down Expand Up @@ -79,6 +115,20 @@
)
}
end
context 'remove connector with purge_connectors' do
let :params do
{
:catalina_base => 'opt/apache-tomcat/test',
:connector_ensure => 'absent',
:purge_connectors => true,
}
end
it do
expect {
should compile
}.to raise_error(Puppet::Error, /\$connector_ensure must be set to 'true' or 'present' to use \$purge_connectors/)
end
end
context 'two connectors with same protocol' do
let :pre_condition do
'class { "tomcat": }
Expand Down