Sunday 18 August 2013

Running JBoss AS7 on Raspberry Pi

Running JBoss

Choose a Mode

The JBoss installation on our Pi offers a couple of different configurations out of the box.
The first choice to be taken is whether to start JBoss in standalone or domain mode. 
Doman mode is a special management mode which we might inspect later. For now we will set off in standalone mode. This just means we will have to configure each instance individually. We can still cluster our standalone instances and even go for high availability in standalone mode.

Choose a Configuration

All the scripts for starting JBoss are located in JBOSS_HOME/bin.
JBoss is started in standalone mode by running standalone.sh:
standalone.sh
Without any parameters, standalone.sh will use the configuration defined in standalone.xml, located in JBOSS_HOME/standalone/configuration directory.
You can choose another configuration by specifying it on the command line:
standalone.sh –server-config=standalone-full.xml

My approach is to backup standlone.xml and to edit the original according to my needs. I’m going for standalone.xml to have a small footprint to start with. Additional features can be included later, either by editing standalone.xml or by using the management console or the command line interface CLI.

JBoss and Java

Standalone.sh inspects first JAVA then JAVA_HOME environment variable for a hint, where java is installed. If both variables are not set, JAVA is simply set to java which means the PATH variable determines if and where Java will be found.
And it will be found like this:
  • We find /usr/bin in our classpath (verify by typing $PATH on a Pi console)
  • /usr/bin contains “java”
  • Java is a softlink into alternatives  (/etc/alternatives/java)
  • Following this link, we find: java -> /usr/lib/jvm/java-7-openjdk-armel/jre/bin/java
And that is what we get when we run Java on the Pi.
Everything depends on soft links and the alternatives concept. This makes it very easy to switch to another Java installation in the future.
To make a long story short, leave everything as it is.

Making JBoss available within Your Network

All my Pis have static IP addresses within my private network. This can be configured within your router.
If you want to be able to reach a JBoss instance running on a Pi, you have to configure JBoss’ “Public Interface”.
This configuration is done standalone.xml located in /JBOSS_HOME/standalone/configuration.
Find the interfaces section and edit the public and the management interface like this:
<interfaces>
        <interface name="management">
            <inet-address value="xxx.xxx.xxx.xxx"/>
        </interface>
        <interface name="public">
            <inet-address value="xxx.xxx.xxx.xxx"/>
        </interface>
</interfaces>
Where xxx.xxx.xxx.xxx is the IP you configured in your rooter for this specific Pi.

Save the changes.

Create JBoss Users

In order to access JBoss’ admin console, we need to create a management-realm user.
This is done by running the add-user.sh script located in /JBOSS_HOME/bin directory.
Be sure to select management realm.







For later use, we create an application-realm user.
For now, assign the guest role to this user.







Starting JBoss

Let’s give JBoss a test run.
Switch to /JBOSS_HOME/bin and run standalone.sh in a Pi terminal window:
sh standalone.sh











When JBoss is up, you can access the web-server from any client within your network.
If you assigned a name to your Pi within your router, you can use this name to access the Pi. If not, use the Pi’s IP address.

 From here, you should be able to access the management console. As credentials, enter the admin-user you just created using add-user script.













Stopping JBoss

The best way to stop JBoss is by using the CLI.
Open another terminal session on the Pi and switch to /JBOSS_HOME/bin.
Run
jboss-cli.sh
The CLI starts in “disconnected” mode, so you have to connect.
Type connect xxx.xxx.xxx.xxx (IP address of your Pi)
When connected successfully, enter
:shutdown
JBoss will shut down and you can exit the terminal session.











Summary

Now we have Java and JBoss installed on our Pi(s).
JBoss is now accessible from anywhere within our network.
We created a management-user and an application-user.
We can start and stop JBoss on the Pi and have access to its management console.
In the next post we will develop our first JEE application and deploy it to the Pi.
See you then…

Tuesday 13 August 2013

Side Note: Accessing the Pi

Accessing the Pi

This blog assumes that your Pi is connected to a network, preferably with access to the internet for easy updates. But of course, everything discussed here can be done in a closed network too.
Apart from the network you don’t need anything. No monitor, no keyboard.
You can easily access your Pi remotely when you enable the ssh service during setup.
From now on you can access it from any client within your network.

Use ssh from any Linux client or putty from a windows client.

Let’s do something practical: Connecting to the Pi from a windows client and checking the Java installation.
Power up your Pi.
Open a putty session on a windows machine, selecting ssh as connection type.

This will start a terminal window where you will have to enter your credentials.
Check the Java installation by typing:
java -version
You should see something like this:

Ok, openJDK seems to be installed properly.
In order to shut your pi down, type:
sudo shutdown –h now

and close the terminal window.

Thursday 8 August 2013

Setting up the Raspberry Pi installing Debian. Java and JBoss

Setting up the Pi  

