Wednesday, June 11, 2014

Ehcache: deploy multiple versions of a Grails app (fix javax.management.InstanceAlreadyExistsException)

When a Grails application makes use of the Ehcache cache plugin in its default configuration it can be impossibile to perform deploys of multiple versions of the app, even though the container might support it.
The same plugin (in its default configuration) also breaks deploying multiple different Grails apps on the same container.

The problem is in the way the plugin generates the name for the cache (which will then be used to register the cache jmx bean): the name is by default set grails-cache-ehcache. When another second application or another application version is deployed registration will fail because the name already exists. The exception message is the following (indented for clarity):

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'ehCacheManagementService':
Invocation of init method failed;
nested exception is net.sf.ehcache.CacheException:
javax.management.InstanceAlreadyExistsException:
net.sf.ehcache:type=CacheManager,name=grails-cache-ehcache

The (undocumented) solution is easy to implement. Edit the Config.groovy file and add the following configuration bit:

grails.cache.config = {
  provider {
    name "ehcache-<yourappname>-"+(new Date().format("yyyyMMddHHmmss"))
  }
}

If you are using the ehcache.xml file instead it might be more difficult to randomize the cache name, but it could be done during the build.

Tested on Grails 2.1.5 and Tomcat 7.

Friday, February 07, 2014

Create an OpenLayers map programmatically

Sometimes it is useful to abstract away the repetitive layer creation code with a configuration-based approach.

For example consider this very simple map taken from the OpenLayers examples:

How could we avoid repeating invoking the layer contructor and instead provde a framework that allows us to instantiate any layer with just configuration? The solution is quite simple.

Tuesday, December 31, 2013

Book review: Sproutcore Web Application Development

TL;DR: Sproutcore is a huge framework, and this book will save you a lot of time (and headaches). Buy it.
Disclaimer: this is a review of a free copy that Packt kindly sent me.
SproutCore Web Application Development cover

Win a free copy of this book, scroll down to know how to participate!

If only I had this book 3 years ago!

3 years ago I started developing a Sproutcore app as a learning experience and, in all honesty, the path has been rough. Sproutcore is a massive framework with lots of features: some are well documented, some mentioned casually in the guides, some others...well you don't know they are there until you start reading the code or chat with one of the more knowledgeable devs in IRC.

Saturday, October 12, 2013

Easy animations with Sproutcore 1.10

The release of Sproutcore 1.10 marks an important step in the life of this very popular framework. Lots of new features make developing applications on the Sproutcore framework even easier and fun.

One improvement that I am sure will catch your eye (pun intended) is view animations. Coding view animations was rather easy also on previous versions, but with 1.10 animations are now first class citizens bolted into the core rendering subsystem.
For an example of what is available out of the box see this demo.

So how would you use this goodness in an actual Sproutcore application? And how much code would it take?

As an example I have put together a very basic Sproutcore app (source, demo) which has two states: an authentication form and a main screen. Logging in transitions the app from the login form to the main screen and logging out returns the app to the login screen. Pretty simple.

Thursday, August 29, 2013

Manage Windows printer event log settings from command line (i.e. GPO scripts)

Just a quick note to self that to enable/disable/query event log registration from the command line on Windows releases greater than XP and Server 2003 you can use the wevutil tool.

For example to enable logging of print requests on Windows 7 for auditing purposes:

wevtutil sl Microsoft-Windows-PrintService/Operational /e:true

The equivalent command for the the above on Windows XP is the following:

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Providers /v EventLog /t REG_DWORD /d 7 /f
net stop spooler
net start spooler

Sunday, July 21, 2013

Developing Sproutcore apps on c9.io

The Cloud9 online IDE running on Chrome/Mac.
Today I was looking for a way to quickly edit a pull request to the Sproutcore project without booting up my laptop, but using the MacMini in the living room instead, which is always on, being our main entertainment system.

Turns out it's quite easy if you do not mind signing in into another online service: the Cloud9 online IDE.

Thursday, July 11, 2013

Book Review: Instant OpenNMS Starter

Disclaimer: Packt kindly sent me a free copy for review.

TL;DR: Rating 4/5. Recommended for beginners and intermediate.


The book itself is short, but packed with information. A fast reader with some experience with OpenNMS should be able to finish it in 4 to 6 hours. Beginners will probably want to follow the pointers to the online documentation, check the configuration files and possibly experiment so they should allocate more time.


Before being published the book has been reviewed by Jeff Gehlbach. Anyone who has been involved with OpenNMS for some time know him, as he is one of the many brilliant minds working for the OpenNMS company, the commercial entity which develops and supports OpenNMS. Surely his involvement serves as a kind of seal of quality for the book. I for one was surprised by the clarity with even the most complex aspects of OpenNMS were presented in such a short text.


Instant OpenNMS Starter is divided in three main parts: installation, quick start and an advanced section that the book calls ‘the top 5 features’. The final section is a reference of sites and humans with more information on OpenNMS.


The author has been careful to link to the relevant sections of the online wiki when he felt that the wiki content was adequate, without devoiding the book of any additional practical information. For instance in the installation section he actually describes a more secure way of installing OpenNMS than that described in the online user guide and he does so by simply citing the extra steps while leaving to the online documentation to specify the rest.


The quick start section is useful for those in a hurry to just have something monitored with OpenNMS and needing to for a pointer on what all those links in the web ui do.


The advanced section is where probably you will spent most of your time as it describes the most interesting features of OpenNMS which are:
  1. service assurance through polling
  2. data collection through collectors
  3. thresholds and notifications
  4. events, alarms and automations
  5. reports


IMHO one glaring omission in this list is the Provisioning system which was introduced with OpenNMS 1.8 and is a key feature because it covers a critical aspect: how nodes are added into OpenNMS for monitoring. I reread the book twice hoping that perhaps it was mistake on my part, but I could not find a single reference to it.


The book covers each of the five areas with enough depth to give a dedicated beginner useful pointers and background on how to implement the most advanced features of OpenNMS. The author again intelligently uses links to the online wiki to extend the text.
Only the section on reports felt a little thin. In defense of the author one could say that the reports area is so complex that it would have quickly grown out of hand for this kind of book. Perhaps in a second edition he should consider expanding it to at least mention the possibility of creating Jasper reports from collected data.


Instant OpenNMS Starter is clearly aimed at, and I recommend it for, people starting with OpenNMS, evaluating it or who might have inherited a working installation and now have to maintain it. Users seeking to master one of the 5 areas listed above should certainly consider buying it when the online bits and pieces feel not enough or too sparse.
By the title it should come as no surprise that advanced users are not likely to find any new or useful information at all, but, again given the price and the short text, it could still be used as a kind of self-check.

Update Oct/2/2013

There was a brief exchange of emails on the opennms-discuss mailing list with the author, I think it gives useful context to some of the items in my review. I reproduce it under here in full (link) :

Regarding Provisiond, I agree that it needs to be there. When I wrote the book I had to follow very specific guidelines from the publisher. In the top 5 features section I had to decide how to organize it. It was either going to be Capsd or the new and improved Provisiond as one of the 5. When I wrote it, Capsd was still enabled by default and I thought it was easier to get started with. If I would redo it now, I would change the section to Provisiond with a simple mention of how it evolved. In fact, I am preparing this very section now and will make it available on my site. Would be nice to have a revised edition though, I'll check with the publisher. Regarding reports I think it would be nice to have a similar short book of its own on the subject, going through OpenNMS' default reporting capabilities, more advanced custom JasperReports and maybe some modern ajax report dashboards built on top of the nice RESTful API (something I've been wanting to explore). Just thoughts...