-
Notifications
You must be signed in to change notification settings - Fork 172
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
Added Manifest for Listener #57
Merged
underscorgan
merged 4 commits into
puppetlabs:master
from
juame:MODULES-1415-ServerListener
Nov 18, 2014
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# This code fragment downloads tomcat 7.0.53, creates an instance and adds a listener | ||
# | ||
class { 'tomcat': } | ||
class { 'java': } | ||
|
||
tomcat::instance { 'mycat': | ||
catalina_base => '/opt/apache-tomcat/mycat', | ||
source_url => 'http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.53/bin/apache-tomcat-7.0.53.tar.gz', | ||
}-> | ||
tomcat::config::server::listener { 'mycat-jmx': | ||
catalina_base => '/opt/apache-tomcat/mycat', | ||
listener_ensure => present, | ||
class_name => 'org.apache.catalina.mbeans.JmxRemoteLifecycleListener', | ||
additional_attributes => { | ||
'rmiRegistryPortPlatform' => '10001', | ||
'rmiServerPortPlatform' => '10002', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Definition: tomcat::config::server::listener | ||
# | ||
# Configure Listener elements in $CATALINA_BASE/conf/server.xml | ||
# | ||
# Parameters: | ||
# - $catalina_base is the base directory for the Tomcat installation. | ||
# - $listener_ensure specifies whether you are trying to add or remove the | ||
# Listener element. Valid values are 'true', 'false', 'present', and | ||
# 'absent'. Defaults to 'present'. | ||
# - $class_name is the Java class name of the implementation to use. | ||
# Defaults to $name. | ||
# - $parent_service is the Service element this Listener should be nested | ||
# beneath. Only valid if $parent_host or $parent_engine is specified. Defaults | ||
# to 'Catalina' if $parent_host or $parent_engine was specified. | ||
# - $parent_engine is the `name` attribute to the Engine element this Listener | ||
# should be nested beneath. | ||
# - $parent_host is the `name` attribute to the Engine element this Listener | ||
# should be nested beneath. | ||
# - An optional hash of $additional_attributes to add to the Listener. Should | ||
# be of the format 'attribute' => 'value'. | ||
# - An optional array of $attributes_to_remove from the Listener. | ||
define tomcat::config::server::listener ( | ||
$catalina_base = $::tomcat::catalina_home, | ||
$listener_ensure = 'present', | ||
$class_name = undef, | ||
$parent_service = undef, | ||
$parent_engine = undef, | ||
$parent_host = undef, | ||
$additional_attributes = {}, | ||
$attributes_to_remove = [], | ||
) { | ||
if versioncmp($::augeasversion, '1.0.0') < 0 { | ||
fail('Server configurations require Augeas >= 1.0.0') | ||
} | ||
|
||
validate_re($listener_ensure, '^(present|absent|true|false)$') | ||
validate_hash($additional_attributes) | ||
validate_array($attributes_to_remove) | ||
|
||
if $parent_service and ! ($parent_host or $parent_engine) { | ||
warning('listener elements cannot be nested directly under service elements, ignoring $parent_service') | ||
} | ||
|
||
if ! $parent_service and ($parent_engine or $parent_host) { | ||
$_parent_service = 'Catalina' | ||
} else { | ||
$_parent_service = $parent_service | ||
} | ||
|
||
if $class_name { | ||
$_class_name = $class_name | ||
} else { | ||
$_class_name = $name | ||
} | ||
|
||
if $parent_engine and ! $parent_host { | ||
$path = "Server/Service[#attribute/name='${_parent_service}']/Engine[#attribute/name='${parent_engine}']/Listener[#attribute/className='${_class_name}']" | ||
} elsif $parent_engine and $parent_host { | ||
$path = "Server/Service[#attribute/name='${_parent_service}']/Engine[#attribute/name='${parent_engine}']/Host[#attribute/name='${parent_host}']/Listener[#attribute/className='${_class_name}']" | ||
} elsif $parent_host { | ||
$path = "Server/Service[#attribute/name='${_parent_service}']/Engine/Host[#attribute/name='${parent_host}']/Listener[#attribute/className='${_class_name}']" | ||
} else { | ||
$path = "Server/Listener[#attribute/className='${_class_name}']" | ||
} | ||
|
||
if $listener_ensure =~ /^(absent|false)$/ { | ||
$augeaschanges = "rm ${path}" | ||
} else { | ||
$listener = "set ${path}/#attribute/className ${_class_name}" | ||
|
||
if ! empty($additional_attributes) { | ||
$_additional_attributes = prefix(join_keys_to_values($additional_attributes, ' '), "set ${path}/#attribute/") | ||
} else { | ||
$_additional_attributes = undef | ||
} | ||
|
||
if ! empty(any2array($attributes_to_remove)) { | ||
$_attributes_to_remove = prefix(any2array($attributes_to_remove), "rm ${path}/#attribute/") | ||
} else { | ||
$_attributes_to_remove = undef | ||
} | ||
|
||
$augeaschanges = delete_undef_values(flatten([$listener, $_additional_attributes, $_attributes_to_remove])) | ||
} | ||
|
||
augeas { "${catalina_base}-${_parent_service}-${parent_engine}-${parent_host}-listener-${name}": | ||
lens => 'Xml.lns', | ||
incl => "${catalina_base}/conf/server.xml", | ||
changes => $augeaschanges, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
require 'spec_helper' | ||
|
||
describe 'tomcat::config::server::listener', :type => :define do | ||
let :pre_condition do | ||
'class { "tomcat": }' | ||
end | ||
let :facts do | ||
{ | ||
:osfamily => 'Debian', | ||
:augeasversion => '1.0.0' | ||
} | ||
end | ||
let :title do | ||
'JmxRemoteLifecycleListener' | ||
end | ||
context 'Add Listener' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:class_name => 'org.apache.catalina.mbeans.JmxRemoteLifecycleListener', | ||
:listener_ensure => 'present', | ||
:additional_attributes => { | ||
'rmiRegistryPortPlatform' => '10001', | ||
'rmiServerPortPlatform' => '10002', | ||
}, | ||
:attributes_to_remove => [ | ||
'foo', | ||
'bar', | ||
'baz', | ||
], | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test----listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/className org.apache.catalina.mbeans.JmxRemoteLifecycleListener', | ||
'set Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/rmiRegistryPortPlatform 10001', | ||
'set Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/rmiServerPortPlatform 10002', | ||
'rm Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/foo', | ||
'rm Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/bar', | ||
'rm Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']/#attribute/baz', | ||
] | ||
) | ||
} | ||
end | ||
context 'No class_name' do | ||
let :title do | ||
'org.apache.catalina.core.AprLifecycleListener' | ||
end | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test----listener-org.apache.catalina.core.AprLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context '$parent_engine, no $parent_service' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
:parent_engine => 'default', | ||
:class_name => 'org.apache.catalina.core.AprLifecycleListener', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test-Catalina-default--listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Service[#attribute/name=\'Catalina\']/Engine[#attribute/name=\'default\']/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context '$parent_engine' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
:parent_engine => 'default', | ||
:parent_service => 'Catalina2', | ||
:class_name => 'org.apache.catalina.core.AprLifecycleListener', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test-Catalina2-default--listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Service[#attribute/name=\'Catalina2\']/Engine[#attribute/name=\'default\']/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context '$parent_host, no $parent_engine or $parent_service' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
:parent_host => 'localhost', | ||
:class_name => 'org.apache.catalina.core.AprLifecycleListener', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test-Catalina--localhost-listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Service[#attribute/name=\'Catalina\']/Engine/Host[#attribute/name=\'localhost\']/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context '$parent_host, no $parent_engine' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
:parent_host => 'localhost', | ||
:parent_service => 'Catalina2', | ||
:class_name => 'org.apache.catalina.core.AprLifecycleListener', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test-Catalina2--localhost-listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Service[#attribute/name=\'Catalina2\']/Engine/Host[#attribute/name=\'localhost\']/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context '$parent_host' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:listener_ensure => 'present', | ||
:parent_engine => 'default', | ||
:parent_host => 'localhost', | ||
:parent_service => 'Catalina2', | ||
:class_name => 'org.apache.catalina.core.AprLifecycleListener', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test-Catalina2-default-localhost-listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'set Server/Service[#attribute/name=\'Catalina2\']/Engine[#attribute/name=\'default\']/Host[#attribute/name=\'localhost\']/Listener[#attribute/className=\'org.apache.catalina.core.AprLifecycleListener\']/#attribute/className org.apache.catalina.core.AprLifecycleListener', | ||
] | ||
) | ||
} | ||
end | ||
context 'Remove Listener' do | ||
let :params do | ||
{ | ||
:catalina_base => '/opt/apache-tomcat/test', | ||
:class_name => 'org.apache.catalina.mbeans.JmxRemoteLifecycleListener', | ||
:listener_ensure => 'absent', | ||
} | ||
end | ||
it { is_expected.to contain_augeas('/opt/apache-tomcat/test----listener-JmxRemoteLifecycleListener').with( | ||
'lens' => 'Xml.lns', | ||
'incl' => '/opt/apache-tomcat/test/conf/server.xml', | ||
'changes' => [ | ||
'rm Server/Listener[#attribute/className=\'org.apache.catalina.mbeans.JmxRemoteLifecycleListener\']' | ||
] | ||
) | ||
} | ||
end | ||
context 'Failing Tests' do | ||
context 'Bad listener_ensure' do | ||
let :params do | ||
{ | ||
:listener_ensure => 'foo', | ||
} | ||
end | ||
it do | ||
expect { | ||
is_expected.to compile | ||
}. to raise_error(Puppet::Error, /does not match/) | ||
end | ||
end | ||
context 'Bad additional_attributes' do | ||
let :params do | ||
{ | ||
:additional_attributes => 'foo', | ||
} | ||
end | ||
it do | ||
expect { | ||
is_expected.to compile | ||
}. to raise_error(Puppet::Error, /is not a Hash/) | ||
end | ||
end | ||
context 'Bad attributes_to_remove' do | ||
let :params do | ||
{ | ||
:attributes_to_remove => 'foo', | ||
} | ||
end | ||
it do | ||
expect { | ||
is_expected.to compile | ||
}. to raise_error(Puppet::Error, /is not an Array/) | ||
end | ||
end | ||
context 'old augeas' do | ||
let :facts do | ||
{ | ||
:osfamily => 'Debian', | ||
:augeasversion => '0.10.0' | ||
} | ||
end | ||
it do | ||
expect { | ||
is_expected.to compile | ||
}.to raise_error(Puppet::Error, /configurations require Augeas/) | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having this block can we have
$class_name
default to$name
? (see https://github.com/puppetlabs/puppetlabs-tomcat/blob/master/manifests/config/server/host.pp#L34-L38)