24
Google App Engine Ensky

Google App Engine

Embed Size (px)

DESCRIPTION

Google adp

Citation preview

Page 1: Google App Engine

Google App Engine Ensky

Page 2: Google App Engine

Outline - Today

• GAE Introduction

• GAE Hello world

• Python

• WebApp2

– A python-based Web development framework

Page 3: Google App Engine

Outline

• Cloud(IaaS, PaaS, SaaS)

• Google App Engine – Some features

• NoSQL

• Storage of GAE - Datastore

Page 4: Google App Engine

Cloud

• Cloud 三兄弟

– IaaS (Infrastructure as a Service)

– PaaS (Platform as a Service)

– SaaS (Software as a Service)

Page 5: Google App Engine

Cloud 三兄弟

• IaaS (Infrastructure as a Service) 直接給你虛擬主機用 優:很彈性,你想安裝任何軟體、採用任何架構都很容易 缺:要管理主機、處理一大堆問題 (ex: 駭客攻擊、版本升級等等)

• amazon AT&T HP

• hinet 台灣大 遠傳

Page 6: Google App Engine

Cloud 三兄弟

• PaaS (Platform as a Service)

規定你APP要怎麼寫,簡化你管理主機的步驟

有些工具的賣點是自動幫你處理擴充問題

優:管理方便,只需要focus在app開發

缺:寫法、使用工具、環境受到限制

• Google app engine

• Microsoft Azure

Page 7: Google App Engine

• SaaS (Software as a Service) 善用別人寫好的web app

• Gmail, Google calendar, Facebook, …

Cloud 三兄弟

Page 8: Google App Engine

Outline

• Cloud(IaaS, PaaS, SaaS)

• Google App Engine – Some features

• NoSQL

• Storage of GAE - Datastore

Page 9: Google App Engine

Google Cloud

• Google cloud包含了四大部份,分別解決不同問題 – Google App Engine

• Build your apps and websites on Google’s infrastructure with Google App Engine.

– Google Compute Engine • Run Linux Virtual Machines in the cloud using Google Compute

Engine (Limited Preview).

– Google Cloud Storage • Store, access and manage your data on Google’s storage

infrastructure.

– Google BigQuery • Analyze Big Data in the cloud using SQL and get real-time business

insights in seconds using Google BigQuery.

Page 10: Google App Engine

GAE

It’s PaaS

• Features – Focus on Web service

–規模自動擴張

–安全性

–效能

–支援Python and Java (and Go)

–完整的SDK

Page 11: Google App Engine

安全 or 限制 ? – Sandbox

• 對外的連線只能是HTTP / HTTPS的protocol 若要對外作任何操作都要透過HTTP 也不能作「listen某個port」的操作

• 不能對file system作任何寫入操作(可以讀取) 你只能用Google提供的GAE datastore或其他服務

• 不能fork一個process來用,也不能在連線結束之後執行別的程式

• 執行時間限制60秒以內要完成

Page 12: Google App Engine

Some useful features

• DataStore – NoSQL schemaless object datastore • BlobStore – Let you store "Binary large object" (blob) • Memcache – Fast Caching server • URL Fetch – Get data from HTTP/HTTPS • Mail – Just a Mail sender • Images – Image Processing, like resize, rotate • User – Supply Google account login • Task Queue – Send heavy load job to queue • Cronjob – Schedule a job

…. and more

Page 13: Google App Engine

Storage

• GAE provide two major Storage engine, for difference usage.

– App Engine Datastore

• NoSQL schemaless object datastore

– App Engine Blobstore

• to store blob data

Page 14: Google App Engine

Not only SQL

• Relational DB focus on relation

– User

• id, username, password, email, …

– Comment

• id, user_id, title, content, …

Page 15: Google App Engine

Not only SQL

• NoSQL focus on scalability, speed, or something else.

– document-oriented 沒有任何的schema, 適合存document

• MongoDB

– key-value database 只有key-value的形式, focus on speed, scalability

• Redis, memcached

Page 16: Google App Engine

Not only SQL

–Distributed database focus on distribution on servers

• HBase, cassandra, …

Page 17: Google App Engine

Outline

• Cloud(IaaS, PaaS, SaaS)

• Google App Engine – Some features

• NoSQL

• Storage of GAE - Datastore

Page 18: Google App Engine

Entity - GAE Datastore

• 一個帳號可以開很多個datastore

• 一個Datastore可以有很多Entity ex: User 這個datastore可以有很多筆資料

• 一個Entity可以有很多屬性(properties)

– ensky, [email protected]

– lalala, [email protected]

Page 19: Google App Engine

Key – GAE Datastore

• 每一筆entity都會有一個unique key

– 就很像SQL的Primary key一樣

• 可以不設讓系統自動產生; 也可以自己設定

• 刪除操作是用key來判斷

Page 20: Google App Engine

Types - GAE Datastore

Property in Python

StringProperty str unicode

BooleanProperty bool

IntegerProperty int

FloatProperty float

DateTimeProperty datetime.datetime

ListProperty list

BlobProperty db.Blob

TextProperty db.Text

Page 21: Google App Engine

Using Datastore

• Create a model

– 定義了該 datastore 的屬性有哪些

• Use it like a ORM

資料皆為物件,對物件操作就是對資料操作

– Insert:新增一個物件,最後呼叫.put()方法儲存

– Update:先query出你想要修改的物件,直接修改該物件,最後呼叫.put()方法儲存

– Delete:先query出你想要刪除的物件,直接呼叫.delete()方法刪除之

Page 22: Google App Engine

Create – GAE Datastore

Page 23: Google App Engine

Get, Update, Delete – GAE Datastore

Page 24: Google App Engine

Reference

• https://developers.google.com/appengine/