Showing posts with label osgi applications. Show all posts
Showing posts with label osgi applications. Show all posts

Friday, July 9, 2010

RAD Tooling for OSGi Applications

RAD V8 Beta 2 is now available with updated support for developing, deploying and testing OSGi Applications using the WAS V7 Feature Pack for OSGi Applications and JPA 2.0. I'll describe some of the new OSGi capabilities of RAD in this post.

Built on top of the latest version of Eclipse (Helios), the RAD V8 Beta provides OSGi tools for enterprise Java developers. While most of the development activities, and hence development tools, for enterprise OSGi applications are common with Java EE there are some new considerations. Primarily, these are around the compile-time classpaths, the authoring of new metadata (the OSGi bundle and application manifests) and, optionally, Blueprint bean definition files. RAD introduces new project types for OSGi Bundle projects and OSGi application projects and a variety of new editors and tools for developing components in these types of projects. OSGi modularity semantics are honored in the project build paths to actively encourage modular design: each project has the scope of a single bundle, with Java package visibility between projects restricted to those packages explicitly imported/exported by the project's bundle manifest. This supports the careful and deliberate exposure of only those Java packages that are intended to be used external to a project . RAD's facet-based configuration enables OSGi projects to be configured as OSGi Web projects or OSGi JPA projects and integrates tools for authoring web.xml, persistence.xml and blueprint.xml. OSGi application projects - representing a complete enterprise application consisting of multiple bundles - can be imported from or exported to enterprise bundle archives, and can be tested and debugged on WAS V7 from the RAD workspace. RAD's SCA development tools are also extended to support "OSGi Applications" as a new implementation type for SCA components. The SCA tools accelerate the assembly of SCA composites; these can include OSGi application components which may selectively expose OSGi services outside the OSGi application and define remote bindings for these services. There's more about the relationship between OSGi services and SCA services here.

One of the quickest ways to explore the new OSGi features in RAD is to import one of the sample applications provided with the WAS V7 feature pack into a RAD workspace. The feature pack's Blog Sample, was described in an earlier post so I'll use that as my example. Start RAD and run the File->Import->OSGi Application (EBA) wizard, enterng the location of the com.ibm.ws.eba.example.blog.eba file (found in the WAS_INSTALL/feature_packs/aries/installableApps directory). Since one of the features this sample is designed to show is the deployment of an application which includes content provisioned from a bundle repository, you also need to make the com.ibm.json.java_1.0.0.jar available in the workspace - which you can do through File->Import->OSGi Bundle. The result is 4 OSGi bundle projects and an OSGi application project in the workspace, with everything correctly resolved.

You can see the relationships between the bundles in this application using RAD's new Bundle Explorer. The figure on the left shows the Bundle Explorer view of the Blog sample application project. Click on the image to enlarge it.

RAD gives you all the syntax assist, refactoring support, and problem quick-fixes you expect as well as new editors for bundle manifests, application manifests and blueprint bean definitions. By encapsulating business logic in POJO Blueprint beans and accessing persistent data through JPA entities, unit testing can be performed with simple frameworks like JUnit without requiring an application server to be running. And, of course, RAD includes integrated support for running and debugging entire OSGi applications on a WAS server, straight from the workspace.

Thursday, June 3, 2010

OSGi applications and JPA2 feature pack has gone GA

WooHoo!!!!!!

Releasing any product involves a lot of hard work, sleepless nights and the occasional lost weekend, so you'll understand why I am happy that the feature pack for OSGi Applications and JPA 2 is now GA and can be installed either from the web, or locally, using installation manager.

Some highlights of what we have delivered:
  • Support for development and deployment of enterprise applications using OSGi
  • Support for Enterprise OSGi specs around Web application, Blueprint and JPA
  • The ability to update the individual bundles in an OSGi applications
  • Support for integrating OSGi and Java EE applications using SCA
  • Support for Java Persistence API 2, both from Java EE and OSGi applications
  • Development tooling for OSGi and JPA2 via the Rational Application Developer beta
  • Good performance increase measured using the SPECjEnterprise2010 benchmark.
