46
Grails, from scratch to prod … plus vite ! MAURY Aurélien Consultant Xebia Email : [email protected] Twitter : @aurelienmaury LinkedIn : http://fr.linkedin.com/in/aurelienmaury Blog : http://blog.xebia.fr

Grails from scratch to prod - MixIT 2010

Embed Size (px)

DESCRIPTION

Slides of my talk at the Mix-IT

Citation preview

Page 1: Grails from scratch to prod - MixIT 2010

Grails, from scratch to prod

… plus vite !

MAURY AurélienConsultant XebiaEmail : [email protected]

Twitter : @aurelienmauryLinkedIn : http://fr.linkedin.com/in/aurelienmauryBlog : http://blog.xebia.fr

Page 2: Grails from scratch to prod - MixIT 2010
Page 3: Grails from scratch to prod - MixIT 2010

Qu'est-ce que Grails ?

Page 4: Grails from scratch to prod - MixIT 2010

Qu'est-ce que Grails ? Framework d'application web complet

× MVC, basé sur le langage Groovy

Inspiré de RoR, Django, TurboGears× Adapté à la culture Java

Bâti sur le roc× Stack éprouvée : Spring, Hibernate, Tomcat

Page 5: Grails from scratch to prod - MixIT 2010

Buts Pile application web Java standard

× Fournir un niveau d'abstraction en plus

Réduire la complexité× En outillant l'existant

Augmenter la productivité× En scriptant les tâches répétitives

Page 6: Grails from scratch to prod - MixIT 2010

Approche Convention over configuration

× Principe de "défaut raisonnable"

Don't repeat yourself× Structure imposée pour réduire les duplications

Plateforme complète× Méthodologie et approche fournies

Page 7: Grails from scratch to prod - MixIT 2010

Histoire Janvier 2007

× Sortie de Groovy 1.0

Février 2008× Sortie de Grails 1.0

Novembre 2008× SpringSource rachète G2One

Page 8: Grails from scratch to prod - MixIT 2010

Rock Stars Guillaume Laforge (@glaforge)

× Leader Groovy chez SpringSource

Graeme Rocher (@graemerocher)

× Leader Grails chez SpringSource

Page 9: Grails from scratch to prod - MixIT 2010

Comment ça marche ?

Page 10: Grails from scratch to prod - MixIT 2010

Plateforme complète

Page 11: Grails from scratch to prod - MixIT 2010

Simplifié par Groovy Syntaxe allégée

× Accessible à tous les développeurs Java

Closures, Collections, Gpars, …× L'essayer c'est l'adopter

Scripts de génération de code× Facilement extensible

Page 12: Grails from scratch to prod - MixIT 2010

Développement rapide

warcreate run

Code

Test

Fix

Page 13: Grails from scratch to prod - MixIT 2010

Support IDE Intellij IDEA

Eclipse STS

Netbeans

Page 14: Grails from scratch to prod - MixIT 2010

$ grails create-app bookstore

Page 15: Grails from scratch to prod - MixIT 2010

Structure d'un projetbookstore|_grails-app| |_conf => BootStraping, Datasources, UrlMappings| |_controllers| |_domain| |_i18n => messages.properties internationalisés| |_services| |_taglib| |_utils| |_views => Groovy Server Pages|_lib => Dépendances Java|_scripts|_src| |_groovy| |_java|_test|_web-app => Ressources statiques: images, JS, CSS, etc

Page 16: Grails from scratch to prod - MixIT 2010

Scaffolding Génération de CRUD à partir des entités

× Economie de temps

Popularisé par Ruby on Rails× Orienté schéma base de données

Adopté par Grails× Orienté domaine

Page 17: Grails from scratch to prod - MixIT 2010

Scaffolding grails create-domain-class

grails create-controller

grails create-service

grails generate-all

Page 18: Grails from scratch to prod - MixIT 2010

Scaffolding

Page 19: Grails from scratch to prod - MixIT 2010

Scaffolding grails generate-all org.bookstore.Book

× BookController× BookControllerTest× grails-app/views/book/list.gsp× grails-app/views/book/show.gsp× grails-app/views/book/edit.gsp× grails-app/views/book/create.gsp

Page 20: Grails from scratch to prod - MixIT 2010

Scaffolding dynamiqueclass BookController {

def index = {…}

def list = {…}

def create = {…}

def save = {…}

def show = {…}

def edit = {…}

def update = {…}

def delete = {…}

}

class BookController {

def scaffold = true

}

Page 21: Grails from scratch to prod - MixIT 2010

GORM : Mapping

class Book {

String title

static belongsTo = [author: Author]

static hasMany = [chapters: Chapters]

static constraints = {

title nullable:false

}

}

Page 22: Grails from scratch to prod - MixIT 2010

GORM : RequêtageBook.list(sort: 'title', order: 'asc')

Book.getAll(37, 41, 43)

Book.findByTitleLike("Harry P%")

Book.withCriteria {

eq('title', 'Harry Potter')

author {

like('Rowli%')

}

}

Page 23: Grails from scratch to prod - MixIT 2010

