Sei sulla pagina 1di 13

Cloud Computing for Enterprises:

WebSphere sMash and DB2 on EC2


IBM leverages Amazon's EC2 to deliver software

Level: Intermediate

Dustin Amrhein (damrhei@us.ibm.com), Technical Evangelist, Emerging Technologies,


IBM

08 April 2009

Among the three cloud types, the public cloud is likely the most well-known and mature
in its offerings. Accessibility and affordability are two of the key characteristics that have
led to the popularity of the public cloud. To both of those ends, the Amazon Elastic
Compute Cloud (EC2) infrastructure provides public cloud infrastructure that hosts
Amazon Machine Image instances which deliver capability to users. To allow users to
utilize EC2, IBM recently released Amazon Machine Images that package some of its
popular software offerings for the EC2 platform, and the AMIs are available under a
development license at no charge. In addition, IBM also supports already purchased IBM
software running within the EC2 infrastructure. This article provides an overview of the
public cloud, and it discusses the use of the WebSphere sMash and DB2 Amazon
Machine Images to deliver web applications hosted on the EC2 infrastructure.

Enterprises and the Public Cloud

Consider two points of view to understand how enterprises can leverage public cloud
computing solutions. In the first scenario, we see enterprises consume applications
provided in the public cloud. This might be an application designed to process employee
payroll data, or it might be a customer relationship management system. By utilizing
software delivered in this way, companies remove the burden of installing and
maintaining the application on its private data centers. Companies might also benefit
from cost savings associated with license fees since most cloud providers charge based on
consumption. In the second public cloud usage scenario, we see companies utilizing
cloud-based hosting solutions to deliver applications to users. By doing so, companies are
freed from the maintenance and upkeep of production systems since the cloud provider is
responsible for providing infrastructure resources to meet the demands users place on the
application. This model also provides for an increase in ubiquity of a company's services
since solutions delivered by way of a public cloud can be accessed at any time from any
machine with a viable network connection.

Regardless of the scenario being discussed, a common theme is bottom-line value to a


business. Public clouds very clearly can help an organization's bottom-line by reducing
costs associated with owning software and data center infrastructure components. In a
more indirect way, public cloud usage can deliver value by enabling the company to
quickly respond to changes in demand for their services, allowing the services to reach
new markets, and allowing valuable human resource to concentrate on delivering
business innovation instead of simply delivering technological infrastructure that supports
the business.

IBM and the Public Cloud

IBM is an active contributor in the public cloud by offering solutions that enable
companies to obtain applications from the cloud and to deliver their end-user applications
by utilizing a public cloud. From an application provider perspective, IBM offers Lotus
Live, Lotus Sametime Unyte, and software development tools hosted in a public cloud.
This suite of tools allows users to meet, discuss, collaborate, and innovate all by
leveraging cloud-provided services. In addition to providing these services, IBM's Global
Business Services division helps clients to implement solutions that leverage public cloud
offerings in order to deliver the sought after cloud value.

The remainder of this articles focuses on how IBM enables developers to deliver effective
applications by utilizing a public cloud infrastructure. To achieve this goal, IBM packages
several of its enterprise product offerings as Amazon Machine Images, thus allowing the
use of the software on the popular Amazon EC2 infrastructure. The IBM AMIs include
WebSphere Portal Server and Lotus Web Content Management Standard Edition,
WebSphere sMash, Informix Dynamic Server Developer Edition 11.5, and DB2 Express-
C 9.5. By making this software available under free development licenses (priced,
production licenses to come later) through Amazon's EC2 infrastructure, IBM is able to
reach out to an ecosystem that serves over 400,000 users and attracts around 80% of all
developers utilizing cloud computing development services. For more information on
IBM's outlook for developers and cloud computing, visit the developerWorks spaces
Cloud Computing site. This article focuses on the Platform as a Service (PaaS) and Data
as a Service capabilities of the WebSphere sMash and DB2 AMIs respectively.