I could go on and list some of the other cool features, like the bundle repository support for OSGi, and the JPA2 criteria API, but some of they have been discussed on the blog already, and then I wouldn't have an excuse to write more about them later.

Download, use, enjoy!
Alasdair

P.S. There is an iFix available for the feature pack and we recommend you install it.
P.P.S. You'll need to have 7.0.0.9 of the application server and JDK to install the feature pack.

Wednesday, March 17, 2010

More OSGi goodness

There is a new feature in the Beta refresh of the OSGi feature pack which went out last week - a tool to inspect application bundles. Here are some brief instructions on how to use it.

First, install the feature pack (see here) and start the application server, then at the shell command line navigate to:

[AppServerHome]/feature_packs/aries/bin


There is a script in there called osgApplicationConsole.sh (or .bat), run it and you should get a "wsadmin>" prompt. Use the list() at the prompt and it will show you ... nothing. That's fine, you need to install and start an application before you can see anything.

Install and start the Blog Sample (as described here), then try list() again, you will see something this:




Two frameworks are listed, 'shared bundles' and the Blog application. Connect to the first like this:

wasadmin>connect(0)

Use the ss() command to look at what is in it:



You don't have to disconnect from a framework explicitly, so to look at framework 1 (the Blog application) just connect to it:

wsadmin> connect(1)

then ss() shows the blog sample bundles.




This may by now be looking slightly familiar to anyone used to the Equinox OSGi console. The difference is that WebSphere is partitioning the space into separate application frameworks which you can look at individually - nice feature if you have a lot of applications. By the way, if you forget which framework you are connected to, list() at the wsadmin> prompt will tell you.


Other console commands can be found in the documentation, or by using 'help()' at the wsadmin> prompt. Have fun!

Friday, February 12, 2010

Try out WebSphere's OSGi Application Feature

The open Beta version of the WebSphere OSGi Application and JPA Feature Pack hits the streets today. This brings together the JPA and OSGi Application Alpha programs and makes them installable features within a managed install. This post focuses on the OSGi Application feature of the Beta which and adds many new and good things beyond the Alpha including a completely re-factored version of the original Blog Sample application. In this post I will step through instructions for running and and modifying the Blog Sample application. Detailed instructions on how to run the Blog Sample are supplied in the Readme.txt that comes with the sample, so I will go over some of the steps quite briefly.

I will refer to your WebSphere home directory as WAS_HOME throughout this post. I ran through this using the free-for-developers version of WebSphere running on Ubuntu, so there may be a slightly Linux-y flavour; I'll document the 'assume nothing' Ubuntu install here. Everything should, of course, work on any supported WAS platform.

The Blog sample



The Blog sample is an OSGi Application that demonstrates the main concepts and many of the benefits of assembling and deploying an enterprise application as an OSGi Application. It comprises four main bundles and an optional fifth bundle, the relationship between the bundles is shown below:

The blog sample demonstrates the use of blueprint management, bean injection, using and publishing services from and to the osgi service registry, using optional services and the use of java persistence. In the main application, supplied as an EBA (enterprise bundle archive), the four bundles are:

  1. The API bundle - describes all of the interfaces in the application
  2. The Web bundle - contains all of the front end (servlet) code and the 'lipstick' (css, images)
  3. The Blog bundle - the main application logic. This bundle publishes a 'blogging service' that the Web bundles uses.
  4. The persistence bundle - the codes that deals with persisting objects (authors, blog posts ..) to a database (Derby in this case). The persistence bundle supplies a service for this which is used by the Blog bundle; the persistence service in this implementation uses JPA, with OpenJPA as the JPA provider.
  5. The final bundle is an upgrade to the persistence service, it contains an additional service that will deal with persisting comments as well as authors and blog posts.




Running the Blog Sample


The first steps in running the sample are to set up some data sources and create the database that the sample will use. There are instructions on how to do both in the Readme.txt file which can be found in WAS_HOME/feature_packs/aries/samples/blog; when you run the blogSampleInstall.py script use the 'setupOnly' option which will just create data sources. I'm going to step through the rest of the installation using the WebSphere Admin Console.

