Thursday, November 27, 2014

Jenkins (Hudson) - Easier than thought...


I always had fascination for automated build systems. For me it was always some magic happening behind those web pages.
Recently I got a chance to unravel the magic by doing a Jenkins install. To be honest it was really really simple; easier than configuring tomcat. Below steps are just high level view to let you know how simple it is, for proper steps please refer the Jenkins site

High level steps:
  1. Download Jenkins WAR
  2. Run with Java (Java -jar jenkins.war). Jenkins war comes with inbuilt jetty, so no need to have a separate container
  3. Configure few properties in the Jenkins web page like JAVA_HOME, ANT you want to use.
  4. Configure the Job (Project)
    1. Specify the source control tool: For us it was perforce, with a very easy to use Jenkins Perforce plug-in the config was simple. Just create a separate perforce work-space that Jenkins will use to sync the code, provide user id etc.
    2. Specify the build file (for us ANT), targets etc.
    3. Specify the polling interval.
That’s it.

Fired some build manually to check if everything was working fine.
Next morning the build ran as per the schedule, it even synced the code taking latest change lists.
Still looks like magic ... :)

Pitfalls:
  1. Initially whole build was OK, but the Dojo part was failing with errors giving hint that there is some path issue. After losing one day, realized that dojo build fails if the path contains a “.”. Jenkins by default creates a home directory by name “.Jenkins” in the user directory and all project, job etc are synced there only. So to avoid any such issue, before you start Jenkins for the first time: Create a system variable by the name of “JENKINS_HOME”, and give a path of your choice.
  2. First time also faced some issue where build was not able to create / update some files. Had to manually set the source folders/files writeable. 

Wednesday, November 5, 2014

Profiling WebSphere Liberty


Took up the job to profile the application I am working on. As WAS Liberty is my favourite app server, wanted to do the profiling on that only.
Tried various tools like VisualVM, JProfiler etc. But even after lot of search couldn't find a good page describing how to enable the application for profiling. Looks like some JMX port configuration is required, didn't check further.

Then tried IBM Heath Center. Initially I was bit sceptical as a related IBM tool - 'Support assistant' is very heavy and had bad experience with it in the past.

But I was pleasantly surprised the way IHC was so easy to install and configure. And good thing, it works with IBM JDK out of the box :)

So below are the steps:

1) Install 'Health Center'

2) Enable the application we need to profile, in our case the Liberty server.
In the Eclipse Liberty Server project, edit the jvm.options file, add following lines:
-Xhealthcenter:port=1973
-agentlib:healthcenter

Start the server. In the startup log you should see:  
INFO: Health Center agent started on port 1973. 

Port can vary as per your setup

3) Connect the health center
Open the HC perspective: Window -> Open Perspective > Health Center Status Summary
File -> New Connection...' . Specify the port mentioned in the log.
Start using the application and the agent will start collecting the information and display in neat interface.

Thursday, October 9, 2014

Lets FACE it...

Looks like my escapade with App Servers has not finished.

After finishing the work on WAS Liberty, I realized that we were at old servlet api version 2.4. Though wanted to move to 3.0, but Weblogic 11GR1 does not support that. So bumped up the version to 2.5. Everything seemed like working until people using weblogic in the team faced issues in deployment itself.
The application failed to even deploy on Weblogic with error : java.lang.ClassNotFoundException: javax.faces.webapp.UIComponentTag.

Surprisingly we don't even use JSF or any faces implementation. Went back to my old friend 'google' and found that internet filled with posts from poor souls like me. After going through lots of pages finally found a page which solved the issue.

In struts libraries there is a jar → struts-faces.jar. If this jar is present in your lib folder, weblogic seems to look for faces related libs and hence the issue.

But funny part is - its all working well with servlet 2.4 declaration in web.xml. Its also working well with 2.5 version declaration in WAS. grrrrr....


Tuesday, September 30, 2014

Eclipse debugger out of sync

Recently faced an issue where while debugging a project (Eclipse, WAS Liberty, RHEL 6.5), I faced the common issue of 'Code not in sync' with the break point.
Checked all the usual suspects - Project clean, server restart, even restarted  Eclipse. No use.
Then I checked the Liberty deploy folder. I was using the "Run from Workspace" option in Eclipse/WAS Liberty. In this Liberty will simply create an XML file at WASInstallDIR//usr/servers/defaultServer/apps, with the name of your-project.xml

Checked the file and wallah found it.

I had recently duplicated my dev environment, one for checkins, and one for checking out large changes before actually making them part of source control. During this copy-paste, project-name.xml was also copied along with Liberty. And Surprisingly, even though I added and removed the project from the Liberty Server multiple times, Liberty was still using the old XML and hence pointing to my old project.
Hufff... Hours lost but lessons learned.

Monday, September 29, 2014

Liberty or death

I was working on an application which was working fine on WebSphere server (as war and Eclipse Project). Deploy on Liberty through WAR was also working fine.

Like any other good developer wanted to shift to WAS Liberty for faster development but on trying to deploy on Liberty through Eclipse project, "js, gif, css" files were not getting loaded in the web page. Because of this the page was looking distorted and most of the functionality was lost. For all the mentioned files (js etc) I got 500 (Internal Server Error). There were no console errors and the server log was also clean.
I tried both loose config and 'from workspace' settings + lots of other workarounds but nothing.
Only helpful hint I found was, there were some spring initialization errors in server log. But Spring code was in a jar which was developed by another team so could not debug. 

After weeks of hard work found the issue which was not even a mile close to the problem I was facing. 

Due to wrong code for REST implementation, the base path was set as root application path “/”, instead of something like "/rest/*" . So whenever the first link to the application was getting clicked, REST API classes were getting instantiated before application was fully initialized. And this REST code was making calls to few Spring instantiated beans. But at this point the Spring listeners had not fired, hence the appcontext was empty. Some of the base application object were getting initialized with empty beans and hence spring security context and related classes were failing to serve the application content properly. 

The thing that makes it more irritating is : The same problematic code is working fine on Websphere full profile and Weblogic and even on Liberty if we deploy as WAR. Not sure what classloading difference is causing difference in behavior. I checked the difference between WAS full profile and liberty profile but nothing specific. 

Good thing is, now I am on Liberty, happily coding, looking forward to solve similar irritating issues in lesser time :)