engineyard-visualvm 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +16 -0
  3. data/LICENSE.txt +23 -0
  4. data/README.md +102 -0
  5. data/Rakefile +76 -0
  6. data/Vagrantfile +94 -0
  7. data/bin/ey-visualvm +9 -0
  8. data/cookbooks/apt/README.md +122 -0
  9. data/cookbooks/apt/files/default/apt-cacher +9 -0
  10. data/cookbooks/apt/files/default/apt-cacher.conf +144 -0
  11. data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
  12. data/cookbooks/apt/metadata.json +34 -0
  13. data/cookbooks/apt/metadata.rb +13 -0
  14. data/cookbooks/apt/providers/repository.rb +73 -0
  15. data/cookbooks/apt/recipes/cacher-client.rb +44 -0
  16. data/cookbooks/apt/recipes/cacher.rb +45 -0
  17. data/cookbooks/apt/recipes/default.rb +50 -0
  18. data/cookbooks/apt/resources/repository.rb +30 -0
  19. data/cookbooks/gems/recipes/default.rb +16 -0
  20. data/cookbooks/java/README.md +102 -0
  21. data/cookbooks/java/attributes/default.rb +29 -0
  22. data/cookbooks/java/files/default/java.seed +11 -0
  23. data/cookbooks/java/metadata.json +50 -0
  24. data/cookbooks/java/metadata.rb +16 -0
  25. data/cookbooks/java/recipes/default.rb +21 -0
  26. data/cookbooks/java/recipes/openjdk.rb +39 -0
  27. data/cookbooks/java/recipes/sun.rb +93 -0
  28. data/cookbooks/jruby/attributes/default.rb +2 -0
  29. data/cookbooks/jruby/recipes/default.rb +24 -0
  30. data/cookbooks/server/recipes/default.rb +9 -0
  31. data/cookbooks/server/templates/default/server.sh.erb +27 -0
  32. data/cookbooks/vagrant_main/recipes/default.rb +4 -0
  33. data/engineyard-visualvm.gemspec +28 -0
  34. data/ext/org/jruby/ext/jmx/Agent.java +169 -0
  35. data/ext/org/jruby/ext/jmx/JavaHome.java +7 -0
  36. data/ext/org/jruby/ext/jmx/RMIServerSocketFactoryImpl.java +37 -0
  37. data/lib/engineyard-visualvm.rb +8 -0
  38. data/lib/engineyard-visualvm/agent.jar +0 -0
  39. data/lib/engineyard-visualvm/cli.rb +205 -0
  40. data/lib/engineyard-visualvm/version.rb +11 -0
  41. data/spec/engineyard-visualvm_spec.rb +164 -0
  42. data/spec/spec_helper.rb +30 -0
  43. metadata +154 -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.0"
