Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

<center>
<h1> Better know a Grails Plugin </h1>

</center>

Welcome

Who am I?

Grails Consulting at Agile Orbit

http://www.agileorbit.com

Practical Grails 3


https://www.grails3book.com

Sproutary.com

Online software for Pre-Schools and Day Cares.
https://sproutary.com

New Plugin Portal

  • Matt Sheehan (mostly), Bobby Warner, & myself.
  • Bintray was not cutting it for usability.
  • OCI Recently revamped in light orange

https://github.com/grails/grails3-plugins

What is this talk about?

A journey around the Grails 3 ecosystem

Plugins are what makes Grails great

So many good plugins out there to quickly setup sane defaults for your app and get going quickly

Plugins are why we use Grails

  • We don’t want to spend time wiring & configuring beans.
  • Build on what others have built upon.

Grails 3 changed (for the better) how plugins work

Jars

  • Grails 1 & 2 plugins were zip’d source, now jar’s
  • Easier distribution

Build system is now gradle

  • opens up a lot more functionality
  • Standard build tool instead of custom

Grails is now built on top of Spring Boot

  • Opens up a lot more functionality
  • Built on top of solid foundation.

Little less magic and a lot more standard

  • Few things not as apparent to newcomers or seasoned Grails 2 devs.

  • Magic is still there and that’s what I’m going to talk about.

Brief history of Grails 3 plugins

Early Days

  • jars instead of zips
  • No portal
    • Hosted on Bintray
    • Users lost
  • Spring-security-core
  • Some plugins left behind
    • and in some cases thats a good thing.

Today

But new issues

  • Binary incompatibility an issues
  • Spring Boot package name changes

Scheduling

@Scheduled

SpringBoot already comes with one

  • Benefit from being based directly on spring-boot!

Great for simple scheduling

  • Use it on a service method
  • Simple health check
  • Clear or refresh a cache
  • System jobs running at set interval
    @Scheduled

Demo!

scheduling/scheduled

Quartz Plugin

Quartz Plugin

  • Defacto Java Scheduler lib Quarts (of course)
  • Uses custom artifact class
    • create Job classes to schedule/execute.
  • Set custom, cron, or one off job executions easily.

Few rough edges

  • Default started, then didn’t, then did
  • Transaction propagation
  • IDE Mark grails-app/jobs as src

Demo!

scheduling/quartz

Schwartz

Also built on Quartz

Different approach

Demo!

scheduling/schwartz

Quartz Pro Tips

  • Can run in cluster
  • No way to stop schedulers cluster wide
    • have to do node by node - eg rolling deploy
  • Ensure each node has a unique id.
  • Can be an easy way to do some async work is to take a request and schedule a job

Jesque

Similar to Ruby resque

  • Uses redis to queue background jobs.
  • Uses similar Job structure as quartz
  • Process work as it comes in.

quartz-admin & jesque-admin

Security

Spring Security

spring-security-core

  • All the power of Spring Security with sane defaults

s2-quickstart

$ grails s2-quickstart com.yourapp User Role

CONFIGURE SUCCESSFUL in 7s
| Creating User class 'User' and Role class 'Role' in package 'com.yourapp'
| Rendered template PersonWithoutInjection.groovy.template to destination grails-app/domain/com/yourapp/User.groovy
| Rendered template PersonPasswordEncoderListener.groovy.template to destination src/main/groovy/com/yourapp/UserPasswordEncoderListener.groovy
| Rendered template Authority.groovy.template to destination grails-app/domain/com/yourapp/Role.groovy
| Rendered template PersonAuthority.groovy.template to destination grails-app/domain/com/yourapp/UserRole.groovy
| 
************************************************************
* Created security-related domain classes. Your            *
* grails-app/conf/application.groovy has been updated with *
* the class names of the configured domain classes;        *
* please verify that the values are correct.               *
************************************************************

Recent improvements

  • bcrypt rounds lowered in tests
  • Ignore Case for username prop
    • Lowers need for custom UserDetails service
  • Password encoder now event listener

