google app engine

22
Google App engine Senthilkumar M Copyright@share2create License 1

Upload: senthilkumar-murugesan

Post on 08-May-2015

322 views

Category:

Career


0 download

TRANSCRIPT

Page 1: Google app engine

Copyright@share2create License 1

Google App engine

Senthilkumar M

Page 2: Google app engine

Copyright@share2create License 2

What is Google App Engine?

• Google App Engine is a complete development stack that uses familiar technologies to build and host applications on the same infrastructure used at Google.

Page 3: Google app engine

Copyright@share2create License 3

Four runtime environments

Python

Java GO

PHP

Page 4: Google app engine

Copyright@share2create License 4

Your code runs in a sandbox

• Secure environment that provides limited access to the underlying operating system.

• The sandbox allows App Engine to• distribute web requests across multiple servers• start and stop servers to meet traffic demands• isolate apps in a secure, reliable environment• abstract hardware, operating system and

physical location of the web server

Page 5: Google app engine

Copyright@share2create License 5

Sandbox limitations

• outbound connections: only through the provided URL fetch and email services or the experimental Socket API.

• inbound connections: only HTTP(s) on ports 80/443.• File system access: writing files is not allowed. An application

can read only files uploaded with the application code.• no native code: libraries that depend on native code are

generally not available.• time limits: app code must terminate within given time

limits. (60s for web requests, 10m for tasks but unlimited time for backend jobs)

Page 6: Google app engine

Copyright@share2create License 6

Storing data

•Three options for data storage

App Engine Data store Google Cloud SQL Google Cloud Storage

NoSQL schemeless data storage built in GAE

relational SQL database service based on MySQL file based storage

Page 7: Google app engine

Copyright@share2create License 7

What special in host on GAE

• No fixed cost pay only on what you use• FREE!!!!• Your APP running on the platform which

powers Google service.• App can be scalable to any extend.

Page 8: Google app engine

Copyright@share2create License 8

Lets Run your First App

• Download the SDK• Go to

https://developers.google.com/appengine/downloads and grab the Python installer.

• Download Python 2.7 installer.• Go tohttp://www.python.org/download/releases/2.7/

Page 9: Google app engine

Copyright@share2create License 9

Startup the Launcher

Page 10: Google app engine

Copyright@share2create License 10

Create a Sample Application

Page 11: Google app engine

Copyright@share2create License 11

Lets write your first code

• App.yaml => It is configuration file for your application

Page 12: Google app engine

Copyright@share2create License 12

Main.py

#!/usr/bin/env python

import webapp2

class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello world!')

app = webapp2.WSGIApplication([ ('/', MainHandler)], debug=True)

Page 13: Google app engine

Copyright@share2create License 13

Datastore(s)

• There are two implementations of datastore• The original one is implemented

in google.appengine.ext.db• The new one is called NDB and it is

implemented in google.appengine.ext.ndb• They are very similar but not identical• We will cover NDB

Page 14: Google app engine

Copyright@share2create License 14

Creating Data store Entity

from google.appengine.ext import ndbclass Contact(ndb.Model): name = ndb.StringProperty() email = ndb.StringProperty() birth_date = ndb.DateProperty()

Page 15: Google app engine

Copyright@share2create License 15

Querying the Data store

from google.appengine.ext import ndb

def StoresByCity(city, limit): query = Store.query(Store.city == city).order(Store.name) return query.fetch(limit, projection=[Store.name, Store.address])

• The Data store API is Object Oriented.• Queries are objects• Filters and projections are specified by calling methods• Make sure you know the limits!

Page 16: Google app engine

Copyright@share2create License 16

Querying the Data store with GQL

from google.appengine.ext import ndb

def query_info(): qry = ndb.gql("SELECT * FROM Account WHERE balance < :1", 100) return qry

• You can write queries with GQL, a SQL-like language.• GQL is translated to NDB's native query API. (This is the

opposite of what traditional ORM libraries do!)

Page 17: Google app engine

Copyright@share2create License 17

View templates

<html> <body> {% for contact in contacts %} {% if contact.name %} <b>{{ contact.name }}</b> {% else %} Unnamed contact {% endif %} <{{ contact.email }}> {% endfor %} <a href="{{ url }}">{{ url_linktext }}</a> </body> </html>

If you use webapp2, Django Templates are supported by default.

Page 18: Google app engine

Copyright@share2create License 18

Dispatch to view templates

def render_template(self, view_filename, params=None) if not params: params = {} path = os.path.join(os.path.dirname(__file__), 'views', view_filename) self.response.out.write(template.render(path, params)):

Here is how to render a template in with webapp2

Page 19: Google app engine

Copyright@share2create License 19

Memcache

from google.appengine.api import memcache def get_data(): data = memcache.get('key') if data is not None: return data else: data = self.query_for_data() memcache.add('key', data, 60) return data

• Memcache is a high-performance, distributed memory object caching system.

• Can be used to minimize hits to the Datastore or to save transient state information.

Page 20: Google app engine

Copyright@share2create License 20

My sample host apps

• Check out this links• http://senonscreen.appspot.com/• http://me2mentor.appspot.com/• http://sentengo.appspot.com/

Page 21: Google app engine

Copyright@share2create License 21

Questions?

Page 22: Google app engine

Copyright@share2create License 22