Before we can start playing JEE on the Raspberry Pi, a few things need to be set up.
As this is not too interesting, I try to cover it in a hurry. Please leave a note if you want one topic or the other dealt with in more detail.

What this post will cover:

  • Choosing and installing a suitable operating system for your Pi
  • Installing Java on the Pi
  • Installing JBoss on the Pi
  • Setting up the Pi network

Choosing and installing a suitable operating system for your Pi

The first task now is to choose and install a suitable operating system for your Pi.
There are several options available on the download page of the Raspberry Pi Foundation: http://www.raspberrypi.org/downloads
We go for Soft-float Debian “wheezy” for the reasons described on the page:
This image is identical to the Raspbian “wheezy” image, but uses the slower soft-float ABI. It is only intended for use with software such as the Oracle JVM which does not yet support the hard-float ABI used by Raspbian.”
 If we want to run java, what we do, we must stick to an operating system offering a soft-float ABI.
I tried the Java8 preview offered by Oracle here: http://jdk8.java.net/download.html which is supposed to support the hard-float ABI. But sorry, this works only when running Java in client mode. As soon as your software needs server-mode, you are out of the game.
This is also true for the embedded version of the Standard Edition.
Do we need server mode? Yes, because software like JBoss AS7 needs it.
So as of now (at the time of this writing) the soft-float Debian “wheezy” seems like a good idea for starting off:
  • Download soft-float Debian “wheezy” image
  • Bring the image to your sd-card
  • Start the Pi and run through the config-script that will start up on first boot
Hint: The config-script now offers to assign a hostname to your Pi. It is a good idea to make use of this. Later, when you have a couple of console windows open on your desktop machine pointing to different Pis, you will be glad to see meaningful prompts identifying the Pis respectively (of course you can change the hostname of your Pi later, but using the config-script is easier).
Later, when plugging your Pis into your network, you want to add these names to your router’s configuration.

Installing Java JDK on the Pi

The next step is installing Java on your Pis.
Software like the Oracle Java 8 preview would have to be installed manually.
The regular Java versions are maintained in the Debian software repositories and can easily be installed by Debians package manager.
I chose this package and installed it with apt-get.
Open up a console and enter:

sudo apt-get install openjdk-7-jdk

After the dust has settled, you have an openJDK 7 on your Pi.

Installing JBoss AS7 on the Pi

When installing JBoss, a little bit more manual effort is required. Here is what you have to do:

Step 1: Download the package

At the time of this writing, JBoss AS7 was available in version 7.1.1.Final.
You can download this package from the console using wget:

sudo wget http://download.jboss.org/jbossas/7.1/jboss-as\
 -7.1.1.Final/jboss-as-7.1.1.Final.tar.gz

Step 2: Extract the download 

Now that we have the tar-file on the pi we have to extract it into a suitable directory.
/usr/local is a good choice:

sudo tar zxvf jboss-as-7.1.1.Final.tar.gz -C /usr/local

(don't forget the -C option or the necessary directories will not be created)

Step 3: Smoothen the installation directory

JBoss AS7 is now installed in /usr/local/jboss-as-7.1.1.Final
If you find this to be a bit unhandy, change it like this:

sudo mv jboss-as-7.1.1.Final/ jboss7

Step 4: Make pi the owner of the installation

I like my pi user to be the owner of the installation.
You can do this with the Change Owner command:
sudo chown -R pi:pi /usr/local/jboss7/

JBoss AS7 is now installed and ready to run on your Raspberry Pi.
Quite some heavy lifting for a little Pi like that. But we'll see JBoss behaves itself very well.

Network configuration

My setup consists of 3 Raspberry Pis plugged into the local network behind my router.
On the router assigned static IP addresses and logical names to them. The Pis are named “frodo”, “samwise” and “gandalf”. 
Naming your Pis according to your rooter's configuration will help you to stay on top of things later.

Before getting serious with playing JEE on the Pi we'll have to do some minor configurations on JBoss.
But I leave this for the next post.

Wednesday 7 August 2013

Why this blog?

Why this blog?

This blog was inspired by a very interesting enterprise architecture project I had the pleasure of being part of. Two reasons made this project somehow more interesting than others. The architecture was supposed to cover service integration spanning the cloud, data center hosted services and services running on small and very small devices operated in the field. On top of that a lot of these field devices were manufactured by the customer himself, making them quite propriety.
This translates into distributed enterprise computing in a very heterogeneous environment.
Perfect fit for the by now quite mature JEE technologies?
In the end, only time will tell. But what we’ve seen so far looks really promising.
Anyway, we used a lot of “heavy weight” JEE technologies on very limited devices. And we are still experimenting.
This blog describes some of these efforts.
I choose the Raspberry Pi, or Pi for short, for representing our small field devices because it is easily available and quite cheap. Two or three Pis in a local network and JEE computing suddenly becomes very tangible and a lot of fun (if you have the kind of humor for this).

If you find this to be interesting, keep on reading and let me know what you think.