Extras

  • <sec:*> taglibs
  • User switching
  • Easily override defaults

spring-security-rest

  • Defaults Stateless JWT (Java Web Tokens)
    • Encodes || Encrypts user in token
    • Other storage (db, redis, memecached)

spring-security-ui

  • While does run on Grails 3, not a lot of new development
  • Provides
    • Self Registration
    • Password Reset tokens
    • Admin UI for Mappings, Roles, etc

Others

  • spring-security-ldap
  • spring-security-cas
  • Supports all the major “enterprise” systems.

Demo!

security/spring-security

Session Management

  • Move session out of container
  • Blue-green deploys
  • No more sticky sessions

Spring-Session

  • Multiple stores - redis, jdbc, hazlecast, etc
  • Session is immutable by default for performance
  • Security API differences

Plugin or not?

  • spring-session works out of box
  • Easily add in mutable sessions yourself

Demo!

session/springsession

  • Stores on client, not server
    • Can add bulk to request

Database

Database Migration

Generates DB Schema

  • Inspects domain classes
  • Takes an educated guess at what to do.
    • Always review the changes.
    • Doesn’t know your data access paths.
  • Underlying technology liqubase.

FlyWay

  • Uses versioned SQL scripts.
  • Run outside your application
    • depending on your deployment needs.
  • Not directly generated to your Domain Classes

Demo!

db/dbm
db/flyway

DB Logging

  • Simple, slightly useful
    datasource { logSql = true }
  • HibernateStats (Interceptor)
  • p6spy

we all know sqlLogging= true, helpfull, but not always clear.

p6spy sits between your app and jdbc driver and intercepts & logs exact sql queries (with params!) unlike hibernate sqlLogging

hibernateStats is available, easily added to an dev-time interceptor

Good to have on in development to quickly see if you’re making 1 or 1000 sql queries, or flushing the session 100’s of times.

Demo!

db/logging

dialects

  • Hibernate stores information nativity
  • PostgreSql Extensions
    • Native sequences
    • Native types (JSONB)
  • java.time.*

Demo!

db/dialects

MultiTenant

  • Segregate data by Tenant
    • Schema, Identifier, DB, etc
  • Built into recent GORM
  • Quickly create SaaS solutions

Great Guides

  • Custom Tenant Resolver by JWT

Demo!

db/multitenant

Honorable mentions

Email

grails-mail

  • Simple, easy to use.
  • Useful async feature to not tie up thread
  • Was in RC6 for 2 years without a release.
    • Until Yesterday :woot:

spring-boot-starter-mail

spring-boot-email-tools

API email services

  • Allow business/marketing to control templates
  • grails-mailgun
  • grails-sendgrid

Email Testing

  • Greenmail to catch emails.
  • Wizer
    • Easy to use in memory map of emails

Demo!

mail/emailtools

Front End

Asset Pipeline

Client Dependencies (gradle)

node npm gradle plugin

Demo!

frontend/assets

HTTP Clients

Consider newer libs

Servlet Containers

  • Simple to switch
  • Chose which fits your needs
  • Easily update Tomcat

https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto-embedded-web-servers.html

Demo!

container/undertow
container/tc

Configuration

external-config

  • Defined similar to Grails 2
    grails.config.locations = [
          "classpath:myconfig.groovy",
          "file:///etc/app/myconfig.yml",
          "~/.grails/myconfig.properties",
          'file:${catalina.base}/myconfig.groovy',
    ]
  • Includes yml<->groovy scripts
    grails yml-to-groovy-config [ymlFile] [optional outputFile]
    grails groovy-to-yml-config [ymlFile] [optional outputFile]

https://plugins.grails.org/plugin/grails/external-config

Spring Boot Externalized Conf

Spring Boot Starters

  • 80+ starters available from Spring Boot
  • Many work with grails out of box
  • Some don’t YMMV
    • Autoconfig makes assumptions

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-starters

Spring Boot Endpoints

  • Allows you to monitor & interact with your application.