GORM : Requêtage

class Book {

static namedQueries = {

withPotterInTitle {

like 'title', '%Potter%'

}

}

}

Book.withPotterInTitle.list()

Page 24: Grails from scratch to prod - MixIT 2010

Vues Groovy Server Pages

× HTML + Taglib groovy

Assemblage par Sitemesh× Commandé par tags GSP

Taglib Grails (Prototype pour le JS)× Formulaires, AJAX

Page 25: Grails from scratch to prod - MixIT 2010

Vues : exemples<g:formRemote name="myForm"

on404="alert('not found!')"

update="updateMe" // onSuccess="jsFunc"

url="[action:'show']">

Login: <input name="login" type="text"></input>

</g:formRemote>

<div id="updateMe">this div is updated by the form</div>

fieldRemote, remoteFunction

Page 26: Grails from scratch to prod - MixIT 2010

Vues : exemples<g:each var="book" in="${books}">

<p>Title: ${book.title}</p>

<p>Author: ${book.author}</p>

</g:each>

if, else, formatDate, sortableColumn, datePicker, …

Page 27: Grails from scratch to prod - MixIT 2010

Contrôleurs grails create-controller org.bookstore.Book

× Génère un contrôlleur coquille

Injection de dépendance× def leNomDeMonService en attribut de classe

Helpers× render as JSON, render as XML

Page 28: Grails from scratch to prod - MixIT 2010

Contrôleurs : exempleclass AuthorController {

def springSecurityService

def list = {

[ authorInstanceList: Author.list(), authorInstanceTotal: Author.count() ]

}

}

Page 29: Grails from scratch to prod - MixIT 2010

Configuration : dépendancesgrails.project.dependency.resolution = {

repositories {

grailsPlugins()

grailsHome()

grailsCentral()

mavenLocal()

mavenCentral()

mavenRepo "http://snapshots.repository.codehaus.org"

}

dependencies {

runtime 'mysql:mysql-connector-java:5.1.13'

}

}

Page 30: Grails from scratch to prod - MixIT 2010

Configuration : environnements

environments {

development {

dataSource {

dbCreate = "create-drop"

url = "jdbc:hsqldb:mem:devDB" } }

test { dataSource { … } }

production { dataSource { … } }

}

Page 31: Grails from scratch to prod - MixIT 2010

Environnements grails run-app => dev

grails test run-app => test

grails test-app => test

grails war => production

Page 32: Grails from scratch to prod - MixIT 2010

Extensible Dépôt de plugins centralisé grails install-plugin …

× spring-security-core× spring-security-ui× quartz× codenarc× mongodb× spock× …

Page 33: Grails from scratch to prod - MixIT 2010

Très extensible× app-engine (GORM en mode JPA)

× groovy-plus-plus× jquery× searchable× gwt× feeds× birt-report× …

ou : grails create-plugin monPlugin

Page 34: Grails from scratch to prod - MixIT 2010

Extensible Plugin Grails == Application Grails

Page 35: Grails from scratch to prod - MixIT 2010

Questions fréquemment posées

Page 36: Grails from scratch to prod - MixIT 2010

Intégration continue ?

Page 37: Grails from scratch to prod - MixIT 2010

Est-ce performant ? Overhead Groovy : x5-7

× Utilisez Groovy++ (x3-5)

Productivité contre vitesse d'exécution× Pas de compile check ? Pas grave.

Optimisations Java× "src/java" ou librairies

Page 38: Grails from scratch to prod - MixIT 2010

Et la courbe d'apprentissage ? Groovy s'apprend vite

× Bases ~ 2 jours, Courant ~ 1 mois

Pièges, GORM Gotchas× Dans l'ensemble, rien ne bloque longtemps

Au delà de la carrosserie× Sur le Tao de Grails, la stack tu maîtriseras

Page 39: Grails from scratch to prod - MixIT 2010

La communauté est-elle active ? 7 versions mineures en 1 an

~ 60 Users Group sur la planète

~ 800 repository GitHub autour de Grails

~ 2500 mails par mois sur les ML

Page 40: Grails from scratch to prod - MixIT 2010

Y a-t-il du support ?

Page 41: Grails from scratch to prod - MixIT 2010

Dans quels cas utiliser Grails ? Minimum Viable Product rapide

× Du prototype au produit en douceur

Reprise d'une application existante× IHM Web rapide, intégration existant en librairie

Tout nouveau projet d'appli web× En toute simplicité

Page 42: Grails from scratch to prod - MixIT 2010

Success stories

Page 43: Grails from scratch to prod - MixIT 2010

Bibliothèque

Page 44: Grails from scratch to prod - MixIT 2010

Linkothèque Groovy home

× http://groovy.codehaus.org/ Grails home

× http://www.grails.org Grails plugins

× http://www.grails.org/plugins/ An army of solipsists (this week in Grails)

× http://burtbeckwith.com/blog/

Page 45: Grails from scratch to prod - MixIT 2010

Questions ?

Page 46: Grails from scratch to prod - MixIT 2010

Merci à touset bon appétit