Skip to main content

Session Notes - Grails for the Enterprise

Presenter: Robert Fischer

What you'll be getting for your time

  • j2ee friendly intro to grails
  • tour of grails functionality
  • practical day-to-day insights on using grails
  • live coding demo
  • argument for a single assertion: all enterprise web app development should be in grails
    • stunningly simple development
    • succinct code using a superset of java
    • sane defaults, straight-forward configuration
      • all the stuff you always use is pre-bundled
    • typing as deemed useful by developer
    • standard java deployment approach
    • springsource backed and here to stay
      • no need to worry about it going away
      • big community behind it that was around even before springsource acquisition

What is Grails?

  • web app dev framework and environment leveraging java and groovy
    • environment is often overlooked
    • easy to do development with vi and bash--need for IDE isn't all that huge
  • convention-based mvc development framework
    • ruby on rails really introduced the idea of convention over configuration
    • grails takes this idea and applies it in the java space
    • powerful command-line tools
  • powered by pre-configured and pre-integrated spring, hibernate, sitemesh, junit, etc.
    • all the technologies you are or should be using

How would you like your grails?

  • conceptually think dynamic mvc framework
    • dynamic, succinct domain and controllers
    • view technology works naturally with html
    • run from source code check-out
    • new features via extensible plugin architecture
      • even the stuff built into grails is based on plugin architecture
  • actually approachable best-of-breed java stack
    • prepackaged java build system
    • builds a war to plug into existing deployments
    • hooks for existing spring and hibernate configs
    • support for other enterprise technologies

How does Grails fit the Enterprise?

  • what is the enterprise?
    • some people see this as "established, extensible, dependable"
    • some people see this as "bloated"
  • unique qualities of enterprise dev
    • large-scale apps with application ownership flux
      • people coding and gathering requirements on app will change over time
    • existence of user-developers
      • people who want/need to use your code but don't want to know how the code works internally
      • google "robert fischer free toilet" to see his rant
    • out-of-control infrastructure
      • literal meaning: infrastructure I the developer don't have control over
        • don't have access to production databases, etc.
      • can also mean out-of-control in terms of there being a lot of different systems that the app needs to tie into

How does Grails fit in?

  • large-scale and ownership flux
    • conventional development
      • common style so doesn't matter who wrote the code originally
    • built-in testing
      • strongly encourages writing of tests--major way to deal with ownership flux
    • groovy
      • more succinct language, easier to read
  • existence of user-developers
    • plugin architecture
      • "experts" can build plugins that "users" can leverage
    • direct java lib interaction
      • don't have to think about how grails deals with the java class you just imported--it's java
  • out-of-control infrastructure
    • big win here is Spring

Architecture of Grails

  • groovy
  • Model
    • GORM
    • Hibernate
      • can plug in other persistence mechanisms (JPA, Hadoop, CouchDB, etc.)
    • JDBC
  • View
    • GSP/Taglibs
      • taglibs are nice, straight-forward way to extend the codebase--much simpler than Java taglibs
    • sitemesh
  • Controller
    • Grails controllers
    • Spring MVC
  • pervasive
    • spring DI
    • spring transactions
    • servlet api
    • junit
    • ant (gant)
    • log4j
    • web.xml

