Debugging CLC using IntelliJ and Debugger

Follow

Objective

In this article we will understand how to use IntelliJ to connect debugger to a running Eucalyptus cloud and debug certain cloud operations inside the IDE.

One of the many benefit/use of such debugger is that one could put breakpoints at several places in the code and step over the line of code while watching the debug output and sometime also watching variables for certain values.

Eucalyptus developer who develop code for the project uses these feature to test and fix their code. It also help other open source enthusiast to write bug fixes and code features for the software.

Prerequisite

a) Reader should have sufficient experience in reading JAVA and should have a programming background to understand the logical flow of code.

b) IntelliJ IDE 13

c) Eucalyptus 3.4.2 cloud

d) git

e) JAVA JDK 1.7.x

f) gradle 1.11

Steps

1) Install IntelliJ IDE 13 on your system and configure it with JAVA JDK 1.7.x 

2) Configure Eucalyptus CLC to accept debugger connection by modifying CLOUD_OPTS in /etc/eucalyptus/eucalyptus.conf like this:

CLOUD_OPTS="--debug"

After modifying the value please restart the CLC service for the changes to take affect:

service eucalyptus-cloud restart

The debug port would be 5005 and same can be verified by following command on CLC:

netstat -tulpn | grep 5005


3) On your system install git and fork the eucalyptus repository by following instructions here:

https://help.github.com/articles/fork-a-repo

Now clone the local eucalyptus repository to your system using following command:

git clone https://github.com/jeevanullas/eucalyptus.git --recursive

4) In order to use IntelliJ IDE with the eucalyptus we would need to build IntelliJ project files using gradle. Instructions listed in the following google group thread would help one to build these files

https://groups.google.com/a/eucalyptus.com/forum/#!msg/develop/pJizeGCm8qM/KMqqq5JB380J

For ease of understanding following steps needs to be followed after downloading build.gradle and settings.gradle in your home directory:

4.1) Navigate inside the directory eucalyptus that gets created after step (3) and checkout the 3.4. master branch. 

cd eucalyptus
git checkout origin/maint/3.4/master

4.2) Now navigate inside the clc/ directory and clone the cloud-libs repository. This is a must do step in order to build the clc project 

cd clc
git clone --depth=1 -b testing git://github.com/eucalyptus/eucalyptus-cloud-libs.git lib
 
4.3) Now setup the clc/ directory for gradle by copying the 2 files settings.gradle and build.gradle (from the google group post) into the clc/ directory
 
cp ~/settings.gradle .
cp ~/build.gradle .
 
4.4) Now we need to modify some of the ivy.xml for modules in the clc project so they can get build. These dependency issues have been resolved in later branches but the 3.4/master branch will have these issues. Kindly look at the diff below:
 
https://gist.github.com/jeevanullas/71536556ee8758d11cab
 
4.5) Finally we build the IntelliJ project files by running gradle like this (inside the clc/ directory):
export PATH=$PATH:~/gradle-1.11/bin
gradle idea
 
Step (4.5) will give us a file call clc.ipr which we would open inside IntelliJ
 
5) Now run IntelliJ on your computer and select "Open Project" then point it to the clc.ipr file in your clc/ directory. 
 
6) After the project is open inside the IDE just select from Build Menu -> Make Project
 
This process should complete with couple of errors which would be in unit tests so safely can be ignored. Following screenshot shows the ones received in one of the builds done locally against the 3.4/master branch
 
 
7) Now we can set up breakpoints anywhere in the code and run the debugger. For the sake of this article we will focus on DescribeInstances. Using the menu option call Navigate -> Symbol , enter the method name as describeInstances and once there put a breakpoint on the first statement inside the method 
 
8) Once the breakpoint is set we will build a new Debug configuration by clicking on the Run Menu -> Debug ... and add a new ("+") "Remote" configuration. Just change the IP address to point to your CLC and keep the port as is i.e 5005. Now click on Apply and then Debug.
 
9) This will now connect the debugger to the CLC on port 5005 and we are ready to fire the euca-describe-instances from euca2ools. Note that as soon as the operation is fired in the IDE the breakpoint would get hit causing the system to stop responding until all data is collected in the IDE and then we can step over the code using the IDE as well as check the values of various variables etc during the code execution step-by-step
 
 
Have more questions? Submit a request

Comments

  • Avatar
    Harold Spencer Jr

    I think there are a few steps missing in the 4.1 step. You have the following:

    cd eucalyptus
    git checkout origin/maint/3.4/master

    from my understanding, I think this needs to be changed to the following:

    cd eucalyptus
    git submodule foreach git checkout maint/3.4/master
    git submodule foreach git pull origin maint/3.4/master
    git checkout maint/3.4/master
    git pull origin maint/3.4/master

    I mention this because the Eucalyptus git repo leverages submodules. Therefore to make sure that everything works in step 4.5, all the modules will be there. When I followed the initial steps you had, I saw the following error:

    $ git checkout origin/maint/3.4/master
    Note: checking out 'origin/maint/3.4/master'.

    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.

    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:

    git checkout -b new_branch_name

    HEAD is now at 7261e02... touch

Powered by Zendesk