Contents


Revitalize your Java EE app with IBM Bluemix services

Amp up any existing application with cloud-based services on IBM's cloud platform

Comments

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.

CloudTrader app Trading and portfolio window
CloudTrader app Trading and portfolio window

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.
Bluemix Cloud image showing the three Bluemix services
Bluemix Cloud image showing the three Bluemix services

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.

Image showing the linkage between IBM DevOps Services, Eclipse, and Bluemix
Image showing the linkage between IBM DevOps Services, Eclipse, and Bluemix

What you will need

1

Get the code from GitHub

  1. Click the Get the code button above, and then click Clone or download and Download Zip.
  2. Launch Eclipse. File > Import > General > Existing Projects into Workspace > Select archive file > [your download].
  3. You should now see the CloudTrader project (with code) in your Project Explorer view.
2

Create a Bluemix server

  1. 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.
  2. In the Define a New Server window, expand the IBM folder, select IBM Bluemix, and click Next.
  3. Enter your credentials for your Bluemix account.
  4. Click Validate Account, then click Finish.
  5. You can now drag and drop the CloudTrader project onto the Bluemix server you just created.
  6. You will be presented with a wizard. Choose a unique name for your application to prevent name collisions in the Bluemix domain.
  7. On the next panel, you can select the URL and Memory information. Accept the defaults and click Next.
  8. 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 for the add service window 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.
  9. Click Finish on both wizards. Within a few moments, your application should be deployed!
3

Add more services

  1. 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. CloudTrader demo overview screen
    CloudTrader demo overview screen
  2. Scale your instance size or count up or down by clicking on the Runtime box.
  3. Visit the application by switching back to the Overview tab and clicking on the link next to your application name.
  4. On the Configuration tab, click (Re)-populate Database to populate your DB2 database with initial users and stocks. Configuration screen
    Configuration screen
  5. Click the Trading & Portfolio tab and log in. Congratulations, your application is up and running great!
  6. 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.
  7. Click Session Cache, then Add to Application, then Create.
  8. 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.xml entries. 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.

  9. 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.

    Auto-scaling                             window
    Auto-scaling window
  10. 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 reaches 80%.

    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!

    Auto-scaling                             policy configuration screen
    Auto-scaling policy configuration screen

Conclusion

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!


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing, Java development
ArticleID=985495
ArticleTitle=Revitalize your Java EE app with IBM Bluemix services
publish-date=07122017