Class: LdsCfPlugin::Tunnel
- Inherits:
-
CF::CLI
- Object
- CF::CLI
- LdsCfPlugin::Tunnel
- Defined in:
- lib/lds-cf-plugin/tunnel.rb
Instance Method Summary collapse
- #filter_debug_instances(app, instances) ⇒ Object
- #precondition ⇒ Object
- #tunnel(app, instances, mode, &post_tunnel) ⇒ Object
- #tunnel_console(&post_tunnel) ⇒ Object
- #tunnel_debug ⇒ Object
- #visualvm ⇒ Object
Instance Method Details
#filter_debug_instances(app, instances) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 55 def filter_debug_instances(app, instances) instances.keep_if do |instance| debugger = instance.debugger puts "#{c('Debugger information for instance', :error)} ##{c(instance.id, :number)} #{c('of', :error)} #{c(app.name, :name)} #{c('not available', :error)}" unless debugger debugger end end |
#precondition ⇒ Object
15 16 17 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 15 def precondition check_target end |
#tunnel(app, instances, mode, &post_tunnel) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 141 def tunnel(app, instances, mode, &post_tunnel) server = input[:tunnel_server] ? input[:tunnel_server] : URI(client.target).host server_port = input[:tunnel_server_port] host = input[:host] port = input[:port] line EventMachine.error_handler do |e| puts "Error: #{c(e, :error)}" log_error(e) end EventMachine.run do instances.each do |instance| TunnelClient::tunnel(client.token.auth_header, server, server_port, app, instance.id, mode, host, port, input[:use_tls]) puts "Listening on #{c(host + ':' + port.to_s, :number)} for #{c(mode, :warning)} connections to forward to #{c(app.name, :name)} instance #{c('#' + instance.id, :instance)}." port = port + 1 end yield instances if post_tunnel end end |
#tunnel_console(&post_tunnel) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 77 def tunnel_console(&post_tunnel) app = input[:app] instances = get_instances(app) instances.keep_if do |instance| console = instance.console puts "#{c('Console information for instance', :error)} ##{c(instance.id, :number)} #{c('of', :error)} #{c(app.name, :name)} #{c(' not available', :error)}" unless console console end fail "Console information for #{c(app.name, :name)} not available." unless instances.size > 0 tunnel(app, instances, "console", &post_tunnel) end |
#tunnel_debug ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 33 def tunnel_debug app = input[:app] instances = get_instances(app) filter_debug_instances(app, instances) unless instances.size > 0 if ask("Restart application #{c(app.name, :name)} in debug mode?", :default => true) invoke :restart, :app => app, :debug_mode => "" instances = get_instances(app) filter_debug_instances(app, instances) else fail "Unable to debug #{c(app.name, :name)} because it is not running in debug mode." end end fail "Debugger information for #{c(app.name, :name)} still not available." unless instances.size > 0 tunnel(app, instances, "debug") end |
#visualvm ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/lds-cf-plugin/tunnel.rb', line 107 def visualvm if !File::exist?(JMXMP_JAR_FILE) with_progress("Downloading JMXMP extension") do File.open(JMXMP_JAR_FILE, "wb") do |saved_file| open(JMXMP_JAR_URL, 'rb') do |read_file| saved_file.write(read_file.read) end end end end tunnel_console do |instances| visualvm = input[:jvisualvm] ? input[:jvisualvm] : "jvisualvm" EventMachine::defer do if system("\"#{visualvm}\" -cp:a \"#{JMXMP_JAR_FILE}\"") == nil fail("Unable to run '#{visualvm}'. Is it in your PATH? If not you can specify where visual vm is with --jvisualvm (e.g. cf visualvm some-app --jvisualvm \"c:/java/bin/jvisualvm.exe\"") end end EventMachine::defer do # Give jvisualvm time to start up sleep(5) host = input[:host] port = input[:port] instances.each do |instance| jmxurl = "service:jmx:jmxmp://#{host}:#{port}" puts "Adding instance #{c('#' + instance.id, :instance)} to VisualVM (#{c(jmxurl, :instance)})" system("\"#{visualvm}\" --openjmx #{jmxurl}") port = port + 1 end end end end |