play framework on google app engine - productivity stack
TRANSCRIPT
![Page 1: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/1.jpg)
smart.biz.plsmart.biz.pl
Play with GAE
1
Productivity stack: Play Framework on Google App EnginePolish Java User GroupKraków 2016-04-05
@marcinstepienwww.smart.biz.pl
![Page 2: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/2.jpg)
smart.biz.plsmart.biz.pl
Marcin Stępień
Developer, [email protected]@marcinstepienlinkedin.com/in/marcinstepien
www.smart.biz.pl
2005
www.whenvi.com
2014
2
![Page 3: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/3.jpg)
smart.biz.plsmart.biz.pl
❖ App Engine intro, scaling & limitations
❖ Play Framework stuff
❖ GAE abstraction
❖ How do this two things work together
❖ Play 2 on GAE?
❖ Trade-offs
3
Play Framework + GAE
![Page 5: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/5.jpg)
smart.biz.pl
PlayFramework
Google AppEngine
5
Productivity
![Page 6: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/6.jpg)
smart.biz.pl
Google Cloud
Compute EngineApp Engine
PaaS IaaS
6
![Page 7: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/7.jpg)
smart.biz.pl
Building blocks
App Engine PaaS
7
Build toolsScalable
Infrastructure
![Page 8: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/8.jpg)
smart.biz.pl
Scaling is simplified
8
One tier of servers
Instances: - capacity- max / min #- manual / autoscale- warm up /
decommission- traffic splitting
Internet
![Page 9: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/9.jpg)
smart.biz.pl
Just a drawing
9
Internet
load balancer frontend servers backed servers data store
You will not deal with that
![Page 10: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/10.jpg)
smart.biz.pl
GAE Limitations
10
Security sandbox
● Java class whitelist
● Java 7
● Servlet API 2.5
○ no real async WS calls
● No raw socket connections
○ no SMTP etc.
○ Url Fetch service instead
Scalability
● Frontend calls are limited to
30s
● Scheduled Jobs limited to
10min
● Url Fetch limited to max 60s
● Do not share object in session
● NoSQL datastore *
● 200 indexes
![Page 11: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/11.jpg)
smart.biz.plsmart.biz.pl
https://cloud.google.com/appengine/docs/the-appengine-environments
11
GAE Environments
![Page 12: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/12.jpg)
smart.biz.pl
Play 1, Play 2, Ninja, Spark … Spring Boot, JHipster
Java micro frameworks
12
![Page 13: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/13.jpg)
smart.biz.pl
Play 1 Play 2
2008 released 2013
Java first service Scala first, Java
Groovy templates Scala
1 GAE module -
by communitymaintenance mode*
developedby authors and community
by 3rd part. commerce supportby authorsand 3rd part.
Play Framework versions
13
![Page 14: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/14.jpg)
smart.biz.pl
There is no HttpServletRequest, HttpSession etc.
Not a JEE Framework
14
GAE module wraps Play app into .war file
![Page 15: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/15.jpg)
smart.biz.pl
There is no server side session
Share Nothing
15
![Page 16: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/16.jpg)
smart.biz.plsmart.biz.pl
#pass value to next request in flash scopeflash.put(“key”, object);
#store in encrypted user cookie, Strings only, 4kbsession.put(“key”, “value”);
#store object in cacheCache.store(“key”, object, “1h”);
16
Share Nothing
![Page 17: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/17.jpg)
smart.biz.pl
hot swapping on dev, just hit F5+
auto scaling on prod
Share Nothing
17
![Page 18: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/18.jpg)
smart.biz.pl
GAE gives 2 types. Transparent use for Play developer.
Distributed Cache
18
![Page 19: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/19.jpg)
smart.biz.pl
But not on GAE with Servlet 2.5 spec
Play is asynchronous
19
![Page 20: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/20.jpg)
smart.biz.plsmart.biz.pl
#com.ning.http.client.AsyncHttpClient
#not on GAE servlet API 2.5Promise<HttpResponse> res1, res2; res1 = WS.url("http://example1").getAsync();res2 = WS.url("http://example2").getAsync();...
#synchronous call works fineWS.url("http://example").get();
#Json parserWS.url("http://example").getJson();
20
WS calls are wrapped in URL fetch
![Page 21: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/21.jpg)
smart.biz.pl
Siena module instead of GAE JPA
Data store: Active Record pattern
21
![Page 22: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/22.jpg)
smart.biz.plsmart.biz.pl
public class Employee extends Model {
@Id public Long id;public String fullName;public Department dep;
}
public class Department extends Model {
@Id public Long id;@Url public String website;public Date launched;
}
22
Data store abstraction
![Page 23: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/23.jpg)
smart.biz.plsmart.biz.pl
Employee adam = new Employee(“Adam”);Adam.dep = department;adam.save();
welcome(adam);
23
Active Record
![Page 24: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/24.jpg)
smart.biz.plsmart.biz.pl
public class Employee extends Model {
@Id public Long id;public String fullName;#no Joins, dep stores only id fieldpublic Department dep;
#retrieves and maps into objectpublic String getDepWebsite() {
#dep.website is null until you call .get()return dep.get().website;
}}
24
Fetching data, no joins
![Page 25: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/25.jpg)
smart.biz.plsmart.biz.pl
public class Employee extends Model {...
public static List<Employee> getAll(Long depId) {return all().filter(“dep”, new Department(depId)).fetch();
}
public static Query<Employee> all() {return all(Employee.class);
}
25
Querying
![Page 26: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/26.jpg)
smart.biz.pl
Controller is tied to HTTP protocol
RESTful
26
![Page 27: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/27.jpg)
smart.biz.plsmart.biz.pl
#http method, app url (regex), controller method
GET /employee/{id} Employees.userPOST /employee/ Employees.createPUT /employee/{id} Employees.updateDELETE /employee/{id} Employees.delete
GET /employee/show-{id} Employees.showGET /employee/list Employees.list
27
Routing
![Page 28: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/28.jpg)
smart.biz.plsmart.biz.pl
#controller methods are static for Play v. < 1.4public class Employees extends App {
public static void create(Employee em) {em.save();show(em.id); #HTTP 302 redirect
}#template is chosen by conventionpublic static void show(Long id) {
#object passed into Employees/show.htmlrender(Employee.get(id));
}
public static void list() {renderJSON(Employee.all());
}}
28
Controller
![Page 29: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/29.jpg)
smart.biz.pl
Data store, Logging, Cache, Gmail, WS calls etc.
GAE Abstraction
29
Is implemented in Play. GAE SDK is hidden.
![Page 30: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/30.jpg)
smart.biz.pl
GAE tooling
30
BigQuery, Security scans, Performance scans, alerts
.
![Page 31: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/31.jpg)
smart.biz.pl
2. Environment (Java 8, Servlet 3.0 +)
Play 2 on GAE ?
31
1. Deployable .war file
![Page 32: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/32.jpg)
smart.biz.plsmart.biz.pl
https://github.com/play2war/play2-war-plugin
32
Play 2 on GAE: war
![Page 33: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/33.jpg)
smart.biz.plsmart.biz.pl
https://cloud.google.com/appengine/docs/flexible/custom-runtimes/
https://cloud.google.com/appengine/docs/flexible/java/dev-jetty9-and-apis
33
Play 2 on GAE: run
Services only via public APIs... Jetty 9 + docker configuration
Flexible runtime Custom runtime
![Page 34: Play Framework on Google App Engine - Productivity Stack](https://reader034.vdocument.in/reader034/viewer/2022050613/589bed211a28ab40348b48d9/html5/thumbnails/34.jpg)
smart.biz.pl
Trade-offs
34
Pros
● Faster deployment
● Scaling
● Google Infrastructure
● maintenance + analytic tools
○ BigQuery etc.
● Abstraction
○ You are not tied with
GAE SDK
Cons
● Sandbox limitations
● Not truly asynchronous on
basic GAE
● Servlet container lowers
application performance
● Watch out for test coverage