grails from scratch to prod - mixit 2011

46
Grails, from scratch to prod … plus vite ! !"#$% "'()*+,- !"#$%&'(#' *+,-( ./0+* . (/(%0123+,-(450 12+3,( . 2(%0+&-+#/(%01 4+-5,67- . 678.99504&-#:+;-#4<"/9-#9(%0+&-+#/(%01 8*9: . 678.99,&"=43+,-(450

Upload: aurelienmaury

Post on 29-Nov-2014

1.327 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Grails from scratch to prod - MixIT 2011

Grails, from scratch to prod

… plus vite !

!"#$%&"'()*+,-&!"#$%&'(#')*+,-()./0+*).)(/(%0123+,-(450)

12+3,().)2(%0+&-+#/(%01)4+-5,67-).)678.99504&-#:+;-#4<"/9-#9(%0+&-+#/(%01)8*9:&.)678.99,&"=43+,-(450)

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

Qu'est-ce que Grails ?

Page 4: Grails from scratch to prod - MixIT 2011

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 2011

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 2011

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 2011

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 2011

Rock Stars !  Guillaume Laforge (@glaforge)

! Leader Groovy chez SpringSource

!  Graeme Rocher (@graemerocher)

! Leader Grails chez SpringSource

Page 9: Grails from scratch to prod - MixIT 2011

Comment ça marche ?

Page 10: Grails from scratch to prod - MixIT 2011

Plateforme complète

Page 11: Grails from scratch to prod - MixIT 2011

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 2011

Développement rapide

>(0)<0+('+) 0%#)

!";+)

?+$')

@-3)

Page 13: Grails from scratch to prod - MixIT 2011

Support IDE !  Intellij IDEA

!  Eclipse STS

!  Netbeans

Page 14: Grails from scratch to prod - MixIT 2011

$ grails create-app bookstore

Page 15: Grails from scratch to prod - MixIT 2011

Structure d'un projet bookstore!|_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 2011

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 2011

Scaffolding !  grails create-domain-class

!  grails create-controller

!  grails create-service

!  grails generate-all

Page 18: Grails from scratch to prod - MixIT 2011

Scaffolding

Page 19: Grails from scratch to prod - MixIT 2011

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 2011

Scaffolding dynamique class 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 2011

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 2011

GORM : Requêtage Book.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 2011

GORM : Requêtage class Book {

static namedQueries = { withPotterInTitle { like 'title', '%Potter%' } }

} Book.withPotterInTitle.list()

Page 24: Grails from scratch to prod - MixIT 2011

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 2011

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 2011

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 2011

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 2011

Contrôleurs : exemple class AuthorController { def springSecurityService

def list = { [ authorInstanceList: Author.list(),

authorInstanceTotal: Author.count() ] } }

Page 29: Grails from scratch to prod - MixIT 2011

Configuration : dépendances grails.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 2011

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 2011

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 2011

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 2011

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 2011

Extensible !  Plugin Grails == Application Grails

Page 35: Grails from scratch to prod - MixIT 2011

Questions fréquemment posées

Page 36: Grails from scratch to prod - MixIT 2011

Intégration continue ?

Page 37: Grails from scratch to prod - MixIT 2011

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 2011

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 2011

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 2011

Y a-t-il du support ?

Page 41: Grails from scratch to prod - MixIT 2011

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 2011

Success stories

Page 43: Grails from scratch to prod - MixIT 2011

Bibliothèque

Page 44: Grails from scratch to prod - MixIT 2011

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 2011

Questions ?

Page 46: Grails from scratch to prod - MixIT 2011

Merci à tous et bon appétit