GithubHelp home page GithubHelp logo

dreamant99 / batch-poc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scizeron/batch-poc

1.0 1.0 0.0 24 KB

spring-boot spring-batch, quartz scheduling and docker swarm

Java 99.73% Shell 0.27%

batch-poc's Introduction

batch-poc

Purpose

Batch processing based on 3 main compoments :

  • scheduler : based on Quartz
  • processor : based on Spring-batch (with DB repository)
  • api : management, executions reports ...

Leverage docker swarm 1.12 +

  • scheduler : service (replicas=1), provide an API to schedule/update jobs
  • the scheduler leverages the service vip, ensuring the processor load balancing
  • the api is also multi replicated

Build

maven clean install

Scheduler

run locally

java -jar target/batch-scheduler.jar

Processor

run locally

java -jar target/batch-processor.jar 

Admin

Based on spring-data-rest-webmvc in order to pusblish a read only API about spring-batch jobs executions

java -jar target/batch-admin.jar 

Swarm Cluster

Docker Image Deployment

mvn clean package docker:build -DpushImage

Assumptions

  • A cluster swarm is up and running
  • An existing overlay network "my-network" or other ...
  • A PostgreSQL server instance
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres
  • A "batch" database with a specific user (batch/batch)
 docker run -it --rm --link some-postgres:postgres postgres psql -h postgres -U postgres
CREATE USER batch WITH PASSWORD 'batch';
CREATE DATABASE batch OWNER batch;

Create services

Set the replicas equals to 1, in order to troubleshoot.

docker service create --name processor --replicas 1 \
--network my-network scizeron/batch-processor:0.0.1-SNAPSHOT --db.batch.host=<db_host>

By default, the db connection info are listed below. Use --var in the command line to override :

  • db.batch.host=localhost
  • db.batch.port=5432
  • db.batch.username=batch
  • db.batch.password=batch
docker service create --name scheduler --replicas 1 \
--network my-network --endpoint-mode vip \
--publish 80:7000 scizeron/batch-scheduler:0.0.1-SNAPSHOT \
--batch.processing.service=processor:7001 --db.batch.host=<db_host>

Schedule jobs

List the scheduled jobs

curl http://<swarm_node_host>/v1/jobs returns an empty array at the begining.

Add a new job

curl -X POST -d '{"jobName":"test", "clientId": "clientId", "description": "desc", "cronExpression": "0 * 14 * * ?"}' http://<swarm_node_host>/v1/jobs

Troubleshooting

  • Find the node where task is running : docker service ps
  • Connect to the host, "docker ps" allows you to get the container id
  • To display the application logs : docker logs -f <container_id>

Scaling

docker service scale processor=2

Jobs executions

docker service create --name admin --replicas 1 \
--network my-network --endpoint-mode vip \
--publish 82:7002 scizeron/batch-admin:0.0.1-SNAPSHOT \
--db.batch.host=<db_host>
curl http://<swarm_node_host>/api/batchJobExecutions

batch-poc's People

Contributors

scizeron avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.