engineyard-visualvm 0.5.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/.gitignore +5 -0
  2. data/ChangeLog +22 -0
  3. data/Gemfile +26 -0
  4. data/LICENSE.txt +23 -0
  5. data/README.md +104 -0
  6. data/Rakefile +124 -0
  7. data/Vagrantfile +94 -0
  8. data/bin/ey-visualvm +9 -0
  9. data/cookbooks/apt/README.md +122 -0
  10. data/cookbooks/apt/files/default/apt-cacher +9 -0
  11. data/cookbooks/apt/files/default/apt-cacher.conf +144 -0
  12. data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
  13. data/cookbooks/apt/metadata.json +34 -0
  14. data/cookbooks/apt/metadata.rb +13 -0
  15. data/cookbooks/apt/providers/repository.rb +73 -0
  16. data/cookbooks/apt/recipes/cacher-client.rb +44 -0
  17. data/cookbooks/apt/recipes/cacher.rb +45 -0
  18. data/cookbooks/apt/recipes/default.rb +50 -0
  19. data/cookbooks/apt/resources/repository.rb +30 -0
  20. data/cookbooks/gems/recipes/default.rb +16 -0
  21. data/cookbooks/java/README.md +102 -0
  22. data/cookbooks/java/attributes/default.rb +29 -0
  23. data/cookbooks/java/files/default/java.seed +11 -0
  24. data/cookbooks/java/metadata.json +50 -0
  25. data/cookbooks/java/metadata.rb +16 -0
  26. data/cookbooks/java/recipes/default.rb +21 -0
  27. data/cookbooks/java/recipes/openjdk.rb +39 -0
  28. data/cookbooks/java/recipes/sun.rb +93 -0
  29. data/cookbooks/jruby/attributes/default.rb +2 -0
  30. data/cookbooks/jruby/recipes/default.rb +24 -0
  31. data/cookbooks/server/recipes/default.rb +9 -0
  32. data/cookbooks/server/templates/default/server.sh.erb +27 -0
  33. data/cookbooks/vagrant_main/recipes/default.rb +4 -0
  34. data/engineyard-visualvm-java.gemspec +47 -0
  35. data/engineyard-visualvm.gemspec +43 -0
  36. data/engineyard-visualvm.gemspec.in +35 -0
  37. data/ext/org/jruby/ext/jmx/Agent.java +169 -0
  38. data/ext/org/jruby/ext/jmx/JavaHome.java +7 -0
  39. data/ext/org/jruby/ext/jmx/RMIServerSocketFactoryImpl.java +37 -0
  40. data/lib/engineyard-visualvm.rb +8 -0
  41. data/lib/engineyard-visualvm/agent.jar +0 -0
  42. data/lib/engineyard-visualvm/cli.rb +225 -0
  43. data/lib/engineyard-visualvm/version.rb +11 -0
  44. data/spec/engineyard-visualvm_spec.rb +202 -0
  45. data/spec/spec_helper.rb +49 -0
  46. metadata +157 -0