WebSphere sMash and DB2


Taken alone, WebSphere sMash and DB2 are both powerful tools for a developer to use.
Using sMash, developers can create Web 2.0 style applications using well-known
technologies and patterns like DOJO, PHP, Groovy, and REST services. DB2 provides
for efficient, responsive, and reliable storage of enterprise data and includes pure XML
handling capabilities. However, an even higher level of value can be realized when these
technologies are combined to deliver rich, responsive, data-oriented web applications.
This article demonstrates a restaurant seating application that provides a glimpse of the
capabilities provided with sMash's Zero Resource Model and a DB2 database. The
patterns for this application can be easily extended to deal with the most complex of data
and data relationships. The Zero Resource Model integrated with DB2 is utilized to
provide a rich front-end experience fueled by a light-weight yet efficient and responsive
back-end.

Setting up the AMIs

To begin using the IBM AMIs, you must meet certain prerequisites. First, set up an
Amazon Web Services account. This is the account that you use to manage the EC2
usage. After you set up the EC2 account, you can acquire both the sMash and DB2 AMIs
and deploy them to your account by way of the supplied instructions. The AMIs are
offered with a development license free of charge, but remember to terminate the
instances upon completion since you are still charged Amazon's normal hourly rate for
instance hosting. Here's a short recap of the setup with links:

1. Set up your own AWS account.

2. Retrieve and configure the sMash AMI.

3. Retrieve and configure the DB2 AMI.

For the purpose of this demonstration, use the default user names when you configure the
DB2 instance, and do not create a database yet as those details are covered in the next
section

Create and activate the database

After you deploy both the DB2 and sMash to EC2, configure the database of your running
DB2 instance. This is the database that contains the tables utilized by your application. To
do this, use Secure Shell (SSH) to authenticate to your DB2 instance. After you log in,
switch users to be the db2inst1 user using the su - db2inst1 command. Next, create the
DB2 database used by the application. From the /home/db2inst1/bin directory, enter
the ./createDatabase RSTDB command.

Figure 1. Creating the database

Stop and restart the DB2 service to activate your new database. Switch back to the root
user using the su command and run the rcdb2 stop and rcdb2 start commands.

Figure 2. Activating the database

After you restart the service, the RSTDB database is activated, and the DB2 instance is
running on port 50001. The configuration of your DB2 instance is now complete. The
Zero Resource Model in sMash is used to integrate with the back-end, so all of your
tables are automatically configured. Here's a short recap of the DB2 configuration steps:
1. Use SSH to log into the DB2 AMI instance

2. Create the database using the createDatabase command

3. Stop and restart the DB2 service to activate the newly created database

Setting up the application

After you set up the sMash AMI instance, log in to the AppBuilder application from
http://<ec2_host>:8070/. Click Create new application to create the sample
application, and name the application as RestaurantSeating. After the application is
created, click the application name.

Leveraging the Zero Resource Model

The Zero Resource Model (ZRM) supported by WebSphere sMash is designed to


radically simplify providing REST-style access to back-end data stores. The model
supports a method of providing this access with very little code and configuration. Simply
create a model of your data and resource handlers that are called to handle REST
interactions with the data. The resource handlers contain very little code in order to
process incoming data, and the ZRM completely hides interactions with the back-end
database.

To begin using the ZRM for the sample, create resource models for your data. You should
already be logged in to the AppBuilder. Click the New file > Zero Resource Model in
app/models > New form.
Figure 3. Creating a new resource model in the AppBuilder

Because you are creating a restaurant seating system, you will need to create resource
models for four different entities: waiting patrons, restaurant tables, seatings, and waiters.
In sMash these models are declared in JSON format. You can use the design editor in the
AppBuilder, or you can directly enter the JSON declarations of the resource models. In
either case, you should have the following four JSON files

Resource model declarations


