rboss 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/.gitignore +9 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/bin/jboss-profile +90 -0
  5. data/bin/twiddle +230 -0
  6. data/examples/jboss_profile/jbb_profile_1.yaml +32 -0
  7. data/examples/jboss_profile/jbb_profile_2.yaml +32 -0
  8. data/examples/jboss_profile/jboss_profile.yaml +7 -0
  9. data/examples/monitor/simple_monitor.rb +61 -0
  10. data/lib/rboss.rb +25 -0
  11. data/lib/rboss/component_processor.rb +177 -0
  12. data/lib/rboss/components/component.rb +52 -0
  13. data/lib/rboss/components/datasource.rb +198 -0
  14. data/lib/rboss/components/deploy_folder.rb +104 -0
  15. data/lib/rboss/components/hypersonic_replacer.rb +58 -0
  16. data/lib/rboss/components/jbossweb.rb +117 -0
  17. data/lib/rboss/components/jmx.rb +88 -0
  18. data/lib/rboss/components/mod_cluster.rb +81 -0
  19. data/lib/rboss/components/org/6.0/deploy_folder.rb +33 -0
  20. data/lib/rboss/components/org/jmx.rb +59 -0
  21. data/lib/rboss/components/profile_folder.rb +44 -0
  22. data/lib/rboss/components/resource.rb +53 -0
  23. data/lib/rboss/components/run_conf.rb +90 -0
  24. data/lib/rboss/components/run_conf.yaml +22 -0
  25. data/lib/rboss/components/service_script.rb +55 -0
  26. data/lib/rboss/components/slimming.rb +124 -0
  27. data/lib/rboss/components/soa-p/hypersonic_replacer.rb +79 -0
  28. data/lib/rboss/components/soa-p/jmx.rb +47 -0
  29. data/lib/rboss/components/xadatasource.rb +67 -0
  30. data/lib/rboss/file_processor.rb +107 -0
  31. data/lib/rboss/jboss_path.rb +53 -0
  32. data/lib/rboss/jboss_profile.rb +344 -0
  33. data/lib/rboss/resources/jboss_init_redhat.sh.erb +140 -0
  34. data/lib/rboss/resources/mod_cluster.sar/META-INF/mod_cluster-jboss-beans.xml +282 -0
  35. data/lib/rboss/resources/mod_cluster.sar/mod_cluster-1.1.2.Final.jar +0 -0
  36. data/lib/rboss/resources/run.conf.erb +62 -0
  37. data/lib/rboss/twiddle.rb +25 -0
  38. data/lib/rboss/twiddle/base_monitor.rb +57 -0
  39. data/lib/rboss/twiddle/mbean.rb +82 -0
  40. data/lib/rboss/twiddle/monitor.rb +144 -0
  41. data/lib/rboss/twiddle/scanner.rb +92 -0
  42. data/lib/rboss/twiddle/twiddle.rb +71 -0
  43. data/lib/rboss/utils.rb +33 -0
  44. data/lib/rboss/version.rb +25 -0
  45. data/rboss.gemspec +20 -0
  46. data/test/datasource_test.rb +211 -0
  47. data/test/deploy_folder_test.rb +126 -0
  48. data/test/mbean_test.rb +53 -0
  49. data/test/test_helper.rb +124 -0
  50. data/test/test_suite.rb +35 -0
  51. metadata +109 -0
