Post on 10-May-2015
description
Rapid Application Development onGoogle App Engine for Java
Kunal Dabir@kdabir
github.com/kdabir
2
Agenda
• Introduction• Rapid Apps – when?• Options• Developing on GAE/J– Pricing – Architecture– What’s wrong– Simpler way
• Demo– Build and deploy a
simple site.• Better Practices• Q & A
3
About the Talk• Level: Basic / Introductory
• Warning: There will be <code>– Some Programming knowledge of Java/Html
• Based on my own experiences:– Working in different web technologies and– Cloud hosting solutions
• Takeaways : – Get your app on cloud in a snap– Learn a thing or two about GAE/J
4
About Me• Programming for more than a decade
• Currently working at ThoughtWorks
• Language Enthusiast: – Java, Groovy, Ruby, JavaScript (Node), CoffeeScript, Scala,…..
• Groovy Evangelist
• Co-Organizer / Speaker: Pune Java User Group
• More at: kunaldabir.appspot.comFacts as on Sept 2013
5
Quick Poll - Who all:• Do Java web apps?
• Have used Google App Engine?
• Have heard of Groovy Language?
• Understand NoSQL data store?
• Deployed an app ?– (cloud/shared hosting /VPS/ anywhere)
• Enjoy programming?
6
Rapid App Development - When ?
• Prototyping
• Personal Pet Project
• Utility Apps
• REST API
7
Rapid App Development - When ?
• Not more than a few pages
• Data Records in thousands
• When time to market is critical
• When resources are limited
8
Options
• Google App Engine – google
• Heroku - salesforce
• CloudFoundry - vmware/spring
• OpenShift - Redhat/jboss
• dotCloud, EngineYard, Joyent, Cloudbees ....
9
Google App Engine - Benefits
• Quick to get development started
• Easy Provisioning
• No Operations
• Horizontal (Auto) Scaling
• Language Support : Python, Java, Go and PHP
10
GAE Has it all• DataStore
• Memcache
• Blobstore
• Users API
• Channel API
• Backends
• Images API
• Logging
• Mail API
• Capabilities API
• Multitenancy
• Task Queue
• Cron Jobs
• URLFetch
• XMPP
• Static File Server
11
At High Level
DataStore HRD• One for app• Multi tennancy• Shared between
version
App Servers• App Code• Auto Scaled• Multi Versioned
Static Web Server• CSS/JS/HTML• Fast Response• Always On
12
Pricing
• Free to start
• Enable Paid app, get resident instance.
• A lot cheaper than competition
• 28 free instance hours $0.08 / hour
• https://cloud.google.com/pricing/
13
The Java Way - What’s Wrong?
As a java web developer:
• Puzzled with OO soup, getters setters, syntactic noises
• Framework hell, Mix and match.
• XML noise or interspersed annotations@@@@
• Deployment ?? where ?? nothing free
14
The Java Way - What’s Wrong?
• Complex Builds– And the Builds files (verbose, xml)
• Nested directory structure of java web apps
• Using the SDK directly– Or the eclipse plugin (can’t build outside IDE)
• Ceremony and Boilerplate
15
The Java Way - What’s Wrong?
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;
public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
response.setContentType("text/html");
PrintWriter out = response.getWriter(); out.println("Hello World"); } }
16
Enter Glide
• Easy Install
• No configuration, well almost
• No complicated directory structure
• Hot reload
• No Lock-in, export to gradle project
17
Built on Awesome technoloG’s
• Google App Engine
• Groovy
• Gaelyk
• Gradle
• Git
• GitHub
18
Gaelyk Recap - Persistence
import com.google.appengine.api.users.Userimport groovyx.gaelyk.datastore.*
@Entityclass Post { String title String content @Indexed Date date = new Date() User user}
19
Gaelyk Recap - Controller
new Post(title: params.title, content: params.content, user: users.currentUser
).save()
log.info "Post Saved"
redirect "/"
20
Gaelyk Recap - Routing
get "/", forward: "/home.gtpl" , cache: 10.minutes
get "/docs/@doc", forward: "/_doc.groovy?docname=@doc"
get "/docs/", redirect: "/docs/intro"
post "/create", forward: "/_create.groovy"
all "/install", forward: "/install.html"
21
Using Glide
You need to know only three commands :
$ glide run
$ glide deploy
$ glide export
22
Configuration Files
• Only three config files, All optional
__glide.groovyDiscussed in next section
__routes.grovyThe gaelyk routes file we just saw
__build.gradleUsed to customize build. Not discussed here.
23
Configure Glide App
• Required to deploy app. • Use the registered app-id
app { name = "app-id" version = "v1"}
24
Layout Template
Sitemesh enabled by default
layout { mappings = [ "/*": "/_layout.html" ]}
25
Security
• Authentication– Use ubiquitous Google id– Or open Id (experimental)– Can Allow only administrator
web { security = [ 'admin': ["/post/*"], '*': ["/view/*"] ]}
26
Demo
27
Getting more mileage• Use CDN
• Hotlink JS Libraries, CSS and Images
• Use static landing page
• Use memcache
• Cache pages
• Enable PageSpeed
• Multiple versions
28
Trade Offs
• Performance
• Slower cold start
• Learning curve
• Difference b/w Local and Live GAE server
29
Question Answers
• Questions are guaranteed in Life, Answers aren’t
30
Resources
• Glide : – http://glide-gae.appspot.com
• Gaelyk : – http://gaelyk.appspot.com
• Group: – http://groups.google.com/forum/#!forum/glide-groovy
• Github: – https://github.com/kdabir/glide