https://docs.spring.io/spring-boot/docs/1.4.x/reference/html/production-ready-endpoints.html

Demo!

info/info

Profiles

  • Brings configuration, dependencies together to start apps.

list-profiles

➜  source grails list-profiles
| Available Profiles
--------------------
* angular - A profile for creating Grails applications with Angular 2
* rest-api - Profile for REST API applications
* base - The base profile extended by other profiles
* angularjs - A profile for creating applications using AngularJS
* plugin - Profile for plugins designed to work across all profiles
* profile - A profile for creating new Grails profiles
* react - A profile for creating Grails applications with a React frontend
* rest-api-plugin - Profile for REST API plugins
* web - Profile for Web applications
* web-jboss7 - A Profile for Creating a JBoss 7.1 EAP Project
* web-plugin - Profile for Plugins designed for Web applications
* webpack - A profile for creating applications with node-based frontends using webpack
  • Mostly front end, but a few for custom deployments.
  • Just Jars, distribute the same way.
  • Create your own
  • NEW: Listed on docs site

Testing

Grails Testing

New Trait based framework (3.3+)

  • Make your own traits
    • eg: api testing/login

Older Mixin framework still works in 3.3+

Test Data

  • Dru
    • Data Reconstruction Utility
  • seed-me
  • Build-test-data
    • Grails 3.3+ Support in progress

CodeNarc

  • Static code analysis
  • Just Gradle plugin now

Demo

testing/testing

Sometimes a plugin is overkill.

Sometimes unnecessary even for a plugin

Using the tools you have, build your own!

Grails provides a lot of great tools to build the functionality you ended quickly

  • Interceptors
    • jsonp
    • rate limit
      • Bucket4J
    • pagination
    • CORS (Now in core)

Settings plugin (older 2.x plugin)

  • (1 domain class, 1 service & a cache)
  • So simple, just implement it.

Evaluating Plugins

What to look for:

  • Release & tests automated?
  • When was last release?
  • Active maintainer?
  • Documentation up to date?
  • Review code you pull into your app!

Where’d they go?

  • buildInfo -> actuator
  • Tomcat & Standalone -> starters
  • jquery & UI? -> client Dependencies or npm (via gradle)
  • Webflow -> x

Conclusion

The Current Echosystem

  • good
  • bad
  • ugly

good

Everything you need to build a website quickly is there.

bad

Discover-ability
You need to know where to look, or come to this talk to find everything.

ugly

2 years between releases
broken links

Gorm versions break plugins more often

Thanks

Deployment

My preferred way AWS elastic beanstalk

AWS gradle plugins make this trivial

What to know

  • Port 5000 SERVER_PORT
  • cant be executable jar - just regular jar
    • it explodes the jar before running it, so unzip wont work with exec
  • .ebextensions included in jar for cache, etc

Docker

docker gradle plugins

Easily build your jar into a container, and define your other infra containers as well

sshoogar

Sometimes you just need to push a file somewhere and restart a service

sshoogar - dsl for doing just that

War (gradle deploy plugin)

Deploy war to Tomcat api

Deploy info

(git commit,)

grailsinfocontributor

Logging slf4j
remote api

Log Accutator API, change logging on the fly

Ship logs off system!
Splunk, ELK, Papertrail, anywhere!

Views

GSP (Yes it’s a plugin now)

Gson (json views)

Static type, speed, inheritance, etc

hal

json-api

Markup

grails-vaadin-plugin

Documentation

asciidoctorj

Easy & powerful writing tool
Gradle integration

Keep documentation with your code!

  • Changelogs
  • Docs

Publish to static site (s3/etc)

spring-restdocs

swagger

Or just use the library itself

Metrics

statsd metrics

Sentry

Datadog

Accutaotrs monitoring

Health

Build your own

Web (Other)

Cookie

  • Cookie spec, creating Secure (new)
    WebSockets(grails-spring-websocket)
  • rabbitmq
    gorm-graphql

scaffolding

Not really something I use, anyways right after building

scaffolding

angular-scaffolding