Plugins

  • if you want other technology than listed above, there's probably a plugin that does what you want
  • functional testing
    • G-Func, Canoo Webtest, Selenium, Fitnesse
  • RIA
    • Grails-UI, RichUI, GWT, Flex, YUI, IUI (for iPhone)
  • Database Management
    • autobase -- runs database migrations
    • rails migrations plugin (you don't want rails migrations!)
  • background tasks
    • BackgroundThread, Quartz
  • tons more -- http://grails.org/plugins
    • rating system but don't put too much credit in it

Autobase

  • manages database state using a non-linear collection of database change sets
    • Rails migrations are a linear path
      • assumes developer who made previous changes will be making future changes
  • leverages existing grails database automation to minimize effort
    • uses HBM -> DDL
    • HBM -> DDL assumes everything will be non-destructive
    • autobase handles destructive changes
    • uses embedded dsl in groovy; allows for things like dropColumn(), renameColumn()

BackgroundThread

  • provides a spring bean that executes arbitrary closures in the background
  • handles some awkwardness with hibernate sessions, provides thread logging and pooling

GORM Labs

  • transactional actions in controllers
    • services are transactional
  • .query -- shorthand for .executeQuery
  • aggregate properties on domain classes
  • property errors on nested domain classes
  • human-readable messages

SubLog and Testing Labs

  • SubLog = Sublime Logging
    • static 'log' properties
      • by default logging is available only on instances of objects
    • dynamic 'log' properties
    • strips off slf4j and gives more direct access for log4j
  • testing labs
    • controller integration test case support

Your Grails Adoption Plan

  • start with a roughly green-field proof of concept web application
    • grails for reporting on an existing database is a great avenue for this
  • replace/supplement a service with grails
    • making grails an endpoint for an ESB
  • use GRAG on SourceForge to generate a db front-end
  • wrap an existing Java or PHP web app in grails and use web.xml (installed via "grails install-templates") to map existing URLs to servlets
    • use url mappings to add new functionality in grails (e.g. http://myapp/g/newStuff)
    • PHP plugin gives you a PHP engine as a servlet--runs existing PHP code
  • do it and don't tell anyone
    • ends up as a WAR
    • ask forgiveness later

Resources

  • live open source apps
    • Grails Crowd
    • grails.org
    • Groovy Blogs
    • Groovy Tweets
  • media
    • Groovy, Grails, Griffon podcast
    • GroovyMag

Live Coding/Q&A

  • anything you want to use in multiple apps, write as a plugin
    • grails generate-plugin PluginName
    • a plugin IS a grails application
      • only difference is it has a XXXGrailsPlugin.groovy file
    • plugin sizes are minimal addition to WAR files
    • once you're done, do grails pacakge-plugin
      • creates a zip file containing the plugin
      • can do grails install-plugin zipfilename
    • need to set up a repository for plugins
    • when you go to production, it bundles the plugin into the war
    • note that plugins aren't included in your application's source--so need to point to a repository or figure out how to include those in source control
  • existing ant tasks can be plugged straight into gant
  • taglibs
    • easy to create and use
    • grails create-tag-lib taglibName
    • can take in attributes and the body between the opening and closing tag
      • e.g. def mytag = { attrs, body -> ... do stuff ... }
    • by default taglibs go into g prefix, e.g. <g:myTag/>
      • define a namespace in the tag library to give it a prefix other than g (static namespace = "whatever")

Comments

Popular posts from this blog

Running a Django Application on Windows Server 2012 with IIS

This is a first for me since under normal circumstances we run all our Django applications on Linux with Nginx, but we're in the process of developing an application for another department and due to the requirements around this project, we'll be handing the code off to them to deploy. They don't have any experience with Linux or web servers other than IIS, so I recently took up the challenge of figuring out how to run Django applications on Windows Server 2012 with IIS.

Based on the dated or complete lack of information around this I'm assuming it's not something that's very common in the wild, so I thought I'd share what I came up with in case others need to do this.


This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Assumptions and CaveatsThe operating system is Windows Server 2012 R2, 64-bit. If another variant of the operating system is being used, these instructions may not work properly.All of the soft…

Installing and Configuring NextPVR as a Replacement for Windows Media Center

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

Fixing DPI Scaling Issues in Skype for Business on Windows 10

My setup for my day job these days is a Surface Pro 4 and either an LG 34UC87M-B or a Dell P2715Q monitor, depending on where I'm working. This is a fantastic setup, but some applications have trouble dealing with the high pixel density and don't scale appropriately.
One case in point is Skype for Business. For some reason it scales correctly as I move between the Surface screen and the external monitor when I use the Dell, but on the LG monitor Skype is either massive on the external monitor, or tiny on the Surface screen.
After a big of digging around I came across a solution that worked for me, which is to change a setting in Skype's manifest file (who knew there was one?). On my machine the file is here: C:\Program Files\Microsoft Office\Office16\LYNC.EXE.MANIFEST
And the setting in question is this:
<dpiAware>True/PM</dpiAware>
Which I changed to this: <dpiAware>False/PM</dpiAware>
Note that you'll probably have to edit the file as administr…