curl -H 'Content-Type: application/json' \ -d '{"entries": [ {"key": "myKey1", "value": "myValue1"}, {"key": "myKey2", "value": "myValue2"} ]}' \ http://localhost:8080/batcheetest/jbatch/batchee/execution/start/myjob
Using Apache BatchEE's server API with JBeret
TweetPosted on Wednesday Mar 04, 2015 at 06:11PM in JBatch
Apache BatchEE is a fork of the JSR352 reference implementation with many additional features. it has useful REST APIs built on JAX-RS so we can manipulate (start, stop, restart, and so on) batches through REST API. fortunately, it is well modularized so we can use its REST API implementation with other JSR352 implementation such as JBeret.
I created an example project which works with WildFly 8.2.0.Final and its JSR352 implementation JBeret. after deploy, issue following command:
Then you’ll see following output in WildFly console:
17:57:18,608 INFO [stdout] (Batch Thread - 9) Hello world! 17:57:18,609 INFO [stdout] (Batch Thread - 9) Job Parameters: {myKey2=myValue2, myKey1=myValue1}
It’s much better than create a servlet which kicks the batch.
And I haven’t tested yet, it also have useful client API for that REST API. we can use JobOperator
transparently thanks to its proxy. for details of REST API and BatchEE, see following URLs:
UPDATE:
I added a test case which uses client API of BatchEE, but it doesn’t work with released version. you need to apply a patch by hand. for details refer https://issues.apache.org/jira/browse/BATCHEE-59
Also I created an example of a test class which uses Arquillian. this won’t work with 0.2-incubating but will work with future versions.
@RunWith(Arquillian.class) public class MyJobArquillianIT { @ArquillianResource private URL url; private JobOperator jobOperator; @Deployment(testable = false) public static Archive<?> war() { final File[] files = Maven.configureResolver() .loadPomFromFile("pom.xml") .resolve("org.apache.batchee:batchee-jaxrs-server") .withTransitivity() .asFile(); return ShrinkWrap.create(WebArchive.class) .addClass(HelloBatchlet.class) .addAsResource("META-INF/batch-jobs/myjob.xml") .addAsLibraries(files); } @Before public void before() { jobOperator = BatchEEJAXRSClientFactory.newClient(url.toExternalForm() + "jbatch"); } @Test public void test() { Properties jobParameters = new Properties(); jobParameters.setProperty("someKey", "someValue"); final JobExecution jobExecution = waitForFinish(jobOperator.start("myjob", jobParameters)); Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus()); } private static final Collection<BatchStatus> BATCH_END_STATUSES = EnumSet.of(BatchStatus.COMPLETED, BatchStatus.FAILED, BatchStatus.STOPPED, BatchStatus.ABANDONED); private JobExecution waitForFinish(long executionId) { JobExecution jobExecution; while (!BATCH_END_STATUSES.contains((jobExecution = jobOperator.getJobExecution(executionId)).getBatchStatus())) { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } return jobExecution; } }
Web frontend
Its web-frontend GUI (batchee-servlet-embedded
) works even against JBeret runtime as follows. you can view executions, jobs and its definition, and can start jobs with custom parameters.
It also exposes simple-rest
API which is more useful when issue the command by hand or some cases (e.g. cron job). in case of this example, you can start a job as follows:
$ curl 'http://localhost:8080/batcheetest/jbatch-gui/rest/start/myjob?param1=x¶m2=y' 5 OK
You can read its help as follows:
$ curl 'http://localhost:8080/batcheetest/jbatch-gui/rest/' -1 FAILURE Unknown command: The returned response if of MIME type text/plain and contains the following information {jobExecutionId} (or -1 if no executionId was detected)\n OK (or FAILURE)\n followed by command specific information Known commands are: * start/ - start a new batch job Sample: http://localhost:8080/myapp/jbatch/rest/start/myjobname?param1=x¶m2=y BatchEE will start the job and immediately return * status/ - query the current status Sample: http://localhost:8080/myapp/jbatch/rest/status/23 will return the state of executionId 23 * stop/ - stop the job with the given executionId Sample: http://localhost:8080/myapp/jbatch/rest/stop/23 will stop the job with executionId 23 * restart/ - restart the job with the given executionId Sample: http://localhost:8080/myapp/jbatch/rest/restart/23 will restart the job with executionId 23
Tags: arquillian batchee jbatch jberet wildfly
Deploying an application to WildFly with Ant + Cargo
TweetPosted on Wednesday Mar 04, 2015 at 04:49PM in WildFly
I created an Ant script which deploys an application to WildFly through ssh tunnel. it creates ssh tunnel using Ant’s sshtunnel
target. the script works well with a Jenkins job.
Configuring automatic push by successfully build
TweetPosted on Sunday Mar 01, 2015 at 11:19PM in Jenkins
Making Jenkins to push to an another remote repository if build finishes successfully.
Recipe
-
Create a bare repository
$ mkdir trader-stable.git $ cd trader-stable.git $ git init --bare Initialized empty Git repository in /Users/Shared/trader-stable.git/ $
-
Click
Add Repository
-
Enter
Repository URL
-
Click
Advanced…
-
Enter
stable
toName
-
Click
Add post-build action
⇒Git Publisher
-
Check
Push Only If Build Succeeds
-
Click
Add Tag
-
Enter
$BUILD_NUMBER
toTag to push
-
Check
Create new tag
-
Enter
stable
toTarget remote name
-
Click
Save
Test
$ pwd /Users/kyle/tmp/trader $ echo 'push if succeeds test' >> hi.txt $ git commit -am 'push if succeeds test' $ git push origin master
Jenkins said Pushing tag 8 to repo stable
$ git remote add stable /Users/Shared/trader-stable.git $ git fetch stable remote: Counting objects: 1, done. remote: Total 1 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (1/1), done. From /Users/Shared/trader-stable * [new tag] 8 -> 8 $
Configuring automatic build by push for git repository
TweetPosted on Sunday Mar 01, 2015 at 07:15PM in Jenkins
We can start the build by send request to following URL.
http://YOURHOST/jenkins/job/PROJECTNAME/build
Recipe
In my case, Jenkins is deployed in /
, and the server is running on port 18080
. so the command to start a build of the job named trader
will be:
curl http://localhost:18080/job/trader/build
So put following shell script into $ORIGIN_BARE_REPOSITORY/hooks/post-receive
and execute chmod +x post-receive
.
#!/bin/sh curl http://localhost:18080/job/trader/build
Testing
Push some modification as follows:
$ echo hook test >> hi.txt $ git add hi.txt $ git commit -m 'hook test' $ git push origin master
Check the build was run automatically as expected, and the output.
Creating a simplest Jenkins job against a git repository
TweetPosted on Sunday Mar 01, 2015 at 05:45PM in Jenkins
-
Click
New Item
-
Enter
trader
inItem name
and selectBuild a free-style software project
-
Select
Git
and enterRepository URL
-
Click
Add build step
-Execute shell
-
Enter
cat hi.txt
intoCommand
-
Click
Save
-
Click
Build Now
-
Click a Build History which just created by build
-
Click
Console Output