Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

enable remote java web application debugging #116

Closed
wants to merge 2 commits into from

2 participants

@dbao

This feature is to enable remote java web application debugging. It has been tested and verified. A wiki page has been created to show how to use the feature.

@ramnivas

I examined the pull request. While implementation is simple, it cannot serve the need of various clouds we offer (open source, Micro Cloud Foundry, CloudFoundry.com, and other clouds hosted by partners). For example, you are expecting clients to specify the debug port through an env variable. How does a developer know which ports are free (realize that he may be deploying to a machine other than local and there may be many applications running on the same box)? This will force developers to keep trying (stop, add-env, start cycle) until a free port is found. Second, the user experience is not as good as we will like (official implementation requires just passing '-d' to 'vmc push'). Third, there is no ability to reject debugging per cloud installation basis. For example, we do not want users to debug (production) applications on cloudfoundry.com (and even if your pull request is accepted, won't work due to how ports are opened etc., this consuming a port for no benefit).

Take a look at official implementation. It may look complex (you comment earlier), but because it addresses all issue I raise above.

As I mentioned earlier, extending the official debugging support to other languages (one of your earlier questions) is far more useful than re-doing Java debugging.

@ramnivas ramnivas closed this
@dbao

Thanks for your comments. I knew there must be some reason that you made more sophisticated changes. We had similar idea initially as yours, later, we decided to go with simple one. You are right, the port availability is the major issue in my implementation if we consider all-around cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2011
  1. enable java debugging

    Dalun Bao authored
Commits on Sep 12, 2011
  1. added readme file for enabling java debugging

    Dalun Bao authored
This page is out of date. Refresh to see the latest.
View
5 cloud_controller/staging/common.rb
@@ -293,6 +293,10 @@ def start_command
app_server['executable']
end
+ def debug_options
+ #interface for debugging options
+ end
+
def local_runtime
'%VCAP_LOCAL_RUNTIME%'
end
@@ -383,6 +387,7 @@ def generate_startup_script(env_vars = {})
after_env_before_script = block_given? ? yield : "\n"
template = <<-SCRIPT
#!/bin/bash
+<%= debug_options %>
<%= environment_statements_for(env_vars) %>
<%= after_env_before_script %>
<%= change_directory_for_start %>
View
21 cloud_controller/staging/java_web/plugin.rb
@@ -44,14 +44,31 @@ def change_directory_for_start
# We redefine this here because Tomcat doesn't want to be passed the cmdline
# args that were given to the 'start' script.
def start_command
- "./bin/catalina.sh run"
+ "./bin/catalina.sh $my_jpda run"
end
def configure_catalina_opts
# We want to set this to what the user requests, *not* set a minum bar
- "-Xms#{application_memory}m -Xmx#{application_memory}m"
+ "-Xms#{application_memory}m -Xmx#{application_memory}m $my_verbose"
end
+ # redefine debugging options, only works for java app
+ def debug_options
+ <<-SCRIPT
+my_jpda=""
+my_verbose=""
+if [ -n "${JPDA+x}" ]; then
+ my_jpda="jpda"
+ my_verbose="-verbose"
+fi
+EXPORT my_jpda
+EXPORT my_verbose
+echo "debug flag : $my_jpda, $my_verbose and JPDA=$JPDA" >debug.log
+ SCRIPT
+ end
+
+
+
private
def startup_script
vars = environment_hash
View
11 cloud_controller/staging/java_web/resources/set_environment
@@ -12,4 +12,15 @@ env = []
env << "-D#{protocol}.proxyHost=#{uri.host} -D#{protocol}.proxyPort=#{uri.port}"
end
end
+
+#debug settins for java debugging
+jpda = ENV['JPDA']
+if jpda
+ {'JPDA_TRANSPORT' => 'dt_socket', 'JPDA_ADDRESS' => '8000', 'JPDA_SUSPEND' => 'n'}.each do |env_var, env_val|
+ ipda_opts = ENV[env_var]
+ ipda_opts = env_val unless ipda_opts
+ env << "-D#{env_var}=#{ipda_opts}"
+ end
+end
+
puts env.join(' ')
View
21 docs/java_debugging.md
@@ -0,0 +1,21 @@
+Instruction on how to enable remote debugging on Java application:
+
+1. Setup Java app for remote debugging with Cloud Foundry
+
+1) Deploy your Java web application as normal vmc push process
+2) Stop the application running "vmc stop [appname]"
+3) Run "vmc env-add [appname] JPDA=1". This will enable debugging for the Java application
+4) You have choice to set the port number for debugging by running
+ vmc env-add [appname] JPDA_ADDRESS=8080
+5) Restart the application by running "vmc start [appname]". You are ready to debug your application.
+
+2. Clean-up after remote debugging
+
+You need to remove the environment variables that you set for remote debugging.
+
+1) Run "vmc env [appname]" to lookup all environment variables that you set
+2) Stop your app by running "vmc stop [appname]"
+3) Remove JPDA variable by "vmc env-del [appname] JPDA"
+4) Remove JPDA_ADDRESS by running "vmc env-del [appname] JPDA_ADDRESS"
+5) Restart your application by running "vmc start [appname]".
+
Something went wrong with that request. Please try again.