cs 683 emerging technologies fall semester, 2008 doc 15 ... · using webapp framework 10 from...
TRANSCRIPT
![Page 1: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/1.jpg)
CS 683 Emerging TechnologiesFall Semester, 2008
Doc 15 Google App EngineOct 28 2008
Copyright ©, All rights reserved. 2008 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA. OpenContent (http://www.opencontent.org/openpub/) license defines the copyright on this document.
![Page 2: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/2.jpg)
References
2
Google App Engine http://code.google.com/appengine/docs/Examples in this lecture are from the Google App Engine documentation
![Page 3: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/3.jpg)
What is Cloud Computing
3
IT-related capabilities are provided “as a service”
Services accesses anywhere via network access
Wikipedia Definition
![Page 4: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/4.jpg)
Michael Sheehan
4
http://cloudcomputing.sys-con.com/node/609938
ApplicationWeb email Software as a Service (SaaS)SalesForce
PlatformEnables cloud applications
Google App Engine, Heroku, Mosso, Engine Yard, Joyent, force.com
InfrastructureEnables cloud applications & platforms
Amazon’s EC2, GoGrid, RightScale, Linode
![Page 5: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/5.jpg)
EC2
5
Linux machines
Run any linux compatible program
EBS, S3 & SimpleDB for storeage
Not web specifix
![Page 6: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/6.jpg)
Google App Engine
6
Dynamic web applicationsGoogle Web framework - webappDjango, CherryPy, Pylons, and web.py
PythonJava in future
Object DatabaseQueries, sorting and transactions
Automatic scaling and load balancing
Authenticating users and sending email using Google Accounts
Caching
Google Data APIsCalendar, Contacts, Documents, Spreadsheets, Picasa
![Page 7: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/7.jpg)
Lock in
7
Using Google Web framework locks you into using App Engine
![Page 8: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/8.jpg)
Simple Example
8
print 'Content-Type: text/plain'print ''print 'Hello, world!'
application: helloworldversion: 1runtime: pythonapi_version: 1
handlers:- url: /.* script: helloworld.py
helloworld.py app.yaml
![Page 9: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/9.jpg)
YAML Ain’t Markup Language
9
Human friendly data serialization format
Multilanguage supportPython, Ruby, Java, C, Perl, JavaScript, Ocaml, Haskell
http://www.yaml.org/
Maps key: value
Sequences each entry indicated by dash & space "- "
application: helloworldversion: 1runtime: pythonapi_version: 1
handlers:- url: /.* script: helloworld.py
app.yaml
![Page 10: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/10.jpg)
Using webapp Framework
10
from google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication( [('/', MainPage)], debug=True)
def main(): run_wsgi_app(application)
if __name__ == "__main__": main()
helloworld.py
![Page 11: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/11.jpg)
Some Python
11
class MainPage(webapp.RequestHandler):
def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!')
define class parent class
definemethod
self required in Python method argument list
Indentation requiredand significant
field in parent class
![Page 12: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/12.jpg)
More Python
12
application = webapp.WSGIApplication( [('/', MainPage)], debug=True)
def main(): run_wsgi_app(application)
if __name__ == "__main__": main()
Variables are not explicitly declaredcalling constructor
[a, b] define a list(a, b) define a tuple
define a function
If used as a program this will call the function main"main" is just a conventionIf called as module main is not called
![Page 13: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/13.jpg)
Templates
13
Generating html in code is awkward
Supports Django html templates
<html> <body> {% for greeting in greetings %} {% if greeting.author %} <b>{{ greeting.author.nickname }}</b> wrote: {% else %} An anonymous person wrote: {% endif %} <blockquote>{{ greeting.content|escape }}</blockquote> {% endfor %}
python code
![Page 14: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/14.jpg)
Static Files
14
application: helloworldversion: 1runtime: pythonapi_version: 1
handlers:- url: /stylesheets static_dir: stylesheets
- url: /.* script: helloworld.py
Static files can be served directly from file
![Page 15: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/15.jpg)
Datastore
15
Distributed object database
class Story(db.Model): title = db.StringProperty() body = db.TextProperty() created = db.DateTimeProperty(auto_now_add=True)
story = Story(title='Music of Django') story.body = 'There one was ...' story.put()
Define a data model
Store object in datastore
![Page 16: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/16.jpg)
Types Supported
16
StringPropertyBooleanPropertyIntegerPropertyFloatPropertyDateTimePropertyDatePropertyTimePropertyListPropertyStringListPropertyReferenceProperty
SelfReferencePropertyUserPropertyBlobPropertyTextPropertyCategoryPropertyLinkPropertyEmailPropertyGeoPtPropertyIMPropertyPhoneNumberPropertyPostalAddressPropertyRatingProperty
![Page 17: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/17.jpg)
Queries
17
stories = Story.all().filter('date >=', yesterday).order('-date') for story in stories: print story.title
Django Like
Greeting.gql("WHERE author = :1 ORDER BY date DESC", users.get_current_user())
GQL
![Page 18: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/18.jpg)
Transactions
18
from google.appengine.ext import db
class Accumulator(db.Model): counter = db.IntegerProperty()
def increment_counter(key, amount): obj = db.get(key) obj.counter += amount obj.put()
q = db.GqlQuery("SELECT * FROM Accumulator")acc = q.get()
db.run_in_transaction(increment_counter, acc.key(), 5)
![Page 19: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/19.jpg)
What about CAP Theorem?
19
Google Appengine docs do not discuss delays in distributing data
Data does seem to be distributed world wide
![Page 20: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/20.jpg)
Memcache
20
A coherent cache for data in your applicationAvailable to all instances of your application
from google.appengine.api import memcache
# Add a value if it doesn't exist in the cache, with a cache expiration of 1 hour.memcache.add(key="weather_USA_98105", value="raining", time=3600)
# Atomically increment an integer value.memcache.set(key="counter", 0)memcache.incr("counter")memcache.incr("counter")memcache.incr("counter")
![Page 21: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/21.jpg)
Admin Console
21
http://appengine.google.com/dashboard?&app_id=cs683
![Page 22: CS 683 Emerging Technologies Fall Semester, 2008 Doc 15 ... · Using webapp Framework 10 from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app](https://reader034.vdocuments.us/reader034/viewer/2022051815/603e93b1c3a49e780a78b22e/html5/thumbnails/22.jpg)
More
22
Sending Mail
mail.send_mail(sender="[email protected]", to="cs683", subject="Cloud Computing", body="""The End"""
Fetching URLS
Access to Google Apps, etc