Introduction to Google App Engine
Upcoming SlideShare
Loading in...5
×
 

Introduction to Google App Engine

on

  • 4,739 views

Slides of a talk I gave on the 22nd of May for the first event of the Catania Google Technology Users Group....

Slides of a talk I gave on the 22nd of May for the first event of the Catania Google Technology Users Group.

The talk is about Google App Engine, and it's a very basic introduction to this platform. In the last part I present a toy example based on Google App Engine.

Statistics

Views

Total Views
4,739
Views on SlideShare
4,660
Embed Views
79

Actions

Likes
6
Downloads
239
Comments
0

3 Embeds 79

http://www.slideshare.net 61
http://www.linkedin.com 15
https://www.linkedin.com 3

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Introduction to Google App Engine Introduction to Google App Engine Presentation Transcript

  • Introduction to Google App Engine Andrea Spadaccini - @lupino3 May 22nd, 2010 - Catania – Italy [email_address]
  • Agenda Overview Developing applications with Google App Engine Toy example Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Overview
  • What is GAE? Google App Engine (GAE) is a service, offered by Google, that allows developers to build applications that can run on Google's infrastructure. It is a form of Cloud Computing. Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Cloud computing Abstraction of details like hardware configuration, physical location of data, operating system. Internet-based computing. Cloud : metaphor inspired by the drawing used to represent the Internet (and, earlier, the PSTN) in network diagrams Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Cloud computing Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Traditional client/server paradigm Client N Client 1 Server Internet
  • Cloud computing Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Cloud Computing Client N Client 1 Internet Server Server Server
  • Cloud layers Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Software as a Service Platform as a Service Infrastructure as a Service HW / Net IaaS Paas SaaS
  • Cloud layers Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Software as a Service Platform as a Service Infrastructure as a Service HW / Net IaaS Paas SaaS
  • GAE Features Run dynamic web applications (request / response) Serve static files Data storage (BigTable) Google infrastructure -> scalability, efficiency Additional features (mail, XMPP, Google Accounts, cron, WebServices, memcache, image manip.) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • App Engine datastore The App Engine Datastore is a distributed efficient storage designed for web applications. Entity : data object to be stored. Contains attributes and is identified by a key . Queries must be run against indexes . It's not a relational DB. There are no joins (or aggregate queries like count(*)). The schema is enforced by the application, not by the database. Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Developing applications with Google App Engine
  • Getting started
      Register an account at http://www.appspot.com You will be able to create up to 10 GAE apps (each with its http:// app-id .appspot.com URL) Download the GAE SDK (Linux, MacOSX, Win)
    Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine … which SDK?
  • Which language? Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Frame taken from Matrix (1999)
  • Which language? Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Which language? Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Hello world! # helloworld.py print “Content-Type: text/html” print print “Hello world” # app.yaml application : gtugct-helloworld version : 1 runtime : python api-version : 1 handlers : - uri : /.* script : helloworld.py Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Taken from App Engine Intro – see References
  • The GAE dev cycle 10 Develop - <your favourite tools here> (hint: ViM) 20 Test - dev_appserver.py 30 Deploy - appcfg.py 40 Repeat - GOTO 10 Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine With the Python SDK
  • Paradigm and features Request / response (max 30 seconds!) URL ↔ script mapping Web Frameworks: GAE comes with webapp , a Web Framework developed by Google. You can use Django (but not its ORM!). Web-based administration console Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Toy Example
  • Answr It! Answr.it by Vanni Rizzo, Pierluigi D'Antrassi, Andrea Spadaccini - http://www.answr.it Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Data modeling (I) # models.py from google.appengine.ext import db class Answr(db.Model): text = db.StringProperty() rand = db.FloatProperty() def to_json(self): return '{&quot;text&quot; : &quot;%s&quot;}' % self.text @staticmethod def get_random(): def add_answr(answr_text, rand = None): Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Data modeling (II) # models.py (continued) class ApplicationData(db.Model): name = db.StringProperty() value = db.IntegerProperty() @staticmethod def getAnswrCounter(): def incrementAnswrCounter(): ... Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Main page code from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from models import Answr class AnswrApp(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'application/json' random_answr = Answr.get_random() self.response.out.write(random_answr.to_json()) application = webapp.WSGIApplication([('/answr', AnswrApp)], debug = True) if __name__ == '__main__': run_wsgi_app(application) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • app.yaml application: answr-it version: 10 runtime: python api_version: 1 handlers: - url: /answr script: main.py - url: / static_files: static/index.html upload: static/index.html - url: /css (same for /img e /js) static_dir: static/css Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Users API from models import Answr from google.appengine.api import users [.. omissis ..] class PopulatePage(webapp.RequestHandler): def get(self): user = users.get_current_user() if not user: print &quot;<a href = '%s'>Log in with your Google Account</a>&quot; % users.create_login_url(self.request.path) elif users.is_current_user_admin(): print &quot;Populating the DB...&quot; answrs = [ .. omissis .. ] for answr_text in answrs: Answr.add_answr(answr_text) Answr.add_answr(&quot;Something strange is going on..&quot;, 1.0) else : logging.warning('Unauthorized access to /populate') Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Live demo http://answr-it.appspot.com .. or .. http://www.answr.it Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Twitter bot (cron + WS) # twitterbot.py import tweepy from models import ApplicationData, Answr # 1. Login auth = tweepy.BasicAuthHandler(&quot;answrit&quot;, &quot;the_password&quot;) api = tweepy.API(auth) logging.info('Login done!') # 2. Follow back who follows me followers = api.followers() friends = api.friends() to_follow = [x for x in followers if x not in friends] for user in to_follow: try : user.follow() except tweepy.TweepError, e: logging.warning(e) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Twitter bot (cron + WS) # twitterbot.py (cont.) # 3. Read last mentions last_id = ApplicationData.getLastAnswredTweetId() if not last_id: mentions = api.mentions(count = 200) else : mentions = api.mentions(count = 200, since_id = last_id) # 4. Random answr for status in mentions: answr = Answr.get_random() api.update_status(&quot;@%s %s&quot; % (status.author.screen_name, answr.text), status.id) if status.id > last_id: last_id = status.id # 5. Save the last ID if last_id: ApplicationData.setLastAnswredTweetId(last_id) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Twitter bot (cron + WS) # cron.yaml cron: - description: answr to people url: /twitterbot schedule: every 1 mins # (part of) app.yaml - url: /twitterbot login: admin script: twitterbot.py Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine DEMO! (if Murphy allows it..) Tweet something to @answrit (like: @answrit: are you ok?)
  • Chat bot (XMPP) # (part of) xmpp.py from google.appengine.api import xmpp from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from models import Answr class XMPPHandler(webapp.RequestHandler): def post(self): message = xmpp.Message(self.request.POST) message.reply(Answr.get_random().text) application = webapp.WSGIApplication([('/_ah/xmpp/message/chat/', XMPPHandler)], debug=True) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Chat bot (XMPP) # (significant part of) app.yaml - url: /_ah/xmpp/message/chat/ script: xmpp.py inbound_services: - xmpp_message Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine DEMO! Add to your XMPP buddy list [email_address] (GTalk is fine), and ask him questions!
  • References http://en.wikipedia.org - Articles on Cloud Computing, Affero GPL and others Google Inc – aa.vv. - “Bigtable: a distributed storage system for structured data” - OSDI 2006 Dan Sanderson - “Programming Google App Engine” - O' Reilly / Google Press – 2009 Google App Engine home page - http://www.appspot.com Simon Willison - “I've (probably) been using Google App Engine for a week longer than you have” - Slides from Barcamp London 4 – 2008” (referred in this document as App Engine Intro ) Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • More stuff
  • No vendor lock-in! Open source implementation of GAE: AppScale http://appscale.cs.ucsb.edu/ Runs on:
    • Amazon EC2
    • XEN (?)
    • KVM
    Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Cloud Freedom - AGPL Software licenses like the General Public License state rights of those who get the program, not of those who use the program via a network The GNU Affero General Public License (AGPL) require the availability of source code when the licensed code is deployed as a network service. http://www.gnu.org/licenses/agpl-3.0.html Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine
  • Python vs. Java Image taken from stacktrace.it: http://stacktrace.it/2009/05/google-app-engine/ Andrea Spadaccini - @lupino3 – Introduzione a Google App Engine