java web programming using cloud platform: module 10

72
Module 10: Java Cloud Platform Dr.Thanachart Numnonda Dr.Thanisa Kruawaisayawan www.imcinstitute.com 18-22 February 2013

Upload: imc-institute

Post on 15-Jan-2015

453 views

Category:

Technology


4 download

DESCRIPTION

Java Web Programming Using Cloud Platform Training 18-22 Feb 2013 Module 10: Google App Engine and Heroku

TRANSCRIPT

Page 1: Java Web Programming Using Cloud Platform: Module 10

Module 10: Java Cloud Platform

Dr.Thanachart Numnonda

Dr.Thanisa Kruawaisayawan

www.imcinstitute.com

18-22 February 2013

Page 2: Java Web Programming Using Cloud Platform: Module 10

2

Objectives

What is Cloud Computing?

What is Google App Engine? Google App Engine for Java Google App Engine Development cycle

Heroku Introduction

Page 3: Java Web Programming Using Cloud Platform: Module 10

3

What is Cloud Computing?

Page 4: Java Web Programming Using Cloud Platform: Module 10

4

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 Using Cloud Platform: Module 10

5

Cloud Computing Characteristics

Massive, abstracted infrastructure Dynamic allocation, scaling, movement of

applications Pay per use No long-term commitments OS, application architecture independent No hardware or software to install

Page 6: Java Web Programming Using Cloud Platform: Module 10

6

Grid to Cloud Evolution

Page 7: Java Web Programming Using Cloud Platform: Module 10

7

Web 2.0 & Cloud Computing

Web 2.0 concentrates on the private user and clouds are decscendents of data centers which services the enterprise.

Web 2.0 promotes SaaS. Web 2.0 needs massive scaling technologies. User centric Web 2.0 companies (Twitter,

Slideshare) are relying on Cloud Services.

Page 8: Java Web Programming Using Cloud Platform: Module 10

8

ISP to Cloud Evolution

Page 9: Java Web Programming Using Cloud Platform: Module 10

9

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 Using Cloud Platform: Module 10

10

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 Using Cloud Platform: Module 10

11

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 Using Cloud Platform: Module 10

12

Page 13: Java Web Programming Using Cloud Platform: Module 10

13

Deployment Model

Public 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 Using Cloud Platform: Module 10

14

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 Using Cloud Platform: Module 10

15

Setting Up App in IaaS

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

Page 16: Java Web Programming Using Cloud Platform: Module 10

16

Setting Up App in PaaS

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

Page 17: Java Web Programming Using Cloud Platform: Module 10

17

PaaS for Java

Amazon Elastic Beanstalk CloudBees Cloud Foundry Google App Engine Heroku for Java Red Hat OpenShift

Page 18: Java Web Programming Using Cloud Platform: Module 10

18

PaaS for Java: Comparison

Page 19: Java Web Programming Using Cloud Platform: Module 10

19

PaaS for Java: Comparison

Page 20: Java Web Programming Using Cloud Platform: Module 10

20

What is Google App Engine?

Page 21: Java Web Programming Using Cloud Platform: Module 10

21

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 Using Cloud Platform: Module 10

22

Google App Engine

Running your web application in Google infrastructure

Support different runtime environments Java (JRE 6 with limitation, Servlet 2.5, JDO,

JPA) Python (2.5.2) Apps run in sandbox. Automatic scaling and load balancing No server restart, no network issues

Page 23: Java Web Programming Using Cloud Platform: Module 10

23

Hosting Java web apps traditionally

Not so popular except enterprise High rates as compared to PHP hosting Shared Tomcat instance among users Restrictions on any time deployments due to

shared server Dedicated hosts works fine but they are costly

Page 24: Java Web Programming Using Cloud Platform: Module 10

24

You end up with all this

Page 25: Java Web Programming Using Cloud Platform: Module 10

25

Page 26: Java Web Programming Using Cloud Platform: Module 10

26

Google Datacenters at Dallas, Oregon

Page 27: Java Web Programming Using Cloud Platform: Module 10

27

GAE Architecture

Page 28: Java Web Programming Using Cloud Platform: Module 10

28

GAE Physical Deployment Diagram

Page 29: Java Web Programming Using Cloud Platform: Module 10

29

Architecture : Application Server

Page 30: Java Web Programming Using Cloud Platform: Module 10

30

Distributed web hosting platform

Page 31: Java Web Programming Using Cloud Platform: Module 10

31

Distributed Datastore

Page 32: Java Web Programming Using Cloud Platform: Module 10

32

Distributed memcache

Page 33: Java Web Programming Using Cloud Platform: Module 10

33

Specialized services

Page 34: Java Web Programming Using Cloud Platform: Module 10

34

Google Apps + your apps

Page 35: Java Web Programming Using Cloud Platform: Module 10

35

Google App Engine for Java

Page 36: Java Web Programming Using Cloud Platform: Module 10

36

GAE/J

Was released on April 08 with Python support. Java included on August 09

Page 37: Java Web Programming Using Cloud Platform: Module 10

37

App Engine for Java : One Year

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

Page 38: Java Web Programming Using Cloud Platform: Module 10

38

GAE Java Runtime Environment

Java 6 VM Servlet 2.5 Container HTTP Session support (need to enable explicitly) JDO/JPA for Datastore API JSR 107 for Memcache API javax.mail for Mail API javax.net.URLConnection for URLFetch API

