Prof. A.R. Rele

cabbagewheatInternet και Εφαρμογές Web

13 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

61 εμφανίσεις

Prof. A.R.
Rele

What Is Google App Engine?



Google

App

Engine

lets

users

run

web

applications

on

Google's

infrastructure
.



App

Engine

applications

are

easy

to

build,

easy

to

maintain,

and

easy

to

scale

as

your

traffic

and

data

storage

needs

grow
.



With

App

Engine,

there

are

no

servers

to

maintain
:

Users

just

need

to

upload

your

application,

and

it's

ready

to

serve

other

users
.


Users

can

serve

your

app

from

your

own

domain

name

(such

as

http
:
//www
.
example
.
com/)

using

Google

Apps
.

Or,

you

can

serve

your

app

using

a

free

name

on

the

appspot
.
com

domain
.

You

can

share

your

application

with

the

world,

or

limit

access

to

members

of

your

organization
.


Google App Engine supports apps written in several programming languages. With App
Engine's

Java runtime environment, you can build your app using standard Java
technologies, including the JVM, Java
servlets
, and the Java programming language

or
any other language using a JVM
-
based interpreter or compiler, such as JavaScript or Ruby.


App
Engine also features two dedicated

Python runtime environments, each of which
includes a fast Python interpreter and the Python standard library.


Finally
, App Engine provides a

Go runtime environment

that runs natively compiled Go
code. These runtime environments are built to ensure that your application runs quickly,
securely, and without interference from other apps on the system
.


App Engine costs nothing to get started. All applications can use up to 1 GB of storage
and enough CPU and bandwidth to support an efficient app serving around 5 million
page views a month, absolutely free. When you enable billing for your application, your
free limits are raised, and you only pay for resources you use above the free levels.

The Application Environment



Google
App Engine makes it easy to build an application that runs reliably,
even under heavy load and with large amounts of data. App Engine includes
the following features:


dynamic web serving, with full support for common web technologies


persistent storage with queries, sorting and transactions


automatic scaling and load balancing


APIs for authenticating users and sending email using Google Accounts


a fully featured local development environment that simulates Google App
Engine on your computer


task queues for performing work outside of the scope of a web request


scheduled tasks for triggering events at specified times and regular
intervals



Your
application can run in one of three runtime environments:
the

Go

environment, the

Java

environment, and
the

Python

environment


The Sandbox



Applications
run in a secure environment that
provides limited access to the underlying operating
system.


These
limitations allow App Engine to distribute web
requests for the application across multiple servers,
and start and stop servers to meet traffic demands.


The
sandbox isolates your application in its own
secure, reliable environment that is independent of
the hardware, operating system and physical location
of the web server.


The Java Runtime Environment



You
can develop your application for the Java runtime environment using
common Java web development tools and API standards. Your app interacts
with the environment using

the Java
Servlet

standard, and can use common
web application technologies such as

JavaServer

Pages

(JSPs).


The Java runtime environment uses Java 6. The App Engine Java SDK supports
developing apps using either Java 5 or 6.


The environment includes the

Java SE Runtime Environment (JRE) 6
platform

and libraries. The restrictions of the sandbox environment are
implemented in the JVM. An app can use any JVM
bytecode

or library feature,
as long as it does not exceed the sandbox restrictions.


Your app accesses most App Engine services using Java standard APIs. For the
App Engine
datastore
, the Java SDK includes implementations of the

Java Data
Objects

(JDO) and

Java Persistence API

(JPA) interfaces.


Your
app can use

the
JavaMail

API

to send email messages with the App Engine
Mail service. Thejava.net

HTTP APIs access the App Engine URL fetch service.


Storing Your Data



The
App Engine environment provides a range of
options for storing your data:


App Engine
Datastore

provides a
NoSQL

schemaless

object
datastore
, with a query engine and atomic
transactions.


Google Cloud SQL

provides a relational SQL
database service for your App Engine application,
based on the familiar
MySQL

RDBMS.


Google Cloud Storage

provides a storage service for
objects and files up to terabytes in size, accessible
from

Python

and

Java

applications.


The Data Store


App Engine provides a distributed
NoSQL

data storage service that features a query
engine and transactions. Just as the distributed web server grows with your traffic, the
distributed
datastore

grows with your data.


The App Engine
datastore

