The batch-processing
quickstart shows how to use chunk oriented batch jobs to import a file to a database.
What is it?
This quickstart simulates a file importation using batch jobs. To make it easy, this quickstart offers the user a way to generate files. The generated file can have its name and the number of records customized. The user can also specify if the file contains an error or not.
The job contains two tasks:
-
It imports the file using a chunk oriented approach.
-
The chunk size is set to
3
. -
The
RecordsReader
is responsible for parsing the file and create an instance ofContact
. -
The
ContactsFormatter
applies the proper case to the contact name and it also applies a mask to the phone number. -
Finally,
ContactsPersister
sends the contact instance to the database.
-
-
It logs the number of records imported.
The database schema defines that the column for name is unique. For that reason, any attempt to persist a duplicate value will throw an exception. On the second attempt to run the job, the ChunkCheckpoint
provides information to skip the contacts that were already persisted.
Getting Started with JBoss EAP for OpenShift
This document contains the basic instructions to build and deploy this quickstart to JBoss EAP for OpenShift or JBoss EAP for OpenShift Online.
See Getting Started with JBoss EAP for OpenShift Container Platform for more detailed information about building and running applications on JBoss EAP for OpenShift.
See Getting Started with JBoss EAP for OpenShift Online for more detailed information about building and running applications on JBoss EAP for OpenShift Online.
Prepare OpenShift for Quickstart Deployment
-
Log in to your OpenShift instance using the
oc login
command. -
Create a new project for the quickstart in OpenShift. You can create a project in OpenShift using the following command.
$ oc new-project batch-processing-project
Import the Latest JBoss EAP for OpenShift Image Streams and Templates
Important
|
If you are building and deploying this quickstart on JBoss EAP for OpenShift, you must configure authentication to the Red Hat Container Registry before you import the image streams and templates into your namespace. Getting Started with JBoss EAP for OpenShift Container Platform provides an example of one way to configure authentication to the registry. For additional information, see Red Hat Container Registry Authentication on the Red Hat Customer Portal. Configuration of authentication to the registry is not necessary if you are building and deploying this quickstart on JBoss EAP for OpenShift Online. |
Use the following command to import the latest JBoss EAP for OpenShift image streams and templates into your OpenShift project’s namespace.
for resource in \ eap-cd-image-stream.json \ eap-cd-amq-persistent-s2i.json \ eap-cd-amq-s2i.json \ eap-cd-basic-s2i.json \ eap-cd-https-s2i.json \ eap-cd-mongodb-persistent-s2i.json \ eap-cd-mongodb-s2i.json \ eap-cd-mysql-persistent-s2i.json \ eap-cd-mysql-s2i.json \ eap-cd-postgresql-persistent-s2i.json \ eap-cd-postgresql-s2i.json \ eap-cd-third-party-db-s2i.json \ eap-cd-tx-recovery-s2i.json \ eap-cd-sso-s2i.json do oc replace --force -f \ https://raw.githubusercontent.com/jboss-container-images/jboss-eap-7-openshift-image/CD19/templates/${resource} done
Note
|
The JBoss EAP image streams and templates imported using the above command are only available within that OpenShift project. If you have administrative access to the general ... oc replace -n openshift --force -f \ ... |
Deploy the JBoss EAP Source-to-Image (S2I) Quickstart to OpenShift
-
Create a new OpenShift application using the JBoss EAP for OpenShift image and the quickstart’s source code. Use the following command to use the
eap-cd-basic-s2i
template with thebatch-processing
source code on GitHub.oc new-app --template=eap-cd-basic-s2i \ -p IMAGE_STREAM_NAMESPACE="batch-processing-project" \ -p SOURCE_REPOSITORY_URL="https://github.com/jboss-developer/jboss-eap-quickstarts" \ -p SOURCE_REPOSITORY_REF="openshift" \ -p ENABLE_GENERATE_DEFAULT_DATASOURCE="true" \ -p CONTEXT_DIR="batch-processing"
With respect to the command parameters:
-
--template
The template to use. -
-p IMAGE_STREAM_NAMESPACE
The latest images streams and templates were imported into the project’s namespace, so you must specify the namespace of where to find the image stream. This is usually the OpenShift project’s name. -
-p SOURCE_REPOSITORY_URL
The URL to the repository containing the application source code. -
-p SOURCE_REPOSITORY_REF
The Git repository reference to use for the source code. This can be a Git branch or tag reference. -
-p ENABLE_GENERATE_DEFAULT_DATASOURCE
Enables the default datasource, which is required by this quickstart. -
-p CONTEXT_DIR
The directory within the source repository to build.
NoteA template can specify default values for many template parameters, and you might have to override some, or all, of the defaults. To see template information, including a list of parameters and any default values, use the command oc describe template TEMPLATE_NAME
. -
Tip
|
It is possible to trim down the JBoss EAP image that will be used to run this quickstart. To do so, please add the -p GALLEON_PROVISION_LAYERS=<galleon layers> argument when creating the new application. Please refer to the JBoss EAP documentation for the list of supported galleon layers.
|
-
Retrieve the name of the build configuration.
$ oc get bc -o name
-
Use the name of the build configuration from the previous step to view the Maven progress of the build.
$ oc logs -f buildconfig/eap-app