mi primera aplicacion en google app engine

23
Mi Primera Aplicacion usando Google App Engine Adrian Catalan

Upload: ykro

Post on 21-Jan-2015

5.305 views

Category:

Technology


0 download

DESCRIPTION

Presentacion para el segundo Barcamp en Guatemala sobre Google App Engine

TRANSCRIPT

Page 1: Mi Primera Aplicacion en Google App Engine

Mi Primera Aplicacion usandoGoogle App Engine

Adrian Catalan

Page 2: Mi Primera Aplicacion en Google App Engine

Y que es eso del GAE?

Google App Engine es una plataforma de desarrollo Python & Java

Cloud Computing Todo como un servicio

I have not heard two people say the same thing about it [cloud]. There are multiple definitions out there of “the cloud”

Andy Isherwood, HP’s Vice President of European Software Sales

Page 3: Mi Primera Aplicacion en Google App Engine

Google App Engine

Tenemos por seguro que hace una cosa bien: correr aplicaciones web

Y ademas... Simple Escalable Seguro Balanceo de carga

Page 4: Mi Primera Aplicacion en Google App Engine

Google App Engine

Datastore Big Table y GQL

Frameworks Django (hell yeah...!) CherryPy Webapp WSGI

Servicios (google accounts, mail, url fetch & mas)

Page 5: Mi Primera Aplicacion en Google App Engine

App Engine Architecture

5

PythonVM

process

stdlib

app

memcachedatastore

mail

images

urlfech

statefulAPIs

stateless APIs R/O FS

req/resp

Page 6: Mi Primera Aplicacion en Google App Engine

Por que voy a dejar de usar LAMP?

Pareciera ser EL estandar ...pero

Configuracion Tuning Problemas con el Hardware Updates Y mas

Page 7: Mi Primera Aplicacion en Google App Engine

Datastore

Las Entidades tienen Kind, Key, y Propiedades Entity ~~ Record ~~ Python dict ~~ Python class 

instance Key ~~ structured foreign key; includes Kind Kind ~~ Table ~~ Python class Property ~~ Column or Field; has a type

Page 8: Mi Primera Aplicacion en Google App Engine

Desventajas

Ambiente muy controlado Solo Python y Java por el momento

Facil de usar ...pero limitado (gratis)

Si los frameworks estan atados a bd relacionales, de que forma pasaran a ser parte de GAE?

Page 9: Mi Primera Aplicacion en Google App Engine

Cuando usar GAE

Queremos tenerlo funcionando ASAP Empezando un proyecto nuevo Conocemos Python Las limitaciones no son un problema para nosotros No estamos en un proyecto muy grande con cosas 

dificiles de implementar

Page 10: Mi Primera Aplicacion en Google App Engine

Google App Engine

Hacia donde vamos?

Page 11: Mi Primera Aplicacion en Google App Engine

Google App Engine

Y ahora...vamos al demo

Page 12: Mi Primera Aplicacion en Google App Engine

Como empezamos?

Descargamos el SDK (duh!) dev_appserver.py appcfg.py

Hola, mundo...desde la nube!

print 'Content­Type: text/plain'

print ' '

print 'Hello, world!'

Page 13: Mi Primera Aplicacion en Google App Engine

Y la configuracion? (app.yaml)

application: helloworld

version: 1

runtime: python

api_version: 1

handlers:

­ url: /.*

  script: helloworld.py

Page 14: Mi Primera Aplicacion en Google App Engine

Empezando a usar webapp

from google.appengine.ext import webapp

from 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!')

Page 15: Mi Primera Aplicacion en Google App Engine

Empezando a usar webapp

application = webapp.WSGIApplication(

                                     [('/', MainPage)],

                                     debug=True)

def main():

  run_wsgi_app(application)

if __name__ == "__main__":

  main()

Page 16: Mi Primera Aplicacion en Google App Engine

Usando el servicio de usuarios

users.get_current_user() create_login_url(dest_url) get_current_user()

Page 17: Mi Primera Aplicacion en Google App Engine

ElModelo

class BlogEntry(db.Model):

  author = db.UserProperty()

  title = db.StringProperty()

  content = db.StringProperty(multiline=True)

  date=db.DateTimeProperty(auto_now_add=True)

Page 18: Mi Primera Aplicacion en Google App Engine

El resto de ElModelo

class BlogComment (db.Model):

  author = db.UserProperty()

  content = db.StringProperty(multiline=True)

  date=db.DateTimeProperty(auto_now_add=True)

  entry = db.ReferenceProperty(BlogEntry,collection_name='cm')

Page 19: Mi Primera Aplicacion en Google App Engine

Agregando al Datastore

class Entry (webapp.RequestHandler):

  def post(self):

    en = BlogEntry()

    en.author = users.get_current_user()

    en.content = self.request.get('content')

    en.title = self.request.get('title')

    en.put()

    self.redirect('/')

Page 20: Mi Primera Aplicacion en Google App Engine

Templates de Django

class MainPage(webapp.RequestHandler):

  def get(self):

    query = BlogEntry.all().order('­date')

    entries = query.fetch(3)

    template_values = {

      'entries': entries,

     }

    path = os.path.join(os.path.dirname(__file__), 'index.html')

    self.response.out.write(template.render(path, template_values))

Page 21: Mi Primera Aplicacion en Google App Engine

Templates de Django

{% for entry in entries %}

      <a href="/show?key={{ entry.key }}"><b>{{ entry.title }}</b></a>

      <blockquote>{{ entry.content|escape }}</blockquote>

      <small>Publicado por <b>{{ entry.author.nickname }}</b></small>

      <hr/>

    {% endfor %}

Page 22: Mi Primera Aplicacion en Google App Engine

Indicando rutas

application = webapp.WSGIApplication(

                                     [('/', MainPage),

                                      ('/comment', Comment),

                                      ('/entry', Entry),

                                      ('/show', ShowEntry),

                                      ('/publish', PublishEntry)],

                                     debug=True)

Page 23: Mi Primera Aplicacion en Google App Engine

El codigo lo encuentran en

http://www.megaupload.com/?d=0XUF9QIG

Preguntas || kthxbye