67
Google App Engine Assoc.Prof. Dr.Thanachart Numnonda Asst.Prof. Thanisa Kruawaisayawan www.imcinstitute.com July 2012

Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Embed Size (px)

DESCRIPTION

Java Web Programming on Google App Engine, July 2012

Citation preview

Page 1: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google App Engine

Assoc.Prof. Dr.Thanachart NumnondaAsst.Prof. Thanisa Kruawaisayawan

www.imcinstitute.comJuly 2012

Page 2: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Agenda

What is Cloud Computing?What is Google App Engine?Google App Engine for JavaGoogle App Engine Development cycle

Page 3: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

What is Cloud Computing?

Page 4: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Grid to Cloud Evolution

Page 7: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

ISP to Cloud Evolution

Page 9: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
Page 13: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Setting Up App in IaaS

Source:http://acloudyplace.com/2012/01/comparing-iaas-and-paas-a-developers-perspective/

Page 16: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Setting Up App in PaaS

Source:http://acloudyplace.com/2012/01/comparing-iaas-and-paas-a-developers-perspective/

Page 17: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

PaaS for JavaAmazon Elastic BeanstalkCloudBeesCloud FoundryGoogle App EngineHeroku for JavaRed Hat OpenShift

Page 18: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

PaaS for Java: Comparison

Page 19: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

PaaS for Java: Comparison

Source: http://www.infoq.com/articles/paas_comparison

Page 20: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

What is Google App Engine?

Page 21: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

You end up with all this

Page 25: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine
Page 26: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google Datacenters at Dallas, Oregon

Page 27: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Architecture

Page 28: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Physical Deployment Diagram

Page 29: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Architecture : Application Server

Page 30: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Distributed web hosting platform

Page 31: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Distributed Datastore

Page 32: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Distributed memcache

Page 33: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Specialized services

Page 34: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google Apps + your apps

Page 35: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google App Engine for Java

Page 36: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE/JWas released on April 08 with Python support. Java

included on August 09

Page 37: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

App Engine for Java : One Year

Source: What’s Hot in Java for App Engine Google Con 2010

Page 38: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Java Standards on GAE

Page 40: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Datastore

Page 43: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Images API

Manipulation of imagesTransformation of imagesChanging image formats

Page 53: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Development Cycle

Page 54: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Development Cycle

Page 55: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google Plugin for Eclipse

Page 58: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Development Environment

Development ServerApplication lifecycle

managementEclipse/NetBeans plugins /

Firefox plugin (GWT).

Page 59: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Google Plugin for Eclipse

Page 60: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Development Server

http://localhost:8888

Page 61: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Development Server Admin Console

http://localhost:8888/_ah/admin

Page 62: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Running your app on Google

http://<version>.<appid>.appspot.com/some/path

Page 64: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Managing Applications

Administration Console http://appengine.google.com/a/yourdomain.comApplication DashboardMultiple application versionsAnalyzing log files (including admin)Analyzing resource usag

Page 65: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

GAE Dashboard

Page 66: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

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

Page 67: Java Web Programming on Google Cloud Platform [1/3] : Google App Engine

Thank you

[email protected]/imcinstitute

www.imcinstitute.com