@@ -0,0 +1,25 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'twiddle/base_monitor'
24
+ require_relative 'twiddle/mbean'
25
+ require_relative 'twiddle/monitor'
@@ -0,0 +1,57 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'monitor'
24
+ require_relative 'scanner'
25
+ require_relative 'twiddle'
26
+
27
+ module JBoss
28
+ module Twiddle
29
+
30
+ class BaseMonitor
31
+ include JBoss::Twiddle::Monitor, JBoss::Twiddle::Scanner
32
+
33
+ def initialize twiddle
34
+ @twiddle = twiddle
35
+ defaults.each do |mbean_id, config|
36
+ monitor mbean_id, config
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ class Invoker
43
+
44
+ def monitor
45
+ @monitor ||= BaseMonitor::new self
46
+ @monitor
47
+ end
48
+
49
+ def mbean id
50
+ monitor.mbean id
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,82 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'twiddle'
24
+
25
+ module JBoss
26
+ class MBean
27
+
28
+ attr_reader :pattern
29
+ attr_accessor :resource, :twiddle
30
+
31
+ def initialize params
32
+ @pattern = params[:pattern]
33
+ @twiddle = params[:twiddle]
34
+ @env = @twiddle
35
+ end
36
+
37
+ def with resource
38
+ @resource = resource
39
+ if block_given?
40
+ yield
41
+ @resource = nil
42
+ end
43
+ self
44
+ end
45
+
46
+ def [] property
47
+ resource = @resource
48
+ env = @env
49
+ query = eval("\"#{pattern}\"")
50
+ result = @twiddle.invoke(:get, query, property)
51
+ def result.value
52
+ self.split(/=/)[1]
53
+ end
54
+ result
55
+ end
56
+
57
+ def []= property, value
58
+ resource = @resource
59
+ env = @env
60
+ query = eval("\"#{pattern}\"")
61
+ @twiddle.invoke :set, query, property, value
62
+ end
63
+
64
+ def method_missing(method, *args, &block)
65
+ _invoke_ method, args, block
66
+ end
67
+
68
+ def _invoke_ method, *args, &block
69
+ resource = @resource
70
+ env = @env
71
+ query = eval("\"#{pattern} #{method}\"")
72
+ return_value = @twiddle.invoke :invoke, query, args
73
+ if block_given?
74
+ block.call return_value
75
+ end
76
+ return_value
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
@@ -0,0 +1,144 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'mbean'
24
+
25
+ module JBoss
26
+ module Twiddle
27
+
28
+ module Monitor
29
+
30
+ def defaults
31
+ {
32
+ :webapp => {
33
+ :pattern => 'jboss.web:type=Manager,host=localhost,path=/#{resource}',
34
+ :properties => %W(activeSessions maxActive)
35
+ },
36
+ :connector => {
37
+ :pattern => 'jboss.web:type=ThreadPool,name=#{resource}',
38
+ :properties => %W(maxThreads currentThreadCount currentThreadsBusy)
39
+ },
40
+ :server_info => {
41
+ :pattern => 'jboss.system:type=ServerInfo',
42
+ :properties => %W(ActiveThreadCount MaxMemory FreeMemory AvailableProcessors
43
+ HostAddress JavaVendor JavaVersion OSName OSArch)
44
+ },
45
+ :server => {
46
+ :pattern => 'jboss.system:type=Server',
47
+ :properties => %W(VersionNumber StartDate)
48
+ },
49
+ :system_properties => {
50
+ :pattern => 'jboss:name=SystemProperties,type=Service'
51
+ },
52
+ :request => {
53
+ :pattern => 'jboss.web:type=GlobalRequestProcessor,name=#{resource}',
54
+ :properties => %W(requestCount errorCount maxTime)
55
+ },
56
+ :datasource => {
57
+ :pattern => 'jboss.jca:service=ManagedConnectionPool,name=#{resource}',
58
+ :properties => %W(MinSize MaxSize AvailableConnectionCount InUseConnectionCount ConnectionCount)
59
+ },
60
+ :queue => {
61
+ :pattern => 'jboss.messaging.destination:service=Queue,name=#{resource}',
62
+ :properties => %W(Name JNDIName MessageCount DeliveringCount
63
+ ScheduledMessageCount MaxSize FullSize Clustered ConsumerCount)
64
+ },
65
+ :ejb => {
66
+ :pattern => 'jboss.j2ee:#{resource},service=EJB3',
67
+ :properties => %W(CreateCount RemoveCount CurrentSize AvailableCount)
68
+ }
69
+ }
70
+ end
71
+
72
+ def properties mbean_id = nil
73
+ @properties ||= {}
74
+ return properties[mbean_id] if mbean_id
75
+ @properties
76
+ end
77
+
78
+ def mbeans
79
+ @mbeans ||= {}
80
+ @mbeans
81
+ end
82
+
83
+ def resources mbean_id = nil, *resources
84
+ @resources ||= {}
85
+ return @resources unless mbean_id
86
+ return @resources[mbean_id] unless resources
87
+ if mbean_id.is_a? Array
88
+ mbean_id.each do |id|
89
+ @resources[id] = resources
90
+ end
91
+ else
92
+ @resources[mbean_id] = resources
93
+ end
94
+ end
95
+
96
+ def monitor mbean_id, params
97
+ mbeans[mbean_id] = JBoss::MBean::new :pattern => params[:pattern], :twiddle => @twiddle
98
+ properties[mbean_id] = params[:properties]
99
+ end
100
+
101
+ def with resource
102
+ resource = send resource if resource.is_a? Symbol
103
+ if block_given?
104
+ if resource.kind_of? Array
105
+ resource.each do |res|
106
+ @current_resource = res
107
+ yield res
108
+ @current_resource = nil
109
+ end
110
+ else
111
+ @current_resource = resource
112
+ yield
113
+ @current_resource = nil
114
+ end
115
+ end
116
+ end
117
+
118
+ def mbean mbean_id = nil
119
+ return get current_scan unless mbean_id
120
+ mbeans[mbean_id]
121
+ end
122
+
123
+ def get mbean_id
124
+ mbean = mbeans[mbean_id]
125
+ if @current_resource
126
+ mbean.with @current_resource
127
+ end
128
+ mbean
129
+ end
130
+
131
+ alias_method :[], :get
132
+
133
+ def method_missing(method, *args, &block)
134
+ mbean_id = method
135
+ mbean = mbeans[mbean_id]
136
+ resource = args[0] || @current_resource
137
+ mbean.with resource
138
+ end
139
+
140
+ end
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,92 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require "set"
24
+
25
+ module JBoss
26
+ module Twiddle
27
+ module Scanner
28
+
29
+ def webapps
30
+ _query_ "jboss.web:type=Manager,*" do |path|
31
+ path.gsub! "jboss.web:type=Manager,path=/", ""
32
+ path.gsub! /,host=.+/, ''
33
+ path
34
+ end
35
+ end
36
+
37
+ def datasources
38
+ _query_ "jboss.jca:service=ManagedConnectionPool,*" do |path|
39
+ path.gsub "jboss.jca:service=ManagedConnectionPool,name=", ""
40
+ end
41
+ end
42
+
43
+ def connectors
44
+ _query_ "jboss.web:type=ThreadPool,*" do |path|
45
+ path.gsub "jboss.web:type=ThreadPool,name=", ""
46
+ end
47
+ end
48
+
49
+ def queues
50
+ _query_ "jboss.messaging.destination:service=Queue,*" do |path|
51
+ path.gsub "jboss.messaging.destination:service=Queue,name=", ""
52
+ end
53
+ end
54
+
55
+ def ejbs
56
+ result = _query_ "jboss.j2ee:service=EJB3,*"
57
+ (result.find_all {|path| path["name="] && path["jar="]}).collect do |path|
58
+ path.gsub("jboss.j2ee:", '').gsub(/,?service=EJB3/, '')
59
+ end
60
+ end
61
+
62
+ def deployments
63
+ wars = _query_ "jboss.web.deployment:*" do |path|
64
+ path.gsub("jboss.web.deployment:", "").split(/,/).find {|p| p.start_with? "war="}
65
+ end
66
+ ears = _query_ "jboss.j2ee:*"
67
+ ears = (ears.find_all {|path| path["ear="] && path["jar="]}).collect do |path|
68
+ path.gsub("jboss.j2ee:",'').split(/,/).find {|p| p.start_with? "ear="}
69
+ end
70
+ result = Set::new
71
+ (wars + ears).each do |deployment|
72
+ result << deployment
73
+ end
74
+ result
75
+ end
76
+
77
+ def can_scan? resource
78
+ self.respond_to? resource.to_sym
79
+ end
80
+
81
+ private
82
+
83
+ def _query_ query, &block
84
+ result = @twiddle.invoke(:query, query)
85
+ return [] if result["No MBean matches for query"]
86
+ result = result.split /\s+/
87
+ block ? result.collect(&block) : result
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,71 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2011 Marcelo Guimarães <ataxexe@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ module JBoss
24
+ module Twiddle
25
+ class Invoker
26
+
27
+ attr_reader :jboss_host, :jboss_port, :jboss_home, :jmx_user, :jmx_password
28
+ attr_accessor :command
29
+
30
+ def initialize params = {}
31
+ params = {
32
+ :jboss_home => ENV["JBOSS_HOME"],
33
+ :jboss_server => nil,
34
+ :jboss_host => '127.0.0.1',
35
+ :jboss_port => 1099,
36
+ :jmx_user => "admin",
37
+ :jmx_password => "admin"
38
+ }.merge! params
39
+ @jboss_home = params[:jboss_home]
40
+
41
+ @jboss_host = params[:jboss_host]
42
+ @jboss_port = params[:jboss_port]
43
+ @jboss_server = params[:jboss_server]
44
+ @jboss_server ||= [@jboss_host, @jboss_port].join ':'
45
+
46
+ @jmx_user = params[:jmx_user]
47
+ @jmx_password = params[:jmx_password]
48
+
49
+ @command = "#{@jboss_home}/bin/twiddle.sh -s #{@jboss_server} -u '#{@jmx_user}' -p '#{@jmx_password}'"
50
+ end
51
+
52
+ def home
53
+ @jboss_home
54
+ end
55
+
56
+ def invoke command, *arguments
57
+ execute(shell command, arguments)
58
+ end
59
+
60
+ def shell operation, *arguments
61
+ "#{command} #{operation} #{arguments.join " "}"
62
+ end
63
+
64
+ def execute shell
65
+ `#{shell}`.chomp
66
+ end
67
+
68
+ end
69
+
70
+ end
71
+ end