Spring Batch Lightmin BOM

BOM for Spring Batch Lightmin

License

License

GroupId

GroupId

org.tuxdevelop
ArtifactId

ArtifactId

spring-batch-lightmin-bom
Last Version

Last Version

2.2.1
Release Date

Release Date

Type

Type

pom
Description

Description

Spring Batch Lightmin BOM
BOM for Spring Batch Lightmin
Source Code Management

Source Code Management

https://github.com/tuxdevelop/spring-batch-lightmin.git

Download spring-batch-lightmin-bom

How to add to project

<!-- https://jarcasting.com/artifacts/org.tuxdevelop/spring-batch-lightmin-bom/ -->
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-bom</artifactId>
    <version>2.2.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/org.tuxdevelop/spring-batch-lightmin-bom/
implementation 'org.tuxdevelop:spring-batch-lightmin-bom:2.2.1'
// https://jarcasting.com/artifacts/org.tuxdevelop/spring-batch-lightmin-bom/
implementation ("org.tuxdevelop:spring-batch-lightmin-bom:2.2.1")
'org.tuxdevelop:spring-batch-lightmin-bom:pom:2.2.1'
<dependency org="org.tuxdevelop" name="spring-batch-lightmin-bom" rev="2.2.1">
  <artifact name="spring-batch-lightmin-bom" type="pom" />
