Latest OpenShift enabled port-forwarding for your OpenShift applications.
This enables you to use a debugger for your JBoss application and it allows you to connect to the database directly and use tools like Eclipse Database Browser instead of only using phpsqlmyadmin.
Of course once you have these things setup in your Eclipse you can use things like reverse engineering and even run your local app against the remote database.
It all works by setting up an ssh tunnel that exposes the internal remote ports running on OpenShift servers on your local machine - this does require some manual steps which i'm outlining in this blog
together with how to configure the database setup in Eclipse and how to remote debug JBoss running on OpenShift.
In future releases of JBoss Tools we'll be looking at simplifying these steps, but for now here are the fully manual steps.
Setting up port forward
The simplest way to do this is to use the rhc command line tools.
Make sure you got the latest version - how to install/update these for various platforms is documented here.
Once you have those run
rhc-port-forward -a <appname>.
I have an app called ‘fonk’ of type ‘jboss-as7’ and with ‘mysql’ cartridge enabled. For such a setup you should see something like this:
rhc-port-forward -a fonk Password: Checking available ports... Binding httpd -> 127.1.255.130:8080... Binding java -> 127.1.255.129:8080... Binding mysqld -> 127.1.255.129:3306... Use ctl + c to stop
In case you get an error print out similar to this:
bind: Can't assign requested address channel_setup_fwd_listener: cannot listen to port: 3306 bind: Can't assign requested address channel_setup_fwd_listener: cannot listen to port: 8080 bind: Can't assign requested address channel_setup_fwd_listener: cannot listen to port: 8080 Could not request local forwarding.
You are most likely running OS X which unfortunately(?) does not automatically allow you to have all 127.x.x.x IP’s setup with a so called loopback alias.
To fix this you need to add such alias manually for each IP you want to connect to.
In my case that is
127.1.255.129 as seen in the first attempt of using rhc-port-forward. These IP’s will be different for each of your app, thus for `fonk’ app I enable loopback aliases by running the following:
sudo ifconfig lo0 alias 127.1.255.130 sudo ifconfig lo0 alias 127.1.255.129
Now when you run
rhc-port-forward you should not be seeing any
bind: Can't assign requested address. error messages.
Note: these alias’es does not survive reboots - if anyone know how to setup global loopback alias or make these persistent between reboots then I would love to hear about that in the comments
Use OpenShift database locally
When port forwarding is enabled you can start using these, for example to setup and connect to MySql database via Eclipse DTP Tools.
To do this open the Data Source Explorer:
Click on the “New Connection Profile” and choose MySql and give it a name.
Click Next and if you do not have an existing driver for MySQL configured you will see an empty list:
To add a driver click the + icon and setup a driver:
For OpenShift MySQL the 5.1 option is best, and it just needs to be told where the driver is under the “Jar List” tab. Here you click the “Edit JAR/Zip” and point it to your downloaded mysql-connectoer-java-5.1.jar.
Once that is done you just need to fill in the right connection details:
The important part for the connection details is that you set URL to match the pattern:
fonk application that would be:
And then set “User Name” to
admin and type in your MySql password.
You can use the “Test Connection” button to verify you can connect.
When you press Finish you should be able to browse your remote mysql database hosted on OpenShift:
From here on out you can now use this Eclipse dataconnection with any plugin that supports such connections. i.e. Hibernate Tools reverse engineering features.
Debug JBoss AS
To enable debug with JBoss we need to add a
enable_jpda marker file to
This is done by simply executing the following:
cd git/fonk touch .openshift/markers/enable_jpda git add .openshit/markers/enable_jpda git commit -a -m "enable jpda" [master 6f7197c] enable jpda 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .openshift/markers/enable_jpda git push <openshift remote build output>
Note: you can of course also do this all from within Eclipse via EGit integration if you prefer that.
When this have been enabled you need to start/restart port-forwarding to get it to pick up the java jpda port.
rhc-port-forward -a fonk Password: Checking available ports... Binding httpd -> 127.1.255.130:8080... Binding java -> 127.1.255.129:8080... Binding java -> 127.1.255.129:8787... Binding mysqld -> 127.1.255.129:3306... Use ctl + c to stop
Binding java -> 127.1.255.129:8787.... line, that is the jpda ip and port you are going to use.
Now to set this up in Eclipse JDT debugger you need to create a ‘Remote Java Application’ under “Debug Configurations”
And here you select ‘Remote Java Application’ and fill in the connection details:
The important pieces here are to set Host: to the ip number (in my case
127.1.255.129) and the port wich for JBoss AS on OpenShift is
8787 by default.
The Project part is optional, but its useful to point it to the matching Eclipse project which will allow it to find the proper source and let you place breakpoints.
Once you press “Debug” it should go and connect to the running server. It might take a while, it is after all going into the Cloud
And if you now set breakpoints and use a browser to trigger them you get something like this:
This showing the remote debugger hitting the breapoint in a jsp page named
I hope I showed you how powerful OpenShift’s latest release with port-forwarding is and how (fairly) easy it is to setup once you get the port-forwarding working.
Being able to connect directly to the remote database and debug you JBoss server makes for a whole new world of possibilities and productivity boost with OpenShift.
Hope you like it and continues to have fun exploring OpenShift and JBoss Tools.