Download Porting Google App Engine Applications to IBM Middleware

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Porting Google App Engine Applications to IBM
Middleware
Author: Animesh Singh, John Reif
Abstract: Google App Engine is a cloud computing platform that hosts third party Web
applications. Application authors write their application front ends in a high-level language
like Python or Java™. Applications can use other Google services like datastore and
Google Accounts as their application back end. Authors upload the application front ends
through the Admin console to the Google App Engine.
At IBM Cloud Labs we have produced interoperability code/documentation to allow GAE
application developers to move easily to IBM middleware. This document shows how to
port the three major Java-based Google App Engine APIs/functionalities to the IBM
middleware environment where application function can be expanded. The APIs
discussed are datastore, Users, and URL fetch.
© Copyright IBM Corporation 2009
Introduction
Google App Engine is a Google service that hosts third party Web applications. Application authors write
their application front ends in a high-level language like Python or Java™. Applications can use other
Google services like datastore and Google Accounts as their application back end. Authors upload the
application front ends through the Admin console to the Google App Engine.
Google App Engine is good for Web applications that are database-backed — applications that look like
Digg, Orkut, and Blogger. Google App Engine provides an environment to run application front ends, a
storage (datastore) back end, an authentication (Google Accounts) back end, an e-mail service, and a
way to fetch content from the Web.
The Google App Engine environment limits what an application can do. Applications can read files in the
application bundle, make Google App Engine API calls, and return an HTTP response to the user.
Applications cannot open network connections directly, write files to a local disk, or run code not
responding to a user request.
Since Google App Engine is an external hosted service, you sometimes need to run your Java/J2EE code
behind the corporate firewall, and all over XM enterprises choose IBM WebSphere to do precisely this.
Also there maybe other compelling technical and business reasons to move between different
environments. With this in mind, we are going to discuss in this aritcle how IBM`s various middleware
components can form a complete suite to address all common application tasks. Just as important, we
are going to show how Java standards make it easy to move your code from one environment to the next
At its most basic level WebSphere is a deployment environment for your Java code -- a regular J2EE
servlet container -- and as it turns out, there are many such containers in the market. With today's Java
runtime, App Engine is one example. WebSphere is another, as well as Tomcat®, WebLogic® and
others Each of these deployment environments has its unique attributes. (WebSphere, for instance,
offers complete set of J2EE features like Java Beans, JDBC, RMI and others.) Certain features and
business rules will favor one environment over another, or require you to move between them. But
because all of these containers and databases can work with standard Java APIs and libraries,
redeployment from App Engine to WebSphere entails only a few config changes
This document shows how to port the three major Java-based Google App Engine APIs/functionalities to
the IBM middleware environment where application function can be expanded. If using IBM middleware
to implement these APIs, applicable IBM products would be used for each. For instance, a combination
of IBM® WebSphere® Application Server v7.0 and IBM® DB2® v9.1 database system would be used to
implement the datastore and a combination of IBM® WebSphere® Application Server v7.0 and IBM®
Tivoli® Directory Server v6.1 would be used to implement the users API. The APIs discussed are:
•
•
•
com.google.appengine.api.datastore
com.google.appengine.api.users
com.google.appengine.api.urlfetch
Currently, only these APIs from Google App Engine are implemented/documented as part of this porting
code. Future versions of this document and sample code may implement more APIs as they become
available. Also please note that this is one of the ways to imple nt/port the API functionalities, and a
user can implement it differently. This article and associated code is meant to provide guidance to the
users how they can port functionalities.
© Copyright IBM Corporation 2009
2
Porting Google App Engine Applications to IBM Middleware
Building an app to run on Google App Engine / IBM
WebSphere
Because the Google App Engine software development kit (SDK) is built on top of the Jetty server and
follows the specification for a Java2 Enterprise Edition (J2EE) servlet, running a Google App Engine
application on top of IBM WebSphere Application Server is straightforward. It is necessary, however, to
port the Google App Engine APIs to support the basic application services of database access,
authentication, and calls to external URLs. Having mentioned that, whenever possible Google supports
the Java standard, which provides the same functionality as their existing App Engine APIs. This section
describes how to port the Google APIs to IBM mddleware, and if there is an alternative standard
Java/J2EE implementation provided by Google for the functionality, we will use that.
Porting datastore operations
The datastore API is used to persist Java objects to the Google datastore. Alternatively Google also
provides a Java data object (JDO) (http://java.sun.com/jdo/) implementation that uses the DataNucleus
project (www.datanucleus.org/) to persist objects to the datastore. Since JDO is a standard spec from
Java, instead of implementing datastore API, we will be showing how datastore operations using JDO via
datanucleus can be ported to persist objects to DB2. This assumes that the user has written a GAE
application to persist objects using JDO, and not proprietary Google datastore API.
Follow these steps to use DataNucleus to write applications that can be ported from the Google datastore
to run on WebSphere talking to IBM DB2 with minimal changes:
1. Configure DataNucleus in Eclipse using
www.datanucleus.org/products/accessplatform_1_0/guides/eclipse/index.html#install
2. Enable auto enhancement to enhance the classes. Identify the classes you are persisting to the
Google datastore, and refactor each to change the primary key from String to int. Google
datastore takes Long, String, Key, String Encoded Key as the primary key for persistable
classes, whereas DB2 takes int, Integer, long, Long through DataNucleus.
3. Change the datanucleus.properties file in your application to point to DB2. Here is a sample
file:
javax.jdo.PersistenceManagerFactoryClass=org.datanucleus.jdo.JDOPersistenc
eManagerFactory
javax.jdo.option.ConnectionDriverName=com.ibm.db2.jcc.DB2Driver
javax.jdo.option.ConnectionURL=jdbc:db2://9.x.x.x.:50000/paces
javax.jdo.option.ConnectionUserName=ldapdb2
javax.jdo.option.ConnectionPassword=time4fun
datanucleus.validateTables=false
datanucleus.validateConstraints=false
datanucleus.NontransactionalRead=true
datanucleus.NontransactionalWrite=true
So we have seen the with three minimal steps we can move an application which makes Google
datastore calls to IBM middleware persisting to DB2
Porting user authentication operations
In the context of the Google App engine, the users API is used to authenticate application users against
Google Accounts. In the context of IBM, we at IBM Cloud Labs have written code to authenticate against
IBM® Tivoli® Directory Server Lightweight Directory Access Protocol (LDAP). The API code for
interoperability (InteropApis.jar) is included with this bundle. Please note that you can implement in
alternative ways also.
© Copyright IBM Corporation 2009
3
Porting Google App Engine Applications to IBM Middleware
1. Place the InteropApis.jar into your lib directory.
2.
Import the LDIF file, userApi.ldif into your LDAP setup.
dn: o=ibm,c=us
objectClass: organization
objectClass: top
o: ibm
dn: uid=guest1, o=ibm,c=us
userpassword:: d2VsY29tZQ==
uid: guest1
objectClass: inetOrgPerson
objectClass: top
objectClass: person
objectClass: organizationalPerson
sn: guest1
cn: guest1
dn: [email protected], o=ibm,c=us
mail: [email protected]
uid: [email protected]
userpassword:: dGltZTRmdW4=
Givenname: ANI
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
title: ADMIN
sn: [email protected]
cn: [email protected]
You can change dn, mail, uid, sn, and cn to correspond to another user, and extra users. The
password shown encrypted in the above ldif file is time4fun .
3. In your application, make a directory called resources under WebContent and add a properties file
ldap.properties. A sample is provided below:
LDAP_PROVIDER=com.sun.jndi.ldap.LdapCtxFactory
LDAP_URL=ldap://9.x.x.x:389
LDAP_URL_CTX=com.sun.jndi.url
BASE_SEARCH=o=ibm,c=us
SECURITY_PROTOCOL=ssl
LDAP_ROOT_USER=cn=root
LDAP_ROOT_PWD=passw0rd
4. Change any package declaration
import com.google.appengine.api.users.*;
to
import com.ibm.appengine.api.users.*;
and the line
© Copyright IBM Corporation 2009
4
Porting Google App Engine Applications to IBM Middleware
UserService userService = UserServiceFactory.getUserService();
to
UserService userService = UserServiceFactory.getUserService(request);
5. Place the login.jsp and the error.jsp provided in the resources directory.
Using these steps you should be able to port an application using Users API for authentication.
Porting URL fetch operations
The URL fetch API is used to open connections to external URLs. This API is written to provide more
security to App engine operations. Although there are alternative ways to achieve this on IBM platforms,
we have implemented these APIs to facilitate interoperability.
1. Change the following declaration in the URL Fetch API to port it to the IBM stack.
import com.google.appengine.api.urlfetch.*;
to
import com.ibm.appengine.api.urlfetch.*;
and the line
URLFetchService urlService = URLFetchServiceFactory.getURLFetchService();
to
URLFetchService urlService = URLFetchServiceFactory.getURLFetchService(request);
App Engine also supports the standard java.net.URL/HttpURLConnection for URL fetch.
Conclusion
With these interoperability APIs and guidelines, you can port an application built for Google App Engine –
Java version to an IBM middleware environment. We have
implementation
regarding all major APIs.
As mentioned above, the InteropApis.jar is available in the bundle. For further information
regarding this technical preview, send an e-mail to [email protected].
References
Google App Engine Web site: (http://code.google.com/appengine/)
Sun JDO: (http://java.sun.com/jdo/)
DataNucleus: (http://www.datanucleus.org/)
© Copyright IBM Corporation 2009
5
Porting Google App Engine Applications to IBM Middleware
Notices
Trademarks
The following are trademarks or registered trademarks
the United States, other countries, or both:
International Business Machines Corporation in
DB2, IBM, Tivoli, WebSphere
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun
Microsystems, Inc. in the United States and other countries.
Special Notice
The information contained in this document has not been submitted to any formal IBM test and is
distributed AS IS. The use of this information or the implementation of any of these techniques is a
customer responsibility and depends on the customer’s ability to evaluate and integrate them into the
customer’s operational environment. While IBM may have reviewed each item for accuracy in a specific
situation, there is no guarantee that the same or similar results will be obtained elsewhere. Anyone
attempting to adapt these techniques to their own environments do so at their own risk.
While IBM may have reviewed each item for accuracy in a specific situation, IBM offers no guarantee or
warranty to any user that the same or similar results will be obtained elsewhere. Any person attempting
to adapt the techniques contained in this document to their own environment(s) does so at their own risk.
Any performance data contained in this document were determined in various controlled laboratory
environments and are for reference purposes only. Customers should not adapt these performance
numbers to their own environments as system performance standards. The results that may be obtained in
other operating environments may vary significantly. Users of this document should verify the applicable
data for their specific environment.
© Copyright IBM Corporation 2009
6
Porting Google App Engine Applications to IBM Middleware