is not like a traditional relational database. Data objects, or
"entities," have a kind and a set of properties. Queries can retrieve entities of a given kind
filtered and sorted by the values of the properties. Property values can be of any of the
supported

property value types.


Datastore

entities are "
schemaless
." The structure of data entities is provided by and
enforced by your application code.


The
Java JDO/JPA interfaces and the Python
datastore

interface include features for
applying and enforcing structure within your app. Your app can also access the
datastore

directly to apply as much or as little structure as it needs.


The
datastore

is strongly

consistent

and uses

optimistic concurrency control. An update
of a entity occurs in a transaction that is retried a fixed number of times if other
processes are trying to update the same entity simultaneously. Your application can
execute multiple
datastore

operations in a single transaction which either all succeed or
all fail, ensuring the integrity of your data.


The
datastore

implements transactions across its distributed network using "entity
groups." A transaction manipulates entities within a single group. Entities of the same
group are stored together for efficient execution of transactions. Your application can
assign entities to groups when the entities are created


App Engine Services



App
Engine provides a variety of services that enable you to perform common operations when
managing your application. The following APIs are provided to access these services
:


URL Fetch


Applications can access resources on the Internet, such as web services or other data, using App
Engine's URL fetch service. The URL fetch service retrieves web resources using the same high
-
speed
Google infrastructure that retrieves web pages for many other Google products
.


Mail


Applications can send email messages using App Engine's mail service. The mail service uses Google
infrastructure to send email messages
.


Memcache


The
Memcache

service provides your application with a high performance in
-
memory key
-
value
cache that is accessible by multiple instances of your application.
Memcache

is useful for data that
does not need the persistence and transactional features of the
datastore
, such as temporary data or
data copied from the
datastore

to the cache for high speed access
.


Image
Manipulation


The
Image service lets your application manipulate images. With this API, you can resize, crop, rotate
and flip images in JPEG and PNG formats.


Development Workflow



The App Engine software development kits

(SDKs) for Java, Python,
and Go each include a web server application that emulates all of the
App Engine services on your local computer.


Each
SDK includes all of the APIs and libraries available on App
Engine. The web server also simulates the secure sandbox environment,
including checks for attempts to access system resources disallowed in
the App Engine runtime environment.


Each SDK also includes a tool to upload your application to App
Engine. Once you have created your application's code, static files and
configuration files, you run the tool to upload the data. The tool
prompts you for your Google account email address and password.


When you build a new major release of an application that is already
running on App Engine, you can upload the new release as a new
version. The old version will continue to serve users until you switch to
the new version. You can test the new version on App Engine while the
old version is still running.


Java SDK



You develop and upload Java applications for
Google App Engine using the App Engine Java
software development kit (SDK
).



The SDK includes software for a web server that
you can run on your own computer to test your
Java applications. The server simulates all of the
App Engine services, including a local version of
the
datastore
, Google Accounts, and the ability to
fetch URLs and send email from your computer
using the App Engine APIs
.


Trying a Demo Application



The App Engine Java SDK includes several demo
applications in the

demos/

directory. The final version of
the guest book application you will create in this tutorial is
included under the directory

guestbook/.



Start
the guest book demo in the development server by
running the following command at a command prompt:


appengine
-
java
-
sdk
\
bin
\
dev_appserver.cmd
appengine
-
java
-
sdk
\
demos
\
guestbook
\
war


The development server starts, and listens for requests on
port 8080. Visit the following URL in your browser:


http
://localhost:8080/


Creating a Project



App Engine Java applications use

the Java
Servlet

standard

for interacting with the web server
environment.


An
application's files, including compiled classes,
JARs, static files and configuration files, are arranged
in a directory structure using the

WAR

standard layout
for Java web applications.

The Project Directory



We
will use a single directory
named

Guestbook/

for
all project files
.



A subdirectory named

src
/

contains the Java source
code, and a subdirectory named

war/

contains the
complete application arranged in the WAR format.


Our
build process compiles the Java source files and
puts the compiled classes in the appropriate location
in

war
/.


The Project Directory



The complete project directory looks like this
:



Guestbook
/


src
/
...Java source code...



META
-
INF
/
...other configuration...



war
/
...JSPs, images, data files...



WEB
-
INF
/
...app configuration...



lib
/
...JARs for libraries...



classes
/
...compiled classes...

The
Servlet

Class



App Engine Java applications use

