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 :)

Friday, September 5, 2014

xerces, what a bliss


I firmly believe that you are not a seasoned Java developer until you have  faced an irritating class loading issue.

Recently found myself in xerces hell, trust me its not a good place to be in. Without going into too much details and various issues I faced (internet is filled with them). I will talk about what solved the issues for me:
Background: XercesImpl.jar and xml-apis.jar are both part of Apache xerces and XML4J xml parser library. One of the product I was working on, somehow was shipping with only XercesImpl.jar. Things worked fine until now. (looks like xml-apis.jar delivered classes were getting picked from the JDK. xerces parser jars are part of JDK since version 6 at-least, may be even earlier)

Problem: Suddenly there were errors thrown up related to “XMLGregorianCalendar2 class not found” , “Duration2 class not found”. Looks like these classes are present in the XML4J - xml-apis.jar. As this jar was not packed with the product, hence the error.

Why these error didn't come up previously: Looks like there was no Gregorian calendar related XML parsing happening in the product previously. Due to some change it started and hence the error.

Possible solution (not working): Add xml-apis.jar in the products/web-inf. But on doing so the xml-apis classes started conflicting with the already loaded apis from the JDK. You would see errors like org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl cannot be cast to javax.xml.datatype.DatatypeFactory. Don't be too surprised, as both the classes are fully compatible but looks like the problem is classloader. Classes are loaded by different classloader and hence mismatch.

Even if the the application is having “parent last” classloader setting, you will see this error. Also I saw some pages where it said that adding xml-apis.jar to web-inf/lib is not suggested.

Correct solution (at-least which worked for me): Removed the xercesImpl.jar from the web-inf/lib. (classes will get served from the JDK)
In case you are using some ancient version of JDK with no XML parser, there is another safer solution > Keep xercesImpl.jar in web-inf/lib, and keep the xml-apis.jar in appserver/domain/lib directory.
This way the required API classes will not be loaded, even if they are, will not conflict with the JDK classes as these will be loaded in the same classloader as that of JDK.
The only problem I see with this solution is that, keeping the jar in domain lib will be extra manual step, outside of the regular app deployment.

In case you are aware of any better solution then do let me know.

(There is a setting in to Prefer application packages in Weblogic, that might also work, but I I have not tried. Anyways its a app server specific fix and playing too much with application class-loading sequence is not suggested)

Thursday, September 4, 2014

Classloading; that simple error was just a beginning

Recently found myself in class-loading issues. Came across two nice tools to analyze the problem.
  1. One is generic tool that can be used with any app server and also standalone programs: http://blog.jhades.org/classnotfoundexception-jhades-jar-hell-made-easy/
  2. Second is weblogic specific, but good thing is you don't need to add any new jar or listener, its available for any application deployed + it also tells about the possible solution for the conflicts:Classloader Analysis Tool (CAT)
Enjoy .... (putting conflicting jars in the classpath and then solving the issues 1 day before the release *_^)

Thursday, February 20, 2014

Making visualization self-explanatory by embedding insights

1.    Background

In recent times data visualization has come up as a popular choice for analysis and planning. There are numerous new visualizations which present the data in different ways for easy fact finding.
But these benefits come with a side effect - Visualizations are getting more and more complex and generally need further information (in textual, audio or visual format) to explain the facts so that user can deduce proper insights.
Dynamic visualizations, where transitions are used to show the changes in data over period of time, elevate the problem even further. As the underlying visualization continuously changes, either we need to ‘pause’ the transition or again provide audio or separate text inputs to support the data presented. Few example of complex visualization are given below: (Ref: http://www.visualcomplexity.com/vc/)


Use Case
Consider the chart shown below; on high level it’s showing the per-capita income in various countries at different point of time. As you will see, over the period of time the data points are moving towards the right top corner. 




Though the intellectual users will get some insights using the axis labels (the static information) in the chart but more insights on a particular instance of dynamic visualization will be difficult or many times totally lost.
For example
Obvious insight:
  • During 1970s, 80s, except few countries all having low per capita income
  • Over the last few decades more countries having better per capita income
Further insights:
  • Even though the already developed countries are growing further, but their growth rate is much slower than the developing nations
  • The difference between the highest earning and lowest earning nations is still almost same
  • Nation X has made the most progress,  etc …

With a bit more complexity in data or visualization, it can be almost impossible to convey the underlying message by just using the visual cues.

Current Solutions and Associated problems
The current solutions partially solve the problem by either:
  • Providing a separate text outside the visualization:
  1. Not user friendly
  2. while sharing the visualization, we need to share both visualization and accompanying information.
  3. Not real time. If the data changes we need to change the text accordingly.
  • Providing a text/annotation on the visualization itself, in other words we can add a text on top of the snapshot of particular visualization. For example on any chart I can add a text box and put an insight for it.
  1. For static visualizations: though it solves the problem of keeping insight with visualization, but the insight is still static. In case the data changes we need to go back put new insights. In case we want to use the similar insight at same event for some other data it can’t be done.
  2. For dynamic visualization, currently there is no feasible way to add annotation at a particular instance of visualization.
  • Using a third party tools to embed text/audio commentary on the visualization: For data based visualizations, this means recoding the screen and adding the labels on top.
  1. Because we have recorded the screen (or taken a snapshot), the whole visualization is no longer attached to the data itself. Hence the insight can’t be used to in some other chart or data as such. For any new data we need to again create the visualization and reuse the tool to add the insight.
  2. Extra time, efforts are required to do the recording and embedding the text/audio.
  3. You need third party tools to achieve this.

2.     Proposed Solution to the Problem

In recent times, many grammar based visualization engines have been introduced in the data visualization field. (Vega (http://trifacta.github.io/vega/editor/), IBM Rave etc.) These engines allow the use to define the visualization using a predefined template.
The solution proposes to attach the insights in the visualization by attaching the trigger points and related insights with the template used to create the visualization.
Based on the trigger, we can show more information about the underlying data in the form of text, audio, graphics or other means. The triggers can be:
‘event’ based,
“when the current visualization is showing the data for 2001” or
“when the data for X axis goes beyond the value 1000” show “…..” .
Time based
      When we are into 3rd minute of transition    
Due to this dynamic nature of attached information we can 
  • change the underlying data with same insight and same visualization(text or audio)
  • change the insight for same or different underlying data.

3.     Benefits

Proposed solution will allow business users to:
  1.  gain more insights from a visualizations.
  2. embed more insights for end users.
  3. as the insights are embedded we can increase the complexity of the visualizations without the fear of overwhelming the end user.
  4. as the insights are embedded in the visualization and can be attached to the data this adds the capability to: 
    • show different insights based on same data 
    • show similar insights for different sets of data

4.     Sample Implementation and Flow

This type of system can be easily built using the popular Grammar of graphics or a similar system. A sample flow:
Sample Visualization Template:





Execution Example:
Condition: Difference between max and min value > 200% of average
:- Insight: There is huge difference between best performing and worse performing nations.


Note: The mentioned insight will be shown if the condition is met. So in case of any other year’s data if the difference is not as huge the text will not be shown. 

5.     Going one step ahead

Once we have the system in place, it will be easy to have an implementation where there are several insight triggers attached to the templates based on a rule and over time these triggers will build up. It’s quite possible that on producing visualization for some a set of data, user will be overwhelmed with multitude of such insights (obviously enough due to several triggers getting fired). To help the end user, the system can provide a facility for providing a ‘filter’ input which will filter the insights shown to the user. So in above mentioned example, in case the user is interested in the progress of only third world countries the respective inputs can be provided. On which the system will filter the insights using a simple text based comparison.