cloud computing for the enterprise: part 2: websphere smash and db2 express-c on the amazon ec2...

Upload: yakura-coffee

Post on 30-May-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    1/14

    Cloud computing for the enterprise: Part 2:

    WebSphere sMash and DB2 Express-C on theAmazon EC2 public cloudDustin Amrhein ([email protected] ), Staff Software Engineer, IBM

    Summary: Part 1 of this article series discussed cloud computing in general, including cloud layersand the different cloud types, along with their benets and drawbacks, and explained why thismovement is important for enterprise developers. This article looks specically at the public cloudand how you can use the IBM WebSphere sMash and IBM DB2 Express-C Amazon MachineImages (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 2009Level: IntermediateActivity: 392 viewsComments: 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 themost well-known and mature in its offerings. Accessibility and affordability are two of the keycharacteristics that have led to the popularity of the public cloud. To these ends, the Amazon ElasticCompute Cloud (EC2) infrastructure provides a public cloud infrastructure that hosts AmazonMachine Image instances which deliver capability to users. To enable users to utilize EC2, IBMrecently released Amazon Machine Images (AMI) that package some of its popular software offeringsfor the EC2 platform; these AMIs are available under a development license at no charge. In addition,IBM also supports specic existing IBM software running within the EC2 infrastructure.

    This article provides an overview of the public cloud, and discusses the use of the IBM WebSpheresMash and IBM DB2 Express-C Amazon Machine Images to deliver Web applications hosted on theEC2 infrastructure.

    Enterprises and the public cloud

    To understand how an enterprise can leverage public cloud computing solutions, consider two pointsof view:

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    2/14

    Enterprises consume applications provided in the public cloud. This might be an applicationdesigned to process employee payroll data, or it might be a customer relationship managementsystem. 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 benetfrom cost savings associated with license fees, since most cloud providers charge based onconsumption.

    Enterprises utilize cloud-based hosting solutions to deliver applications to users. By doingso, companies are freed from the maintenance and upkeep of production systems since thecloud provider is responsible for providing infrastructure resources to meet the demands usersplace on the application. This model also provides for an increase in the ubiquity of acompany's services, since solutions delivered by way of a public cloud can be accessed at anytime 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 veryclearly can help an organization reduce costs associated with owning software and data centerinfrastructure components. Less directly, public cloud usage can deliver value by enabling a companyto 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 thansimply 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 obtainapplications 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 SametimeUnyte, 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 thatleverage 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 byutilizing a public cloud infrastructure. As mentioned earlier, IBM packages several of its enterpriseproduct offerings as Amazon Machine Images, thus enabling the use of the software on the popularAmazon EC2 infrastructure. IBM AMIs include:

    IBM WebSphere PortalIBM Lotus Web Content Management Standard EditionIBM WebSphere sMash

    IBM Informix Dynamic Server Developer Edition 11.5IBM DB2 Express-C 9.5

    By making this software available under free development licenses through the Amazon EC2infrastructure, IBM is able to reach out to an ecosystem that serves over 400,000 users and attractsaround 80% of all developers utilizing cloud computing development services.

    For more information on IBM's outlook for developers and cloud computing, visit the

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    3/14

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

    WebSphere sMash and DB2 Express-C

    Individually, WebSphere sMash and DB2 Express-C are powerful tools for developers. UsingWebSphere sMash, you can create Web 2.0 style applications using well-known technologies andpatterns like DOJO, PHP, Groovy, and REST services. DB2 Express-C provides efcient, responsive,and reliable storage of enterprise data and includes pure XML handling capabilities. However, an evenhigher 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 thatprovides 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 dealwith the most complex of data and data relationships. The Zero Resource Model integrated with DB2Express-C is utilized to provide a rich front end experience fueled by a lightweight yet efcient andresponsive back end.

    The IBM AMIs are offered with a development license free of charge, but remember to terminate theinstances upon completion. Otherwise, you will continue to be charged Amazon's normal hourly ratefor instance hosting.

    Set up the AMIs

    To use the IBM AMIs, you must perform these steps, the rst of which is a prerequisite:

    Set up your own Amazon Web Services (AWS) account . This account is used to manageyour EC2 usage.

    a.

    Retrieve and congure the WebSphere sMash AMI and the DB2 Express-C AMI . Whenyou congure 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 nextsection.

    b.

    Deploy the AMIs to your AWS account by way of the supplied instructions.c.

    1.

    Create and activate the database

    After deploying both the DB2 Express-C and WebSphere sMash AMIs to EC2, congure thedatabase of your running DB2 Express-C instance. This database contains the tables utilized byyour application.

    Use SSH to log into and authenticate your DB2 AMI instance. After you log in, switch tothe db2inst1 user using the su - db2inst1 command.

    a.

    Create the database for the application using the createDatabase command. From the/home/db2inst1/bin directory, enter the ./createDatabase RSTDB command.

    b.

    2.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    4/14

    Figure 1. Creating the database

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

    Figure 2. Activating the database

    c.

    After you restart the service, the RSTDB database is activated, and the DB2 Express-C instanceis running on port 50001. The conguration 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 areautomatically congured.

    Set up the application

    After you set up the WebSphere sMash AMI instance, log in to the AppBuilder application fromhttp://:8070/ . Here you will create the WebSphere sMash application that will beused 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 . Aftercreating the application, click on the application name in the center panel of the console tobegin adding content to the application.

    3.

    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.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    5/14

    this access with very little code and conguration. Simply create a model of your data andresource handlers that are called to handle REST interactions with the data. The resourcehandlers contain very little code in order to process incoming data, and the ZRM completelyhides interactions with the back end database.

    To begin using the ZRM for the sample, create resource models for your data. Theseresource models dene the data format of the resources in your application and are usedby the ZRM to provide access to data stored in the database. You should already belogged in to the AppBuilder, so select New le => Zero Resource Model in app/models=> New form .

    Figure 3. Creating a new resource model in the AppBuilder

    a.

    Create a JSON data model for each entity. These JSON models dene the attributes thatmake up each of your resources. This includes information about the data type of theattribute 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 forfour different entities:Waiting patronsRestaurant tablesSeatingsWaiters.

    In WebSphere sMash, these models are declared in JSON format. You can use the design

    b.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    6/14

    editor in the AppBuilder, or you can directly enter the JSON declarations of the resourcemodels. In either case, you should have the four JSON les 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

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    7/14

    // 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. The resource handlers provide REST accessto the data dened by your resource models, and in this example they are implemented in

    the Groovy language. Select New le => Resource handler in app/resources to createfour resource handlers, one for each of the resource models. The resource handlers shouldhave the same name as the resource models but a .groovy rather than .json le extension.From there, select Resource handler in app/resources. There is an onList, onRetrieve,onCreate, onUpdate, and onDelete method within each resource handler. Each methodcorresponds 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.

    c.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    8/14

    Listing 2. waiter.groovy le

    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 entirecontents of the le with a single line: ZRM.delegate() . There is no need to dene eachmethod, but doing so enables you to insert custom code into each of the methods, if necessary.

    Create the database tables

    After you create both the resource models and handlers, you can use command line tools andconguration les in WebSphere sMash to create your database tables.

    Use SSH to log into the WebSphere sMash AMI instance and update the /home/smash/apps/RestaurantSeating/cong/zero.cong le. Add the name, location, andconguration of your back end data store.

    Listing 3. Integrating the ZRM and DB2 Express-C

    /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"}

    a.

    Copy the db2cc.jar and db2cc_license_cu.jar to the WebSphere sMash application library.In earlier steps, you provided the information required for the ZRM, including datasource class name, database location, and access information for the database. Next, sinceyou are pointing to the com.ibm.db2.jcc.DB2SimpleDataSource data source class, youneed to ensure the appropriate DB2 libraries are available to WebSphere sMash. Use anSCP program to retrieve the /home/db2inst1/sqllib/java/db2cc.jar and /home/db2inst1

    b.

    5.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    9/14

    /sqllib/java/db2cc_license_cu.jar les from the DB2 Express-C AMI instance. Copy theles to the /home/smash/apps/RestaurantSeating/lib directory. Run zero resolve from the/home/smash/apps/RestaurantSeating directory of the WebSphere sMash instance to havethe new JAR les added to the application classpath.Optionally, you can now dene the initial data for your database tables. To save timeentering data after you create the tables, you can use a feature for dening some initial

    data to be populated as you create tables. This data is dened in the initial_data.json le,located in the app/models/xtures directory within the application. Entries in this le areinstances of the resource models that were dened in previous steps. To generate yourtables and populate them with the initial data, run the zero model sync command. As aresult, the tables are created on your DB2 Express-C AMI instance, and any data youdeend in the initial_data.json le will be inserted into the tables after they are created.

    c.

    Create the user interface

    Now you need to enable users of your system to view and interact with the data. WebSpheresMash 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 conguration information, and the result is a friendlyuser-interface that delivers create, read, update, and delete access to back end data using thepreviously created resource handlers.

    6.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    10/14

    Dene a DataStore that interacts with a ZRM resource handler and dene a DataGrid thatutilizes the DataStore. In your restaurant seating system, hostesses need the ability toview currently waiting patrons, add new patrons, and view the current seatings. You canuse 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 --congured to use the ZRM.)

    Listing 4. The patron DataGrid and DataStore

    // patron DataStore

    // patron DataGrid

    The DataStore references the patron (patron.json) resource collection, and the DataGridreferences the DataStore. Figure 4 shows an example of the output.

    Figure 4. The patron zero.grid.DataGrid

    a.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    0 of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    11/14

    In addition to the DataGrid that displays your data, you can add a new patron or seat anexisting 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 inthe download le 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 happenederror: function (error) {

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

    }

    Enable communication with ZRM resource handlers using HTML and JavaScript. Thepreceding example results in a call to the patron.groovy resource handler, whichinternally delegates to the ZRM to handle populating the DB2 database with the newdata. Figure 5 extends the concepts described earlier to address the presentation andupdating of information about the current seatings. Using some minor HTML andJavaScript code results in the user interface shown in Figure 5.

    Figure 5. User interface for the restaurant seating system

    b.

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    1 of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    12/14

    The result is a succinct, visually effective, and expressive user interface that enables hostessesto 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 thisarticle. You need few resources to try out the application, as you can leverage the AMIs and EC2 forhosting both the WebSphere sMash and DB2 Express-C platforms. Follow the general instructionsprovided above to quickly get both AMIs launched and congured for use in Amazon EC2.

    With WebSphere sMash's ZRM, you can concentrate on the data, its relationships, and how thoserelationships are best presented to users, rather then focus on low level aspects of databasecommunication. Couple these benets with the robust, responsive, and comprehensive database

    capabilities offered by DB2 Express-C, and you can deliver a rich, data-oriented user experiencedirectly to the browser.

    Download

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    2 of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    13/14

    Description Name Size Download methodCode sample restaurantSample.zip 52 KB 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 cloudcomputing.

    Project Zero and WebSphere sMash Learn about WebSphere sMash and the latest developmentversion, 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 computinglandscape as it relates to WebSphere developers.

    Group: Google cloud computing discussion group

    Follow us on Twitter

    Project Zero Web community

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    3 of 14 7/21/09 2:03 P

  • 8/14/2019 Cloud computing for the enterprise: Part 2: WebSphere sMash and DB2 Express-C on the Amazon EC2 public cloud

    14/14

    About the author

    Dustin Amrhein joined IBM as a member of the development team for WebSphere ApplicationServer. While in that position, Dustin worked primarily on Web services infrastructure and Webservices programming models. In addition, Dustin worked on the development of a RESTful servicesframework for Java runtimes. In his current role, Dustin is a technical evangelist for emergingtechnologies in IBMs WebSphere portfolio.

    Trademarks

    Cloud computing for the enterprise: Part 2: WebSphere sMash a... http://www.ibm.com/developerworks/websphere/techjournal/0...

    4 of 14 7/21/09 2:03 P