Page 39: Java Web Programming Using Cloud Platform: Module 10

39

Java Standards on GAE

Page 40: Java Web Programming Using Cloud Platform: Module 10

40

Services by App Engine

Memcache API – high performance in-memory key-value cache

Datastore – database storage and operations URLFetch – invoking external URLs Mail – sending mail from your application Task Queues – for invoking background processes Images – for image manipulation Cron Jobs – scheduled tasks on defined time User Accounts – using Google accounts for

authentication

Page 41: Java Web Programming Using Cloud Platform: Module 10

41

Limitations

Programming Model : Application runs in sandbox and can not– Write to file system

– Make arbitrary network connections

– Use multiple threads/processes

– Perform long-lasting processing

– Permissions

– Know about other instances/applications Quotas (Requests, In/Out bandwidth, CPU time,

API calls)

Page 42: Java Web Programming Using Cloud Platform: Module 10

42

GAE Datastore

Page 43: Java Web Programming Using Cloud Platform: Module 10

43

GAE Datastore

Storing data and manipulation Based on Bigtable Bigtable is proprietary and hidden from the app

developers Not a relational database (No SQL) GQL (Google Query Language) to query Stores data as entities Distribution, replication, load balancing behind

the scene Need to use JDO/JPA

Page 44: Java Web Programming Using Cloud Platform: Module 10

44

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, id The Development Server simulates Google

Accounts Access constraints based on roles

Page 45: Java Web Programming Using Cloud Platform: Module 10

45

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 Using Cloud Platform: Module 10

46

URLFetch API

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

Invoking external URLs from your application over HTTP and HTTPs

Page 47: Java Web Programming Using Cloud Platform: Module 10

47

Mail API Send 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 Using Cloud Platform: Module 10

48

Memcache Service

Distributed in memory cache, better than DataStore

Key-value pair mapping Configurable expiration time but Unreliable might be vanished at any time Supported Interfaces :

– JACHE (JSR 107: JCACHE – Java Temporary Caching API)

– The Low-Level Memcache API

Page 49: Java Web Programming Using Cloud Platform: Module 10

49

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 Using Cloud Platform: Module 10

50

Task Queues API Perform 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 Using Cloud Platform: Module 10

51

Cron Jobs Up to 20 scheduled tasks per app Cron jobs (scheduled tasks) supported in cron.xml

in WEB-INF dir Schedule 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 Using Cloud Platform: Module 10

52

Images API

Manipulation of images

Transformation of images

Changing image formats

Page 53: Java Web Programming Using Cloud Platform: Module 10

53

GAE Development Cycle

Page 54: Java Web Programming Using Cloud Platform: Module 10

54

GAE Development Cycle

Page 55: Java Web Programming Using Cloud Platform: Module 10

55

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 Using Cloud Platform: Module 10

56

Software Development Kit

App Engine SDK

– Includes web server (Jetty)– Emulates all the GAE services

SDK includes an upload tool to deploy app to GAE

Command line tools included.

Page 57: Java Web Programming Using Cloud Platform: Module 10

57

Google Plugin for Eclipse

Page 58: Java Web Programming Using Cloud Platform: Module 10

58

Development Environment

Development Server Application lifecycle

management Eclipse/NetBeans

plugins /

Firefox plugin (GWT)

Page 59: Java Web Programming Using Cloud Platform: Module 10

59

Google Plugin for Eclipse

Page 60: Java Web Programming Using Cloud Platform: Module 10

60

Development Server

http://localhost:8888

Page 61: Java Web Programming Using Cloud Platform: Module 10

61

Development Server Admin Consolehttp://localhost:8888/_ah/admin

Page 62: Java Web Programming Using Cloud Platform: Module 10

62

Deployment Environment

Application is deployed as .war which contains. Deployment is integrated in IDE Deploy multiple version of the application at the

same time Your app lives at

– <app_id>.appspot.com or– Custom domain with Google Apps

Page 63: Java Web Programming Using Cloud Platform: Module 10

63

Running your app on Google

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

Page 64: Java Web Programming Using Cloud Platform: Module 10

64

Managing Applications

Administration Console

http://appengine.google.com/a/yourdomain.com Application Dashboard Multiple application versions Analyzing log files (including admin) Analyzing resource usage

Page 65: Java Web Programming Using Cloud Platform: Module 10

65

GAE Dashboard

Page 66: Java Web Programming Using Cloud Platform: Module 10

66

Page 67: Java Web Programming Using Cloud Platform: Module 10

67

Heroku

Platform as a Service for professional apps developers

Forget servers Run anything See everything Trust & Managed

Page 68: Java Web Programming Using Cloud Platform: Module 10

68

Forget Servers

Agile deployment for Ruby, Node.js, Clojure, Java, Python, and Scala.

Page 69: Java Web Programming Using Cloud Platform: Module 10

69

Page 70: Java Web Programming Using Cloud Platform: Module 10

70

Page 71: Java Web Programming Using Cloud Platform: Module 10

71

Resources

Google App Engine at a glance, Stefan Christoph Developing Java Based Web Applications in Google App Engine, Tahir Akram, Dec. 2009 Google App Engine, Patrick Chanezon, Mar 2010

Page 72: Java Web Programming Using Cloud Platform: Module 10

72

Thank you

[email protected]

www.facebook.com/imcinstitute

www.imcinstitute.com