@@ -0,0 +1,11 @@
1
+ #--
2
+ # Copyright (c) 2011 Engine Yard, Inc.
3
+ # See the file LICENSE.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ module EngineYard
8
+ module VisualVM
9
+ VERSION = "0.5.3"
10
+ end
11
+ end
@@ -0,0 +1,202 @@
1
+ #--
2
+ # Copyright (c) 2011 Engine Yard, Inc.
3
+ # See the file LICENSE.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require File.expand_path('../spec_helper', __FILE__)
8
+
9
+ describe EngineYard::VisualVM::Helpers do
10
+ context "when included in a class"
11
+ let(:object) do
12
+ clz = Class.new
13
+ clz.class_eval { include EngineYard::VisualVM::Helpers }
14
+ clz.new
15
+ end
16
+
17
+ it "can calculate JVM arguments" do
18
+ object.jvm_arguments.tap {|args|
19
+ args.should =~ /org\.jruby\.jmx\.agent/
20
+ args.should =~ /javaagent:.*agent\.jar/
21
+ }
22
+ end
23
+ end
24
+
25
+ describe EngineYard::VisualVM::CLI do
26
+ let(:script) { Class.new(EngineYard::VisualVM::CLI) { include SystemDouble } }
27
+
28
+ context "#help" do
29
+ it "prints the default port" do
30
+ capture { script.start(["help", "start"]) }.should =~ /Default:/
31
+ end
32
+ end
33
+
34
+ context "#url" do
35
+ it "prints a JMX service URL" do
36
+ capture { script.start(["url"]) }.should =~ /service:jmx:rmi/
37
+ end
38
+
39
+ it "allows the port number to be specified" do
40
+ capture { script.start(["url", "--port=1234"]) }.should =~ /service:jmx:rmi.*:1234/
41
+ end
42
+ end
43
+
44
+ context "#start" do
45
+ let(:system_double) { double("system").tap {|d| script.system_double = d } }
46
+ let(:ssh_process) { double("ssh process double").tap {|d| d.should_receive(:start) } }
47
+ let(:visualvm_process) do
48
+ double("visualvm process double").tap {|d|
49
+ d.should_receive(:start)
50
+ d.should_receive(:exited?).and_return(true)
51
+ }
52
+ end
53
+
54
+ before :each do
55
+ script.class_eval do
56
+ no_tasks { define_method(:fetch_environment) {|e,a| raise EY::Error, "error" } }
57
+ end
58
+ end
59
+
60
+ it "starts jvisualvm with the service URL" do
61
+ ChildProcess.should_receive(:build).and_return do |*args|
62
+ args[0].should == "jvisualvm"
63
+ args[1].should == "--openjmx"
64
+ args[2].should =~ /service:jmx:rmi/
65
+ visualvm_process
66
+ end
67
+ script.start(["start"])
68
+ end
69
+
70
+ it "allows the port number to be specified" do
71
+ ChildProcess.should_receive(:build).and_return do |*args|
72
+ args[2].should =~ /service:jmx:rmi.*:1234/
73
+ visualvm_process
74
+ end
75
+ script.start(["start", "--port=1234"])
76
+ end
77
+
78
+ it "allows the host to be specified" do
79
+ ChildProcess.should_receive(:build).and_return do |*args|
80
+ args[2].should =~ /service:jmx:rmi.*example.com:/
81
+ visualvm_process
82
+ end
83
+ script.start(["start", "--host=example.com"])
84
+ end
85
+
86
+ it "sets up an ssh tunnel if the user@host format is used" do
87
+ system_double.should_receive(:system).with("ssh user@example.com true").ordered.and_return true
88
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
89
+ args.join(' ').should =~ /ssh -NL.*user@example.com/
90
+ ssh_process
91
+ end
92
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
93
+ args[2].should =~ /service:jmx:rmi.*localhost:/
94
+ visualvm_process
95
+ end
96
+ ssh_process.should_receive(:stop)
97
+
98
+ script.start(["start", "--host=user@example.com"])
99
+ end
100
+
101
+ it "allows an ssh tunnel to be forced" do
102
+ system_double.should_receive(:system).ordered.and_return true
103
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
104
+ args.join(' ').should =~ /ssh -NL/
105
+ ssh_process
106
+ end
107
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
108
+ args[2].should =~ /service:jmx:rmi.*localhost:/
109
+ visualvm_process
110
+ end
111
+ ssh_process.should_receive(:stop)
112
+
113
+ script.start(["start", "--ssh"])
114
+ end
115
+
116
+ context "with a port conflict" do
117
+ before :each do
118
+ @port = EngineYard::VisualVM::Helpers.next_free_port
119
+ @server = TCPServer.new("127.0.0.1", @port)
120
+ @next_port = EngineYard::VisualVM::Helpers.next_free_port
121
+ end
122
+
123
+ after :each do
124
+ @server.close; @server = nil
125
+ end
126
+
127
+ it "finds an open port for the local side of the ssh tunnel" do
128
+ system_double.should_receive(:system).ordered.and_return true
129
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
130
+ args.join(' ').should =~ /ssh -NL #{@next_port}:localhost:#{@port}/
131
+ ssh_process
132
+ end
133
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
134
+ args[2].should =~ /service:jmx:rmi.*localhost:/
135
+ visualvm_process
136
+ end
137
+ ssh_process.should_receive(:stop)
138
+
139
+ script.start(["start", "--ssh", "--port=#{@port}"])
140
+ end
141
+ end
142
+
143
+ context "with --environment specified" do
144
+ let(:environment) do
145
+ double(:environment).tap {|e|
146
+ e.stub!(:username).and_return "deploy"
147
+ }
148
+ end
149
+ before :each do
150
+ env = environment
151
+ script.class_eval do
152
+ no_tasks { define_method(:fetch_environment) {|e,a| env } }
153
+ end
154
+ end
155
+
156
+ it "sets the user to 'deploy' and the host to the load balancer IP address" do
157
+ system_double.should_receive(:system).ordered.and_return true
158
+ environment.stub!(:load_balancer_ip_address).and_return "0.0.0.0"
159
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
160
+ args.join(' ').should =~ /ssh -NL.* deploy@0.0.0.0/
161
+ ssh_process
162
+ end
163
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
164
+ args[2].should =~ /service:jmx:rmi.*localhost:/
165
+ visualvm_process
166
+ end
167
+ ssh_process.should_receive(:stop)
168
+
169
+ script.start(["start", "--environment=jruby"])
170
+ end
171
+
172
+ it "uses the public hostname of the first instance if no load balancer" do
173
+ system_double.should_receive(:system).ordered.and_return true
174
+ environment.stub!(:load_balancer_ip_address).and_return nil
175
+ environment.stub!(:instances).and_return [double("instance").tap{|d| d.stub!(:public_hostname).and_return "example.com" }]
176
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
177
+ args.join(' ').should =~ /ssh -NL.* deploy@example.com/
178
+ ssh_process
179
+ end
180
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
181
+ args[2].should =~ /service:jmx:rmi.*localhost:/
182
+ visualvm_process
183
+ end
184
+ ssh_process.should_receive(:stop)
185
+
186
+ script.start(["start", "--environment=jruby"])
187
+ end
188
+ end
189
+ end
190
+
191
+ context "#jvmargs" do
192
+ it "prints the arguments for the server VM" do
193
+ output = capture { script.start(["jvmargs"]) }
194
+ output.should =~ /-Dorg\.jruby\.jmx\.agent\.port=/
195
+ output.should =~ /-javaagent:.*agent\.jar/
196
+ end
197
+
198
+ it "allows the port number to be specified" do
199
+ capture { script.start(["jvmargs", "--port=1234"]) }.should =~ /-Dorg\.jruby\.jmx\.agent\.port=1234/
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,49 @@
1
+ #--
2
+ # Copyright (c) 2011 Engine Yard, Inc.
3
+ # See the file LICENSE.txt included with the distribution for
4
+ # software license details.
5
+ #++
6
+
7
+ require 'rspec'
8
+ require 'engineyard-visualvm'
9
+
10
+ module EYVisualVMSpecHelpers
11
+ def silence(io = nil)
12
+ require 'stringio'
13
+ io = StringIO.new
14
+ old_stdout = $stdout
15
+ old_stderr = $stderr
16
+ $stdout = io
17
+ $stderr = io
18
+ yield
19
+ io.string
20
+ ensure
21
+ $stdout = old_stdout
22
+ $stderr = old_stderr
23
+ end
24
+
25
+ alias capture silence
26
+ end
27
+
28
+ module SystemDouble
29
+ def self.included(base)
30
+ def base.system_double
31
+ @@double
32
+ end
33
+ def base.system_double=(d)
34
+ @@double = d
35
+ end
36
+ end
37
+
38
+ def system_double
39
+ @@double
40
+ end
41
+
42
+ def system(*args)
43
+ system_double.system(*args)
44
+ end
45
+ end
46
+
47
+ RSpec.configure do |config|
48
+ config.include EYVisualVMSpecHelpers
49
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: engineyard-visualvm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.5.3
6
+ platform: java
7
+ authors:
8
+ - Nick Sieger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-12-21 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: childprocess
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: engineyard
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: jruby-openssl
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: ffi-ncurses
50
+ prerelease: false
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
60
+ name: rspec
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id005
70
+ description: |-
71
+ This provides a Java agent and command-line utility to enable
72
+ JMX in any Java process such that it can be accessed through a firewall,
73
+ and a VisualVM launcher aid to connect to that process through ssh.
74
+ email:
75
+ - nick@nicksieger.com
76
+ executables:
77
+ - ey-visualvm
78
+ extensions: []
79
+
80
+ extra_rdoc_files: []
81
+
82
+ files:
83
+ - .gitignore
84
+ - ChangeLog
85
+ - Gemfile
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - Vagrantfile
90
+ - bin/ey-visualvm
91
+ - cookbooks/apt/README.md
92
+ - cookbooks/apt/files/default/apt-cacher
93
+ - cookbooks/apt/files/default/apt-cacher.conf
94
+ - cookbooks/apt/files/default/apt-proxy-v2.conf
95
+ - cookbooks/apt/metadata.json
96
+ - cookbooks/apt/metadata.rb
97
+ - cookbooks/apt/providers/repository.rb
98
+ - cookbooks/apt/recipes/cacher-client.rb
99
+ - cookbooks/apt/recipes/cacher.rb
100
+ - cookbooks/apt/recipes/default.rb
101
+ - cookbooks/apt/resources/repository.rb
102
+ - cookbooks/gems/recipes/default.rb
103
+ - cookbooks/java/README.md
104
+ - cookbooks/java/attributes/default.rb
105
+ - cookbooks/java/files/default/java.seed
106
+ - cookbooks/java/metadata.json
107
+ - cookbooks/java/metadata.rb
108
+ - cookbooks/java/recipes/default.rb
109
+ - cookbooks/java/recipes/openjdk.rb
110
+ - cookbooks/java/recipes/sun.rb
111
+ - cookbooks/jruby/attributes/default.rb
112
+ - cookbooks/jruby/recipes/default.rb
113
+ - cookbooks/server/recipes/default.rb
114
+ - cookbooks/server/templates/default/server.sh.erb
115
+ - cookbooks/vagrant_main/recipes/default.rb
116
+ - engineyard-visualvm-java.gemspec
117
+ - engineyard-visualvm.gemspec
118
+ - engineyard-visualvm.gemspec.in
119
+ - ext/org/jruby/ext/jmx/Agent.java
120
+ - ext/org/jruby/ext/jmx/JavaHome.java
121
+ - ext/org/jruby/ext/jmx/RMIServerSocketFactoryImpl.java
122
+ - lib/engineyard-visualvm.rb
123
+ - lib/engineyard-visualvm/agent.jar
124
+ - lib/engineyard-visualvm/cli.rb
125
+ - lib/engineyard-visualvm/version.rb
126
+ - spec/engineyard-visualvm_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: https://github.com/engineyard/engineyard-visualvm
129
+ licenses: []
130
+
131
+ post_install_message:
132
+ rdoc_options: []
133
+
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: "0"
148
+ requirements: []
149
+
150
+ rubyforge_project: jruby-extras
151
+ rubygems_version: 1.8.9
152
+ signing_key:
153
+ specification_version: 3
154
+ summary: Client and server helpers for using JMX and VisualVM with EY Cloud.
155
+ test_files:
156
+ - spec/engineyard-visualvm_spec.rb
157
+ - spec/spec_helper.rb