Start up WebSphere and point your web browser at the Admin Console, if you are running on a local machine and have not set up administrative security you will find the console at http://localhost:9060/ibm/console. Before going any further check that the data sources were set up properly by navigating to Resources->JDBC->Data sources, you should see something like this:



In the next sections I will work through installing the sample, starting with the bundles that it depends on.


Deploying bundles by reference


The Blog sample uses a common JSON library; while it could be deployed as part of the application the Blog sample illustrates how common libraries can be installed to the new WebSphere OSGi bundle repository and provisioned as part of the installation of an application that requires it. So the first thing we do is add the common JSON library to the WebSphere bundle respository. Navigate to Environment->OSGi Bundle Repositories->Internal bundle repository, the repository will be empty if you are using a new installation.

Click on 'New' to add a new bundle, on the next screen add the asset WAS_HOME/feature_packs/aries/InstallableApps/com.ibm.json.java_1.0.0.jar. Click 'OK' and then save the configuration, you should see this screen:




Creating the Blog Asset


Installing an OSGi Application through the Admin console is accomplished in two steps, described in this section. The blogSampleInstall.py script mentioned above illustrates the underlying wsadmin commands for a scripted install. The first step is to add an EBA (enterprise bundle archive) archive as an administrative asset, the .eba extension just indicates that this is an OSGi Application. Navigate to Applications->Application Types->Assets. Click 'Import' and add WAS_HOME/feature_packs/aries/InstallableApps/com.ibm.ws.eba.example.blog.eba. After saving you should see this:





Creating the Blog Sample Business Level Application



The second step is to to create an application which uses the EBA asset. Navigate to Applications->Business Level Applications, add a new application called Blog Sample:





After you have added the application you must associate it with the Blog sample asset, click on the sample and add com.ibm.ws.eba.examples.blog.eba under Deployed Assets.



As usual, save the configuration.

Start and run the Blog Sample application



At this point everything is in place and ready to run the application. From the Business Level Application screen, select the radio button beside the Blog sample and click start. If the sample starts as expected then point your web browser to
http://localhost:9080/blog, and you will see this:



With the blog sample running you will be able to add authors and posts and see that they are persisted to the database. Here is my first post to the Blog sample:



There isn't a great deal of functional code in this 1.0.0 version of the sample but a 1.1.0 version of the blog.persistence bundle is provided which adds a functional service to enable you to add comments to blog posts. We'll now illustrate how to update an application to add a new service by moving from version 1.0.0 of the blog persistence bundle to version 1.1.0 which contains the new service.

Changing the bundles that the Blog Sample application uses


First you will need to add the blog.persistence_1.1.0 jar to the internal bundle repository. This means repeating the same steps as for adding the JSON jar above. The path to the archive is WAS_HOME/feature_packs/aries/InstallableApps/com.ibm.ws.eba.example.blog.persistence_1.1.0.jar. Add it to the internal bundle repository and save the configuration.

Now you need to allow the application to use the new bundle. To do this, select the blog sample asset by navigating to Applications->Application types->Assets and clicking on com.ibm.ws.eba.examples.blog.eba. Scroll down to close to the end of the next screen where you will find this link:



Clicking on the 'Update bundle versions...' link will take you to this page:



Click on the the drop down arrow to the right of the line for the persistence bundle, you will be offered a choice of using the 1.0.0. or the 1.1.0 bundle. Choose 1.1.0 and follow through the preview and commit screens. You will need to restart the Blog application (from the Business Level Application screen) to make it use the new bundle, after that, navigating to http://localhost:9080/blog should show you the blog application with a new link to add comments. Unfortunately, it doesn't. This is what you will see:



This turns out to be entirely my mistake. In the last minute scramble to get the sample into the Beta delivery I didn't notice that some changes had been made to the JPA support had been made at the same time. The consequence of those changes is that my MANIFEST.MF requires an additional line. This is an easy fix and in the next section I'll describe how to make it.

How to modify the Blog Sample



All of the sample source code and Ant build files can be found under WAS_HOME/feature_packs/aries/samples/blog. Before making any other changes you should modify the build.properties file in this directory so that the first line refers to your WAS_HOME, you will need this file to build code with later on.