the Java
Servlet

API

to interact with the web server. An HTTP
servlet

is
an application class that can process and respond to
web requests
.


Our guest book project begins with one
servlet

class, a
simple
servlet

that displays a
message


create the directories for the path

src
/guestbook/, then
create the
servlet

class file described below.



In the directory

src
/guestbook/, make a file named
GuestbookServlet.java with the following contents:


package
guestbook;


import
java.io.IOException
;

import
javax.servlet.http
.*;


public class
GuestbookServlet

extends
HttpServlet

{





public void
doGet
(
HttpServletRequest

req
,
HttpServletResponse

resp
)













throws
IOException

{









resp.setContentType
("text/plain");









resp.getWriter
().
println
("Hello, world");





}

}

The web.xml File



When the web server receives a request, it determines
which
servlet

class to call using a configuration file
known as the "web application deployment
descriptor."


This
file is named

web.xml, and resides in
the

war/WEB
-
INF/

directory in the WAR.

WEB
-
INF/

and

web.xml

are part of the
servlet

specification.


In the directory

war/WEB
-
INF/, a file
named

web.xml

has the following contents:



<?xml version="1.0" encoding="utf
-
8"?>

<!DOCTYPE web
-
app PUBLIC


"
-
//Oracle Corporation//DTD Web Application 2.3//EN"


"http://java.sun.com/dtd/web
-
app_2_3.dtd">


<web
-
app
xmlns
="http://java.sun.com/xml/ns/javaee"
version="2.5">





<
servlet
>









<
servlet
-
name>guestbook</
servlet
-
name>









<
servlet
-
class>
guestbook.GuestbookServlet
</
servlet
-
class>





</
servlet
>





<
servlet
-
mapping>









<
servlet
-
name>guestbook</
servlet
-
name>









<
url
-
pattern>/guestbook</
url
-
pattern>





</
servlet
-
mapping>





<welcome
-
file
-
list>









<welcome
-
file>index.html</welcome
-
file>





</welcome
-
file
-
list>

</web
-
app>

The appengine
-
web.xml File



App Engine needs one additional configuration file to
figure out how to deploy and run the application.


This
file is named

appengine
-
web.xml, and resides
in

WEB
-
INF/

alongside

web.xml. It includes the
registered ID of your application (Eclipse creates this
with an empty ID for you to fill in later), the version
number of your application, and lists of files that
ought to be treated as static files (such as images and
CSS) and resource files (such as JSPs and other
application data).



<?
xml version="1.0" encoding="utf
-
8"?>

<
appengine
-
web
-
app
xmlns
="http://appengine.google.com/ns/1.0">





<application></application>





<version>1</version>

</
appengine
-
web
-
app>

In the directory

war/WEB
-
INF/, a file named

appengine
-
web.xml

has the
following contents:

Running and Testing the
Application


The App Engine SDK includes a web server application
you can use to test your application. The server
simulates the App Engine environment and services,
including sandbox restrictions, the
datastore
, and the
services
.



http://localhost:8080/guestbook



Registering the Application



You
create and manage App Engine web applications from the App Engine
Administration Console, at the following URL:

https
://appengine.google.com
/



Sign in to App Engine using your Google account.



To create a new application, click the "Create an Application" button. Follow
the instructions to register an application ID, a name unique to this
application
.



Edit the

appengine
-
web.xml

file, then change the value of
the

<application>

element to be your registered application ID
.



You
should probably elect to use the free appspot.com domain name, and so
the full URL for the application will behttp://
your_app_id
.appspot.com
/


Uploading Your Application



You create and manage applications in App Engine
using the Administration Console. Once you have
registered an application ID for your application, you
upload it to App Engine using either the Eclipse
plugin
, or a command
-
line tool in the SDK.

Uploading Using the Command
Prompt



You
can upload your application code and files using a
command included in the SDK
named

appcfg.cmd

(Windows
)


AppCfg

is a multi
-
purpose tool for interacting with
your app on App Engine. The command takes the
name of an action, the path to your
app's

war/

directory, and other options.


To
upload the app, using Windows:


..
\
appengine
-
java
-
sdk
\
bin
\
appcfg.cmd
update

Accessing Your Application



You
can now see your application running on App
Engine. If you set up a free appspot.com domain name,
the URL for your website begins with your application
ID
:


http://
your_app_id
.appspot.com/