Download - Google App Engine
![Page 1: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/1.jpg)
Google App Engine
Assoc.Prof. Dr.Thanachart NumnondaAsst.Prof. Thanisa Kruawaisayawan
Mini Master of Java TechnologyKMITL
July 2012
![Page 2: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/2.jpg)
Agenda
What is Cloud Computing?What is Google App Engine?Google App Engine for JavaGoogle App Engine Development cycle
![Page 3: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/3.jpg)
What is Cloud Computing?
![Page 4: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/4.jpg)
Cloud computing : Definition (Wikipedia)
Cloud Computing is Internet-based computing, whereby shared resources, software, and information
are provided to computers and other devices on demand, like the electricity grid.
![Page 5: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/5.jpg)
Cloud computing characteristics
Massive, abstracted infrastructureDynamic allocation, scaling, movement of applicationsPay per useNo long-term commitmentsOS, application architecture independentNo hardware or software to install
![Page 6: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/6.jpg)
Grid to Cloud Evolution
![Page 7: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/7.jpg)
Web 2.0 & Cloud ComputingWeb 2,0 concentrate on the private user and clouds
are decscendents of data centers which services the enterprise
Web 2.0 promote SaaSWeb 2.0 needs massive scaling technologiesUser centric Web 2.0 companies (Twitter, Slideshare)
are relying on Cloud Services
![Page 8: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/8.jpg)
ISP to Cloud Evolution
![Page 9: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/9.jpg)
Software as a Service (SaaS)SaaS is at the highest layer and features a complete
application offered as a service, on-demand,via multitenancy — meaning a single instance of the
software runs on the provider’s infrastructure and serves multiple client organizations.
![Page 10: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/10.jpg)
Platform as a Service (PaaS)The middle layer, or PaaS, is the encapsulation of a
development environment abstraction and the packaging of a payload of services
PaaS offerings can provide for every phase of software development and testing, or they can be specialized around a particular area, such as content management
![Page 11: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/11.jpg)
Infrastructure as a Service (IaaS)IaaS is at the lowest layer and is a means of delivering basic
storage and compute capabilities as standardized services over the network.
Servers, storage systems, switches,routers, and other systems are pooled (through virtualization technology, for example) to handle specific types of workloads — from batch processing to server/storage augmentation during peak loads.
![Page 12: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/12.jpg)
![Page 13: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/13.jpg)
Deployment ModelPublic Cloud: provider refers to the cloud platform that
targets any types of customers.Private Cloud: infrastructure that’s hosted internally, targeting
specific customers or sometimes exclusively within an organization.
Hybrid Cloud: the combination of public and private clouds, or sometimes on-premise services.
![Page 14: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/14.jpg)
IaaS & PaaS: Developer's Perspectives IaaS normally provides up to O/S level as your choice; for
example Amazon Web Services (AWS) offers several types of Operating Systems such as Windows Server, Linux SUSE, and Linux Red Hat. Developer need to install own middleware, database, etc.
PaaS, given that the database server, VM, and web server VM are readily provisioned,
![Page 15: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/15.jpg)
Setting Up App in IaaS
Source:http://acloudyplace.com/2012/01/comparing-iaas-and-paas-a-developers-perspective/
![Page 16: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/16.jpg)
Setting Up App in PaaS
Source:http://acloudyplace.com/2012/01/comparing-iaas-and-paas-a-developers-perspective/
![Page 17: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/17.jpg)
PaaS for JavaAmazon Elastic BeanstalkCloudBeesCloud FoundryGoogle App EngineHeroku for JavaRed Hat OpenShift
![Page 18: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/18.jpg)
PaaS for Java: Comparison
![Page 19: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/19.jpg)
PaaS for Java: Comparison
Source: http://www.infoq.com/articles/paas_comparison
![Page 20: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/20.jpg)
What is Google App Engine?
![Page 21: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/21.jpg)
Google App Engine : Definition (Wikipedia)
It is a platform for hosting web applications in Google-managed data centers. It is cloud computing
technology which virtualizes applications across multiple servers and data centers.
![Page 22: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/22.jpg)
Google App EngineRunning your web application in Google infrastructureSupport different runtime environmentsJava (JRE 6 with limitation, Servlet 2.5, JDO, JPA)Python (2.5.2)
Apps run in sandbox.Automatic scaling and load balancingNo server restart, no network issues
![Page 23: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/23.jpg)
Hosting Java web apps traditionallyNot so popular except enterpriseHigh rates as compared to PHP hostingShared Tomcat instance among usersRestrictions on any time deployments due to shared
serverDedicated hosts works fine but they are costly
![Page 24: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/24.jpg)
You end up with all this
![Page 25: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/25.jpg)
![Page 26: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/26.jpg)
Google Datacenters at Dallas, Oregon
![Page 27: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/27.jpg)
GAE Architecture
![Page 28: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/28.jpg)
GAE Physical Deployment Diagram
![Page 29: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/29.jpg)
Architecture : Application Server
![Page 30: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/30.jpg)
Distributed web hosting platform
![Page 31: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/31.jpg)
Distributed Datastore
![Page 32: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/32.jpg)
Distributed memcache
![Page 33: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/33.jpg)
Specialized services
![Page 34: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/34.jpg)
Google Apps + your apps
![Page 35: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/35.jpg)
Google App Engine for Java
![Page 36: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/36.jpg)
GAE/JWas released on April 08 with Python support. Java
included on August 09
![Page 37: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/37.jpg)
App Engine for Java : One Year
Source: What’s Hot in Java for App Engine Google Con 2010
![Page 38: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/38.jpg)
GAE Java Runtime EnvironmentJava 6 VMServlet 2.5 ContainerHTTP Session support (need to enable explicitly)JDO/JPA for Datastore APIJSR 107 for Memcache APIjavax.mail for Mail APIjavax.net.URLConnection for URLFetch API
![Page 39: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/39.jpg)
Java Standards on GAE
![Page 40: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/40.jpg)
Services by App EngineMemcache API – high performance in-memory key-value cacheDatastore – database storage and operationsURLFetch – invoking external URLsMail – sending mail from your applicationTask Queues – for invoking background processesImages – for image manipulation Cron Jobs – scheduled tasks on defined timeUser Accounts – using Google accounts for authentication
![Page 41: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/41.jpg)
LimitationsProgramming Model : Application runs in sandbox and
can notWrite to file systemMake arbitrary network connectionsUse multiple threads/processesPerform long-lasting processingPermissionsKnow about other instances/applications
Quotas (Requests, In/Out bandwidth, CPU time, API calls)
![Page 42: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/42.jpg)
GAE Datastore
![Page 43: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/43.jpg)
GAE Datastore
Storing data and manipulationBased on BigtableBigtable is proprietary and hidden from the app developers Not a relational database (No SQL)GQL (Google Query Language) to query Stores data as entitiesDistribution, replication, load balancing behind the scene Need to use JDO/JPA
![Page 44: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/44.jpg)
User Service : Google Accounts
Google Accounts are encouraged as the preferred authentication mechanism for App Engine– It assumes that all users have a Google Account – Google authentication for private domains isn’t available yet
Access to Google account data -> email, idThe Development Server simulates Google AccountsAccess constraints based on roles
![Page 45: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/45.jpg)
User API : Example
import com.google.appengine.api.users.*;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String navBar;
if (user == null) {
navBar = "<p>Welcome! <a href=\"" + userService.createLoginURL("/") +"\">Sign in or register</a> to customize.</p>";
} else {
navBar = "<p>Welcome, " + user.getEmail() + "! You can <a href=\"" +userService.createLogoutURL("/") +"\">sign out</a>.</p>";
}
import com.google.appengine.api.users.*;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String navBar;
if (user == null) {
navBar = "<p>Welcome! <a href=\"" + userService.createLoginURL("/") +"\">Sign in or register</a> to customize.</p>";
} else {
navBar = "<p>Welcome, " + user.getEmail() + "! You can <a href=\"" +userService.createLogoutURL("/") +"\">sign out</a>.</p>";
}
![Page 46: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/46.jpg)
URLFetch APIInvoking external URLs from your application over HTTP and
HTTPs import java.net.*;
import java.io.*;
URL url = new URL("htp://...");
InputStream inp = new InputStreamReader(url.openStream());
BufferedReader reader = new BufferedReader(inp);
String line;
while ((line = reader.readLine()) != null) {
//do something
}
reader.close();
import java.net.*;
import java.io.*;
URL url = new URL("htp://...");
InputStream inp = new InputStreamReader(url.openStream());
BufferedReader reader = new BufferedReader(inp);
String line;
while ((line = reader.readLine()) != null) {
//do something
}
reader.close();
![Page 47: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/47.jpg)
Mail APISend emails on the behalf of app administrator to the Google
account use.You can not receive emails import javax.mail.*;
Session session = Session.getDefaultInstance(new Properties(), null);
InternetAddress admins = new InternetAddress("admins");
Message msg = new MimeMessage(session);
msg.setFrom(admins);
msg.addRecipient(Message.RecipientType.TO, admins);
msg.setSubject("subject");
msg.setText("text");
Transport.send(msg);
import javax.mail.*;
Session session = Session.getDefaultInstance(new Properties(), null);
InternetAddress admins = new InternetAddress("admins");
Message msg = new MimeMessage(session);
msg.setFrom(admins);
msg.addRecipient(Message.RecipientType.TO, admins);
msg.setSubject("subject");
msg.setText("text");
Transport.send(msg);
![Page 48: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/48.jpg)
Memcache Service
Distributed in memory cache, better than DataStore Key-value pair mappingConfigurable expiration time butUnreliable might be vanished at any timeSupported Interfaces :– JACHE (JSR 107: JCACHE – Java Temporary Caching API)– The Low-Level Memcache API
![Page 49: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/49.jpg)
Memcache API : Example
import static java.util.Collections.emptyMap;
import javax.cache.*;
CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
Cache cache = cacheFactory.createCache(emptyMap());
cache.put(key, value);
cache.get(key);
import static java.util.Collections.emptyMap;
import javax.cache.*;
CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
Cache cache = cacheFactory.createCache(emptyMap());
cache.put(key, value);
cache.get(key);
![Page 50: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/50.jpg)
Task Queues APIPerform background processes by inserting tasks into queues.Instructions need to be mention in file queue.xml, in the WEB-INF/ dir
import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions;
// ...
TaskOptions taskOptions =
TaskOptions.Builder.url("/send_invitation_task")
.param("address", "[email protected]")
.param("firstname", "Juliet");
Queue queue = QueueFactory.getDefaultQueue();
queue.add(taskOptions);
import com.google.appengine.api.labs.taskqueue.Queue;
import com.google.appengine.api.labs.taskqueue.QueueFactory;
import com.google.appengine.api.labs.taskqueue.TaskOptions;
// ...
TaskOptions taskOptions =
TaskOptions.Builder.url("/send_invitation_task")
.param("address", "[email protected]")
.param("firstname", "Juliet");
Queue queue = QueueFactory.getDefaultQueue();
queue.add(taskOptions);
![Page 51: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/51.jpg)
Cron JobsUp to 20 scheduled tasks per appCron jobs (scheduled tasks) supported in cron.xml in WEB-INF dirSchedule instructions contain Englis-like format
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/listbooks</url>
<description>Repopulate the cache every day at
5am</description>
<schedule>every day 05:00</schedule>
</cron>
</cronentries>
<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
<cron>
<url>/listbooks</url>
<description>Repopulate the cache every day at
5am</description>
<schedule>every day 05:00</schedule>
</cron>
</cronentries>
![Page 52: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/52.jpg)
Images API
Manipulation of imagesTransformation of imagesChanging image formats
![Page 53: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/53.jpg)
GAE Development Cycle
![Page 54: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/54.jpg)
GAE Development Cycle
![Page 55: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/55.jpg)
Getting Started
The application owner must have a Google Account to get the tools regardless of language.
Use Java 6 for development.Eclipse and Netbeans have official plugins.Both SDKs ship with a Development Web Server that
runs locally and provides a sandbox almost identical to the real run-time.
![Page 56: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/56.jpg)
Software Development Kit
App Engine SDK– Includes web server (Jetty)–Emulates all the GAE services
SDK includes an upload tool to deploy app to GAECommand line tools included.
![Page 57: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/57.jpg)
Google Plugin for Eclipse
![Page 58: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/58.jpg)
Development Environment
Development ServerApplication lifecycle
managementEclipse/NetBeans plugins /
Firefox plugin (GWT).
![Page 59: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/59.jpg)
Google Plugin for Eclipse
![Page 60: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/60.jpg)
Development Server
http://localhost:8888
![Page 61: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/61.jpg)
Development Server Admin Console
http://localhost:8888/_ah/admin
![Page 62: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/62.jpg)
Deployment Environment
Application is deployed as .war which contains.Deployment is integrated in IDEDeploy multiple version of the application at the same
timeYour app lives at–<app_id>.appspot.com or–Custom domain with Google Apps
![Page 63: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/63.jpg)
Running your app on Google
http://<version>.<appid>.appspot.com/some/path
![Page 64: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/64.jpg)
Managing Applications
Administration Console http://appengine.google.com/a/yourdomain.comApplication DashboardMultiple application versionsAnalyzing log files (including admin)Analyzing resource usag
![Page 65: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/65.jpg)
GAE Dashboard
![Page 66: Google App Engine](https://reader033.vdocuments.site/reader033/viewer/2022060107/554c20ffb4c905e7568b5672/html5/thumbnails/66.jpg)
ResourcesGoogle App Engine at a glance, Stefan ChristophDeveloping Java Based Web Applications in Google App Engine, Tahir Akram, Dec. 2009Google App Engine, Patrick Chanezon, Mar 2010