AppEngine - University of Toronto · AppEngine Recommended Text: Programming Google App Engine Dan Sandersons O’Reilly 2 AppEngine ! Web application hosting environment ! Highly
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
! Possible to use Google Accounts to handle user authentication ! Can detect whether the current user has signed in ! Redirect the user to the appropriate sign-in page to sign in ! App can access the user's email address ! Detect whether the current user is an administrator • Simplify implementation of admin-only areas of the app.
UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); user.getEmail(); user.getUserId();
4
13
Security Configuration
! Configured in war/WEB-INF/web.xml ! HTTPS
! User authorization with Google Accounts • <role-name> can be either * or admin
14
Frontend Performance
! Can configure in management console ! Administration->Application Settings->Performance • Frontend Instance Class
• Idle instances • # of idle instances kept in standby
• Pending latency • Latency before starting new instance to handle waiting requests
15
Backend Performance
! Special App Engine instances ! Have no request deadlines, higher memory and CPU limits ! Persistent state across requests ! Started automatically ! Can run continously for long periods ! Individually addressable • http://[instance].[backend_name].[your_app_id].appspot.com
16
Bankend Configuration
! war/WEB-INF/backends.xml
! Administer • AppEngine management console
• appcfg.sh command line tool (part of the Java SDK)
5
17
Storage
! AppEngine Datastore • a NoSQL schemaless object datastore, with a query engine and atomic
transactions.
! Google Cloud SQL • Managed relational database
• https://developers.google.com/cloud-sql/
! Google Cloud Storage • Scalable, highly available storage service for objects and files up to terabytes
• https://developers.google.com/storage/
18
Datastore
! Highly scalable ! Fault tolerant ! Distributed ! Resembles a object database ! Data stored as entities • Similar to a RDB tuple
! Entity consists of: • Kind
• Similar to a RDB table, immutable
• Key • Immutable • Similar to primary key
• Properties • Similar to table columns • Different entities of the same kind may store different properties • A property can store multiple values at once
19
Data Types
20
Key
! Uniquely identifies object in Datastore ! Immutable ! Consists of: • Application’s ID (hidden from view)
• Kind • Entity ID, one of:
• key name - set by application • ID - set automatically by datastore if no name is given
! Key can be store as a property value ! Retrieving a entity by it’s key is faster than a datastore query
6
21
Datastore Low Level Interface
! Key creation: Key k = KeyFactory.createKey(“Entity”,”alphabeta”);
String k_str = KeyFactory.keyToString(k); Key k = KeyFactory.stringToKey(k_str);
! Store entity: DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); Entity e1 = new Entity(k);
e1.setProperty("prop1", 1);
ds.put(e1);
! Retrieve entity: Entity result = ds.get(e1.getKey());
22
Java Persistence API (JPA)
! Standard Java API for persisting Java objects ! Supported by AppEngine Datastore ! Annotations define entity kind, id and which properties to persist • By default JPA persists builtin Java types (e.g., String, Date) • @Basic persists a non-standard Java type property • @Transient marks property as non-persistent
23
Java Persistence API (JPA)
! J2EE standard ! Supported by Google Datastore ! Mappings • kinds -> classes
• entities -> objects • fields -> properties
! Data types supported by either • Primitive Java data type (e.g., String, Int) • Application-defined data type (e.g., Preferences)