10
+ end
11
+ end
@@ -0,0 +1,164 @@
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::CLI do
10
+ let(:script) { Class.new(EngineYard::VisualVM::CLI) }
11
+
12
+ context "#help" do
13
+ it "prints the default port" do
14
+ capture { script.start(["help", "start"]) }.should =~ /Default:/
15
+ end
16
+ end
17
+
18
+ context "#url" do
19
+ it "prints a JMX service URL" do
20
+ capture { script.start(["url"]) }.should =~ /service:jmx:rmi/
21
+ end
22
+
23
+ it "allows the port number to be specified" do
24
+ capture { script.start(["url", "--port=1234"]) }.should =~ /service:jmx:rmi.*:1234/
25
+ end
26
+ end
27
+
28
+ context "#start" do
29
+ let(:ssh_process) { double("ssh process double").tap {|d| d.should_receive(:start) } }
30
+ let(:visualvm_process) do
31
+ double("visualvm process double").tap {|d|
32
+ d.should_receive(:start)
33
+ d.should_receive(:exited?).and_return(true)
34
+ }
35
+ end
36
+
37
+ before :each do
38
+ script.class_eval do
39
+ no_tasks { define_method(:fetch_environment) { raise EY::Error, "error" } }
40
+ end
41
+ end
42
+
43
+ it "starts jvisualvm with the service URL" do
44
+ ChildProcess.should_receive(:build).and_return do |*args|
45
+ args[0].should == "jvisualvm"
46
+ args[1].should == "--openjmx"
47
+ args[2].should =~ /service:jmx:rmi/
48
+ visualvm_process
49
+ end
50
+ script.start(["start"])
51
+ end
52
+
53
+ it "allows the port number to be specified" do
54
+ ChildProcess.should_receive(:build).and_return do |*args|
55
+ args[2].should =~ /service:jmx:rmi.*:1234/
56
+ visualvm_process
57
+ end
58
+ script.start(["start", "--port=1234"])
59
+ end
60
+
61
+ it "allows the host to be specified" do
62
+ ChildProcess.should_receive(:build).and_return do |*args|
63
+ args[2].should =~ /service:jmx:rmi.*example.com:/
64
+ visualvm_process
65
+ end
66
+ script.start(["start", "--host=example.com"])
67
+ end
68
+
69
+ it "sets up an ssh tunnel if the user@host format is used" do
70
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
71
+ args.join(' ').should =~ /ssh -NL.*user@example.com/
72
+ ssh_process
73
+ end
74
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
75
+ args[2].should =~ /service:jmx:rmi.*localhost:/
76
+ visualvm_process
77
+ end
78
+ ssh_process.should_receive(:stop)
79
+
80
+ script.start(["start", "--host=user@example.com"])
81
+ end
82
+
83
+ it "allows an ssh tunnel to be forced" do
84
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
85
+ args.join(' ').should =~ /ssh -NL/
86
+ ssh_process
87
+ end
88
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
89
+ args[2].should =~ /service:jmx:rmi.*localhost:/
90
+ visualvm_process
91
+ end
92
+ ssh_process.should_receive(:stop)
93
+
94
+ script.start(["start", "--ssh"])
95
+ end
96
+
97
+ context "with a port conflict" do
98
+ before :each do
99
+ @port = EngineYard::VisualVM::Helpers.next_free_port
100
+ @server = TCPServer.new("127.0.0.1", @port)
101
+ @next_port = EngineYard::VisualVM::Helpers.next_free_port
102
+ end
103
+
104
+ after :each do
105
+ @server.close; @server = nil
106
+ end
107
+
108
+ it "finds an open port for the local side of the ssh tunnel" do
109
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
110
+ args.join(' ').should =~ /ssh -NL #{@next_port}:localhost:#{@port}/
111
+ ssh_process
112
+ end
113
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
114
+ args[2].should =~ /service:jmx:rmi.*localhost:/
115
+ visualvm_process
116
+ end
117
+ ssh_process.should_receive(:stop)
118
+
119
+ script.start(["start", "--ssh", "--port=#{@port}"])
120
+ end
121
+ end
122
+
123
+ context "with --environment specified" do
124
+ let(:environment) do
125
+ double(:environment).tap {|e|
126
+ e.stub!(:load_balancer_ip_address).and_return "0.0.0.0"
127
+ e.stub!(:username).and_return "deploy"
128
+ }
129
+ end
130
+ before :each do
131
+ env = environment
132
+ script.class_eval do
133
+ no_tasks { define_method(:fetch_environment) { env } }
134
+ end
135
+ end
136
+
137
+ it "sets the user to 'deploy' and the host to the load balancer IP address" do
138
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
139
+ args.join(' ').should =~ /ssh -NL.* deploy@0.0.0.0/
140
+ ssh_process
141
+ end
142
+ ChildProcess.should_receive(:build).ordered.and_return do |*args|
143
+ args[2].should =~ /service:jmx:rmi.*localhost:/
144
+ visualvm_process
145
+ end
146
+ ssh_process.should_receive(:stop)
147
+
148
+ script.start(["start", "--environment=jruby"])
149
+ end
150
+ end
151
+ end
152
+
153
+ context "#jvmargs" do
154
+ it "prints the arguments for the server VM" do
155
+ output = capture { script.start(["jvmargs"]) }
156
+ output.should =~ /-Dorg\.jruby\.jmx\.agent\.port=/
157
+ output.should =~ /-javaagent:.*agent\.jar/
158
+ end
159
+
160
+ it "allows the port number to be specified" do
161
+ capture { script.start(["jvmargs", "--port=1234"]) }.should =~ /-Dorg\.jruby\.jmx\.agent\.port=1234/
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,30 @@
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
+ RSpec.configure do |config|
29
+ config.include EYVisualVMSpecHelpers
30
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: engineyard-visualvm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.5.0
6
+ platform: ruby
7
+ authors:
8
+ - Nick Sieger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-11-30 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
+ - Gemfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - Vagrantfile
89
+ - bin/ey-visualvm
90
+ - cookbooks/apt/README.md
91
+ - cookbooks/apt/files/default/apt-cacher
92
+ - cookbooks/apt/files/default/apt-cacher.conf
93
+ - cookbooks/apt/files/default/apt-proxy-v2.conf
94
+ - cookbooks/apt/metadata.json
95
+ - cookbooks/apt/metadata.rb
96
+ - cookbooks/apt/providers/repository.rb
97
+ - cookbooks/apt/recipes/cacher-client.rb
98
+ - cookbooks/apt/recipes/cacher.rb
99
+ - cookbooks/apt/recipes/default.rb
100
+ - cookbooks/apt/resources/repository.rb
101
+ - cookbooks/gems/recipes/default.rb
102
+ - cookbooks/java/README.md
103
+ - cookbooks/java/attributes/default.rb
104
+ - cookbooks/java/files/default/java.seed
105
+ - cookbooks/java/metadata.json
106
+ - cookbooks/java/metadata.rb
107
+ - cookbooks/java/recipes/default.rb
108
+ - cookbooks/java/recipes/openjdk.rb
109
+ - cookbooks/java/recipes/sun.rb
110
+ - cookbooks/jruby/attributes/default.rb
111
+ - cookbooks/jruby/recipes/default.rb
112
+ - cookbooks/server/recipes/default.rb
113
+ - cookbooks/server/templates/default/server.sh.erb
114
+ - cookbooks/vagrant_main/recipes/default.rb
115
+ - engineyard-visualvm.gemspec
116
+ - ext/org/jruby/ext/jmx/Agent.java
117
+ - ext/org/jruby/ext/jmx/JavaHome.java
118
+ - ext/org/jruby/ext/jmx/RMIServerSocketFactoryImpl.java
119
+ - lib/engineyard-visualvm.rb
120
+ - lib/engineyard-visualvm/agent.jar
121
+ - lib/engineyard-visualvm/cli.rb
122
+ - lib/engineyard-visualvm/version.rb
123
+ - spec/engineyard-visualvm_spec.rb
124
+ - spec/spec_helper.rb
125
+ homepage: https://github.com/engineyard/engineyard-visualvm
126
+ licenses: []
127
+
128
+ post_install_message:
129
+ rdoc_options: []
130
+
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: "0"
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ requirements: []
146
+
147
+ rubyforge_project: jruby-extras
148
+ rubygems_version: 1.8.9
149
+ signing_key:
150
+ specification_version: 3
151
+ summary: Client and server helpers for using JMX and VisualVM with EY Cloud.
152
+ test_files:
153
+ - spec/engineyard-visualvm_spec.rb
154
+ - spec/spec_helper.rb