</dependency>
@Grapes(
@Grab(group='org.tuxdevelop', module='spring-batch-lightmin-bom', version='2.2.1')
)
libraryDependencies += "org.tuxdevelop" % "spring-batch-lightmin-bom" % "2.2.1"
[org.tuxdevelop/spring-batch-lightmin-bom "2.2.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Spring Batch Lightmin

About

Spring Batch Lightmin is a client/server batch and scheduling platform for the Spring Boot stack. The batch stack based on Spring Batch.

Architecture

lightmin architecture.001

Documentation

The full documentation can be found at

  • 2.2.x (Spring Boot 2.4.x)

  • 2.1.x (Spring Boot 2.2.x, 2.3.x)

  • 2.0.x (Spring Boot 2.1.x)

  • 1.x (Spring Boot 1.5.x) - End of life

  • 0.5.x (old design - Spring Boot 1.5.x) - End of life

Samples

All samples for Spring Batch Lightmin can be found at Sample Applications

Getting Started

Important

Spring 5.1.x set the the property spring.main.allow-bean-definition-overriding to false as a default. In order to use the current version of Spring Batch Lightmin, this property has to be set to true.

This issue can hopefully be solved in the upcoming releases.

The following section describes a quick start guide to setup the client server architecture. If your want to get an overview of the configuration options, please read the documentation. The getting started guide for the Embedded Mode can be found in the section Embedded Lightmin.

Spring Batch Lightmin BOM

Add the Spring Batch Lightmin BOM to the dependency management section of your project.

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-bom</artifactId>
    <version>${spring-batch-lightmin.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

Setting up the Server

The server is the component which is used to configure clients and schedule jobs.

Important

The server can be operated in standalone and cluster mode. The standalone mode does not support any synchronisation between multiple cluster instances. Also the server cluster scheduler are working totally independent from each other in standalone mode.

The server itself is also a Spring Boot application.

Maven Dependencies

Standalone

The following dependency has to added to your project.

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-server-standalone</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>
Cluster

The project currently provides one cluster implementation based on Infinispan.

Infinispan
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-server-cluster-infinispan</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

Enable the Server

In order to enable the server, the annotation @EnableLightminServer has to added to one of the @Configuration classes.

@EnableLightminServer
@SpringBootApplication
public class LightminServer {

}

Enable the Cluster

If you added the cluster dependencies the following actions have to be done:

Infinispan

In order to enable the server, the annotation @EnableLightminServer has to added to one of the @Configuration classes.

@EnableLightminServer
@EnableServerClusterInfinispan
@SpringBootApplication
public class LightminServer {

}

The Infinispan cluster configuration will provide the following clustered features:

  • Synchronized poller for server scheduler and clean up jobs

  • LightminServerLockManager implenentation for Infinispan

  • Distributed Repositories for

    • JobExecutionEventRepository

    • JournalRepository

    • LightminApplicationRepository

If the following properties are set to true, additional distributed repositories will be provided:

spring:
  batch:
    lightmin:
      server:
        cluster:
          infinispan:
            repository:
              init-scheduler-configuration-repository: true # default false (1)
              init-scheduler-execution-repository: true # default false (2)
  1. if true, a distributed SchedulerConfigurationRepository will be provided

  2. if true, a distributed SchedulerExecutionRepository will be provided

Important

It is highly recommended to use persistent repositories for SchedulerConfigurationRepository and SchedulerExecutionRepository like the JDBC repositories. The distributed repositories will contain the stored values as long as one cluster member is up and running.

Infinispan Global Configuration

In order to use the infinispan cluster, a GlobalConfiguration has to be provided. The documentation of Infinispan and jGroups will give you insides how to configure it for your need.

@Configuration
public class MyConfiguration {

    @Bean
    public GlobalConfiguration globalConfiguration() {
        return new GlobalConfigurationBuilder()
                // Configure the global configuration
                .build();
    }

}

Server Scheduler

Since lightmin version 2.1.1 the server provides a scheduler to trigger jobs at the clients. In order to provide this feature, the scheduler configurations and executions have to be stored.

The SchedulerConfigurationRepository and SchedulerExecutionRepository are responsible for the doing the job. Per dafault, the standalone server will configure inmemory repositories, which are cleared after each restart.

Configuration Properties

The behavior of the Server Scheduler can be changed via application properties.

spring:
  batch:
    lightmin:
      server:
        scheduler:
          enabled: true # default true (1)
          create-new-executions-on-failure: false # default false (2)
          create-new-executions-on-lost: false # default false (3)
          fail-on-instance-execution-count: true # default true (4)
          poller-period: 1000 # default 1000 (5)
          poller-period-retry: 1000 # default 1000 (6)
          repository:
            delete-poller-period: PT10m # default 10 minutes (7)
            delete-failed:  true # default true (8)
            delete-finished: true # default true (9)
            delete-lost: true # default true (10)
            keep-failed: PT24h # default 24 hours (11)
            keep-finished: PT24h  # default 24 hours (12)
            keep-lost: PT24h  # default 24 hours (13)
  1. If set to false, no schedulers will be executed

  2. If set to true, a new executions based on the configuration will be created on failure.

  3. If set to true, a new executions based on the configuration will be created on lost after configured retries failed.

  4. If true, the execution will fail if not enough instances are available.

  5. Time in millis to fetch new executions to be executed by the scheduler

  6. Time in millis to fetch executions to be retried by the scheduler

  7. Duration of the clean up poller for the repositories

  8. If set to true, the failed executions will be deleted automatically.

  9. If set to true, the finished executions will be deleted automatically.

  10. If set to true, the lost executions will be deleted automatically.

  11. Duration how long failed executions should be kept before getting deleted automatically.

  12. Duration how long finished executions should be kept before getting deleted automatically.

  13. Duration how long lost executions should be kept before getting deleted automatically.

Important

The properties

create-new-executions-on-failure: false
create-new-executions-on-lost: false
fail-on-instance-execution-count: true

are global properties. There is the possibility that future releases will support this configuration option per execution.

Server Scheduler Jdbc Repositories

The database schema for the repositories are available in the dependency at org.tuxdevelop.spring.batch.lightmin.server.scheduler.repository

Maven Dependency
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-server-scheduler-repository-jdbc</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>
Enable the JDBC Repository
@EnableLightminServer
@EnableServerSchedulerJdbcRepository
@SpringBootApplication
public class MyApplication {
    ...
}

Service Discovery

Depending on the clients, the server is also able to find the clients via service discovery.

To enable the feature, a DiscoveryClient implementation has to added and configured(e.g. Consul, Eureka, etc…​) and the following property has to set to true

spring::
  batch:
    lightmin:
      server:
        discovery-enabled: true

Server behind a Proxy

The server frontend uses redirects and the HOST header is taken to create the redirect urls. This is the default behaviour of Spring MVC. If the server frontend is running behind a proxy, the implementation of the server takes care, that the X-FORWARD-PREFIX header is used as well.

If the proxy cannot pass the HOST header or you do not want to change the defaults, e.g. Zuul, the following property can force the server to use the X-FORWARDED-HOST header to build the redirect urls.

spring:
  batch:
    lightmin:
      server:
        use-x-forwarded-headers: true

Setting up a Client

The client applications are responsible to provide Spring Batch Job definitions. The Spring Batch Lightmin client framework provides all the configurations to set up Spring Batch and the communication with the server.

Step one - Client type

The type of the client decides how the registration to the server should be done. Currently to types are supported, classic and via service discovery.

Classic

The classic client has to know where the servers are located and will send a registration request after the start up.

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-client-classic</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The dependency above will provide everything which is required for the classic client. The annotation @EnableLightminClientClassic has to added to one of the configuration classes.

@SpringBootApplication
@EnableLightminClientClassic
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

The following configuration properties have to be present

spring:
  application:
    name: my-client-application (1)
  batch:
    lightmin:
      client:
        classic:
          server:
            url: http://myserver1.domain:8180, http://myserver2.domain:8180 (2)
  1. The spring.application.name is used to identify a client and handle a cluster of the instances.

  2. The url property is a list of server to which the registration request should be send.

Service Discovery

Spring Batch Lightmin provides two implementations for the discovery client type. Both implementations add a tags to the underlying service discovery technology, so the server could identify lightmin clients.

Consul Client

The following dependency has to added for the consul client

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-client-discovery-consul</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The annotation @EnableLightminClientConsul enables the fully integration with Consul.

@SpringBootApplication
@EnableLightminClientConsul
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

The configuration options for Consul can be found in the Spring Cloud Consul documentation.

The client is sending per default events to the server, in order to find the server via service discovery, the following property has to be set.

spring:
  batch:
    lightmin:
      client:
        discovery:
          server-discovery-name: lightmin-server (1)
  1. The service discovery name of the server.

Eureka Client

The following dependency has to added for the eureka client

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-client-discovery-eureka</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The annotation @EnableLightminClientEureka enables the fully integration with Eureka.

@SpringBootApplication
@EnableLightminClientEureka
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

The configuration options for Eureka can be found in the Spring Cloud Netflix documentation.

The client is sending per default events to the server, in order to find the server via service discovery, the following property has to be set.

spring:
  batch:
    lightmin:
      client:
        discovery:
          server-discovery-name: lightmin-server (1)
  1. The service discovery name of the server.

Step two - The Configuration Repository

The Configuration Repository is the component which stores the scheduler and listener configurations of the lightmin clients. This configurations are loaded at start time and can be managed with the server frontend or API calls.

Spring Batch Lightmin provides three implementation of the repository

  • map - In memory repository, all changes will be gone after a restart.

  • jdbc - The client fetches and stores the configurations in a database.

  • remote - The client fetches and stores the configurations via API calls to a repository server.

Map Repository
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-repository-map</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The annotation @EnableLightminMapConfigurationRepository enables the in memory repository.

@SpringBootApplication
@EnableLightminClientConsul
@EnableLightminMapConfigurationRepository
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}
Jdbc Repository
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-repository-jdbc</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The annotation @EnableLightminJdbcConfigurationRepository enables the jdbc repository.

@SpringBootApplication
@EnableLightminClientConsul
@EnableLightminJdbcConfigurationRepository
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

The jdbc repository requires a configured datasource bean with the name dataSource.

If the project configuration requires a specific datasource for the lightmin repository, the bean name can set via configuration property. More configuration options can be found in the documentation.

spring:
  batch:
    lightmin:
      repository:
        jdbc:
          data-source-name: myDataSource (1)
  1. Overriding the default datasource name.

The database schema ddl and drop scripts for various databases are located in the dependency above under the path:

org/tuxdevelop/spring/batch/lightmin/repository
Remote Repository
<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-repository-remote</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

The annotation @EnableLightminRemoteConfigurationRepository enables the remote repository.

@SpringBootApplication
@EnableLightminClientConsul
@EnableLightminRemoteConfigurationRepository
public class ClientApplication {

    public static void main(final String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }
}

The remote repository can be located via url and service discovery.

For the url way, the following properties has to be set:

  spring:
    batch:
      lightmin:
        repository:
          remote:
            server-url: http://my-server.domain:8280 (1)
  1. The url to the remote repository server

For the service discovery approach, the following properties has to set and a DiscoveryClient bean has to be present.

  spring:
    batch:
      lightmin:
        repository:
          remote:
            discover-remote-repository: true (1)
            server-discovery-name: remoteRepositorySever (2)
  1. Enables the discovery feature

  2. The discovery name of the remote repository server

Further configuration options can be found in the documentation.

Step three - Configure Spring Batch

The client configurations are enabling the Spring Batch stack as well. Spring Batch itself has to have a configured JobRepository. This JobRepository can be in memory via map or jdbc.

The configuration of the JobRepository can be done via properties, so Spring Batch Lightmin knows what to configure.

Map JobRepository

For the map repository, the following configuration is enough:

spring:
  batch:
    lightmin:
      batch:
        repository-type: map
Jdbc Repository

For the jdbc repository, the following configuration is enough:

spring:
  batch:
    lightmin:
      batch:
        repository-type: jdbc

Properties like dataSource name, table prefix etc. can be overridden as well. Please check the documentation for more details.

Clients in Containers

If a client runs inside a container like Docker, the dns name of the host systems has to be transferred to server on registration time. For this use case, a property is available.

spring:
  batch:
    lightmin:
      client:
        hostname: FQDN of the host

Lightmin Client and JPA

If your clients uses JPA, the following annotation is required to initialize the JPA specific Lightmin BatchConfigurer.

@Configuration
@EnableLightminBatchJpa (1)
public class MyConfiguration {

}
  1. @EnableLightminBatchJpa configures the JPA specific BatchConfigurer

Remote Repository Server

The Remote Repository Server is a Spring Boot application which provides a REST API for clients.

The server itself needs a job configuration repository itself. The server supports map and jdbc.

Maven

For the Jdbc repository, the following dependencies have to be added.

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-repository-server</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-repository-jdbc</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

Configuration

The configuration of the used repository can be found in the client section.

The annotation @EnableLightminRepositoryServer enables the server and the corresponding annotation the job configuration repository.

@SpringBootApplication
@EnableLightminRepositoryServer
@EnableLightminJdbcConfigurationRepository
public class RepositoryServerApplication {

    public static void main(final String[] args) {
        SpringApplication.run(RepositoryServerApplication.class, args);
    }
}

Embedded Lightmin

If the client server architecture does not fit the requirements, Spring Batch Lightmin also provides am embedded mode, which ships the client and server in one package.

Maven

<dependency>
    <groupId>org.tuxdevelop</groupId>
    <artifactId>spring-batch-lightmin-embedded</artifactId>
    <version>${spring-batch-lightmin.version}</version>
</dependency>

Configuration

In this case, a specific client does not have to be configured. The Job Configuration Repository and Spring Batch have to be configured like for a regular client.

@SpringBootApplication
@EnableLightminEmbedded
@EnableLightminMapConfigurationRepository
public class EmbeddedLightminApplication {

    public static void main(final String[] args) {
        SpringApplication.run(EmbeddedLightminApplication.class, args);
    }
}
spring:
  batch:
    lightmin:
      batch:
        repository-type: map

Spring Batch Lightmin Metrics

Lightmin Metrics introduces some custom metrics for the Lightmin-Platform. It uses Micrometer to collect metrics. The metrics are available for client and server applications.

Enabling Client Metrics

In order to collect metrics of a Lightmin client application, the following property has to be to true.

spring:
    batch:
        lightmin:
            client:
                metrics-enabled: true # default true
Important

If you want to use runtime information of a client on a server, the following property has to be set to true. The information send will be transformed to metrics on the server, if the sever metrics feature is enabled.

spring:
    batch:
        lightmin:
            client:
                publish-job-events: true # default true

Enabling Server Metrics

In order to collect metrics of a Lightmin server , the following property has to be set to true.

spring:
    batch:
        lightmin:
            server:
                metrics-enabled: true # default true

Exposing Metrics via actuator

In order to expose the collected metrics, a Micrometer registry dependencies has to be added to the client and the server.

For prometheus, the following dependencies has to be added

<dependency>
  <groupId>io.micrometer</groupId>
  <artifactId>micrometer-registry-prometheus</artifactId>
  <version>${micrometer.version}</version>
</dependency>
Important

The lightmin dependencies do not provide any registries out of the box

Modifying Lighmin Metrics

Metrics will be published over prometheus actuator and can be modified by adding MeterFilter into the metrics configuration. Refer to Micrometer Documentation for more information.

@Configuration
public class Config{

final static String name = "EXAMPLE";

@Bean
public MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
        return registry -> {
            if (name != null) {
                registry.config().meterFilter(
                        new MeterFilter() {
                            @Override
                            public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
                                if (id.getName().startsWith("lightmin")) {
                                    // Example Filter - Activating histogram on all lightmin metrics
                                    return DistributionStatisticConfig.builder().percentilesHistogram(true)
                                            .percentiles(0.95)
                                            .build()
                                            .merge(config);
                                }
                                return config;
                            }
                        })
                        .commonTags("example_tag", name);
            }
        };
    }
}

