Revitalize your Java EE app with IBM Bluemix services
Amp up any existing application with cloud-based services on IBM's cloud platform
This tutorial was written using a previous version of the IBM Bluemix® interface. Given the rapid evolution of technology, some steps and illustrations may have changed.
IBM Bluemix® is based on Cloud Foundry and helps you rapidly build, deploy, and manage cloud applications, while tapping a growing ecosystem of available services and runtime frameworks.
In this tutorial, you learn how to bring code from GitHub into your Eclipse workspace, build and deploy the application to Bluemix, and consume a database services and other services in the cloud. To demonstrate this process, we'll work with the CloudTrader sample application.
CloudTrader is a Java™ EE application that simulates an online stock trading system. This application allows users to log in, view their portfolio, look up stock quotes, and buy or sell shares. It is built primarily with Java Servlets, JSPs, and JavaBeans. To show you how to migrate your existing applications to Bluemix and revitalize them with cloud-based services, we created CloudTrader by making changes to a ten-year-old day trading application.
The CloudTrader application can consume the following Bluemix services:
- dashDB (required): CloudTrader uses the dashDB database service. The data source connection information is created as a JNDI namespace entry, ready for the application to look up and start using in seconds.
- Session Cache: When bound to CloudTrader, this service enables persistence for all sessions across multiple instances of the application. In the event of a failure, sessions are seamlessly recovered.
- Auto-Scaling: Auto-Scaling enables you to automatically increase or decrease the computing capacity of your application. The number of application instances are adjusted dynamically based on the Auto-Scaling policy you define.
Okay, let's get started. We're going to download the code from GitHub, make some changes, and deploy the application on Bluemix. We'll also create a database and an analytics service as well.
What you will need
- A Bluemix account (register for your free trial account or log in to Bluemix if you already have an account).
- Eclipse for Java EE Developers with the Bluemix plug-in
Get the code from GitHub
- Click the Get the code button above, and then click Clone or download and Download Zip.
- Launch Eclipse. File > Import > General > Existing Projects into Workspace > Select archive file > [your download].
- You should now see the CloudTrader project (with code) in your Project Explorer view.
Create a Bluemix server
- In Eclipse, right-click the Servers view and select New > Server. If you don't see the Servers view in Eclipse, make sure you are in the Java EE perspective and look in the bottom section for the Servers tab.
- In the Define a New Server window, expand the IBM folder, select IBM Bluemix, and click Next.
- Enter your credentials for your Bluemix account.
- Click Validate Account, then click Finish.
- You can now drag and drop the CloudTrader project onto the Bluemix server you just created.
- You will be presented with a wizard. Choose a unique name for your application to prevent name collisions in the Bluemix domain.
- On the next panel, you can select the URL and Memory information. Accept the defaults and click Next.
- On the Services selection panel, we will create the
services the application needs. For now, we will only create the
database service. Click the Add Service icon near the top right to open
the Add Service window. For the Name, enter
TradeDataSource. Bluemix will create the necessary configuration so that CloudTrader can look for this datasource with this JNDI name. Select dashDB for the Type.
- Click Finish on both wizards. Within a few moments, your application should be deployed!
Add more services
- Log in to Bluemix, go to your dashboard, and click your application. You should see more information about your application server runtime and the database service you created for it.
- Scale your instance size or count up or down by clicking on the Runtime box.
- Visit the application by switching back to the Overview tab and clicking on the link next to your application name.
- On the Configuration tab, click (Re)-populate Database to populate your DB2 database with initial users and stocks.
- Click the Trading & Portfolio tab and log in. Congratulations, your application is up and running great!
- Next, let's add the Session Cache service. Go back to your Bluemix dashboard, click your application, and scroll down to find the Add New Service button.
- Click Session Cache, then Add to Application, then Create.
- The application now needs to be re-staged to
auto-configure the new service. Go back to Eclipse and find your
application in the Servers view. Right-click your application and
select Update and Restart.
That's it! Nothing else needs to be done for your sessions to be persisted. The Liberty build pack will detect that you bound the Session Cache service and create the necessary
server.xmlentries. The Session Cache service offloads your sessions to a remote location so that sessions are not lost when a server instance crashes or is removed as part of a scale-down. A re-started server or another server instance will pick up the session.
- Now that your sessions are being persisted, you can scale your
instances up and down without losing valuable session data.
Next, repeat steps 6-8 to add the Auto-Scaling and the Monitoring and Analytics services.
- You can use the Auto-Scaling service to automatically increase or
decrease the instances of your application by creating a policy. For
example, you can protect your application from failing due to running
out of memory by creating rules to scale up when Memory or JVM Heap
I recommend carefully reading the documentation to help you set a good policy that matches your application needs. You can use the Monitoring and Analytics services to gain deeper insights into your application performance. These are all powerful tools to help make the application perform at its best!
In this article, you've seen how easy it is to revitalize existing applications by adding IBM Bluemix services. The sample application we worked with is CloudTrader, which was based on a ten-year-old day trading app. The steps outlined here can be used to amp up any existing application. Have fun!
- Sign up for a free Bluemix trial
- Connect with Bluemix developers
- dashDB service
- Session Cache service
- Auto-Scaling service