WASdev/sample.batch.sleepybatchlet

Name: sample.batch.sleepybatchlet

Owner: WASdev

Description: A simple sample batchlet for use with feature batch-1.0 on WebSphere Liberty. #JavaEE7

Created: 2014-09-11 18:05:29.0

Updated: 2016-11-30 21:18:48.0

Pushed: 2017-04-26 01:39:05.0

Homepage:

Size: 2715

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SleepyBatchlet sample for batch-1.0 on Liberty

SleepyBatchlet is a simple sample batchlet for use with feature batch-1.0 on WebSphere Liberty Profile. batch-1.0 is Liberty's implementation of the Batch Programming Model in Java EE 7, as specified by JSR 352.

The batchlet itself is rather uninteresting. All it does is sleep in 1 second increments for a default time of 15 seconds. The sleep time is configurable via batch property sleep.time.seconds. The batchlet prints a message to System.out each second, so you can easily verify that it's running.

Build the sample

For your convenience, the sample application has already been built: SleepyBatchletSample-1.0.war.

To build from source, use maven or import the project into WDT (WebSphere Developer Tools).

Install and run the sample
  1. Use the sample server.xml as a guide for configuring your Liberty server with batch-1.0.

  2. Install the sample app to your server by copying SleepyBatchletSample-1.0.war into the server's dropins/ directory.

  3. Run the sample. The sample app includes a generic JobOperatorServlet that acts as thin wrapper around the JobOperator API. You can start the batch job thru this servlet by hitting the following URL:

    http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=start&jobXMLName=sleepy-batchlet

Controlling sample jobs

Besides starting a job, you can use the JobOperatorServlet to stop, restart, and get status, by hitting the following URLs:

http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=stop&executionId=xx
http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=restart&executionId=xx
http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=status&executionId=xx

Where executionId=xx is the job execution ID. Each http request returns JobInstance and JobExecution records for the job.

For a complete list of actions available from the JobOperatorServlet, use action=help:

http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=help

Note: The JobOperatorServlet is a generic HTTP wrapper for the JobOperator API. You can copy it into your own application and use it to control the jobs for that application.

Example session

Below is an example session, using cURL.

Note: The query parameter sleep.time.seconds is passed along as a job parameter for the job, and then injected into the batchlet via a batch property. The property controls how long SleepyBatchlet runs.

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=start&jobXMLName=sleepy-batchlet'
t(jobXMLName=sleepy-batchlet, jobParameters=null): Job started!
nstance: instanceId=1, jobName=sleepy-batchlet
xecution: executionId=1, jobName=sleepy-batchlet, batchStatus=STARTED, createTime=Fri May 22 11:24:00 EDT 2015, startTime=Fri May 22 11:24:00 EDT 2015, endTime=null, lastUpdatedTime=Fri May 22 11:24:00 EDT 2015, jobParameters=null

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=status&executionId=1'
us(executionId=1):
nstance: instanceId=1, jobName=sleepy-batchlet
xecution: executionId=1, jobName=sleepy-batchlet, batchStatus=COMPLETED, createTime=Fri May 22 11:24:00 EDT 2015, startTime=Fri May 22 11:24:00 EDT 2015, endTime=Fri May 22 11:24:15 EDT 2015, lastUpdatedTime=Fri May 22 11:24:15 EDT 2015, jobParameters=null

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=start&jobXMLName=sleepy-batchlet&jobParameters=sleep.time.seconds=32'
t(jobXMLName=sleepy-batchlet, jobParameters={sleep.time.seconds=32}): Job started!
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STARTING, createTime=Fri May 22 11:25:11 EDT 2015, startTime=null, endTime=null, lastUpdatedTime=Fri May 22 11:25:11 EDT 2015, jobParameters={sleep.time.seconds=32}

url 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=status&executionId=2'
us(executionId=2):
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STARTED, createTime=Fri May 22 11:25:11 EDT 2015, startTime=Fri May 22 11:25:11 EDT 2015, endTime=null, lastUpdatedTime=Fri May 22 11:25:11 EDT 2015, jobParameters={sleep.time.seconds=32}

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=stop&executionId=2'
(executionId=2): Stop request submitted!
us(executionId=2):
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STOPPING, createTime=Fri May 22 11:25:11 EDT 2015, startTime=Fri May 22 11:25:11 EDT 2015, endTime=null, lastUpdatedTime=Fri May 22 11:25:31 EDT 2015, jobParameters={sleep.time.seconds=32}

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=status&executionId=2'
us(executionId=2):
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STOPPED, createTime=Fri May 22 11:25:11 EDT 2015, startTime=Fri May 22 11:25:11 EDT 2015, endTime=Fri May 22 11:25:31 EDT 2015, lastUpdatedTime=Fri May 22 11:25:31 EDT 2015, jobParameters={sleep.time.seconds=32}

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=restart&executionId=2&restartParameters=sleep.time.seconds=10'
art(executionId=2, restartParameters={sleep.time.seconds=10}): Job restarted!
us(executionId=2):
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=3, jobName=sleepy-batchlet, batchStatus=STARTED, createTime=Fri May 22 11:26:29 EDT 2015, startTime=Fri May 22 11:26:29 EDT 2015, endTime=null, lastUpdatedTime=Fri May 22 11:26:29 EDT 2015, jobParameters={sleep.time.seconds=10}
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STOPPED, createTime=Fri May 22 11:25:11 EDT 2015, startTime=Fri May 22 11:25:11 EDT 2015, endTime=Fri May 22 11:25:31 EDT 2015, lastUpdatedTime=Fri May 22 11:25:31 EDT 2015, jobParameters={sleep.time.seconds=32}

rl 'http://localhost:9080/SleepyBatchletSample-1.0/joboperator?action=status&executionId=2'
us(executionId=2):
nstance: instanceId=2, jobName=sleepy-batchlet
xecution: executionId=3, jobName=sleepy-batchlet, batchStatus=COMPLETED, createTime=Fri May 22 11:26:29 EDT 2015, startTime=Fri May 22 11:26:29 EDT 2015, endTime=Fri May 22 11:26:39 EDT 2015, lastUpdatedTime=Fri May 22 11:26:39 EDT 2015, jobParameters={sleep.time.seconds=10}
xecution: executionId=2, jobName=sleepy-batchlet, batchStatus=STOPPED, createTime=Fri May 22 11:25:11 EDT 2015, startTime=Fri May 22 11:25:11 EDT 2015, endTime=Fri May 22 11:25:31 EDT 2015, lastUpdatedTime=Fri May 22 11:25:31 EDT 2015, jobParameters={sleep.time.seconds=32}

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.