Better know a Grails Plugin

### Welcome
### Who am I?
### Eric Helgeson
erichelgeson@gmail.com
@nulleric
### Grails Consulting at Agile Orbit
http://www.agileorbit.com
### Sproutary.com
Online software for Pre-Schools and Day Cares.
https://sproutary.com
### Practical Grails 3

https://www.grails3book.com
* Gr8conf will be giving out some free copies!
### Join Groovy/Grails Slack
* https://groovycommunity.com/
* https://grails-slack.cfapps.io/
### What is this talk about?
### Survey - Show hands
### Version of Grails?
3?
2?
1...?
### A journey around the Grails 3 ecosystem
See many plugins you know and some you don't with example code
### Plugins are what makes Grails great
So many good plugins out there allow you 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.
### 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.
### Venture outside the Grails ecosystem
* Grails builds on top of technologies that have their own plugin systems as well
* Gradle, spring-boot, etc
### Brief history of Grails 3 plugins
### 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.
### 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
* Plugin Portal hosted by OCI
- Pulls data from Bintray, GitHub
* Open source
- https://github.com/grails/grails3-plugins
* OCI owned & revamped in light orange
### 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
* Use traits on Grails Service to implement job instead of custom artifact.
* Provide builder for easily building complex schedules.
* Very well documented.
* Generates db-migration changelog for you.
* Helps you utilize Quartz without getting in the way.
http://blog.agileorbit.com/grails-schwartz/latest/index.html#comparisonWithQuartzPlugin
### 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
* `` 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`
### Honorable Mentions
* Shiro
- Simple ACL
- http://grails-plugins.github.io/grails-spring-security-shiro
* Enforcer
- Simplify Spring-Security ACL
- http://plugins.grails.org/plugin/virtualdogbert/org.grails.plugins:enforcer
### 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`
### Cookie session Plugin
* 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
- http://guides.grails.org/grails-custom-security-tenant-resolver/guide/index.html
* Database per Tenant Multi-Tenancy
- http://guides.grails.org/database-per-tenant/guide/index.html
* Configure Datasources dynamically while using DATABASE Multi-tenancy
- http://guides.grails.org/grails-dynamic-multiple-datasources/guide/index.html
### Demo!
`db/multitenant`
### Honorable mentions
* Audit logging
* [Cache](http://grails-plugins.github.io/grails-cache/snapshot/guide/index.html) 4.0 / [EhCache](http://grails-plugins.github.io/grails-cache-ehcache/latest/) 3.x
- Requires GORM 6.1.x+
* [soft-delete](http://plugins.grails.org/plugin/danlobo/soft-delete)
* [hibernate-search](http://plugins.grails.org/plugin/lgrignon/hibernate-search)
* [hibernate-search](http://plugins.grails.org/plugin/lgrignon/hibernate-search)
### Email
### grails-mail
* Simple, easy to use.
* Useful async feature to not tie up thread
### spring-boot-starter-mail
* Quite low level, lots of setup, etc
* Example Usage
- http://www.opencodez.com/java/java-mail-framework-using-spring-boot.htm
### spring-boot-email-tools
* Multiple template engines
* Scheduling/Priority
* Redis queue
* Builder interface
https://github.com/ozimov/spring-boot-email-tools
### API email services
* Allow business/marketing to control templates
* grails-mailgun
* grails-sendgrid
### Email Testing
* Greenmail to catch emails.
* [Wizer](https://github.com/voodoodyne/subethasmtp/blob/master/Wiser.md)
- Easy to use in memory map of emails
### Demo!
`mail/emailtools`
### Front End
### Asset Pipeline
* Process & bundle all your js/css
* Has own plugin ecosystem
- http://www.asset-pipeline.com/plugins
- Handlebars, less, sass, etc
* Not only Grails
- Micronaut, Ratpack, Spring Boot, Gradle static site, etc
### Client Dependencies (gradle)
* Resolves front end dependencies
* Stores in `grails-app/assets/vendor`
* Supports yarn, npm, and bower
https://github.com/craigburke/client-dependencies-gradle
### node npm gradle plugin
* Use the same tools as FE devs
* Allows you to run npm command via gradle tasks
- Sometimes best to use npm/yarn nativity for tasks (eg webpack)
* Isolate for easy CI process
https://github.com/srs/gradle-node-plugin
### Demo!
`sproutary-grails`
### Demo!
`frontend/assets`
### HTTP Clients
* [http-builder-helper](https://plugins.grails.org/plugin/grails/http-builder-helper)
- Only keeping updated for a client
#### Consider newer libs
* [http-builder-ng](https://github.com/http-builder-ng/http-builder-ng)
* [http-requests](https://github.com/budjb/http-requests)
### 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`
### Also
https://www.grails3book.com/blog/2018/2018-03-27-tomcat-native.html
### 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.config.location
```
--spring.config.location=classpath:/some.properties
```
* ENV_VARS
```
SERVER_PORT == server.port
```
* Many options
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
### 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/1.5.x/spring-boot-starters
### Spring Boot Endpoints
* Allows you to monitor & interact with your application.
https://docs.spring.io/spring-boot/docs/1.5.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
* Based on Spock
* Can run JUnit Rules as well!
- https://stefanbirkner.github.io/system-rules/
* [Spock up and Running](http://shop.oreilly.com/product/0636920038597.do)
### 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](https://github.com/agorapulse/dru)
- Data Reconstruction Utility
* [seed-me](http://plugins.grails.org/plugin/bertramlabs/seed-me)
* Build-test-data
- Grails 3.3+ Support in progress
### CodeNarc
* Static code analysis
* Just Gradle plugin now
### Coverage
* [Clover](http://guides.grails.org/grails-code-coverage/guide/index.html)
* [Cobertura](http://cobertura.github.io/cobertura/)
* [Jacoco](https://docs.gradle.org/current/userguide/jacoco_plugin.html)
More info
http://mariogarcia.github.io/blog/blog/2017/04/grails_coverage.html
### Demo
`testing/testing`
### Sometimes a plugin is overkill.
Sometimes unnecessary even for a plugin
* Stripe
* [Excel](http://jameskleeh.com/groovy-excel-builder/)
### 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`, npm or yarn (via gradle)
### 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
years between releases
better changelogs
broken links
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)
https://github.com/bmuschko/gradle-cargo-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
https://github.com/jlstrater/grails-spring-restdocs-example
swagger
https://github.com/ajay-kmr/swagger
Or just use the library itself
Metrics
http://plugins.grails.org/plugin/grails/dropwizard-metrics
http://plugins.grails.org/plugin/sergiomichels/grails-melody-plugin
statsd metrics
Sentry
Datadog
Accutaotrs monitoring
Health
Build your own
(careful, up/down one) - https://tedvinke.wordpress.com/2017/10/25/why-is-springs-health-down-down-up-up-up-and-down-again/
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