// start patron.json (model for waiting customers)
{
"fields": {
"name": {
"label": "Name",
"required": true,
"type": "string",
"description": "",
"default_value": "",
"max_length": 50
},
"capacity_requested": {
"label": "Number needed",
"required": true,
"type": "integer",
"description": "",
"default_value": ""
},
"seated": {
"label": "",
"required": true,
"type": "string",
"description": "",
"default_value": "false",
"max_length": 5
}
}
}
// end patron.json

// start rest_table.json (model for restaurant tables)


{
"fields": {
"capacity": {
"label": "Capacity",
"required": true,
"type": "integer",
"description": "",
"default_value": ""
},
"table_type": {
"label": "Type",
"required": true,
"type": "string",
"description": "",
"default_value": "",
"max_length": 50
}
}
}
// end rest_table.json

// start waiter.json (model for waiters)


{
"fields": {
"name": {
"label": "Name",
"required": true,
"type": "string",
"description": "",
"default_value": "",
"max_length": 50
}
}
}
// end waiter.json

// start seating.json (model for a seating in the restaurant)


{
"fields": {
"table_id": {
"label": "Table Id",
"required": true,
"type": "integer",
"description": "",
"default_value": ""
},
"patron_name": {
"label": "Patron Name",
"required": true,
"type": "string",
"description": "",
"default_value": "",
"max_length": 50
},
"waiter_name": {
"label": "Waiter Name",
"required": true,
"type": "string",
"description": "",
"default_value": "",
"max_length": 50
}
}
}
// end seating.json

You can now set up your resource handlers to handle the REST requests that interact with
the data defined in the preceding models. The resource handlers are implemented in the
Groovy language. Click New file > Resource handler in app/resources to create four
resource handlers, one for each of the resource models. The resource handlers contain the
same name as the resource models, but have a .groovy file extension instead of a .json file
extension. From there, select Resource handler in app/resources. Within each
resource handler, there is an onList, onRetrieve, onCreate, onUpdate, and onDelete
method. Each method corresponds to an HTTP method, GET, GET, POST, PUT, and
DELETE respectively. The following is an example of the resource handler for the waiter
resource model.

The waiter.groovy file


def onList()
{
ZRM.delegate();
}

def onRetrieve()
{
ZRM.delegate();
}

def onCreate()
{
ZRM.delegate();
}

def onUpdate()
{
ZRM.delegate();
}

def onDelete()
{
ZRM.delegate();
}

You can make the preceding groovy declaration even simpler by replacing the entire
contents of the file with a single line, ZRM.delegate(), or each method can be fully
customized. Here's a short recap of setting up the ZRM and resource handlers:

1. Create a JSON data model for each entity

2. Create a resource handler that maps to each data model

3. Optionally customize resource handlers

Creating the database tables

After you create both the resource models and handlers, you can use sMash to create your
database tables. Log in to the sMash AMI instance using SSH and update the /home/
smash/apps/RestaurantSeating/config/zero.config file. Add the name, location,
and configuration of your back-end data store.

Integrating the ZRM and DB2


/config/db/zero-resource = {
"class" : "com.ibm.db2.jcc.DB2SimpleDataSource",
"driverType" : 4,
"serverName" : "ec2-75-101-207-229.compute-1.amazonaws.com",
"portNumber" : 50001,
"databaseName" : "RSTDB",
"user" : "db2inst1",
"password" : "passw0rd"
}

In the preceding steps, you provided the necessary information, including data source
class name, database location, and access information for the database, needed for the
ZRM. Next, ensure the appropriate DB2 libraries are available to sMash since you are
pointing to the com.ibm.db2.jcc.DB2SimpleDataSource data source class. Use an SCP
program to retrieve the /home/db2inst1/sqllib/java/db2cc.jar and /home/
db2inst1/sqllib/java/db2cc_license_cu.jar files from the DB2 AMI instance.
Copy the files to the /home/smash/apps/RestaurantSeating/lib directory. Run zero
resolve from the /home/smash/apps/RestaurantSeating directory of the sMash
instance to have the newly added JARs added to the application classpath.