The best way to fix the problem with the MANIFEST.MF is to create another version of the persistence bundle, it should be a 1.1.1 version since the fix is very small. To start with, create a new directory under WAS_HOME/feature_packs/aries/samples/blog called com.ibm.ws.eba.example.blog.persistence_1.1.1, then copy the entire contents of com.ibm.ws.eba.example.blog.persistece_1.1.0 into it. Two files need to be modified, the META_INF/MANIFEST.MF needs to be changed to add the pink highlights shown below:




be very careful with the Meta-Persistence: line, it must have a space after the colon and the code will not compile if it doesn't. The second file that needs a small modification is the build.xml file, the project name needs to end 1.1.1, not 1.1.0.

After making the changes, run the build.xml file in your new 1.1.1 directory, like this:

ant -propertyfile ../build.properties -buildfile build.xml


This will create the archive target/lib/com.ibm.ws.eba/blog.persistence_1.1.1.jar. To install the new archive, go back to the WAS console and repeat the steps for adding it to the internal bundle repository and making the Blog Asset use it. Finally, restart the Blog application, point the web browser to the Blog and hit refresh. Et voila! A new link has appeared so that comments can be added to the post. Here is a screen shot with a comment added:




How does it work?



This Blog sample is designed to demonstrate how easy it is to change bundles and how to use optional services. To make this work we had to think about how to design the sample to be able to use the additional comment service from the start. This isn't really unrealistic, how often have you had a complete design in mind but not had time to implement the whole thing before delivering it? In this case we stopped short of delivering the service in the first version but we were able to supply it as an upgrade with an almost undetectable interruption to the service.

The sample is designed so that the bundles can be maintained completely independently of each other - I want the ability to upgrade one bit at a time. This might be overkill for an application of this size but the principle applies to applications of any complexity.

The other thing I have rather glossed over is that I didn't change the database, again the database had to have the right structure for the comment service from the start. However, this follows fairly naturally from designing the application to expect to be able to use commenting.

The best way to understand what is happening when the application is running is to look at the META-INF.MANIFEST.MF and OSGI-INF/blueprint/blueprint.xml files for each bundle. As the code is fairly simple, it's easy to follow through to the Java code and see where properties are injected by the container as specified in the application blueprint.

In the next revision of the Beta release I will fix the mistake in the MANIFEST.MF and will also correct a horrible anti-pattern that I introduced in trying to keep the persistence blog layers separate. In fact, I'll buy a beer for anyone that can see it and send me a good fix for it!

Monday, December 21, 2009

IBM brings the power of OSGi to WebSphere

Back in 2006 we rebased WebSphere Application Server on OSGi in order to help us deliver a better application server. In 2009 we are bringing the power of OSGi to help you build better applications.

The IBM WebSphere Application Server V7 OSGi Applications Open Alpha program introduces to the application server the ability to build, deploy and run applications running on OSGi. Building on the work done in the OSGi Alliance Enterprise Expert Group (EEG) and in the Apache Aries incubator the alpha allows you to build modular applications that make use of familiar JEE technologies such as Servlets, JSPs and JPA.

There are many advantages to the support we are delivering in this alpha, some highlights include:
  • The ability to deploy a WAR file into the OSGi environment
  • Blueprint Container - A Spring-like Dependency Injection based container integrated with the OSGi service registry and standardized by the OSGi Alliance
  • The ability to share libraries between applications
  • Application composition by reference
  • The ability to provision an application based on the application dependencies and the content of an OSGi bundle repository
The alpha is available and includes some samples to get you going. We have also shipped the product documentation as a PDF and the Apache Aries site includes some information on the application model.

There has already been some coverage on the web about what we are doing in the alpha and I wanted to highlight two in particular. The first is a blog post by Kirk Knoernschild, who is giving a keynote at OSGi DevCon London in February. The other is an article on dzone where Ian Robinson is interviewed about the alpha.

Since I have mentioned it if you are in London in February some of my team are going to be at OSGi DevCon London running a tutorial on using Blueprint. In addition David Bosschaert one of the OSGi Alliance EEG co-chairs will be talking about the OSGi 4.2 Enterprise Release and we will be talking about the Apache Aries incubator.

Alasdair