java web programming on google cloud platform [1/3] : google app engine

Post on 29-May-2015

1.144 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

Java Web Programming on Google App Engine, July 2012

TRANSCRIPT

Google App Engine

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

www.imcinstitute.comJuly 2012

Agenda

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

What is Cloud Computing?

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.

Cloud computing characteristics

Massive, abstracted infrastructureDynamic allocation, scaling, movement of applicationsPay per useNo long-term commitmentsOS, application architecture independentNo hardware or software to install

Grid to Cloud Evolution

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

ISP to Cloud Evolution

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.

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

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.

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.

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,

Setting Up App in IaaS

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

Setting Up App in PaaS

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

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

PaaS for Java: Comparison

PaaS for Java: Comparison

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

What is 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.

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

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

You end up with all this

Google Datacenters at Dallas, Oregon

GAE Architecture

GAE Physical Deployment Diagram

Architecture : Application Server

Distributed web hosting platform

Distributed Datastore

Distributed memcache

Specialized services

Google Apps + your apps

Google App Engine for Java

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

included on August 09

App Engine for Java : One Year

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

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

Java Standards on GAE

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

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)

GAE Datastore

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

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

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>";

}

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();

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);

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

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);

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", "juliet@example.com")

.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", "juliet@example.com")

.param("firstname", "Juliet");

Queue queue = QueueFactory.getDefaultQueue();

queue.add(taskOptions);

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>

Images API

Manipulation of imagesTransformation of imagesChanging image formats

GAE Development Cycle

GAE Development Cycle

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.

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.

Google Plugin for Eclipse

Development Environment

Development ServerApplication lifecycle

managementEclipse/NetBeans plugins /

Firefox plugin (GWT).

Google Plugin for Eclipse

Development Server

http://localhost:8888

Development Server Admin Console

http://localhost:8888/_ah/admin

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

Running your app on Google

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

Managing Applications

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

GAE Dashboard

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

Thank you

thananum@gmail.comwww.facebook.com/imcinstitute

www.imcinstitute.com

top related