You can now generate the tables for your database. To save data input time after you
create the tables, you can use a feature to define some initial data to be populated as you
create tables. This data is defined in the initial_data.json file. The file is in the app/
models/fixtures directory within the application. To generate your tables and populate
them with the initial data, run the zero model sync command. As a result, the tables are
created on your DB2 AMI instance, and an initial set of data is inserted in the tables.
Here's a short recap of creating the database tables:

1. Use SSH to log into the sMash AMI instance

2. Copy the db2cc.jar and db2cc_license_cu.jar to the sMash application's library

3. Optionally define initial data for your tables

4. Run the zero resolve command to generate the appropriate tables

Creating the user interface

Now you need to enable users of your system to view and interact with the data.
WebSphere sMash provides custom DOJO widgets that access stored data utilizing
facilities in the ZRM.

In your restaurant seating system, your hostesses need the ability to view currently
waiting patrons, add new patrons, and view the current seatings. You can use the
zero.resource.DataStore and the zero.grid.DataGrid to display patron information. Note
that you can apply the same techniques to your seating data or for that matter any data
configured to use the ZRM.

The patron DataGrid and DataStore


// patron DataStore
<span dojoType="zero.resource.DataStore" id="patronDataStore"
jsId="patronDataStore"
contextRoot="./resources"
resourceCollection="patron">
</span>

// patron DataGrid
<div dojoType="zero.grid.DataGrid"
id="patronDataGrid"
visibleFields="name,capacity_requested,id"
store="patronDataStore"
readonly="true"
style="width: 348px; height: 271px;">
</div>

The DataStore references the patron (patron.json) resource collection, and the DataGrid
references the DataStore. The following is an example of the output:

Figure 4. The patron zero.grid.DataGrid

In addition to the DataGrid that displays your data, you can add a new patron or seat an
existing patron. New data can be easily added to a back-end data store utilizing the ZRM.
See the attached code samples for the HTML forms and styles used to capture this
information.

Adding new patron data


function addPatron() {
dojo.xhrPost({
url: "resources/patron",
form: "addPatronForm",
load: function (data) {
hideAddPatron();
displayWaitingPatrons();
},

// Call this function if an error happened


error: function (error) {
console.error ('Error: ', error);
}
});
}

The preceding example results in a call to the patron.groovy resource handler, which
internally delegates to the ZRM to handle populating the DB2 database with the new data.
The following extends the concepts previously mentioned to address presenting and
updating information about the current seatings. Using a small amount of HTML and
JavaScript results in the following user interface:

Figure 5. User interface for the restaurant seating system

The result is a succinct, visually effective, and expressive user interface that allows
hostesses to fully control aspects of seating within the restaurant. Here's a short recap of
building the GUI:

1. Define a DataStore that interacts with a ZRM resource handler

2. Define a DataGrid that utilizes the DataStore


3. Enable communication with ZRM resource handlers using HTML and JavaScript

Try it for yourself

You can download the full sMash application code for the sample discussed in this
article. You need few resources to try out the application as you can leverage the AMIs
and EC2 for hosting both the sMash and DB2 platforms. You can refer to the above
information to quickly get both AMIs launched and configured for use in Amazon’s EC2.

With WebSphere sMash's ZRM, you can concentrate on the data, its relationships, and
how those relationships are best presented to users instead of concentrating on low-level
database communication aspects. Couple these benefits with the robust, responsive,
comprehensive database capabilities offered by DB2, and you can deliver rich, data-
oriented user experiences directly to the browser.

Resources

 Our Blogs - Read and react to what we have to say about cloud computing.

 IBM AMIs A link to the collection of IBM Amazon Machine Images.

 IBM's Cloud Read the latest IBM news in cloud computing.

 DeveloperWorks Cloud Space A DeveloperWorks space devoted to cloud


computing.

 Cloud Computing Journal A collection of stories, blog entries, and general


information in cloud computing.

Potrebbero piacerti anche