30
Rapid Application Development on Google App Engine for Java Kunal Dabir @kdabir github.com/kdabir

Rapid Application Development on Google App Engine for Java

Embed Size (px)

DESCRIPTION

When you need to build and host web application as soon as possible with no cost involved and want no nonsense stuff to come in between, glide can come handy.

Citation preview

Page 1: Rapid Application Development on Google App Engine for Java

Rapid Application Development onGoogle App Engine for Java

Kunal Dabir@kdabir

github.com/kdabir

Page 2: Rapid Application Development on Google App Engine for Java

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

Page 3: Rapid Application Development on Google App Engine for Java

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

Page 4: Rapid Application Development on Google App Engine for Java

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

Page 5: Rapid Application Development on Google App Engine for Java

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?

Page 6: Rapid Application Development on Google App Engine for Java

6

Rapid App Development - When ?

• Prototyping

• Personal Pet Project

• Utility Apps

• REST API

Page 7: Rapid Application Development on Google App Engine for Java

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

Page 8: Rapid Application Development on Google App Engine for Java

8

Options

• Google App Engine – google

• Heroku - salesforce

• CloudFoundry - vmware/spring

• OpenShift - Redhat/jboss

• dotCloud, EngineYard, Joyent, Cloudbees ....

Page 9: Rapid Application Development on Google App Engine for Java

9

Google App Engine - Benefits

• Quick to get development started

• Easy Provisioning

• No Operations

• Horizontal (Auto) Scaling

• Language Support : Python, Java, Go and PHP

Page 10: Rapid Application Development on Google App Engine for Java

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

Page 11: Rapid Application Development on Google App Engine for Java

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

Page 12: Rapid Application Development on Google App Engine for Java

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/

Page 13: Rapid Application Development on Google App Engine for Java

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

Page 14: Rapid Application Development on Google App Engine for Java

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

Page 15: Rapid Application Development on Google App Engine for Java

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"); } }

Page 16: Rapid Application Development on Google App Engine for Java

16

Enter Glide

• Easy Install

• No configuration, well almost

• No complicated directory structure

• Hot reload

• No Lock-in, export to gradle project

Page 17: Rapid Application Development on Google App Engine for Java

17

Built on Awesome technoloG’s

• Google App Engine

• Groovy

• Gaelyk

• Gradle

• Git

• GitHub

Page 18: Rapid Application Development on Google App Engine for Java

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}

Page 19: Rapid Application Development on Google App Engine for Java

19

Gaelyk Recap - Controller

new Post(title: params.title, content: params.content, user: users.currentUser

).save()

log.info "Post Saved"

redirect "/"

Page 20: Rapid Application Development on Google App Engine for Java

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"

Page 21: Rapid Application Development on Google App Engine for Java

21

Using Glide

You need to know only three commands :

$ glide run

$ glide deploy

$ glide export

Page 22: Rapid Application Development on Google App Engine for Java

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.

Page 23: Rapid Application Development on Google App Engine for Java

23

Configure Glide App

• Required to deploy app. • Use the registered app-id

app { name = "app-id" version = "v1"}

Page 24: Rapid Application Development on Google App Engine for Java

24

Layout Template

Sitemesh enabled by default

layout { mappings = [ "/*": "/_layout.html" ]}

Page 25: Rapid Application Development on Google App Engine for Java

25

Security

• Authentication– Use ubiquitous Google id– Or open Id (experimental)– Can Allow only administrator

web { security = [ 'admin': ["/post/*"], '*': ["/view/*"] ]}

Page 26: Rapid Application Development on Google App Engine for Java

26

Demo

Page 27: Rapid Application Development on Google App Engine for Java

27

Getting more mileage• Use CDN

• Hotlink JS Libraries, CSS and Images

• Use static landing page

• Use memcache

• Cache pages

• Enable PageSpeed

• Multiple versions

Page 28: Rapid Application Development on Google App Engine for Java

28

Trade Offs

• Performance

• Slower cold start

• Learning curve

• Difference b/w Local and Live GAE server

Page 29: Rapid Application Development on Google App Engine for Java

29

Question Answers

• Questions are guaranteed in Life, Answers aren’t

Page 30: Rapid Application Development on Google App Engine for Java

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