Sunday, May 30, 2010

Managing enterprise clients with p2 query api

In my last post I left some quite angry words to the p2 team, I hope they will forgive me. After some more days of intense research I finally made p2 do what I want to. And you might want to notice that I'm quite happy about that.

Our system (It's german,  Buchmanager) is a client server architecture with hibernate/spring on the backend and a remote RCP Client. Our customers have a strong demand for automated updates, as users are forced to sync their client on server updates.

The Problem: Client and server have to match and we cannot know what server version the customer is running.

The Solution: p2 queries.
At Workbench startup the client asks the server for the required client version numbers. Then we make a p2 Query with a VersionRange (as qualifier may indicate a compatible update)

IQueryResult matches = queryable.query( QueryUtil.createIUQuery("",new VersionRange(Version.createOSGi(major, minor, micro), true, Version.createOSGi(major, minor, micro + 1), false)), new NullProgressMonitor());
Thereby we ask the repository to give us "product" IUs only matching the servers requirements. Then we use the high level api UpdateOperation to resolve an update for us. As there may be updates for a higher (=newer) server version available, we use "setSelectedUpdates" to Update only to the compatible client. this is quite easy using the equals & compareTo on Update & Version classes.

I have to note that we had to remove the p2 ui bundles completely, as they would have still offered the _wrong_ update to the user. I guess that could be changed using a Policy, but that is work to come when we feel a need for a ui.

Follow me on


ekke said...

good to hear that you finally solved your problems.

Thomas said...

I think your criticism about documentation being scarce, examples not up-to-date etc. in many ways is well deserved. The problem isn't that we don't grock that we need to do more to help. It's about resources. It' all about resources. We need more people to write articles about p2 that can be helpful to others and we need help with examples and experiences from people that has tried it. I'm sure articles like this one will help.

If someone with writer experience could help us put together a well structured thorough user documentation, that would be incredible helpful.