Inspired by the discussion on ‘How would you launch a Quartz job from a script?’ and basing on the post about ‘Tiny GroovyServ’, I decided to write a simple batch system using Grails and quartz, spring-security-core and batch-launcher plugins.
The batch-launcher has been choosen because, in the company where I work, there are segregated environments for online (web) applications and batch applications. So in the exclusive environment for batch applications there isn’t Tomcat, WebLogic or any Web Container or Application Server. In this context, batch applications are responsible for all massive and asynchronous processing, especially when it is required to integrate two or more systems.
Basically I created an application made by services and scheduled tasks, whose synchronous or asynchronous invocation can be done through an SSH client. The step-by-step test:
- Download the file simple_batch_system-0.1.zip (its size is about 25 Mbytes and it contains all dependencies needed to run the application)
- Unzip the file in a directory
- Start the application (the only prerequisite for this step it is to have a installed JRE and make java available in the PATH)
- Start the execution of services or scheduled tasks logged in as admin0 (password is admin):
ssh -p 8123 admin0@localhost task1Job,task3Service
[daniel@techdm simple_batch_system-0.1]$ ./simple_batch_system.sh
Some important notes:
- For cases where there is no segregation of online (web) and batch environments, a similar approach can be used for developing regular (web) Grails applications. The source code written for handling ssh commands, can be found here;
- The plugin spring-security-core is optional and it was used only to create a known domain model of users and profiles;
- The mechanism of public and private keys can be adopted as an alternative authentication. This combined with a ssh-agent would eliminate the need of password exchanging, without reducing the security of the solution;
- It is possible to develop an interactive SSH session for command execution;
- During any development using batch-launcher, the essential commands are ‘grails batch-run-app’, ‘grails interactive’ (combined with ‘batch-reload-app’) and ‘grails batch-war’.