trinidad_lifecycle_extension 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -6,10 +6,6 @@ Trinidad's server context as well as each application context that runs on top
6
6
  of Trinidad.
7
7
 
8
8
 
9
- [WARNING] This extension is completely experimental and has not been tested nor
10
- published yet.
11
-
12
-
13
9
  Configuration
14
10
  =============
15
11
 
@@ -24,6 +20,24 @@ Trinidad will try to load each class into that directory and add it to the
24
20
  approrpiated context regarding where the extension will be configured, into the
25
21
  server section or into the web_app section.
26
22
 
23
+ This extension also allows to enable the jmx monitoring capabilities of Tomcat.
24
+ The configuration that Tomcat needs can be set as JAVA_OPTS properties or
25
+ through the Trinidad's configuration file:
26
+
27
+ extensions:
28
+ lifecycle:
29
+ jmx:
30
+ port: 9000 # not required, 8181 by default
31
+ authenticate: true # not required, false by default
32
+ ssl_enabled: #not required
33
+ ssl_cypher_suites: #not required
34
+ ssl_auth: # not required
35
+ password_file: # not required
36
+ access_file: #not required
37
+
38
+ See the Tomcat's documention for a complete references of the options:
39
+
40
+ http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html
27
41
 
28
42
  How to write a lifecycle listener
29
43
  =================================
@@ -5,7 +5,12 @@ require 'trinidad/extensions'
5
5
  module Trinidad
6
6
  module Extensions
7
7
  module Lifecycle
8
- VERSION = '0.1.0'
8
+ VERSION = '0.2.0'
9
+
10
+ DEFAULT_JMX_OPTIONS = {
11
+ :port => '8181',
12
+ :authenticate => false
13
+ }
9
14
 
10
15
  def init_listeners(context, path, mod_name)
11
16
  Dir.glob("#{path}/*.rb").each do |listener|
@@ -31,7 +36,35 @@ module Trinidad
31
36
  include Lifecycle
32
37
 
33
38
  def configure(tomcat)
34
- init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
39
+ if @options.has_key?(:path)
40
+ init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
41
+ end
42
+ if @options.has_key?(:jmx)
43
+ export_jmx_settings
44
+
45
+ require File.expand_path('../../trinidad-libs/tomcat-catalina-jmx-remote', __FILE__)
46
+ tomcat.server.add_lifecycle_listener(org.apache.catalina.mbeans.JmxRemoteLifecycleListener.new)
47
+ end
48
+ end
49
+
50
+ def export_jmx_settings
51
+ options = DEFAULT_JMX_OPTIONS.merge(@options[:jmx] || {})
52
+
53
+ set_property("com.sun.management.jmxremote", "true")
54
+ set_property("com.sun.management.jmxremote.port", options[:port])
55
+
56
+ set_property("com.sun.management.jmxremote.ssl", options[:ssl_enabled])
57
+ set_property("com.sun.management.jmxremote.ssl.enabled.protocols", options[:ssl_protocols])
58
+ set_property("com.sun.management.jmxremote.ssl.enabled.cipher.suites", options[:ssl_cypher_suites])
59
+ set_property("com.sun.management.jmxremote.ssl.need.client.auth", options[:ssl_auth])
60
+ set_property("com.sun.management.jmxremote.authenticate", options[:authenticate])
61
+ set_property("com.sun.management.jmxremote.password.file", options[:password_file])
62
+ set_property("com.sun.management.jmxremote.access.file", options[:access_file])
63
+ end
64
+
65
+ private
66
+ def set_property(name, option)
67
+ java.lang.System.set_property(name, option) if option
35
68
  end
36
69
  end
37
70
 
@@ -18,6 +18,29 @@ describe 'Trinidad lifecycle extension' do
18
18
  subject.configure(@tomcat)
19
19
  @tomcat.server.findLifecycleListeners().should have(1).listener
20
20
  end
21
+
22
+ it "adds the jmx lifecycle listener when the jmx option is true" do
23
+ ext = Trinidad::Extensions::LifecycleServerExtension.new({:jmx => nil})
24
+ ext.configure(@tomcat)
25
+ @tomcat.server.findLifecycleListeners().should have(1).listener
26
+ end
27
+
28
+ it "exports jmx option when is enabled" do
29
+ ext = Trinidad::Extensions::LifecycleServerExtension.new({:jmx => nil})
30
+ ext.configure(@tomcat)
31
+
32
+ java.lang.System.get_property("com.sun.management.jmxremote").should == 'true'
33
+ java.lang.System.get_property("com.sun.management.jmxremote.port").should == '8181'
34
+ end
35
+
36
+ it "exports custom jmx option when it exists" do
37
+ ext = Trinidad::Extensions::LifecycleServerExtension.new({
38
+ :jmx => {:ssl_enabled => 'true'}
39
+ })
40
+ ext.configure(@tomcat)
41
+
42
+ java.lang.System.get_property("com.sun.management.jmxremote.ssl").should == 'true'
43
+ end
21
44
  end
22
45
 
23
46
  context "when it's a webapp extension" do
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'trinidad_lifecycle_extension'
16
- s.version = '0.1.0'
17
- s.date = '2010-09-12'
16
+ s.version = '0.2.0'
17
+ s.date = '2010-09-26'
18
18
  s.rubyforge_project = 'trinidad_lifecycle_extension'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -59,6 +59,7 @@ Gem::Specification.new do |s|
59
59
  spec/spec.opts
60
60
  spec/spec_helper.rb
61
61
  spec/trinidad_lifecycle_extension_spec.rb
62
+ trinidad-libs/tomcat-catalina-jmx-remote.jar
62
63
  trinidad_lifecycle_extension.gemspec
63
64
  ]
64
65
  # = MANIFEST =
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinidad_lifecycle_extension
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
- - 1
7
+ - 2
9
8
  - 0
10
- version: 0.1.0
9
+ version: 0.2.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - David Calavera
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-12 00:00:00 +02:00
17
+ date: 2010-09-26 00:00:00 +02:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -37,6 +36,7 @@ files:
37
36
  - spec/spec.opts
38
37
  - spec/spec_helper.rb
39
38
  - spec/trinidad_lifecycle_extension_spec.rb
39
+ - trinidad-libs/tomcat-catalina-jmx-remote.jar
40
40
  - trinidad_lifecycle_extension.gemspec
41
41
  has_rdoc: true
42
42
  homepage: http://github.com/calavera/trinidad_lifecycle_extension
@@ -52,7 +52,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
- hash: 3
56
55
  segments:
57
56
  - 0
58
57
  version: "0"
@@ -61,7 +60,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
60
  requirements:
62
61
  - - ">="
63
62
  - !ruby/object:Gem::Version
64
- hash: 3
65
63
  segments:
66
64
  - 0
67
65
  version: "0"