Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud Dustin Amrhein (
[email protected]), Staff Software Engineer, IBM Summary: Part 1 of this article series discussed cloud computing in general, including cloud layers and the different cloud types, along with their benefits and drawbacks, and explained why this movement is important for enterprise developers. This article looks specifically at the public cloud and how you can use the IBM® WebSphere® sMash and IBM DB2® Express-C Amazon Machine Images (AMI) to deliver Web applications hosted on the EC2 public cloud infrastructure. This content is part of the IBM WebSphere Developer Technical Journal. Date: 20 May 2009 Level: Intermediate Activity: 392 views Comments: 0 (Add comments) Average rating (based on 0 votes) Introduction Among the three cloud types -- public, private, and hybrid clouds -- the public cloud is probably 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 these ends, the Amazon Elastic Compute Cloud (EC2) infrastructure provides a public cloud infrastructure that hosts Amazon Machine Image instances which deliver capability to users. To enable users to utilize EC2, IBM recently released Amazon Machine Images (AMI) that package some of its popular software offerings for the EC2 platform; these AMIs are available under a development license at no charge. In addition, IBM also supports specific existing IBM software running within the EC2 infrastructure. This article provides an overview of the public cloud, and discusses the use of the IBM WebSphere sMash and IBM DB2 Express-C Amazon Machine Images to deliver Web applications hosted on the EC2 infrastructure. Enterprises and the public cloud To understand how an enterprise can leverage public cloud computing solutions, consider two points of view:
1 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
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, a company can remove the burden of installing and maintaining the application on private data centers. Companies might also benefit from cost savings associated with license fees, since most cloud providers charge based on consumption. Enterprises utilize 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 the 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, a common theme is the bottom line value to a business. Public clouds very clearly can help an organization reduce costs associated with owning software and data center infrastructure components. Less directly, public cloud usage can deliver value by enabling a company to respond quickly to changes in demand for their services, enabling the services to reach new markets and enabling valuable human resources to concentrate on delivering business innovation, rather than simply deliver the technological infrastructure that supports the business. IBM and the public cloud IBM is an active contributor in the public cloud, offering solutions that enables a company to obtain applications from the cloud and deliver their own end-user applications by utilizing a public cloud. From an application provider perspective, IBM offers IBM Lotus® Live, IBM Lotus Sametime® Unyte®, and software development tools hosted in a public cloud. This suite of tools lets users meet, discuss, collaborate, and innovate all by leveraging cloud-provided services. In addition to providing these services, IBM's Global Business Services division helps organizations implement solutions that leverage public cloud offerings in order to deliver the sought after cloud value. The remainder of this article focuses on how IBM enables you to deliver effective applications by utilizing a public cloud infrastructure. As mentioned earlier, IBM packages several of its enterprise product offerings as Amazon Machine Images, thus enabling the use of the software on the popular Amazon EC2 infrastructure. IBM AMIs include: IBM WebSphere Portal IBM Lotus Web Content Management Standard Edition IBM WebSphere sMash IBM Informix® Dynamic Server Developer Edition 11.5 IBM DB2 Express-C 9.5 By making this software available under free development licenses through the Amazon 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 2 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
developerWorks spaces Cloud Computing site. This article focuses on the Platform as a Service (PaaS) and Data as a Service (DaaS) capabilities of the WebSphere sMash and DB2 Express-C AMIs respectively. WebSphere sMash and DB2 Express-C Individually, WebSphere sMash and DB2 Express-C are powerful tools for developers. Using WebSphere sMash, you can create Web 2.0 style applications using well-known technologies and patterns like DOJO, PHP, Groovy, and REST services. DB2 Express-C provides 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. The sample application included with this article demonstrates a restaurant seating application that provides a glimpse of the capabilities provided with the WebSphere sMash Zero Resource Model (ZRM) and a DB2 Express-C 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 Express-C is utilized to provide a rich front end experience fueled by a lightweight yet efficient and responsive back end. The IBM AMIs are offered with a development license free of charge, but remember to terminate the instances upon completion. Otherwise, you will continue to be charged Amazon's normal hourly rate for instance hosting. 1. Set up the AMIs To use the IBM AMIs, you must perform these steps, the first of which is a prerequisite: a. Set up your own Amazon Web Services (AWS) account. This account is used to manage your EC2 usage. b. Retrieve and configure the WebSphere sMash AMI and the DB2 Express-C AMI. When you configure the DB2 Express-C instance, use the default user names for the purpose of this demonstration. Do not create a database yet; those details are described in the next section. c. Deploy the AMIs to your AWS account by way of the supplied instructions. 2. Create and activate the database After deploying both the DB2 Express-C and WebSphere sMash AMIs to EC2, configure the database of your running DB2 Express-C instance. This database contains the tables utilized by your application. a. Use SSH to log into and authenticate your DB2 AMI instance. After you log in, switch to the db2inst1 user using the su - db2inst1 command. b. Create the database for the application using the createDatabase command. From the /home/db2inst1/bin directory, enter the ./createDatabase RSTDB command.
3 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
Figure 1. Creating the database
c. 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 Express-C instance is running on port 50001. The configuration of your DB2 Express-C instance is now complete. The ZRM in WebSphere sMash is used to integrate with the back end, so all of your tables are automatically configured. 3. Set up the application After you set up the WebSphere sMash AMI instance, log in to the AppBuilder application from http://<ec2_host>:8070/. Here you will create the WebSphere sMash application that will be used in the sample. To do that, click Create new application to create the sample application in the left panel of the AppBuilder. When prompted for a name enter RestaurantSeating. After creating the application, click on the application name in the center panel of the console to begin adding content to the application. 4. Leverage the Zero Resource Model The ZRM supported by WebSphere sMash is designed to radically simplify the process of providing REST-style access to back end data stores. The model supports a method of providing
4 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
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. a. To begin using the ZRM for the sample, create resource models for your data. These resource models define the data format of the resources in your application and are used by the ZRM to provide access to data stored in the database. You should already be logged in to the AppBuilder, so select New file => Zero Resource Model in app/models => New form. Figure 3. Creating a new resource model in the AppBuilder
b. Create a JSON data model for each entity. These JSON models define the attributes that make up each of your resources. This includes information about the data type of the attribute as well as other information like default values, data length, and more. Because you are creating a restaurant seating system, you will need to create resource models for four different entities: Waiting patrons Restaurant tables Seatings Waiters. In WebSphere sMash, these models are declared in JSON format. You can use the design 5 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
editor in the AppBuilder, or you can directly enter the JSON declarations of the resource models. In either case, you should have the four JSON files declared in Listing 1.
Listing 1. 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
6 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
// 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
c. You can now set up your resource handlers. The resource handlers provide REST access to the data defined by your resource models, and in this example they are implemented in the Groovy language. Select New file => Resource handler in app/resources to create four resource handlers, one for each of the resource models. The resource handlers should have the same name as the resource models but a .groovy rather than .json file extension. From there, select Resource handler in app/resources. There is an onList, onRetrieve, onCreate, onUpdate, and onDelete method within each resource handler. Each method corresponds to an HTTP method, GET, GET, POST, PUT, and DELETE respectively. Listing 2 shows an example of the resource handler for the waiter resource model.
7 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
Listing 2. waiter.groovy file def onList() { ZRM.delegate(); } def onRetrieve() { ZRM.delegate(); } def onCreate() { ZRM.delegate(); } def onUpdate() { ZRM.delegate(); } def onDelete() { ZRM.delegate(); }
The preceding groovy declaration can be made even simpler by replacing the entire contents of the file with a single line: ZRM.delegate(). There is no need to define each method, but doing so enables you to insert custom code into each of the methods, if necessary. 5. Create the database tables After you create both the resource models and handlers, you can use command line tools and configuration files in WebSphere sMash to create your database tables. a. Use SSH to log into the WebSphere sMash AMI instance and update the /home/smash /apps/RestaurantSeating/config/zero.config file. Add the name, location, and configuration of your back end data store. Listing 3. Integrating the ZRM and DB2 Express-C /config/db/zero-resource = {
b. Copy the db2cc.jar and db2cc_license_cu.jar to the WebSphere sMash application library. "class" : "com.ibm.db2.jcc.DB2SimpleDataSource", In earlier steps, :you "driverType" 4,provided the information required for the ZRM, including data "serverName" : "ec2-75-101-207-229.compute-1.amazonaws.com", source class name, database location, and access information for the database. Next, since "portNumber" : 50001, you are pointing to the com.ibm.db2.jcc.DB2SimpleDataSource data source class, you "databaseName" : "RSTDB", need to ensure the appropriate DB2 libraries are available to WebSphere sMash. Use an "user" : "db2inst1", "password" SCP program:to"passw0rd" retrieve the /home/db2inst1/sqllib/java/db2cc.jar and /home/db2inst1 }
8 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
/sqllib/java/db2cc_license_cu.jar files from the DB2 Express-C 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 WebSphere sMash instance to have the new JAR files added to the application classpath. c. Optionally, you can now define the initial data for your database tables. To save time entering data after you create the tables, you can use a feature for defining some initial data to be populated as you create tables. This data is defined in the initial_data.json file, located in the app/models/fixtures directory within the application. Entries in this file are instances of the resource models that were defined in previous steps. 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 Express-C AMI instance, and any data you defiend in the initial_data.json file will be inserted into the tables after they are created. 6. Create 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. These widgets provide out-of-the-box functionality. You can place them anywhere on your HTML page, provide the necessary configuration information, and the result is a friendly user-interface that delivers create, read, update, and delete access to back end data using the previously created resource handlers.
9 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
a. Define a DataStore that interacts with a ZRM resource handler and define a DataGrid that utilizes the DataStore. In your restaurant seating system, 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. (You can apply the same techniques to your seating data -- or any data for that matter -configured to use the ZRM.) Listing 4. The patron DataGrid and DataStore // patron DataStore <span dojoType="zero.resource.DataStore" id="patronDataStore" jsId="patronDataStore" contextRoot="./resources" resourceCollection="patron"> // patron DataGrid
The DataStore references the patron (patron.json) resource collection, and the DataGrid references the DataStore. Figure 4 shows an example of the output.
Figure 4. The patron zero.grid.DataGrid
10 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
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 code samples for the HTML forms and styles used to capture this information in the download file included with this article.)
Listing 5. 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); } }); }
b. Enable communication with ZRM resource handlers using HTML and JavaScript™. 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. Figure 5 extends the concepts described earlier to address the presentation and updating of information about the current seatings. Using some minor HTML and JavaScript code results in the user interface shown in Figure 5. Figure 5. User interface for the restaurant seating system
11 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
The result is a succinct, visually effective, and expressive user interface that enables hostesses to fully control aspects of seating within the restaurant. Try it yourself You can download the code for the full WebSphere sMash application for the sample described in this article. You need few resources to try out the application, as you can leverage the AMIs and EC2 for hosting both the WebSphere sMash and DB2 Express-C platforms. Follow the general instructions provided above to quickly get both AMIs launched and configured for use in Amazon EC2. With WebSphere sMash's ZRM, you can concentrate on the data, its relationships, and how those relationships are best presented to users, rather then focus on low level aspects of database communication. Couple these benefits with the robust, responsive, and comprehensive database capabilities offered by DB2 Express-C, and you can deliver a rich, data-oriented user experience directly to the browser.
Download
12 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
Description Code sample
Name restaurantSample.zip
http://www.ibm.com/developerworks/websphere/techjournal/0...
Size 52 KB
Download method HTTP
Information about download methods
Resources Learn Cloud Computing: Gain access to your Applications from anywhere, at any time Cloud Computing Journal A collection of stories, blog entries, and general information in cloud computing. Project Zero and WebSphere sMash Learn about WebSphere sMash and the latest development version, called Project Zero Is there value in cloud computing? IBM developerWorks WebSphere Get products and technologies Get IBM WebSphere sMash AMI for cloud computing Get IBM DB2 Express-C 9.5 AMI Discuss Blog: A view from the clouds: Cloud computing for the WebSphere developer Space: Cloud Computing Central WebSphere Cloud Computing for Developers community discusses the cloud computing landscape as it relates to WebSphere developers. Group: Google cloud computing discussion group Follow us on Twitter Project Zero Web community
13 of 14
7/21/09 2:03 PM
Cloud computing for the enterprise: Part 2: WebSphere sMash a...
http://www.ibm.com/developerworks/websphere/techjournal/0...
About the author Dustin Amrhein joined IBM as a member of the development team for WebSphere Application Server. While in that position, Dustin worked primarily on Web services infrastructure and Web services programming models. In addition, Dustin worked on the development of a RESTful services framework for Java runtimes. In his current role, Dustin is a technical evangelist for emerging technologies in IBM’s WebSphere portfolio. Trademarks
14 of 14
7/21/09 2:03 PM