Grafana Dashboards

Lightmin Metrics introduces prebuild Grafana Dashboards for server and client. The json files are available in the resources folder of the lightmin-metrics project. In order to use the plugin, please install the following Plugins:

  • Statusmap by Flant JSC

Lightmin Dashboard

The Spring Batch Lightmin Dashboard provides information about all Lightmin clients which are configured as target in Prometheus. The following variables are available:

  • Service - taken from the tag APPLICATION_NAME (Lightmin Clients should be listed here)

  • Job Name - Name of all jobs, or all jobs of the selected Services

  • Job Count Interval - Time period for the overall SUCCESSFUL and FAILED overview

grafana all

If a specific Job Name is selected, the details about the job and step execution will be displayed.

grafana job

Lightmin Server Dashboard

The Server Dashboard provides an overview of all Job Executions, which are send from the clients to the server. The Lightmin server(s) should be configured as target in Prometheus.

grafana server all
Important

The boards require a Prometheus datasource.

Server User Interface

Applications

The start page of the SpringBatchLightmin shows all register applications. The status icon shows the current health status of the application.

applications

Application Instance Dashboard

The application dashboard is the entry point to the monitoring and administration of a client application instance. The overview shows the important endpoints, all known Spring Batch Jobs and configured external links of the client application.

dashboard

Batch Jobs

The batch jobs overview shows all registered batch jobs of the application instance and the execution count of them.

batch jobs

Batch Job Executions

The view shows an overview of all executions for the selected job. To get details of the job execution, click on the desired id.

batch job

Job Execution

The job execution view shows you a detailed overview about the job and step executions of the selected job execution.

job execution

Job Scheduler

Job Scheduler Configurations are cron or time based scheduler.

scheduler

Add Job Scheduler Configuration

Period Scheduler
scheduler period add
Cron Scheduler
scheduler cron add

Job Listener

listener

Add Job Listener configuration

listener add

Job Launcher

job launcher

Job Execution Events

job execution events

Journal

journal

Server Scheduler

Server Scheduler Executions

server scheduler executions

Server Scheduler Configurations

server scheduler configurations

Add Server Scheduler Configuration

server scheduler configuration add

Versions

Version
2.2.1
2.2.0
2.1.2
2.1.1
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
1.0.0